wip catch signals
authorLaurent Mazet <mazet@softndesign.org>
Wed, 22 Jan 2025 07:29:31 +0000 (08:29 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Wed, 22 Jan 2025 07:29:31 +0000 (08:29 +0100)
fm.c

diff --git a/fm.c b/fm.c
index ffa61d69c1ea36c95eee991148ecbddd032d4bea..db64f568952e03b6119649e508ebb9ac38ee5a31 100644 (file)
--- a/fm.c
+++ b/fm.c
@@ -6,7 +6,8 @@
 
 #include <curses.h>
 #include <dirent.h>
-#include <stdio.h>
+#include <signal.h>
+#include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
@@ -34,6 +35,11 @@ int xoffset = 1;
 int yoffset = 2;
 int width = 0;
 
+window_t *windir[MAXPANELS] = {0};
+window_t *winelem[MAXPANELS] = {0};
+window_t *winmenu = NULL;
+window_t *winscreen = NULL;
+
 char *help =
     "alt Menu functions\n"
     "ret Go dir/View file\n"
@@ -63,6 +69,13 @@ int usage (int ret)
     return ret;
 }
 
+void dostop (int sig)
+{
+    if (askwindow (" Restart (Y/N) ", winscreen, "Yy", "Nn") == 1) {
+        exit (1);
+    }
+}
+
 /* main function */
 int main (int argc, char *argv[])
 {
@@ -149,14 +162,13 @@ int main (int argc, char *argv[])
     }
 
     /* init menu window */
-    window_t *winmenu = allocwindow ();
+    winmenu = allocwindow ();
     winmenu->xoffset = 0;
     winmenu->xsize = width;
     winmenu->yoffset = 0;
     winmenu->ysize = 1;
 
     /* init panel windows */
-    window_t *windir[MAXPANELS] = {0};
     for (i = 0; i < MAXPANELS; i++) {
         windir[i] = allocwindow ();
         windir[i]->active = (panel == i);
@@ -167,14 +179,13 @@ int main (int argc, char *argv[])
     }
 
     /* init screen window */
-    window_t *winscreen = allocwindow ();
+    winscreen = allocwindow ();
     winscreen->xoffset = xoffset;
     winscreen->xsize = width - 2 * xoffset;
     winscreen->yoffset = yoffset;
     winscreen->ysize = height - 2 * yoffset;
 
     /* init status windows */
-    window_t *winelem[MAXPANELS] = {0};
     for (i = 0; i < MAXPANELS; i++) {
         winelem[i] = allocwindow ();
         winelem[i]->xoffset = xoffset + width / 2 * i;
@@ -191,6 +202,14 @@ int main (int argc, char *argv[])
     list_t *list[MAXPANELS] = {0};
     int page[MAXPANELS] = {0};
 
+    /* catch signals */
+#ifndef _WIN32 /* Posix */
+    signal (SIGINT, &dostop);
+#endif
+    signal (SIGABRT, &dostop);
+    signal (SIGSEGV, &dostop);
+    signal (SIGTERM, &dostop);
+
     /* event loop */
     int stop = 0;
     while (!stop) {