mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-27 11:52:03 +00:00
rc: add subscript sequences (Erik Quanstrom)
This commit is contained in:
parent
78a779a383
commit
94e1f2a438
2 changed files with 40 additions and 5 deletions
|
@ -208,6 +208,11 @@ If
|
||||||
is followed by a parenthesized list of subscripts, the
|
is followed by a parenthesized list of subscripts, the
|
||||||
value substituted is a list composed of the requested elements (origin 1).
|
value substituted is a list composed of the requested elements (origin 1).
|
||||||
The parenthesis must follow the variable name with no spaces.
|
The parenthesis must follow the variable name with no spaces.
|
||||||
|
Subscripts can also take the form
|
||||||
|
.IB m - n
|
||||||
|
or
|
||||||
|
.IB m -
|
||||||
|
to indicate a sequence of elements.
|
||||||
Assignments to variables are described below.
|
Assignments to variables are described below.
|
||||||
.HP
|
.HP
|
||||||
.BI $# argument
|
.BI $# argument
|
||||||
|
|
|
@ -685,22 +685,52 @@ Xqdol(void)
|
||||||
efree(s);
|
efree(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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*
|
word*
|
||||||
subwords(word *val, int len, word *sub, word *a)
|
subwords(word *val, int len, word *sub, word *a)
|
||||||
{
|
{
|
||||||
int n;
|
int n, m;
|
||||||
char *s;
|
char *s;
|
||||||
if(!sub)
|
if(!sub)
|
||||||
return a;
|
return a;
|
||||||
a = subwords(val, len, sub->next, a);
|
a = subwords(val, len, sub->next, a);
|
||||||
s = sub->word;
|
s = sub->word;
|
||||||
deglob(s);
|
deglob(s);
|
||||||
|
m = 0;
|
||||||
n = 0;
|
n = 0;
|
||||||
while('0'<=*s && *s<='9') n = n*10+ *s++ -'0';
|
while('0'<=*s && *s<='9')
|
||||||
if(n<1 || len<n)
|
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;
|
return a;
|
||||||
for(;n!=1;--n) val = val->next;
|
if(n+m>len)
|
||||||
return newword(val->word, a);
|
m = len-n;
|
||||||
|
while(--n > 0)
|
||||||
|
val = val->next;
|
||||||
|
return copynwords(val, a, m+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue