4 * $Id: rdps.c,v 1.3 1999/07/21 17:40:34 gram Exp $
5 * Ethereal - Network traffic analyzer
6 * By Gerald Combs <gerald@zing.org>
7 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 /* takes the file listed as the first argument and creates the file listed
26 as the second argument. It takes a PostScript file and creates a C program
42 #define BUFFER_SIZE 1024
44 void start_code(FILE *fd, char *func);
45 void write_code(FILE *fd, char *string);
46 void end_code(FILE *fd);
47 void ps_clean_string(unsigned char *out, const unsigned char *in,
50 enum ps_state { null, preamble, hex, finale };
52 int main(int argc, char **argv)
56 char buf[BUFFER_SIZE]; /* static sized buffer! */
57 enum ps_state state = null;
60 fprintf(stderr, "%s: input_file output_file\n", argv[0]);
64 if (!(input = fopen(argv[1], "r"))) {
65 fprintf(stderr, "%s: cannot open %s for input.\n", argv[0], argv[1]);
69 if (!(output = fopen(argv[2], "w"))) {
70 fprintf(stderr, "%s: cannot open %s for output.\n", argv[0], argv[2]);
74 fprintf(output, "/* Created by rdps.c. Do not edit! */\n\n"
75 "#include <stdio.h>\n\n"
76 "#include \"ps.h\"\n\n");
78 while (fgets(buf, BUFFER_SIZE - 1, input)) {
81 if (strcmp(buf, "% ---- ethereal preamble start ---- %\n") == 0) {
83 start_code(output, "preamble");
86 else if (strcmp(buf, "% ---- ethereal hex start ---- %\n") == 0) {
88 start_code(output, "hex");
91 else if (strcmp(buf, "% ---- ethereal finale start ---- %\n") == 0) {
93 start_code(output, "finale");
97 else if (state == preamble) {
98 if (strcmp(buf, "% ---- ethereal preamble end ---- %\n") == 0) {
104 write_code(output, buf);
107 else if (state == hex) {
108 if (strcmp(buf, "% ---- ethereal hex end ---- %\n") == 0) {
114 write_code(output, buf);
117 else if (state == finale) {
118 if (strcmp(buf, "% ---- ethereal finale end ---- %\n") == 0) {
124 write_code(output, buf);
128 fprintf(stderr, "NO MATCH:%s", buf);
135 void start_code(FILE *fd, char *func)
137 fprintf(fd, "/* Created by rdps.c. Do not edit! */\n");
138 fprintf(fd, "void print_ps_%s(FILE *fd) {\n", func);
141 void write_code(FILE *fd, char *string)
143 char psbuf[BUFFER_SIZE];
144 ps_clean_string(psbuf, string, BUFFER_SIZE);
145 fprintf(fd, "\tfprintf(fd, \"%s\");\n", psbuf);
148 void end_code(FILE *fd)
150 fprintf(fd, "}\n\n\n");
153 void ps_clean_string(unsigned char *out, const unsigned char *in,
159 for (rd = 0, wr = 0 ; wr < outbuf_size; rd++, wr++ ) {