From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <38d3e7c62047cfab2336cdd89e451486@quanstro.net> To: 9fans@9fans.net From: erik quanstrom Date: Tue, 1 Jul 2008 21:00:06 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: [9fans] forgotten rc hack Topicbox-Message-UUID: d5691818-ead3-11e9-9d60-3106f5b1d025 some time ago, i had a want for es-style subscripting like ; x=(1 2 3) ; echo $x(1-2) 1 2 ; echo $x(2-) 2 3 ; x = $x(2-) # shift x i'd forgotten all about it. the following replacement for exec.c:subwords() is all that you need to enable this. - erik ---- word* copynwords(word *a, word *tail, int n) { word *v = 0, **end; for(end=&v;a && n-- != 0;a = a->next,end=&(*end)->next) *end = newword(a->word, 0); *end = tail; return v; } word* subwords(word *val, int len, word *sub, word *a) { int n, m; char *s; if(!sub) return a; s = sub->word; deglob(s); a = subwords(val, len, sub->next, a); n = 0; m = 0; while('0'<=*s && *s<='9') n = n*10+ *s++ -'0'; if(*s++ == '-'){ if(*s) while('0'<=*s && *s<='9') m = m*10+ *s++ -'0'; else m = len; m -= n; } if(n<1 || lennext; return copynwords(val, a, m+1); }