You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.0KB

  1. /*
  2. * Copy me if you can.
  3. * by 20h
  4. */
  5. #ifndef ARG_H__
  6. #define ARG_H__
  7. extern char *argv0;
  8. /* use main(int argc, char *argv[]) */
  9. #define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
  10. argv[0] && argv[0][0] == '-'\
  11. && argv[0][1];\
  12. argc--, argv++) {\
  13. char argc_;\
  14. char **argv_;\
  15. int brk_;\
  16. if (argv[0][1] == '-' && argv[0][2] == '\0') {\
  17. argv++;\
  18. argc--;\
  19. break;\
  20. }\
  21. int i_;\
  22. for (i_ = 1, brk_ = 0, argv_ = argv;\
  23. argv[0][i_] && !brk_;\
  24. i_++) {\
  25. if (argv_ != argv)\
  26. break;\
  27. argc_ = argv[0][i_];\
  28. switch (argc_)
  29. #define ARGEND }\
  30. }
  31. #define ARGC() argc_
  32. #define EARGF(x) ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
  33. ((x), abort(), (char *)0) :\
  34. (brk_ = 1, (argv[0][i_+1] != '\0')?\
  35. (&argv[0][i_+1]) :\
  36. (argc--, argv++, argv[0])))
  37. #define ARGF() ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
  38. (char *)0 :\
  39. (brk_ = 1, (argv[0][i_+1] != '\0')?\
  40. (&argv[0][i_+1]) :\
  41. (argc--, argv++, argv[0])))
  42. #endif