Message-Id: <200004241603.LAA20560@darwin.sfbr.org> Date: Mon, 24 Apr 2000 11:03:08 -0500 (CDT) From: Jeff Williams Subject: patch to getopt.txh To: djgpp-workers AT delorie DOT com MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii Content-MD5: 8DBVYnYD8bi7SKhcfaSO7Q== X-Mailer: dtmail 1.3.0 @(#)CDE Version 1.3.4 SunOS 5.7 sun4u sparc Reply-To: djgpp-workers AT delorie DOT com The following patch adds a bit to the documentation for the `getopt' libc function to clarify how the `?' character can be used as a valid option as well as for flagging an unexpected option. It's something I found useful; I hope you agree it is a worthwhile patch. I made it against the latest CVS source (d/l'ed this morning). jtw *** src/libc/posix/unistd/getopt.txh.old Fri Sep 10 15:19:52 1999 --- src/libc/posix/unistd/getopt.txh Mon Apr 24 10:51:48 2000 *************** *** 22,27 **** --- 22,30 ---- If an unexpected option is found, @code{getopt} will return @code{?}, and if @code{opterr} is nonzero, will print an error message to stderr. + The example below shows how @code{?} can be still be used as an option + (e.g., to request a summary of program usage) in addition to flagging + an unexpected option. The special option @code{--} indicates that no more options follow on the command line, and cause @code{getopt} to stop looking. *************** *** 39,45 **** @example int c; opterr = 0; ! while ((c=getopt(argc, argv, "vbf:")) != -1) @{ switch (c) @{ --- 42,48 ---- @example int c; opterr = 0; ! while ((c=getopt(argc, argv, "?vbf:")) != -1) @{ switch (c) @{ *************** *** 53,61 **** output_filename = optarg; break; case '?': ! printf("Unknown option %c\n", optopt); ! usage(); ! exit(1); @} @} @end example --- 56,69 ---- output_filename = optarg; break; case '?': ! if (optopt == '?') @{ ! usage(); ! exit(0); ! @} else @{ ! printf("Unknown option %c\n", optopt); ! usage(); ! exit(1); ! @} @} @} @end example