Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ucbvax!bostic From: bostic@ucbvax.BERKELEY.EDU (Keith Bostic) Newsgroups: comp.unix.wizards Subject: Re: Command interfaces Message-ID: <22179@ucbvax.BERKELEY.EDU> Date: 15 Dec 87 19:35:39 GMT References: <432@cresswell.quintus.UUCP> <57900005@ccvaxa> Organization: University of California at Berkeley Lines: 48 In article <57900005@ccvaxa>, aglew@ccvaxa.UUCP writes: > > > Henry Spencer on getopt(): > > Why don't people use getopt > > more? Because the interface to getopt is a little complicated and it is > > hard to get it right when you are typing a program in from scratch. (For > > some discussion about why this is the wrong way to program, and how to > > avoid it, come to the Dallas Usenix and listen to my talk!) If the interface to the program is reasonably well defined, i.e. it follows the rules laid down in S5, it's not tough at all. Just put the following 14 lines in a file in some directory, copy them in and edit as needed. It just doesn't get any easier, this side of 4th GL's. #includeextern char *optarg; extern int optind; int ch; while ((ch = getopt(argc, argv, "")) != EOF) switch((char)ch) { case '': break; case '?': default: fprintf(stderr, "usage: %s", *argv); exit(1); } > 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"? > Actually, I'm a little relieved to hear Henry say that getopt is not > used as often as it should be. I don't particularly like getopt, > but feel guilty when I don't use it. Why wouldn't you use it? It's easier to write a command interface with it than without it, if you do the interface correctly. Getopt is the best thing of its type I've seen, although I'm certainly open to something new. That guilty feeling? It's a good thing, go with it. Keith Bostic ARPA: bostic@okeeffe.berkeley.edu UUCP: ucbvax!bostic or seismo!keith