9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: [9fans] forgotten rc hack
Date: Tue,  1 Jul 2008 21:00:06 -0400	[thread overview]
Message-ID: <38d3e7c62047cfab2336cdd89e451486@quanstro.net> (raw)

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 || len<n)
		return a;
	while(--n) val = val->next;
	return copynwords(val, a, m+1);
}




                 reply	other threads:[~2008-07-02  1:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38d3e7c62047cfab2336cdd89e451486@quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).