mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 03:59:52 +00:00
qapi: Factor parse_command_line() out of the generators
Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
72aaa73a4a
commit
2114f5a98d
@ -15,9 +15,7 @@
|
||||
from ordereddict import OrderedDict
|
||||
from qapi import *
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
import getopt
|
||||
import errno
|
||||
|
||||
def generate_command_decl(name, args, ret_type):
|
||||
@ -376,42 +374,16 @@ def gen_command_def_prologue(prefix="", proxy=False):
|
||||
ret += '#include "%sqmp-commands.h"' % prefix
|
||||
return ret + "\n\n"
|
||||
|
||||
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:m",
|
||||
["source", "header", "prefix=",
|
||||
"input-file=", "output-dir=",
|
||||
"middle"])
|
||||
except getopt.GetoptError, err:
|
||||
print str(err)
|
||||
sys.exit(1)
|
||||
|
||||
output_dir = ""
|
||||
prefix = ""
|
||||
c_file = 'qmp-marshal.c'
|
||||
h_file = 'qmp-commands.h'
|
||||
middle_mode = False
|
||||
|
||||
do_c = False
|
||||
do_h = False
|
||||
(input_file, output_dir, do_c, do_h, prefix, opts) = \
|
||||
parse_command_line("m", ["middle"])
|
||||
|
||||
for o, a in opts:
|
||||
if o in ("-p", "--prefix"):
|
||||
prefix = a
|
||||
elif o in ("-i", "--input-file"):
|
||||
input_file = a
|
||||
elif o in ("-o", "--output-dir"):
|
||||
output_dir = a + "/"
|
||||
elif o in ("-m", "--middle"):
|
||||
if o in ("-m", "--middle"):
|
||||
middle_mode = True
|
||||
elif o in ("-c", "--source"):
|
||||
do_c = True
|
||||
elif o in ("-h", "--header"):
|
||||
do_h = True
|
||||
|
||||
if not do_c and not do_h:
|
||||
do_c = True
|
||||
do_h = True
|
||||
|
||||
c_file = output_dir + prefix + c_file
|
||||
h_file = output_dir + prefix + h_file
|
||||
|
@ -11,9 +11,7 @@
|
||||
|
||||
from ordereddict import OrderedDict
|
||||
from qapi import *
|
||||
import sys
|
||||
import os
|
||||
import getopt
|
||||
import errno
|
||||
|
||||
def _generate_event_api_name(event_name, params):
|
||||
@ -219,38 +217,10 @@ const char *%(event_enum_name)s_lookup[] = {
|
||||
|
||||
# Start the real job
|
||||
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:",
|
||||
["source", "header", "prefix=",
|
||||
"input-file=", "output-dir="])
|
||||
except getopt.GetoptError, err:
|
||||
print str(err)
|
||||
sys.exit(1)
|
||||
|
||||
input_file = ""
|
||||
output_dir = ""
|
||||
prefix = ""
|
||||
c_file = 'qapi-event.c'
|
||||
h_file = 'qapi-event.h'
|
||||
|
||||
do_c = False
|
||||
do_h = False
|
||||
|
||||
for o, a in opts:
|
||||
if o in ("-p", "--prefix"):
|
||||
prefix = a
|
||||
elif o in ("-i", "--input-file"):
|
||||
input_file = a
|
||||
elif o in ("-o", "--output-dir"):
|
||||
output_dir = a + "/"
|
||||
elif o in ("-c", "--source"):
|
||||
do_c = True
|
||||
elif o in ("-h", "--header"):
|
||||
do_h = True
|
||||
|
||||
if not do_c and not do_h:
|
||||
do_c = True
|
||||
do_h = True
|
||||
(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
|
||||
|
||||
c_file = output_dir + prefix + c_file
|
||||
h_file = output_dir + prefix + h_file
|
||||
|
@ -11,9 +11,7 @@
|
||||
|
||||
from ordereddict import OrderedDict
|
||||
from qapi import *
|
||||
import sys
|
||||
import os
|
||||
import getopt
|
||||
import errno
|
||||
|
||||
def generate_fwd_struct(name, members, builtin_type=False):
|
||||
@ -275,42 +273,16 @@ void qapi_free_%(name)s(%(c_type)s obj)
|
||||
c_type=c_type(name), name=c_name(name))
|
||||
return ret
|
||||
|
||||
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:i:o:",
|
||||
["source", "header", "builtins",
|
||||
"prefix=", "input-file=", "output-dir="])
|
||||
except getopt.GetoptError, err:
|
||||
print str(err)
|
||||
sys.exit(1)
|
||||
|
||||
output_dir = ""
|
||||
input_file = ""
|
||||
prefix = ""
|
||||
c_file = 'qapi-types.c'
|
||||
h_file = 'qapi-types.h'
|
||||
|
||||
do_c = False
|
||||
do_h = False
|
||||
do_builtins = False
|
||||
|
||||
for o, a in opts:
|
||||
if o in ("-p", "--prefix"):
|
||||
prefix = a
|
||||
elif o in ("-i", "--input-file"):
|
||||
input_file = a
|
||||
elif o in ("-o", "--output-dir"):
|
||||
output_dir = a + "/"
|
||||
elif o in ("-c", "--source"):
|
||||
do_c = True
|
||||
elif o in ("-h", "--header"):
|
||||
do_h = True
|
||||
elif o in ("-b", "--builtins"):
|
||||
do_builtins = True
|
||||
(input_file, output_dir, do_c, do_h, prefix, opts) = \
|
||||
parse_command_line("b", ["builtins"])
|
||||
|
||||
if not do_c and not do_h:
|
||||
do_c = True
|
||||
do_h = True
|
||||
for o, a in opts:
|
||||
if o in ("-b", "--builtins"):
|
||||
do_builtins = True
|
||||
|
||||
c_file = output_dir + prefix + c_file
|
||||
h_file = output_dir + prefix + h_file
|
||||
|
@ -15,9 +15,7 @@
|
||||
from ordereddict import OrderedDict
|
||||
from qapi import *
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
import getopt
|
||||
import errno
|
||||
|
||||
implicit_structs = []
|
||||
@ -376,41 +374,16 @@ void visit_type_%(name)s(Visitor *m, %(name)s *obj, const char *name, Error **er
|
||||
''',
|
||||
name=c_name(name))
|
||||
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:i:o:",
|
||||
["source", "header", "builtins", "prefix=",
|
||||
"input-file=", "output-dir="])
|
||||
except getopt.GetoptError, err:
|
||||
print str(err)
|
||||
sys.exit(1)
|
||||
|
||||
input_file = ""
|
||||
output_dir = ""
|
||||
prefix = ""
|
||||
c_file = 'qapi-visit.c'
|
||||
h_file = 'qapi-visit.h'
|
||||
|
||||
do_c = False
|
||||
do_h = False
|
||||
do_builtins = False
|
||||
|
||||
for o, a in opts:
|
||||
if o in ("-p", "--prefix"):
|
||||
prefix = a
|
||||
elif o in ("-i", "--input-file"):
|
||||
input_file = a
|
||||
elif o in ("-o", "--output-dir"):
|
||||
output_dir = a + "/"
|
||||
elif o in ("-c", "--source"):
|
||||
do_c = True
|
||||
elif o in ("-h", "--header"):
|
||||
do_h = True
|
||||
elif o in ("-b", "--builtins"):
|
||||
do_builtins = True
|
||||
(input_file, output_dir, do_c, do_h, prefix, opts) = \
|
||||
parse_command_line("b", ["builtins"])
|
||||
|
||||
if not do_c and not do_h:
|
||||
do_c = True
|
||||
do_h = True
|
||||
for o, a in opts:
|
||||
if o in ("-b", "--builtins"):
|
||||
do_builtins = True
|
||||
|
||||
c_file = output_dir + prefix + c_file
|
||||
h_file = output_dir + prefix + h_file
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
import re
|
||||
from ordereddict import OrderedDict
|
||||
import getopt
|
||||
import os
|
||||
import sys
|
||||
import string
|
||||
@ -978,3 +979,42 @@ def guardend(name):
|
||||
|
||||
''',
|
||||
name=guardname(name))
|
||||
|
||||
def parse_command_line(extra_options = "", extra_long_options = []):
|
||||
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:],
|
||||
"chp:i:o:" + extra_options,
|
||||
["source", "header", "prefix=",
|
||||
"input-file=", "output-dir="]
|
||||
+ extra_long_options)
|
||||
except getopt.GetoptError, err:
|
||||
print str(err)
|
||||
sys.exit(1)
|
||||
|
||||
output_dir = ""
|
||||
prefix = ""
|
||||
do_c = False
|
||||
do_h = False
|
||||
extra_opts = []
|
||||
|
||||
for oa in opts:
|
||||
o, a = oa
|
||||
if o in ("-p", "--prefix"):
|
||||
prefix = a
|
||||
elif o in ("-i", "--input-file"):
|
||||
input_file = a
|
||||
elif o in ("-o", "--output-dir"):
|
||||
output_dir = a + "/"
|
||||
elif o in ("-c", "--source"):
|
||||
do_c = True
|
||||
elif o in ("-h", "--header"):
|
||||
do_h = True
|
||||
else:
|
||||
extra_opts.append(oa)
|
||||
|
||||
if not do_c and not do_h:
|
||||
do_c = True
|
||||
do_h = True
|
||||
|
||||
return (input_file, output_dir, do_c, do_h, prefix, extra_opts)
|
||||
|
Loading…
Reference in New Issue
Block a user