/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */ #include #include #include #include #include #include /* external functions */ extern char *malloc(); extern int getopt(); extern void exit(); extern int atoi(); extern int _filbuf(); extern char *optarg; extern int optind, opterr; /* static functions */ static void extract(); static void replace(); static void yankstr(); static void badformat(); static void prstr(); static int getachar(); static void usage(); /* static variables */ static int eflg; /* find strings in source file(s) */ 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 Lineno; /* line number in source file */ static int Posno; /* character position within line */ static int flag; /* sets when newline is encountered */ static jmp_buf to_eof; main(argc, argv) int argc; char *argv[]; { int ch; while ((ch = getopt(argc, argv, "erd")) != -1) switch(ch) { case 'e': if (rflg) errflg++; else eflg++; continue; case 'r': if (eflg) errflg++; else rflg++; continue; case 'd': if (eflg) errflg++; else dflg++; continue; default: 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); exit(1); } repbufp = repstr; repstr = strchr(repbufp,':'); if (repstr == (char *)NULL) badformat(curline); *repstr++ = '\0'; cp = repbufp; 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); exit(1); } curmsgno = atoi(repbufp); /* move up to this line */ while (Lineno != curlineno ) { if (outp != outbuf) { while(*inp != '\0') *outp++ = *inp++; *outp = '\0'; (void)fputs(outbuf,stdout); } else if (*linebuf != '\0') (void)fputs(linebuf,stdout); outp = outbuf; inp = linebuf; if (fgets(linebuf, sizeof linebuf, fi) == (char *)NULL) { (void)fprintf(stderr, "read error\n"); exit(1); } Lineno++; Posno = 0; } if (Posno > curposno) { (void)fprintf(stderr, "Bad input record line number %d\n",Lineno); exit(1); } while (Posno != curposno) { *outp++ = *inp++; Posno++; } if (*inp != '"') { 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); exit(1); } cont_str++; Lineno++; } if (cont_str) { cp = linebuf; 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); exit(1); } inp = cp; Posno = cp - linebuf; } if (dflg) outp += sprintf(outp,"gettxt(\"%s:%d\", \"%s\")",msgfile, curmsgno, repstr); else outp += sprintf(outp,"gettxt(\"%s:%d\", \"\")",msgfile,curmsgno); if (!cont_str) { inp += strlen(repstr)+2; Posno += strlen(repstr)+2; } else cont_str = 0; } if (outp != outbuf) { while(*inp != '\0') *outp++ = *inp++; *outp = '\0'; (void)fputs(outbuf,stdout); } while(fgets(linebuf,sizeof linebuf, fi) != (char *)NULL) (void)fputs(linebuf, stdout); } static void badformat(line) char *line; { (void)fprintf(stderr, "exstr: ERROR: stdin: Badly formatted replacement string\n%s", line); exit(1); }