17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
22884db8abSpetede /*
23884db8abSpetede * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24884db8abSpetede * Use is subject to license terms.
25884db8abSpetede */
26884db8abSpetede
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*bcc2c2b8SToomas Soome /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <stdio.h>
32*bcc2c2b8SToomas Soome #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include <ctype.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <signal.h>
367c478bd9Sstevel@tonic-gate #include <setjmp.h>
377c478bd9Sstevel@tonic-gate #include <string.h>
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate /* static functions */
407c478bd9Sstevel@tonic-gate
41*bcc2c2b8SToomas Soome static void extract(char *);
42*bcc2c2b8SToomas Soome static void replace(char *);
43*bcc2c2b8SToomas Soome static void yankstr(void);
44*bcc2c2b8SToomas Soome static void badformat(char *);
45*bcc2c2b8SToomas Soome static void prstr(char *, int, int);
46*bcc2c2b8SToomas Soome static int getachar(void);
47*bcc2c2b8SToomas Soome static void usage(void);
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate /* static variables */
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate static int eflg; /* find strings in source file(s) */
52884db8abSpetede static int dflg; /* use replaced string a second argument */
537c478bd9Sstevel@tonic-gate static int rflg; /* replace strings by function calls */
54884db8abSpetede static int errflg; /* syntax error on command line */
55884db8abSpetede static char *Fname; /* name of source file */
567c478bd9Sstevel@tonic-gate static int Lineno; /* line number in source file */
577c478bd9Sstevel@tonic-gate static int Posno; /* character position within line */
58884db8abSpetede static int flag; /* sets when newline is encountered */
597c478bd9Sstevel@tonic-gate static jmp_buf to_eof;
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate
620d8b5334Sceastha int
main(int argc,char * argv[])630d8b5334Sceastha main(int argc, char *argv[])
647c478bd9Sstevel@tonic-gate {
65884db8abSpetede int ch;
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate while ((ch = getopt(argc, argv, "erd")) != -1)
68884db8abSpetede switch (ch) {
69*bcc2c2b8SToomas Soome case 'e':
707c478bd9Sstevel@tonic-gate if (rflg)
717c478bd9Sstevel@tonic-gate errflg++;
727c478bd9Sstevel@tonic-gate else
737c478bd9Sstevel@tonic-gate eflg++;
747c478bd9Sstevel@tonic-gate continue;
75*bcc2c2b8SToomas Soome case 'r':
767c478bd9Sstevel@tonic-gate if (eflg)
777c478bd9Sstevel@tonic-gate errflg++;
787c478bd9Sstevel@tonic-gate else
797c478bd9Sstevel@tonic-gate rflg++;
807c478bd9Sstevel@tonic-gate continue;
81*bcc2c2b8SToomas Soome case 'd':
827c478bd9Sstevel@tonic-gate if (eflg)
837c478bd9Sstevel@tonic-gate errflg++;
847c478bd9Sstevel@tonic-gate else
857c478bd9Sstevel@tonic-gate dflg++;
867c478bd9Sstevel@tonic-gate continue;
87*bcc2c2b8SToomas Soome default:
887c478bd9Sstevel@tonic-gate errflg++;
897c478bd9Sstevel@tonic-gate }
90884db8abSpetede if (optind == argc || errflg)
917c478bd9Sstevel@tonic-gate usage();
927c478bd9Sstevel@tonic-gate if (!rflg)
93884db8abSpetede for (; optind < argc; optind++)
947c478bd9Sstevel@tonic-gate extract(argv[optind]);
957c478bd9Sstevel@tonic-gate else {
967c478bd9Sstevel@tonic-gate if (optind+1 != argc)
977c478bd9Sstevel@tonic-gate usage();
987c478bd9Sstevel@tonic-gate replace(argv[optind]);
997c478bd9Sstevel@tonic-gate }
100884db8abSpetede return (0);
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate
103*bcc2c2b8SToomas Soome static void
extract(char * name)104*bcc2c2b8SToomas Soome extract(char *name)
1057c478bd9Sstevel@tonic-gate {
106884db8abSpetede if (freopen(name, "r", stdin) == NULL) {
107884db8abSpetede (void) fprintf(
108884db8abSpetede stderr, "exstr: ERROR: couldn't open file '%s'\n", name);
1097c478bd9Sstevel@tonic-gate exit(1);
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate Fname = name;
1127c478bd9Sstevel@tonic-gate flag = 1;
1137c478bd9Sstevel@tonic-gate Lineno = 0;
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate if (setjmp(to_eof) != 0)
1167c478bd9Sstevel@tonic-gate return;
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate for (;;) {
1197c478bd9Sstevel@tonic-gate char ch;
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate ch = getachar();
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate switch (ch) {
1247c478bd9Sstevel@tonic-gate case '#':
1257c478bd9Sstevel@tonic-gate if (Posno != 0)
1267c478bd9Sstevel@tonic-gate continue;
1277c478bd9Sstevel@tonic-gate do {
1287c478bd9Sstevel@tonic-gate ch = getachar();
1297c478bd9Sstevel@tonic-gate } while (isspace(ch));
1307c478bd9Sstevel@tonic-gate if (ch == 'd')
1317c478bd9Sstevel@tonic-gate continue;
132*bcc2c2b8SToomas Soome while (getachar() != '\n')
133*bcc2c2b8SToomas Soome ;
1347c478bd9Sstevel@tonic-gate break;
1357c478bd9Sstevel@tonic-gate case '"':
1367c478bd9Sstevel@tonic-gate yankstr();
1377c478bd9Sstevel@tonic-gate break;
1387c478bd9Sstevel@tonic-gate case '\'':
1397c478bd9Sstevel@tonic-gate while ((ch = getachar()) != '\'')
1407c478bd9Sstevel@tonic-gate if (ch == '\\')
1417c478bd9Sstevel@tonic-gate ch = getachar();
1427c478bd9Sstevel@tonic-gate break;
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate case '/':
1457c478bd9Sstevel@tonic-gate ch = getachar();
1467c478bd9Sstevel@tonic-gate if (ch == '*') {
1477c478bd9Sstevel@tonic-gate int level = 0;
148884db8abSpetede while (level != 2) {
1497c478bd9Sstevel@tonic-gate ch = getachar();
1507c478bd9Sstevel@tonic-gate if (level == 0 && ch == '*')
1517c478bd9Sstevel@tonic-gate level++;
1527c478bd9Sstevel@tonic-gate else if (level == 1 && ch == '/')
1537c478bd9Sstevel@tonic-gate level++;
1547c478bd9Sstevel@tonic-gate else
1557c478bd9Sstevel@tonic-gate level = 0;
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate break;
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate
163*bcc2c2b8SToomas Soome static void
yankstr(void)164*bcc2c2b8SToomas Soome yankstr(void)
1657c478bd9Sstevel@tonic-gate {
1667c478bd9Sstevel@tonic-gate char cc;
1677c478bd9Sstevel@tonic-gate char dbuf[BUFSIZ];
1687c478bd9Sstevel@tonic-gate register char *dp = dbuf;
1697c478bd9Sstevel@tonic-gate int saved_posno;
1707c478bd9Sstevel@tonic-gate int saved_lineno;
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate saved_posno = Posno;
1737c478bd9Sstevel@tonic-gate saved_lineno = Lineno;
1747c478bd9Sstevel@tonic-gate while ((cc = getachar()) != '"') {
175884db8abSpetede if (cc == '\\') {
1767c478bd9Sstevel@tonic-gate *dp++ = cc;
1777c478bd9Sstevel@tonic-gate cc = getachar();
1787c478bd9Sstevel@tonic-gate }
1797c478bd9Sstevel@tonic-gate if (cc == '\n') {
1807c478bd9Sstevel@tonic-gate dp--;
1817c478bd9Sstevel@tonic-gate continue;
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate *dp++ = cc;
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate *dp = 0;
186884db8abSpetede prstr(dbuf, saved_lineno, saved_posno);
1877c478bd9Sstevel@tonic-gate }
1887c478bd9Sstevel@tonic-gate
189*bcc2c2b8SToomas Soome static void
prstr(char * cp,int lineno,int posno)190*bcc2c2b8SToomas Soome prstr(char *cp, int lineno, int posno)
1917c478bd9Sstevel@tonic-gate {
1927c478bd9Sstevel@tonic-gate if (eflg)
193884db8abSpetede (void) fprintf(stdout, "%s:%d:%d:::%s\n", Fname, lineno, posno,
194884db8abSpetede cp);
1957c478bd9Sstevel@tonic-gate else
196884db8abSpetede (void) fprintf(stdout, "%s:%s\n", Fname, cp);
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate
200*bcc2c2b8SToomas Soome static void
usage(void)201*bcc2c2b8SToomas Soome usage(void)
2027c478bd9Sstevel@tonic-gate {
203884db8abSpetede (void) fprintf(stderr, "usage: exstr [-e] files\n");
204884db8abSpetede (void) fprintf(stderr, "or : exstr -r [-d] file\n");
2057c478bd9Sstevel@tonic-gate exit(1);
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate
208*bcc2c2b8SToomas Soome static int
getachar(void)209*bcc2c2b8SToomas Soome getachar(void)
2107c478bd9Sstevel@tonic-gate {
2117c478bd9Sstevel@tonic-gate int cc;
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate cc = getchar();
2147c478bd9Sstevel@tonic-gate if (flag) {
2157c478bd9Sstevel@tonic-gate Lineno++;
2167c478bd9Sstevel@tonic-gate Posno = 0;
2177c478bd9Sstevel@tonic-gate flag = 0;
2187c478bd9Sstevel@tonic-gate } else
2197c478bd9Sstevel@tonic-gate Posno++;
2207c478bd9Sstevel@tonic-gate if (cc == EOF)
2217c478bd9Sstevel@tonic-gate longjmp(to_eof, 1);
2227c478bd9Sstevel@tonic-gate if (cc == '\n')
2237c478bd9Sstevel@tonic-gate flag = 1;
224884db8abSpetede return (cc);
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate static void
replace(char * name)229*bcc2c2b8SToomas Soome replace(char *name)
2307c478bd9Sstevel@tonic-gate {
231884db8abSpetede char linebuf[BUFSIZ];
2327c478bd9Sstevel@tonic-gate char *cp;
2337c478bd9Sstevel@tonic-gate int curlineno; /* line number in strings file */
2347c478bd9Sstevel@tonic-gate int curposno; /* character position in string file */
2357c478bd9Sstevel@tonic-gate int savelineno = 0;
2367c478bd9Sstevel@tonic-gate int curmsgno; /* message number in strings file */
2377c478bd9Sstevel@tonic-gate int wrong_msg; /* invalid message number */
238884db8abSpetede int cont_str = 0; /* string continues in the next line */
2397c478bd9Sstevel@tonic-gate char *repstr;
2407c478bd9Sstevel@tonic-gate char repbuf[BUFSIZ], *repbufp;
2417c478bd9Sstevel@tonic-gate char curline[BUFSIZ];
2427c478bd9Sstevel@tonic-gate char outbuf[BUFSIZ];
243884db8abSpetede /* keeps track of character position within input file */
244884db8abSpetede char *inp;
245884db8abSpetede /* keeps track of character position within output buffer */
246884db8abSpetede char *outp;
2477c478bd9Sstevel@tonic-gate char *msgfile;
2487c478bd9Sstevel@tonic-gate FILE *fi; /* input source file pointer */
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate inp = linebuf;
2517c478bd9Sstevel@tonic-gate outp = outbuf;
2527c478bd9Sstevel@tonic-gate linebuf[0] = '\0';
2537c478bd9Sstevel@tonic-gate /* open input C source file */
254*bcc2c2b8SToomas Soome if ((fi = fopen(name, "r")) == NULL) {
255884db8abSpetede (void) fprintf(stderr,
256884db8abSpetede "exstr: ERROR: couldn't open file '%s'\n", name);
2577c478bd9Sstevel@tonic-gate exit(1);
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate Fname = name;
2607c478bd9Sstevel@tonic-gate
261884db8abSpetede (void) fprintf(stdout, "extern char *gettxt();\n");
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate /* process file containing the list of strings */
264*bcc2c2b8SToomas Soome while (fgets(repbuf, sizeof (repbuf), stdin) != NULL) {
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate wrong_msg = 0;
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate /* save a copy of the current line */
269884db8abSpetede (void) strcpy(curline, repbuf);
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate /* take apart the input string */
272884db8abSpetede repbufp = strchr(repbuf, ':');
273*bcc2c2b8SToomas Soome if (repbufp == NULL)
2747c478bd9Sstevel@tonic-gate badformat(curline);
2757c478bd9Sstevel@tonic-gate *repbufp++ = '\0';
2767c478bd9Sstevel@tonic-gate /* verify that string belongs to the input C source file */
277*bcc2c2b8SToomas Soome if (strcmp(repbuf, name) != 0)
2787c478bd9Sstevel@tonic-gate continue;
279884db8abSpetede repstr = strchr(repbufp, ':');
280*bcc2c2b8SToomas Soome if (repstr == NULL)
2817c478bd9Sstevel@tonic-gate badformat(curline);
2827c478bd9Sstevel@tonic-gate *repstr++ = '\0';
2837c478bd9Sstevel@tonic-gate curlineno = atoi(repbufp);
2847c478bd9Sstevel@tonic-gate if (curlineno < savelineno) {
285884db8abSpetede (void) fprintf(stderr,
286884db8abSpetede "exstr: ERROR: stdin: line out of order\n");
287884db8abSpetede (void) fprintf(stderr, "%s", curline);
2887c478bd9Sstevel@tonic-gate exit(1);
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate savelineno = curlineno;
2917c478bd9Sstevel@tonic-gate repbufp = repstr;
292884db8abSpetede repstr = strchr(repbufp, ':');
293*bcc2c2b8SToomas Soome if (repstr == NULL)
2947c478bd9Sstevel@tonic-gate badformat(curline);
2957c478bd9Sstevel@tonic-gate repstr[strlen(repstr) - 1 ] = '\0';
2967c478bd9Sstevel@tonic-gate *repstr++ = '\0';
2977c478bd9Sstevel@tonic-gate curposno = atoi(repbufp);
2987c478bd9Sstevel@tonic-gate repbufp = repstr;
299884db8abSpetede repstr = strchr(repbufp, ':');
300*bcc2c2b8SToomas Soome if (repstr == NULL)
3017c478bd9Sstevel@tonic-gate badformat(curline);
3027c478bd9Sstevel@tonic-gate *repstr++ = '\0';
3037c478bd9Sstevel@tonic-gate msgfile = repbufp;
304884db8abSpetede if (strlen(msgfile) > (size_t)14 || *msgfile == '\0') {
305884db8abSpetede (void) fprintf(stderr,
306884db8abSpetede "exstr: ERROR: stdin: invalid message file name "
307884db8abSpetede "'%s'\n", msgfile);
308884db8abSpetede (void) fprintf(stderr, "%s", curline);
3097c478bd9Sstevel@tonic-gate exit(1);
3107c478bd9Sstevel@tonic-gate }
3117c478bd9Sstevel@tonic-gate repbufp = repstr;
312884db8abSpetede repstr = strchr(repbufp, ':');
313*bcc2c2b8SToomas Soome if (repstr == NULL)
3147c478bd9Sstevel@tonic-gate badformat(curline);
3157c478bd9Sstevel@tonic-gate *repstr++ = '\0';
3167c478bd9Sstevel@tonic-gate cp = repbufp;
317884db8abSpetede while (*cp)
318884db8abSpetede if (!isdigit(*cp++)) {
3197c478bd9Sstevel@tonic-gate wrong_msg++;
3207c478bd9Sstevel@tonic-gate break;
3217c478bd9Sstevel@tonic-gate }
322884db8abSpetede if (*repbufp == '\0' || wrong_msg) {
323884db8abSpetede (void) fprintf(stderr, "exstr: ERROR: stdin: invalid "
324884db8abSpetede "message number '%s'\n", repbufp);
325884db8abSpetede (void) fprintf(stderr, "%s", curline);
3267c478bd9Sstevel@tonic-gate exit(1);
327884db8abSpetede }
3287c478bd9Sstevel@tonic-gate curmsgno = atoi(repbufp);
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate /* move up to this line */
331884db8abSpetede while (Lineno != curlineno) {
3327c478bd9Sstevel@tonic-gate if (outp != outbuf) {
333884db8abSpetede while (*inp != '\0')
3347c478bd9Sstevel@tonic-gate *outp++ = *inp++;
3357c478bd9Sstevel@tonic-gate *outp = '\0';
336884db8abSpetede (void) fputs(outbuf, stdout);
3377c478bd9Sstevel@tonic-gate } else if (*linebuf != '\0')
338884db8abSpetede (void) fputs(linebuf, stdout);
3397c478bd9Sstevel@tonic-gate outp = outbuf;
3407c478bd9Sstevel@tonic-gate inp = linebuf;
341884db8abSpetede if (fgets(linebuf,
342*bcc2c2b8SToomas Soome sizeof (linebuf), fi) == NULL) {
343884db8abSpetede (void) fprintf(stderr, "read error\n");
3447c478bd9Sstevel@tonic-gate exit(1);
3457c478bd9Sstevel@tonic-gate }
3467c478bd9Sstevel@tonic-gate Lineno++;
3477c478bd9Sstevel@tonic-gate Posno = 0;
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate if (Posno > curposno) {
350884db8abSpetede (void) fprintf(stderr,
351884db8abSpetede "Bad input record line number %d\n", Lineno);
3527c478bd9Sstevel@tonic-gate exit(1);
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate while (Posno != curposno) {
3557c478bd9Sstevel@tonic-gate *outp++ = *inp++;
3567c478bd9Sstevel@tonic-gate Posno++;
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate if (*inp != '"') {
359884db8abSpetede (void) fprintf(stderr, "exstr: ERROR: cannot replace "
360884db8abSpetede "string '%s' in line (%d) of file (%s)\n", repstr,
361884db8abSpetede Lineno, Fname);
3627c478bd9Sstevel@tonic-gate exit(1);
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate /* check if string continues in next line */
365884db8abSpetede while (inp[strlen(inp)-2] == '\\' &&
366884db8abSpetede inp[strlen(inp)-1] == '\n') {
367884db8abSpetede if (fgets(linebuf,
368*bcc2c2b8SToomas Soome sizeof (linebuf), fi) == NULL) {
369884db8abSpetede (void) fprintf(stderr, "exstr: ERROR: read "
370884db8abSpetede "error in file (%s)\n", Fname);
3717c478bd9Sstevel@tonic-gate exit(1);
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate cont_str++;
3747c478bd9Sstevel@tonic-gate Lineno++;
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate if (cont_str) {
3777c478bd9Sstevel@tonic-gate cp = linebuf;
378884db8abSpetede while (*cp != '\0' && *cp++ != '"')
379884db8abSpetede ;
3807c478bd9Sstevel@tonic-gate if (*cp == '\0') {
381884db8abSpetede (void) fprintf(stderr, "exstr: ERROR: cannot "
382884db8abSpetede "replace string '%s' in line (%d) of file "
383884db8abSpetede "(%s)\n", repstr, Lineno, Fname);
3847c478bd9Sstevel@tonic-gate exit(1);
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate inp = cp;
3877c478bd9Sstevel@tonic-gate Posno = cp - linebuf;
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate if (dflg)
390884db8abSpetede outp += snprintf(outp, BUFSIZ - (outp - outbuf),
391884db8abSpetede "gettxt(\"%s:%d\", \"%s\")", msgfile, curmsgno,
392884db8abSpetede repstr);
3937c478bd9Sstevel@tonic-gate else
394884db8abSpetede outp += snprintf(outp, BUFSIZ - (outp - outbuf),
395884db8abSpetede "gettxt(\"%s:%d\", \"\")", msgfile, curmsgno);
3967c478bd9Sstevel@tonic-gate if (!cont_str) {
3977c478bd9Sstevel@tonic-gate inp += strlen(repstr)+2;
3987c478bd9Sstevel@tonic-gate Posno += strlen(repstr)+2;
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate else
4017c478bd9Sstevel@tonic-gate cont_str = 0;
4027c478bd9Sstevel@tonic-gate }
4037c478bd9Sstevel@tonic-gate if (outp != outbuf) {
404884db8abSpetede while (*inp != '\0')
4057c478bd9Sstevel@tonic-gate *outp++ = *inp++;
4067c478bd9Sstevel@tonic-gate *outp = '\0';
407884db8abSpetede (void) fputs(outbuf, stdout);
4087c478bd9Sstevel@tonic-gate }
409*bcc2c2b8SToomas Soome while (fgets(linebuf, sizeof (linebuf), fi) != NULL)
410884db8abSpetede (void) fputs(linebuf, stdout);
411884db8abSpetede
412884db8abSpetede (void) fclose(fi);
4137c478bd9Sstevel@tonic-gate }
4147c478bd9Sstevel@tonic-gate
4157c478bd9Sstevel@tonic-gate static void
badformat(char * line)416*bcc2c2b8SToomas Soome badformat(char *line)
4177c478bd9Sstevel@tonic-gate {
418884db8abSpetede (void) fprintf(stderr, "exstr: ERROR: stdin: Badly formatted "
419884db8abSpetede "replacement string\n%s", line);
4207c478bd9Sstevel@tonic-gate exit(1);
4217c478bd9Sstevel@tonic-gate }
422