]> git.datanom.net - lensdb.git/blob - src/main.c
before transition to proper ide
[lensdb.git] / src / main.c
1 /*
2 * main.c
3 *
4 * Copyright 2024 Michael Rasmussen <mir@datanom.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 *
21 *
22 */
23
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27 #include <gtk/gtk.h>
28 #include <glib.h>
29 #include <glib/gstdio.h>
30 #include <glib-object.h>
31 #include <stdio.h>
32 #include "sqlite-storage.h"
33 #include "gui.h"
34 #include "csv.h"
35 #include "lib/scanner.h"
36
37 gint main(gint argc, gchar** argv) {
38 gint status = 0;
39 /*
40 CvsError* err = NULL;
41 CsvParser* parser = csv_parser_new("/tmp/test.csv", false, true, &err);
42 if (parser) {
43 Record* r = csv_parser_next_line(parser, &err);
44 if (err) {
45 fprintf(stderr, "[Line: %zu - %s]\n", err->line, err->message);
46 csv_error_clear(&err);
47 }
48 while (r != NULL) {
49 csv_record_print(r);
50 csv_record_free(r);
51 r = csv_parser_next_line(parser, &err);
52 if (err) {
53 fprintf(stderr, "[Line: %zu - %s]\n", err->line, err->message);
54 csv_error_clear(&err);
55 }
56 }
57 csv_parser_free(parser);
58 } else {
59 fprintf(stderr, "[Line: %zu - %s]\n", err->line, err->message);
60 csv_error_clear(&err);
61 }
62 */
63 //gchar* path = g_path_get_dirname(argv[0]);
64 gchar* path = g_build_filename(g_get_user_config_dir(), PACKAGE, NULL); //g_strconcat(g_get_home_dir(), "/.local/share/", PACKAGE, NULL);
65 if (!g_file_test(path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
66 if (g_mkdir(path, 0766)) {
67 fprintf(stderr, "%s: Failed to create dir for database\n", path);
68 g_free(path);
69 return EXIT_FAILURE;
70 }
71 }
72 fprintf(stdout, "workdir: %s\n", path);
73 if ((status = init_storage(path)) > 0) {
74 fprintf(stderr, "%s: Failed to open DB\n", path);
75 } else {
76 gtk_init(&argc, &argv);
77 /*
78 parser = csv_parser_new("/tmp/test.csv", true, true, &err);
79 if (parser) {
80 dump_storage(parser);
81 } else {
82 fprintf(stderr, "[Line: %zu - %s]\n", err->line, err->message);
83 csv_error_clear(&err);
84 }
85 g_free(path);
86 close_storage();
87 return EXIT_SUCCESS;
88 */
89 if (init_gui()) {
90 g_free(path);
91 close_storage();
92 gchar* err = g_strdup_printf("Failed initializing GUI\n");
93 fprintf(stderr, err);
94 show_err_msg(GTK_MESSAGE_ERROR, err);
95 g_free(err);
96 return EXIT_FAILURE;
97 }
98 }
99 g_free(path);
100 close_storage();
101
102 return status;
103 }
This page took 0.891392 seconds and 6 git commands to generate.