tkUnixInit.c
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:4k
源码类别:

通讯编程

开发平台:

Visual C++

  1. /* 
  2.  * tkUnixInit.c --
  3.  *
  4.  * This file contains Unix-specific interpreter initialization
  5.  * functions.
  6.  *
  7.  * Copyright (c) 1995-1997 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.  * RCS: @(#) $Id: tkUnixInit.c,v 1.5.2.1 2005/05/24 04:21:34 das Exp $
  13.  */
  14. #include "tkInt.h"
  15. #include "tkUnixInt.h"
  16. /*
  17.  * The Init script (common to Windows and Unix platforms) is
  18.  * defined in tkInitScript.h
  19.  */
  20. #include "tkInitScript.h"
  21. #ifdef HAVE_COREFOUNDATION
  22. static int MacOSXGetLibraryPath _ANSI_ARGS_((
  23.     Tcl_Interp *interp));
  24. #endif /* HAVE_COREFOUNDATION */
  25. /*
  26.  *----------------------------------------------------------------------
  27.  *
  28.  * TkpInit --
  29.  *
  30.  * Performs Unix-specific interpreter initialization related to the
  31.  *      tk_library variable.
  32.  *
  33.  * Results:
  34.  * Returns a standard Tcl result.  Leaves an error message or result
  35.  * in the interp's result.
  36.  *
  37.  * Side effects:
  38.  * Sets "tk_library" Tcl variable, runs "tk.tcl" script.
  39.  *
  40.  *----------------------------------------------------------------------
  41.  */
  42. int
  43. TkpInit(interp)
  44.     Tcl_Interp *interp;
  45. {
  46.     TkCreateXEventSource();
  47. #ifdef HAVE_COREFOUNDATION
  48.     MacOSXGetLibraryPath(interp);
  49. #endif /* HAVE_COREFOUNDATION */
  50.     return Tcl_Eval(interp, initScript);
  51. }
  52. /*
  53.  *----------------------------------------------------------------------
  54.  *
  55.  * TkpGetAppName --
  56.  *
  57.  * Retrieves the name of the current application from a platform
  58.  * specific location.  For Unix, the application name is the tail
  59.  * of the path contained in the tcl variable argv0.
  60.  *
  61.  * Results:
  62.  * Returns the application name in the given Tcl_DString.
  63.  *
  64.  * Side effects:
  65.  * None.
  66.  *
  67.  *----------------------------------------------------------------------
  68.  */
  69. void
  70. TkpGetAppName(interp, namePtr)
  71.     Tcl_Interp *interp;
  72.     Tcl_DString *namePtr; /* A previously initialized Tcl_DString. */
  73. {
  74.     CONST char *p, *name;
  75.     name = Tcl_GetVar(interp, "argv0", TCL_GLOBAL_ONLY);
  76.     if ((name == NULL) || (*name == 0)) {
  77. name = "tk";
  78.     } else {
  79. p = strrchr(name, '/');
  80. if (p != NULL) {
  81.     name = p+1;
  82. }
  83.     }
  84.     Tcl_DStringAppend(namePtr, name, -1);
  85. }
  86. /*
  87.  *----------------------------------------------------------------------
  88.  *
  89.  * TkpDisplayWarning --
  90.  *
  91.  * This routines is called from Tk_Main to display warning
  92.  * messages that occur during startup.
  93.  *
  94.  * Results:
  95.  * None.
  96.  *
  97.  * Side effects:
  98.  * Generates messages on stdout.
  99.  *
  100.  *----------------------------------------------------------------------
  101.  */
  102. void
  103. TkpDisplayWarning(msg, title)
  104.     CONST char *msg; /* Message to be displayed. */
  105.     CONST char *title; /* Title of warning. */
  106. {
  107.     Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR);
  108.     if (errChannel) {
  109. Tcl_WriteChars(errChannel, title, -1);
  110. Tcl_WriteChars(errChannel, ": ", 2);
  111. Tcl_WriteChars(errChannel, msg, -1);
  112. Tcl_WriteChars(errChannel, "n", 1);
  113.     }
  114. }
  115. /*
  116.  *----------------------------------------------------------------------
  117.  *
  118.  * MacOSXGetLibraryPath --
  119.  *
  120.  * If we have a bundle structure for the Tk installation,
  121.  * then check there first to see if we can find the libraries
  122.  * there.
  123.  *
  124.  * Results:
  125.  * TCL_OK if we have found the tk library; TCL_ERROR otherwise.
  126.  *
  127.  * Side effects:
  128.  * Same as for Tcl_MacOSXOpenVersionedBundleResources.
  129.  *
  130.  *----------------------------------------------------------------------
  131.  */
  132. #ifdef HAVE_COREFOUNDATION
  133. static int
  134. MacOSXGetLibraryPath(Tcl_Interp *interp)
  135. {
  136.     int foundInFramework = TCL_ERROR;
  137. #ifdef TK_FRAMEWORK
  138.     char tkLibPath[PATH_MAX + 1];
  139.     foundInFramework = Tcl_MacOSXOpenVersionedBundleResources(interp, 
  140. "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 0, PATH_MAX, tkLibPath);
  141.     if (tkLibPath[0] != '') {
  142.         Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
  143.     }
  144. #endif
  145.     return foundInFramework;
  146. }
  147. #endif /* HAVE_COREFOUNDATION */