xref: /titanic_50/usr/src/cmd/deroff/deroff.c (revision b55148877d473978f0b46d593fd6213fa526fcc5)
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  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27*b5514887Smuffin /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*b5514887Smuffin /*	  All Rights Reserved  	*/
29*b5514887Smuffin 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <assert.h>
337c478bd9Sstevel@tonic-gate #include <errno.h>
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #include <string.h>
377c478bd9Sstevel@tonic-gate #include <locale.h>
387c478bd9Sstevel@tonic-gate #include <sys/varargs.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * Deroff command -- strip troff, eqn, and Tbl sequences from a file.
427c478bd9Sstevel@tonic-gate  * Has three flags argument, -w, to cause output one word per line
437c478bd9Sstevel@tonic-gate  * rather than in the original format.
447c478bd9Sstevel@tonic-gate  * -mm (or -ms) causes the corresponding macro's to be interpreted
457c478bd9Sstevel@tonic-gate  * so that just sentences are output
467c478bd9Sstevel@tonic-gate  * -ml  also gets rid of lists.
477c478bd9Sstevel@tonic-gate  * -i causes deroff to ignore .so and .nx commands.
487c478bd9Sstevel@tonic-gate  * Deroff follows .so and .nx commands, removes contents of macro
497c478bd9Sstevel@tonic-gate  * definitions, equations (both .EQ ... .EN and $...$),
507c478bd9Sstevel@tonic-gate  * Tbl command sequences, and Troff backslash constructions.
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * All input is through the C macro; the most recently read character
537c478bd9Sstevel@tonic-gate  * is in c.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #define	C	((c = getc(infile)) == EOF ? eof() : \
577c478bd9Sstevel@tonic-gate 		    ((c == ldelim) && (filesp == files) ? skeqn() : c))
587c478bd9Sstevel@tonic-gate #define	C1	((c = getc(infile)) == EOF ? eof() : c)
597c478bd9Sstevel@tonic-gate #define	SKIP	while (C != '\n')
607c478bd9Sstevel@tonic-gate #define	SKIP_TO_COM	SKIP; SKIP; pc = c; \
617c478bd9Sstevel@tonic-gate 			while ((C != '.') || (pc != '\n') || \
627c478bd9Sstevel@tonic-gate 			    (C > 'Z')) { \
637c478bd9Sstevel@tonic-gate 				pc = c; \
647c478bd9Sstevel@tonic-gate 			}
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #define	YES 1
677c478bd9Sstevel@tonic-gate #define	NO 0
687c478bd9Sstevel@tonic-gate #define	MS 0
697c478bd9Sstevel@tonic-gate #define	MM 1
707c478bd9Sstevel@tonic-gate #define	ONE 1
717c478bd9Sstevel@tonic-gate #define	TWO 2
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #define	NOCHAR -2
747c478bd9Sstevel@tonic-gate #define	SPECIAL 0
757c478bd9Sstevel@tonic-gate #define	APOS 1
767c478bd9Sstevel@tonic-gate #define	DIGIT 2
777c478bd9Sstevel@tonic-gate #define	LETTER 3
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	MAXLINESZ	512
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate static int wordflag = NO;
827c478bd9Sstevel@tonic-gate static int msflag = NO;
837c478bd9Sstevel@tonic-gate static int iflag = NO;
847c478bd9Sstevel@tonic-gate static int mac = MM;
857c478bd9Sstevel@tonic-gate static int disp = 0;
867c478bd9Sstevel@tonic-gate static int inmacro = NO;
877c478bd9Sstevel@tonic-gate static int intable = NO;
887c478bd9Sstevel@tonic-gate static int lindx;
897c478bd9Sstevel@tonic-gate static size_t linesize = MAXLINESZ;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate static char chars[128];  /* SPECIAL, APOS, DIGIT, or LETTER */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate static char *line = NULL;
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate static char c;
967c478bd9Sstevel@tonic-gate static int pc;
977c478bd9Sstevel@tonic-gate static int ldelim	= NOCHAR;
987c478bd9Sstevel@tonic-gate static int rdelim	= NOCHAR;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate static int argc;
1017c478bd9Sstevel@tonic-gate static char **argv;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate extern int optind;
1047c478bd9Sstevel@tonic-gate extern char *optarg;
1057c478bd9Sstevel@tonic-gate static char fname[50];
1067c478bd9Sstevel@tonic-gate static FILE *files[15];
1077c478bd9Sstevel@tonic-gate static FILE **filesp;
1087c478bd9Sstevel@tonic-gate static FILE *infile;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate static void backsl(void);
1117c478bd9Sstevel@tonic-gate static void comline(void);
1127c478bd9Sstevel@tonic-gate static char *copys(char *);
1137c478bd9Sstevel@tonic-gate static int eof(void);
1147c478bd9Sstevel@tonic-gate static void eqn(void);
1157c478bd9Sstevel@tonic-gate static void fatal(const char *, ...);
1167c478bd9Sstevel@tonic-gate static void fatal_msg(char *);
1177c478bd9Sstevel@tonic-gate static void getfname(void);
1187c478bd9Sstevel@tonic-gate static void macro(void);
1197c478bd9Sstevel@tonic-gate static FILE *opn(char *);
1207c478bd9Sstevel@tonic-gate static void putmac(char *, int);
1217c478bd9Sstevel@tonic-gate static void putwords(int);
1227c478bd9Sstevel@tonic-gate static void regline(int, int);
1237c478bd9Sstevel@tonic-gate static void sce(void);
124*b5514887Smuffin static int skeqn(void);
1257c478bd9Sstevel@tonic-gate static void sdis(char, char);
1267c478bd9Sstevel@tonic-gate static void stbl(void);
1277c478bd9Sstevel@tonic-gate static void tbl(void);
1287c478bd9Sstevel@tonic-gate static void usage(void);
129*b5514887Smuffin static void work(void)	__NORETURN;
1307c478bd9Sstevel@tonic-gate 
131*b5514887Smuffin int
main(int ac,char ** av)1327c478bd9Sstevel@tonic-gate main(int ac, char **av)
1337c478bd9Sstevel@tonic-gate {
1347c478bd9Sstevel@tonic-gate 	int i;
1357c478bd9Sstevel@tonic-gate 	int errflg = 0;
1367c478bd9Sstevel@tonic-gate 	int optchar;
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1397c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
1407c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
1417c478bd9Sstevel@tonic-gate #endif
1427c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1437c478bd9Sstevel@tonic-gate 	argc = ac;
1447c478bd9Sstevel@tonic-gate 	argv = av;
1457c478bd9Sstevel@tonic-gate 	while ((optchar = getopt(argc, argv, "wim:")) != EOF) {
1467c478bd9Sstevel@tonic-gate 		switch (optchar) {
1477c478bd9Sstevel@tonic-gate 		case 'w':
1487c478bd9Sstevel@tonic-gate 			wordflag = YES;
1497c478bd9Sstevel@tonic-gate 			break;
1507c478bd9Sstevel@tonic-gate 		case 'm':
1517c478bd9Sstevel@tonic-gate 			msflag = YES;
1527c478bd9Sstevel@tonic-gate 			if (*optarg == 'm')
1537c478bd9Sstevel@tonic-gate 				mac = MM;
1547c478bd9Sstevel@tonic-gate 			else if (*optarg == 's')
1557c478bd9Sstevel@tonic-gate 				mac = MS;
1567c478bd9Sstevel@tonic-gate 			else if (*optarg == 'l')
1577c478bd9Sstevel@tonic-gate 				disp = 1;
1587c478bd9Sstevel@tonic-gate 			else
1597c478bd9Sstevel@tonic-gate 				errflg++;
1607c478bd9Sstevel@tonic-gate 			break;
1617c478bd9Sstevel@tonic-gate 		case 'i':
1627c478bd9Sstevel@tonic-gate 			iflag = YES;
1637c478bd9Sstevel@tonic-gate 			break;
1647c478bd9Sstevel@tonic-gate 		case '?':
1657c478bd9Sstevel@tonic-gate 			errflg++;
1667c478bd9Sstevel@tonic-gate 		}
1677c478bd9Sstevel@tonic-gate 	}
168*b5514887Smuffin 	if (errflg) {
1697c478bd9Sstevel@tonic-gate 		usage();
170*b5514887Smuffin 		return (1);
171*b5514887Smuffin 	}
1727c478bd9Sstevel@tonic-gate 	if (optind == argc)
1737c478bd9Sstevel@tonic-gate 		infile = stdin;
1747c478bd9Sstevel@tonic-gate 	else
1757c478bd9Sstevel@tonic-gate 		infile = opn(argv[optind++]);
1767c478bd9Sstevel@tonic-gate 	files[0] = infile;
1777c478bd9Sstevel@tonic-gate 	filesp = &files[0];
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	for (i = 'a'; i <= 'z'; ++i)
1807c478bd9Sstevel@tonic-gate 		chars[i] = LETTER;
1817c478bd9Sstevel@tonic-gate 	for (i = 'A'; i <= 'Z'; ++i)
1827c478bd9Sstevel@tonic-gate 		chars[i] = LETTER;
1837c478bd9Sstevel@tonic-gate 	for (i = '0'; i <= '9'; ++i)
1847c478bd9Sstevel@tonic-gate 		chars[i] = DIGIT;
1857c478bd9Sstevel@tonic-gate 	chars['\''] = APOS;
1867c478bd9Sstevel@tonic-gate 	chars['&'] = APOS;
1877c478bd9Sstevel@tonic-gate 	work();
188*b5514887Smuffin 	/* NOTREACHED */
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate static int
skeqn(void)193*b5514887Smuffin skeqn(void)
1947c478bd9Sstevel@tonic-gate {
1957c478bd9Sstevel@tonic-gate 	while ((c = getc(infile)) != rdelim) {
1967c478bd9Sstevel@tonic-gate 		if (c == EOF) {
1977c478bd9Sstevel@tonic-gate 			c = eof();
1987c478bd9Sstevel@tonic-gate 		} else if (c == '"') {
1997c478bd9Sstevel@tonic-gate 			while ((c = getc(infile)) != '"') {
2007c478bd9Sstevel@tonic-gate 				if (c == EOF) {
2017c478bd9Sstevel@tonic-gate 					c = eof();
2027c478bd9Sstevel@tonic-gate 				} else if (c == '\\') {
2037c478bd9Sstevel@tonic-gate 					if ((c = getc(infile)) == EOF) {
2047c478bd9Sstevel@tonic-gate 						c = eof();
2057c478bd9Sstevel@tonic-gate 					}
2067c478bd9Sstevel@tonic-gate 				}
2077c478bd9Sstevel@tonic-gate 			}
2087c478bd9Sstevel@tonic-gate 		}
2097c478bd9Sstevel@tonic-gate 	}
2107c478bd9Sstevel@tonic-gate 	if (msflag) {
2117c478bd9Sstevel@tonic-gate 		return (c = 'x');
2127c478bd9Sstevel@tonic-gate 	}
2137c478bd9Sstevel@tonic-gate 	return (c = ' ');
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /* Functions calling opn() should ensure 'p' is non-null */
2187c478bd9Sstevel@tonic-gate static FILE *
opn(char * p)2197c478bd9Sstevel@tonic-gate opn(char *p)
2207c478bd9Sstevel@tonic-gate {
2217c478bd9Sstevel@tonic-gate 	FILE *fd;
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	assert(p != NULL);
2247c478bd9Sstevel@tonic-gate 	if ((fd = fopen(p, "r")) == NULL)
2257c478bd9Sstevel@tonic-gate 		fatal(gettext("Cannot open file %s: %s\n"), p, strerror(errno));
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	return (fd);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate static int
eof(void)2337c478bd9Sstevel@tonic-gate eof(void)
2347c478bd9Sstevel@tonic-gate {
2357c478bd9Sstevel@tonic-gate 	if (infile != stdin)
2367c478bd9Sstevel@tonic-gate 		(void) fclose(infile);
2377c478bd9Sstevel@tonic-gate 	if (filesp > files) {
2387c478bd9Sstevel@tonic-gate 		infile = *--filesp;
2397c478bd9Sstevel@tonic-gate 	} else if (optind < argc) {
2407c478bd9Sstevel@tonic-gate 		infile = opn(argv[optind++]);
2417c478bd9Sstevel@tonic-gate 	} else {
2427c478bd9Sstevel@tonic-gate 		exit(0);
2437c478bd9Sstevel@tonic-gate 	}
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	return (C);
2467c478bd9Sstevel@tonic-gate }
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate static void
getfname(void)2517c478bd9Sstevel@tonic-gate getfname(void)
2527c478bd9Sstevel@tonic-gate {
2537c478bd9Sstevel@tonic-gate 	char *p;
2547c478bd9Sstevel@tonic-gate 	struct chain {
2557c478bd9Sstevel@tonic-gate 		struct chain *nextp;
2567c478bd9Sstevel@tonic-gate 		char *datap;
2577c478bd9Sstevel@tonic-gate 	};
2587c478bd9Sstevel@tonic-gate 	struct chain *q;
2597c478bd9Sstevel@tonic-gate 	static struct chain *namechain = NULL;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	while (C == ' ')
2627c478bd9Sstevel@tonic-gate 		;
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	for (p = fname; ((*p = c) != '\n') && (c != ' ') && (c != '\t') &&
2657c478bd9Sstevel@tonic-gate 	    (c != '\\'); ++p) {
2667c478bd9Sstevel@tonic-gate 		(void) C;
2677c478bd9Sstevel@tonic-gate 	}
2687c478bd9Sstevel@tonic-gate 	*p = '\0';
2697c478bd9Sstevel@tonic-gate 	while (c != '\n') {
2707c478bd9Sstevel@tonic-gate 		(void) C;
2717c478bd9Sstevel@tonic-gate 	}
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	/* see if this name has already been used */
2747c478bd9Sstevel@tonic-gate 	for (q = namechain; q; q = q->nextp)
2757c478bd9Sstevel@tonic-gate 		if (strcmp(fname, q->datap) != 0) {
2767c478bd9Sstevel@tonic-gate 			fname[0] = '\0';
2777c478bd9Sstevel@tonic-gate 			return;
2787c478bd9Sstevel@tonic-gate 		}
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	q = (struct chain *)calloc(1, sizeof (*namechain));
2817c478bd9Sstevel@tonic-gate 	q->nextp = namechain;
2827c478bd9Sstevel@tonic-gate 	q->datap = copys(fname);
2837c478bd9Sstevel@tonic-gate 	namechain = q;
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate /*
2887c478bd9Sstevel@tonic-gate  * Functions calling fatal() should ensure 'format' and
2897c478bd9Sstevel@tonic-gate  * arguments are non-null.
2907c478bd9Sstevel@tonic-gate  */
2917c478bd9Sstevel@tonic-gate static void
fatal(const char * format,...)2927c478bd9Sstevel@tonic-gate fatal(const char *format, ...)
2937c478bd9Sstevel@tonic-gate {
2947c478bd9Sstevel@tonic-gate 	va_list	alist;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	assert(format != NULL);
2977c478bd9Sstevel@tonic-gate 	(void) fputs(gettext("deroff: "), stderr);
2987c478bd9Sstevel@tonic-gate 	va_start(alist, format);
2997c478bd9Sstevel@tonic-gate 	(void) vfprintf(stderr, format, alist);
3007c478bd9Sstevel@tonic-gate 	exit(1);
3017c478bd9Sstevel@tonic-gate }
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate /* Functions calling fatal_msg() should ensure 's' is non-null */
3047c478bd9Sstevel@tonic-gate static void
fatal_msg(char * s)3057c478bd9Sstevel@tonic-gate fatal_msg(char *s)
3067c478bd9Sstevel@tonic-gate {
3077c478bd9Sstevel@tonic-gate 	assert(s != NULL);
3087c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("deroff: %s\n"), s);
3097c478bd9Sstevel@tonic-gate 	exit(1);
3107c478bd9Sstevel@tonic-gate }
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate static void
usage(void)3137c478bd9Sstevel@tonic-gate usage(void)
3147c478bd9Sstevel@tonic-gate {
3157c478bd9Sstevel@tonic-gate 	(void) fputs(gettext(
3167c478bd9Sstevel@tonic-gate 	    "usage: deroff [ -w ] [ -m (m s l) ] [ -i ] "
3177c478bd9Sstevel@tonic-gate 	    "[ file ] ... \n"), stderr);
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate static void
work(void)3217c478bd9Sstevel@tonic-gate work(void)
3227c478bd9Sstevel@tonic-gate {
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	for (;;) {
3257c478bd9Sstevel@tonic-gate 		if ((C == '.') || (c == '\''))
3267c478bd9Sstevel@tonic-gate 			comline();
3277c478bd9Sstevel@tonic-gate 		else
3287c478bd9Sstevel@tonic-gate 			regline(NO, TWO);
3297c478bd9Sstevel@tonic-gate 	}
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate static void
regline(int macline,int cnst)3347c478bd9Sstevel@tonic-gate regline(int macline, int cnst)
3357c478bd9Sstevel@tonic-gate {
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 	if (line == NULL) {
3387c478bd9Sstevel@tonic-gate 		if ((line = (char *)malloc(linesize * sizeof (char))) == NULL) {
3397c478bd9Sstevel@tonic-gate 			fatal_msg(gettext("Cannot allocate memory"));
3407c478bd9Sstevel@tonic-gate 		}
3417c478bd9Sstevel@tonic-gate 	}
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	lindx = 0;
3447c478bd9Sstevel@tonic-gate 	line[lindx] = c;
3457c478bd9Sstevel@tonic-gate 	for (;;) {
3467c478bd9Sstevel@tonic-gate 		if (c == '\\') {
3477c478bd9Sstevel@tonic-gate 			line[lindx] = ' ';
3487c478bd9Sstevel@tonic-gate 			backsl();
3497c478bd9Sstevel@tonic-gate 			if (c == '%') {	/* no blank for hyphenation char */
3507c478bd9Sstevel@tonic-gate 				lindx--;
3517c478bd9Sstevel@tonic-gate 			}
3527c478bd9Sstevel@tonic-gate 		}
3537c478bd9Sstevel@tonic-gate 		if (c == '\n') {
3547c478bd9Sstevel@tonic-gate 			break;
3557c478bd9Sstevel@tonic-gate 		}
3567c478bd9Sstevel@tonic-gate 		/*
3577c478bd9Sstevel@tonic-gate 		 * We're just about to add another character to the line
3587c478bd9Sstevel@tonic-gate 		 * buffer so ensure we don't overrun it.
3597c478bd9Sstevel@tonic-gate 		 */
3607c478bd9Sstevel@tonic-gate 		if (++lindx >= linesize - 1) {
3617c478bd9Sstevel@tonic-gate 			linesize = linesize * 2;
3627c478bd9Sstevel@tonic-gate 			if ((line = (char *)realloc(line,
3637c478bd9Sstevel@tonic-gate 			    linesize * sizeof (char))) == NULL) {
3647c478bd9Sstevel@tonic-gate 				fatal_msg(gettext("Cannot allocate memory"));
3657c478bd9Sstevel@tonic-gate 			}
3667c478bd9Sstevel@tonic-gate 		}
3677c478bd9Sstevel@tonic-gate 		if (intable && (c == 'T')) {
3687c478bd9Sstevel@tonic-gate 			line[lindx] = C;
3697c478bd9Sstevel@tonic-gate 			if ((c == '{') || (c == '}')) {
3707c478bd9Sstevel@tonic-gate 				line[lindx - 1] = ' ';
3717c478bd9Sstevel@tonic-gate 				line[lindx] = C;
3727c478bd9Sstevel@tonic-gate 			}
3737c478bd9Sstevel@tonic-gate 		} else {
3747c478bd9Sstevel@tonic-gate 			line[lindx] = C;
3757c478bd9Sstevel@tonic-gate 		}
3767c478bd9Sstevel@tonic-gate 	}
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 	line[lindx] = '\0';
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	if (line[0] != '\0') {
3817c478bd9Sstevel@tonic-gate 		if (wordflag) {
3827c478bd9Sstevel@tonic-gate 			putwords(macline);
3837c478bd9Sstevel@tonic-gate 		} else if (macline) {
3847c478bd9Sstevel@tonic-gate 			putmac(line, cnst);
3857c478bd9Sstevel@tonic-gate 		} else {
3867c478bd9Sstevel@tonic-gate 			(void) puts(line);
3877c478bd9Sstevel@tonic-gate 		}
3887c478bd9Sstevel@tonic-gate 	}
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate static void
putmac(char * s,int cnst)3957c478bd9Sstevel@tonic-gate putmac(char *s, int cnst)
3967c478bd9Sstevel@tonic-gate {
3977c478bd9Sstevel@tonic-gate 	char *t;
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 	while (*s) {
4007c478bd9Sstevel@tonic-gate 		while ((*s == ' ') || (*s == '\t')) {
4017c478bd9Sstevel@tonic-gate 			(void) putchar(*s++);
4027c478bd9Sstevel@tonic-gate 		}
4037c478bd9Sstevel@tonic-gate 		for (t = s; (*t != ' ') && (*t != '\t') && (*t != '\0'); ++t)
4047c478bd9Sstevel@tonic-gate 			;
4057c478bd9Sstevel@tonic-gate 		if (*s == '\"')
4067c478bd9Sstevel@tonic-gate 			s++;
4077c478bd9Sstevel@tonic-gate 		if ((t > s + cnst) && (chars[s[0]] == LETTER) &&
4087c478bd9Sstevel@tonic-gate 		    (chars[s[1]] == LETTER)) {
4097c478bd9Sstevel@tonic-gate 			while (s < t) {
4107c478bd9Sstevel@tonic-gate 				if (*s == '\"')
4117c478bd9Sstevel@tonic-gate 					s++;
4127c478bd9Sstevel@tonic-gate 				else
4137c478bd9Sstevel@tonic-gate 					(void) putchar(*s++);
4147c478bd9Sstevel@tonic-gate 			}
4157c478bd9Sstevel@tonic-gate 		} else {
4167c478bd9Sstevel@tonic-gate 			s = t;
4177c478bd9Sstevel@tonic-gate 		}
4187c478bd9Sstevel@tonic-gate 	}
4197c478bd9Sstevel@tonic-gate 	(void) putchar('\n');
4207c478bd9Sstevel@tonic-gate }
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate static void
putwords(int macline)4257c478bd9Sstevel@tonic-gate putwords(int macline)	/* break into words for -w option */
4267c478bd9Sstevel@tonic-gate {
4277c478bd9Sstevel@tonic-gate 	char *p, *p1;
4287c478bd9Sstevel@tonic-gate 	int i, nlet;
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	for (p1 = line; ; ) {
4317c478bd9Sstevel@tonic-gate 		/* skip initial specials ampersands and apostrophes */
4327c478bd9Sstevel@tonic-gate 		while (chars[*p1] < DIGIT) {
4337c478bd9Sstevel@tonic-gate 			if (*p1++ == '\0')
4347c478bd9Sstevel@tonic-gate 				return;
4357c478bd9Sstevel@tonic-gate 		}
4367c478bd9Sstevel@tonic-gate 		nlet = 0;
4377c478bd9Sstevel@tonic-gate 		for (p = p1; (i = chars[*p]) != SPECIAL; ++p) {
4387c478bd9Sstevel@tonic-gate 			if (i == LETTER)
4397c478bd9Sstevel@tonic-gate 				++nlet;
4407c478bd9Sstevel@tonic-gate 		}
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate 		if ((!macline && (nlet > 1)) /* MDM definition of word */ ||
4437c478bd9Sstevel@tonic-gate 		    (macline && (nlet > 2) && (chars[p1[0]] == LETTER) &&
4447c478bd9Sstevel@tonic-gate 		    (chars[p1[1]] == LETTER))) {
4457c478bd9Sstevel@tonic-gate 			/* delete trailing ampersands and apostrophes */
4467c478bd9Sstevel@tonic-gate 			while ((p[-1] == '\'') || (p[-1] == '&')) {
4477c478bd9Sstevel@tonic-gate 				--p;
4487c478bd9Sstevel@tonic-gate 			}
4497c478bd9Sstevel@tonic-gate 			while (p1 < p) {
4507c478bd9Sstevel@tonic-gate 				(void) putchar(*p1++);
4517c478bd9Sstevel@tonic-gate 			}
4527c478bd9Sstevel@tonic-gate 			(void) putchar('\n');
4537c478bd9Sstevel@tonic-gate 		} else {
4547c478bd9Sstevel@tonic-gate 			p1 = p;
4557c478bd9Sstevel@tonic-gate 		}
4567c478bd9Sstevel@tonic-gate 	}
4577c478bd9Sstevel@tonic-gate }
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate static void
comline(void)4627c478bd9Sstevel@tonic-gate comline(void)
4637c478bd9Sstevel@tonic-gate {
4647c478bd9Sstevel@tonic-gate 	int c1, c2;
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate com:
4677c478bd9Sstevel@tonic-gate 	while ((C == ' ') || (c == '\t'))
4687c478bd9Sstevel@tonic-gate 		;
4697c478bd9Sstevel@tonic-gate comx:
4707c478bd9Sstevel@tonic-gate 	if ((c1 = c) == '\n')
4717c478bd9Sstevel@tonic-gate 		return;
4727c478bd9Sstevel@tonic-gate 	c2 = C;
4737c478bd9Sstevel@tonic-gate 	if ((c1 == '.') && (c2 != '.'))
4747c478bd9Sstevel@tonic-gate 		inmacro = NO;
4757c478bd9Sstevel@tonic-gate 	if (c2 == '\n')
4767c478bd9Sstevel@tonic-gate 		return;
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate 	if ((c1 == 'E') && (c2 == 'Q') && (filesp == files)) {
4797c478bd9Sstevel@tonic-gate 		eqn();
4807c478bd9Sstevel@tonic-gate 	} else if ((c1 == 'T') && ((c2 == 'S') || (c2 == 'C') ||
4817c478bd9Sstevel@tonic-gate 	    (c2 == '&')) && (filesp == files)) {
4827c478bd9Sstevel@tonic-gate 		if (msflag) {
4837c478bd9Sstevel@tonic-gate 			stbl();
4847c478bd9Sstevel@tonic-gate 		} else {
4857c478bd9Sstevel@tonic-gate 			tbl();
4867c478bd9Sstevel@tonic-gate 		}
4877c478bd9Sstevel@tonic-gate 	} else if ((c1 == 'T') && (c2 == 'E')) {
4887c478bd9Sstevel@tonic-gate 		intable = NO;
4897c478bd9Sstevel@tonic-gate 	} else if (!inmacro && (c1 == 'd') && (c2 == 'e')) {
4907c478bd9Sstevel@tonic-gate 		macro();
4917c478bd9Sstevel@tonic-gate 	} else if (!inmacro && (c1 == 'i') && (c2 == 'g')) {
4927c478bd9Sstevel@tonic-gate 		macro();
4937c478bd9Sstevel@tonic-gate 	} else if (!inmacro && (c1 == 'a') && (c2 == 'm')) {
4947c478bd9Sstevel@tonic-gate 		macro();
4957c478bd9Sstevel@tonic-gate 	} else if ((c1 == 's') && (c2 == 'o')) {
4967c478bd9Sstevel@tonic-gate 		if (iflag) {
4977c478bd9Sstevel@tonic-gate 			SKIP;
4987c478bd9Sstevel@tonic-gate 		} else {
4997c478bd9Sstevel@tonic-gate 			getfname();
5007c478bd9Sstevel@tonic-gate 			if (fname[0]) {
5017c478bd9Sstevel@tonic-gate 				infile = *++filesp = opn(fname);
5027c478bd9Sstevel@tonic-gate 			}
5037c478bd9Sstevel@tonic-gate 		}
5047c478bd9Sstevel@tonic-gate 	} else if ((c1 == 'n') && (c2 == 'x')) {
5057c478bd9Sstevel@tonic-gate 		if (iflag) {
5067c478bd9Sstevel@tonic-gate 			SKIP;
5077c478bd9Sstevel@tonic-gate 		} else {
5087c478bd9Sstevel@tonic-gate 			getfname();
5097c478bd9Sstevel@tonic-gate 			if (fname[0] == '\0') {
5107c478bd9Sstevel@tonic-gate 				exit(0);
5117c478bd9Sstevel@tonic-gate 			}
5127c478bd9Sstevel@tonic-gate 			if (infile != stdin) {
5137c478bd9Sstevel@tonic-gate 				(void) fclose(infile);
5147c478bd9Sstevel@tonic-gate 			}
5157c478bd9Sstevel@tonic-gate 			infile = *filesp = opn(fname);
5167c478bd9Sstevel@tonic-gate 		}
5177c478bd9Sstevel@tonic-gate 	} else if ((c1 == 'h') && (c2 == 'w')) {
5187c478bd9Sstevel@tonic-gate 		SKIP;
5197c478bd9Sstevel@tonic-gate 	} else if (msflag && (c1 == 'T') && (c2 == 'L')) {
5207c478bd9Sstevel@tonic-gate 		SKIP_TO_COM;
5217c478bd9Sstevel@tonic-gate 		goto comx;
5227c478bd9Sstevel@tonic-gate 	} else if (msflag && (c1 == 'N') && (c2 == 'R')) {
5237c478bd9Sstevel@tonic-gate 		SKIP;
5247c478bd9Sstevel@tonic-gate 	} else if (msflag && (c1 == 'A') && ((c2 == 'U') || (c2 == 'I'))) {
5257c478bd9Sstevel@tonic-gate 		if (mac == MM) {
5267c478bd9Sstevel@tonic-gate 			SKIP;
5277c478bd9Sstevel@tonic-gate 		} else {
5287c478bd9Sstevel@tonic-gate 			SKIP_TO_COM;
5297c478bd9Sstevel@tonic-gate 			goto comx;
5307c478bd9Sstevel@tonic-gate 		}
5317c478bd9Sstevel@tonic-gate 	} else if (msflag && (c1 == 'F') && (c2 == 'S')) {
5327c478bd9Sstevel@tonic-gate 		SKIP_TO_COM;
5337c478bd9Sstevel@tonic-gate 		goto comx;
5347c478bd9Sstevel@tonic-gate 	} else if (msflag && (c1 == 'S') && (c2 == 'H')) {
5357c478bd9Sstevel@tonic-gate 		SKIP_TO_COM;
5367c478bd9Sstevel@tonic-gate 		goto comx;
5377c478bd9Sstevel@tonic-gate 	} else if (msflag && (c1 == 'N') && (c2 == 'H')) {
5387c478bd9Sstevel@tonic-gate 		SKIP_TO_COM;
5397c478bd9Sstevel@tonic-gate 		goto comx;
5407c478bd9Sstevel@tonic-gate 	} else if (msflag && (c1 == 'O') && (c2 == 'K')) {
5417c478bd9Sstevel@tonic-gate 		SKIP_TO_COM;
5427c478bd9Sstevel@tonic-gate 		goto comx;
5437c478bd9Sstevel@tonic-gate 	} else if (msflag && (c1 == 'N') && (c2 == 'D')) {
5447c478bd9Sstevel@tonic-gate 		SKIP;
5457c478bd9Sstevel@tonic-gate 	} else if (msflag && (mac == MM) && (c1 == 'H') &&
5467c478bd9Sstevel@tonic-gate 	    ((c2 == ' ') || (c2 == 'U'))) {
5477c478bd9Sstevel@tonic-gate 		SKIP;
5487c478bd9Sstevel@tonic-gate 	} else if (msflag && (mac == MM) && (c2 == 'L')) {
5497c478bd9Sstevel@tonic-gate 		if (disp || (c1 == 'R')) {
5507c478bd9Sstevel@tonic-gate 			sdis('L', 'E');
5517c478bd9Sstevel@tonic-gate 		} else {
5527c478bd9Sstevel@tonic-gate 			SKIP;
5537c478bd9Sstevel@tonic-gate 			(void) putchar('.');
5547c478bd9Sstevel@tonic-gate 		}
5557c478bd9Sstevel@tonic-gate 	} else if (msflag && ((c1 == 'D') || (c1 == 'N') ||
5567c478bd9Sstevel@tonic-gate 	    (c1 == 'K') || (c1 == 'P')) && (c2 == 'S')) {
5577c478bd9Sstevel@tonic-gate 		sdis(c1, 'E');		/* removed RS-RE */
5587c478bd9Sstevel@tonic-gate 	} else if (msflag && (c1 == 'K' && c2 == 'F')) {
5597c478bd9Sstevel@tonic-gate 		sdis(c1, 'E');
5607c478bd9Sstevel@tonic-gate 	} else if (msflag && (c1 == 'n') && (c2 == 'f')) {
5617c478bd9Sstevel@tonic-gate 		sdis('f', 'i');
5627c478bd9Sstevel@tonic-gate 	} else if (msflag && (c1 == 'c') && (c2 == 'e')) {
5637c478bd9Sstevel@tonic-gate 		sce();
5647c478bd9Sstevel@tonic-gate 	} else {
5657c478bd9Sstevel@tonic-gate 		if ((c1 == '.') && (c2 == '.')) {
5667c478bd9Sstevel@tonic-gate 			while (C == '.')
5677c478bd9Sstevel@tonic-gate 				;
5687c478bd9Sstevel@tonic-gate 		}
5697c478bd9Sstevel@tonic-gate 		++inmacro;
5707c478bd9Sstevel@tonic-gate 		if ((c1 <= 'Z') && msflag) {
5717c478bd9Sstevel@tonic-gate 			regline(YES, ONE);
5727c478bd9Sstevel@tonic-gate 		} else {
5737c478bd9Sstevel@tonic-gate 			regline(YES, TWO);
5747c478bd9Sstevel@tonic-gate 		}
5757c478bd9Sstevel@tonic-gate 		--inmacro;
5767c478bd9Sstevel@tonic-gate 	}
5777c478bd9Sstevel@tonic-gate }
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate static void
macro(void)5827c478bd9Sstevel@tonic-gate macro(void)
5837c478bd9Sstevel@tonic-gate {
5847c478bd9Sstevel@tonic-gate 	if (msflag) {
5857c478bd9Sstevel@tonic-gate 		/* look for  .. */
5867c478bd9Sstevel@tonic-gate 		do {
5877c478bd9Sstevel@tonic-gate 			SKIP;
5887c478bd9Sstevel@tonic-gate 		} while ((C != '.') || (C != '.') || (C == '.'));
5897c478bd9Sstevel@tonic-gate 		if (c != '\n') {
5907c478bd9Sstevel@tonic-gate 			SKIP;
5917c478bd9Sstevel@tonic-gate 		}
5927c478bd9Sstevel@tonic-gate 		return;
5937c478bd9Sstevel@tonic-gate 	}
5947c478bd9Sstevel@tonic-gate 	SKIP;
5957c478bd9Sstevel@tonic-gate 	inmacro = YES;
5967c478bd9Sstevel@tonic-gate }
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate static void
sdis(char a1,char a2)6027c478bd9Sstevel@tonic-gate sdis(char a1, char a2)
6037c478bd9Sstevel@tonic-gate {
6047c478bd9Sstevel@tonic-gate 	int c1, c2;
6057c478bd9Sstevel@tonic-gate 	int eqnf;
6067c478bd9Sstevel@tonic-gate 	int notdone = 1;
6077c478bd9Sstevel@tonic-gate 	eqnf = 1;
6087c478bd9Sstevel@tonic-gate 	SKIP;
6097c478bd9Sstevel@tonic-gate 	while (notdone) {
6107c478bd9Sstevel@tonic-gate 		while (C != '.')
6117c478bd9Sstevel@tonic-gate 			SKIP;
6127c478bd9Sstevel@tonic-gate 		if ((c1 = C) == '\n')
6137c478bd9Sstevel@tonic-gate 			continue;
6147c478bd9Sstevel@tonic-gate 		if ((c2 = C) == '\n')
6157c478bd9Sstevel@tonic-gate 			continue;
6167c478bd9Sstevel@tonic-gate 		if ((c1 == a1) && (c2 == a2)) {
6177c478bd9Sstevel@tonic-gate 			SKIP;
6187c478bd9Sstevel@tonic-gate 			if (eqnf)
6197c478bd9Sstevel@tonic-gate 				(void) putchar('.');
6207c478bd9Sstevel@tonic-gate 			(void) putchar('\n');
6217c478bd9Sstevel@tonic-gate 			return;
6227c478bd9Sstevel@tonic-gate 		} else if ((a1 == 'D') && (c1 == 'E') && (c2 == 'Q')) {
6237c478bd9Sstevel@tonic-gate 			eqn();
6247c478bd9Sstevel@tonic-gate 			eqnf = 0;
6257c478bd9Sstevel@tonic-gate 		} else {
6267c478bd9Sstevel@tonic-gate 			SKIP;
6277c478bd9Sstevel@tonic-gate 		}
6287c478bd9Sstevel@tonic-gate 	}
6297c478bd9Sstevel@tonic-gate }
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate static void
tbl(void)6327c478bd9Sstevel@tonic-gate tbl(void)
6337c478bd9Sstevel@tonic-gate {
6347c478bd9Sstevel@tonic-gate 	while (C != '.')
6357c478bd9Sstevel@tonic-gate 		;
6367c478bd9Sstevel@tonic-gate 	SKIP;
6377c478bd9Sstevel@tonic-gate 	intable = YES;
6387c478bd9Sstevel@tonic-gate }
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate static void
stbl(void)6417c478bd9Sstevel@tonic-gate stbl(void)
6427c478bd9Sstevel@tonic-gate {
6437c478bd9Sstevel@tonic-gate 	while (C != '.')
6447c478bd9Sstevel@tonic-gate 		;
6457c478bd9Sstevel@tonic-gate 	SKIP_TO_COM;
6467c478bd9Sstevel@tonic-gate 	if ((c != 'T') || (C != 'E')) {
6477c478bd9Sstevel@tonic-gate 		SKIP;
6487c478bd9Sstevel@tonic-gate 		pc = c;
6497c478bd9Sstevel@tonic-gate 		while ((C != '.') || (pc != '\n') ||
6507c478bd9Sstevel@tonic-gate 		    (C != 'T') || (C != 'E')) {
6517c478bd9Sstevel@tonic-gate 			pc = c;
6527c478bd9Sstevel@tonic-gate 		}
6537c478bd9Sstevel@tonic-gate 	}
6547c478bd9Sstevel@tonic-gate }
6557c478bd9Sstevel@tonic-gate 
6567c478bd9Sstevel@tonic-gate static void
eqn(void)6577c478bd9Sstevel@tonic-gate eqn(void)
6587c478bd9Sstevel@tonic-gate {
6597c478bd9Sstevel@tonic-gate 	int c1, c2;
6607c478bd9Sstevel@tonic-gate 	int dflg;
6617c478bd9Sstevel@tonic-gate 	int last;
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 	last = 0;
6647c478bd9Sstevel@tonic-gate 	dflg = 1;
6657c478bd9Sstevel@tonic-gate 	SKIP;
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate 	for (;;) {
6687c478bd9Sstevel@tonic-gate 		if ((C1 == '.') || (c == '\'')) {
6697c478bd9Sstevel@tonic-gate 			while ((C1 == ' ') || (c == '\t'))
6707c478bd9Sstevel@tonic-gate 				;
6717c478bd9Sstevel@tonic-gate 			if ((c == 'E') && (C1 == 'N')) {
6727c478bd9Sstevel@tonic-gate 				SKIP;
6737c478bd9Sstevel@tonic-gate 				if (msflag && dflg) {
6747c478bd9Sstevel@tonic-gate 					(void) putchar('x');
6757c478bd9Sstevel@tonic-gate 					(void) putchar(' ');
6767c478bd9Sstevel@tonic-gate 					if (last) {
6777c478bd9Sstevel@tonic-gate 						(void) putchar('.');
6787c478bd9Sstevel@tonic-gate 						(void) putchar(' ');
6797c478bd9Sstevel@tonic-gate 					}
6807c478bd9Sstevel@tonic-gate 				}
6817c478bd9Sstevel@tonic-gate 				return;
6827c478bd9Sstevel@tonic-gate 			}
6837c478bd9Sstevel@tonic-gate 		} else if (c == 'd') {	/* look for delim */
6847c478bd9Sstevel@tonic-gate 			if ((C1 == 'e') && (C1 == 'l')) {
6857c478bd9Sstevel@tonic-gate 				if ((C1 == 'i') && (C1 == 'm')) {
6867c478bd9Sstevel@tonic-gate 					while (C1 == ' ')
6877c478bd9Sstevel@tonic-gate 						;
6887c478bd9Sstevel@tonic-gate 					if (((c1 = c) == '\n') ||
6897c478bd9Sstevel@tonic-gate 					    ((c2 = C1) == '\n') ||
6907c478bd9Sstevel@tonic-gate 					    ((c1 == 'o') && (c2 == 'f') &&
6917c478bd9Sstevel@tonic-gate 					    (C1 == 'f'))) {
6927c478bd9Sstevel@tonic-gate 						ldelim = NOCHAR;
6937c478bd9Sstevel@tonic-gate 						rdelim = NOCHAR;
6947c478bd9Sstevel@tonic-gate 					} else {
6957c478bd9Sstevel@tonic-gate 						ldelim = c1;
6967c478bd9Sstevel@tonic-gate 						rdelim = c2;
6977c478bd9Sstevel@tonic-gate 					}
6987c478bd9Sstevel@tonic-gate 				}
6997c478bd9Sstevel@tonic-gate 				dflg = 0;
7007c478bd9Sstevel@tonic-gate 			}
7017c478bd9Sstevel@tonic-gate 		}
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 		if (c != '\n') {
7047c478bd9Sstevel@tonic-gate 			while (C1 != '\n') {
7057c478bd9Sstevel@tonic-gate 				if (c == '.') {
7067c478bd9Sstevel@tonic-gate 					last = 1;
7077c478bd9Sstevel@tonic-gate 				} else {
7087c478bd9Sstevel@tonic-gate 					last = 0;
7097c478bd9Sstevel@tonic-gate 				}
7107c478bd9Sstevel@tonic-gate 			}
7117c478bd9Sstevel@tonic-gate 		}
7127c478bd9Sstevel@tonic-gate 	}
7137c478bd9Sstevel@tonic-gate }
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate static void
backsl(void)7187c478bd9Sstevel@tonic-gate backsl(void)	/* skip over a complete backslash construction */
7197c478bd9Sstevel@tonic-gate {
7207c478bd9Sstevel@tonic-gate 	int bdelim;
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate sw:	switch (C) {
7237c478bd9Sstevel@tonic-gate 	case '"':
7247c478bd9Sstevel@tonic-gate 		SKIP;
7257c478bd9Sstevel@tonic-gate 		return;
7267c478bd9Sstevel@tonic-gate 	case 's':
7277c478bd9Sstevel@tonic-gate 		if (C == '\\') {
7287c478bd9Sstevel@tonic-gate 			backsl();
7297c478bd9Sstevel@tonic-gate 		} else {
7307c478bd9Sstevel@tonic-gate 			while ((C >= '0') && (c <= '9'))
7317c478bd9Sstevel@tonic-gate 				;
7327c478bd9Sstevel@tonic-gate 			(void) ungetc(c, infile);
7337c478bd9Sstevel@tonic-gate 			c = '0';
7347c478bd9Sstevel@tonic-gate 		}
7357c478bd9Sstevel@tonic-gate 		lindx--;
7367c478bd9Sstevel@tonic-gate 		return;
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 	case 'f':
7397c478bd9Sstevel@tonic-gate 	case 'n':
7407c478bd9Sstevel@tonic-gate 	case '*':
7417c478bd9Sstevel@tonic-gate 		if (C != '(')
7427c478bd9Sstevel@tonic-gate 			return;
7437c478bd9Sstevel@tonic-gate 		/* FALLTHROUGH */
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 	case '(':
7467c478bd9Sstevel@tonic-gate 		if (C != '\n') {
7477c478bd9Sstevel@tonic-gate 			(void) C;
7487c478bd9Sstevel@tonic-gate 		}
7497c478bd9Sstevel@tonic-gate 		return;
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate 	case '$':
7527c478bd9Sstevel@tonic-gate 		(void) C;	/* discard argument number */
7537c478bd9Sstevel@tonic-gate 		return;
7547c478bd9Sstevel@tonic-gate 
7557c478bd9Sstevel@tonic-gate 	case 'b':
7567c478bd9Sstevel@tonic-gate 	case 'x':
7577c478bd9Sstevel@tonic-gate 	case 'v':
7587c478bd9Sstevel@tonic-gate 	case 'h':
7597c478bd9Sstevel@tonic-gate 	case 'w':
7607c478bd9Sstevel@tonic-gate 	case 'o':
7617c478bd9Sstevel@tonic-gate 	case 'l':
7627c478bd9Sstevel@tonic-gate 	case 'L':
7637c478bd9Sstevel@tonic-gate 		if ((bdelim = C) == '\n')
7647c478bd9Sstevel@tonic-gate 			return;
7657c478bd9Sstevel@tonic-gate 		while ((C != '\n') && (c != bdelim))
7667c478bd9Sstevel@tonic-gate 			if (c == '\\')
7677c478bd9Sstevel@tonic-gate 				backsl();
7687c478bd9Sstevel@tonic-gate 		return;
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate 	case '\\':
7717c478bd9Sstevel@tonic-gate 		if (inmacro)
7727c478bd9Sstevel@tonic-gate 			goto sw;
7737c478bd9Sstevel@tonic-gate 	default:
7747c478bd9Sstevel@tonic-gate 		return;
7757c478bd9Sstevel@tonic-gate 	}
7767c478bd9Sstevel@tonic-gate }
7777c478bd9Sstevel@tonic-gate 
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate static char *
copys(char * s)7827c478bd9Sstevel@tonic-gate copys(char *s)
7837c478bd9Sstevel@tonic-gate {
7847c478bd9Sstevel@tonic-gate 	char *t, *t0;
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate 	if ((t0 = t = calloc((unsigned)(strlen(s) + 1), sizeof (*t))) == NULL)
7877c478bd9Sstevel@tonic-gate 		fatal_msg(gettext("Cannot allocate memory"));
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 	while (*t++ = *s++)
7907c478bd9Sstevel@tonic-gate 		;
7917c478bd9Sstevel@tonic-gate 	return (t0);
7927c478bd9Sstevel@tonic-gate }
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate static void
sce(void)7957c478bd9Sstevel@tonic-gate sce(void)
7967c478bd9Sstevel@tonic-gate {
7977c478bd9Sstevel@tonic-gate 	char *ap;
7987c478bd9Sstevel@tonic-gate 	int n, i;
7997c478bd9Sstevel@tonic-gate 	char a[10];
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate 	for (ap = a; C != '\n'; ap++) {
8027c478bd9Sstevel@tonic-gate 		*ap = c;
8037c478bd9Sstevel@tonic-gate 		if (ap == &a[9]) {
8047c478bd9Sstevel@tonic-gate 			SKIP;
8057c478bd9Sstevel@tonic-gate 			ap = a;
8067c478bd9Sstevel@tonic-gate 			break;
8077c478bd9Sstevel@tonic-gate 		}
8087c478bd9Sstevel@tonic-gate 	}
8097c478bd9Sstevel@tonic-gate 	if (ap != a) {
8107c478bd9Sstevel@tonic-gate 		n = atoi(a);
8117c478bd9Sstevel@tonic-gate 	} else {
8127c478bd9Sstevel@tonic-gate 		n = 1;
8137c478bd9Sstevel@tonic-gate 	}
8147c478bd9Sstevel@tonic-gate 	for (i = 0; i < n; ) {
8157c478bd9Sstevel@tonic-gate 		if (C == '.') {
8167c478bd9Sstevel@tonic-gate 			if (C == 'c') {
8177c478bd9Sstevel@tonic-gate 				if (C == 'e') {
8187c478bd9Sstevel@tonic-gate 					while (C == ' ')
8197c478bd9Sstevel@tonic-gate 						;
8207c478bd9Sstevel@tonic-gate 					if (c == '0') {
8217c478bd9Sstevel@tonic-gate 						break;
8227c478bd9Sstevel@tonic-gate 					} else {
8237c478bd9Sstevel@tonic-gate 						SKIP;
8247c478bd9Sstevel@tonic-gate 					}
8257c478bd9Sstevel@tonic-gate 				} else {
8267c478bd9Sstevel@tonic-gate 					SKIP;
8277c478bd9Sstevel@tonic-gate 				}
8287c478bd9Sstevel@tonic-gate 			} else {
8297c478bd9Sstevel@tonic-gate 				SKIP;
8307c478bd9Sstevel@tonic-gate 			}
8317c478bd9Sstevel@tonic-gate 		} else {
8327c478bd9Sstevel@tonic-gate 			SKIP;
8337c478bd9Sstevel@tonic-gate 			i++;
8347c478bd9Sstevel@tonic-gate 		}
8357c478bd9Sstevel@tonic-gate 	}
8367c478bd9Sstevel@tonic-gate }
837