From 122cae5e6830abf3e023d14979f7676c44253fc7 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Fri, 3 Jun 2016 00:57:46 +0200 Subject: [PATCH 2/2] Fix Clang compilation warnings by explicit typecasts between enums and change the libical-glib-private.h to not redefine types. A little change in annotation in i-cal-timezone-phase.xml had been fixed too. --- src/libical-glib/api/i-cal-component.xml | 2 +- src/libical-glib/api/i-cal-derived-parameter.xml | 42 ++-- src/libical-glib/api/i-cal-derived-property.xml | 2 +- src/libical-glib/api/i-cal-derived-value.xml | 46 ++-- src/libical-glib/api/i-cal-enums.xml | 4 +- src/libical-glib/api/i-cal-error.xml | 4 +- src/libical-glib/api/i-cal-parser.xml | 2 +- src/libical-glib/api/i-cal-recurrence-type.xml | 30 +-- src/libical-glib/api/i-cal-restriction.xml | 2 +- src/libical-glib/api/i-cal-timezone-phase.xml | 6 +- .../api/i-cal-unknowntokenhandling.xml | 2 +- src/libical-glib/tools/generator.c | 245 +++++++++++++-------- src/libical-glib/tools/generator.h | 2 +- src/libical-glib/tools/xml-parser.c | 30 +-- src/libical-glib/tools/xml-parser.h | 1 + 15 files changed, 239 insertions(+), 181 deletions(-) diff --git a/src/libical-glib/api/i-cal-component.xml b/src/libical-glib/api/i-cal-component.xml index 5115eb3..f1f431a 100644 --- a/src/libical-glib/api/i-cal-component.xml +++ b/src/libical-glib/api/i-cal-component.xml @@ -14,7 +14,7 @@ along with this library. If not, see . --> - + Create a new #ICalComponent with specific type. diff --git a/src/libical-glib/api/i-cal-derived-parameter.xml b/src/libical-glib/api/i-cal-derived-parameter.xml index bb9a1fe..c6b2f47 100644 --- a/src/libical-glib/api/i-cal-derived-parameter.xml +++ b/src/libical-glib/api/i-cal-derived-parameter.xml @@ -14,7 +14,7 @@ along with this library. If not, see . --> - + @@ -63,13 +63,13 @@ - + - + @@ -78,19 +78,19 @@ - + - + - + @@ -98,13 +98,13 @@ - + - + @@ -116,19 +116,19 @@ - + - + - + @@ -136,13 +136,13 @@ - + - + @@ -150,38 +150,38 @@ - + - + - + - + - + - + @@ -199,7 +199,7 @@ - + @@ -212,7 +212,7 @@ - + diff --git a/src/libical-glib/api/i-cal-derived-property.xml b/src/libical-glib/api/i-cal-derived-property.xml index e8b76aa..1a64919 100644 --- a/src/libical-glib/api/i-cal-derived-property.xml +++ b/src/libical-glib/api/i-cal-derived-property.xml @@ -14,7 +14,7 @@ along with this library. If not, see . --> - + diff --git a/src/libical-glib/api/i-cal-derived-value.xml b/src/libical-glib/api/i-cal-derived-value.xml index c989e79..201ec72 100644 --- a/src/libical-glib/api/i-cal-derived-value.xml +++ b/src/libical-glib/api/i-cal-derived-value.xml @@ -14,7 +14,7 @@ along with this library. If not, see . --> - + @@ -52,36 +52,36 @@ - - + + - - + + - + - - + + - + @@ -97,7 +97,7 @@ - + @@ -116,27 +116,27 @@ - - + + - - + + - + - - + + @@ -147,21 +147,21 @@ - - + + - - + + - - + + diff --git a/src/libical-glib/api/i-cal-enums.xml b/src/libical-glib/api/i-cal-enums.xml index 6a0c791..d6c4035 100644 --- a/src/libical-glib/api/i-cal-enums.xml +++ b/src/libical-glib/api/i-cal-enums.xml @@ -14,7 +14,7 @@ along with this library. If not, see . --> - + @@ -47,7 +47,7 @@ - + diff --git a/src/libical-glib/api/i-cal-error.xml b/src/libical-glib/api/i-cal-error.xml index 0645905..5e3d795 100644 --- a/src/libical-glib/api/i-cal-error.xml +++ b/src/libical-glib/api/i-cal-error.xml @@ -14,7 +14,7 @@ along with this library. If not, see . --> - + @@ -27,7 +27,7 @@ - + diff --git a/src/libical-glib/api/i-cal-parser.xml b/src/libical-glib/api/i-cal-parser.xml index 4dc75c9..b8f5db2 100644 --- a/src/libical-glib/api/i-cal-parser.xml +++ b/src/libical-glib/api/i-cal-parser.xml @@ -14,7 +14,7 @@ along with this library. If not, see . --> - + diff --git a/src/libical-glib/api/i-cal-recurrence-type.xml b/src/libical-glib/api/i-cal-recurrence-type.xml index a7c7d10..d3efcfe 100644 --- a/src/libical-glib/api/i-cal-recurrence-type.xml +++ b/src/libical-glib/api/i-cal-recurrence-type.xml @@ -14,7 +14,7 @@ along with this library. If not, see . --> - + @@ -24,7 +24,7 @@ - + @@ -34,24 +34,24 @@ - + - - - - - - - Check whether rscale is supported. - - - - Get an array of calendars supporting rscale (currently always return NULL). - + + + + + + + Check whether rscale is supported. + + + + Get an array of calendars supporting rscale (currently always return NULL). + struct icalrecurrencetype ret; diff --git a/src/libical-glib/api/i-cal-restriction.xml b/src/libical-glib/api/i-cal-restriction.xml index 0e1bf3c..30198ca 100644 --- a/src/libical-glib/api/i-cal-restriction.xml +++ b/src/libical-glib/api/i-cal-restriction.xml @@ -14,7 +14,7 @@ along with this library. If not, see . --> - + diff --git a/src/libical-glib/api/i-cal-timezone-phase.xml b/src/libical-glib/api/i-cal-timezone-phase.xml index 9f9f127..ead6113 100644 --- a/src/libical-glib/api/i-cal-timezone-phase.xml +++ b/src/libical-glib/api/i-cal-timezone-phase.xml @@ -34,7 +34,7 @@ - + Get the is_stdandard of #ICalTimezonePhase. g_return_val_if_fail (phase != NULL && I_CAL_IS_TIMEZONE_PHASE (phase), FALSE); return ((struct icaltimezonephase *)i_cal_object_get_native ((ICalObject *)phase))->is_stdandard; @@ -63,7 +63,7 @@ - + Get the offsetto of #ICalTimezonePhase. Returns -61 if there is an error. g_return_val_if_fail (phase != NULL && I_CAL_IS_TIMEZONE_PHASE (phase), -61); return ((struct icaltimezonephase *)i_cal_object_get_native ((ICalObject *)phase))->offsetto; @@ -77,7 +77,7 @@ - + Get the tzoffsetfrom of #ICalTimezonePhase. Returns -61 if there is an error. g_return_val_if_fail (phase != NULL && I_CAL_IS_TIMEZONE_PHASE (phase), -61); return ((struct icaltimezonephase *)i_cal_object_get_native ((ICalObject *)phase))->tzoffsetfrom; diff --git a/src/libical-glib/api/i-cal-unknowntokenhandling.xml b/src/libical-glib/api/i-cal-unknowntokenhandling.xml index 0a4819f..fed510a 100644 --- a/src/libical-glib/api/i-cal-unknowntokenhandling.xml +++ b/src/libical-glib/api/i-cal-unknowntokenhandling.xml @@ -14,7 +14,7 @@ along with this library. If not, see . --> - + diff --git a/src/libical-glib/tools/generator.c b/src/libical-glib/tools/generator.c index 5be856e..7bf7278 100644 --- a/src/libical-glib/tools/generator.c +++ b/src/libical-glib/tools/generator.c @@ -14,6 +14,8 @@ * along with this library. If not, see . */ +#include + #include "generator.h" static const gchar *templates_dir = NULL; @@ -343,7 +345,7 @@ void generate_header_method_get_type(FILE *out, Structure *structure) get_type->ret->type = g_strdup("GType"); get_type->name = g_strconcat(lowerSnake, "_get_type", NULL); g_free(lowerSnake); - generate_header_method_proto(out, get_type); + generate_header_method_proto(out, get_type, FALSE); method_free(get_type); } @@ -392,7 +394,7 @@ void generate_header_method_new_full(FILE *out, Structure *structure) para = NULL; } - generate_header_method_proto(out, new_full); + generate_header_method_proto(out, new_full, TRUE); method_free(new_full); } @@ -638,6 +640,19 @@ gchar *get_source_method_proto_get_property(Structure *structure) return res; } +static void write_str(FILE *fp, const gchar *str) +{ + gint len; + + g_return_if_fail(fp != NULL); + g_return_if_fail(str != NULL); + + len = strlen(str); + + if (fwrite(str, sizeof(gchar), len, fp) != (size_t) len) + g_error("Failed to write %d bytes to file: %s", len, g_strerror(errno)); +} + static FILE *open_private_header(void) { static gboolean first_private_header_write = TRUE; @@ -652,7 +667,8 @@ static FILE *open_private_header(void) fp = fopen(PRIVATE_HEADER, mode); if ((g_strcmp0(mode, "wb") == 0) && fp != NULL) { - (void)fwrite(guard, sizeof(gchar), strlen(guard), fp); + write_str(fp, guard); + write_str(fp, "\n#include \"libical-glib.h\"\n"); } return fp; } @@ -664,7 +680,7 @@ static void close_private_header(void) fp = fopen(PRIVATE_HEADER, "ab"); if (fp != NULL) { - (void)fwrite(endGuard, sizeof(gchar), strlen(endGuard), fp); + write_str(fp, endGuard); (void)fclose(fp); } } @@ -679,7 +695,7 @@ void generate_header_method_protos(FILE *out, Structure *structure) privateHeader = NULL; typeName = g_strconcat(structure->nameSpace, structure->name, NULL); - privateHeaderComment = g_strconcat("/* Private header for ", typeName, " */\n", NULL); + privateHeaderComment = g_strconcat("\n/* Private methods for ", typeName, " */\n", NULL); if (structure->native != NULL) { /** Open or create the private header file if it does not exist. @@ -687,14 +703,7 @@ void generate_header_method_protos(FILE *out, Structure *structure) * Create the new_full method in it. */ privateHeader = open_private_header(); - (void)fwrite(privateHeaderComment, sizeof(gchar), strlen(privateHeaderComment), - privateHeader); - (void)fwrite("typedef struct _", sizeof(gchar), strlen("typedef struct _"), privateHeader); - (void)fwrite(typeName, sizeof(gchar), strlen(typeName), privateHeader); - fputc(' ', privateHeader); - (void)fwrite(typeName, sizeof(gchar), strlen(typeName), privateHeader); - fputc(';', privateHeader); - fputc('\n', privateHeader); + write_str(privateHeader, privateHeaderComment); generate_header_method_new_full(privateHeader, structure); generate_header_method_get_type(out, structure); @@ -708,17 +717,10 @@ void generate_header_method_protos(FILE *out, Structure *structure) If not, the forward declaration is needed. */ if (privateHeader == NULL) { privateHeader = open_private_header(); - (void)fwrite("typedef struct _", sizeof(gchar), strlen("typedef struct _"), - privateHeader); - (void)fwrite(typeName, sizeof(gchar), strlen(typeName), privateHeader); - fputc(' ', privateHeader); - (void)fwrite(typeName, sizeof(gchar), strlen(typeName), privateHeader); - fputc(';', privateHeader); - fputc('\n', privateHeader); } - generate_header_method_proto(privateHeader, method); + generate_header_method_proto(privateHeader, method, TRUE); } else { - generate_header_method_proto(out, method); + generate_header_method_proto(out, method, FALSE); } } @@ -730,7 +732,7 @@ void generate_header_method_protos(FILE *out, Structure *structure) } } -void generate_header_method_proto(FILE *out, Method *method) +void generate_header_method_proto(FILE *out, Method *method, gboolean isPrivate) { GList *iter_list; Parameter *para; @@ -742,13 +744,16 @@ void generate_header_method_proto(FILE *out, Method *method) buffer = g_new(gchar, BUFFER_SIZE); *buffer = '\0'; - fprintf(out, "\nLIBICAL_ICAL_EXPORT\n"); + if (isPrivate) + write_str(out, "\n"); + else + write_str(out, "\nLIBICAL_ICAL_EXPORT\n"); /* Generate the method return */ if (method->ret == NULL) { - (void)fwrite("void", sizeof(char), strlen("void"), out); + write_str(out, "void"); for (iter = 0; iter < RET_TAB_COUNT; iter++) { - (void)fwrite("\t", sizeof(char), strlen("\t"), out); + write_str(out, "\t"); } } else { count = (gint) strlen(method->ret->type) / TAB_SIZE; @@ -764,11 +769,11 @@ void generate_header_method_proto(FILE *out, Method *method) buffer[len + 1] = '\0'; } - (void)fwrite(method->ret->type, sizeof(char), strlen(method->ret->type), out); + write_str(out, method->ret->type); if (method->ret->type[strlen(method->ret->type) - 1] != '*') { - fputc(' ', out); + write_str(out, " "); } - (void)fwrite(buffer, sizeof(gchar), strlen(buffer), out); + write_str(out, buffer); } /* Generate the method name */ @@ -791,8 +796,8 @@ void generate_header_method_proto(FILE *out, Method *method) } } - (void)fwrite(method->name, sizeof(char), strlen(method->name), out); - (void)fwrite(buffer, sizeof(gchar), strlen(buffer), out); + write_str(out, method->name); + write_str(out, buffer); /* Generate all the parameters */ for (iter = 0; iter < RET_TAB_COUNT + METHOD_NAME_TAB_COUNT; iter++) { @@ -801,27 +806,27 @@ void generate_header_method_proto(FILE *out, Method *method) buffer[iter] = '\0'; if (method->parameters == NULL) { - (void)fwrite("(void);", sizeof(gchar), strlen("(void);"), out); + write_str(out, "(void);"); } else { for (iter_list = g_list_first(method->parameters); iter_list != NULL; iter_list = g_list_next(iter_list)) { para = (Parameter *) iter_list->data; if (iter_list == g_list_first(method->parameters)) { - (void)fwrite("(", sizeof(char), strlen("("), out); + write_str(out, "("); } else { - (void)fwrite(",\n", sizeof(char), strlen(",\n"), out); - (void)fwrite(buffer, sizeof(gchar), strlen(buffer), out); - fputc(' ', out); + write_str(out, ",\n"); + write_str(out, buffer); + write_str(out, " "); } - (void)fwrite((char *)para->type, sizeof(char), strlen(para->type), out); + write_str(out, para->type); if (para->type[strlen(para->type) - 1] != '*') { - fputc(' ', out); + write_str(out, " "); } - (void)fwrite((char *)para->name, sizeof(char), strlen(para->name), out); + write_str(out, para->name); } - (void)fwrite(");", sizeof(char), strlen(");"), out); + write_str(out, ");"); } - fputc('\n', out); + write_str(out, "\n"); g_free(buffer); } @@ -881,9 +886,9 @@ void generate_code_from_template(FILE *in, FILE *out, Structure *structure, GHas iter = g_list_next(iter)) { method = get_source_method_body((Method *) iter->data, structure->nameSpace); - (void)fwrite(method, sizeof(gchar), strlen(method), out); + write_str(out, method); if (iter != g_list_last(structure->methods)) { - (void)fwrite("\n\n", sizeof(gchar), strlen("\n\n"), out); + write_str(out, "\n\n"); } g_free(method); } @@ -901,14 +906,14 @@ void generate_code_from_template(FILE *in, FILE *out, Structure *structure, GHas generate_header_header_declaration(out, structure); } else if (g_hash_table_contains(table, buffer)) { val = g_hash_table_lookup(table, buffer); - (void)fwrite(val, sizeof(gchar), strlen(val), out); + write_str(out, val); val = NULL; } else if (g_strcmp0(buffer, "structure_boilerplate") == 0) { if (structure->native != NULL) generate_header_structure_boilerplate(out, structure, table); } else if (g_hash_table_contains(table, buffer)) { val = g_hash_table_lookup(table, buffer); - (void)fwrite(val, sizeof(gchar), strlen(val), out); + write_str(out, val); val = NULL; } else if (g_strcmp0(buffer, "source_boilerplate") == 0) { if (structure->native != NULL) @@ -969,14 +974,14 @@ void generate_header_includes(FILE *out, Structure *structure) for (iter = g_list_first(structure->includes); iter != NULL; iter = g_list_next(iter)) { includeName = (gchar *) iter->data; - (void)fwrite("#include <", sizeof(gchar), strlen("#include <"), out); - (void)fwrite(includeName, sizeof(gchar), strlen(includeName), out); - (void)fwrite(">\n", sizeof(gchar), strlen(">\n"), out); + write_str(out, "#include <"); + write_str(out, includeName); + write_str(out, ">\n"); } - (void)fwrite("#include <", sizeof(gchar), strlen("#include <"), out); - (void)fwrite(COMMON_HEADER, sizeof(gchar), strlen(COMMON_HEADER), out); - (void)fwrite(".h>\n", sizeof(gchar), strlen(".h>\n"), out); + write_str(out, "#include <"); + write_str(out, COMMON_HEADER); + write_str(out, ".h>\n"); g_return_if_fail(out != NULL && structure != NULL); @@ -1017,10 +1022,9 @@ void generate_header_includes(FILE *out, Structure *structure) for (g_hash_table_iter_init(&iter_table, includeNames); g_hash_table_iter_next(&iter_table, &key, &value);) { includeName = (gchar *) key; - (void)fwrite("#include \n", sizeof(gchar), strlen(".h>\n"), out); + write_str(out, "#include \n"); } g_hash_table_destroy(includeNames); } @@ -1045,14 +1049,14 @@ void generate_source_includes(FILE *out, Structure *structure) upperCamel = g_strconcat(structure->nameSpace, structure->name, NULL); lowerTrain = get_lower_train_from_upper_camel(upperCamel); g_free(upperCamel); - (void)fwrite("#include \"", sizeof(gchar), strlen("#include \""), out); - (void)fwrite(lowerTrain, sizeof(gchar), strlen(lowerTrain), out); - (void)fwrite(".h\"\n", sizeof(gchar), strlen(".h\"\n"), out); + write_str(out, "#include \""); + write_str(out, lowerTrain); + write_str(out, ".h\"\n"); g_free(lowerTrain); - (void)fwrite("#include \"", sizeof(gchar), strlen("#include \""), out); - (void)fwrite(PRIVATE_HEADER, sizeof(gchar), strlen(PRIVATE_HEADER), out); - (void)fwrite("\"\n", sizeof(gchar), strlen("\"\n"), out); + write_str(out, "#include \""); + write_str(out, PRIVATE_HEADER); + write_str(out, "\"\n"); for (g_hash_table_iter_init(&iter_table, structure->dependencies); g_hash_table_iter_next(&iter_table, &key, &value);) { @@ -1076,12 +1080,12 @@ void generate_source_includes(FILE *out, Structure *structure) for (g_hash_table_iter_init(&iter_table, includeNames); g_hash_table_iter_next(&iter_table, &key, &value);) { includeName = (gchar *) key; - (void)fwrite("#include \"", sizeof(gchar), strlen("#include \""), out); - (void)fwrite(includeName, sizeof(gchar), strlen(includeName), out); - (void)fwrite(".h\"\n", sizeof(gchar), strlen(".h\"\n"), out); + write_str(out, "#include \""); + write_str(out, includeName); + write_str(out, ".h\"\n"); } - fputc('\n', out); + write_str(out, "\n"); g_hash_table_destroy(includeNames); } @@ -1129,15 +1133,14 @@ void generate_header_forward_declaration(FILE *out, Structure *structure) for (g_hash_table_iter_init(&iter_table, includeNames); g_hash_table_iter_next(&iter_table, &key, &value);) { typeName = (gchar *) key; - (void)fwrite("typedef struct _", sizeof(gchar), strlen("typedef struct _"), out); - (void)fwrite(typeName, sizeof(gchar), strlen(typeName), out); - fputc(' ', out); - (void)fwrite(typeName, sizeof(gchar), strlen(typeName), out); - fputc(';', out); - fputc('\n', out); + write_str(out, "typedef struct _"); + write_str(out, typeName); + write_str(out, " "); + write_str(out, typeName); + write_str(out, ";\n"); } if (typeName != NULL) { - fputc('\n', out); + write_str(out, "\n"); } g_hash_table_destroy(includeNames); @@ -1327,7 +1330,7 @@ void generate_conditional(FILE *out, Structure *structure, gchar *statement, GHa if (g_hash_table_contains(table, var)) { val = g_hash_table_lookup(table, var); - (void)fwrite(val, sizeof(gchar), strlen(val), out); + write_str(out, val); val = NULL; } else { printf("The string %s is not recognized in conditional, " @@ -1381,6 +1384,23 @@ gchar *get_source_method_code(Method *method) return ret; } +static gboolean is_enum_type(const gchar *type) +{ + gchar *trueType; + const gchar *structureKind; + gboolean res = FALSE; + + g_return_val_if_fail(type != NULL, FALSE); + + trueType = get_true_type(type); + if (trueType && g_hash_table_contains(type2kind, trueType)) { + structureKind = g_hash_table_lookup(type2kind, trueType); + res = g_strcmp0 (structureKind, "enum") == 0; + } + + return res; +} + gchar *get_translator_for_parameter(Parameter *para) { gchar *trueType; @@ -1407,7 +1427,23 @@ gchar *get_translator_for_parameter(Parameter *para) } else { is_bare = structure->isBare; } - if (g_strcmp0(structureKind, "enum") != 0) { + if (g_strcmp0(structureKind, "enum") == 0) { + GList *link; + + for (link = structure->enumerations; link; link = g_list_next(link)) { + Enumeration *enumeration = link->data; + + if (g_strcmp0 (trueType, enumeration->name) == 0) { + if (!enumeration->nativeName) { + g_printerr("Missing 'native_name' for enum %s\n", enumeration->name); + break; + } + + res = g_strconcat("(", enumeration->nativeName, ")", NULL); + break; + } + } + } else { /* If the kind of parameter is specified */ if (para->native_op != NULL) { if (g_strcmp0(para->native_op, "OBJECT") == 0) { @@ -1461,8 +1497,31 @@ gchar *get_translator_for_return(Ret *ret) } else { trueType = get_true_type(ret->type); if (g_hash_table_contains(type2kind, trueType)) { + Structure *structure; + kind = g_strdup(g_hash_table_lookup(type2kind, trueType)); - if (g_strcmp0(kind, "enum") != 0) { + structure = g_hash_table_lookup(type2structure, trueType); + if (!structure) { + printf("ERROR: There is no corresponding structure for type %s\n", trueType); + } + + if (structure && g_strcmp0(kind, "enum") == 0) { + GList *link; + + for (link = structure->enumerations; link; link = g_list_next(link)) { + Enumeration *enumeration = link->data; + + if (g_strcmp0 (trueType, enumeration->name) == 0) { + if (!enumeration->nativeName) { + g_printerr("Missing 'native_name' for enum %s\n", enumeration->name); + break; + } + + res = g_strconcat("(", enumeration->name, ")", NULL); + break; + } + } + } else { lowerSnake = get_lower_snake_from_upper_camel(trueType); res = g_strconcat(lowerSnake, "_new_full", NULL); g_free(lowerSnake); @@ -1495,14 +1554,14 @@ gchar *get_inline_parameter(Parameter *para) if (translator != NULL) { (void)g_stpcpy(buffer + strlen(buffer), translator); (void)g_stpcpy(buffer + strlen(buffer), " ("); - if (para->translator == NULL) + if (para->translator == NULL && !is_enum_type(para->type)) (void)g_stpcpy(buffer + strlen(buffer), "I_CAL_OBJECT ("); } (void)g_stpcpy(buffer + strlen(buffer), para->name); if (translator != NULL) { - if (para->translator == NULL) { + if (para->translator == NULL && !is_enum_type(para->type)) { (void)g_stpcpy(buffer + strlen(buffer), ")"); } (void)g_stpcpy(buffer + strlen(buffer), ")"); @@ -1630,7 +1689,7 @@ gchar *get_source_method_body(Method *method, const gchar *nameSpace) trueType = get_true_type(method->ret->type); if (g_hash_table_contains(type2structure, trueType)) { structure = g_hash_table_lookup(type2structure, trueType); - if (structure->isBare == FALSE) { + if (!structure->isBare && !is_enum_type(method->ret->type)) { (void)g_stpcpy(buffer + strlen(buffer), ", NULL"); } } @@ -1831,7 +1890,7 @@ void generate_header_enums(FILE *out, Structure *structure) enumeration = (Enumeration *) iter->data; generate_header_enum(out, enumeration); - fputc('\n', out); + write_str(out, "\n"); } } @@ -1870,19 +1929,19 @@ void generate_header_enum(FILE *out, Enumeration *enumeration) g_free(comment); comment = tmp; - (void)fwrite(comment, sizeof(gchar), strlen(comment), out); + write_str(out, comment); g_free(comment); comment = NULL; tmp = NULL; } /*Generate the declaration */ - (void)fwrite("typedef enum {", sizeof(gchar), strlen("typedef enum {"), out); + write_str(out, "typedef enum {"); for (iter = g_list_first(enumeration->elements); iter != NULL; iter = g_list_next(iter)) { nativeName = (gchar *) iter->data; if (iter != g_list_first(enumeration->elements)) { - fputc(',', out); + write_str(out, ","); } if (enum_header_len >= (guint) strlen(nativeName)) { printf("The enum name %s is longer than the enum header %s\n", nativeName, ENUM_HEADER); @@ -1903,19 +1962,17 @@ void generate_header_enum(FILE *out, Enumeration *enumeration) newName = g_strconcat("I_CAL_", nativeName + i, NULL); } - fputc('\n', out); - fputc('\t', out); - (void)fwrite(newName, sizeof(gchar), strlen(newName), out); - (void)fwrite(" = ", sizeof(gchar), strlen(" = "), out); - (void)fwrite(nativeName, sizeof(gchar), strlen(nativeName), out); + write_str(out, "\n\t"); + write_str(out, newName); + write_str(out, " = "); + write_str(out, nativeName); g_free(newName); } - (void)fwrite("\n} ", sizeof(gchar), strlen("\n} "), out); - (void)fwrite(enumeration->name, sizeof(gchar), strlen(enumeration->name), out); - fputc(';', out); - fputc('\n', out); + write_str(out, "\n} "); + write_str(out, enumeration->name); + write_str(out, ";\n"); } gchar *get_source_run_time_checkers(Method *method, const gchar *namespace) @@ -2188,8 +2245,8 @@ void generate_header_header_declaration(FILE *out, Structure *structure) declaration = (Declaration *) list_iter->data; if (g_strcmp0(declaration->position, "header") == 0) { - (void)fwrite(declaration->content, sizeof(gchar), strlen(declaration->content), out); - fputc('\n', out); + write_str(out, declaration->content); + write_str(out, "\n"); } declaration = NULL; } @@ -2235,7 +2292,7 @@ void generate_header_header_file(GList *structures) upperCamel = g_strconcat(structure->nameSpace, structure->name, NULL); lowerTrain = get_lower_train_from_upper_camel(upperCamel); header = g_strconcat("#include \n", NULL); - (void)fwrite(header, sizeof(gchar), strlen(header), out); + write_str(out, header); g_free(header); g_free(upperCamel); g_free(lowerTrain); diff --git a/src/libical-glib/tools/generator.h b/src/libical-glib/tools/generator.h index 00f8cb4..b94daa7 100644 --- a/src/libical-glib/tools/generator.h +++ b/src/libical-glib/tools/generator.h @@ -72,7 +72,7 @@ gchar *get_source_method_proto_get_property(Structure *structure); GHashTable *get_hash_table_from_structure(Structure *structure); void generate_header_method_protos(FILE *out, Structure *structure); -void generate_header_method_proto(FILE *out, Method *method); +void generate_header_method_proto(FILE *out, Method *method, gboolean isPrivate); void generate_header_method_new_full(FILE *out, Structure *structure); void generate_header_method_get_type(FILE *out, Structure *structure); void generate_header_enums(FILE *out, Structure *structure); diff --git a/src/libical-glib/tools/xml-parser.c b/src/libical-glib/tools/xml-parser.c index 36d3611..81add51 100644 --- a/src/libical-glib/tools/xml-parser.c +++ b/src/libical-glib/tools/xml-parser.c @@ -20,7 +20,7 @@ Structure *structure_new() { Structure *structure; - structure = g_new(Structure, 1); + structure = g_new0(Structure, 1); structure->nameSpace = NULL; structure->name = NULL; structure->native = NULL; @@ -70,13 +70,12 @@ void structure_free(Structure * structure) g_free(structure->cloneFunc); g_free(structure->defaultNative); g_hash_table_destroy(structure->dependencies); - - structure = NULL; + g_free(structure); } Declaration *declaration_new() { - Declaration *declaration = g_new(Declaration, 1); + Declaration *declaration = g_new0(Declaration, 1); declaration->position = NULL; declaration->content = NULL; @@ -102,7 +101,7 @@ Method *method_new() { Method *method; - method = g_new(Method, 1); + method = g_new0(Method, 1); method->name = NULL; method->corresponds = NULL; @@ -138,15 +137,14 @@ void method_free(Method * method) g_free(method->comment); g_free(method->custom); ret_free(method->ret); - - method = NULL; + g_free(method); } Parameter *parameter_new() { Parameter *parameter; - parameter = g_new(Parameter, 1); + parameter = g_new0(Parameter, 1); parameter->comment = NULL; parameter->name = NULL; parameter->type = NULL; @@ -182,15 +180,14 @@ void parameter_free(Parameter * para) g_free(para->translator); g_free(para->native_op); g_free(para->owner_op); - - para = NULL; + g_free(para); } Ret *ret_new() { Ret *ret; - ret = g_new(Ret, 1); + ret = g_new0(Ret, 1); ret->comment = NULL; ret->type = NULL; ret->annotations = NULL; @@ -221,16 +218,16 @@ void ret_free(Ret * ret) g_free(ret->comment); g_free(ret->translator); g_free(ret->errorReturnValue); - - ret = NULL; + g_free(ret); } Enumeration *enumeration_new() { - Enumeration *enumeration = g_new(Enumeration, 1); + Enumeration *enumeration = g_new0(Enumeration, 1); enumeration->elements = NULL; enumeration->name = NULL; + enumeration->nativeName = NULL; enumeration->defaultNative = NULL; enumeration->comment = NULL; @@ -249,9 +246,10 @@ void enumeration_free(Enumeration * enumeration) } g_list_free(enumeration->elements); g_free(enumeration->name); + g_free(enumeration->nativeName); g_free(enumeration->defaultNative); g_free(enumeration->comment); - enumeration = NULL; + g_free(enumeration); } GList *get_list_from_string(const gchar * str) @@ -456,6 +454,8 @@ gboolean parse_enumeration(xmlNode * node, Enumeration * enumeration) for (attr = node->properties; attr != NULL; attr = attr->next) { if (xmlStrcmp(attr->name, (xmlChar *) "name") == 0) { enumeration->name = (gchar *) xmlNodeListGetString(attr->doc, attr->children, 1); + } else if (xmlStrcmp(attr->name, (xmlChar *) "native_name") == 0) { + enumeration->nativeName = (gchar *) xmlNodeListGetString(attr->doc, attr->children, 1); } else if (xmlStrcmp(attr->name, (xmlChar *) "default_native") == 0) { enumeration->defaultNative = (gchar *) xmlNodeListGetString(attr->doc, attr->children, 1); diff --git a/src/libical-glib/tools/xml-parser.h b/src/libical-glib/tools/xml-parser.h index 64b51ca..4e29c85 100644 --- a/src/libical-glib/tools/xml-parser.h +++ b/src/libical-glib/tools/xml-parser.h @@ -77,6 +77,7 @@ typedef struct Declaration { typedef struct Enumeration { gchar *name; + gchar *nativeName; GList *elements; gchar *defaultNative; gchar *comment; -- 2.7.4