diff --git a/funcs.c b/funcs.c index ee2f3e8..54f7778 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.211 2012/03/29 19:22:58 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.212 2012/04/06 13:28:59 tg Exp $"); #if HAVE_KILLPG /* @@ -1275,7 +1275,7 @@ c_kill(const char **wp) /* assume old style options if -digits or -UPPERCASE */ if ((p = wp[1]) && *p == '-' && (ksh_isdigit(p[1]) || ksh_isupper(p[1]))) { - if (!(t = gettrap(p + 1, true))) { + if (!(t = gettrap(p + 1, false))) { bi_errorf("bad signal '%s'", p + 1); return (1); } diff --git a/histrap.c b/histrap.c index 68da49c..5299058 100644 --- a/histrap.c +++ b/histrap.c @@ -27,7 +27,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.121 2012/04/01 03:23:08 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.122 2012/04/06 13:29:00 tg Exp $"); Trap sigtraps[NSIG + 1]; static struct sigaction Sigact_ign; @@ -987,8 +987,14 @@ inittraps(void) else { char *s; - if (!strncasecmp(cs, "SIG", 3)) + /* this is not optimal, what about SIGSIG1? */ + if ((cs[0] & 0xDF) == 'S' && + (cs[1] & 0xDF) == 'I' && + (cs[2] & 0xDF) == 'G' && + cs[3] != '\0') { + /* skip leading "SIG" */ cs += 3; + } strdupx(s, cs, APERM); sigtraps[i].name = s; while ((*s = ksh_toupper(*s))) @@ -1056,27 +1062,45 @@ alarm_catcher(int sig MKSH_A_UNUSED) } Trap * -gettrap(const char *name, int igncase) +gettrap(const char *cs, bool igncase) { - int n = NSIG + 1; + int i; Trap *p; - const char *n2; - int (*cmpfunc)(const char *, const char *) = strcmp; + char *as; - if (ksh_isdigit(*name)) { - if (getn(name, &n) && 0 <= n && n < NSIG) - return (&sigtraps[n]); - else - return (NULL); + if (ksh_isdigit(*cs)) { + return ((getn(cs, &i) && 0 <= i && i < NSIG) ? + (&sigtraps[i]) : NULL); } - n2 = strncasecmp(name, "SIG", 3) ? NULL : name + 3; - if (igncase) - cmpfunc = strcasecmp; - for (p = sigtraps; --n >= 0; p++) - if (!cmpfunc(p->name, name) || (n2 && !cmpfunc(p->name, n2))) - return (p); - return (NULL); + /* this breaks SIGSIG1, but we do that above anyway */ + if ((cs[0] & 0xDF) == 'S' && + (cs[1] & 0xDF) == 'I' && + (cs[2] & 0xDF) == 'G' && + cs[3] != '\0') { + /* skip leading "SIG" */ + cs += 3; + } + if (igncase) { + char *s; + + strdupx(as, cs, ATEMP); + cs = s = as; + while ((*s = ksh_toupper(*s))) + ++s; + } else + as = NULL; + + p = sigtraps; + for (i = 0; i <= NSIG; i++) { + if (!strcmp(p->name, cs)) + goto found; + ++p; + } + p = NULL; + found: + afree(as, ATEMP); + return (p); } /* diff --git a/sh.h b/sh.h index c6e0e6c..72f4810 100644 --- a/sh.h +++ b/sh.h @@ -152,7 +152,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.541 2012/04/06 12:59:28 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.542 2012/04/06 13:29:01 tg Exp $"); #endif #define MKSH_VERSION "R40 2012/03/29" @@ -326,11 +326,6 @@ extern int getrusage(int, struct rusage *); extern int revoke(const char *); #endif -#ifdef __ultrix -/* XXX imake style */ -int strcasecmp(const char *, const char *); -#endif - #if !HAVE_STRLCPY size_t strlcpy(char *, const char *, size_t); #endif @@ -1662,7 +1657,7 @@ int findhist(int, int, const char *, int); char **hist_get_newest(bool); void inittraps(void); void alarm_init(void); -Trap *gettrap(const char *, int); +Trap *gettrap(const char *, bool); void trapsig(int); void intrcheck(void); int fatal_trap_check(void);