src/frontend/variable.c, fix expansion of '$var' when $var is an empty list
test case: set foo = ( ) set foo = ( $foo baz bar ) echo $foo
This commit is contained in:
parent
bd441171a7
commit
33d33e9d50
|
|
@ -724,6 +724,7 @@ cp_variablesubst(wordlist *wlist)
|
|||
t = wl->wl_word;
|
||||
i = 0;
|
||||
while ((s = strchr(t, cp_dol)) != NULL) {
|
||||
char *s_dollar = s, *end;
|
||||
while (t < s)
|
||||
wbuf[i++] = *t++;
|
||||
wbuf[i] = '\0';
|
||||
|
|
@ -731,22 +732,17 @@ cp_variablesubst(wordlist *wlist)
|
|||
s = buf;
|
||||
/* Get s and t past the end of the var name. */
|
||||
{
|
||||
char *end = span_var_expr(t);
|
||||
end = span_var_expr(t);
|
||||
while (t < end)
|
||||
*s++ = *t++;
|
||||
}
|
||||
*s = '\0';
|
||||
nwl = vareval(buf);
|
||||
if (i) {
|
||||
(void) strcpy(buf, wbuf);
|
||||
if (nwl) {
|
||||
(void) strcpy(buf, wbuf);
|
||||
(void) strcat(buf, nwl->wl_word);
|
||||
tfree(nwl->wl_word);
|
||||
nwl->wl_word = copy(buf);
|
||||
} else {
|
||||
nwl = wl_cons(copy(buf), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
(void) strcpy(tbuf, t); /* Save t*/
|
||||
if ((wl = wl_splice(wl, nwl)) == NULL) {/* this frees wl */
|
||||
|
|
@ -756,6 +752,7 @@ cp_variablesubst(wordlist *wlist)
|
|||
/* Go back to beginning of wlist */
|
||||
for (wlist = wl; wlist->wl_prev; wlist = wlist->wl_prev)
|
||||
;
|
||||
i = strlen(wl->wl_word);
|
||||
/* limit copying to buffer of size BSIZE_SP */
|
||||
(void) strncpy(buf, wl->wl_word, BSIZE_SP - 1 - strlen(tbuf));
|
||||
i = (int) strlen(buf);
|
||||
|
|
@ -765,6 +762,21 @@ cp_variablesubst(wordlist *wlist)
|
|||
|
||||
tfree(wl->wl_word);
|
||||
wl->wl_word = copy(buf);
|
||||
} else {
|
||||
for (s = s_dollar; *end; )
|
||||
*s++ = *end++;
|
||||
*s = '\0';
|
||||
if (s == wl->wl_word) {
|
||||
wordlist *next = wl->wl_next;
|
||||
if (wlist == wl)
|
||||
wlist = next;
|
||||
wl_delete_slice(wl, next);
|
||||
if (!next)
|
||||
return wlist;
|
||||
wl = next;
|
||||
}
|
||||
}
|
||||
|
||||
t = &wl->wl_word[i];
|
||||
s = wl->wl_word;
|
||||
for (i = 0; s < t; s++)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
|
||||
TESTS = bugs-1.cir
|
||||
TESTS = bugs-1.cir dollar-1.cir
|
||||
|
||||
TESTS_ENVIRONMENT = ngspice_vpath=$(srcdir) $(SHELL) $(top_srcdir)/tests/bin/check.sh $(top_builddir)/src/ngspice
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
test $var expansion
|
||||
|
||||
v1 1 0 dc = 0
|
||||
|
||||
.control
|
||||
|
||||
set foo = ""
|
||||
echo "TEST:" ">{$foo}< should be ><"
|
||||
|
||||
set foo = ( 1 2 3 )
|
||||
set bar = 2
|
||||
echo "TEST:" ">$foo[0]< should be >1<"
|
||||
echo "TEST:" ">$foo[$bar]< should be >2<"
|
||||
|
||||
set foo = ( $foo baz bar )
|
||||
echo "TEST:" $foo
|
||||
echo "TEST:" "should be >1 2 3 baz bar<"
|
||||
echo "TEST:" ">$foo[0]< should be >1<"
|
||||
|
||||
set aux = ( )
|
||||
echo "TEST:" $aux "end"
|
||||
|
||||
set foo = ( $aux mi au )
|
||||
set bar = ( mi $aux au )
|
||||
set baz = ( mi au $aux )
|
||||
|
||||
echo "TEST:" $foo
|
||||
echo "TEST:" "should be >mi au<"
|
||||
echo "TEST:" ">$foo[0]< should be >mi<"
|
||||
|
||||
echo "TEST:" $bar
|
||||
echo "TEST:" "should be >mi au<"
|
||||
echo "TEST:" ">$bar[0]< should be >mi<"
|
||||
|
||||
echo "TEST:" $baz
|
||||
echo "TEST:" "should be >mi au<"
|
||||
echo "TEST:" ">$baz[0]< should be >mi<"
|
||||
|
||||
quit 0
|
||||
|
||||
.endc
|
||||
|
||||
.end
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
Circuit: test for regression of already fixed bugs
|
||||
|
||||
TEST: >< should be ><
|
||||
TEST: >1< should be >1<
|
||||
TEST: >2< should be >2<
|
||||
TEST: 1 2 3 baz bar
|
||||
TEST: should be >1 2 3 baz bar<
|
||||
TEST: >1< should be >1<
|
||||
TEST: end
|
||||
TEST: mi au
|
||||
TEST: should be >mi au<
|
||||
TEST: >mi< should be >mi<
|
||||
TEST: mi au
|
||||
TEST: should be >mi au<
|
||||
TEST: >mi< should be >mi<
|
||||
TEST: mi au
|
||||
TEST: should be >mi au<
|
||||
TEST: >mi< should be >mi<
|
||||
|
||||
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
|
||||
|
||||
|
||||
No. of Data Rows : 1
|
||||
Loading…
Reference in New Issue