mirror of https://github.com/mkerrisk/man-pages
87ce949275
Explain that `optstring` cannot contain a semi-colon (`;`) character. [mtk: verified with a small test program; see also posix/getopt.c in the glibc sources: if (temp == NULL || c == ':' || c == ';') { if (print_errors) fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c); d->optopt = c; return '?'; } ] Also explain that `optstring` can include `+` as an option character, possibly in addition to that character being used as the first character in `optstring` to denote `POSIXLY_CORRECT` behaviour. [mtk: verified with a small test program.] Test program below. Example runs: $ ./a.out -+ opt = 43 (+); optind = 2 Got plus $ ./a.out -';' ./a.out: invalid option -- ';' opt = 63 (?); optind = 2; optopt = 59 (;) Unrecognized option (-;) Usage: ./a.out [-p arg] [-x] Signed-off-by: James O. D. Hunt <jamesodhunt@gmail.com> Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com> 8x---8x---8x---8x---8x---8x---8x---8x---8x---8x---8x--- #include <ctype.h> #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #define printable(ch) (isprint((unsigned char) ch) ? ch : '#') static void /* Print "usage" message and exit */ usageError(char *progName, char *msg, int opt) { if (msg != NULL && opt != 0) fprintf(stderr, "%s (-%c)\n", msg, printable(opt)); fprintf(stderr, "Usage: %s [-p arg] [-x]\n", progName); exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { int opt, xfnd; char *pstr; xfnd = 0; pstr = NULL; while ((opt = getopt(argc, argv, "p:x+;")) != -1) { printf("opt =%3d (%c); optind = %d", opt, printable(opt), optind); if (opt == '?' || opt == ':') printf("; optopt =%3d (%c)", optopt, printable(optopt)); printf("\n"); switch (opt) { case 'p': pstr = optarg; break; case 'x': xfnd++; break; case ';': printf("Got semicolon\n"); break; case '+': printf("Got plus\n"); break; case ':': usageError(argv[0], "Missing argument", optopt); case '?': usageError(argv[0], "Unrecognized option", optopt); default: printf("Unexpected case in switch()\n"); exit(EXIT_FAILURE); } } if (xfnd != 0) printf("-x was specified (count=%d)\n", xfnd); if (pstr != NULL) printf("-p was specified with the value \"%s\"\n", pstr); if (optind < argc) printf("First nonoption argument is \"%s\" at argv[%d]\n", argv[optind], optind); exit(EXIT_SUCCESS); } |
||
---|---|---|
man1 | ||
man2 | ||
man3 | ||
man4 | ||
man5 | ||
man6 | ||
man7 | ||
man8 | ||
scripts | ||
.gitignore | ||
CONTRIBUTING | ||
Changes | ||
Changes.old | ||
MAINTAINER_NOTES | ||
Makefile | ||
README | ||
man-pages-5.13.Announce | ||
man-pages-5.13.lsm |
README
This package contains Linux man pages for sections 1 through 8. Some more information is given in the 'man-pages-x.y.Announce' file. Homepage ======== For information about the Linux man-pages project, see http://www.kernel.org/doc/man-pages/index.html. Bug reports and contributing ============================ If you have corrections and additions to suggest, see http://www.kernel.org/doc/man-pages/contributing.html (Although there is a mirror of this repository on GitHub, please don't report issues via the GitHub issue tracker!) For further information on contributing, see the CONTRIBUTING file. Installing and uninstalling =========================== "make install" will copy these man pages to /usr/local/share/man/man[1-8]. To install to a path different from /usr/local, use "make install prefix=/install/path". "make remove" or "make uninstall" will remove any man page in this distribution from its destination. Use with caution, and remember to use "prefix" if desired, as with the "install" target. To install only a specific man section (mandir) such as man3, use "make install-man3". Similar syntax can be used to uninstall a specific man section, such as man7: "make uninstall-man7". "make" or "make all" will perform "make uninstall" followed by "make install". Consider using multiple threads (at least 2) when installing these man pages, as the Makefile is optimized for multiple threads: "make -j install". Copyrights ========== See the 'man-pages-x.y.Announce' file.