0001-sh-1-Expand-LINENO-to-the-current-line-number.patch

Beket, 07/21/2009 12:03 PM

Download (4.31 KB)

View differences:

bin/sh/expand.c
636 636
		special = 1;
637 637
	p = strchr(p, '=') + 1;
638 638
again: /* jump here after setting a variable with ${var=text} */
639
	if (special) {
639
	if (varflags & VSLINENO) {
640
		set = 1;
641
		special = 0;
642
		val = var;
643
		p[-1] = '\0';	/* temporarily overwrite '=' to have \0
644
				   terminated string */
645
	} else if (special) {
640 646
		set = varisset(var, varflags & VSNUL);
641 647
		val = NULL;
642 648
	} else {
......
766 772
	default:
767 773
		abort();
768 774
	}
775
	p[-1] = '=';	/* recover overwritten '=' */
769 776

  
770 777
	if (subtype != VSNORMAL) {	/* skip to end of alternative */
771 778
		int nesting = 1;
bin/sh/parser.c
99 99
STATIC struct heredoc *heredoc;
100 100
STATIC int quoteflag;		/* set if (part of) last token was quoted */
101 101
STATIC int startlinno;		/* line # where last token started */
102
STATIC int funclinno;		/* line # where the current function started */
102 103

  
103 104
/* XXX When 'noaliases' is set to one, no alias expansion takes place. */
104 105
static int noaliases = 0;
......
566 567
			/* We have a function */
567 568
			if (readtoken() != TRP)
568 569
				synexpect(TRP);
570
			funclinno = plinno;
569 571
#ifdef notdef
570 572
			if (! goodname(n->narg.text))
571 573
				synerror("Bad function name");
572 574
#endif
573 575
			n->type = NDEFUN;
574 576
			n->narg.next = command();
577
			funclinno = 0;
575 578
			return n;
576 579
		} else {
577 580
			tokpushback++;
......
1159 1162
 */
1160 1163

  
1161 1164
parsesub: {
1165
	char buf[10];
1162 1166
	int subtype;
1163 1167
	int typeloc;
1164 1168
	int flags;
1165 1169
	char *p;
1166 1170
	static const char types[] = "}-+?=";
1167
       int bracketed_name = 0; /* used to handle ${[0-9]*} variables */
1171
	int bracketed_name = 0; /* used to handle ${[0-9]*} variables */
1172
	int i;
1173
	int linno;
1168 1174

  
1169 1175
	c = pgetc();
1170 1176
	if (c != '(' && c != '{' && (is_eof(c) || !is_name(c)) &&
......
1183 1189
		typeloc = out - stackblock();
1184 1190
		USTPUTC(VSNORMAL, out);
1185 1191
		subtype = VSNORMAL;
1192
		flags = 0;
1186 1193
		if (c == '{') {
1187 1194
			bracketed_name = 1;
1188 1195
			c = pgetc();
......
1196 1203
				subtype = 0;
1197 1204
		}
1198 1205
		if (!is_eof(c) && is_name(c)) {
1206
			p = out;
1199 1207
			do {
1200 1208
				STPUTC(c, out);
1201 1209
				c = pgetc();
1202 1210
			} while (!is_eof(c) && is_in_name(c));
1211
			if (out - p == 6 && strncmp(p, "LINENO", 6) == 0) {
1212
				/* Replace the variable name with the
1213
				 * current line number. */
1214
				linno = plinno;
1215
				if (funclinno != 0)
1216
					linno -= funclinno - 1;
1217
				snprintf(buf, sizeof(buf), "%d", linno);
1218
				STADJUST(-6, out);
1219
				for (i = 0; buf[i] != '\0'; i++)
1220
					STPUTC(buf[i], out);
1221
				flags |= VSLINENO;
1222
			}
1203 1223
		} else if (is_digit(c)) {
1204 1224
			if (bracketed_name) {
1205 1225
				do {
......
1222 1242
				c = pgetc();
1223 1243
			}
1224 1244
		}
1225
		flags = 0;
1226 1245
		if (subtype == 0) {
1227 1246
			switch (c) {
1228 1247
			case ':':
1229
				flags = VSNUL;
1248
				flags |= VSNUL;
1230 1249
				c = pgetc();
1231 1250
				/*FALLTHROUGH*/
1232 1251
			default:
bin/sh/parser.h
50 50
#define	CTLQUOTEMARK '\210'
51 51

  
52 52
/* variable substitution byte (follows CTLVAR) */
53
#define VSTYPE	0x0f		/* type of variable substitution */
54
#define VSNUL	0x10		/* colon--treat the empty string as unset */
55
#define VSQUOTE 0x80		/* inside double quotes--suppress splitting */
53
#define VSTYPE		0x0f	/* type of variable substitution */
54
#define VSNUL		0x10	/* colon--treat the empty string as unset */
55
#define VSLINENO	0x20	/* expansion of $LINENO, the line number \
56
				   follows immediately */
57
#define VSQUOTE		0x80	/* inside double quotes--suppress splitting */
56 58

  
57 59
/* values of VSTYPE field */
58 60
#define VSNORMAL	0x1		/* normal variable:  $var or ${var} */
59
-