5 * Ethereal - Network traffic analyzer
6 * By Gerald Combs <gerald@ethereal.com>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 /* takes the file listed as the first argument and creates the file listed
25 as the second argument. It takes a PostScript file and creates a C program
40 #define BUFFER_SIZE 1024
42 void start_code(FILE *fd, const char *func);
43 void write_code(FILE *fd, char *string);
44 void end_code(FILE *fd);
45 void ps_clean_string(char *out, const char *in,
48 enum ps_state { null, preamble, hex, finale };
50 int main(int argc, char **argv)
54 char buf[BUFFER_SIZE]; /* static sized buffer! */
55 enum ps_state state = null;
58 fprintf(stderr, "%s: input_file output_file\n", argv[0]);
62 if (!(input = fopen(argv[1], "r"))) {
63 fprintf(stderr, "%s: cannot open %s for input.\n", argv[0], argv[1]);
67 if (!(output = fopen(argv[2], "w"))) {
68 fprintf(stderr, "%s: cannot open %s for output.\n", argv[0], argv[2]);
72 fprintf(output, "/* Created by rdps.c. Do not edit! */\n\n"
73 "#include <stdio.h>\n\n"
74 "#include \"ps.h\"\n\n");
76 while (fgets(buf, BUFFER_SIZE - 1, input)) {
79 if (strcmp(buf, "% ---- ethereal preamble start ---- %\n") == 0) {
81 start_code(output, "preamble");
84 else if (strcmp(buf, "% ---- ethereal finale start ---- %\n") == 0) {
86 start_code(output, "finale");
90 else if (state == preamble) {
91 if (strcmp(buf, "% ---- ethereal preamble end ---- %\n") == 0) {
97 write_code(output, buf);
100 else if (state == hex) {
101 if (strcmp(buf, "% ---- ethereal hex end ---- %\n") == 0) {
107 write_code(output, buf);
110 else if (state == finale) {
111 if (strcmp(buf, "% ---- ethereal finale end ---- %\n") == 0) {
117 write_code(output, buf);
121 fprintf(stderr, "NO MATCH:%s", buf);
128 void start_code(FILE *fd, const char *func)
130 fprintf(fd, "/* Created by rdps.c. Do not edit! */\n");
131 fprintf(fd, "void print_ps_%s(FILE *fd) {\n", func);
134 void write_code(FILE *fd, char *string)
136 char psbuf[BUFFER_SIZE];
137 ps_clean_string(psbuf, string, BUFFER_SIZE);
138 fprintf(fd, "\tfprintf(fd, \"%s\");\n", psbuf);
141 void end_code(FILE *fd)
143 fprintf(fd, "}\n\n\n");
146 void ps_clean_string(char *out, const char *in,
152 for (rd = 0, wr = 0 ; wr < outbuf_size; rd++, wr++ ) {