summaryrefslogtreecommitdiffstats
path: root/common/hush.c
diff options
context:
space:
mode:
authorSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-09-25 13:42:33 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-09-25 13:42:33 +0200
commit603ccc23789cb53961306a4021fbcc55bb86e7eb (patch)
tree07b84aac5b6475c12cefd927290fa331b957a498 /common/hush.c
parent913691eccd13c1509470eb8b059aa0beecc6d8d8 (diff)
downloadbarebox-603ccc23789cb53961306a4021fbcc55bb86e7eb.tar.gz
barebox-603ccc23789cb53961306a4021fbcc55bb86e7eb.tar.xz
add $# handling for hush
Diffstat (limited to 'common/hush.c')
-rw-r--r--common/hush.c28
1 files changed, 28 insertions, 0 deletions
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++;