aboutsummaryrefslogtreecommitdiffstats
path: root/maketables
diff options
context:
space:
mode:
Diffstat (limited to 'maketables')
-rwxr-xr-xmaketables41
1 files changed, 24 insertions, 17 deletions
diff --git a/maketables b/maketables
index fe4e62c..7c54c6a 100755
--- a/maketables
+++ b/maketables
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright (c) 2008-2010 Wind River Systems, Inc.
+# Copyright (c) 2008-2010, 2013 Wind River Systems, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the Lesser GNU General Public License version 2.1 as
@@ -23,9 +23,9 @@ The names are used to create enums and a table of strings, as well as
to/from lookups between the ids and names. If additional columns are
defined, each column (separated by ", ") is used to create an additional
table of the given name, and a lookup function from ids. Example:
- foo: FFF; bar = GOZINTA
- hello, yah
- world, nope
+ foo: FFF; const char *bar = "GOZINTA"
+ hello, "yah"
+ world, "nope"
produces:
typedef enum {
FFF_UNKNOWN = -1,
@@ -74,7 +74,14 @@ class DataType:
name, default = string.split(col, ' = ')
else:
name, default = col, ""
- self.columns.append({"name":name, "value":default})
+ if " " in name:
+ words = string.split(name, ' ')
+ name = words[-1]
+ del words[-1]
+ type = ' '.join(words)
+ else:
+ type = "char *"
+ self.columns.append({"type":type, "name":name, "value":default})
else:
self.columns = []
self.data = []
@@ -94,7 +101,7 @@ class DataType:
if len(cols) > 0:
column_list.append({"name":col["name"], "value":cols.pop(0)})
else:
- column_list.append({"name":col["name"], "value":col["default"]})
+ column_list.append({"name":col["name"], "value":col["value"]})
item["cols"] = column_list
self.data.append(item)
@@ -113,15 +120,15 @@ class DataType:
out += "type: %s_t" % self.name
out += " (prefix '%s_ENUM')\n" % self.prefix
for col in self.columns:
- out += " extra column: %s (default '%s')\n" % (col["name"], col["value"])
+ out += " extra column: %s %s (default %s)\n" % (col["type"], col["name"], col["value"])
out += " "
for item in self.data:
column = column + 1
if column > 4 and column % 4 == 1:
out += "\n "
out += "%-19s" % item["name"]
-# for col in item["cols"]:
-# out += "\t%s(%s)\n" % (col["name"], col["value"])
+# for col in item["cols"]:
+# out += "\t%s(%s)\n" % (col["name"], col["value"])
return out
def comment(self):
@@ -140,11 +147,11 @@ class DataType:
decl_lines = []
column = 0
for col in self.columns:
- decl_lines.append("static const char *%s_id_to_%s[] = {" % (self.name, col["name"]))
- decl_lines.append('\t"%s",' % col["value"])
+ decl_lines.append("static %s %s_id_to_%s[] = {" % (col["type"], self.name, col["name"]))
+ decl_lines.append('\t%s,' % col["value"])
for item in self.data:
- decl_lines.append('\t"%s",' % item["cols"][column]["value"])
- decl_lines.append('\tNULL')
+ decl_lines.append('\t%s,' % item["cols"][column]["value"])
+ decl_lines.append('\t0')
decl_lines.append("};")
column = column + 1
return '\n'.join(decl_lines)
@@ -152,11 +159,11 @@ class DataType:
def column_funcs(self):
decl_lines = []
for col in self.columns:
- decl_lines.append('extern const char *')
+ decl_lines.append('extern %s' % col["type"])
decl_lines.append('pseudo_%s_%s(pseudo_%s_t id) {' %
(self.name, col["name"], self.name))
decl_lines.append('\tif (id < 0 || id >= %s_MAX)' % (self.prefix))
- decl_lines.append('\t\treturn "%s";' % col["value"])
+ decl_lines.append('\t\treturn %s;' % col["value"])
decl_lines.append('\treturn %s_id_to_%s[id];' %
(self.name, col["name"]))
decl_lines.append('}')
@@ -165,8 +172,8 @@ class DataType:
def column_protos(self):
decl_lines = []
for col in self.columns:
- decl_lines.append('extern const char *pseudo_%s_%s(pseudo_%s_t id);' %
- (self.name, col["name"], self.name))
+ decl_lines.append('extern %s pseudo_%s_%s(pseudo_%s_t id);' %
+ (col["type"], self.name, col["name"], self.name))
return '\n'.join(decl_lines)
def main():