aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/rc
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2008-07-20 04:15:41 -0400
committerRuss Cox <rsc@swtch.com>2008-07-20 04:15:41 -0400
commit94e1f2a4388f674331b2a2f988fb815133d2ab6b (patch)
tree29e64248846fdaf194cd98b3fef90bd8ef86c1a8 /src/cmd/rc
parent78a779a3834cf39d7c0bcd93a15824b29df947a3 (diff)
downloadplan9port-94e1f2a4388f674331b2a2f988fb815133d2ab6b.tar.gz
plan9port-94e1f2a4388f674331b2a2f988fb815133d2ab6b.tar.bz2
plan9port-94e1f2a4388f674331b2a2f988fb815133d2ab6b.zip
rc: add subscript sequences (Erik Quanstrom)
Diffstat (limited to 'src/cmd/rc')
-rw-r--r--src/cmd/rc/exec.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/cmd/rc/exec.c b/src/cmd/rc/exec.c
index c54c0d89..ebb46b0d 100644
--- a/src/cmd/rc/exec.c
+++ b/src/cmd/rc/exec.c
@@ -686,21 +686,51 @@ Xqdol(void)
}
word*
+copynwords(word *a, word *tail, int n)
+{
+ word *v, **end;
+
+ v = 0;
+ end = &v;
+ while(n-- > 0){
+ *end = newword(a->word, 0);
+ end = &(*end)->next;
+ a = a->next;
+ }
+ *end = tail;
+ return v;
+}
+
+word*
subwords(word *val, int len, word *sub, word *a)
{
- int n;
+ int n, m;
char *s;
if(!sub)
return a;
a = subwords(val, len, sub->next, a);
s = sub->word;
deglob(s);
+ m = 0;
n = 0;
- while('0'<=*s && *s<='9') n = n*10+ *s++ -'0';
- if(n<1 || len<n)
+ while('0'<=*s && *s<='9')
+ n = n*10+ *s++ -'0';
+ if(*s == '-'){
+ if(*++s == 0)
+ m = len - n;
+ else{
+ while('0'<=*s && *s<='9')
+ m = m*10+ *s++ -'0';
+ m -= n;
+ }
+ }
+ if(n<1 || n>len || m<0)
return a;
- for(;n!=1;--n) val = val->next;
- return newword(val->word, a);
+ if(n+m>len)
+ m = len-n;
+ while(--n > 0)
+ val = val->next;
+ return copynwords(val, a, m+1);
}
void