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

Collapse All | Expand All

(-)eval.c (+2 lines)
Lines 841-846 Link Here
841
	const char *path = pathval();
841
	const char *path = pathval();
842
	int i;
842
	int i;
843
843
844
	setlinno(cmd->ncmd.linno);
845
844
	/* First expand the arguments. */
846
	/* First expand the arguments. */
845
	TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags));
847
	TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags));
846
	emptyarglist(&arglist);
848
	emptyarglist(&arglist);
(-)expand.c (-15 / +3 lines)
Lines 681-691 Link Here
681
	if (! is_name(*p))
681
	if (! is_name(*p))
682
		special = 1;
682
		special = 1;
683
	p = strchr(p, '=') + 1;
683
	p = strchr(p, '=') + 1;
684
	if (varflags & VSLINENO) {
684
685
		set = 1;
685
	if (special) {
686
		special = 1;
687
		val = NULL;
688
	} else if (special) {
689
		set = varisset(var, varflags & VSNUL);
686
		set = varisset(var, varflags & VSNUL);
690
		val = NULL;
687
		val = NULL;
691
	} else {
688
	} else {
Lines 713-728 Link Here
713
	if (set && subtype != VSPLUS) {
710
	if (set && subtype != VSPLUS) {
714
		/* insert the value of the variable */
711
		/* insert the value of the variable */
715
		if (special) {
712
		if (special) {
716
			if (varflags & VSLINENO) {
713
			varvalue(var, varflags & VSQUOTE, subtype, flag, dst);
717
				if (p - var > (ptrdiff_t)sizeof(buf))
718
					abort();
719
				memcpy(buf, var, p - var - 1);
720
				buf[p - var - 1] = '\0';
721
				strtodest(buf, flag, subtype,
722
				    varflags & VSQUOTE, dst);
723
			} else
724
				varvalue(var, varflags & VSQUOTE, subtype, flag,
725
				    dst);
726
			if (subtype == VSLENGTH) {
714
			if (subtype == VSLENGTH) {
727
				varlenb = expdest - stackblock() - startloc;
715
				varlenb = expdest - stackblock() - startloc;
728
				varlen = varlenb;
716
				varlen = varlenb;
(-)nodetypes (+1 lines)
Lines 58-63 Link Here
58
	type	  int
58
	type	  int
59
	args	  nodeptr		# the arguments
59
	args	  nodeptr		# the arguments
60
	redirect  nodeptr		# list of file redirections
60
	redirect  nodeptr		# list of file redirections
61
	linno     int           # value for LINENO
61
62
62
NPIPE npipe			# a pipeline
63
NPIPE npipe			# a pipeline
63
	type	  int
64
	type	  int
(-)parser.c (-16 / +6 lines)
Lines 694-699 Link Here
694
	n->type = NCMD;
694
	n->type = NCMD;
695
	n->ncmd.args = args;
695
	n->ncmd.args = args;
696
	n->ncmd.redirect = redir;
696
	n->ncmd.redirect = redir;
697
	if (funclinno)
698
		n->ncmd.linno = plinno - funclinno - 1;
699
	else if (plinno > 1)
700
		n->ncmd.linno = plinno - 1;
701
	else
702
		n->ncmd.linno = 1;
697
	return n;
703
	return n;
698
}
704
}
699
705
Lines 1622-1628 Link Here
1622
	int flags;
1628
	int flags;
1623
	char *p;
1629
	char *p;
1624
	static const char types[] = "}-+?=";
1630
	static const char types[] = "}-+?=";
1625
	int linno;
1626
	int length;
1631
	int length;
1627
	int c1;
1632
	int c1;
1628
1633
Lines 1656-1676 Link Here
1656
				c = pgetc_linecont();
1661
				c = pgetc_linecont();
1657
				length++;
1662
				length++;
1658
			} while (!is_eof(c) && is_in_name(c));
1663
			} while (!is_eof(c) && is_in_name(c));
1659
			if (length == 6 &&
1660
			    strncmp(out - length, "LINENO", length) == 0) {
1661
				/* Replace the variable name with the
1662
				 * current line number. */
1663
				STADJUST(-6, out);
1664
				CHECKSTRSPACE(11, out);
1665
				linno = plinno;
1666
				if (funclinno != 0)
1667
					linno -= funclinno - 1;
1668
				length = snprintf(out, 11, "%d", linno);
1669
				if (length > 10)
1670
					length = 10;
1671
				out += length;
1672
				flags |= VSLINENO;
1673
			}
1674
		} else if (is_digit(c)) {
1664
		} else if (is_digit(c)) {
1675
			if (subtype != VSNORMAL) {
1665
			if (subtype != VSNORMAL) {
1676
				do {
1666
				do {
(-)parser.h (-2 lines)
Lines 50-57 Link Here
50
/* variable substitution byte (follows CTLVAR) */
50
/* variable substitution byte (follows CTLVAR) */
51
#define VSTYPE		0x0f	/* type of variable substitution */
51
#define VSTYPE		0x0f	/* type of variable substitution */
52
#define VSNUL		0x10	/* colon--treat the empty string as unset */
52
#define VSNUL		0x10	/* colon--treat the empty string as unset */
53
#define VSLINENO	0x20	/* expansion of $LINENO, the line number \
54
				   follows immediately */
55
#define VSQUOTE		0x80	/* inside double quotes--suppress splitting */
53
#define VSQUOTE		0x80	/* inside double quotes--suppress splitting */
56
54
57
/* values of VSTYPE field */
55
/* values of VSTYPE field */
(-)var.c (-25 / +22 lines)
Lines 83-89 Link Here
83
	void (*func)(const char *);
83
	void (*func)(const char *);
84
};
84
};
85
85
86
87
#ifndef NO_HISTORY
86
#ifndef NO_HISTORY
88
struct var vhistsize;
87
struct var vhistsize;
89
struct var vterm;
88
struct var vterm;
Lines 97-102 Link Here
97
struct var vps4;
96
struct var vps4;
98
static struct var voptind;
97
static struct var voptind;
99
struct var vdisvfork;
98
struct var vdisvfork;
99
static struct var vlinno;
100
#define LINNOBUFSIZ 64
101
static char vlinnobuf[LINNOBUFSIZ];
100
102
101
struct localvar *localvars;
103
struct localvar *localvars;
102
int forcelocal;
104
int forcelocal;
Lines 103-136 Link Here
103
105
104
static const struct varinit varinit[] = {
106
static const struct varinit varinit[] = {
105
#ifndef NO_HISTORY
107
#ifndef NO_HISTORY
106
	{ &vhistsize,	VUNSET,				"HISTSIZE=",
108
	{ &vhistsize, VUNSET, "HISTSIZE=", sethistsize },
107
	  sethistsize },
109
	{ &vterm, VUNSET, "TERM=", setterm },
108
#endif
110
#endif
109
	{ &vifs,	0,				"IFS= \t\n",
111
	{ &vifs, 0, "IFS= \t\n", NULL },
110
	  NULL },
112
	{ &vmail, VUNSET, "MAIL=", NULL },
111
	{ &vmail,	VUNSET,				"MAIL=",
113
	{ &vmpath, VUNSET, "MAILPATH=", NULL },
112
	  NULL },
114
	{ &vpath, 0, "PATH=" _PATH_DEFPATH, changepath },
113
	{ &vmpath,	VUNSET,				"MAILPATH=",
114
	  NULL },
115
	{ &vpath,	0,				"PATH=" _PATH_DEFPATH,
116
	  changepath },
117
	/*
115
	/*
118
	 * vps1 depends on uid
116
	 * vps1 depends on uid
119
	 */
117
	 */
120
	{ &vps2,	0,				"PS2=> ",
118
	{ &vps2, 0, "PS2=> ", NULL },
121
	  NULL },
119
	{ &vps4, 0, "PS4=+ ", NULL },
122
	{ &vps4,	0,				"PS4=+ ",
120
	{ &voptind, 0, "OPTIND=1", getoptsreset },
123
	  NULL },
121
	{ &vdisvfork, VUNSET, "SH_DISABLE_VFORK=", NULL },
124
#ifndef NO_HISTORY
122
	{ &vlinno, VREADONLY, vlinnobuf, NULL },
125
	{ &vterm,	VUNSET,				"TERM=",
123
	{ NULL, 0, NULL, NULL }
126
	  setterm },
127
#endif
128
	{ &voptind,	0,				"OPTIND=1",
129
	  getoptsreset },
130
	{ &vdisvfork,	VUNSET,				"SH_DISABLE_VFORK=",
131
	  NULL },
132
	{ NULL,	0,				NULL,
133
	  NULL }
134
};
124
};
135
125
136
static struct var *vartab[VTABSIZE];
126
static struct var *vartab[VTABSIZE];
Lines 164-169 Link Here
164
	struct var **vpp;
154
	struct var **vpp;
165
	char **envp;
155
	char **envp;
166
156
157
	setlinno(1);
158
167
	for (ip = varinit ; (vp = ip->var) != NULL ; ip++) {
159
	for (ip = varinit ; (vp = ip->var) != NULL ; ip++) {
168
		if (find_var(ip->text, &vpp, &vp->name_len) != NULL)
160
		if (find_var(ip->text, &vpp, &vp->name_len) != NULL)
169
			continue;
161
			continue;
Lines 418-423 Link Here
418
	INTON;
410
	INTON;
419
}
411
}
420
412
413
void
414
setlinno(int n)
415
{
416
	snprintf(vlinnobuf, LINNOBUFSIZ, "LINENO=%d", n);
417
}
421
418
422
419
423
/*
420
/*
(-)var.h (+1 lines)
Lines 130-132 Link Here
130
void poplocalvars(void);
130
void poplocalvars(void);
131
int unsetvar(const char *);
131
int unsetvar(const char *);
132
int setvarsafe(const char *, const char *, int);
132
int setvarsafe(const char *, const char *, int);
133
void setlinno(int n);

Return to bug 235589