Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | #include <config.h> | - |
22 | | - |
23 | #if defined (HAVE_UNISTD_H) | - |
24 | # include <unistd.h> | - |
25 | #endif | - |
26 | | - |
27 | #include "../bashansi.h" | - |
28 | #include <chartypes.h> | - |
29 | #include <errno.h> | - |
30 | | - |
31 | #include "../shell.h" | - |
32 | #include "common.h" | - |
33 | | - |
34 | #include "bashgetopt.h" | - |
35 | | - |
36 | #define ISOPT(s) (((*(s) == '-') || (plus && *(s) == '+')) && (s)[1]) | - |
37 | #define NOTOPT(s) (((*(s) != '-') && (!plus || *(s) != '+')) || (s)[1] == '\0') | - |
38 | | - |
39 | static int sp; | - |
40 | | - |
41 | char *list_optarg; | - |
42 | int list_optopt; | - |
43 | int list_opttype; | - |
44 | | - |
45 | static WORD_LIST *lhead = (WORD_LIST *)NULL; | - |
46 | WORD_LIST *lcurrent = (WORD_LIST *)NULL; | - |
47 | WORD_LIST *loptend; | - |
48 | | - |
49 | int | - |
50 | internal_getopt(list, opts) | - |
51 | WORD_LIST *list; | - |
52 | char *opts; | - |
53 | { | - |
54 | register int c; | - |
55 | register char *cp; | - |
56 | int plus; | - |
57 | static char errstr[3] = { '-', '\0', '\0' }; | - |
58 | | - |
59 | plus = *opts == '+'; | - |
60 | if (plus)TRUE | evaluated 3264812 times by 1 test | FALSE | evaluated 4037354 times by 1 test |
| 3264812-4037354 |
61 | opts++;executed 3264812 times by 1 test: opts++; | 3264812 |
62 | | - |
63 | if (list == 0) {TRUE | evaluated 612 times by 1 test | FALSE | evaluated 7301554 times by 1 test |
| 612-7301554 |
64 | list_optarg = (char *)NULL; | - |
65 | loptend = (WORD_LIST *)NULL; | - |
66 | return -1;executed 612 times by 1 test: return -1; | 612 |
67 | } | - |
68 | | - |
69 | if (list != lhead || lhead == 0) {TRUE | evaluated 4645157 times by 1 test | FALSE | evaluated 2656397 times by 1 test |
TRUE | never evaluated | FALSE | evaluated 2656397 times by 1 test |
| 0-4645157 |
70 | | - |
71 | sp = 1; | - |
72 | lcurrent = lhead = list; | - |
73 | loptend = (WORD_LIST *)NULL; | - |
74 | }executed 4645157 times by 1 test: end of block | 4645157 |
75 | | - |
76 | if (sp == 1) {TRUE | evaluated 5980174 times by 1 test | FALSE | evaluated 1321380 times by 1 test |
| 1321380-5980174 |
77 | if (lcurrent == 0 || NOTOPT(lcurrent->word->word)) {TRUE | evaluated 1521 times by 1 test | FALSE | evaluated 5978653 times by 1 test |
TRUE | evaluated 4633464 times by 1 test | FALSE | evaluated 1345189 times by 1 test |
TRUE | evaluated 1382788 times by 1 test | FALSE | evaluated 3250676 times by 1 test |
TRUE | evaluated 3250305 times by 1 test | FALSE | evaluated 371 times by 1 test |
TRUE | evaluated 30 times by 1 test | FALSE | evaluated 1345530 times by 1 test |
| 30-5978653 |
78 | lhead = (WORD_LIST *)NULL; | - |
79 | loptend = lcurrent; | - |
80 | return(-1);executed 4634644 times by 1 test: return(-1); | 4634644 |
81 | } else if (ISHELP (lcurrent->word->word)) { never executed: __result = (((const unsigned char *) (const char *) ( (lcurrent->word->word) ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( "--help" ))[3] - __s2[3]); never executed: end of block never executed: end of block TRUE | evaluated 1345159 times by 1 test | FALSE | evaluated 371 times by 1 test |
TRUE | never evaluated | FALSE | evaluated 1345159 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-1345159 |
82 | lhead = (WORD_LIST *)NULL; | - |
83 | loptend = lcurrent; | - |
84 | return (GETOPT_HELP); never executed: return (-99); | 0 |
85 | } else if (lcurrent->word->word[0] == '-' &&TRUE | evaluated 1345159 times by 1 test | FALSE | evaluated 371 times by 1 test |
| 371-1345159 |
86 | lcurrent->word->word[1] == '-' &&TRUE | evaluated 10441 times by 1 test | FALSE | evaluated 1334718 times by 1 test |
| 10441-1334718 |
87 | lcurrent->word->word[2] == 0) {TRUE | evaluated 10441 times by 1 test | FALSE | never evaluated |
| 0-10441 |
88 | lhead = (WORD_LIST *)NULL; | - |
89 | loptend = lcurrent->next; | - |
90 | return(-1);executed 10441 times by 1 test: return(-1); | 10441 |
91 | } | - |
92 | errstr[0] = list_opttype = lcurrent->word->word[0]; | - |
93 | }executed 1335089 times by 1 test: end of block | 1335089 |
94 | | - |
95 | list_optopt = c = lcurrent->word->word[sp]; | - |
96 | | - |
97 | if (c == ':' || (cp = strchr(opts, c)) == NULL) {TRUE | never evaluated | FALSE | evaluated 2656469 times by 1 test |
TRUE | evaluated 57 times by 1 test | FALSE | evaluated 2656412 times by 1 test |
TRUE | never evaluated | FALSE | evaluated 2656469 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-2656469 |
98 | errstr[1] = c; | - |
99 | sh_invalidopt (errstr); | - |
100 | if (lcurrent->word->word[++sp] == '\0') {TRUE | evaluated 57 times by 1 test | FALSE | never evaluated |
| 0-57 |
101 | lcurrent = lcurrent->next; | - |
102 | sp = 1; | - |
103 | }executed 57 times by 1 test: end of block | 57 |
104 | list_optarg = NULL; | - |
105 | if (lcurrent)TRUE | evaluated 35 times by 1 test | FALSE | evaluated 22 times by 1 test |
| 22-35 |
106 | loptend = lcurrent->next;executed 35 times by 1 test: loptend = lcurrent->next; | 35 |
107 | return('?');executed 57 times by 1 test: return('?'); | 57 |
108 | } | - |
109 | | - |
110 | if (*++cp == ':' || *cp == ';') {TRUE | evaluated 1324560 times by 1 test | FALSE | evaluated 1331852 times by 1 test |
TRUE | evaluated 1114 times by 1 test | FALSE | evaluated 1330738 times by 1 test |
| 1114-1331852 |
111 | | - |
112 | | - |
113 | | - |
114 | if (lcurrent->word->word[sp+1]) {TRUE | evaluated 1321209 times by 1 test | FALSE | evaluated 4465 times by 1 test |
| 4465-1321209 |
115 | list_optarg = lcurrent->word->word + sp + 1; | - |
116 | lcurrent = lcurrent->next; | - |
117 | | - |
118 | | - |
119 | #if 0 | - |
120 | } else if (lcurrent->next && (*cp == ':' || lcurrent->next->word->word[0] != '-')) { | - |
121 | #else | - |
122 | } else if (lcurrent->next && (*cp == ':' || NOTOPT(lcurrent->next->word->word))) {executed 1321209 times by 1 test: end of block TRUE | evaluated 4461 times by 1 test | FALSE | evaluated 4 times by 1 test |
TRUE | evaluated 3351 times by 1 test | FALSE | evaluated 1110 times by 1 test |
TRUE | evaluated 1110 times by 1 test | FALSE | never evaluated |
TRUE | evaluated 241 times by 1 test | FALSE | evaluated 869 times by 1 test |
TRUE | evaluated 869 times by 1 test | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-1321209 |
123 | #endif | - |
124 | lcurrent = lcurrent->next; | - |
125 | list_optarg = lcurrent->word->word; | - |
126 | lcurrent = lcurrent->next; | - |
127 | } else if (*cp == ';') {executed 4461 times by 1 test: end of block TRUE | evaluated 4 times by 1 test | FALSE | never evaluated |
| 0-4461 |
128 | list_optarg = (char *)NULL; | - |
129 | lcurrent = lcurrent->next; | - |
130 | } else { executed 4 times by 1 test: end of block | 4 |
131 | errstr[1] = c; | - |
132 | sh_needarg (errstr); | - |
133 | sp = 1; | - |
134 | list_optarg = (char *)NULL; | - |
135 | return('?'); never executed: return('?'); | 0 |
136 | } | - |
137 | sp = 1; | - |
138 | } else if (*cp == '#') {executed 1325674 times by 1 test: end of block TRUE | never evaluated | FALSE | evaluated 1330738 times by 1 test |
| 0-1330738 |
139 | | - |
140 | if (lcurrent->word->word[sp+1]) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
141 | if (DIGIT(lcurrent->word->word[sp+1])) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
142 | list_optarg = lcurrent->word->word + sp + 1; | - |
143 | lcurrent = lcurrent->next; | - |
144 | } else never executed: end of block | 0 |
145 | list_optarg = (char *)NULL; never executed: list_optarg = (char *) ((void *)0) ; | 0 |
146 | } else { | - |
147 | if (lcurrent->next && legal_number(lcurrent->next->word->word, (intmax_t *)0)) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
148 | lcurrent = lcurrent->next; | - |
149 | list_optarg = lcurrent->word->word; | - |
150 | lcurrent = lcurrent->next; | - |
151 | } else { never executed: end of block | 0 |
152 | errstr[1] = c; | - |
153 | sh_neednumarg (errstr); | - |
154 | sp = 1; | - |
155 | list_optarg = (char *)NULL; | - |
156 | return ('?'); never executed: return ('?'); | 0 |
157 | } | - |
158 | } | - |
159 | | - |
160 | } else { | - |
161 | | - |
162 | if (lcurrent->word->word[++sp] == '\0') {TRUE | evaluated 9358 times by 1 test | FALSE | evaluated 1321380 times by 1 test |
| 9358-1321380 |
163 | sp = 1; | - |
164 | lcurrent = lcurrent->next; | - |
165 | }executed 9358 times by 1 test: end of block | 9358 |
166 | list_optarg = (char *)NULL; | - |
167 | }executed 1330738 times by 1 test: end of block | 1330738 |
168 | | - |
169 | return(c);executed 2656412 times by 1 test: return(c); | 2656412 |
170 | } | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | void | - |
177 | reset_internal_getopt () | - |
178 | { | - |
179 | lhead = lcurrent = loptend = (WORD_LIST *)NULL; | - |
180 | sp = 1; | - |
181 | }executed 4645769 times by 1 test: end of block | 4645769 |
| | |