1*e0b8e63eSJohn Marino /*-
2*e0b8e63eSJohn Marino * Copyright (c) 1992, 1993, 1994
3*e0b8e63eSJohn Marino * The Regents of the University of California. All rights reserved.
4*e0b8e63eSJohn Marino *
5*e0b8e63eSJohn Marino * Redistribution and use in source and binary forms, with or without
6*e0b8e63eSJohn Marino * modification, are permitted provided that the following conditions
7*e0b8e63eSJohn Marino * are met:
8*e0b8e63eSJohn Marino * 1. Redistributions of source code must retain the above copyright
9*e0b8e63eSJohn Marino * notice, this list of conditions and the following disclaimer.
10*e0b8e63eSJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
11*e0b8e63eSJohn Marino * notice, this list of conditions and the following disclaimer in the
12*e0b8e63eSJohn Marino * documentation and/or other materials provided with the distribution.
13*e0b8e63eSJohn Marino * 3. Neither the name of the University nor the names of its contributors
14*e0b8e63eSJohn Marino * may be used to endorse or promote products derived from this software
15*e0b8e63eSJohn Marino * without specific prior written permission.
16*e0b8e63eSJohn Marino *
17*e0b8e63eSJohn Marino * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18*e0b8e63eSJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*e0b8e63eSJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*e0b8e63eSJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21*e0b8e63eSJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*e0b8e63eSJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*e0b8e63eSJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*e0b8e63eSJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*e0b8e63eSJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*e0b8e63eSJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*e0b8e63eSJohn Marino * SUCH DAMAGE.
28*e0b8e63eSJohn Marino */
29*e0b8e63eSJohn Marino
30*e0b8e63eSJohn Marino #include <ctype.h>
31*e0b8e63eSJohn Marino #include <stdio.h>
32*e0b8e63eSJohn Marino
33*e0b8e63eSJohn Marino static void
parse(FILE * fp)34*e0b8e63eSJohn Marino parse(FILE *fp)
35*e0b8e63eSJohn Marino {
36*e0b8e63eSJohn Marino int ch, s1, s2, s3;
37*e0b8e63eSJohn Marino
38*e0b8e63eSJohn Marino #define TESTD(s) { \
39*e0b8e63eSJohn Marino if ((s = getc(fp)) == EOF) \
40*e0b8e63eSJohn Marino return; \
41*e0b8e63eSJohn Marino if (!isdigit(s)) \
42*e0b8e63eSJohn Marino continue; \
43*e0b8e63eSJohn Marino }
44*e0b8e63eSJohn Marino #define TESTP { \
45*e0b8e63eSJohn Marino if ((ch = getc(fp)) == EOF) \
46*e0b8e63eSJohn Marino return; \
47*e0b8e63eSJohn Marino if (ch != '|') \
48*e0b8e63eSJohn Marino continue; \
49*e0b8e63eSJohn Marino }
50*e0b8e63eSJohn Marino #define MOVEC(t) { \
51*e0b8e63eSJohn Marino do { \
52*e0b8e63eSJohn Marino if ((ch = getc(fp)) == EOF) \
53*e0b8e63eSJohn Marino return; \
54*e0b8e63eSJohn Marino } while (ch != (t)); \
55*e0b8e63eSJohn Marino }
56*e0b8e63eSJohn Marino for (;;) {
57*e0b8e63eSJohn Marino MOVEC('"');
58*e0b8e63eSJohn Marino TESTD(s1);
59*e0b8e63eSJohn Marino TESTD(s2);
60*e0b8e63eSJohn Marino TESTD(s3);
61*e0b8e63eSJohn Marino TESTP;
62*e0b8e63eSJohn Marino putchar('"');
63*e0b8e63eSJohn Marino putchar(s1);
64*e0b8e63eSJohn Marino putchar(s2);
65*e0b8e63eSJohn Marino putchar(s3);
66*e0b8e63eSJohn Marino putchar('|');
67*e0b8e63eSJohn Marino for (;;) { /* dump to end quote. */
68*e0b8e63eSJohn Marino if ((ch = getc(fp)) == EOF)
69*e0b8e63eSJohn Marino return;
70*e0b8e63eSJohn Marino putchar(ch);
71*e0b8e63eSJohn Marino if (ch == '"')
72*e0b8e63eSJohn Marino break;
73*e0b8e63eSJohn Marino if (ch == '\\') {
74*e0b8e63eSJohn Marino if ((ch = getc(fp)) == EOF)
75*e0b8e63eSJohn Marino return;
76*e0b8e63eSJohn Marino putchar(ch);
77*e0b8e63eSJohn Marino }
78*e0b8e63eSJohn Marino }
79*e0b8e63eSJohn Marino putchar('\n');
80*e0b8e63eSJohn Marino }
81*e0b8e63eSJohn Marino }
82*e0b8e63eSJohn Marino
83*e0b8e63eSJohn Marino int
main(int argc,char * argv[])84*e0b8e63eSJohn Marino main(int argc, char *argv[])
85*e0b8e63eSJohn Marino {
86*e0b8e63eSJohn Marino FILE *fp;
87*e0b8e63eSJohn Marino
88*e0b8e63eSJohn Marino for (; *argv != NULL; ++argv) {
89*e0b8e63eSJohn Marino if ((fp = fopen(*argv, "r")) == NULL) {
90*e0b8e63eSJohn Marino perror(*argv);
91*e0b8e63eSJohn Marino return (1);
92*e0b8e63eSJohn Marino }
93*e0b8e63eSJohn Marino parse(fp);
94*e0b8e63eSJohn Marino (void)fclose(fp);
95*e0b8e63eSJohn Marino }
96*e0b8e63eSJohn Marino return (0);
97*e0b8e63eSJohn Marino }
98