home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tcl8.0 / unix / tclLoadOSF.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-15  |  3.9 KB  |  129 lines  |  [TEXT/CWIE]

  1. /* 
  2.  * tclLoadOSF.c --
  3.  *
  4.  *    This procedure provides a version of the TclLoadFile that works
  5.  *    under OSF/1 1.0/1.1/1.2 and related systems, utilizing the old OSF/1
  6.  *    /sbin/loader and /usr/include/loader.h.  OSF/1 versions from 1.3 and
  7.  *    on use ELF, rtld, and dlopen()[/usr/include/ldfcn.h].
  8.  *
  9.  *    This is useful for:
  10.  *        OSF/1 1.0, 1.1, 1.2 (from OSF)
  11.  *            includes: MK4 and AD1 (from OSF RI)
  12.  *        OSF/1 1.3 (from OSF) using ROSE
  13.  *        HP OSF/1 1.0 ("Acorn") using COFF
  14.  *
  15.  *    This is likely to be useful for:
  16.  *        Paragon OSF/1 (from Intel) 
  17.  *        HI-OSF/1 (from Hitachi) 
  18.  *
  19.  *    This is NOT to be used on:
  20.  *        Digitial Alpha OSF/1 systems
  21.  *        OSF/1 1.3 or later (from OSF) using ELF
  22.  *            includes: MK6, MK7, AD2, AD3 (from OSF RI)
  23.  *
  24.  *    This approach to things was utter @&^#; thankfully,
  25.  *     OSF/1 eventually supported dlopen().
  26.  *
  27.  *    John Robert LoVerso <loverso@freebsd.osf.org>
  28.  *
  29.  * Copyright (c) 1995 Sun Microsystems, Inc.
  30.  *
  31.  * See the file "license.terms" for information on usage and redistribution
  32.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  33.  *
  34.  * SCCS: @(#) tclLoadOSF.c 1.2 96/02/15 11:58:40
  35.  */
  36.  
  37. #include "tclInt.h"
  38. #include <sys/types.h>
  39. #include <loader.h>
  40.  
  41. /*
  42.  *----------------------------------------------------------------------
  43.  *
  44.  * TclLoadFile --
  45.  *
  46.  *    Dynamically loads a binary code file into memory and returns
  47.  *    the addresses of two procedures within that file, if they
  48.  *    are defined.
  49.  *
  50.  * Results:
  51.  *    A standard Tcl completion code.  If an error occurs, an error
  52.  *    message is left in interp->result.  *proc1Ptr and *proc2Ptr
  53.  *    are filled in with the addresses of the symbols given by
  54.  *    *sym1 and *sym2, or NULL if those symbols can't be found.
  55.  *
  56.  * Side effects:
  57.  *    New code suddenly appears in memory.
  58.  *
  59.  *----------------------------------------------------------------------
  60.  */
  61.  
  62. int
  63. TclLoadFile(interp, fileName, sym1, sym2, proc1Ptr, proc2Ptr)
  64.     Tcl_Interp *interp;        /* Used for error reporting. */
  65.     char *fileName;        /* Name of the file containing the desired
  66.                  * code. */
  67.     char *sym1, *sym2;        /* Names of two procedures to look up in
  68.                  * the file's symbol table. */
  69.     Tcl_PackageInitProc **proc1Ptr, **proc2Ptr;
  70.                 /* Where to return the addresses corresponding
  71.                  * to sym1 and sym2. */
  72. {
  73.     ldr_module_t lm;
  74.     char *pkg;
  75.  
  76.     lm = (Tcl_PackageInitProc *) load(fileName, LDR_NOFLAGS);
  77.     if (lm == LDR_NULL_MODULE) {
  78.     Tcl_AppendResult(interp, "couldn't load file \"", fileName,
  79.         "\": ", Tcl_PosixError (interp), (char *) NULL);
  80.     return TCL_ERROR;
  81.     }
  82.  
  83.     /*
  84.      * My convention is to use a [OSF loader] package name the same as shlib,
  85.      * since the idiots never implemented ldr_lookup() and it is otherwise
  86.      * impossible to get a package name given a module.
  87.      *
  88.      * I build loadable modules with a makefile rule like 
  89.      *        ld ... -export $@: -o $@ $(OBJS)
  90.      */
  91.     if ((pkg = strrchr(fileName, '/')) == NULL)
  92.     pkg = fileName;
  93.     else
  94.     pkg++;
  95.     *proc1Ptr = ldr_lookup_package(pkg, sym1);
  96.     *proc2Ptr = ldr_lookup_package(pkg, sym2);
  97.     return TCL_OK;
  98. }
  99.  
  100. /*
  101.  *----------------------------------------------------------------------
  102.  *
  103.  * TclGuessPackageName --
  104.  *
  105.  *    If the "load" command is invoked without providing a package
  106.  *    name, this procedure is invoked to try to figure it out.
  107.  *
  108.  * Results:
  109.  *    Always returns 0 to indicate that we couldn't figure out a
  110.  *    package name;  generic code will then try to guess the package
  111.  *    from the file name.  A return value of 1 would have meant that
  112.  *    we figured out the package name and put it in bufPtr.
  113.  *
  114.  * Side effects:
  115.  *    None.
  116.  *
  117.  *----------------------------------------------------------------------
  118.  */
  119.  
  120. int
  121. TclGuessPackageName(fileName, bufPtr)
  122.     char *fileName;        /* Name of file containing package (already
  123.                  * translated to local form if needed). */
  124.     Tcl_DString *bufPtr;    /* Initialized empty dstring.  Append
  125.                  * package name to this if possible. */
  126. {
  127.     return 0;
  128. }
  129.