119304Speter/*-
219304Speter * Copyright (c) 1992, 1993, 1994
319304Speter *	The Regents of the University of California.  All rights reserved.
419304Speter *
519304Speter * Redistribution and use in source and binary forms, with or without
619304Speter * modification, are permitted provided that the following conditions
719304Speter * are met:
819304Speter * 1. Redistributions of source code must retain the above copyright
919304Speter *    notice, this list of conditions and the following disclaimer.
1019304Speter * 2. Redistributions in binary form must reproduce the above copyright
1119304Speter *    notice, this list of conditions and the following disclaimer in the
1219304Speter *    documentation and/or other materials provided with the distribution.
1319304Speter * 3. All advertising materials mentioning features or use of this software
1419304Speter *    must display the following acknowledgement:
1519304Speter *	This product includes software developed by the University of
1619304Speter *	California, Berkeley and its contributors.
1719304Speter * 4. Neither the name of the University nor the names of its contributors
1819304Speter *    may be used to endorse or promote products derived from this software
1919304Speter *    without specific prior written permission.
2019304Speter *
2119304Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2219304Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2319304Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2419304Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2519304Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2619304Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2719304Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2819304Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2919304Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3019304Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3119304Speter * SUCH DAMAGE.
3219304Speter */
3319304Speter
3419304Speter#ifndef lint
3519304Speterstatic char copyright[] =
3619304Speter"@(#) Copyright (c) 1992, 1993, 1994\n\
3719304Speter	The Regents of the University of California.  All rights reserved.\n";
3819304Speter#endif /* not lint */
3919304Speter
4019304Speter#ifndef lint
4119304Speterstatic char sccsid[] = "@(#)dump.c	8.1 (Berkeley) 8/31/94";
4219304Speter#endif /* not lint */
4319304Speter
4419304Speter#include <ctype.h>
4519304Speter#include <stdio.h>
4619304Speter
4719304Speterstatic void
4819304Speterparse(fp)
4919304Speter	FILE *fp;
5019304Speter{
5119304Speter	int ch, s1, s2, s3;
5219304Speter
5319304Speter#define	TESTD(s) {							\
5419304Speter	if ((s = getc(fp)) == EOF)					\
5519304Speter		return;							\
5619304Speter	if (!isdigit(s))						\
5719304Speter		continue;						\
5819304Speter}
5919304Speter#define	TESTP {								\
6019304Speter	if ((ch = getc(fp)) == EOF)					\
6119304Speter		return;							\
6219304Speter	if (ch != '|')							\
6319304Speter		continue;						\
6419304Speter}
6519304Speter#define	MOVEC(t) {							\
6619304Speter	do {								\
6719304Speter		if ((ch = getc(fp)) == EOF)				\
6819304Speter			return;						\
6919304Speter	} while (ch != (t));						\
7019304Speter}
7119304Speter	for (;;) {
7219304Speter		MOVEC('"');
7319304Speter		TESTD(s1);
7419304Speter		TESTD(s2);
7519304Speter		TESTD(s3);
7619304Speter		TESTP;
7719304Speter		putchar('"');
7819304Speter		putchar(s1);
7919304Speter		putchar(s2);
8019304Speter		putchar(s3);
8119304Speter		putchar('|');
8219304Speter		for (;;) {		/* dump to end quote. */
8319304Speter			if ((ch = getc(fp)) == EOF)
8419304Speter				return;
8519304Speter			putchar(ch);
8619304Speter			if (ch == '"')
8719304Speter				break;
8819304Speter			if (ch == '\\') {
8919304Speter				if ((ch = getc(fp)) == EOF)
9019304Speter					return;
9119304Speter				putchar(ch);
9219304Speter			}
9319304Speter		}
9419304Speter		putchar('\n');
9519304Speter	}
9619304Speter}
9719304Speter
9819304Speterint
9919304Spetermain(argc, argv)
10019304Speter	int argc;
10119304Speter	char *argv[];
10219304Speter{
10319304Speter	FILE *fp;
10419304Speter
10519304Speter	for (; *argv != NULL; ++argv) {
10619304Speter		if ((fp = fopen(*argv, "r")) == NULL) {
10719304Speter			perror(*argv);
108254225Speter			return (1);
10919304Speter		}
11019304Speter		parse(fp);
11119304Speter		(void)fclose(fp);
11219304Speter	}
113254225Speter	return (0);
11419304Speter}
115