home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcltk805.zip / tcl805s.zip / tk8.0.5 / os2 / os2Main.c < prev    next >
C/C++ Source or Header  |  2000-04-05  |  4KB  |  177 lines

  1. /* 
  2.  * os2Main.c --
  3.  *
  4.  *    Main entry point for wish and other Tk-based applications.
  5.  *
  6.  * Copyright (c) 1996-2000 Illya Vaes
  7.  * Copyright (c) 1995 Sun Microsystems, Inc.
  8.  *
  9.  * See the file "license.terms" for information on usage and redistribution
  10.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11.  */
  12.  
  13. #include <tk.h>
  14. #define INCL_PM
  15. #include <os2.h>
  16. #undef INCL_PM
  17. #include <malloc.h>
  18. #include <locale.h>
  19. #include <stdarg.h>
  20.  
  21. /*
  22.  * The following declarations refer to internal Tk routines.  These
  23.  * interfaces are available for use, but are not supported.
  24.  */
  25.  
  26. EXTERN void             TkConsoleCreate _ANSI_ARGS_((void));
  27. EXTERN int              TkConsoleInit _ANSI_ARGS_((Tcl_Interp *interp));
  28.  
  29. /*
  30.  * Forward declarations for procedures defined later in this file:
  31.  */
  32.  
  33. static void WishPanic TCL_VARARGS(char *,format);
  34.  
  35. #ifdef TK_TEST
  36. EXTERN int              Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp));
  37. #endif /* TK_TEST */
  38.  
  39.  
  40. /*
  41.  *----------------------------------------------------------------------
  42.  *
  43.  * main --
  44.  *
  45.  *    Main entry point from OS/2.
  46.  *
  47.  * Results:
  48.  *    Returns false if initialization fails, true otherwise.
  49.  *
  50.  * Side effects:
  51.  *    Just about anything, since from here we call arbitrary Tcl code.
  52.  *
  53.  *----------------------------------------------------------------------
  54.  */
  55.  
  56. int
  57. main( int argc, char **argv )
  58. {
  59.     /* Initialize PM: done in DLL */
  60.  
  61.     /*
  62.      * Set up the default locale to be standard "C" locale so parsing
  63.      * is performed correctly.
  64.      */
  65.  
  66.     setlocale(LC_ALL, "C");
  67.  
  68.     Tcl_SetPanicProc(WishPanic);
  69.  
  70.     /*
  71.      * Create the console channels and install them as the standard
  72.      * channels.  All I/O will be discarded until TkConsoleInit is
  73.      * called to attach the console to a text widget.
  74.      */
  75.  
  76.     TkConsoleCreate();
  77.  
  78.     Tk_Main(argc, argv, Tcl_AppInit);
  79.  
  80.     /* Shutting down PM: done in DLL */
  81.  
  82.     return 1;
  83. }
  84.  
  85. /*
  86.  *----------------------------------------------------------------------
  87.  *
  88.  * Tcl_AppInit --
  89.  *
  90.  *    This procedure performs application-specific initialization.
  91.  *    Most applications, especially those that incorporate additional
  92.  *    packages, will have their own version of this procedure.
  93.  *
  94.  * Results:
  95.  *    Returns a standard Tcl completion code, and leaves an error
  96.  *    message in interp->result if an error occurs.
  97.  *
  98.  * Side effects:
  99.  *    Depends on the startup script.
  100.  *
  101.  *----------------------------------------------------------------------
  102.  */
  103.  
  104. int
  105. Tcl_AppInit(interp)
  106.     Tcl_Interp *interp;        /* Interpreter for application. */
  107. {
  108.     if (Tcl_Init(interp) == TCL_ERROR) {
  109.     return TCL_ERROR;
  110.     }
  111.     if (Tk_Init(interp) == TCL_ERROR) {
  112.     return TCL_ERROR;
  113.     }
  114.     Tcl_StaticPackage(interp, "Tk", Tk_Init, (Tcl_PackageInitProc *) NULL);
  115.  
  116.     /*
  117.      * Initialize the console only if we are running as an interactive
  118.      * application.
  119.      */
  120.  
  121.     if (strcmp(Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY), "1")
  122.             == 0) {
  123.         if (TkConsoleInit(interp) == TCL_ERROR) {
  124.             goto error;
  125.         }
  126.     }
  127.  
  128. #ifdef TK_TEST
  129.     if (Tktest_Init(interp) == TCL_ERROR) {
  130.     goto error;
  131.     }
  132.     Tcl_StaticPackage(interp, "Tktest", Tktest_Init,
  133.             (Tcl_PackageInitProc *) NULL);
  134. #endif /* TK_TEST */
  135.  
  136.     Tcl_SetVar(interp, "tcl_rcFileName", "~/wishrc.tcl", TCL_GLOBAL_ONLY);
  137.     return TCL_OK;
  138.  
  139. error:
  140.     WishPanic(interp->result);
  141.     return TCL_ERROR;
  142. }
  143.  
  144. /*
  145.  *----------------------------------------------------------------------
  146.  *
  147.  * WishPanic --
  148.  *
  149.  *    Display a message and exit.
  150.  *
  151.  * Results:
  152.  *    None.
  153.  *
  154.  * Side effects:
  155.  *    Exits the program.
  156.  *
  157.  *----------------------------------------------------------------------
  158.  */
  159.  
  160. void
  161. WishPanic TCL_VARARGS_DEF(char *,arg1)
  162. {
  163.     va_list argList;
  164.     char buf[1024];
  165.     char *format;
  166.     
  167.     format = TCL_VARARGS_START(char *,arg1,argList);
  168.     vsprintf(buf, format, argList);
  169.  
  170.     /* Make sure pointer is not captured (for WinMessageBox) */
  171.     WinSetCapture(HWND_DESKTOP, NULLHANDLE);
  172.     WinAlarm(HWND_DESKTOP, WA_ERROR);
  173.     WinMessageBox(HWND_DESKTOP, NULLHANDLE, buf, "Fatal Error in WISH", 0,
  174.         MB_OK | MB_ERROR | MB_APPLMODAL);
  175.     exit(1);
  176. }
  177.