Xref: utzoo comp.lang.c:9014 comp.unix.wizards:7642 Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!nrl-cmf!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: command line options Message-ID: <7630@brl-smoke.ARPA> Date: 8 Apr 88 12:10:21 GMT References: <2414@zyx.UUCP> <8039@elsie.UUCP> <7628@brl-smoke.ARPA> <8040@elsie.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 33 In article <8040@elsie.UUCP> ado@elsie.UUCP (Arthur David Olson) writes: >> > I want some uniform way of getting programs to output their usage messages. >> Under the existing getopts scheme, typing >> command -? >> is guaranteed to get the usage message. >A problem and a two questions. First, the problem: > No manual entry for getopts. "getopts" is a builtin in the SVR3 and later shells; it is also built into the current BRL version of the SVR2 shell. I was actually referring to the getopt() library function, since that's what the ongoing discussion was about. A command that uses getopt() will branch to the "error case" if you use the ? flag option. The normal response in the error case is to print a usage message. >Second, the questions. Is a public-domain implementation of "the existing >getopts scheme," or at least a public-domain manual page, available? AT&T placed the getopt() source code, its manual page, the now-obsolete "getopt" utility, and its manual page into the public domain a few years ago. You can get this free from the AT&T UNIX System ToolChest, and I believe it was posted to one of the sources newsgroups. I typed up a "getopts" shell builtin manual page that I can send you, if you can't find it in UNIX System V Release 3 documentation. >is the scheme idiot-proof enough to work when executed in directories with >files named, for example, "-l"? If you have reason to believe that your command may have to handle non-option arguments with names starting with -, then follow the options with the -- option, which causes getopt() to stop interpreting arguments as options.