Revision 8d3bc517 scripts/qapi-visit.py
b/scripts/qapi-visit.py | ||
---|---|---|
139 | 139 |
name=name) |
140 | 140 |
|
141 | 141 |
try: |
142 |
opts, args = getopt.gnu_getopt(sys.argv[1:], "p:o:", ["prefix=", "output-dir="]) |
|
142 |
opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:", |
|
143 |
["source", "header", "prefix=", "output-dir="]) |
|
143 | 144 |
except getopt.GetoptError, err: |
144 | 145 |
print str(err) |
145 | 146 |
sys.exit(1) |
... | ... | |
149 | 150 |
c_file = 'qapi-visit.c' |
150 | 151 |
h_file = 'qapi-visit.h' |
151 | 152 |
|
153 |
do_c = False |
|
154 |
do_h = False |
|
155 |
|
|
152 | 156 |
for o, a in opts: |
153 | 157 |
if o in ("-p", "--prefix"): |
154 | 158 |
prefix = a |
155 | 159 |
elif o in ("-o", "--output-dir"): |
156 | 160 |
output_dir = a + "/" |
161 |
elif o in ("-c", "--source"): |
|
162 |
do_h = True |
|
163 |
elif o in ("-h", "--header"): |
|
164 |
do_c = True |
|
165 |
|
|
166 |
if not do_c and not do_h: |
|
167 |
do_c = True |
|
168 |
do_h = True |
|
157 | 169 |
|
158 | 170 |
c_file = output_dir + prefix + c_file |
159 | 171 |
h_file = output_dir + prefix + h_file |
... | ... | |
164 | 176 |
if e.errno != errno.EEXIST: |
165 | 177 |
raise |
166 | 178 |
|
167 |
fdef = open(c_file, 'w') |
|
168 |
fdecl = open(h_file, 'w') |
|
179 |
def maybe_open(really, name, opt): |
|
180 |
class Null(object): |
|
181 |
def write(self, str): |
|
182 |
pass |
|
183 |
def read(self): |
|
184 |
return '' |
|
185 |
if really: |
|
186 |
return open(name, opt) |
|
187 |
|
|
188 |
fdef = maybe_open(do_c, c_file, 'w') |
|
189 |
fdecl = maybe_open(do_h, h_file, 'w') |
|
169 | 190 |
|
170 | 191 |
fdef.write(mcgen(''' |
171 | 192 |
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */ |
Also available in: Unified diff