Xref: utzoo comp.unix.wizards:7566 comp.lang.c:8885 Path: utzoo!mnetor!uunet!husc6!bloom-beacon!athena.mit.edu!peter From: peter@athena.mit.edu (Peter J Desnoyers) Newsgroups: comp.unix.wizards,comp.lang.c Subject: Re: command line options Message-ID: <4335@bloom-beacon.MIT.EDU> Date: 5 Apr 88 01:37:19 GMT References: <2414@zyx.UUCP> <738@srs.UUCP> <26423@cca.CCA.COM> <761@srs.UUCP> <26550@cca.CCA.COM> <6546@bellcore.bellcore.com> <625@umb.umb.edu> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: peter@athena.mit.edu (Peter J Desnoyers) Organization: Massachusetts Institute of Technology Lines: 29 Summary: Finally remembered the bbn package... I finally remembered the operation of the argument parser I mentioned in a previous posting. It was used as follows: [pretend 1-column text] #define OPT 0 optarray[OPT] = { "O", "Optimize", BOOLEAN}; #define MAXERR 1 optarray[MAXERR] = { "m", "maxerr", DECIMAL}; #define LIST 2 optarray[LIST] = { "l", "list", STRING}; This was usually done in the .h file for the main module. Then you would call get_args( argc, argv [,optarray?]) and it would shove everything into a global, but hidden, array. Finally, you would reference the resulting values with macros, sort of like: if (SET_P( LIST)) /* works for -l=list.out */ list_file = fopen( VALUE( LIST),"w"); /* and -list=list.out */ compile( ARG( 1)); /* handles args mixed with opts */ if (++errnum > VALUE( MAXERR)) /* parsed decimal value */ go_up_in_flames(); /* -maxerr=10, -m=10 */ if (SET_P( OPT)) /* simple flag '-O' */ go_off_and_optimize(); and suchlike. The global arrays were a kludge, but you need some type of sort-of-global flag for something like -O, and it will probably be a kludge, anyway. The only problem was that it wasn't re-entrant, and it supported a weird argument-passing style. (sort of like VMS but with '-' instead of '/'.) Peter Desnoyers peter@athena.mit.edu