tclAppInit.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * tclAppInit.c --
  3. *
  4. * Provides a default version of the main program and Tcl_AppInit
  5. * procedure for tclsh and other Tcl-based applications (without Tk).
  6. *
  7. * Copyright (c) 1993 The Regents of the University of California.
  8. * Copyright (c) 1994-1997 Sun Microsystems, Inc.
  9. * Copyright (c) 1998-1999 Scriptics Corporation.
  10. *
  11. * See the file "license.terms" for information on usage and redistribution of
  12. * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13. */
  14. #undef BUILD_tcl
  15. #undef STATIC_BUILD
  16. #include "tcl.h"
  17. #if TCL_MAJOR_VERSION < 9 && TCL_MINOR_VERSION < 7
  18. # define Tcl_LibraryInitProc Tcl_PackageInitProc
  19. # define Tcl_StaticLibrary Tcl_StaticPackage
  20. #endif
  21. #ifdef TCL_TEST
  22. extern Tcl_LibraryInitProc Tcltest_Init;
  23. extern Tcl_LibraryInitProc Tcltest_SafeInit;
  24. #endif /* TCL_TEST */
  25. #ifdef TCL_XT_TEST
  26. extern void XtToolkitInitialize(void);
  27. extern Tcl_LibraryInitProc Tclxttest_Init;
  28. #endif /* TCL_XT_TEST */
  29. /*
  30. * The following #if block allows you to change the AppInit function by using
  31. * a #define of TCL_LOCAL_APPINIT instead of rewriting this entire file. The
  32. * #if checks for that #define and uses Tcl_AppInit if it does not exist.
  33. */
  34. #ifndef TCL_LOCAL_APPINIT
  35. #define TCL_LOCAL_APPINIT Tcl_AppInit
  36. #endif
  37. #ifndef MODULE_SCOPE
  38. # define MODULE_SCOPE extern
  39. #endif
  40. MODULE_SCOPE int TCL_LOCAL_APPINIT(Tcl_Interp *);
  41. MODULE_SCOPE int main(int, char **);
  42. /*
  43. * The following #if block allows you to change how Tcl finds the startup
  44. * script, prime the library or encoding paths, fiddle with the argv, etc.,
  45. * without needing to rewrite Tcl_Main()
  46. */
  47. #ifdef TCL_LOCAL_MAIN_HOOK
  48. MODULE_SCOPE int TCL_LOCAL_MAIN_HOOK(int *argc, char ***argv);
  49. #endif
  50. /*
  51. *----------------------------------------------------------------------
  52. *
  53. * main --
  54. *
  55. * This is the main program for the application.
  56. *
  57. * Results:
  58. * None: Tcl_Main never returns here, so this procedure never returns
  59. * either.
  60. *
  61. * Side effects:
  62. * Just about anything, since from here we call arbitrary Tcl code.
  63. *
  64. *----------------------------------------------------------------------
  65. */
  66. int
  67. main(
  68. int argc, /* Number of command-line arguments. */
  69. char *argv[]) /* Values of command-line arguments. */
  70. {
  71. #ifdef TCL_XT_TEST
  72. XtToolkitInitialize();
  73. #endif
  74. #ifdef TCL_LOCAL_MAIN_HOOK
  75. TCL_LOCAL_MAIN_HOOK(&argc, &argv);
  76. #elif (TCL_MAJOR_VERSION > 8 || TCL_MINOR_VERSION > 6) && (!defined(_WIN32) || defined(UNICODE))
  77. /* New in Tcl 8.7. This doesn't work on Windows without UNICODE */
  78. TclZipfs_AppHook(&argc, &argv);
  79. #endif
  80. Tcl_Main(argc, argv, TCL_LOCAL_APPINIT);
  81. return 0; /* Needed only to prevent compiler warning. */
  82. }
  83. /*
  84. *----------------------------------------------------------------------
  85. *
  86. * Tcl_AppInit --
  87. *
  88. * This procedure performs application-specific initialization. Most
  89. * applications, especially those that incorporate additional packages,
  90. * will have their own version of this procedure.
  91. *
  92. * Results:
  93. * Returns a standard Tcl completion code, and leaves an error message in
  94. * the interp's result if an error occurs.
  95. *
  96. * Side effects:
  97. * Depends on the startup script.
  98. *
  99. *----------------------------------------------------------------------
  100. */
  101. int
  102. Tcl_AppInit(
  103. Tcl_Interp *interp) /* Interpreter for application. */
  104. {
  105. if ((Tcl_Init)(interp) == TCL_ERROR) {
  106. return TCL_ERROR;
  107. }
  108. #ifdef TCL_XT_TEST
  109. if (Tclxttest_Init(interp) == TCL_ERROR) {
  110. return TCL_ERROR;
  111. }
  112. #endif
  113. #ifdef TCL_TEST
  114. if (Tcltest_Init(interp) == TCL_ERROR) {
  115. return TCL_ERROR;
  116. }
  117. Tcl_StaticLibrary(interp, "Tcltest", Tcltest_Init, Tcltest_SafeInit);
  118. #endif /* TCL_TEST */
  119. /*
  120. * Call the init procedures for included packages. Each call should look
  121. * like this:
  122. *
  123. * if (Mod_Init(interp) == TCL_ERROR) {
  124. * return TCL_ERROR;
  125. * }
  126. *
  127. * where "Mod" is the name of the module. (Dynamically-loadable packages
  128. * should have the same entry-point name.)
  129. */
  130. /*
  131. * Call Tcl_CreateCommand for application-specific commands, if they
  132. * weren't already created by the init procedures called above.
  133. */
  134. /*
  135. * Specify a user-specific startup file to invoke if the application is
  136. * run interactively. Typically the startup file is "~/.apprc" where "app"
  137. * is the name of the application. If this line is deleted then no
  138. * user-specific startup file will be run under any conditions.
  139. */
  140. #ifdef DJGPP
  141. (Tcl_ObjSetVar2)(interp, Tcl_NewStringObj("tcl_rcFileName", -1), NULL,
  142. Tcl_NewStringObj("~/tclsh.rc", -1), TCL_GLOBAL_ONLY);
  143. #else
  144. (Tcl_ObjSetVar2)(interp, Tcl_NewStringObj("tcl_rcFileName", -1), NULL,
  145. Tcl_NewStringObj("~/.tclshrc", -1), TCL_GLOBAL_ONLY);
  146. #endif
  147. return TCL_OK;
  148. }
  149. /*
  150. * Local Variables:
  151. * mode: c
  152. * c-basic-offset: 4
  153. * fill-column: 78
  154. * End:
  155. */