1 /*        $NetBSD: dump.c,v 1.4 2014/01/28 20:43:55 joerg Exp $ */
2 /*-
3  * Copyright (c) 1992, 1993, 1994
4  *        The Regents of the University of California.  All rights reserved.
5  *
6  * %sccs.include.redist.c%
7  */
8 
9 #if defined(__NetBSD__)
10 #include <sys/cdefs.h>
11 #if 0
12 #ifndef lint
13 static char copyright[] =
14 "%Z% Copyright (c) 1992, 1993, 1994\n\
15           The Regents of the University of California.  All rights reserved.\n";
16 #endif /* not lint */
17 #else
18 __RCSID("$NetBSD: dump.c,v 1.4 2014/01/28 20:43:55 joerg Exp $");
19 #endif
20 #endif
21 
22 #include <ctype.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 
26 static void
parse(fp)27 parse(fp)
28           FILE *fp;
29 {
30           int ch, s1, s2, s3;
31 
32 #define   TESTD(s) {                                                                      \
33           if ((s = getc(fp)) == EOF)                                            \
34                     return;                                                               \
35           if (!isdigit(s))                                                      \
36                     continue;                                                   \
37 }
38 #define   TESTP {                                                                         \
39           if ((ch = getc(fp)) == EOF)                                           \
40                     return;                                                               \
41           if (ch != '|')                                                                  \
42                     continue;                                                   \
43 }
44 #define   MOVEC(t) {                                                                      \
45           do {                                                                            \
46                     if ((ch = getc(fp)) == EOF)                                 \
47                               return;                                                     \
48           } while (ch != (t));                                                            \
49 }
50           for (;;) {
51                     MOVEC('"');
52                     TESTD(s1);
53                     TESTD(s2);
54                     TESTD(s3);
55                     TESTP;
56                     putchar('"');
57                     putchar(s1);
58                     putchar(s2);
59                     putchar(s3);
60                     putchar('|');
61                     for (;;) {                    /* dump to end quote. */
62                               if ((ch = getc(fp)) == EOF)
63                                         return;
64                               putchar(ch);
65                               if (ch == '"')
66                                         break;
67                               if (ch == '\\') {
68                                         if ((ch = getc(fp)) == EOF)
69                                                   return;
70                                         putchar(ch);
71                               }
72                     }
73                     putchar('\n');
74           }
75 }
76 
77 int
main(argc,argv)78 main(argc, argv)
79           int argc;
80           char *argv[];
81 {
82           FILE *fp;
83 
84           for (; *argv != NULL; ++argv) {
85                     if ((fp = fopen(*argv, "r")) == NULL) {
86                               perror(*argv);
87                               exit (1);
88                     }
89                     parse(fp);
90                     (void)fclose(fp);
91           }
92           exit (0);
93 }
94