Lines 41-46
__FBSDID("$FreeBSD$");
Link Here
|
41 |
#include <signal.h> |
41 |
#include <signal.h> |
42 |
#include <unistd.h> |
42 |
#include <unistd.h> |
43 |
#include <stdlib.h> |
43 |
#include <stdlib.h> |
|
|
44 |
#include <stdbool.h> |
44 |
|
45 |
|
45 |
#include "shell.h" |
46 |
#include "shell.h" |
46 |
#define DEFINE_OPTIONS |
47 |
#define DEFINE_OPTIONS |
Lines 148-157
optschanged(void)
Link Here
|
148 |
static void |
149 |
static void |
149 |
options(int cmdline) |
150 |
options(int cmdline) |
150 |
{ |
151 |
{ |
|
|
152 |
bool cflag; |
151 |
char *kp, *p; |
153 |
char *kp, *p; |
152 |
int val; |
154 |
int val; |
153 |
int c; |
155 |
int c; |
154 |
|
156 |
|
|
|
157 |
cflag = false; |
158 |
|
155 |
if (cmdline) |
159 |
if (cmdline) |
156 |
minusc = NULL; |
160 |
minusc = NULL; |
157 |
while ((p = *argptr) != NULL) { |
161 |
while ((p = *argptr) != NULL) { |
Lines 186-201
options(int cmdline)
Link Here
|
186 |
val = 0; |
190 |
val = 0; |
187 |
} else { |
191 |
} else { |
188 |
argptr--; |
192 |
argptr--; |
|
|
193 |
if (cflag) |
194 |
minusc = *argptr++; |
189 |
break; |
195 |
break; |
190 |
} |
196 |
} |
191 |
while ((c = *p++) != '\0') { |
197 |
while ((c = *p++) != '\0') { |
192 |
if (c == 'c' && cmdline) { |
198 |
if (c == 'c' && cmdline) { |
193 |
char *q; |
199 |
cflag = true; |
194 |
|
|
|
195 |
q = *argptr++; |
196 |
if (q == NULL || minusc != NULL) |
197 |
error("Bad -c option"); |
198 |
minusc = q; |
199 |
} else if (c == 'o') { |
200 |
} else if (c == 'o') { |
200 |
minus_o(*argptr, val); |
201 |
minus_o(*argptr, val); |
201 |
if (*argptr) |
202 |
if (*argptr) |
Lines 204-209
options(int cmdline)
Link Here
|
204 |
setoption(c, val); |
205 |
setoption(c, val); |
205 |
} |
206 |
} |
206 |
} |
207 |
} |
|
|
208 |
|
209 |
if (cflag && minusc == NULL) |
210 |
error("Bad -c option"); |
211 |
|
207 |
return; |
212 |
return; |
208 |
|
213 |
|
209 |
/* When processing `set', a single "-" means turn off -x and -v */ |
214 |
/* When processing `set', a single "-" means turn off -x and -v */ |
Lines 227-232
end_options2:
Link Here
|
227 |
} |
232 |
} |
228 |
|
233 |
|
229 |
/* |
234 |
/* |
|
|
235 |
* If "-c" has been encountered, the first argument following the |
236 |
* options is the command_string, and any remaining arguments are used |
237 |
* as special parameter 0 and positional parameters. |
238 |
*/ |
239 |
if (cflag) { |
240 |
minusc = *argptr++; |
241 |
if (minusc == NULL) |
242 |
error("Bad -c option"); |
243 |
return; |
244 |
} |
245 |
|
246 |
/* |
230 |
* At this point we are processing options given to 'sh' on a command |
247 |
* At this point we are processing options given to 'sh' on a command |
231 |
* line. If an end-of-options marker ("-" or "--") is followed by an |
248 |
* line. If an end-of-options marker ("-" or "--") is followed by an |
232 |
* arg of "#", then skip over all remaining arguments. Some scripting |
249 |
* arg of "#", then skip over all remaining arguments. Some scripting |
Lines 242-247
end_options2:
Link Here
|
242 |
/* We need to keep the final argument */ |
259 |
/* We need to keep the final argument */ |
243 |
argptr--; |
260 |
argptr--; |
244 |
} |
261 |
} |
|
|
262 |
|
245 |
} |
263 |
} |
246 |
|
264 |
|
247 |
static void |
265 |
static void |