Revision 8d3bc517 scripts/qapi-types.py

b/scripts/qapi-types.py
163 163

  
164 164

  
165 165
try:
166
    opts, args = getopt.gnu_getopt(sys.argv[1:], "p:o:", ["prefix=", "output-dir="])
166
    opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:",
167
                                   ["source", "header", "prefix=", "output-dir="])
167 168
except getopt.GetoptError, err:
168 169
    print str(err)
169 170
    sys.exit(1)
......
173 174
c_file = 'qapi-types.c'
174 175
h_file = 'qapi-types.h'
175 176

  
177
do_c = False
178
do_h = False
179

  
176 180
for o, a in opts:
177 181
    if o in ("-p", "--prefix"):
178 182
        prefix = a
179 183
    elif o in ("-o", "--output-dir"):
180 184
        output_dir = a + "/"
185
    elif o in ("-c", "--source"):
186
        do_h = True
187
    elif o in ("-h", "--header"):
188
        do_c = True
189

  
190
if not do_c and not do_h:
191
    do_c = True
192
    do_h = True
181 193

  
182 194
c_file = output_dir + prefix + c_file
183 195
h_file = output_dir + prefix + h_file
......
188 200
    if e.errno != errno.EEXIST:
189 201
        raise
190 202

  
191
fdef = open(c_file, 'w')
192
fdecl = open(h_file, 'w')
203
def maybe_open(really, name, opt):
204
    class Null(object):
205
        def write(self, str):
206
            pass
207
        def read(self):
208
            return ''
209
    if really:
210
        return open(name, opt)
211

  
212
fdef = maybe_open(do_c, c_file, 'w')
213
fdecl = maybe_open(do_h, h_file, 'w')
193 214

  
194 215
fdef.write(mcgen('''
195 216
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */

Also available in: Unified diff