1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-11-25 14:20:53 +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

@ -1,3 +1,12 @@
2000-05-19 Peter Stephenson <pws@cambridgesiliconradio.com>
* zsh-users/3071: Completion/Core/compdump: avoid HOME=/
causing zcompdump beginning with //, which confuses cygwin.
* 11467: Src/match.c, Src/params.c, Src/subst.c, Doc/Zsh/arith.yo:
[#<base>] in math mode specifies output base for printing and any
implicit type conversions.
2000-05-19 Oliver Kiddle <opk@zsh.org>
* 11470: Completion/User/_su: fix to use user's shell after -c

View file

@ -19,6 +19,7 @@ setopt extendedglob
typeset _d_file _d_f _d_bks _d_line _d_als
_d_file=${_comp_dumpfile-${0:h}/compinit.dump}.$HOST.$$
[[ $_d_file = //* ]] && _d_file=${_d_file[2,-1]}
typeset -U _d_files
_d_files=( ${^~fpath:/.}/^([^_]*|*~|*.zwc)(N:t) )

View file

@ -43,6 +43,28 @@ The var(base)tt(#) may also be omitted, in which case
base 10 is used. For backwards compatibility the form
`tt([)var(base)tt(])var(n)' is also accepted.
It is also possible to specify a base to be used for output in the form
`tt([#)var(base)tt(])', for example `tt([#16])'. This is used when
outputting arithmetical substitutions or when assigning to scalar
parameters, but an explicitly defined integer or floating point parameter
will not be affected. If an integer variable is implicitly defined by an
arithmetic expression, any base specified in this way will be set as the
variable's output arithmetic base as if the option `tt(-i) var(base)' to
the tt(typeset) builtin had been used. The expression has no precedence
and if it occurs more than once in a mathematical expression, the last
encountered is used. For clarity it is recommended that it appear at the
beginning of an expression. As an example:
example(typeset -i 16 y
print $(( [#8] x = 32, y = 32 ))
print $x $y)
outputs first `tt(8#40)', the rightmost value in the given output base, and
then `tt(8#40 16#20)', because tt(y) has been explicitly declared to
have output base 16, while tt(x) (assuming it does not already exist) is
implicitly typed by the arithmetic evaluation, where it acquires the output
base 8.
Floating point constants are recognized by the presence of a decimal point
or an exponent. The decimal point may be the first character of the
constant, but the exponent character tt(e) or tt(E) may not, as it will be

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