aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/contrib
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2009-08-19 06:31:59 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2009-11-20 17:29:33 +0100
commitadb8bcea5f0a5f34b5742df124b2a9de1cba602a (patch)
tree2e851c5102aa431707553b13ca093abbb23e0ae6 /openbsc/contrib
parentb9b8c6dbb69374f3b59214e9d80ff42dcb5b9c9d (diff)
[contrib] Add a utility to convert an IE page to an enum
This script is parsing the values, converting the bits into a number and replacing the text... This should help to go from spec to code more quickly... next thing would be this for the structs used...
Diffstat (limited to 'openbsc/contrib')
-rwxr-xr-xopenbsc/contrib/convert_to_enum.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/openbsc/contrib/convert_to_enum.py b/openbsc/contrib/convert_to_enum.py
new file mode 100755
index 000000000..bcd6f2cee
--- /dev/null
+++ b/openbsc/contrib/convert_to_enum.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+#
+# Convert ETSI documents to an enum
+#
+
+import re, sys
+
+def convert(string):
+ string = string.strip().replace(" ", "").rjust(8, "0")
+ var = 0
+ offset = 7
+ for char in string:
+ assert offset >= 0
+ var = var | (int(char) << offset)
+ offset = offset - 1
+
+ return var
+
+def string(name):
+ name = name.replace(" ", "_")
+ name = name.replace('"', "")
+ name = name.replace('/', '_')
+ name = name.replace('(', '_')
+ name = name.replace(')', '_')
+ return "%s_%s" % (sys.argv[2], name.upper())
+
+file = open(sys.argv[1])
+
+
+for line in file:
+ m = re.match(r"[ \t]*(?P<value>[01 ]+)[ ]+(?P<name>[a-zA-Z /0-9()]+)", line[:-1])
+
+ if m:
+ print "\t%s\t\t= %d," % (string(m.groupdict()["name"]), convert(m.groupdict()["value"]))
+ else:
+ print line[:-1]