diff --git a/usr.bin/xstr/xstr.c b/usr.bin/xstr/xstr.c index 7cff25b2cc13..a4646a1ce3dd 100644 --- a/usr.bin/xstr/xstr.c +++ b/usr.bin/xstr/xstr.c @@ -1,4 +1,4 @@ -/* $NetBSD: xstr.c,v 1.14 2003/08/07 11:17:51 agc Exp $ */ +/* $NetBSD: xstr.c,v 1.15 2003/11/08 18:12:01 christos Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\ #if 0 static char sccsid[] = "@(#)xstr.c 8.1 (Berkeley) 6/9/93"; #else -__RCSID("$NetBSD: xstr.c,v 1.14 2003/08/07 11:17:51 agc Exp $"); +__RCSID("$NetBSD: xstr.c,v 1.15 2003/11/08 18:12:01 christos Exp $"); #endif #endif /* not lint */ @@ -61,21 +61,21 @@ __RCSID("$NetBSD: xstr.c,v 1.14 2003/08/07 11:17:51 agc Exp $"); * November, 1978 */ -static off_t hashit __P((char *, int)); -static void onintr __P((int)); -static off_t yankstr __P((char **)); -static int octdigit __P((char)); -static void inithash __P((void)); -static int fgetNUL __P((char *, int, FILE *)); -static int xgetc __P((FILE *)); -static void flushsh __P((void)); -static void found __P((int, off_t, char *)); -static void prstr __P((char *)); -static void xsdotc __P((void)); -static char lastchr __P((char *)); -static int istail __P((char *, char *)); -static void process __P((char *)); -static void usage __P((void)); +static off_t hashit(const char *, int); +static void onintr(int); +static off_t yankstr(char **); +static int octdigit(char); +static void inithash(void); +static int fgetNUL(char *, int, FILE *); +static int xgetc(FILE *); +static void flushsh(void); +static void found(int, off_t, const char *); +static void prstr(const char *); +static void xsdotc(void); +static char lastchr(const char *); +static int istail(const char *, const char *); +static void process(const char *); +static void usage(void); static off_t tellpt; static off_t mesgpt; @@ -95,12 +95,10 @@ static struct hash { short hnew; } bucket[BUCKETS]; -int main __P((int, char *[])); +int main(int, char *[]); int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int c; @@ -160,8 +158,7 @@ main(argc, argv) } static void -process(name) - char *name; +process(const char *name) { char *cp; int c; @@ -185,73 +182,75 @@ process(name) printf("%s", linebuf); continue; } - for (cp = linebuf; (c = *cp++);) switch (c) { + for (cp = linebuf; (c = *cp++);) + switch (c) { - case '"': - if (incomm || inasm) - goto def; - if ((ret = (int) yankstr(&cp)) == -1) - goto out; - printf("(&%s[%d])", array, ret); - break; - - case '\'': - if (incomm || inasm) - goto def; - putchar(c); - if (*cp) - putchar(*cp++); - break; - - case '/': - if (incomm || *cp != '*') - goto def; - incomm = 1; - cp++; - printf("/*"); - continue; - - case '*': - if (incomm && *cp == '/') { - incomm = 0; - cp++; - printf("*/"); - continue; - } - goto def; - - case '(': - if (!incomm && inasm) - asmparnest++; - goto def; - - case ')': - if (!incomm && inasm && !--asmparnest) - inasm = 0; - goto def; - - case '_': - if (incomm || inasm) - goto def; - if (!strncmp(cp, "_asm", 4)) { - cp += 4; - printf("__asm"); - if (!strncmp(cp, "__", 2)) { - cp += 2; - printf("__"); - } - if (isalnum(*cp) || *cp == '_') + case '"': + if (incomm || inasm) goto def; - asmparnest = 0; - inasm = 1; - } else + if ((ret = (int) yankstr(&cp)) == -1) + goto out; + printf("(&%s[%d])", array, ret); + break; + + case '\'': + if (incomm || inasm) + goto def; + putchar(c); + if (*cp) + putchar(*cp++); + break; + + case '/': + if (incomm || *cp != '*') + goto def; + incomm = 1; + cp++; + printf("/*"); + continue; + + case '*': + if (incomm && *cp == '/') { + incomm = 0; + cp++; + printf("*/"); + continue; + } goto def; - break; + + case '(': + if (!incomm && inasm) + asmparnest++; + goto def; + + case ')': + if (!incomm && inasm && !--asmparnest) + inasm = 0; + goto def; + + case '_': + if (incomm || inasm) + goto def; + if (!strncmp(cp, "_asm", 4)) { + cp += 4; + printf("__asm"); + if (!strncmp(cp, "__", 2)) { + cp += 2; + printf("__"); + } + if (isalnum((unsigned char)*cp) || + *cp == '_') + goto def; + asmparnest = 0; + inasm = 1; + } else + goto def; + break; def: - default: - putchar(c); - break; - } + default: + putchar(c); + break; + } } out: if (ferror(stdout)) { @@ -261,8 +260,7 @@ out: } static off_t -yankstr(cpp) - char **cpp; +yankstr(char **cpp) { char *cp = *cpp; int c, ch; @@ -270,7 +268,7 @@ yankstr(cpp) char *dp = dbuf; char *tp; - while ((c = *cp++)) { + while ((c = *cp++) != '\0') { switch (c) { case '"': @@ -315,7 +313,7 @@ gotc: out: *cpp = --cp; *dp = 0; - return (hashit(dbuf, 1)); + return hashit(dbuf, 1); } static int @@ -327,7 +325,7 @@ octdigit(c) } static void -inithash() +inithash(void) { char buf[BUFSIZ]; FILE *mesgread = fopen(strings, "r"); @@ -344,34 +342,28 @@ inithash() } static int -fgetNUL(obuf, rmdr, file) - char *obuf; - int rmdr; - FILE *file; +fgetNUL(char *obuf, int rmdr, FILE *file) { int c; char *buf = obuf; - while (--rmdr > 0 && (c = xgetc(file)) != 0 && c != EOF) + while (--rmdr > 0 && (c = xgetc(file) != 0 && c != EOF)) *buf++ = c; *buf++ = 0; - return ((feof(file) || ferror(file)) ? 0 : 1); + return (feof(file) || ferror(file)) ? 0 : 1; } static int -xgetc(file) - FILE *file; +xgetc(FILE *file) { tellpt++; - return (getc(file)); + return getc(file); } static off_t -hashit(str, new) - char *str; - int new; +hashit(const char *str, int new) { int i; struct hash *hp, *hp0; @@ -383,7 +375,7 @@ hashit(str, new) if (i >= 0) return (hp->hpt + i); } - if ((hp = (struct hash *) calloc(1, sizeof (*hp))) == NULL) + if ((hp = calloc(1, sizeof (*hp))) == NULL) err(1, NULL); hp->hpt = mesgpt; if ((hp->hstr = strdup(str)) == NULL) @@ -396,7 +388,7 @@ hashit(str, new) } static void -flushsh() +flushsh(void) { int i; struct hash *hp; @@ -418,7 +410,7 @@ flushsh() for (hp = bucket[i].hnext; hp != NULL; hp = hp->hnext) { found(hp->hnew, hp->hpt, hp->hstr); if (hp->hnew) { - fseek(mesgwrit, hp->hpt, 0); + (void)fseek(mesgwrit, hp->hpt, 0); (void)fwrite(hp->hstr, strlen(hp->hstr) + 1, 1, mesgwrit); if (ferror(mesgwrit)) @@ -430,10 +422,7 @@ flushsh() } static void -found(new, off, str) - int new; - off_t off; - char *str; +found(int new, off_t off, const char *str) { if (vflg == 0) return; @@ -446,24 +435,23 @@ found(new, off, str) } static void -prstr(cp) - char *cp; +prstr(const char *cp) { int c; - while ((c = (*cp++ & 0377))) + while ((c = (*cp++ & 0377)) != '\0') if (c < ' ') - fprintf(stderr, "^%c", c + '`'); + (void)fprintf(stderr, "^%c", c + '`'); else if (c == 0177) - fprintf(stderr, "^?"); + (void)fprintf(stderr, "^?"); else if (c > 0200) - fprintf(stderr, "\\%03o", c); + (void)fprintf(stderr, "\\%03o", c); else - fprintf(stderr, "%c", c); + (void)fprintf(stderr, "%c", c); } static void -xsdotc() +xsdotc(void) { FILE *strf = fopen(strings, "r"); FILE *xdotcf; @@ -473,7 +461,7 @@ xsdotc() xdotcf = fopen("xs.c", "w"); if (xdotcf == NULL) err(1, "Cannot open `%s'", "xs.c"); - fprintf(xdotcf, "char\t%s[] = {\n", array); + (void)fprintf(xdotcf, "char\t%s[] = {\n", array); for (;;) { int i, c; @@ -484,22 +472,21 @@ xsdotc() onintr(1); } if (feof(strf)) { - fprintf(xdotcf, "\n"); + (void)fprintf(xdotcf, "\n"); goto out; } - fprintf(xdotcf, "0x%02x,", c); + (void)fprintf(xdotcf, "0x%02x,", c); } - fprintf(xdotcf, "\n"); + (void)fprintf(xdotcf, "\n"); } out: - fprintf(xdotcf, "};\n"); + (void)fprintf(xdotcf, "};\n"); (void)fclose(xdotcf); (void)fclose(strf); } static char -lastchr(cp) - char *cp; +lastchr(const char *cp) { while (cp[0] && cp[1]) @@ -508,8 +495,7 @@ lastchr(cp) } static int -istail(str, of) - char *str, *of; +istail(const char *str, const char *of) { int d = strlen(of) - strlen(str); @@ -519,8 +505,7 @@ istail(str, of) } static void -onintr(dummy) - int dummy; +onintr(int dummy) { (void)signal(SIGINT, SIG_IGN); @@ -532,7 +517,7 @@ onintr(dummy) } static void -usage() +usage(void) { (void)fprintf(stderr, "Usage: %s [-vc] [-l array] [-] [ ...]\n",