tkAppInit.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * tkAppInit.c --
  3. *
  4. * Provides a default version of the main program and Tcl_AppInit
  5. * procedure for wish and other Tk-based applications.
  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_tk
  15. #undef STATIC_BUILD
  16. #include "tk.h"
  17. #include "tkPort.h"
  18. #if TCL_MAJOR_VERSION < 9 && TCL_MINOR_VERSION < 7
  19. # define Tcl_LibraryInitProc Tcl_PackageInitProc
  20. # define Tcl_StaticLibrary Tcl_StaticPackage
  21. #endif
  22. #ifdef TK_TEST
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. extern Tcl_LibraryInitProc Tktest_Init;
  27. #ifdef __cplusplus
  28. }
  29. #endif
  30. #endif /* TK_TEST */
  31. /*
  32. * The following #if block allows you to change the AppInit function by using
  33. * a #define of TCL_LOCAL_APPINIT instead of rewriting this entire file. The
  34. * #if checks for that #define and uses Tcl_AppInit if it doesn't exist.
  35. */
  36. #ifndef TK_LOCAL_APPINIT
  37. #define TK_LOCAL_APPINIT Tcl_AppInit
  38. #endif
  39. #ifndef MODULE_SCOPE
  40. # ifdef __cplusplus
  41. # define MODULE_SCOPE extern "C"
  42. # else
  43. # define MODULE_SCOPE extern
  44. # endif
  45. #endif
  46. MODULE_SCOPE int TK_LOCAL_APPINIT(Tcl_Interp *);
  47. MODULE_SCOPE int main(int, char **);
  48. /*
  49. * The following #if block allows you to change how Tcl finds the startup
  50. * script, prime the library or encoding paths, fiddle with the argv, etc.,
  51. * without needing to rewrite Tk_Main()
  52. */
  53. #ifdef TK_LOCAL_MAIN_HOOK
  54. MODULE_SCOPE int TK_LOCAL_MAIN_HOOK(int *argc, char ***argv);
  55. #endif
  56. /* Make sure the stubbed variants of those are never used. */
  57. #undef Tcl_ObjSetVar2
  58. #undef Tcl_NewStringObj
  59. /*
  60. *----------------------------------------------------------------------
  61. *
  62. * main --
  63. *
  64. * This is the main program for the application.
  65. *
  66. * Results:
  67. * None: Tk_Main never returns here, so this procedure never returns
  68. * either.
  69. *
  70. * Side effects:
  71. * Just about anything, since from here we call arbitrary Tcl code.
  72. *
  73. *----------------------------------------------------------------------
  74. */
  75. int
  76. main(
  77. int argc, /* Number of command-line arguments. */
  78. char **argv) /* Values of command-line arguments. */
  79. {
  80. #ifdef TK_LOCAL_MAIN_HOOK
  81. TK_LOCAL_MAIN_HOOK(&argc, &argv);
  82. #endif
  83. Tk_Main(argc, argv, TK_LOCAL_APPINIT);
  84. return 0; /* Needed only to prevent compiler warning. */
  85. }
  86. /*
  87. *----------------------------------------------------------------------
  88. *
  89. * Tcl_AppInit --
  90. *
  91. * This procedure performs application-specific initialization. Most
  92. * applications, especially those that incorporate additional packages,
  93. * will have their own version of this procedure.
  94. *
  95. * Results:
  96. * Returns a standard Tcl completion code, and leaves an error message in
  97. * the interp's result if an error occurs.
  98. *
  99. * Side effects:
  100. * Depends on the startup script.
  101. *
  102. *----------------------------------------------------------------------
  103. */
  104. int
  105. Tcl_AppInit(
  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_StaticLibrary(interp, "Tk", Tk_Init, Tk_SafeInit);
  115. #if defined(USE_CUSTOM_EXIT_PROC)
  116. if (TkpWantsExitProc()) {
  117. Tcl_SetExitProc(TkpExitProc);
  118. }
  119. #endif
  120. #ifdef TK_TEST
  121. if (Tktest_Init(interp) == TCL_ERROR) {
  122. return TCL_ERROR;
  123. }
  124. Tcl_StaticLibrary(interp, "Tktest", Tktest_Init, 0);
  125. #endif /* TK_TEST */
  126. /*
  127. * Call the init procedures for included packages. Each call should look
  128. * like this:
  129. *
  130. * if (Mod_Init(interp) == TCL_ERROR) {
  131. * return TCL_ERROR;
  132. * }
  133. *
  134. * where "Mod" is the name of the module. (Dynamically-loadable packages
  135. * should have the same entry-point name.)
  136. */
  137. /*
  138. * Call Tcl_CreateObjCommand for application-specific commands, if they
  139. * weren't already created by the init procedures called above.
  140. */
  141. /*
  142. * Specify a user-specific startup file to invoke if the application is
  143. * run interactively. Typically the startup file is "~/.apprc" where "app"
  144. * is the name of the application. If this line is deleted then no user-
  145. * specific startup file will be run under any conditions.
  146. */
  147. Tcl_ObjSetVar2(interp, Tcl_NewStringObj("tcl_rcFileName", -1), NULL,
  148. Tcl_NewStringObj("~/.wishrc", -1), TCL_GLOBAL_ONLY);
  149. return TCL_OK;
  150. }
  151. /*
  152. * Local Variables:
  153. * mode: c
  154. * c-basic-offset: 4
  155. * fill-column: 78
  156. * End:
  157. */