summaryrefslogtreecommitdiff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/Modules/datetime.c2
-rw-r--r--Src/Zle/compctl.c9
-rw-r--r--Src/jobs.c23
-rw-r--r--Src/math.c2
-rw-r--r--Src/prompt.c30
-rw-r--r--Src/subst.c2
-rw-r--r--Src/utils.c23
7 files changed, 68 insertions, 23 deletions
diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c
index 18c7fb58e..521c15a5b 100644
--- a/Src/Modules/datetime.c
+++ b/Src/Modules/datetime.c
@@ -148,7 +148,7 @@ output_strftime(char *nam, char **argv, Options ops, UNUSED(int func))
} else if (*argv[2] == '\0' || *endptr != '\0') {
zwarnnam(nam, "%s: invalid decimal number", argv[2]);
return 1;
- } else if (ts.tv_nsec < 0) {
+ } else if (ts.tv_nsec < 0 || ts.tv_nsec > 999999999) {
zwarnnam(nam, "%s: invalid nanosecond value", argv[2]);
return 1;
}
diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c
index 87d13afc1..fe87409cb 100644
--- a/Src/Zle/compctl.c
+++ b/Src/Zle/compctl.c
@@ -3256,6 +3256,15 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd)
rpl = strlen(rpre);
rsl = strlen(rsuf);
}
+ else
+ {
+ for (p = rpre; *p; ++p)
+ if (*p == Dash)
+ *p = '-';
+ for (p = rsuf; *p; ++p)
+ if (*p == Dash)
+ *p = '-';
+ }
untokenize(lpre);
untokenize(lsuf);
diff --git a/Src/jobs.c b/Src/jobs.c
index ed9f81f26..73d7f26da 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -1910,7 +1910,7 @@ getjob(const char *s, const char *prog)
/* "%%", "%+" and "%" all represent the current job */
if (*s == '%' || *s == '+' || !*s) {
if (curjob == -1) {
- if (prog)
+ if (prog && !isset(POSIXBUILTINS))
zwarnnam(prog, "no current job");
returnval = -1;
goto done;
@@ -1921,7 +1921,7 @@ getjob(const char *s, const char *prog)
/* "%-" represents the previous job */
if (*s == '-') {
if (prevjob == -1) {
- if (prog)
+ if (prog && !isset(POSIXBUILTINS))
zwarnnam(prog, "no previous job");
returnval = -1;
goto done;
@@ -1944,7 +1944,7 @@ getjob(const char *s, const char *prog)
returnval = jobnum;
goto done;
}
- if (prog)
+ if (prog && !isset(POSIXBUILTINS))
zwarnnam(prog, "%%%s: no such job", s);
returnval = -1;
goto done;
@@ -1962,7 +1962,7 @@ getjob(const char *s, const char *prog)
returnval = jobnum;
goto done;
}
- if (prog)
+ if (prog && !isset(POSIXBUILTINS))
zwarnnam(prog, "job not found: %s", s);
returnval = -1;
goto done;
@@ -1976,7 +1976,8 @@ getjob(const char *s, const char *prog)
}
/* if we get here, it is because none of the above succeeded and went
to done */
- zwarnnam(prog, "job not found: %s", s);
+ if (!isset(POSIXBUILTINS))
+ zwarnnam(prog, "job not found: %s", s);
returnval = -1;
done:
return returnval;
@@ -2375,9 +2376,10 @@ bin_fg(char *name, char **argv, Options ops, int func)
}
}
} else if ((retval = getbgstatus(pid)) < 0) {
- zwarnnam(name, "pid %d is not a child of this shell", pid);
+ if (!isset(POSIXBUILTINS))
+ zwarnnam(name, "pid %d is not a child of this shell", pid);
/* presumably lastval2 doesn't tell us a heck of a lot? */
- retval = 1;
+ retval = 127;
}
thisjob = ocj;
continue;
@@ -2391,15 +2393,16 @@ bin_fg(char *name, char **argv, Options ops, int func)
job = (*argv) ? getjob(*argv, name) : firstjob;
firstjob = -1;
if (job == -1) {
- retval = 1;
+ retval = 127;
break;
}
jstat = oldjobtab ? oldjobtab[job].stat : jobtab[job].stat;
if (!(jstat & STAT_INUSE) ||
(jstat & STAT_NOPRINT)) {
- zwarnnam(name, "%s: no such job", *argv);
+ if (!isset(POSIXBUILTINS))
+ zwarnnam(name, "%s: no such job", *argv);
unqueue_signals();
- return 1;
+ return 127;
}
/* If AUTO_CONTINUE is set (automatically make stopped jobs running
* on disown), we actually do a bg and then delete the job table entry. */
diff --git a/Src/math.c b/Src/math.c
index b08e05cb4..a38770073 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -342,6 +342,8 @@ getmathparam(struct mathvalue *mptr)
mptr->pval = (Value)zhalloc(sizeof(struct value));
if (!getvalue(mptr->pval, &s, 1))
{
+ if (unset(UNSET))
+ zerr("%s: parameter not set", mptr->lval);
mptr->pval = NULL;
if (isset(FORCEFLOAT)) {
result.type = MN_FLOAT;
diff --git a/Src/prompt.c b/Src/prompt.c
index 568bfc2a9..135aca942 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -1764,7 +1764,12 @@ output_colour(int colour, int fg_bg, int use_tc, int truecol, char *buf)
/* length of hex triplet always 7, don't need sprintf to count */
atrlen += buf ? sprintf(ptr, "#%02x%02x%02x", colour >> 16,
(colour >> 8) & 0xff, colour & 0xff) : 7;
- /* colour should only be > 7 if using termcap but let's be safe */
+ /* colour should only be > 7 if using termcap but let's be safe. Update:
+ * currently other places in code don't always imply that colour > 7 =>
+ * using-termcap - if zle_highlight will be non-default, then it will be
+ * used instead of termcap even for colour > 7. Here this just emits the
+ * color number, so it works fine for both zle_highlight and tercap cases
+ */
} else if (use_tc || colour > 7) {
char digbuf[DIGBUFSIZE];
sprintf(digbuf, "%d", colour);
@@ -1995,6 +2000,7 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
char *ptr;
int do_free, is_prompt = (flags & TSC_PROMPT) ? 1 : 0;
int colour, tc, def, use_termcap, use_truecolor;
+ int is_default_zle_highlight = 1;
if (fg_bg == COL_SEQ_FG) {
colour = txtchangeget(atr, TXT_ATTR_FG_COL);
@@ -2010,6 +2016,15 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
use_termcap = txtchangeisset(atr, TXT_ATTR_BG_TERMCAP);
}
+ /* Test if current zle_highlight settings are customized, or
+ * the typical "standard" codes */
+ if (0 != strcmp(fg_bg_sequences[fg_bg].start, fg_bg == COL_SEQ_FG ? "\e[3" : "\e[4") ||
+ 0 != strcmp(fg_bg_sequences[fg_bg].def, "9") || /* the same in-fix for both FG and BG */
+ 0 != strcmp(fg_bg_sequences[fg_bg].end, "m") /* the same suffix for both FG and BG */
+ ) {
+ is_default_zle_highlight = 0;
+ }
+
/*
* If we're not restoring the default, and either have a
* colour value that is too large for ANSI, or have been told
@@ -2020,7 +2035,7 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
* highlighting variables, so much of this shouldn't be
* necessary at this point, but we might as well be safe.
*/
- if (!def && !use_truecolor && (colour > 7 || use_termcap)) {
+ if (!def && !use_truecolor && (is_default_zle_highlight && (colour > 7 || use_termcap))) {
/*
* We can if it's available, and either we couldn't get
* the maximum number of colours, or the colour is in range.
@@ -2046,9 +2061,10 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
}
/*
* Nope, that didn't work.
- * If 0 to 7, assume standard ANSI works, otherwise it won't.
+ * If 0 to 7, assume standard ANSI works, if 8 to 255, assume
+ * typical 256-color escapes works, otherwise it won't.
*/
- if (colour > 7)
+ if (colour > 255)
return;
}
@@ -2057,6 +2073,10 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
allocate_colour_buffer();
}
+ /* Build the reset-code: .start + .def + . end
+ * or the typical true-color code: .start + 8;2;%d;%d;%d + .end
+ * or the typical 256-color code: .start + 8;5;%d + .end
+ */
strcpy(colseq_buf, fg_bg_sequences[fg_bg].start);
ptr = colseq_buf + strlen(colseq_buf);
@@ -2067,6 +2087,8 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
} else if (use_truecolor) {
ptr += sprintf(ptr, "8;2;%d;%d;%d", colour >> 16,
(colour >> 8) & 0xff, colour & 0xff);
+ } else if (colour > 7 && colour <= 255) {
+ ptr += sprintf(ptr, "8;5;%d", colour);
} else
*ptr++ = colour + '0';
strcpy(ptr, fg_bg_sequences[fg_bg].end);
diff --git a/Src/subst.c b/Src/subst.c
index ff6750a59..60eb33390 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -2338,7 +2338,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
zerr("bad substitution");
return NULL;
}
- } else if (inbrace && inull(*s)) {
+ } else if (inbrace && inull(*s) && *s != Bnull) {
/*
* Handles things like ${(f)"$(<file)"} by skipping
* the double quotes. We don't need to know what was
diff --git a/Src/utils.c b/Src/utils.c
index e43a3cdb4..32f600858 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3334,19 +3334,28 @@ morefmt:
#endif
switch (*fmt++) {
case '.':
- if (ztrftimebuf(&bufsize, digs))
- return -1;
+ {
+ long fnsec = nsec;
if (digs > 9)
digs = 9;
+ if (ztrftimebuf(&bufsize, digs))
+ return -1;
if (digs < 9) {
int trunc;
- for (trunc = 8 - digs; trunc; trunc--)
- nsec /= 10;
- nsec = (nsec + 8) / 10;
+ long max = 100000000;
+ for (trunc = 8 - digs; trunc; trunc--) {
+ max /= 10;
+ fnsec /= 10;
+ }
+ max -= 1;
+ fnsec = (fnsec + 5) / 10;
+ if (fnsec > max)
+ fnsec = max;
}
- sprintf(buf, "%0*ld", digs, nsec);
+ sprintf(buf, "%0*ld", digs, fnsec);
buf += digs;
break;
+ }
case '\0':
/* Guard against premature end of string */
*buf++ = '%';
@@ -3837,7 +3846,7 @@ sepjoin(char **s, char *sep, int heap)
char sepbuf[2];
if (!*s)
- return heap ? "" : ztrdup("");
+ return heap ? dupstring("") : ztrdup("");
if (!sep) {
/* optimise common case that ifs[0] is space */
if (ifs && *ifs != ' ') {