tclAppInit.c 4.4 KB

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