From 603ccc23789cb53961306a4021fbcc55bb86e7eb Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 25 Sep 2007 13:42:33 +0200 Subject: add $# handling for hush --- common/hush.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'common/hush.c') diff --git a/common/hush.c b/common/hush.c index ced60271cc..181491a238 100644 --- a/common/hush.c +++ b/common/hush.c @@ -328,6 +328,29 @@ static int b_addqchr(o_string *o, int ch, int quote) return b_addchr(o, ch); } +/* belongs in utility.c */ +char *simple_itoa(unsigned int i) +{ + /* 21 digits plus null terminator, good for 64-bit or smaller ints */ + static char local[22]; + char *p = &local[21]; + *p-- = '\0'; + do { + *p-- = '0' + i % 10; + i /= 10; + } while (i > 0); + return p + 1; +} + +static int b_adduint(o_string *o, unsigned int i) +{ + int r; + char *p = simple_itoa(i); + /* no escape checking necessary */ + do r=b_addchr(o, *p++); while (r==0 && *p); + return r; +} + static int static_get(struct in_str *i) { int ch=*i->p++; @@ -335,6 +358,7 @@ static int static_get(struct in_str *i) return ch; } + static int static_peek(struct in_str *i) { return *i->p; @@ -1078,6 +1102,10 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *i b_addchr(dest, SPECIAL_VAR_SYMBOL); advance = 1; break; + case '#': + b_adduint(dest,ctx->global_argc ? ctx->global_argc-1 : 0); + advance = 1; + break; case '{': b_addchr(dest, SPECIAL_VAR_SYMBOL); ctx->child->sp++; -- cgit v1.2.3