generate files for one XML file

def generate_message_definitions(basename, xml):
    '''generate files for one XML file'''

    directory = os.path.join(basename, xml.basename)

    print("Generating Objective-C implementation in directory %s" % directory)
    mavparse.mkdir_p(directory)

    xml.basename_camel_case = camel_case_from_underscores(xml.basename)

    # Add some extra field attributes for convenience
    for m in xml.message:
        m.basename = xml.basename
        m.parse_time = xml.parse_time
        m.name_camel_case = camel_case_from_underscores(m.name_lower)
        for f in m.fields:
            f.name_lower_camel_case = lower_camel_case_from_underscores(f.name);
            f.get_message = "[self %s]" % f.name_lower_camel_case
            f.return_method_implementation = ''
            f.array_prefix = ''
            f.array_return_arg = ''
            f.get_arg = ''
            f.get_arg_objc = ''
            if f.enum:
                f.return_type = f.enum
                f.arg_type = f.enum
            else:
                f.return_type = f.type
                f.arg_type = f.type
            if f.print_format is None:
                if f.array_length != 0:
                    f.print_format = "%@"
                elif f.type.startswith('uint64_t'):
                    f.print_format = "%lld"
                elif f.type.startswith('uint') or f.type.startswith('int'):
                    f.print_format = "%d"
                elif f.type.startswith('float'):
                    f.print_format = "%f"
                elif f.type.startswith('char'):
                    f.print_format = "%c"
                else:
                    print("print_format unsupported for type %s" % f.type)
            if f.array_length != 0:
                f.get_message = '@"[array of %s[%d]]"' % (f.type, f.array_length)
                f.array_prefix = ' *'
                f.array_return_arg = '%s, %u, ' % (f.name, f.array_length)
                f.return_type = 'uint16_t'
                f.get_arg = ', %s' % (f.name)
                f.get_arg_objc = ':(%s *)%s' % (f.type, f.name)
                if f.type == 'char':
                    # Special handling for strings (assumes all char arrays are strings)
                    f.return_type = 'NSString *'
                    f.get_arg_objc = ''
                    f.get_message = "[self %s]" % f.name_lower_camel_case
                    f.return_method_implementation = \
"""char string[%(array_length)d];
  mavlink_msg_%(message_name_lower)s_get_%(name)s(&(self->_message), (char *)&string);
  return [[NSString alloc] initWithBytes:string length:%(array_length)d encoding:NSASCIIStringEncoding];""" % {'array_length': f.array_length, 'message_name_lower': m.name_lower, 'name': f.name}

            if not f.return_method_implementation:
                f.return_method_implementation = \
"""return mavlink_msg_%(message_name_lower)s_get_%(name)s(&(self->_message)%(get_arg)s);""" % {'message_name_lower': m.name_lower, 'name': f.name, 'get_arg': f.get_arg}

    for m in xml.message:
        m.arg_fields = []
        for f in m.fields:
            if not f.omit_arg:
                m.arg_fields.append(f)
 
    generate_message_definitions_h(directory, xml)
    for m in xml.message:
        generate_message(directory, m)