#include <stdio.h>
Include dependency graph for getopt.c:

Go to the source code of this file.
Defines | |
| #define | EPR fprintf(stderr, |
| #define | ERR(str, chr) if(opterr){EPR "%s%c\n", str, chr);} |
Functions | |
| int | getopt (int argc, char *const argv[], const char *opts) |
| char * | strchr () |
Variables | |
| char * | optarg |
| int | opterr = 1 |
| int | optind = 1 |
| int | optopt |
|
|
|
|
|
Definition at line 3 of file getopt.c. Referenced by getopt(). |
|
||||||||||||||||
|
Definition at line 11 of file getopt.c. References argc, argv, c, cp, ERR, optarg, optind, optopt, strchr(), and strcmp(). 00012 {
00013 static int sp = 1;
00014 int c;
00015 char *cp;
00016
00017 if (sp == 1)
00018 if (optind >= argc ||
00019 argv[optind][0] != '-' || argv[optind][1] == '\0')
00020 return -1;
00021 else if (strcmp(argv[optind], "--") == 0) {
00022 optind++;
00023 return -1;
00024 }
00025 optopt = c = argv[optind][sp];
00026 if (c == ':' || (cp=strchr(opts, c)) == 0) {
00027 ERR (": illegal option -- ", c);
00028 if (argv[optind][++sp] == '\0') {
00029 optind++;
00030 sp = 1;
00031 }
00032 return '?';
00033 }
00034 if (*++cp == ':') {
00035 if (argv[optind][sp+1] != '\0')
00036 optarg = &argv[optind++][sp+1];
00037 else if (++optind >= argc) {
00038 ERR (": option requires an argument -- ", c);
00039 sp = 1;
00040 return '?';
00041 } else
00042 optarg = argv[optind++];
00043 sp = 1;
00044 } else {
00045 if (argv[optind][++sp] == '\0') {
00046 sp = 1;
00047 optind++;
00048 }
00049 optarg = 0;
00050 }
00051 return c;
00052 }
|
Here is the call graph for this function:

|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 6 of file getopt.c. Referenced by getopt(). |
1.3.9.1