View | Details | Raw Unified | Return to bug 220587 | Differences between
and this patch

Collapse All | Expand All

(-)b/bin/sh/options.c (-6 / +24 lines)
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
(-)b/bin/sh/tests/invocation/Makefile (+6 lines)
Lines 10-18 ATF_TESTS_SH= functional_test Link Here
10
${PACKAGE}FILES+=	sh-ac1.0
10
${PACKAGE}FILES+=	sh-ac1.0
11
${PACKAGE}FILES+=	sh-c-end-marker1.0
11
${PACKAGE}FILES+=	sh-c-end-marker1.0
12
${PACKAGE}FILES+=	sh-c-end-marker2.0
12
${PACKAGE}FILES+=	sh-c-end-marker2.0
13
${PACKAGE}FILES+=	sh-c-end-marker3.0
14
${PACKAGE}FILES+=	sh-c-end-marker4.0
13
${PACKAGE}FILES+=	sh-c-missing1.0
15
${PACKAGE}FILES+=	sh-c-missing1.0
14
${PACKAGE}FILES+=	sh-c1.0
16
${PACKAGE}FILES+=	sh-c1.0
17
${PACKAGE}FILES+=	sh-c2.0
15
${PACKAGE}FILES+=	sh-ca1.0
18
${PACKAGE}FILES+=	sh-ca1.0
19
${PACKAGE}FILES+=	sh-ca2.0
20
${PACKAGE}FILES+=	sh-f-c-a1.0
16
${PACKAGE}FILES+=	sh-fca1.0
21
${PACKAGE}FILES+=	sh-fca1.0
22
${PACKAGE}FILES+=	sh-fca2.0
17
23
18
.include <bsd.test.mk>
24
.include <bsd.test.mk>
(-)b/bin/sh/tests/invocation/sh-ac2.0 (+8 lines)
Added Link Here
1
# $FreeBSD$
2
# Test that option processing ends at command_string
3
# and connected options before c are processed
4
5
case `${SH} -ac 'echo $-:$0:$@' -foo -bar` in
6
*a*:-foo:-bar) true ;;
7
*) false ;;
8
esac
(-)b/bin/sh/tests/invocation/sh-c-end-marker3.0 (+6 lines)
Added Link Here
1
# $FreeBSD$
2
3
case `echo echo bad | ${SH} -c - 'echo hi' 2>/dev/null` in
4
hi) true ;;
5
*) false ;;
6
esac
(-)b/bin/sh/tests/invocation/sh-c-end-marker4.0 (+6 lines)
Added Link Here
1
# $FreeBSD$
2
3
case `echo echo bad | ${SH} -c -- 'echo hi' 2>/dev/null` in
4
hi) true ;;
5
*) false ;;
6
esac
(-)b/bin/sh/tests/invocation/sh-c2.0 (+8 lines)
Added Link Here
1
# $FreeBSD$
2
# Test that -c executes command_string with the given name and arg
3
# and does not process the name as an option
4
5
case `${SH} -c 'echo $-:$0:$@' -a foo` in
6
*:-a:foo) true ;;
7
*) false ;;
8
esac
(-)b/bin/sh/tests/invocation/sh-ca2.0 (+8 lines)
Added Link Here
1
# $FreeBSD$
2
# Test that option processing ends at command_string
3
# and connected options after c are processed
4
5
case `${SH} -ca 'echo $-:$0:$@' -foo -bar` in
6
*a*:-foo:-bar) true ;;
7
*) false ;;
8
esac
(-)b/bin/sh/tests/invocation/sh-f-c-a1.0 (+8 lines)
Added Link Here
1
# $FreeBSD$
2
# Test that option processing ends at command_string
3
# and separated options before and after c are processed
4
5
case `${SH} -f -c -a 'echo $-:$-:$0:$@' -foo -bar` in
6
*f*:*a*:-foo:-bar) true ;;
7
*) false ;;
8
esac
(-)b/bin/sh/tests/invocation/sh-fca2.0 (+8 lines)
Added Link Here
1
# $FreeBSD$
2
# Test that option processing ends at command_string
3
# and connected options before and after c are processed
4
5
case `${SH} -fca 'echo $-:$-:$0:$@' -foo -bar` in
6
*f*:*a*:-foo:-bar) true ;;
7
*) false ;;
8
esac

Return to bug 220587