7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
9 # Copyright 1998 Gerald Combs
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 takes the file listed as the first argument and creates the file listed
28 as the second argument. It takes a PostScript file and creates a C source
33 Ported to Python from rdps.c.
39 def ps_clean_string(raw_str):
52 def start_code(fd, func):
53 script_name = os.path.split(__file__)[-1]
54 fd.write("/* Created by %s. Do not edit! */\n" % script_name)
55 fd.write("void print_ps_%s(FILE *fd) {\n" % func)
57 def write_code(fd, raw_str):
58 ps_str = ps_clean_string(raw_str)
59 fd.write("\tfprintf(fd, \"%s\");\n" % ps_str)
64 def exit_err(msg=None, *param):
66 sys.stderr.write(msg % param)
71 STATE_PREAMBLE = 'preamble'
72 STATE_FINALE = 'finale'
77 if len(sys.argv) != 3:
78 exit_err("%s: input_file output_file\n", __file__)
80 input = open(sys.argv[1], 'r')
81 output = open(sys.argv[2], 'w')
83 script_name = os.path.split(__file__)[-1]
86 /* Created by %s. Do not edit! */
96 if state is STATE_NULL:
97 if line.startswith("% ---- wireshark preamble start ---- %"):
98 state = STATE_PREAMBLE
99 start_code(output, "preamble")
101 elif line.startswith("% ---- wireshark finale start ---- %"):
103 start_code(output, "finale")
105 elif state is STATE_PREAMBLE:
106 if line.startswith("% ---- wireshark preamble end ---- %"):
111 write_code(output, line)
112 elif state is STATE_FINALE:
113 if line.startswith("% ---- wireshark finale end ---- %"):
118 write_code(output, line)
120 exit_err("NO MATCH:%s", line)
124 if __name__ == "__main__":