Ejemplo n.º 1
0
def parse_json_to_c(obj, c_file, prefix):
    """
    Description: generate c language for parse json file
    Interface: None
    History: 2019-06-17
    """
    if not helpers.judge_complex(obj.typ):
        return
    if obj.typ == 'object' or obj.typ == 'mapStringObject':
        if obj.subtypname:
            return
        obj_typename = typename = helpers.get_prefixe_name(obj.name, prefix)
    if obj.typ == 'array':
        obj_typename = typename = helpers.get_name_substr(obj.name, prefix)
        objs = obj.subtypobj
        if objs is None or obj.subtypname:
            return
    c_file.write("%s *make_%s(yajl_val tree, const struct parser_context *ctx, "\
        "parser_error *err) {\n" % (typename, typename))
    c_file.write("    %s *ret = NULL;\n" % (typename))
    c_file.write("    *err = 0;\n")
    c_file.write("    if (tree == NULL)\n")
    c_file.write("        return ret;\n")
    c_file.write("    ret = safe_malloc(sizeof(*ret));\n")
    if obj.typ == 'mapStringObject':
        parse_map_string_obj(obj, c_file, prefix, obj_typename)

    if obj.typ == 'object' or (obj.typ == 'array' and obj.subtypobj):
        parse_obj_arr_obj(obj, c_file, prefix, obj_typename)
    c_file.write('    return ret;\n')
    c_file.write("}\n\n")
Ejemplo n.º 2
0
def parse_map_string_obj(obj, c_file, prefix, obj_typename):
    """
    Description: generate c language for parse json map string object
    Interface: None
    History: 2019-06-17
    """
    child = obj.children[0]
    if helpers.valid_basic_map_name(child.typ):
        childname = helpers.make_basic_map_name(child.typ)
    else:
        if child.subtypname:
            childname = child.subtypname
        else:
            childname = helpers.get_prefixe_name(child.name, prefix)
    c_file.write('    if (YAJL_GET_OBJECT(tree) != NULL && YAJL_GET_OBJECT(tree)->len > 0) {\n')
    c_file.write('        size_t i;\n')
    c_file.write('        ret->len = YAJL_GET_OBJECT(tree)->len;\n')
    c_file.write('        ret->keys = safe_malloc((YAJL_GET_OBJECT(tree)->len + 1) ' \
                 '* sizeof(*ret->keys));\n')
    c_file.write('        ret->%s = safe_malloc((YAJL_GET_OBJECT(tree)->len + 1) ' \
                 '* sizeof(*ret->%s));\n' % (child.fixname, child.fixname))
    c_file.write('        for (i = 0; i < YAJL_GET_OBJECT(tree)->len; i++) {\n')
    c_file.write('            const char *tmpkey = YAJL_GET_OBJECT(tree)->keys[i];\n')
    c_file.write('            ret->keys[i] = safe_strdup(tmpkey ? tmpkey : "");\n')
    c_file.write('            yajl_val val = YAJL_GET_OBJECT(tree)->values[i];\n')
    c_file.write('            ret->%s[i] = make_%s(val, ctx, err);\n' \
                 % (child.fixname, childname))
    c_file.write('            if (ret->%s[i] == NULL) {\n' % (child.fixname))
    c_file.write("                free_%s(ret);\n" % obj_typename)
    c_file.write("                return NULL;\n")
    c_file.write('            }\n')
    c_file.write('        }\n')
    c_file.write('    }\n')
Ejemplo n.º 3
0
def get_c_json(obj, c_file, prefix):
    """
    Description: c language generate json file
    Interface: None
    History: 2019-06-17
    """
    if not helpers.judge_complex(obj.typ) or obj.subtypname:
        return
    if obj.typ == 'object' or obj.typ == 'mapStringObject':
        typename = helpers.get_prefixe_name(obj.name, prefix)
    elif obj.typ == 'array':
        typename = helpers.get_name_substr(obj.name, prefix)
        objs = obj.subtypobj
        if objs is None:
            return
    c_file.write(
        "yajl_gen_status gen_%s(yajl_gen g, const %s *ptr, const struct parser_context " \
        "*ctx, parser_error *err) {\n" % (typename, typename))
    c_file.write("    yajl_gen_status stat = yajl_gen_status_ok;\n")
    c_file.write("    *err = 0;\n")
    if obj.typ == 'mapStringObject':
        get_map_string_obj(obj, c_file, prefix)
    elif obj.typ == 'object' or (obj.typ == 'array' and obj.subtypobj):
        nodes = obj.children if obj.typ == 'object' else obj.subtypobj
        if nodes is None:
            c_file.write('    if (!(ctx->options & OPT_GEN_SIMPLIFY))\n')
            c_file.write('        yajl_gen_config(g, yajl_gen_beautify, 0);\n')

        c_file.write("    stat = yajl_gen_map_open((yajl_gen)g);\n")
        c_file.write("    if (yajl_gen_status_ok != stat)\n")
        c_file.write("        GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        for i in nodes or []:
            get_obj_arr_obj(i, c_file, prefix)
        if obj.typ == 'object':
            if obj.children is not None:
                c_file.write("    if (ptr != NULL && ptr->_residual != NULL)\n")
                c_file.write("    {\n")
                c_file.write("        stat = gen_yajl_object_residual (ptr->_residual, g, err);\n")
                c_file.write("        if (yajl_gen_status_ok != stat)\n")
                c_file.write("            GEN_SET_ERROR_AND_RETURN (stat, err);\n")
                c_file.write("    }\n")
        c_file.write("    stat = yajl_gen_map_close((yajl_gen)g);\n")
        c_file.write("    if (yajl_gen_status_ok != stat)\n")
        c_file.write("        GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        if nodes is None:
            c_file.write('    if (!(ctx->options & OPT_GEN_SIMPLIFY))\n')
            c_file.write('        yajl_gen_config(g, yajl_gen_beautify, 1);\n')
    c_file.write('    return yajl_gen_status_ok;\n')
    c_file.write("}\n\n")
Ejemplo n.º 4
0
def get_map_string_obj(obj, c_file, prefix):
    """
    Description: c language generate map string object
    Interface: None
    History: 2019-06-17
    """
    child = obj.children[0]
    if helpers.valid_basic_map_name(child.typ):
        childname = helpers.make_basic_map_name(child.typ)
    else:
        if child.subtypname:
            childname = child.subtypname
        else:
            childname = helpers.get_prefixe_name(child.name, prefix)
    c_file.write('    size_t len = 0, i;\n')
    c_file.write("    if (ptr != NULL)\n")
    c_file.write("        len = ptr->len;\n")
    c_file.write("    if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n")
    c_file.write('        yajl_gen_config(g, yajl_gen_beautify, 0);\n')
    c_file.write("    stat = yajl_gen_map_open((yajl_gen)g);\n")
    c_file.write("    if (yajl_gen_status_ok != stat)\n")
    c_file.write("        GEN_SET_ERROR_AND_RETURN(stat, err);\n")
    c_file.write('    if (len ||(ptr != NULL && ptr->keys != NULL && ptr->%s != NULL)) {\n' \
                 % child.fixname)
    c_file.write('        for (i = 0; i < len; i++) {\n')
    c_file.write('            char *str = ptr->keys[i] ? ptr->keys[i] : "";\n')
    c_file.write('            stat = yajl_gen_string((yajl_gen)g, \
        (const unsigned char *)str, strlen(str));\n')
    c_file.write("            if (yajl_gen_status_ok != stat)\n")
    c_file.write("                GEN_SET_ERROR_AND_RETURN(stat, err);\n")
    c_file.write('            stat = gen_%s(g, ptr->%s[i], ctx, err);\n' \
                 % (childname, child.fixname))
    c_file.write("            if (yajl_gen_status_ok != stat)\n")
    c_file.write("                GEN_SET_ERROR_AND_RETURN(stat, err);\n")
    c_file.write('        }\n')
    c_file.write('    }\n')
    c_file.write("    stat = yajl_gen_map_close((yajl_gen)g);\n")
    c_file.write("    if (yajl_gen_status_ok != stat)\n")
    c_file.write("        GEN_SET_ERROR_AND_RETURN(stat, err);\n")
    c_file.write("    if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n")
    c_file.write('        yajl_gen_config(g, yajl_gen_beautify, 1);\n')
Ejemplo n.º 5
0
def append_type_c_header(obj, header, prefix):
    '''
    Description: Write c header file
    Interface: None
    History: 2019-06-17
    '''
    if not helpers.judge_complex(obj.typ):
        return

    if obj.typ == 'array':
        append_header_arr(obj, header, prefix)
        return

    if obj.typ == 'mapStringObject':
        if obj.subtypname is not None:
            return
        append_header_map_str_obj(obj, header, prefix)
    elif obj.typ == 'object':
        if obj.subtypname is not None:
            return
        header.write("typedef struct {\n")
        if obj.children is None:
            header.write(
                "    char unuseful; // unuseful definition to avoid empty struct\n"
            )
        for i in obj.children or []:
            if i.typ == 'array':
                append_header_child_arr(i, header, prefix)
            else:
                append_header_child_others(i, header, prefix)

    typename = helpers.get_prefixe_name(obj.name, prefix)
    header.write("}\n%s;\n\n" % typename)
    header.write("void free_%s(%s *ptr);\n\n" % (typename, typename))
    header.write("%s *make_%s(yajl_val tree, const struct parser_context *ctx, parser_error *err)"\
        ";\n\n" % (typename, typename))
    header.write("yajl_gen_status gen_%s(yajl_gen g, const %s *ptr, const struct parser_context "\
        "*ctx, parser_error *err);\n\n" % (typename, typename))
Ejemplo n.º 6
0
def parse_obj_type(obj, c_file, prefix, obj_typename):
    """
    Description: generate c language for parse object type
    Interface: None
    History: 2019-06-17
    """
    if obj.typ == 'string':
        c_file.write('    {\n')
        read_val_generator(c_file, 2, 'get_val(tree, "%s", yajl_t_string)' % obj.origname, \
                             "ret->%s" % obj.fixname, obj.typ, obj.origname, obj_typename)
        c_file.write('    }\n')
    elif helpers.judge_data_type(obj.typ):
        c_file.write('    {\n')
        read_val_generator(c_file, 2, 'get_val(tree, "%s", yajl_t_number)' % obj.origname, \
                             "ret->%s" % obj.fixname, obj.typ, obj.origname, obj_typename)
        c_file.write('    }\n')
    elif helpers.judge_data_pointer_type(obj.typ):
        c_file.write('    {\n')
        read_val_generator(c_file, 2, 'get_val(tree, "%s", yajl_t_number)' % obj.origname, \
                             "ret->%s" % obj.fixname, obj.typ, obj.origname, obj_typename)
        c_file.write('    }\n')
    if obj.typ == 'boolean':
        c_file.write('    {\n')
        read_val_generator(c_file, 2, 'get_val(tree, "%s", yajl_t_true)' % obj.origname, \
                             "ret->%s" % obj.fixname, obj.typ, obj.origname, obj_typename)
        c_file.write('    }\n')
    if obj.typ == 'booleanPointer':
        c_file.write('    {\n')
        read_val_generator(c_file, 2, 'get_val(tree, "%s", yajl_t_true)' % obj.origname, \
                             "ret->%s" % obj.fixname, obj.typ, obj.origname, obj_typename)
        c_file.write('    }\n')
    elif obj.typ == 'object' or obj.typ == 'mapStringObject':
        if obj.subtypname is not None:
            typename = obj.subtypname
        else:
            typename = helpers.get_prefixe_name(obj.name, prefix)
        c_file.write(
            '    ret->%s = make_%s(get_val(tree, "%s", yajl_t_object), ctx, err);\n' \
            % (obj.fixname, typename, obj.origname))
        c_file.write("    if (ret->%s == NULL && *err != 0) {\n" % obj.fixname)
        c_file.write("        free_%s(ret);\n" % obj_typename)
        c_file.write("        return NULL;\n")
        c_file.write("    }\n")
    elif obj.typ == 'array' and (obj.subtypobj or obj.subtyp == 'object'):
        if obj.subtypname:
            typename = obj.subtypname
        else:
            typename = helpers.get_name_substr(obj.name, prefix)
        c_file.write('    {\n')
        c_file.write('        yajl_val tmp = get_val(tree, "%s", yajl_t_array);\n' \
                     % (obj.origname))
        c_file.write('        if (tmp != NULL && YAJL_GET_ARRAY(tmp) != NULL &&' \
                     ' YAJL_GET_ARRAY(tmp)->len > 0) {\n')
        c_file.write('            size_t i;\n')
        c_file.write('            ret->%s_len = YAJL_GET_ARRAY(tmp)->len;\n' %
                     (obj.fixname))
        c_file.write('            ret->%s = safe_malloc((YAJL_GET_ARRAY(tmp)->len + 1) ' \
                     '* sizeof(*ret->%s));\n' % (obj.fixname, obj.fixname))
        c_file.write(
            '            for (i = 0; i < YAJL_GET_ARRAY(tmp)->len; i++) {\n')
        c_file.write(
            '                yajl_val val = YAJL_GET_ARRAY(tmp)->values[i];\n')
        c_file.write('                ret->%s[i] = make_%s(val, ctx, err);\n' \
                     % (obj.fixname, typename))
        c_file.write('                if (ret->%s[i] == NULL) {\n' %
                     (obj.fixname))
        c_file.write("                    free_%s(ret);\n" % obj_typename)
        c_file.write("                    return NULL;\n")
        c_file.write('                }\n')
        c_file.write('            }\n')
        c_file.write('        }\n')
        c_file.write('    }\n')
    elif obj.typ == 'array' and obj.subtyp == 'byte':
        c_file.write('    {\n')
        c_file.write('        yajl_val tmp = get_val(tree, "%s", yajl_t_string);\n' \
                     % (obj.origname))
        c_file.write('        if (tmp != NULL) {\n')
        c_file.write('            char *str = YAJL_GET_STRING(tmp);\n')
        c_file.write('            ret->%s = (uint8_t *)safe_strdup(str ? str : "");\n' \
                     % obj.fixname)
        c_file.write('            ret->%s_len = str != NULL ? strlen(str) : 0;\n' \
                     % obj.fixname)
        c_file.write('        }\n')
        c_file.write('    }\n')
    elif obj.typ == 'array':
        c_file.write('    {\n')
        c_file.write('        yajl_val tmp = get_val(tree, "%s", yajl_t_array);\n' \
                     % (obj.origname))
        c_file.write('        if (tmp != NULL && YAJL_GET_ARRAY(tmp) != NULL &&'  \
                     ' YAJL_GET_ARRAY(tmp)->len > 0) {\n')
        c_file.write('            size_t i;\n')
        c_file.write('            ret->%s_len = YAJL_GET_ARRAY(tmp)->len;\n' %
                     (obj.fixname))
        c_file.write(
            '            ret->%s = safe_malloc((YAJL_GET_ARRAY(tmp)->len + 1) *' \
            ' sizeof(*ret->%s));\n' % (obj.fixname, obj.fixname))
        c_file.write(
            '            for (i = 0; i < YAJL_GET_ARRAY(tmp)->len; i++) {\n')
        read_val_generator(c_file, 4, 'YAJL_GET_ARRAY(tmp)->values[i]', \
                             "ret->%s[i]" % obj.fixname, obj.subtyp, obj.origname, obj_typename)
        c_file.write('            }\n')
        c_file.write('        }\n')
        c_file.write('    }\n')
    elif helpers.valid_basic_map_name(obj.typ):
        c_file.write('    {\n')
        c_file.write('        yajl_val tmp = get_val(tree, "%s", yajl_t_object);\n' \
                     % (obj.origname))
        c_file.write('        if (tmp != NULL) {\n')
        c_file.write('            ret->%s = make_%s(tmp, ctx, err);\n' \
                     % (obj.fixname, helpers.make_basic_map_name(obj.typ)))
        c_file.write('            if (ret->%s == NULL) {\n' % (obj.fixname))
        c_file.write('                char *new_error = NULL;\n')
        c_file.write("                if (asprintf(&new_error, \"Value error for key" \
                     " '%s': %%s\", *err ? *err : \"null\") < 0) {\n" % (obj.origname))
        c_file.write('                    new_error = safe_strdup(' \
                     '"error allocating memory");\n')
        c_file.write('                }\n')
        c_file.write('                free(*err);\n')
        c_file.write('                *err = new_error;\n')
        c_file.write('                free_%s(ret);\n' % obj_typename)
        c_file.write('                return NULL;\n')
        c_file.write('            }\n')
        c_file.write('        }\n')
        c_file.write('    }\n')
Ejemplo n.º 7
0
def make_c_free(obj, c_file, prefix):
    """
    Description: generate c free function
    Interface: None
    History: 2019-06-17
    """
    if not helpers.judge_complex(obj.typ) or obj.subtypname:
        return
    typename = helpers.get_prefixe_name(obj.name, prefix)
    case = obj.typ
    result = {
        'mapStringObject': lambda x: [],
        'object': lambda x: x.children,
        'array': lambda x: x.subtypobj
    }[case](obj)
    objs = result
    if obj.typ == 'array':
        if objs is None:
            return
        else:
            typename = helpers.get_name_substr(obj.name, prefix)
    c_file.write("void free_%s(%s *ptr) {\n" % (typename, typename))
    c_file.write("    if (ptr == NULL)\n")
    c_file.write("        return;\n")
    if obj.typ == 'mapStringObject':
        child = obj.children[0]
        if helpers.valid_basic_map_name(child.typ):
            childname = helpers.make_basic_map_name(child.typ)
        else:
            if child.subtypname:
                childname = child.subtypname
            else:
                childname = helpers.get_prefixe_name(child.name, prefix)
        c_file_map_str(c_file, child, childname)
    for i in objs or []:
        if helpers.valid_basic_map_name(i.typ):
            free_func = helpers.make_basic_map_name(i.typ)
            c_file.write("    free_%s(ptr->%s);\n" % (free_func, i.fixname))
            c_file.write("    ptr->%s = NULL;\n" % (i.fixname))
        if i.typ == 'mapStringObject':
            if i.subtypname:
                free_func = i.subtypname
            else:
                free_func = helpers.get_prefixe_name(i.name, prefix)
            c_file.write("    free_%s(ptr->%s);\n" % (free_func, i.fixname))
            c_file.write("    ptr->%s = NULL;\n" % (i.fixname))
        elif i.typ == 'array':
            if helpers.valid_basic_map_name(i.subtyp):
                free_func = helpers.make_basic_map_name(i.subtyp)
                c_file.write("    if (ptr->%s != NULL) {\n" % i.fixname)
                c_file.write("        size_t i;\n")
                c_file.write("        for (i = 0; i < ptr->%s_len; i++) {\n" %
                             i.fixname)
                c_file.write("            if (ptr->%s[i] != NULL) {\n" %
                             (i.fixname))
                c_file.write("                free_%s(ptr->%s[i]);\n" %
                             (free_func, i.fixname))
                c_file.write("                ptr->%s[i] = NULL;\n" %
                             (i.fixname))
                c_file.write("            }\n")
                c_file.write("        }\n")
                c_file.write("        free(ptr->%s);\n" % (i.fixname))
                c_file.write("        ptr->%s = NULL;\n" % (i.fixname))
                c_file.write("    }\n")
            elif i.subtyp == 'string':
                c_file_str(c_file, i)
            elif not helpers.judge_complex(i.subtyp):
                c_file.write("    free(ptr->%s);\n" % (i.fixname))
                c_file.write("    ptr->%s = NULL;\n" % (i.fixname))
            elif i.subtyp == 'object' or i.subtypobj is not None:
                if i.subtypname is not None:
                    free_func = i.subtypname
                else:
                    free_func = helpers.get_name_substr(i.name, prefix)
                c_file.write("    if (ptr->%s != NULL) {\n" % i.fixname)
                c_file.write("        size_t i;\n")
                c_file.write("        for (i = 0; i < ptr->%s_len; i++)\n" %
                             i.fixname)
                c_file.write("            if (ptr->%s[i] != NULL) {\n" %
                             (i.fixname))
                c_file.write("                free_%s(ptr->%s[i]);\n" %
                             (free_func, i.fixname))
                c_file.write("                ptr->%s[i] = NULL;\n" %
                             (i.fixname))
                c_file.write("            }\n")
                c_file.write("        free(ptr->%s);\n" % i.fixname)
                c_file.write("        ptr->%s = NULL;\n" % (i.fixname))
                c_file.write("    }\n")
            c_typ = helpers.obtain_pointer(i.name, i.subtypobj, prefix)
            if c_typ == "":
                continue
            if i.subobj is not None:
                c_typ = c_typ + "_element"
            c_file.write("    free_%s(ptr->%s);\n" % (c_typ, i.fixname))
            c_file.write("    ptr->%s = NULL;\n" % (i.fixname))
        else:
            typename = helpers.get_prefixe_name(i.name, prefix)
            if i.typ == 'string' or i.typ == 'booleanPointer' or \
                    helpers.judge_data_pointer_type(i.typ):
                c_file.write("    free(ptr->%s);\n" % (i.fixname))
                c_file.write("    ptr->%s = NULL;\n" % (i.fixname))
            elif i.typ == 'object':
                if i.subtypname is not None:
                    typename = i.subtypname
                c_file.write("    if (ptr->%s != NULL) {\n" % (i.fixname))
                c_file.write("        free_%s(ptr->%s);\n" %
                             (typename, i.fixname))
                c_file.write("        ptr->%s = NULL;\n" % (i.fixname))
                c_file.write("    }\n")
    c_file.write("    free(ptr);\n")
    c_file.write("}\n\n")
Ejemplo n.º 8
0
def get_obj_arr_obj(obj, c_file, prefix):
    """
    Description: c language generate object or array object
    Interface: None
    History: 2019-06-17
    """
    if obj.typ == 'string':
        c_file.write('    if ((ctx->options & OPT_GEN_KAY_VALUE) ||' \
                     ' (ptr != NULL && ptr->%s != NULL)) {\n' % obj.fixname)
        c_file.write('        char *str = "";\n')
        c_file.write('        stat = yajl_gen_string((yajl_gen)g, \
            (const unsigned char *)("%s"), strlen("%s"));\n' %
                     (obj.origname, obj.origname))
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write("        if (ptr != NULL && ptr->%s != NULL) {\n" %
                     obj.fixname)
        c_file.write("            str = ptr->%s;\n" % obj.fixname)
        c_file.write("        }\n")
        json_value_generator(c_file, 2, "str", 'g', 'ctx', obj.typ)
        c_file.write("    }\n")
    elif helpers.judge_data_type(obj.typ):
        c_file.write('    if ((ctx->options & OPT_GEN_KAY_VALUE) ||' \
                     ' (ptr != NULL && ptr->%s)) {\n' % obj.fixname)
        if obj.typ == 'double':
            numtyp = 'double'
        elif obj.typ.startswith(
                "uint") or obj.typ == 'GID' or obj.typ == 'UID':
            numtyp = 'long long unsigned int'
        else:
            numtyp = 'long long int'
        c_file.write('        %s num = 0;\n' % numtyp)
        c_file.write('        stat = yajl_gen_string((yajl_gen)g, \
            (const unsigned char *)("%s"), strlen("%s"));\n' %
                     (obj.origname, obj.origname))
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write("        if (ptr != NULL && ptr->%s) {\n" % obj.fixname)
        c_file.write("            num = (%s)ptr->%s;\n" %
                     (numtyp, obj.fixname))
        c_file.write("        }\n")
        json_value_generator(c_file, 2, "num", 'g', 'ctx', obj.typ)
        c_file.write("    }\n")
    elif helpers.judge_data_pointer_type(obj.typ):
        c_file.write('    if ((ptr != NULL && ptr->%s != NULL)) {\n' %
                     obj.fixname)
        numtyp = helpers.obtain_data_pointer_type(obj.typ)
        if numtyp == "":
            return
        c_file.write('        %s num = 0;\n' % helpers.get_map_c_types(numtyp))
        c_file.write('        stat = yajl_gen_string((yajl_gen)g, \
            (const unsigned char *)("%s"), strlen("%s"));\n' %
                     (obj.origname, obj.origname))
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write("        if (ptr != NULL && ptr->%s != NULL) {\n" %
                     obj.fixname)
        c_file.write("            num = (%s)*(ptr->%s);\n" \
                     % (helpers.get_map_c_types(numtyp), obj.fixname))
        c_file.write("        }\n")
        json_value_generator(c_file, 2, "num", 'g', 'ctx', numtyp)
        c_file.write("    }\n")
    elif obj.typ == 'boolean':
        c_file.write('    if ((ctx->options & OPT_GEN_KAY_VALUE) ||' \
                     ' (ptr != NULL && ptr->%s)) {\n' % obj.fixname)
        c_file.write('        bool b = false;\n')
        c_file.write('        stat = yajl_gen_string((yajl_gen)g, \
            (const unsigned char *)("%s"), strlen("%s"));\n' %
                     (obj.origname, obj.origname))
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write("        if (ptr != NULL && ptr->%s) {\n" % obj.fixname)
        c_file.write("            b = ptr->%s;\n" % obj.fixname)
        c_file.write("        }\n")
        json_value_generator(c_file, 2, "b", 'g', 'ctx', obj.typ)
        c_file.write("    }\n")
    elif obj.typ == 'object' or obj.typ == 'mapStringObject':
        if obj.subtypname:
            typename = obj.subtypname
        else:
            typename = helpers.get_prefixe_name(obj.name, prefix)
        c_file.write('    if ((ctx->options & OPT_GEN_KAY_VALUE) ||' \
                     ' (ptr != NULL && ptr->%s != NULL)) {\n' % obj.fixname)
        c_file.write('        stat = yajl_gen_string((yajl_gen)g, \
            (const unsigned char *)("%s"), strlen("%s"));\n' %
                     (obj.origname, obj.origname))
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write('        stat = gen_%s(g, ptr != NULL ? ptr->%s : NULL, ctx, err);\n' \
                     % (typename, obj.fixname))
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write("    }\n")
    elif obj.typ == 'array' and (obj.subtypobj or obj.subtyp == 'object'):
        if obj.subtypname:
            typename = obj.subtypname
        else:
            typename = helpers.get_name_substr(obj.name, prefix)
        c_file.write('    if ((ctx->options & OPT_GEN_KAY_VALUE) || ' \
                     '(ptr != NULL && ptr->%s != NULL)) {\n' % obj.fixname)
        c_file.write('        size_t len = 0, i;\n')
        c_file.write('        stat = yajl_gen_string((yajl_gen)g, \
            (const unsigned char *)("%s"), strlen("%s"));\n' %
                     (obj.origname, obj.origname))
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write("        if (ptr != NULL && ptr->%s != NULL) {\n" %
                     obj.fixname)
        c_file.write("            len = ptr->%s_len;\n" % obj.fixname)
        c_file.write("        }\n")
        c_file.write(
            "        if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n")
        c_file.write('            yajl_gen_config(g, yajl_gen_beautify, 0);\n')
        c_file.write('        stat = yajl_gen_array_open((yajl_gen)g);\n')
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write('        for (i = 0; i < len; i++) {\n')
        c_file.write('            stat = gen_%s(g, ptr->%s[i], ctx, err);\n' \
                     % (typename, obj.fixname))
        c_file.write("            if (yajl_gen_status_ok != stat)\n")
        c_file.write("                GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write('        }\n')
        c_file.write('        stat = yajl_gen_array_close((yajl_gen)g);\n')
        c_file.write(
            "        if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n")
        c_file.write('            yajl_gen_config(g, yajl_gen_beautify, 1);\n')
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write('    }\n')
    elif obj.typ == 'array' and obj.subtyp == 'byte':
        c_file.write('    if ((ctx->options & OPT_GEN_KAY_VALUE) ||' \
                     ' (ptr != NULL && ptr->%s != NULL && ptr->%s_len)) {\n' \
                     % (obj.fixname, obj.fixname))
        c_file.write('        const char *str = "";\n')
        c_file.write('        size_t len = 0;\n')
        c_file.write('        stat = yajl_gen_string((yajl_gen)g, \
        (const unsigned char *)("%s"), strlen("%s"));\n' %
                     (obj.origname, obj.origname))
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write("        if (ptr != NULL && ptr->%s != NULL) {\n" %
                     obj.fixname)
        c_file.write("            str = (const char *)ptr->%s;\n" %
                     obj.fixname)
        c_file.write("            len = ptr->%s_len;\n" % obj.fixname)
        c_file.write("        }\n")
        c_file.write('        stat = yajl_gen_string((yajl_gen)g, \
        (const unsigned char *)str, len);\n')
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write("    }\n")
    elif obj.typ == 'array':
        c_file.write('    if ((ctx->options & OPT_GEN_KAY_VALUE) || ' \
                     '(ptr != NULL && ptr->%s != NULL)) {\n' % obj.fixname)
        c_file.write('        size_t len = 0, i;\n')
        c_file.write('        stat = yajl_gen_string((yajl_gen)g, \
            (const unsigned char *)("%s"), strlen("%s"));\n' %
                     (obj.origname, obj.origname))
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write("        if (ptr != NULL && ptr->%s != NULL) {\n" %
                     obj.fixname)
        c_file.write("            len = ptr->%s_len;\n" % obj.fixname)
        c_file.write("        }\n")
        c_file.write(
            "        if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n")
        c_file.write('            yajl_gen_config(g, yajl_gen_beautify, 0);\n')
        c_file.write('        stat = yajl_gen_array_open((yajl_gen)g);\n')
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write('        for (i = 0; i < len; i++) {\n')
        json_value_generator(c_file, 3, "ptr->%s[i]" % obj.fixname, 'g', 'ctx',
                             obj.subtyp)
        c_file.write('        }\n')
        c_file.write('        stat = yajl_gen_array_close((yajl_gen)g);\n')
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write(
            "        if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n")
        c_file.write('            yajl_gen_config(g, yajl_gen_beautify, 1);\n')
        c_file.write('    }\n')
    elif helpers.valid_basic_map_name(obj.typ):
        c_file.write('    if ((ctx->options & OPT_GEN_KAY_VALUE) || ' \
                     '(ptr != NULL && ptr->%s != NULL)) {\n' % obj.fixname)
        c_file.write('        stat = yajl_gen_string((yajl_gen)g, \
        (const unsigned char *)("%s"), strlen("%s"));\n' %
                     (obj.origname, obj.origname))
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write('        stat = gen_%s(g, ptr ? ptr->%s : NULL, ctx, err);\n' \
                     % (helpers.make_basic_map_name(obj.typ), obj.fixname))
        c_file.write("        if (yajl_gen_status_ok != stat)\n")
        c_file.write("            GEN_SET_ERROR_AND_RETURN(stat, err);\n")
        c_file.write("    }\n")