5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 1998 Gerald Combs
9 # SPDX-License-Identifier: GPL-2.0-or-later
13 takes the file listed as the first argument and creates the file listed
14 as the second argument. It takes a PostScript file and creates a C source
19 Ported to Python from rdps.c.
26 def ps_clean_string(raw_str
):
38 def start_code(fd
, name
):
39 fd
.write("static const char ps_%s[] =\n" % name
)
42 def write_code(fd
, raw_str
):
43 ps_str
= ps_clean_string(raw_str
)
44 fd
.write("\t\"%s\"\n" % ps_str
)
47 def end_code(fd
, name
):
50 fd
.write("void print_ps_%s(FILE *fd) {\n" % name
)
51 fd
.write("\tfwrite(ps_%s, sizeof ps_%s - 1, 1, fd);\n" % ( name
, name
) )
55 def exit_err(msg
=None, *param
):
57 sys
.stderr
.write(msg
% param
)
63 STATE_PREAMBLE
= 'preamble'
64 STATE_FINALE
= 'finale'
70 if len(sys
.argv
) != 3:
71 exit_err("%s: input_file output_file\n", __file__
)
73 input = open(sys
.argv
[1], 'r')
74 output
= open(sys
.argv
[2], 'w')
76 script_name
= os
.path
.split(__file__
)[-1]
84 * Definitions for generating PostScript(R) packet output.
86 * Wireshark - Network traffic analyzer
87 * By Gerald Combs <gerald@wireshark.org>
88 * Copyright 1998 Gerald Combs
90 * SPDX-License-Identifier: GPL-2.0-or-later
100 #line = line.rstrip()
101 if state
== STATE_NULL
:
102 if line
.startswith("% ---- wireshark preamble start ---- %"):
103 state
= STATE_PREAMBLE
104 start_code(output
, "preamble")
106 elif line
.startswith("% ---- wireshark finale start ---- %"):
108 start_code(output
, "finale")
110 elif state
== STATE_PREAMBLE
:
111 if line
.startswith("% ---- wireshark preamble end ---- %"):
113 end_code(output
, "preamble")
116 write_code(output
, line
)
117 elif state
== STATE_FINALE
:
118 if line
.startswith("% ---- wireshark finale end ---- %"):
120 end_code(output
, "finale")
123 write_code(output
, line
)
125 exit_err("NO MATCH:%s", line
)
129 if __name__
== "__main__":
133 # Editor modelines - https://www.wireshark.org/tools/modelines.html
137 # indent-tabs-mode: nil
140 # vi: set shiftwidth=4 expandtab:
141 # :indentSize=4:noTabs=true: