menu system: handle console setup/cleanup differently
authorH. Peter Anvin <hpa@zytor.com>
Wed, 1 Nov 2006 23:28:41 +0000 (15:28 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 1 Nov 2006 23:28:41 +0000 (15:28 -0800)
Handle console setup/cleanup explicitly, instead of relying on a
destructor.  The destructor doesn't get called on outbound API calls
that don't return.

com32/modules/menu.c
com32/modules/menu.h
com32/modules/menumain.c
com32/modules/vesamenu.c

index b733864..1f2c510 100644 (file)
 #include <consoles.h>
 #include "menu.h"
 
+void console_prepare(void)
+{
+  /* Nothing special to do */
+}
+
+void console_cleanup(void)
+{
+  /* Nothing special to do */
+}
+
 int main(int argc, char *argv[])
 {
   console_ansi_raw();
index e856977..a70ba92 100644 (file)
@@ -74,5 +74,7 @@ static inline int my_isspace(char c)
 }
 
 int menu_main(int argc, char *argv[]);
+void console_prepare(void);
+void console_cleanup(void);
 
 #endif /* MENU_H */
index d0c0243..9d33bab 100644 (file)
@@ -848,6 +848,8 @@ int menu_main(int argc, char *argv[])
 
   (void)argc;
 
+  console_prepare();
+
   install_default_color_table();
   if (getscreensize(1, &rows, &cols)) {
     /* Unknown screen size? */
@@ -876,6 +878,8 @@ int menu_main(int argc, char *argv[])
     cmdline = run_menu();
 
     printf("\033[?25h\033[%d;1H\033[0m", END_ROW);
+    console_cleanup();
+
     if ( cmdline ) {
       execute(cmdline);
       if ( onerror )
@@ -883,5 +887,7 @@ int menu_main(int argc, char *argv[])
     } else {
       return 0;                        /* Exit */
     }
+
+    console_prepare();         /* If we're looping... */
   }
 }
index 88fe78d..6316eae 100644 (file)
 #include <console.h>
 #include "menu.h"
 
-static void __attribute__((destructor)) console_cleanup(void)
+void console_prepare(void)
+{
+  fputs("\033[0m\033[20h\033[25l", stdout);
+}
+
+void console_cleanup(void)
 {
   /* For the serial console, be nice and clean up */
   fputs("\033[0m\033[20l", stdout);
@@ -34,7 +39,6 @@ int vesacon_load_background(const char *);
 int main(int argc, char *argv[])
 {
   openconsole(&dev_rawcon_r, &dev_vesaserial_w);
-  fputs("\033[0m\033[20h\033[25l", stdout);
   
   draw_background = vesacon_load_background;