]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - c++/cursesmain.cc
ncurses 6.2 - patch 20200404
[ncurses.git] / c++ / cursesmain.cc
index 7a3721ddc0d1f3bcfd15bd96adba4076a0d32028..9c11c9932638d51d349acbb6d98be6ca4c5358f4 100644 (file)
@@ -1,6 +1,7 @@
 // * this is for making emacs happy: -*-Mode: C++;-*-
 /****************************************************************************
- * Copyright (c) 1998,2001 Free Software Foundation, Inc.                   *
+ * Copyright 2019,2020 Thomas E. Dickey                                     *
+ * Copyright 1998-2007,2013 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
 
 /****************************************************************************
  *   Author: Juergen Pfeifer, 1997                                          *
- *   Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en             *
  ****************************************************************************/
 
 #include "internal.h"
 #include "cursesapp.h"
 
-MODULE_ID("$Id: cursesmain.cc,v 1.9 2002/07/06 15:47:52 juergen Exp $")
+#if CPP_HAS_TRY_CATCH && HAVE_IOSTREAM
+#pragma GCC diagnostic ignored "-Weffc++"
+#include <iostream>
+#pragma GCC diagnostic warning "-Weffc++"
+#else
+#undef CPP_HAS_TRY_CATCH
+#define CPP_HAS_TRY_CATCH 0
+#endif
+
+MODULE_ID("$Id: cursesmain.cc,v 1.18 2020/04/04 23:25:34 tom Exp $")
+
+#if HAVE_LOCALE_H
+#include <locale.h>
+#else
+#define setlocale(name,string) /* nothing */
+#endif
+
+#if NO_LEAKS
+#include <nc_alloc.h>
+#endif
 
 /* This is the default implementation of main() for a NCursesApplication.
  * You only have to instantiate a static NCursesApplication object in your
  * main application source file and link this module with your application.
- */ 
-int main(int argc, char* argv[])
+ */
+NCURSES_EXPORT(int) main(int argc, char* argv[])
 {
+  setlocale(LC_ALL, "");
+
   NCursesApplication* A = NCursesApplication::getApplication();
   if (!A)
     return(1);
@@ -51,8 +72,25 @@ int main(int argc, char* argv[])
 
     A->handleArgs(argc,argv);
     ::endwin();
+#if CPP_HAS_TRY_CATCH
+    try {
+      res = (*A)();
+      ::endwin();
+    }
+    catch(const NCursesException &e) {
+      ::endwin();
+      std::cerr << e.message << std::endl;
+      res = e.errorno;
+    }
+#else
     res = (*A)();
     ::endwin();
+#endif
+#if NO_LEAKS
+    delete A;
+    exit_curses(res);
+#else
     return(res);
+#endif
   }
 }