scriptapp.h

Go to the documentation of this file.
00001 
00004 
00005 //
00006 // Copyright (c) 2005-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Mon Jun 27 13:23:46 2005
00010 // commit: $Id: scriptapp.h 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/tcl/scriptapp.h $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00033 
00034 #ifndef GROOVX_TCL_SCRIPTAPP_H_UTC20050628162420_DEFINED
00035 #define GROOVX_TCL_SCRIPTAPP_H_UTC20050628162420_DEFINED
00036 
00037 #include "rutz/fstring.h"
00038 #include "rutz/trace.h"
00039 
00040 #include <exception>
00041 #include <tcl.h>
00042 
00043 namespace tcl
00044 {
00045   class script_app;
00046 
00047   struct package_info
00048   {
00049     const char*            name;
00050     Tcl_PackageInitProc*   init_proc;
00051     const char*            version;
00052     bool                   requires_gui;
00053   };
00054 }
00055 
00057 class tcl::script_app
00058 {
00059 public:
00060   script_app(const char* appname_, int argc_, char** argv_) throw();
00061   ~script_app() throw();
00062 
00064 
00065   void no_gui() { m_nowindow = true; }
00066 
00068 
00074   void splash(const char* msg) { m_splashmsg = msg; }
00075 
00077   void pkg_dir(const char* dir) { m_pkgdir = dir; }
00078 
00079   void packages(const package_info* pkgs_) { m_pkgs = pkgs_; }
00080 
00081   void run();
00082 
00083   int exit_status() const { return m_exitcode; }
00084 
00085   static void init_in_macro_only();
00086 
00087   static void handle_exception_in_macro_only(const std::exception* e);
00088 
00089 private:
00090   script_app(const script_app&); // not implemented
00091   script_app& operator=(const script_app&); // not implemented
00092 
00093   rutz::fstring       const m_appname;
00094   int                       m_script_argc;
00095   char**                    m_script_argv;
00096   bool                      m_minimal;
00097   bool                      m_nowindow;
00098   rutz::fstring             m_splashmsg;
00099   rutz::fstring             m_pkgdir;
00100   const package_info*       m_pkgs;
00101   int                       m_exitcode;
00102 };
00103 
00105 
00107 #define GVX_SCRIPT_PROG_BEGIN(app, name, argc, argv)    \
00108   try                                                   \
00109   {                                                     \
00110   GVX_TRACE(name);                                      \
00111                                                         \
00112     tcl::script_app::init_in_macro_only();              \
00113                                                         \
00114     tcl::script_app app(name, argc, argv);
00115 
00116 
00118 #define GVX_SCRIPT_PROG_END(app)                                \
00119     return app.exit_status();                                   \
00120   }                                                             \
00121   catch (std::exception& err)                                   \
00122     {                                                           \
00123       tcl::script_app::handle_exception_in_macro_only(&err);    \
00124     }                                                           \
00125   catch (...)                                                   \
00126     {                                                           \
00127       tcl::script_app::handle_exception_in_macro_only(0);       \
00128     }                                                           \
00129   return -1;
00130 
00131 static const char __attribute__((used)) vcid_groovx_tcl_scriptapp_h_utc20050628162420[] = "$Id: scriptapp.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00132 #endif // !GROOVX_TCL_SCRIPTAPP_H_UTC20050628162420_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:41 2008 by Doxygen version 1.5.5.