Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / tools / rdps.py
blobbaf9b2d0392e39a6e3fdd4ce4894b4089996046d
1 #!/usr/bin/env python3
3 # rdps.py
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
12 '''\
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
15 with 2 functions:
16 print_ps_preamble()
17 print_ps_finale()
19 Ported to Python from rdps.c.
20 '''
22 import sys
23 import os.path
26 def ps_clean_string(raw_str):
27 ps_str = ''
28 for c in raw_str:
29 if c == '\\':
30 ps_str += '\\\\'
31 elif c == '\n':
32 ps_str += '\\n'
33 else:
34 ps_str += c
35 return ps_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):
48 fd.write(";\n")
49 fd.write("\n")
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 ) )
52 fd.write("}\n\n\n")
55 def exit_err(msg=None, *param):
56 if msg is not None:
57 sys.stderr.write(msg % param)
58 sys.exit(1)
61 # Globals
62 STATE_NULL = 'null'
63 STATE_PREAMBLE = 'preamble'
64 STATE_FINALE = 'finale'
67 def main():
68 state = STATE_NULL
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]
78 output.write('''\
79 /* DO NOT EDIT
81 * Created by %s.
83 * ps.c
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
93 #include <stdio.h>
95 #include "ps.h"
97 ''' % script_name)
99 for line in input:
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")
105 continue
106 elif line.startswith("% ---- wireshark finale start ---- %"):
107 state = STATE_FINALE
108 start_code(output, "finale")
109 continue
110 elif state == STATE_PREAMBLE:
111 if line.startswith("% ---- wireshark preamble end ---- %"):
112 state = STATE_NULL
113 end_code(output, "preamble")
114 continue
115 else:
116 write_code(output, line)
117 elif state == STATE_FINALE:
118 if line.startswith("% ---- wireshark finale end ---- %"):
119 state = STATE_NULL
120 end_code(output, "finale")
121 continue
122 else:
123 write_code(output, line)
124 else:
125 exit_err("NO MATCH:%s", line)
127 sys.exit(0)
129 if __name__ == "__main__":
130 main()
133 # Editor modelines - https://www.wireshark.org/tools/modelines.html
135 # Local variables:
136 # c-basic-offset: 4
137 # indent-tabs-mode: nil
138 # End:
140 # vi: set shiftwidth=4 expandtab:
141 # :indentSize=4:noTabs=true: