summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2000-05-19 18:22:50 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2000-05-19 18:22:50 +0000
commit8d17d2f02dfa2b0bb4c19efcf52854fbb7fa19e5 (patch)
tree65bf9ac762900c25f7aa4b7ea88123bd6517254d
parente20600c8a404d35bd4b4c02976ce08f5b166f415 (diff)
downloadzsh-8d17d2f02dfa2b0bb4c19efcf52854fbb7fa19e5.tar.gz
zsh-8d17d2f02dfa2b0bb4c19efcf52854fbb7fa19e5.zip
11467: [#<base>] syntax for output base
zsh-users/3071: compdump tweak to avoid // in path
-rw-r--r--ChangeLog9
-rw-r--r--Completion/Core/compdump1
-rw-r--r--Doc/Zsh/arith.yo22
-rw-r--r--Src/math.c19
-rw-r--r--Src/params.c13
-rw-r--r--Src/subst.c9
6 files changed, 62 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 38a030659..c2fb96411 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/Completion/Core/compdump b/Completion/Core/compdump
index 3cccbd06e..92e47c19f 100644
--- a/Completion/Core/compdump
+++ b/Completion/Core/compdump
@@ -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) )
diff --git a/Doc/Zsh/arith.yo b/Doc/Zsh/arith.yo
index e47c0284a..095756667 100644
--- a/Doc/Zsh/arith.yo
+++ b/Doc/Zsh/arith.yo
@@ -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
diff --git a/Src/math.c b/Src/math.c
index a7fcd0978..38466ed8e 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -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;
diff --git a/Src/params.c b/Src/params.c
index 6ccfd9307..8c39ec2ac 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -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;
}
diff --git a/Src/subst.c b/Src/subst.c
index 94a1222d8..beb99b5ee 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -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--;