summaryrefslogtreecommitdiff
path: root/build-aux/mbim-codegen
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-04-11 19:32:00 +0200
committerAleksander Morgado <aleksander@lanedo.com>2013-04-21 19:28:14 +0200
commit0d2dbd0585075d1b339fbe411e4f188c03f8d5dd (patch)
tree59103613dad23fe9462fcc9882c47f37c995fd82 /build-aux/mbim-codegen
parent453b34db2b478bafa5fae2e9630a17a79bf0cf0a (diff)
downloadlibmbim-0d2dbd0585075d1b339fbe411e4f188c03f8d5dd.tar.gz
mbim-codegen: let the field names be written in CamelCase, as in the docs
Write all field names in CamelCase, to match the name given in the docs.
Diffstat (limited to 'build-aux/mbim-codegen')
-rw-r--r--build-aux/mbim-codegen/Message.py20
-rw-r--r--build-aux/mbim-codegen/Struct.py10
-rw-r--r--build-aux/mbim-codegen/utils.py2
3 files changed, 17 insertions, 15 deletions
diff --git a/build-aux/mbim-codegen/Message.py b/build-aux/mbim-codegen/Message.py
index 38870df..b9c1480 100644
--- a/build-aux/mbim-codegen/Message.py
+++ b/build-aux/mbim-codegen/Message.py
@@ -90,7 +90,7 @@ class Message:
if container != None:
for field in container.fields:
- translations['field_name_underscore'] = utils.build_underscore_name (field.name)
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase (field.name)
translations['field_in_format'] = field.in_format
inner_template = (
' ${field_in_format}${field_name_underscore},\n')
@@ -108,7 +108,7 @@ class Message:
if container != None:
for field in container.fields:
translations['field_name'] = field.name
- translations['field_name_underscore'] = utils.build_underscore_name (field.name)
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase (field.name)
translations['field_in_description'] = field.in_description
inner_template = (
' * @${field_name_underscore}: the \'${field_name}\' field, given as ${field_in_description}\n')
@@ -126,7 +126,7 @@ class Message:
if container != None:
for field in container.fields:
- translations['field_name_underscore'] = utils.build_underscore_name (field.name)
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase (field.name)
translations['field_in_format'] = field.in_format
inner_template = (
' ${field_in_format}${field_name_underscore},\n')
@@ -145,7 +145,7 @@ class Message:
if container != None:
template += ('\n')
for field in container.fields:
- translations['field_name_underscore'] = utils.build_underscore_name(field.name)
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase(field.name)
translations['field_format_underscore'] = utils.build_underscore_name(field.format)
inner_template = (
' _mbim_message_command_builder_append_${field_format_underscore} (builder, ${field_name_underscore});\n')
@@ -177,7 +177,7 @@ class Message:
if container != None:
for field in container.fields:
- translations['field_name_underscore'] = utils.build_underscore_name (field.name)
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase(field.name)
translations['field_out_format'] = field.out_format
inner_template = (
' ${field_out_format}${field_name_underscore},\n')
@@ -196,7 +196,7 @@ class Message:
if container != None:
for field in container.fields:
translations['field_name'] = field.name
- translations['field_name_underscore'] = utils.build_underscore_name (field.name)
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase(field.name)
translations['field_out_description'] = field.out_description
inner_template = (
' * @${field_name_underscore}: ${field_out_description}\n')
@@ -215,7 +215,7 @@ class Message:
if container != None:
for field in container.fields:
- translations['field_name_underscore'] = utils.build_underscore_name (field.name)
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase(field.name)
translations['field_out_format'] = field.out_format
inner_template = (
' ${field_out_format}${field_name_underscore},\n')
@@ -228,14 +228,14 @@ class Message:
if container != None:
for field in container.fields:
if field.is_array_size:
- translations['field_name_underscore'] = utils.build_underscore_name (field.name)
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase(field.name)
inner_template = (
' guint32 _${field_name_underscore};\n')
template += (string.Template(inner_template).substitute(translations))
if container != None:
for field in container.fields:
- translations['field_name_underscore'] = utils.build_underscore_name(field.name)
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase(field.name)
translations['field_format_underscore'] = utils.build_underscore_name(field.format)
translations['field_size'] = field.size
translations['field_size_string'] = field.size_string
@@ -247,7 +247,7 @@ class Message:
' {\n')
if field.is_array:
- translations['array_size_field_name_underscore'] = utils.build_underscore_name (field.array_size_field)
+ translations['array_size_field_name_underscore'] = utils.build_underscore_name_from_camelcase (field.array_size_field)
translations['array_member_size'] = str(field.array_member_size)
translations['struct_name'] = (field.struct_type_underscore + '_') if field.format == 'struct-array' else ''
diff --git a/build-aux/mbim-codegen/Struct.py b/build-aux/mbim-codegen/Struct.py
index 8163ff6..3b0767d 100644
--- a/build-aux/mbim-codegen/Struct.py
+++ b/build-aux/mbim-codegen/Struct.py
@@ -43,7 +43,7 @@ class Struct:
'\n'
'typedef struct {\n')
for field in self.contents:
- translations['field_name_underscore'] = utils.build_underscore_name(field['name'])
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase(field['name'])
if field['format'] == 'uuid':
inner_template = (
' MbimUuid ${field_name_underscore};\n')
@@ -92,7 +92,7 @@ class Struct:
'{\n')
for field in self.contents:
- translations['field_name_underscore'] = utils.build_underscore_name(field['name'])
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase(field['name'])
inner_template = ''
if field['format'] == 'uuid':
pass
@@ -160,7 +160,7 @@ class Struct:
' out = g_new (${name}, 1);\n')
for field in self.contents:
- translations['field_name_underscore'] = utils.build_underscore_name(field['name'])
+ translations['field_name_underscore'] = utils.build_underscore_name_from_camelcase(field['name'])
translations['format_underscore'] = utils.build_underscore_name(field['format'])
translations['offset'] = offset
@@ -176,7 +176,7 @@ class Struct:
' out->${field_name_underscore} = _mbim_message_read_guint32 (self, offset);\n'
' offset += 4;\n')
elif field['format'] == 'guint32-array':
- translations['array_size_field_name_underscore'] = utils.build_underscore_name (field['array-size-field'])
+ translations['array_size_field_name_underscore'] = utils.build_underscore_name_from_camelcase(field['array-size-field'])
inner_template += (
'\n'
' out->${field_name_underscore} = _mbim_message_read_guint32_array (self, out->${array_size_field_name_underscore}, offset);\n'
@@ -187,7 +187,7 @@ class Struct:
' out->${field_name_underscore} = _mbim_message_read_string (self, offset);\n'
' offset += 8;\n')
elif field['format'] == 'string-array':
- translations['array_size_field_name_underscore'] = utils.build_underscore_name (field['array-size-field'])
+ translations['array_size_field_name_underscore'] = utils.build_underscore_name_from_camelcase(field['array-size-field'])
inner_template += (
'\n'
' out->${field_name_underscore} = _mbim_message_read_string_array (self, out->${array_size_field_name_underscore}, offset);\n'
diff --git a/build-aux/mbim-codegen/utils.py b/build-aux/mbim-codegen/utils.py
index 157b6fb..ddcf92f 100644
--- a/build-aux/mbim-codegen/utils.py
+++ b/build-aux/mbim-codegen/utils.py
@@ -138,6 +138,7 @@ def build_underscore_uppercase_name(name):
return name.replace(' ', '_').replace('-', '_').upper()
+
"""
Build an underscore name from the given camelcase name
e.g.: "ThisIsAMessage" --> "this_is_a_message"
@@ -147,6 +148,7 @@ def build_underscore_name_from_camelcase(camelcase):
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
+
"""
Build a camelcase name from the given full name
e.g.: "This is a message" --> "ThisIsAMessage"