src/util/getopt.c File Reference
#include <stdio.h>
#include "util.h"
Go to the source code of this file.
Function Documentation
int util_getopt |
( |
int |
argc, |
|
|
char *const |
argv[], |
|
|
char const * |
optstring | |
|
) |
| | |
Definition at line 40 of file getopt.c.
00041 {
00042 register int c;
00043 register char *place;
00044
00045 util_optarg = NIL(char);
00046
00047 if (scan == NIL(char) || *scan == '\0') {
00048 if (util_optind == 0) util_optind++;
00049 if (util_optind >= argc) return EOF;
00050 place = argv[util_optind];
00051 if (place[0] != '-' || place[1] == '\0') return EOF;
00052 util_optind++;
00053 if (place[1] == '-' && place[2] == '\0') return EOF;
00054 scan = place+1;
00055 }
00056
00057 c = *scan++;
00058 place = strchr(optstring, c);
00059 if (place == NIL(char) || c == ':') {
00060 (void) fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
00061 return '?';
00062 }
00063 if (*++place == ':') {
00064 if (*scan != '\0') {
00065 util_optarg = scan;
00066 scan = NIL(char);
00067 } else {
00068 if (util_optind >= argc) {
00069 (void) fprintf(stderr, "%s: %c requires an argument\n",
00070 argv[0], c);
00071 return '?';
00072 }
00073 util_optarg = argv[util_optind];
00074 util_optind++;
00075 }
00076 }
00077 return c;
00078 }
void util_getopt_reset |
( |
void |
|
) |
|
Variable Documentation