X-Git-Url: http://git.datanom.net/lensdb.git/blobdiff_plain/7c60663584be170ea036431529ee3a1668d2e2fb..refs/heads/release/0.9.2:/src/main.c diff --git a/src/main.c b/src/main.c index ca8161e..a875abb 100644 --- a/src/main.c +++ b/src/main.c @@ -26,19 +26,78 @@ #endif #include #include +#include #include #include #include "sqlite-storage.h" #include "gui.h" - +#include "csv.h" +#include "lib/scanner.h" gint main(gint argc, gchar** argv) { - gtk_init(&argc, &argv); - printf("test\n"); - if (init_gui()) { - fprintf(stderr, "Failed initializing GUI\n"); - return 1; + gint status = 0; +/* + CvsError* err = NULL; + CsvParser* parser = csv_parser_new("/tmp/test.csv", false, true, &err); + if (parser) { + Record* r = csv_parser_next_line(parser, &err); + if (err) { + fprintf(stderr, "[Line: %zu - %s]\n", err->line, err->message); + csv_error_clear(&err); + } + while (r != NULL) { + csv_record_print(r); + csv_record_free(r); + r = csv_parser_next_line(parser, &err); + if (err) { + fprintf(stderr, "[Line: %zu - %s]\n", err->line, err->message); + csv_error_clear(&err); + } + } + csv_parser_free(parser); + } else { + fprintf(stderr, "[Line: %zu - %s]\n", err->line, err->message); + csv_error_clear(&err); + } +*/ + //gchar* path = g_path_get_dirname(argv[0]); + gchar* path = g_build_filename(g_get_user_config_dir(), PACKAGE, NULL); //g_strconcat(g_get_home_dir(), "/.local/share/", PACKAGE, NULL); + if (!g_file_test(path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { + if (g_mkdir(path, 0766)) { + fprintf(stderr, "%s: Failed to create dir for database\n", path); + g_free(path); + return EXIT_FAILURE; + } + } + fprintf(stdout, "workdir: %s\n", path); + if ((status = init_storage(path)) > 0) { + fprintf(stderr, "%s: Failed to open DB\n", path); + } else { + gtk_init(&argc, &argv); +/* + parser = csv_parser_new("/tmp/test.csv", true, true, &err); + if (parser) { + dump_storage(parser); + } else { + fprintf(stderr, "[Line: %zu - %s]\n", err->line, err->message); + csv_error_clear(&err); + } + g_free(path); + close_storage(); + return EXIT_SUCCESS; +*/ + if (init_gui()) { + g_free(path); + close_storage(); + gchar* err = g_strdup_printf("Failed initializing GUI\n"); + fprintf(stderr, err); + show_err_msg(GTK_MESSAGE_ERROR, err); + g_free(err); + return EXIT_FAILURE; + } } + g_free(path); + close_storage(); - return 0; + return status; }