diff options
| author | Marc-André Lureau <marcandre.lureau@gmail.com> | 2012-12-21 16:11:59 +0100 |
|---|---|---|
| committer | Paolo Bonzini <pbonzini@redhat.com> | 2013-01-09 13:56:08 +0100 |
| commit | e9f59527fd72f7c9e306a2ecfe99caa176d3f3ec (patch) | |
| tree | 6c08e97f2bd8ed405e3852429f4026b82b4ae49b /tools | |
| parent | 205d3e7a02648770e2a98772d66d078477b6c03e (diff) | |
| download | msitools-e9f59527fd72f7c9e306a2ecfe99caa176d3f3ec.tar.gz msitools-e9f59527fd72f7c9e306a2ecfe99caa176d3f3ec.tar.xz msitools-e9f59527fd72f7c9e306a2ecfe99caa176d3f3ec.zip | |
Remove LibmsiResult from public API
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/msibuild.c | 43 | ||||
| -rw-r--r-- | tools/msiinfo.c | 54 |
2 files changed, 41 insertions, 56 deletions
diff --git a/tools/msibuild.c b/tools/msibuild.c index bebef7d..a80af2c 100644 --- a/tools/msibuild.c +++ b/tools/msibuild.c @@ -79,24 +79,24 @@ static gboolean init_suminfo(LibmsiSummaryInfo *si, GError **error) return TRUE; } -static LibmsiResult open_database(const char *msifile, LibmsiDatabase **db, - GError **error) +static gboolean open_database(const char *msifile, LibmsiDatabase **db, + GError **error) { LibmsiSummaryInfo *si = NULL; - LibmsiResult r = LIBMSI_RESULT_FUNCTION_FAILED; + gboolean success = FALSE; struct stat st; if (stat(msifile, &st) == -1) { *db = libmsi_database_new(msifile, LIBMSI_DB_OPEN_CREATE, error); if (!*db) - return LIBMSI_RESULT_FUNCTION_FAILED; + goto end; si = libmsi_summary_info_new(*db, INT_MAX, error); if (!si) { fprintf(stderr, "failed to open summary info\n"); - return LIBMSI_RESULT_FUNCTION_FAILED; + goto end; } if (!init_suminfo(si, error)) @@ -109,23 +109,23 @@ static LibmsiResult open_database(const char *msifile, LibmsiDatabase **db, { fprintf(stderr, "failed to commit database\n"); g_object_unref(*db); - return LIBMSI_RESULT_FUNCTION_FAILED; + goto end; } } else { *db = libmsi_database_new(msifile, LIBMSI_DB_OPEN_TRANSACT, error); if (!*db) - return LIBMSI_RESULT_FUNCTION_FAILED; + goto end; } - r = LIBMSI_RESULT_SUCCESS; + success = TRUE; end: if (si) g_object_unref(si); - return r; + return success; } static LibmsiDatabase *db; @@ -220,7 +220,7 @@ end: static int do_query(const char *sql, void *opaque) { GError **error = opaque; - LibmsiResult r = LIBMSI_RESULT_FUNCTION_FAILED; + gboolean success = FALSE; LibmsiQuery *query; query = libmsi_query_new(db, sql, error); @@ -234,7 +234,7 @@ static int do_query(const char *sql, void *opaque) goto end; } - r = LIBMSI_RESULT_SUCCESS; + success = TRUE; end: if (query) { @@ -242,7 +242,7 @@ end: g_object_unref(query); } - return r; + return !success; } static void show_usage(void) @@ -262,7 +262,7 @@ static void show_usage(void) int main(int argc, char *argv[]) { GError *error = NULL; - int r = LIBMSI_RESULT_SUCCESS; + gboolean success = FALSE; int n; g_type_init(); @@ -274,12 +274,12 @@ int main(int argc, char *argv[]) /* Accept package after first option for winemsibuilder compatibility. */ if (argc >= 3 && argv[1][0] == '-') { - r = open_database(argv[2], &db, &error); + success = open_database(argv[2], &db, &error); argv[2] = argv[1]; } else { - r = open_database(argv[1], &db, &error); + success = open_database(argv[1], &db, &error); } - if (r != LIBMSI_RESULT_SUCCESS) return 1; + if (!success) return 1; argc -= 2, argv += 2; while (argc > 0) { @@ -337,15 +337,10 @@ int main(int argc, char *argv[]) show_usage(); break; } - if (r != LIBMSI_RESULT_SUCCESS) { - break; - } } - if (r == LIBMSI_RESULT_SUCCESS) { - if (!libmsi_database_commit(db, &error)) - goto end; - } + if (!libmsi_database_commit(db, &error)) + goto end; end: g_object_unref(db); @@ -356,5 +351,5 @@ end: exit(1); } - return r != LIBMSI_RESULT_SUCCESS; + return 0; } diff --git a/tools/msiinfo.c b/tools/msiinfo.c index 7e9a8dd..e6235dc 100644 --- a/tools/msiinfo.c +++ b/tools/msiinfo.c @@ -91,7 +91,7 @@ static void cmd_usage(FILE *out, struct Command *cmd) exit (out == stderr); } -static void print_libmsi_error(LibmsiResult r) +static void print_libmsi_error(LibmsiResultError r) { switch (r) { @@ -314,7 +314,6 @@ static int cmd_suminfo(struct Command *cmd, int argc, char **argv, GError **erro { LibmsiDatabase *db = NULL; LibmsiSummaryInfo *si = NULL; - LibmsiResult r; if (argc != 2) { cmd_usage(stderr, cmd); @@ -430,7 +429,7 @@ end: return r; } -static unsigned export_create_table(const char *table, +static gboolean export_create_table(const char *table, LibmsiRecord *names, LibmsiRecord *types, LibmsiRecord *keys) @@ -438,7 +437,6 @@ static unsigned export_create_table(const char *table, guint num_columns = libmsi_record_get_field_count(names); guint num_keys = libmsi_record_get_field_count(keys); guint i, len; - unsigned r = LIBMSI_RESULT_SUCCESS; char size[20], extra[30]; gchar *name, *type; unsigned sz; @@ -454,10 +452,10 @@ static unsigned export_create_table(const char *table, for (i = 1; i <= num_columns; i++) { name = libmsi_record_get_string(names, i); - g_return_val_if_fail(name != NULL, LIBMSI_RESULT_FUNCTION_FAILED); + g_return_val_if_fail(name != NULL, FALSE); type = libmsi_record_get_string(types, i); - g_return_val_if_fail(type != NULL, LIBMSI_RESULT_FUNCTION_FAILED); + g_return_val_if_fail(type != NULL, FALSE); if (i > 1) { printf(", "); @@ -501,13 +499,13 @@ static unsigned export_create_table(const char *table, for (i = 1; i <= num_keys; i++) { name = libmsi_record_get_string(names, i); - g_return_val_if_fail(name != NULL, LIBMSI_RESULT_FUNCTION_FAILED); + g_return_val_if_fail(name != NULL, FALSE); printf("%s `%s`", (i > 1 ? "," : " PRIMARY KEY"), name); g_free(name); } printf(")\n"); - return r; + return TRUE; } static void print_quoted_string(const char *s) @@ -525,7 +523,7 @@ static void print_quoted_string(const char *s) putchar('\''); } -static unsigned export_insert(const char *table, +static gboolean export_insert(const char *table, LibmsiRecord *names, LibmsiRecord *types, LibmsiRecord *vals) @@ -533,7 +531,6 @@ static unsigned export_insert(const char *table, guint num_columns = libmsi_record_get_field_count(names); gchar *name, *type; guint i; - unsigned r; unsigned sz; char *s; @@ -546,7 +543,7 @@ static unsigned export_insert(const char *table, sz = sizeof(name); name = libmsi_record_get_string(names, i); - g_return_val_if_fail(name != NULL, LIBMSI_RESULT_FUNCTION_FAILED); + g_return_val_if_fail(name != NULL, FALSE); if (i > 1) { printf(", "); @@ -568,7 +565,7 @@ static unsigned export_insert(const char *table, sz = sizeof(type); type = libmsi_record_get_string(types, i); - g_return_val_if_fail(type != NULL, LIBMSI_RESULT_FUNCTION_FAILED); + g_return_val_if_fail(type != NULL, FALSE); switch (type[0]) { @@ -592,10 +589,10 @@ static unsigned export_insert(const char *table, g_free(type); } printf(")\n"); - return r; + return TRUE; } -static unsigned export_sql( LibmsiDatabase *db, const char *table, GError **error) +static gboolean export_sql( LibmsiDatabase *db, const char *table, GError **error) { GError *err = NULL; LibmsiRecord *name = NULL; @@ -603,7 +600,7 @@ static unsigned export_sql( LibmsiDatabase *db, const char *table, GError **erro LibmsiRecord *keys = NULL; LibmsiRecord *rec = NULL; LibmsiQuery *query = NULL; - unsigned r; + gboolean success = FALSE; char *sql; sql = g_strdup_printf("select * from `%s`", table); @@ -630,41 +627,37 @@ static unsigned export_sql( LibmsiDatabase *db, const char *table, GError **erro goto done; } - r = export_create_table(table, name, type, keys); - if (r) { + if (!export_create_table(table, name, type, keys)) goto done; - } /* write out row 4 onwards, the data */ while ((rec = libmsi_query_fetch(query, &err))) { unsigned size = PATH_MAX; - r = export_insert(table, name, type, rec); + success = export_insert(table, name, type, rec); g_object_unref(rec); - if (r) { + if (!success) { break; } } - if (!g_error_matches(err, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS)) + if (!g_error_matches(err, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_NO_MORE_ITEMS)) { g_propagate_error(error, err); + success = FALSE; + } g_clear_error(&err); - if (r == LIBMSI_RESULT_NO_MORE_ITEMS) { - r = LIBMSI_RESULT_SUCCESS; - } done: g_object_unref(name); g_object_unref(type); g_object_unref(keys); g_object_unref(query); - return r; + return success; } static int cmd_export(struct Command *cmd, int argc, char **argv, GError **error) { LibmsiDatabase *db = NULL; - LibmsiResult r = LIBMSI_RESULT_SUCCESS; gboolean sql = FALSE; if (argc > 1 && !strcmp(argv[1], "-s")) { @@ -682,12 +675,8 @@ static int cmd_export(struct Command *cmd, int argc, char **argv, GError **error return 1; if (sql) { - r = export_sql(db, argv[2], error); - if (r) { - print_libmsi_error(r); - } - - + if (!export_sql(db, argv[2], error)) + return 1; } else { #if O_BINARY _setmode(STDOUT_FILENO, O_BINARY); @@ -801,6 +790,7 @@ int main(int argc, char **argv) int result = cmd->func(cmd, argc - 1, argv + 1, &error); if (error != NULL) { g_printerr("error: %s\n", error->message); + print_libmsi_error(error->code); g_clear_error(&error); } |
