9
0
Fork 0

add $# handling for hush

This commit is contained in:
Sascha Hauer 2007-09-25 13:42:33 +02:00
parent 913691eccd
commit 603ccc2378
1 changed files with 28 additions and 0 deletions

View File

@ -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++;