home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tk42r2s.zip / tk4.2 / os2 / os2Main.c < prev    next >
C/C++ Source or Header  |  1998-01-25  |  4KB  |  178 lines

  1. /* 
  2.  * os2Main.c --
  3.  *
  4.  *    Main entry point for wish and other Tk-based applications.
  5.  *
  6.  * Copyright (c) 1996-1998 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, otherwise it never
  49.  *    returns. 
  50.  *
  51.  * Side effects:
  52.  *    Just about anything, since from here we call arbitrary Tcl code.
  53.  *
  54.  *----------------------------------------------------------------------
  55.  */
  56.  
  57. int
  58. main( int argc, char **argv )
  59. {
  60.     /* Initialize PM: done in DLL */
  61.  
  62.     /*
  63.      * Set up the default locale to be standard "C" locale so parsing
  64.      * is performed correctly.
  65.      */
  66.  
  67.     setlocale(LC_ALL, "C");
  68.  
  69.     Tcl_SetPanicProc(WishPanic);
  70.  
  71.     /*
  72.      * Create the console channels and install them as the standard
  73.      * channels.  All I/O will be discarded until TkConsoleInit is
  74.      * called to attach the console to a text widget.
  75.      */
  76.  
  77.     TkConsoleCreate();
  78.  
  79.     Tk_Main(argc, argv, Tcl_AppInit);
  80.  
  81.     /* Shutting down PM: done in DLL */
  82.  
  83.     return 1;
  84. }
  85.  
  86. /*
  87.  *----------------------------------------------------------------------
  88.  *
  89.  * Tcl_AppInit --
  90.  *
  91.  *    This procedure performs application-specific initialization.
  92.  *    Most applications, especially those that incorporate additional
  93.  *    packages, will have their own version of this procedure.
  94.  *
  95.  * Results:
  96.  *    Returns a standard Tcl completion code, and leaves an error
  97.  *    message in interp->result if an error occurs.
  98.  *
  99.  * Side effects:
  100.  *    Depends on the startup script.
  101.  *
  102.  *----------------------------------------------------------------------
  103.  */
  104.  
  105. int
  106. Tcl_AppInit(interp)
  107.     Tcl_Interp *interp;        /* Interpreter for application. */
  108. {
  109.     if (Tcl_Init(interp) == TCL_ERROR) {
  110.     return TCL_ERROR;
  111.     }
  112.     if (Tk_Init(interp) == TCL_ERROR) {
  113.     return TCL_ERROR;
  114.     }
  115.     Tcl_StaticPackage(interp, "Tk", Tk_Init, (Tcl_PackageInitProc *) NULL);
  116.  
  117.     /*
  118.      * Initialize the console only if we are running as an interactive
  119.      * application.
  120.      */
  121.  
  122.     if (strcmp(Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY), "1")
  123.             == 0) {
  124.         if (TkConsoleInit(interp) == TCL_ERROR) {
  125.             goto error;
  126.         }
  127.     }
  128.  
  129. #ifdef TK_TEST
  130.     if (Tktest_Init(interp) == TCL_ERROR) {
  131.     goto error;
  132.     }
  133.     Tcl_StaticPackage(interp, "Tktest", Tktest_Init,
  134.             (Tcl_PackageInitProc *) NULL);
  135. #endif /* TK_TEST */
  136.  
  137.     Tcl_SetVar(interp, "tcl_rcFileName", "~/wishrc.tcl", TCL_GLOBAL_ONLY);
  138.     return TCL_OK;
  139.  
  140. error:
  141.     WishPanic(interp->result);
  142.     return TCL_ERROR;
  143. }
  144.  
  145. /*
  146.  *----------------------------------------------------------------------
  147.  *
  148.  * WishPanic --
  149.  *
  150.  *    Display a message and exit.
  151.  *
  152.  * Results:
  153.  *    None.
  154.  *
  155.  * Side effects:
  156.  *    Exits the program.
  157.  *
  158.  *----------------------------------------------------------------------
  159.  */
  160.  
  161. void
  162. WishPanic TCL_VARARGS_DEF(char *,arg1)
  163. {
  164.     va_list argList;
  165.     char buf[1024];
  166.     char *format;
  167.     
  168.     format = TCL_VARARGS_START(char *,arg1,argList);
  169.     vsprintf(buf, format, argList);
  170.  
  171.     /* Make sure pointer is not captured (for WinMessageBox) */
  172.     WinSetCapture(HWND_DESKTOP, NULLHANDLE);
  173.     WinAlarm(HWND_DESKTOP, WA_ERROR);
  174.     WinMessageBox(HWND_DESKTOP, NULLHANDLE, buf, "Fatal Error in WISH", 0,
  175.         MB_OK | MB_ERROR | MB_APPLMODAL);
  176.     exit(1);
  177. }
  178.