sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit c6cbb33ef02075c21b519bb59e1c69f74ff8470f
parent ec8218c93bb19777f212addf94544ac01c3012c2
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Thu, 11 Dec 2025 12:43:42 +0100

bc: Unify local() and param()

These functions only differentiate in a single letter, so it
was a good opportunity to merge them. Also, it was a good idea
to add the values in reverse order to make the output more
similar to other bc implementations.

Diffstat:
Mbc.y | 29++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/bc.y b/bc.y @@ -88,7 +88,7 @@ int cflag, dflag, lflag, sflag; %token SCALE %token IBASE %token OBASE -%token AUTO +%token AUTO PARAM %token PRINT %type <str> item statlst scolonlst @@ -381,7 +381,7 @@ macro(int op) } static char * -param(char *list, char *id) +decl(int type, char *list, char *id) { char *i1, *i2; @@ -389,23 +389,26 @@ param(char *list, char *id) i2 = estrdup(id); free(id); - unwind = code(unwind ? "L%ss.%s" : "L%ss.", i1, unwind); + if (!unwind) + unwind = estrdup(""); + if (!list) + list = estrdup(""); + + unwind = code("%sL%ss.", unwind, i1); - return code(list ? "S%s%s" : "S%s" , i2, list); + return code((type == AUTO) ? "0S%s%s" : "S%s%s", i2, list); } static char * -local(char *list, char *id) +param(char *list, char *id) { - char *i1, *i2; - - i1 = estrdup(id); - i2 = estrdup(id); - free(id); - - unwind = code(unwind ? "L%ss.%s" : "L%ss.", i1, unwind); + return decl(PARAM, list, id); +} - return code(list ? "0S%s%s" : "0S%s" , i2, list); +static char * +local(char *list, char *id) +{ + return decl(AUTO, list, id); } static char *