aboutsummaryrefslogtreecommitdiffstats
path: root/tools/value_string.py
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-01-22 23:35:25 +0100
committerHarald Welte <laforge@gnumonks.org>2017-01-24 17:09:26 +0100
commitd248204bb7f609d1f89ad36e70e471af78f5b2bb (patch)
treec649ef0fbdfac0eb1d9408c099a558ef43d2ae8e /tools/value_string.py
parent78ced2084d7732bc2a37a9eb9bb37c9392372066 (diff)
python scripts: Generate file header with #include statements
Diffstat (limited to 'tools/value_string.py')
-rw-r--r--tools/value_string.py33
1 files changed, 24 insertions, 9 deletions
diff --git a/tools/value_string.py b/tools/value_string.py
index 2bdc499..31db752 100644
--- a/tools/value_string.py
+++ b/tools/value_string.py
@@ -17,13 +17,28 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+class ValueStringWriter(object):
+ def __init__(self, flavor='osmocom', weak=False, includes=[]):
+ self.flavor = flavor
+ self.weak = weak
+ self.includes = includes
-def export_value_str(name, vals, flavor='osmocom', sort_key=int):
- if flavor == 'osmocom':
- print("const struct value_string %s[] = {" % name);
- elif flavor == 'wireshark':
- print("const value_string %s[] = {" % name);
- for v in sorted(vals.iterkeys(), key=sort_key):
- print("\t{ %s, \"%s\" }," % (v, vals[v]));
- print("\t{ 0, NULL }")
- print("};");
+ def export_value_str(self, name, vals, sort_key=int):
+ if self.weak:
+ print("__attribute__((weak))")
+ if self.flavor == 'osmocom':
+ print("const struct value_string %s[] = {" % name);
+ elif self.flavor == 'wireshark':
+ print("const value_string %s[] = {" % name);
+ for v in sorted(vals.iterkeys(), key=sort_key):
+ print("\t{ %s, \"%s\" }," % (v, vals[v]));
+ print("\t{ 0, NULL }")
+ print("};");
+
+ def export_header(self):
+ print("/* GENERATED FILE, DO NOT EDIT */")
+ if self.flavor == 'osmocom':
+ print("#include <osmocom/core/utils.h>")
+ for i in self.includes:
+ print('#include "%s"' % i)
+ print("")