tmisu

Notification to stdout daemon
git clone https://git.inz.fi/tmisu/
Log | Files | Refs | README | LICENSE

arg.h (1680B)


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