3 * $Id: rdps.c,v 1.5 2002/08/28 21:00:41 jmayer Exp $
4 * Ethereal - Network traffic analyzer
5 * By Gerald Combs <gerald@ethereal.com>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 /* takes the file listed as the first argument and creates the file listed
24 as the second argument. It takes a PostScript file and creates a C program
39 #define BUFFER_SIZE 1024
41 void start_code(FILE *fd, char *func);
42 void write_code(FILE *fd, char *string);
43 void end_code(FILE *fd);
44 void ps_clean_string(unsigned char *out, const unsigned char *in,
47 enum ps_state { null, preamble, hex, finale };
49 int main(int argc, char **argv)
53 char buf[BUFFER_SIZE]; /* static sized buffer! */
54 enum ps_state state = null;
57 fprintf(stderr, "%s: input_file output_file\n", argv[0]);
61 if (!(input = fopen(argv[1], "r"))) {
62 fprintf(stderr, "%s: cannot open %s for input.\n", argv[0], argv[1]);
66 if (!(output = fopen(argv[2], "w"))) {
67 fprintf(stderr, "%s: cannot open %s for output.\n", argv[0], argv[2]);
71 fprintf(output, "/* Created by rdps.c. Do not edit! */\n\n"
72 "#include <stdio.h>\n\n"
73 "#include \"ps.h\"\n\n");
75 while (fgets(buf, BUFFER_SIZE - 1, input)) {
78 if (strcmp(buf, "% ---- ethereal preamble start ---- %\n") == 0) {
80 start_code(output, "preamble");
83 else if (strcmp(buf, "% ---- ethereal finale start ---- %\n") == 0) {
85 start_code(output, "finale");
89 else if (state == preamble) {
90 if (strcmp(buf, "% ---- ethereal preamble end ---- %\n") == 0) {
96 write_code(output, buf);
99 else if (state == hex) {
100 if (strcmp(buf, "% ---- ethereal hex end ---- %\n") == 0) {
106 write_code(output, buf);
109 else if (state == finale) {
110 if (strcmp(buf, "% ---- ethereal finale end ---- %\n") == 0) {
116 write_code(output, buf);
120 fprintf(stderr, "NO MATCH:%s", buf);
127 void start_code(FILE *fd, char *func)
129 fprintf(fd, "/* Created by rdps.c. Do not edit! */\n");
130 fprintf(fd, "void print_ps_%s(FILE *fd) {\n", func);
133 void write_code(FILE *fd, char *string)
135 char psbuf[BUFFER_SIZE];
136 ps_clean_string(psbuf, string, BUFFER_SIZE);
137 fprintf(fd, "\tfprintf(fd, \"%s\");\n", psbuf);
140 void end_code(FILE *fd)
142 fprintf(fd, "}\n\n\n");
145 void ps_clean_string(unsigned char *out, const unsigned char *in,
151 for (rd = 0, wr = 0 ; wr < outbuf_size; rd++, wr++ ) {