Last change
on this file was
2,
checked in by oldcode, 24 years ago
|
Initial revision
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
File size:
1.3 KB
|
Line | |
---|
1 | /* |
---|
2 | * mygetopt.c Adachi, J. 1994.06.30 |
---|
3 | * Copyright (C) 1992, 1993 J. Adachi & M. Hasegawa, All rights reserved. |
---|
4 | */ |
---|
5 | |
---|
6 | /* #include <stdio.h> */ |
---|
7 | /* #include <string.h> */ |
---|
8 | #include "molphy.h" |
---|
9 | |
---|
10 | /* #define SW_CHAR '-' switch character, '-'(UNIX) or '/'(DOS) */ |
---|
11 | int Optindex = 1; /* index of next argument */ |
---|
12 | int Opterror = 1; /* error message level */ |
---|
13 | char *Optargp; /* pointer to argument of current option */ |
---|
14 | static char *Optlocp = NULL; /* next option char's location */ |
---|
15 | |
---|
16 | int mygetopt(argc, argv, optstring) |
---|
17 | int argc; |
---|
18 | char **argv; |
---|
19 | char *optstring; |
---|
20 | { |
---|
21 | unsigned char ch; |
---|
22 | char *optp; |
---|
23 | |
---|
24 | if (argc > Optindex) { |
---|
25 | if (Optlocp == NULL) { |
---|
26 | if ((Optlocp = argv[Optindex]) == NULL || *(Optlocp++) != SW_CHAR) |
---|
27 | goto lgetopteof; |
---|
28 | if (*Optlocp == SW_CHAR) { |
---|
29 | Optindex++; |
---|
30 | goto lgetopteof; |
---|
31 | } |
---|
32 | } |
---|
33 | if ((ch = *(Optlocp++)) == 0) { |
---|
34 | Optindex++; |
---|
35 | goto lgetopteof; |
---|
36 | } |
---|
37 | if (ch == ':' || (optp = strchr(optstring, ch)) == NULL) |
---|
38 | goto lgetopterr; |
---|
39 | if (':' == *(++optp)) { |
---|
40 | Optindex++; |
---|
41 | if (0 == *Optlocp) { |
---|
42 | if (argc <= Optindex) |
---|
43 | goto lgetopterr; |
---|
44 | Optlocp = argv[Optindex++]; |
---|
45 | } |
---|
46 | Optargp = Optlocp; |
---|
47 | Optlocp = NULL; |
---|
48 | } else { |
---|
49 | if (0 == *Optlocp) { |
---|
50 | Optindex++; |
---|
51 | Optlocp = NULL; |
---|
52 | } |
---|
53 | Optargp = NULL; |
---|
54 | } |
---|
55 | return ch; |
---|
56 | } |
---|
57 | |
---|
58 | lgetopteof: |
---|
59 | Optargp = Optlocp = NULL; |
---|
60 | return EOF; |
---|
61 | |
---|
62 | lgetopterr: |
---|
63 | Optargp = NULL; |
---|
64 | return ('?'); |
---|
65 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.