/***********************************************************************
 *
 *	Local definitions of C functions for GNU Smalltalk 
 *
 *	$Revision: 1.4 $
 *	$Date: 1995/07/18 06:25:09 $
 *	$Author: sbb $
 *
 ***********************************************************************/

/***********************************************************************
 *
 * Copyright (C) 1994, 1995 Free Software Foundation, Inc.
 * Written by Steve Byrne.
 *
 * This file is part of GNU Smalltalk.
 *
 * GNU Smalltalk is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 1, or (at your option) any later 
 * version.
 * 
 * GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
 * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
 *
 ***********************************************************************/

/*
 *    Change Log
 * ============================================================================
 * Author      Date       Change 
 * sbb	     14 Jan 95	  Changed the name from DLD to USE_DLD to avoid
 *			  conflicts with symbols defined by the DLD package in
 *			  the future.
 *
 * sbb	      3 Sep 94	  Cloned from lib/cfuncs.c
 *
 * sbb	      3 Sep 94	  This is the first file in the distribution to not
 *			  start with "mst".  This is the precursor to having
 *			  short file names so that primitive operating systems
 *			  can deal with an advanced system like Smalltalk :-)
 *			  :-) :-).
 *
 * sbb	      3 Sep 94	  Created.
 *
 */


#include "gst.h"

#undef USE_DLD /* DLD stuff is down in cxtnsn */

extern void defineCFunc();

void
initUserCFuncs()
{
#ifdef USE_DLD
  initDldLib();
#endif

}


#ifdef USE_DLD

/***********************************************************************
 *
 *	GNU Dynamic Linking support code
 *
 ***********************************************************************/

#include <dld.h>

char	*dldArgv0;

static int getUndefinedSymCount()
{
  return (dld_undefined_sym_count);
}

static void
testDLD()
{
  void (*func)();
  printf("linking a file %d\n", dld_link("xxx.o"));
  
  func = dld_get_func("foopartner");
  printf("func is %x\n", func);
  (*func)();
}

initDldLib()
{
  extern int main();
  if (dld_init (dld_find_executable (dldArgv0)) == 0) {
    defineCFunc("dldLink", dld_link);
    defineCFunc("dldUnlinkByFile", dld_unlink_by_file);
    defineCFunc("dldUnlinkBySymbol", dld_unlink_by_symbol);
    defineCFunc("dldGetSymbol", dld_get_symbol);
    defineCFunc("dldGetFunc", dld_get_func);
    defineCFunc("dldFunctionExecutableP", dld_function_executable_p);
    defineCFunc("dldListUndefinedSym", dld_list_undefined_sym);
    defineCFunc("dldCreateReference", dld_create_reference);
    defineCFunc("dldDefineSym", dld_define_sym);
    defineCFunc("dldRemoveDefinedSymbol", dld_remove_defined_symbol);

    defineCFunc("getUndefinedSymCount", getUndefinedSymCount);

    /* so user level code can invoke it! */
    defineCFunc("defineCFunc", defineCFunc);

    defineCFunc("testDLD", testDLD);
  }
}

#endif


