From ec73d8f6ccff31ac4a5b4805fdaf7a24dde4809b Mon Sep 17 00:00:00 2001 From: Romain de Laage Date: Sun, 14 Feb 2021 16:19:39 +0100 Subject: [PATCH] Add default file --- src/gemparse.c | 11 +++++++++++ src/main.c | 17 +++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/gemparse.c b/src/gemparse.c index 8755407..84f1e4e 100644 --- a/src/gemparse.c +++ b/src/gemparse.c @@ -1,7 +1,9 @@ #include #include +#ifndef TESTGEMPARSE #include #include "../include/gemgui.h" +#endif #ifdef TESTGEMPARSE @@ -32,7 +34,16 @@ parseFile (char *path) char line[4096]; if (fileToParse == NULL) + { +#ifdef TESTGEMPARSE + printf("error"); +#else + addH1 (render, "An error occured"); + addText (render, "Can't open the file"); + addCode (render, path, NULL); +#endif return 1; + } while (fgets (line, 4096, fileToParse) != NULL) { diff --git a/src/main.c b/src/main.c index ddb18e1..2387aca 100644 --- a/src/main.c +++ b/src/main.c @@ -27,21 +27,22 @@ goAction (GtkWidget *widget, } static void -makeRender (void) +makeRender (char *path) { if (render != NULL) gtk_widget_destroy (render); render = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - parseFile ("test.gmi"); + parseFile (path); gtk_container_add (GTK_CONTAINER (scrollbar), render); } /* This function's goal is to build the main interface */ static void -build_interface (GtkWidget *window) +build_interface (GtkWidget *window, + char *path) { GtkWidget *pathBar; GtkWidget *headerBar; @@ -64,7 +65,7 @@ build_interface (GtkWidget *window) gtk_container_add (GTK_CONTAINER (headerBar), pathBar); gtk_container_add (GTK_CONTAINER (headerBar), goButtonBox); - makeRender (); + makeRender (path); } /* This function's goal is to create the window then show it */ @@ -75,9 +76,9 @@ activate (GtkApplication *app, GtkWidget *window; window = gtk_application_window_new (app); - gtk_window_set_title (GTK_WINDOW (window), "MDViewer"); + gtk_window_set_title (GTK_WINDOW (window), "Scorpius"); gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); - build_interface (window); + build_interface (window, (char *)user_data); gtk_widget_show_all (window); } @@ -89,8 +90,8 @@ main (int argc, int status; app = gtk_application_new ("ovh.rdelaage.mdviewer", G_APPLICATION_FLAGS_NONE); - g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); - status = g_application_run(G_APPLICATION (app), argc, argv); + g_signal_connect (app, "activate", G_CALLBACK (activate), (argc >= 2) ? argv[1] : "readme.gmi"); + status = g_application_run(G_APPLICATION (app), 1, argv); g_object_unref (app); return status;