mirror of
git://git.suckless.org/ubase
synced 2024-12-24 23:52:34 +00:00
Add support for obsolete -NUM arguments in arg.h
Fix naming, _brk, _argc and _argv are reserved for the implementation. Thanks to nsz@port70.net for reporting this, the mail excerpt below. "actually __.* and _[A-Z].* are reserved for any usage and _.* is reserved for file scope identifiers" We just rename them to brk_, argc_ and argv_.
This commit is contained in:
parent
a42f909362
commit
34ea6ae10a
37
arg.h
37
arg.h
@ -13,38 +13,51 @@ extern char *argv0;
|
|||||||
argv[0] && argv[0][1]\
|
argv[0] && argv[0][1]\
|
||||||
&& argv[0][0] == '-';\
|
&& argv[0][0] == '-';\
|
||||||
argc--, argv++) {\
|
argc--, argv++) {\
|
||||||
char _argc;\
|
char argc_;\
|
||||||
char **_argv;\
|
char **argv_;\
|
||||||
int _brk;\
|
int brk_;\
|
||||||
if (argv[0][1] == '-' && argv[0][2] == '\0') {\
|
if (argv[0][1] == '-' && argv[0][2] == '\0') {\
|
||||||
argv++;\
|
argv++;\
|
||||||
argc--;\
|
argc--;\
|
||||||
break;\
|
break;\
|
||||||
}\
|
}\
|
||||||
for (_brk = 0, argv[0]++, _argv = argv;\
|
for (brk_ = 0, argv[0]++, argv_ = argv;\
|
||||||
argv[0][0] && !_brk;\
|
argv[0][0] && !brk_;\
|
||||||
argv[0]++) {\
|
argv[0]++) {\
|
||||||
if (_argv != argv)\
|
if (argv_ != argv)\
|
||||||
break;\
|
break;\
|
||||||
_argc = argv[0][0];\
|
argc_ = argv[0][0];\
|
||||||
switch (_argc)
|
switch (argc_)
|
||||||
|
|
||||||
|
/* Handles obsolete -NUM syntax */
|
||||||
|
#define ARGNUM case '0':\
|
||||||
|
case '1':\
|
||||||
|
case '2':\
|
||||||
|
case '3':\
|
||||||
|
case '4':\
|
||||||
|
case '5':\
|
||||||
|
case '6':\
|
||||||
|
case '7':\
|
||||||
|
case '8':\
|
||||||
|
case '9'
|
||||||
|
|
||||||
#define ARGEND }\
|
#define ARGEND }\
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ARGC() _argc
|
#define ARGC() argc_
|
||||||
|
|
||||||
|
#define ARGNUMF(base) (brk_ = 1, estrtol(argv[0], (base)))
|
||||||
|
|
||||||
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
||||||
((x), abort(), (char *)0) :\
|
((x), abort(), (char *)0) :\
|
||||||
(_brk = 1, (argv[0][1] != '\0')?\
|
(brk_ = 1, (argv[0][1] != '\0')?\
|
||||||
(&argv[0][1]) :\
|
(&argv[0][1]) :\
|
||||||
(argc--, argv++, argv[0])))
|
(argc--, argv++, argv[0])))
|
||||||
|
|
||||||
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
||||||
(char *)0 :\
|
(char *)0 :\
|
||||||
(_brk = 1, (argv[0][1] != '\0')?\
|
(brk_ = 1, (argv[0][1] != '\0')?\
|
||||||
(&argv[0][1]) :\
|
(&argv[0][1]) :\
|
||||||
(argc--, argv++, argv[0])))
|
(argc--, argv++, argv[0])))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user