#include <sys/file.h>
#endif
-__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.152 2016/01/14 23:18:08 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.158 2016/08/04 20:31:00 tg Exp $");
Trap sigtraps[ksh_NSIG + 1];
static struct sigaction Sigact_ign;
static off_t histfsize;
#endif
-static const char Tnot_in_history[] = "not in history";
-#define Thistory (Tnot_in_history + 7)
-
-static const char TFCEDIT_dollaru[] = "${FCEDIT:-/bin/ed} $_";
-#define Tspdollaru (TFCEDIT_dollaru + 18)
-
/* HISTSIZE default: size of saved history, persistent or standard */
#ifdef MKSH_SMALL
#define MKSH_DEFHISTSIZE 255
else if (!last)
last = p;
else {
- bi_errorf("too many arguments");
+ bi_errorf(Ttoo_many_args);
return (1);
}
break;
if (!first && (first = *wp))
wp++;
if (last || *wp) {
- bi_errorf("too many arguments");
+ bi_errorf(Ttoo_many_args);
return (1);
}
xp += rep_len;
}
if (!any_subst) {
- bi_errorf("bad substitution");
+ bi_errorf(Tbadsubst);
return (1);
}
len = strlen(s) + 1;
if (!last && (last = *wp))
wp++;
if (*wp) {
- bi_errorf("too many arguments");
+ bi_errorf(Ttoo_many_args);
return (1);
}
if (!first) {
for (hp = rflag ? hlast : hfirst;
hp >= hfirst && hp <= hlast; hp += rflag ? -1 : 1) {
if (!nflag)
- shf_fprintf(shl_stdout, "%lu",
+ shf_fprintf(shl_stdout, Tf_lu,
(unsigned long)hist_source->line -
(unsigned long)(histptr - hp));
shf_putc('\t', shl_stdout);
*t++ = '\n';
s = t;
}
- shf_fprintf(shl_stdout, "%s\n", s);
+ shf_fprintf(shl_stdout, Tf_sN, s);
}
shf_flush(shl_stdout);
return (0);
tf = maketemp(ATEMP, TT_HIST_EDIT, &e->temps);
if (!(shf = tf->shf)) {
- bi_errorf("can't %s temporary file %s: %s",
- "create", tf->tffn, cstrerror(errno));
+ bi_errorf(Tf_temp, Tcreate, tf->tffn, cstrerror(errno));
return (1);
}
for (hp = rflag ? hlast : hfirst;
hp >= hfirst && hp <= hlast; hp += rflag ? -1 : 1)
- shf_fprintf(shf, "%s\n", *hp);
+ shf_fprintf(shf, Tf_sN, *hp);
if (shf_close(shf) == -1) {
- bi_errorf("can't %s temporary file %s: %s",
- "write", tf->tffn, cstrerror(errno));
+ bi_errorf(Tf_temp, Twrite, tf->tffn, cstrerror(errno));
return (1);
}
/* Ignore setstr errors here (arbitrary) */
setstr(local("_", false), tf->tffn, KSH_RETURN_ERROR);
- /* XXX: source should not get trashed by this.. */
- {
- Source *sold = source;
- int ret;
-
- ret = command(editor ? editor : TFCEDIT_dollaru, 0);
- source = sold;
- if (ret)
- return (ret);
- }
+ if ((optc = command(editor ? editor : TFCEDIT_dollaru, 0)))
+ return (optc);
{
struct stat statb;
ssize_t n;
if (!(shf = shf_open(tf->tffn, O_RDONLY, 0, 0))) {
- bi_errorf("can't %s temporary file %s: %s",
- "open", tf->tffn, cstrerror(errno));
+ bi_errorf(Tf_temp, Topen, tf->tffn, cstrerror(errno));
return (1);
}
if (stat(tf->tffn, &statb) < 0)
n = 128;
else if ((off_t)statb.st_size > MKSH_MAXHISTFSIZE) {
- bi_errorf("%s %s too large: %lu", Thistory,
- "file", (unsigned long)statb.st_size);
+ bi_errorf(Tf_toolarge, Thistory,
+ Tfile, (unsigned long)statb.st_size);
goto errout;
} else
n = (size_t)statb.st_size + 1;
XcheckN(xs, xp, Xlength(xs, xp));
}
if (n < 0) {
- bi_errorf("can't %s temporary file %s: %s",
- "read", tf->tffn, cstrerror(shf_errno(shf)));
+ bi_errorf(Tf_temp, Tread, tf->tffn,
+ cstrerror(shf_errno(shf)));
errout:
shf_close(shf);
return (1);
hist_execute(char *cmd, Area *areap)
{
static int last_line = -1;
- Source *sold;
- int ret;
/* Back up over last histsave */
if (histptr >= history && last_line != hist_source->line) {
afree(cmd, areap);
cmd = *histptr;
/* pdksh says POSIX doesn’t say this is done, testsuite needs it */
- shellf("%s\n", cmd);
+ shellf(Tf_sN, cmd);
/*-
* Commands are executed here instead of pushing them onto the
* X=y fc -e - 42 2> /dev/null
* are to effect the repeated commands environment.
*/
- /* XXX: source should not get trashed by this.. */
- sold = source;
- ret = command(cmd, 0);
- source = sold;
- return (ret);
+ return (command(cmd, 0));
}
/*
if (approx)
hp = hist_get_oldest();
else {
- bi_errorf("%s: %s", str, Tnot_in_history);
+ bi_errorf(Tf_sD_s, str, Tnot_in_history);
hp = NULL;
}
} else if ((size_t)hp > (size_t)histptr) {
if (approx)
hp = hist_get_newest(allow_cur);
else {
- bi_errorf("%s: %s", str, Tnot_in_history);
+ bi_errorf(Tf_sD_s, str, Tnot_in_history);
hp = NULL;
}
} else if (!allow_cur && hp == histptr) {
- bi_errorf("%s: %s", str, "invalid range");
+ bi_errorf(Tf_sD_s, str, "invalid range");
hp = NULL;
}
} else {
/* the -1 is to avoid the current fc command */
if ((n = findhist(histptr - history - 1, 0, str, anchored)) < 0)
- bi_errorf("%s: %s", str, Tnot_in_history);
+ bi_errorf(Tf_sD_s, str, Tnot_in_history);
else
hp = &history[n];
}
strndupx(c, cmd, ccp - cmd, APERM);
if (svmode != HIST_APPEND) {
- if (ignoredups && !strcmp(c, *histptr)
+ if (ignoredups &&
+ histptr >= history &&
+ !strcmp(c, *histptr)
#if !defined(MKSH_SMALL) && HAVE_PERSISTENT_HISTORY
&& !histsync()
#endif
goto retry;
}
if (hs != hist_init_retry)
- bi_errorf("can't %s %s: %s",
+ bi_errorf(Tf_cant,
"unlink HISTFILE", hname, cstrerror(errno));
histfsize = 0;
return;
{
int i;
const char *cs;
+#if !HAVE_SYS_SIGNAME
+ const struct mksh_sigpair *pair;
+#endif
trap_exstat = -1;
- /* Populate sigtraps based on sys_signame and sys_siglist. */
+ /* populate sigtraps based on sys_signame and sys_siglist */
for (i = 1; i < ksh_NSIG; i++) {
sigtraps[i].signal = i;
#if HAVE_SYS_SIGNAME
cs = sys_signame[i];
#else
- const struct mksh_sigpair *pair = mksh_sigpairs;
+ pair = mksh_sigpairs;
while ((pair->nr != i) && (pair->name != NULL))
++pair;
cs = pair->name;
#endif
if ((cs == NULL) ||
(cs[0] == '\0'))
- sigtraps[i].name = shf_smprintf("%d", i);
+ sigtraps[i].name = null;
else {
char *s;
sigtraps[i].name = s;
while ((*s = ksh_toupper(*s)))
++s;
+ /* check for reserved names */
+ if (!strcmp(sigtraps[i].name, "EXIT") ||
+ !strcmp(sigtraps[i].name, "ERR")) {
+#ifndef MKSH_SMALL
+ internal_warningf("ignoring invalid signal name %s",
+ sigtraps[i].name);
+#endif
+ sigtraps[i].name = null;
+ }
}
+ if (sigtraps[i].name == null)
+ sigtraps[i].name = shf_smprintf(Tf_d, i);
#if HAVE_SYS_SIGLIST
sigtraps[i].mess = sys_siglist[i];
#elif HAVE_STRSIGNAL
#endif
if ((sigtraps[i].mess == NULL) ||
(sigtraps[i].mess[0] == '\0'))
- sigtraps[i].mess = shf_smprintf("%s %d",
+ sigtraps[i].mess = shf_smprintf(Tf_sd,
"Signal", i);
}
sigtraps[ksh_SIGEXIT].signal = ksh_SIGEXIT;