summaryrefslogtreecommitdiffstats
path: root/scripts/qapi-event.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/qapi-event.py')
-rw-r--r--scripts/qapi-event.py125
1 files changed, 28 insertions, 97 deletions
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 47dc041..56bc602 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -11,23 +11,19 @@
from ordereddict import OrderedDict
from qapi import *
-import sys
-import os
-import getopt
-import errno
def _generate_event_api_name(event_name, params):
- api_name = "void qapi_event_send_%s(" % c_fun(event_name).lower();
+ api_name = "void qapi_event_send_%s(" % c_name(event_name).lower();
l = len(api_name)
if params:
for argname, argentry, optional in parse_args(params):
if optional:
- api_name += "bool has_%s,\n" % c_var(argname)
+ api_name += "bool has_%s,\n" % c_name(argname)
api_name += "".ljust(l)
api_name += "%s %s,\n" % (c_type(argentry, is_param=True),
- c_var(argname))
+ c_name(argname))
api_name += "".ljust(l)
api_name += "Error **errp)"
@@ -98,7 +94,7 @@ def generate_event_implement(api_name, event_name, params):
ret += mcgen("""
if (has_%(var)s) {
""",
- var = c_var(argname))
+ var = c_name(argname))
push_indent()
if argentry == "str":
@@ -113,7 +109,7 @@ def generate_event_implement(api_name, event_name, params):
}
""",
var_type = var_type,
- var = c_var(argname),
+ var = c_name(argname),
type = type_name(argentry),
name = argname)
@@ -177,7 +173,7 @@ typedef enum %(event_enum_name)s
event_enum_name = event_enum_name)
# append automatically generated _MAX value
- enum_max_value = generate_enum_full_value(event_enum_name, "MAX")
+ enum_max_value = c_enum_const(event_enum_name, "MAX")
enum_values = event_enum_values + [ enum_max_value ]
i = 0
@@ -216,67 +212,9 @@ const char *%(event_enum_name)s_lookup[] = {
''')
return ret
+(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
-# Start the real job
-
-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-event.c'
-h_file = 'qapi-event.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
-
-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
-
-try:
- os.makedirs(output_dir)
-except os.error, e:
- if e.errno != errno.EEXIST:
- raise
-
-def maybe_open(really, name, opt):
- if really:
- return open(name, opt)
- else:
- import StringIO
- return StringIO.StringIO()
-
-fdef = maybe_open(do_c, c_file, 'w')
-fdecl = maybe_open(do_h, h_file, 'w')
-
-fdef.write(mcgen('''
-/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
+c_comment = '''
/*
* schema-defined QAPI event functions
*
@@ -289,19 +227,8 @@ fdef.write(mcgen('''
* See the COPYING.LIB file in the top-level directory.
*
*/
-
-#include "qemu-common.h"
-#include "%(header)s"
-#include "%(prefix)sqapi-visit.h"
-#include "qapi/qmp-output-visitor.h"
-#include "qapi/qmp-event.h"
-
-''',
- prefix=prefix, header=basename(h_file)))
-
-fdecl.write(mcgen('''
-/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
+'''
+h_comment = '''
/*
* schema-defined QAPI event functions
*
@@ -314,16 +241,29 @@ fdecl.write(mcgen('''
* See the COPYING.LIB file in the top-level directory.
*
*/
+'''
-#ifndef %(guard)s
-#define %(guard)s
+(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
+ 'qapi-event.c', 'qapi-event.h',
+ c_comment, h_comment)
+fdef.write(mcgen('''
+#include "qemu-common.h"
+#include "%(prefix)sqapi-event.h"
+#include "%(prefix)sqapi-visit.h"
+#include "qapi/qmp-output-visitor.h"
+#include "qapi/qmp-event.h"
+
+''',
+ prefix=prefix))
+
+fdecl.write(mcgen('''
#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
#include "%(prefix)sqapi-types.h"
''',
- prefix=prefix, guard=guardname(h_file)))
+ prefix=prefix))
exprs = parse_schema(input_file)
@@ -343,8 +283,7 @@ for expr in exprs:
fdecl.write(ret)
# We need an enum value per event
- event_enum_value = generate_enum_full_value(event_enum_name,
- event_name)
+ event_enum_value = c_enum_const(event_enum_name, event_name)
ret = generate_event_implement(api_name, event_name, params)
fdef.write(ret)
@@ -357,12 +296,4 @@ fdecl.write(ret)
ret = generate_event_enum_lookup(event_enum_name, event_enum_strings)
fdef.write(ret)
-fdecl.write('''
-#endif
-''')
-
-fdecl.flush()
-fdecl.close()
-
-fdef.flush()
-fdef.close()
+close_output(fdef, fdecl)
OpenPOWER on IntegriCloud