Line | |
---|
1 | /*************************************************************************/ |
---|
2 | /* */ |
---|
3 | /* This file is included in case your version of Unix doesn't include */ |
---|
4 | /* the getopt utility. If it does, discard this file and amend the */ |
---|
5 | /* Makefile accordingly. */ |
---|
6 | /* */ |
---|
7 | /* There is no copyright on this file. */ |
---|
8 | /* */ |
---|
9 | /*************************************************************************/ |
---|
10 | |
---|
11 | |
---|
12 | #include <stdio.h> |
---|
13 | |
---|
14 | |
---|
15 | int optind = 1; |
---|
16 | char *optarg; |
---|
17 | |
---|
18 | |
---|
19 | getopt(Argc, Argv, Str) |
---|
20 | /* ------ */ |
---|
21 | int Argc; |
---|
22 | char **Argv, *Str; |
---|
23 | { |
---|
24 | int Optchar; |
---|
25 | char *Option; |
---|
26 | |
---|
27 | if ( optind >= Argc ) return EOF; |
---|
28 | |
---|
29 | Option = Argv[optind++]; |
---|
30 | |
---|
31 | if ( *Option++ != '-' ) return '?'; |
---|
32 | |
---|
33 | Optchar = *Option++; |
---|
34 | |
---|
35 | while ( *Str && *Str != Optchar ) Str++; |
---|
36 | if ( ! *Str ) return '?'; |
---|
37 | |
---|
38 | if ( *++Str == ':' ) |
---|
39 | { |
---|
40 | if ( *Option ) optarg = Option; |
---|
41 | else |
---|
42 | if ( optind < Argc ) optarg = Argv[optind++]; |
---|
43 | else |
---|
44 | Optchar = '?'; |
---|
45 | } |
---|
46 | |
---|
47 | return Optchar; |
---|
48 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.