home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcltk805.zip / tcl805s.zip / tcl8.0.5 / os2 / tclOS2AppInit.c < prev    next >
C/C++ Source or Header  |  2001-08-16  |  5KB  |  173 lines

  1. /* 
  2.  * tclOS2AppInit.c --
  3.  *
  4.  *    Provides a default version of the main program and Tcl_AppInit
  5.  *    procedure for Tcl applications (without Tk).
  6.  *
  7.  * Copyright (c) 1993 The Regents of the University of California.
  8.  * Copyright (c) 1994-1996 Sun Microsystems, Inc.
  9.  * Copyright (c) 1996-2001 Illya Vaes
  10.  *
  11.  * See the file "license.terms" for information on usage and redistribution
  12.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13.  */
  14.  
  15.  
  16. #include "tcl.h"
  17. #include <locale.h>
  18. #include "tclOS2Int.h"
  19. /* Important if you want to have a PM-application */
  20. #ifndef CLI_VERSION
  21.    #include "tclOS2Console.h"
  22. #endif
  23.  
  24. /*
  25.  * The following variable is a special hack that is needed in order for
  26.  * Sun shared libraries to be used for Tcl.
  27.  */
  28. extern int _matherr();
  29. int *tclDummyMathPtr = (int *) _matherr;
  30.  
  31. #ifdef TCL_TEST
  32. EXTERN int        Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
  33. EXTERN int              TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));
  34. #endif /* TCL_TEST */
  35.  
  36. /*
  37.  *----------------------------------------------------------------------
  38.  *
  39.  * main --
  40.  *
  41.  *    This is the main program for the application.
  42.  *
  43.  * Results:
  44.  *    None: Tcl_Main never returns here, so this procedure never
  45.  *    returns either.
  46.  *
  47.  * Side effects:
  48.  *    Whatever the application does.
  49.  *
  50.  *----------------------------------------------------------------------
  51.  */
  52.  
  53. int
  54. main(argc, argv)
  55.     int argc;            /* Number of command-line arguments. */
  56.     char **argv;        /* Values of command-line arguments. */
  57. {
  58.     char *p;
  59.  
  60.     /*
  61.      * Set up the default locale.
  62.      */
  63.  
  64.     p = setlocale(LC_ALL, "C");
  65.     if (p == NULL) {
  66.         fprintf(stderr, "setlocale failed\n");
  67.     }
  68.  
  69.     /*
  70.      * Replace argv[0] with forward slashes substituted for backslashes.
  71.      */
  72.  
  73. #ifdef VERBOSE
  74.     printf("environ %p, environ[0] [%s]\n", environ, environ != NULL ?
  75.            environ[0] : "");
  76. #endif
  77.  
  78.     for (p = argv[0]; *p != '\0'; p++) {
  79.         if (*p == '\\') {
  80.             *p = '/';
  81.         }
  82.     }
  83.  
  84. #ifdef CLI_VERSION
  85.     TclOS2SetUsePm(0);
  86.     TclOS2PMInitialize();
  87. #else
  88.     TclOS2SetUsePm(1);
  89.  
  90.     /* Initialize PM */
  91.     if (!TclOS2PMInitialize()) {
  92.         return 1;
  93.     }
  94.     /* Register "Terminal" class */
  95.     if (!RegisterTerminalClass(TclOS2GetHAB())) {
  96.         WinMessageBox(HWND_DESKTOP, NULLHANDLE, "Cannot register Terminal",
  97.                       "Tclsh", 0, MB_OK | MB_ERROR | MB_APPLMODAL);
  98.         /* Don't forget to cleanly exit PM */
  99.         TclOS2PMShutdown();
  100.         return 1;
  101.     }
  102.  
  103. #endif
  104.  
  105.     Tcl_Main(argc, argv, Tcl_AppInit);
  106.     return 0;            /* Needed only to prevent compiler warning. */
  107. }
  108.  
  109. /*
  110.  *----------------------------------------------------------------------
  111.  *
  112.  * Tcl_AppInit --
  113.  *
  114.  *    This procedure performs application-specific initialization.
  115.  *    Most applications, especially those that incorporate additional
  116.  *    packages, will have their own version of this procedure.
  117.  *
  118.  * Results:
  119.  *    Returns a standard Tcl completion code, and leaves an error
  120.  *    message in interp->result if an error occurs.
  121.  *
  122.  * Side effects:
  123.  *    Depends on the startup script.
  124.  *
  125.  *----------------------------------------------------------------------
  126.  */
  127.  
  128. int
  129. Tcl_AppInit(interp)
  130.     Tcl_Interp *interp;        /* Interpreter for application. */
  131. {
  132.     if (Tcl_Init(interp) == TCL_ERROR) {
  133.     return TCL_ERROR;
  134.     }
  135.  
  136. #ifdef TCL_TEST
  137.     if (Tcltest_Init(interp) == TCL_ERROR) {
  138.     return TCL_ERROR;
  139.     }
  140.     Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
  141.             (Tcl_PackageInitProc *) NULL);
  142.     if (TclObjTest_Init(interp) == TCL_ERROR) {
  143.         return TCL_ERROR;
  144.     }
  145. #endif /* TCL_TEST */
  146.  
  147.     /*
  148.      * Call the init procedures for included packages.  Each call should
  149.      * look like this:
  150.      *
  151.      * if (Mod_Init(interp) == TCL_ERROR) {
  152.      *     return TCL_ERROR;
  153.      * }
  154.      *
  155.      * where "Mod" is the name of the module.
  156.      */
  157.  
  158.     /*
  159.      * Call Tcl_CreateCommand for application-specific commands, if
  160.      * they weren't already created by the init procedures called above.
  161.      */
  162.  
  163.     /*
  164.      * Specify a user-specific startup file to invoke if the application
  165.      * is run interactively.  Typically the startup file is "~/.apprc"
  166.      * where "app" is the name of the application.  If this line is deleted
  167.      * then no user-specific startup file will be run under any conditions.
  168.      */
  169.  
  170.     Tcl_SetVar(interp, "tcl_rcFileName", "~/tclshrc.tcl", TCL_GLOBAL_ONLY);
  171.     return TCL_OK;
  172. }
  173.