Path: utzoo!mnetor!uunet!husc6!hao!oddjob!gargoyle!ihnp4!cbosgd!mandrill!hal!ncoast!allbery From: allbery@ncoast.UUCP (Brandon Allbery) Newsgroups: comp.unix.wizards Subject: Re: Command interfaces Message-ID: <6870@ncoast.UUCP> Date: 19 Dec 87 19:55:29 GMT References: <432@cresswell.quintus.UUCP> <57900005@ccvaxa> <22179@ucbvax.BERKELEY.EDU> Reply-To: allbery@ncoast.UUCP (Brandon Allbery) Followup-To: comp.unix.wizards Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 43 As quoted from <22179@ucbvax.BERKELEY.EDU> by bostic@ucbvax.BERKELEY.EDU (Keith Bostic): +--------------- | In article <57900005@ccvaxa>, aglew@ccvaxa.UUCP writes: | > Another reason not to use getopt: because it requires information to | > be put in two places. You have to have a string containing your option | > letters, and a case for the actual option. Bad design. | | I am totally lost. You want to explain how you're going to avoid having | "information in two places"? +--------------- You answered *this* one a bit earlier in your posting. ("It doesn't get any easier, _this_side_of_4th_GL's_." Emphasis is mine.) v---- note $ token in column 1 to trigger preprocessing $ options (argc, argv) { /* usage is "[-b str]" */ string option 'b' into foo: /* this option's usage is "[-c]" */ boolean option 'c' into bar: break; /* usage is "[-d mode]" */ string option 'd' into baz as "mode": if (strcmp(baz, "gorf") == 0) { fprintf(stderr, "%s" -dgorf invalid\n"); exit(1); } break; } Notice that type conversion and assignment is automatic; and, if necessary, special processing can be performed. I may actually write such a preprocessor; it could collect the options and their arguments, and build a usage string automatically. By default any unmatched option would get the usage string and exit, but a "default:" phrase could be used to allow special processing. (Note: I already *have* written some preprocessors of this general form, most of them are for DBMS C hooks. It's not difficult for someone experienced with lex/yacc.) -- Brandon S. Allbery necntc!ncoast!allbery@harvard.harvard.edu {hoptoad,harvard!necntc,cbosgd,sun!mandrill!hal,uunet!hnsurg3}!ncoast!allbery Moderator of comp.sources.misc