args.h 1.1 KB

1234567891011121314151617181920212223242526272829
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. extern char *argv0;
  10. #define ARGBEGIN for((argv0? 0: (argv0=*argv)),argv++,argc--;\
  11. argv[0] && argv[0][0]=='-' && argv[0][1];\
  12. argc--, argv++) {\
  13. char *_args, *_argt;\
  14. Rune _argc;\
  15. _args = &argv[0][1];\
  16. if(_args[0]=='-' && _args[1]==0){\
  17. argc--; argv++; break;\
  18. }\
  19. _argc = 0;\
  20. while(*_args && (_args += chartorune(&_argc, _args)))\
  21. switch(_argc)
  22. #define ARGEND SET(_argt);USED(_argt); USED(_argc); USED(_args);}USED(argv); USED(argc);
  23. #define ARGF() (_argt=_args, _args="",\
  24. (*_argt? _argt: argv[1]? (argc--, *++argv): 0))
  25. #define ARGC() _argc
  26. #define EARGF(x) (_argt=_args, _args="",\
  27. (*_argt? _argt: argv[1]? (argc--, *++argv): (x, (char*)0)))