diff --git a/histrap.c b/histrap.c index 1e152e2..1cd486d 100644 --- a/histrap.c +++ b/histrap.c @@ -3,7 +3,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.39 2007/01/12 02:06:34 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.40 2007/01/15 02:48:27 tg Exp $"); Trap sigtraps[NSIG + 1]; static struct sigaction Sigact_ign, Sigact_trap; @@ -943,7 +943,7 @@ hist_finish(void) static int sprinkle(int fd) { - static unsigned char mag[] = { HMAGIC1, HMAGIC2 }; + static const unsigned char mag[] = { HMAGIC1, HMAGIC2 }; return(write(fd, mag, 2) != 2); } diff --git a/sh.h b/sh.h index 9d13a1a..5b0cb25 100644 --- a/sh.h +++ b/sh.h @@ -8,7 +8,7 @@ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ -#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.97 2007/01/15 00:38:20 tg Exp $" +#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.98 2007/01/15 02:48:27 tg Exp $" #define MKSH_VERSION "R29 2007/01/14" #if HAVE_SYS_PARAM_H @@ -201,10 +201,8 @@ EXTERN uid_t ksheuid; /* effective uid of shell */ EXTERN int exstat; /* exit status */ EXTERN int subst_exstat; /* exit status of last $(..)/`..` */ EXTERN const char *safe_prompt; /* safe prompt if PS1 substitution fails */ -#ifndef EXTERN_DEFINED -static const char initvsn[] = "KSH_VERSION=@(#)MIRBSD KSH " MKSH_VERSION; -#endif -EXTERN const char *KSH_VERSION I__(initvsn + 16); +EXTERN const char initvsn[] I__("KSH_VERSION=@(#)MIRBSD KSH " MKSH_VERSION); +#define KSH_VERSION (initvsn + 16) /* * Area-based allocation built on malloc/free diff --git a/shf.c b/shf.c index e409999..02d0835 100644 --- a/shf.c +++ b/shf.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.10 2007/01/15 00:37:42 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.11 2007/01/15 02:48:28 tg Exp $"); /* flags to shf_emptybuf() */ #define EB_READSW 0x01 /* about to switch to reading */ @@ -727,18 +727,14 @@ shf_smprintf(const char *fmt, ...) int shf_vfprintf(struct shf *shf, const char *fmt, va_list args) { - char c, *s; - int tmp = 0; - int field, precision; - int len; - int flags; - unsigned long lnum; - /* %#o produces the longest output */ - char numbuf[(8 * sizeof(long) + 2) / 3 + 1]; + const char *s; + char c, *cp; + int tmp = 0, field, precision, len, flags; + unsigned long lnum; + /* %#o produces the longest output */ + char numbuf[(8 * sizeof(long) + 2) / 3 + 1]; /* this stuff for dealing with the buffer */ - int nwritten = 0; - - static char nulls[] = "(null %s)"; + int nwritten = 0; if (!fmt) return 0; @@ -842,7 +838,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) case 'u': case 'x': flags |= FL_NUMBER; - s = &numbuf[sizeof(numbuf)]; + cp = &numbuf[sizeof (numbuf)]; /*- * XXX any better way to do this? * XXX hopefully the compiler optimises this out @@ -869,28 +865,28 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) case 'u': do { - *--s = lnum % 10 + '0'; + *--cp = lnum % 10 + '0'; lnum /= 10; } while (lnum); if (c != 'u') { if (tmp) - *--s = '-'; + *--cp = '-'; else if (flags & FL_PLUS) - *--s = '+'; + *--cp = '+'; else if (flags & FL_BLANK) - *--s = ' '; + *--cp = ' '; } break; case 'o': do { - *--s = (lnum & 0x7) + '0'; + *--cp = (lnum & 0x7) + '0'; lnum >>= 3; } while (lnum); - if ((flags & FL_HASH) && *s != '0') - *--s = '0'; + if ((flags & FL_HASH) && *cp != '0') + *--cp = '0'; break; case 'p': @@ -900,17 +896,17 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) "0123456789ABCDEF" : "0123456789abcdef"; do { - *--s = digits[lnum & 0xf]; + *--cp = digits[lnum & 0xf]; lnum >>= 4; } while (lnum); if (flags & FL_HASH) { - *--s = (flags & FL_UPPER) ? 'X' : 'x'; - *--s = '0'; + *--cp = (flags & FL_UPPER) ? 'X' : 'x'; + *--cp = '0'; } } } - len = &numbuf[sizeof(numbuf)] - s; + len = &numbuf[sizeof (numbuf)] - (s = cp); if (flags & FL_DOT) { if (precision > len) { field = precision; @@ -921,8 +917,8 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) break; case 's': - if (!(s = va_arg(args, char *))) - s = nulls; + if (!(s = va_arg(args, const char *))) + s = "(null)"; len = strlen(s); break; @@ -942,9 +938,8 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) } /* - * At this point s should point to a string that is - * to be formatted, and len should be the length of the - * string. + * At this point s should point to a string that is to be + * formatted, and len should be the length of the string. */ if (!(flags & FL_DOT) || len < precision) precision = len; @@ -954,7 +949,8 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) field = -field; /* skip past sign or 0x when padding with 0 */ if ((flags & FL_ZERO) && (flags & FL_NUMBER)) { - if (*s == '+' || *s == '-' || *s ==' ') { + if (*s == '+' || *s == '-' || + *s == ' ') { shf_putc(*s, shf); s++; precision--; diff --git a/var.c b/var.c index 32d37e3..48873f6 100644 --- a/var.c +++ b/var.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.33 2006/11/19 16:43:43 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.34 2007/01/15 02:48:28 tg Exp $"); /* * Variables @@ -32,7 +32,7 @@ void newblock(void) { struct block *l; - static char *empty[] = {null}; + static char *empty[] = { null }; l = (struct block *) alloc(sizeof(struct block), ATEMP); l->flags = 0;