* Removed references to NOMAIN.

* Replaced / with \ under Win32.
  * The Win32 version looks for .scm files in the scm subdirectory of the
    executable's current directory.


git-svn-id: svn://svn.zoy.org/elk/trunk@148 55e467fa-43c5-0310-a8a2-de718669efc6
This commit is contained in:
sam 2003-09-13 00:34:58 +00:00
parent 892fa3085f
commit b12222213e
5 changed files with 57 additions and 30 deletions

View File

@ -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

View File

@ -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 = \

View File

@ -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);

View File

@ -45,6 +45,10 @@
# endif
#endif
#ifdef WIN32
# include <windows.h>
#endif
#ifdef FIND_AOUT
# ifdef HAVE_UNISTD_H
# include <unistd.h>
@ -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[] = {

View File

@ -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));
}