1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-26 04:30:27 +01:00

11467: [#<base>] syntax for output base

zsh-users/3071: compdump tweak to avoid // in path
This commit is contained in:
Peter Stephenson 2000-05-19 18:22:50 +00:00
parent e20600c8a4
commit 8d17d2f02d
6 changed files with 62 additions and 11 deletions

View file

@ -186,6 +186,8 @@ static int type[TOKCOUNT] =
/* 50 */ LR|OP_OPF, RL|OP_E2, LR|OP_OPF
};
/**/
int outputradix;
/**/
static int
@ -340,12 +342,22 @@ zzlex(void)
return EOI;
case '[':
{
int base = zstrtol(ptr, &ptr, 10);
int base, setradix = 0;
if (*ptr == '#') {
ptr++;
setradix = 1;
}
base = zstrtol(ptr, &ptr, 10);
if (*ptr == ']')
ptr++;
yyval.u.l = zstrtol(ptr, &ptr, lastbase = base);
return NUM;
if (setradix)
outputradix = base;
else {
yyval.u.l = zstrtol(ptr, &ptr, lastbase = base);
return NUM;
}
break;
}
case ' ':
case '\t':
@ -934,6 +946,7 @@ matheval(char *s)
char *junk;
mnumber x;
int xmtok = mtok;
outputradix = 0;
if (!*s) {
x.type = MN_INTEGER;

View file

@ -1577,9 +1577,11 @@ setnumvalue(Value v, mnumber val)
switch (PM_TYPE(v->pm->flags)) {
case PM_SCALAR:
case PM_ARRAY:
if (val.type & MN_INTEGER)
convbase(p = buf, val.u.l, 0);
else
if ((val.type & MN_INTEGER) || outputradix) {
if (!(val.type & MN_INTEGER))
val.u.l = (zlong) val.u.d;
convbase(p = buf, val.u.l, outputradix);
} else
p = convfloat(val.u.d, 0, 0, NULL);
setstrvalue(v, ztrdup(p));
break;
@ -1909,9 +1911,10 @@ setnparam(char *s, mnumber val)
pm = createparam(t, (val.type & MN_INTEGER) ? PM_INTEGER
: PM_FFLOAT);
DPUTS(!pm, "BUG: parameter not created");
if (val.type & MN_INTEGER)
if (val.type & MN_INTEGER) {
pm->ct = outputradix;
pm->u.val = val.u.l;
else
} else
pm->u.dval = val.u.d;
return pm;
}

View file

@ -1964,10 +1964,13 @@ arithsubst(char *a, char **bptr, char *rest)
singsub(&a);
v = matheval(a);
if (v.type & MN_FLOAT)
if ((v.type & MN_FLOAT) && !outputradix)
b = convfloat(v.u.d, 0, 0, NULL);
else
convbase(buf, v.u.l, 0);
else {
if (v.type & MN_FLOAT)
v.u.l = (zlong) v.u.d;
convbase(buf, v.u.l, outputradix);
}
t = *bptr = (char *) hcalloc(strlen(*bptr) + strlen(b) +
strlen(rest) + 1);
t--;