--- bc-stage/usr/src/cmd/exstr/exstr.c Fri Jul 22 12:31:54 2005 +++ bc/usr/src/cmd/exstr/exstr.c Fri Jul 22 12:30:50 2005 @@ -34,13 +34,12 @@ /* external functions */ -extern char *malloc(); extern int getopt(); extern void exit(); extern int atoi(); extern int _filbuf(); extern char *optarg; -extern int optind, opterr; +extern int optind, opterr; /* static functions */ @@ -55,13 +54,13 @@ /* static variables */ static int eflg; /* find strings in source file(s) */ -static int dflg; /* use replaced string a second argument */ +static int dflg; /* use replaced string a second argument */ static int rflg; /* replace strings by function calls */ -static int errflg; /* syntax error on command line */ -static char *Fname; /* name of source file */ +static int errflg; /* syntax error on command line */ +static char *Fname; /* name of source file */ static int Lineno; /* line number in source file */ static int Posno; /* character position within line */ -static int flag; /* sets when newline is encountered */ +static int flag; /* sets when newline is encountered */ static jmp_buf to_eof; @@ -69,10 +68,10 @@ int argc; char *argv[]; { - int ch; + int ch; while ((ch = getopt(argc, argv, "erd")) != -1) - switch(ch) { + switch (ch) { case 'e': if (rflg) errflg++; @@ -94,10 +93,10 @@ default: errflg++; } - if (optind == argc || errflg) + if (optind == argc || errflg) usage(); if (!rflg) - for(;optind (size_t) 14 || *msgfile == '\0' ){ - (void)fprintf(stderr, "exstr: ERROR: stdin: invalid message file name '%s'\n", msgfile); - (void)fprintf(stderr, "%s", curline); + if (strlen(msgfile) > (size_t)14 || *msgfile == '\0') { + (void) fprintf(stderr, + "exstr: ERROR: stdin: invalid message file name " + "'%s'\n", msgfile); + (void) fprintf(stderr, "%s", curline); exit(1); } repbufp = repstr; - repstr = strchr(repbufp,':'); + repstr = strchr(repbufp, ':'); if (repstr == (char *)NULL) badformat(curline); *repstr++ = '\0'; cp = repbufp; - while(*cp) - if(!isdigit(*cp++)) { + while (*cp) + if (!isdigit(*cp++)) { wrong_msg++; break; } - if ( *repbufp == '\0' || wrong_msg ) { - (void)fprintf(stderr, "exstr: ERROR: stdin: invalid message number '%s'\n", repbufp); - (void)fprintf(stderr, "%s", curline); + if (*repbufp == '\0' || wrong_msg) { + (void) fprintf(stderr, "exstr: ERROR: stdin: invalid " + "message number '%s'\n", repbufp); + (void) fprintf(stderr, "%s", curline); exit(1); - } + } curmsgno = atoi(repbufp); /* move up to this line */ - while (Lineno != curlineno ) { + while (Lineno != curlineno) { if (outp != outbuf) { - while(*inp != '\0') + while (*inp != '\0') *outp++ = *inp++; *outp = '\0'; - (void)fputs(outbuf,stdout); + (void) fputs(outbuf, stdout); } else if (*linebuf != '\0') - (void)fputs(linebuf,stdout); + (void) fputs(linebuf, stdout); outp = outbuf; inp = linebuf; - if (fgets(linebuf, sizeof linebuf, fi) == (char *)NULL) { - (void)fprintf(stderr, "read error\n"); + if (fgets(linebuf, sizeof (linebuf), fi) + == (char *)NULL) { + (void) fprintf(stderr, "read error\n"); exit(1); } Lineno++; @@ -346,7 +355,8 @@ Posno = 0; } if (Posno > curposno) { - (void)fprintf(stderr, "Bad input record line number %d\n",Lineno); + (void) fprintf(stderr, + "Bad input record line number %d\n", Lineno); exit(1); } while (Posno != curposno) { @@ -354,13 +364,18 @@ Posno++; } if (*inp != '"') { - fprintf(stderr, "exstr: ERROR: cannot replace string '%s' in line (%d) of file (%s)\n", repstr, Lineno, Fname); + (void) fprintf(stderr, "exstr: ERROR: cannot replace " + "string '%s' in line (%d) of file (%s)\n", repstr, + Lineno, Fname); exit(1); } /* check if string continues in next line */ - while (inp[strlen(inp)-2] == '\\' && inp[strlen(inp)-1] == '\n') { - if (fgets(linebuf,sizeof linebuf, fi) == (char *)NULL) { - fprintf(stderr, "exstr: ERROR: read error in file (%s)\n", Fname); + while (inp[strlen(inp)-2] == '\\' && inp[strlen(inp)-1] + == '\n') { + if (fgets(linebuf, sizeof (linebuf), fi) + == (char *)NULL) { + (void) fprintf(stderr, "exstr: ERROR: read " + "error in file (%s)\n", Fname); exit(1); } cont_str++; @@ -368,9 +383,12 @@ } if (cont_str) { cp = linebuf; - while (*cp != '\0' && *cp++ != '"') ; + while (*cp != '\0' && *cp++ != '"') + ; if (*cp == '\0') { - fprintf(stderr, "exstr: ERROR: cannot replace string '%s' in line (%d) of file (%s)\n", repstr, Lineno, Fname); + (void) fprintf(stderr, "exstr: ERROR: cannot " + "replace string '%s' in line (%d) of file " + "(%s)\n", repstr, Lineno, Fname); exit(1); } inp = cp; @@ -377,9 +395,12 @@ Posno = cp - linebuf; } if (dflg) - outp += sprintf(outp,"gettxt(\"%s:%d\", \"%s\")",msgfile, curmsgno, repstr); + outp += snprintf(outp, BUFSIZ - (outp - outbuf), + "gettxt(\"%s:%d\", \"%s\")", msgfile, curmsgno, + repstr); else - outp += sprintf(outp,"gettxt(\"%s:%d\", \"\")",msgfile,curmsgno); + outp += snprintf(outp, BUFSIZ - (outp - outbuf), + "gettxt(\"%s:%d\", \"\")", msgfile, curmsgno); if (!cont_str) { inp += strlen(repstr)+2; Posno += strlen(repstr)+2; @@ -388,13 +409,13 @@ cont_str = 0; } if (outp != outbuf) { - while(*inp != '\0') + while (*inp != '\0') *outp++ = *inp++; *outp = '\0'; - (void)fputs(outbuf,stdout); + (void) fputs(outbuf, stdout); } - while(fgets(linebuf,sizeof linebuf, fi) != (char *)NULL) - (void)fputs(linebuf, stdout); + while (fgets(linebuf, sizeof (linebuf), fi) != (char *)NULL) + (void) fputs(linebuf, stdout); (void) fclose(fi); } @@ -403,6 +424,7 @@ badformat(line) char *line; { - (void)fprintf(stderr, "exstr: ERROR: stdin: Badly formatted replacement string\n%s", line); + (void) fprintf(stderr, "exstr: ERROR: stdin: Badly formatted " + "replacement string\n%s", line); exit(1); }