diff --git a/include/intern.h b/include/intern.h index 48f5629..d2c7868 100644 --- a/include/intern.h +++ b/include/intern.h @@ -111,7 +111,7 @@ extern Object General_Load P_((Object, Object)); */ extern Object General_Assoc P_((Object, Object, int)); -/* main.c +/* libelk.c */ extern char *stkbase, *A_Out_Name; extern int Stack_Grows_Down; @@ -121,6 +121,8 @@ extern char *Brk_On_Dump; extern int Verb_Load, Verb_Init, Case_Insensitive; extern SYMTAB *The_Symbols; extern void Exit_Handler P_((void)); +extern char *Scm_Dir; +extern char *Lib_Dir; #ifndef HAVE_ATEXIT extern void exit P_((int)); #endif diff --git a/src/Makefile.am b/src/Makefile.am index 0282933..1a99c1b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ NULL = lib_LTLIBRARIES = libelk.la -libelk_la_CFLAGS = -I/usr/include/libelf -DNOMAIN +libelk_la_CFLAGS = -I/usr/include/libelf libelk_la_LDFLAGS = libelk_la_LIBADD = @ELK_LIBS@ libelk_la_SOURCES = \ diff --git a/src/io.c b/src/io.c index 4ecc97c..45b671c 100644 --- a/src/io.c +++ b/src/io.c @@ -189,7 +189,11 @@ Object General_File_Operation (Object s, register int op) { return s; } Alloca (r, char*, strlen (dir) + 1 + strlen (p) + 1); +#ifdef WIN32 + sprintf (r, "%s\\%s", dir, p); +#else sprintf (r, "%s/%s", dir, p); +#endif ret = Make_String (r, strlen (r)); Alloca_End; return ret; @@ -236,7 +240,11 @@ Object Open_File (char *name, int flags, int err) { p = Internal_Tilde_Expand (name, &dir); if (p) { Alloca (name, char*, strlen (dir) + 1 + strlen (p) + 1); +#ifdef WIN32 + sprintf (name, "%s\\%s", dir, p); +#else sprintf (name, "%s/%s", dir, p); +#endif } if (!err && stat (name, &st) == -1 && (errno == ENOENT || errno == ENOTDIR)) { @@ -271,7 +279,11 @@ Object General_Open_File (Object name, int flags, Object path) { name = Get_File_Name (name); len = STRING(name)->size; fn = STRING(name)->data; +#ifdef WIN32 + if (fn[0] < 'A' || fn[0] > 'Z' || fn[1] != ':' ) { +#else if (fn[0] != '/' && fn[0] != '~') { +#endif for ( ; TYPE(path) == T_Pair; path = Cdr (path)) { pref = Car (path); if (TYPE(pref) == T_Symbol) @@ -286,8 +298,13 @@ Object General_Open_File (Object name, int flags, Object path) { Alloca (buf, char*, blen); } memcpy (buf, STRING(pref)->data, plen); +#ifdef WIN32 + if (buf[plen-1] != '\\') + buf[plen++] = '\\'; +#else if (buf[plen-1] != '/') buf[plen++] = '/'; +#endif memcpy (buf+plen, fn, len); buf[len+plen] = '\0'; port = Open_File (buf, flags, 0); diff --git a/src/libelk.c b/src/libelk.c index 6802e5b..4a479a0 100644 --- a/src/libelk.c +++ b/src/libelk.c @@ -45,6 +45,10 @@ # endif #endif +#ifdef WIN32 +# include +#endif + #ifdef FIND_AOUT # ifdef HAVE_UNISTD_H # include @@ -101,6 +105,8 @@ int Verb_Load = 0, Verb_Init = 0; char **Argv; int Argc, First_Arg; +char *Scm_Dir; +char *Lib_Dir; #ifdef FIND_AOUT char *A_Out_Name; char *Find_Executable(); @@ -145,22 +151,12 @@ char *Brk_On_Dump; * an incompatible way. */ void Check_If_Dump_Works () { -#ifdef NOMAIN Primitive_Error ("not yet supported for standalone applications"); -#endif } -#ifdef NOMAIN - void Elk_Init (int ac, char **av, int init_objects, char *toplevel) { -#else - -int main (int ac, char **av) { - -#endif - /* To avoid that the stack copying code overwrites argv if a dumped * copy of the interpreter is invoked with more arguments than the * original a.out, move the stack base INITIAL_STK_OFFSET bytes down. @@ -175,7 +171,7 @@ int main (int ac, char **av) { Object file; struct stat st; extern int errno; -#if defined(CAN_DUMP) && defined(NOMAIN) +#if defined(CAN_DUMP) # define foo (av[0][0]) #else char foo; @@ -189,9 +185,29 @@ int main (int ac, char **av) { } Get_Stack_Limit (); -#ifdef FIND_AOUT + Lib_Dir = NULL; + Scm_Dir = NULL; + +#ifdef WIN32 + if (av[0]) { + char path[MAX_PATH], *exe; + GetFullPathName (av[0], MAX_PATH, path, &exe); + if (exe > path && exe[-1] == '\\') { + char newpath[MAX_PATH+5]; + exe[-1] = '\0'; + sprintf (newpath, "%s\\lib", path); + Lib_Dir = strdup (newpath); + sprintf (newpath, "%s\\scm", path); + Scm_Dir = strdup (newpath); + } + } +#elif defined(FIND_AOUT) A_Out_Name = Find_Executable (av[0]); #endif + if (Scm_Dir == NULL) + Scm_Dir = strdup (SCM_DIR); + if (Lib_Dir == NULL) + Lib_Dir = strdup (LIB_DIR); Argc = ac; Argv = av; First_Arg = 1; @@ -275,18 +291,11 @@ int main (int ac, char **av) { Fatal_Error ("atexit returned non-zero value"); #endif #ifdef INIT_OBJECTS -#ifdef NOMAIN if (init_objects) { Set_Error_Tag ("init-objects"); The_Symbols = Open_File_And_Snarf_Symbols (A_Out_Name); Call_Initializers (The_Symbols, (char *)0, PR_EXTENSION); } -#else - Set_Error_Tag ("init-objects"); - The_Symbols = Open_File_And_Snarf_Symbols (A_Out_Name); - Call_Initializers (The_Symbols, (char *)0, PR_CONSTRUCTOR); - Call_Initializers (The_Symbols, (char *)0, PR_EXTENSION); -#endif #endif if (loadpath || (loadpath = getenv (LOADPATH_ENV))) Init_Loadpath (loadpath); @@ -299,8 +308,12 @@ int main (int ac, char **av) { * the load-path, so that -p can be used. */ Set_Error_Tag ("scheme-init"); - initfile = Safe_Malloc (strlen (SCM_DIR) + 1 + sizeof (INITFILE) + 1); - sprintf (initfile, "%s/%s", SCM_DIR, INITFILE); + initfile = Safe_Malloc (strlen (Scm_Dir) + 1 + sizeof (INITFILE) + 1); +#ifdef WIN32 + sprintf (initfile, "%s\\%s", Scm_Dir, INITFILE); +#else + sprintf (initfile, "%s/%s", Scm_Dir, INITFILE); +#endif if (stat (initfile, &st) == -1 && errno == ENOENT) file = Make_String (INITFILE, sizeof(INITFILE)-1); else @@ -311,7 +324,6 @@ int main (int ac, char **av) { Install_Intr_Handler (); Set_Error_Tag ("top-level"); -#ifdef NOMAIN if (toplevel == 0) { Interpreter_Initialized = 1; GC_Debug = debug; @@ -320,7 +332,6 @@ int main (int ac, char **av) { /* Special case: if toplevel is "", act as if run from main() */ if (loadfile == 0 && toplevel[0] != '\0') loadfile = toplevel; -#endif if (loadfile == 0) loadfile = "toplevel.scm"; file = Make_String (loadfile, strlen (loadfile)); @@ -330,9 +341,6 @@ int main (int ac, char **av) { Load_Source_Port (Standard_Input_Port); else (void)General_Load (file, The_Environment); -#ifndef NOMAIN - return 0; -#endif } static char *Usage_Msg[] = { diff --git a/src/load.c b/src/load.c index 1f704df..ffbf2ca 100644 --- a/src/load.c +++ b/src/load.c @@ -47,8 +47,8 @@ void Load_Source (Object); void Init_Load () { Define_Variable (&V_Load_Path, "load-path", Cons (Make_String (".", 1), - Cons (Make_String (SCM_DIR, sizeof (SCM_DIR) - 1), - Cons (Make_String (LIB_DIR, sizeof (LIB_DIR) - 1), Null)))); + Cons (Make_String (Scm_Dir, strlen (Scm_Dir)), + Cons (Make_String (Lib_Dir, strlen (Lib_Dir)), Null)))); Define_Variable (&V_Load_Noisilyp, "load-noisily?", False); Define_Variable (&V_Load_Libraries, "load-libraries", Make_String ("", 0)); }