nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/usr/bin/env python
2 #
3 # rdps.py
4 #
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 1998 Gerald Combs
8 #
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.
13 #
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.
18 #
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #
23  
24 '''\
25 takes the file listed as the first argument and creates the file listed
26 as the second argument. It takes a PostScript file and creates a C source
27 with 2 functions:
28 print_ps_preamble()
29 print_ps_finale()
30  
31 Ported to Python from rdps.c.
32 '''
33  
34 import sys
35 import os.path
36  
37 def ps_clean_string(raw_str):
38 ps_str = ''
39 for c in raw_str:
40 if c == '\\':
41 ps_str += '\\\\'
42 elif c == '%':
43 ps_str += '%%'
44 elif c == '\n':
45 ps_str += '\\n'
46 else:
47 ps_str += c
48 return ps_str
49  
50 def start_code(fd, func):
51 script_name = os.path.split(__file__)[-1]
52 fd.write("void print_ps_%s(FILE *fd) {\n" % func)
53  
54 def write_code(fd, raw_str):
55 ps_str = ps_clean_string(raw_str)
56 fd.write("\tfprintf(fd, \"%s\");\n" % ps_str)
57  
58 def end_code(fd):
59 fd.write("}\n\n\n")
60  
61 def exit_err(msg=None, *param):
62 if msg is not None:
63 sys.stderr.write(msg % param)
64 sys.exit(1)
65  
66 # Globals
67 STATE_NULL = 'null'
68 STATE_PREAMBLE = 'preamble'
69 STATE_FINALE = 'finale'
70  
71 def main():
72 state = STATE_NULL;
73  
74 if len(sys.argv) != 3:
75 exit_err("%s: input_file output_file\n", __file__)
76  
77 input = open(sys.argv[1], 'r')
78 output = open(sys.argv[2], 'w')
79  
80 script_name = os.path.split(__file__)[-1]
81  
82 output.write('''\
83 /* DO NOT EDIT
84 *
85 * Created by %s.
86 *
87 * ps.c
88 * Definitions for generating PostScript(R) packet output.
89 *
90 * Wireshark - Network traffic analyzer
91 * By Gerald Combs <gerald@wireshark.org>
92 * Copyright 1998 Gerald Combs
93 *
94 * This program is free software; you can redistribute it and/or
95 * modify it under the terms of the GNU General Public License
96 * as published by the Free Software Foundation; either version 2
97 * of the License, or (at your option) any later version.
98 *
99 * This program is distributed in the hope that it will be useful,
100 * but WITHOUT ANY WARRANTY; without even the implied warranty of
101 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102 * GNU General Public License for more details.
103 *
104 * You should have received a copy of the GNU General Public License
105 * along with this program; if not, write to the Free Software
106 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
107 */
108  
109 #include <stdio.h>
110  
111 #include "ps.h"
112  
113 ''' % script_name)
114  
115 for line in input:
116 #line = line.rstrip()
117 if state is STATE_NULL:
118 if line.startswith("% ---- wireshark preamble start ---- %"):
119 state = STATE_PREAMBLE
120 start_code(output, "preamble")
121 continue
122 elif line.startswith("% ---- wireshark finale start ---- %"):
123 state = STATE_FINALE
124 start_code(output, "finale")
125 continue
126 elif state is STATE_PREAMBLE:
127 if line.startswith("% ---- wireshark preamble end ---- %"):
128 state = STATE_NULL
129 end_code(output)
130 continue
131 else:
132 write_code(output, line)
133 elif state is STATE_FINALE:
134 if line.startswith("% ---- wireshark finale end ---- %"):
135 state = STATE_NULL
136 end_code(output)
137 continue
138 else:
139 write_code(output, line)
140 else:
141 exit_err("NO MATCH:%s", line)
142  
143 sys.exit(0)
144  
145 if __name__ == "__main__":
146 main()
147  
148 #
149 # Editor modelines - http://www.wireshark.org/tools/modelines.html
150 #
151 # Local variables:
152 # c-basic-offset: 4
153 # indent-tabs-mode: nil
154 # End:
155 #
156 # vi: set shiftwidth=4 expandtab:
157 # :indentSize=4:noTabs=true:
158 #