xref: /minix3/external/bsd/nvi/dist/catalog/dump.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: dump.c,v 1.4 2014/01/28 20:43:55 joerg Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994
484d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
584d9c625SLionel Sambuc  *
684d9c625SLionel Sambuc  * %sccs.include.redist.c%
784d9c625SLionel Sambuc  */
884d9c625SLionel Sambuc 
9*0a6a1f1dSLionel Sambuc #if defined(__NetBSD__)
10*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
11*0a6a1f1dSLionel Sambuc #if 0
1284d9c625SLionel Sambuc #ifndef lint
1384d9c625SLionel Sambuc static char copyright[] =
1484d9c625SLionel Sambuc "%Z% Copyright (c) 1992, 1993, 1994\n\
1584d9c625SLionel Sambuc 	The Regents of the University of California.  All rights reserved.\n";
1684d9c625SLionel Sambuc #endif /* not lint */
17*0a6a1f1dSLionel Sambuc #else
18*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: dump.c,v 1.4 2014/01/28 20:43:55 joerg Exp $");
19*0a6a1f1dSLionel Sambuc #endif
20*0a6a1f1dSLionel Sambuc #endif
2184d9c625SLionel Sambuc 
2284d9c625SLionel Sambuc #include <ctype.h>
2384d9c625SLionel Sambuc #include <stdio.h>
2484d9c625SLionel Sambuc #include <stdlib.h>
2584d9c625SLionel Sambuc 
2684d9c625SLionel Sambuc static void
parse(fp)2784d9c625SLionel Sambuc parse(fp)
2884d9c625SLionel Sambuc 	FILE *fp;
2984d9c625SLionel Sambuc {
3084d9c625SLionel Sambuc 	int ch, s1, s2, s3;
3184d9c625SLionel Sambuc 
3284d9c625SLionel Sambuc #define	TESTD(s) {							\
3384d9c625SLionel Sambuc 	if ((s = getc(fp)) == EOF)					\
3484d9c625SLionel Sambuc 		return;							\
3584d9c625SLionel Sambuc 	if (!isdigit(s))						\
3684d9c625SLionel Sambuc 		continue;						\
3784d9c625SLionel Sambuc }
3884d9c625SLionel Sambuc #define	TESTP {								\
3984d9c625SLionel Sambuc 	if ((ch = getc(fp)) == EOF)					\
4084d9c625SLionel Sambuc 		return;							\
4184d9c625SLionel Sambuc 	if (ch != '|')							\
4284d9c625SLionel Sambuc 		continue;						\
4384d9c625SLionel Sambuc }
4484d9c625SLionel Sambuc #define	MOVEC(t) {							\
4584d9c625SLionel Sambuc 	do {								\
4684d9c625SLionel Sambuc 		if ((ch = getc(fp)) == EOF)				\
4784d9c625SLionel Sambuc 			return;						\
4884d9c625SLionel Sambuc 	} while (ch != (t));						\
4984d9c625SLionel Sambuc }
5084d9c625SLionel Sambuc 	for (;;) {
5184d9c625SLionel Sambuc 		MOVEC('"');
5284d9c625SLionel Sambuc 		TESTD(s1);
5384d9c625SLionel Sambuc 		TESTD(s2);
5484d9c625SLionel Sambuc 		TESTD(s3);
5584d9c625SLionel Sambuc 		TESTP;
5684d9c625SLionel Sambuc 		putchar('"');
5784d9c625SLionel Sambuc 		putchar(s1);
5884d9c625SLionel Sambuc 		putchar(s2);
5984d9c625SLionel Sambuc 		putchar(s3);
6084d9c625SLionel Sambuc 		putchar('|');
6184d9c625SLionel Sambuc 		for (;;) {		/* dump to end quote. */
6284d9c625SLionel Sambuc 			if ((ch = getc(fp)) == EOF)
6384d9c625SLionel Sambuc 				return;
6484d9c625SLionel Sambuc 			putchar(ch);
6584d9c625SLionel Sambuc 			if (ch == '"')
6684d9c625SLionel Sambuc 				break;
6784d9c625SLionel Sambuc 			if (ch == '\\') {
6884d9c625SLionel Sambuc 				if ((ch = getc(fp)) == EOF)
6984d9c625SLionel Sambuc 					return;
7084d9c625SLionel Sambuc 				putchar(ch);
7184d9c625SLionel Sambuc 			}
7284d9c625SLionel Sambuc 		}
7384d9c625SLionel Sambuc 		putchar('\n');
7484d9c625SLionel Sambuc 	}
7584d9c625SLionel Sambuc }
7684d9c625SLionel Sambuc 
7784d9c625SLionel Sambuc int
main(argc,argv)7884d9c625SLionel Sambuc main(argc, argv)
7984d9c625SLionel Sambuc 	int argc;
8084d9c625SLionel Sambuc 	char *argv[];
8184d9c625SLionel Sambuc {
8284d9c625SLionel Sambuc 	FILE *fp;
8384d9c625SLionel Sambuc 
8484d9c625SLionel Sambuc 	for (; *argv != NULL; ++argv) {
8584d9c625SLionel Sambuc 		if ((fp = fopen(*argv, "r")) == NULL) {
8684d9c625SLionel Sambuc 			perror(*argv);
8784d9c625SLionel Sambuc 			exit (1);
8884d9c625SLionel Sambuc 		}
8984d9c625SLionel Sambuc 		parse(fp);
9084d9c625SLionel Sambuc 		(void)fclose(fp);
9184d9c625SLionel Sambuc 	}
9284d9c625SLionel Sambuc 	exit (0);
9384d9c625SLionel Sambuc }
94