core: Refactor boot-0 loading.

* src/mes.c (load_boot): New function.
  (load_env): Use it.
This commit is contained in:
Jan Nieuwenhuizen 2018-05-28 18:53:25 +02:00
parent be34aaf636
commit 58a0b97991
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
1 changed files with 37 additions and 41 deletions

View File

@ -1445,7 +1445,7 @@ eval_apply ()
input = set_current_input_port (r1); input = set_current_input_port (r1);
else else
assert (0); assert (0);
push_cc (input, r2, r0, cell_vm_return); push_cc (input, r2, r0, cell_vm_return);
x = read_input_file_env (r0); x = read_input_file_env (r0);
gc_pop_frame (); gc_pop_frame ();
@ -2215,65 +2215,61 @@ a = acons (lookup_symbol_ (scm_display_error_.string), cell_display_error_, a);
SCM read_input_file_env (SCM); SCM read_input_file_env (SCM);
int
load_boot (char *prefix, char const *boot, char const *location)
{
strcpy (prefix + strlen (prefix), boot);
if (g_debug > 1)
{
eputs ("mes: reading boot-0 [");
eputs (location);
eputs ("]: ");
eputs (prefix);
eputs ("\n");
}
int fd = open (prefix, O_RDONLY);
if (g_debug && fd > 0)
{
eputs ("mes: read boot-0: ");
eputs (prefix);
eputs ("\n");
}
return fd;
}
SCM SCM
load_env (SCM a) ///((internal)) load_env (SCM a) ///((internal))
{ {
r0 = a; r0 = a;
g_stdin = -1; g_stdin = -1;
char prefix[1024];
char boot[1024]; char boot[1024];
char buf[1024];
if (getenv ("MES_BOOT")) if (getenv ("MES_BOOT"))
strcpy (boot, getenv ("MES_BOOT")); strcpy (boot, getenv ("MES_BOOT"));
else else
strcpy (boot, "boot-0.scm"); strcpy (boot, "boot-0.scm");
if (getenv ("MES_PREFIX")) if (getenv ("MES_PREFIX"))
{ {
strcpy (buf, getenv ("MES_PREFIX")); strcpy (prefix, getenv ("MES_PREFIX"));
strcpy (buf + strlen (buf), "/module"); strcpy (prefix + strlen (prefix), "/module");
strcpy (buf + strlen (buf), "/mes/"); strcpy (prefix + strlen (prefix), "/mes/");
strcpy (buf + strlen (buf), boot); g_stdin = load_boot (prefix, boot, "MES_PREFIX");
if (getenv ("MES_DEBUG"))
{
eputs ("MES_PREFIX reading boot-0:");
eputs (buf);
eputs ("\n");
}
g_stdin = open (buf, O_RDONLY);
} }
if (g_stdin < 0) if (g_stdin < 0)
{ {
char const *prefix = MODULEDIR "/mes/"; char const *p = MODULEDIR "/mes/";
strcpy (buf, prefix); strcpy (prefix, p);
strcpy (buf + strlen (buf), boot); g_stdin = load_boot (prefix, boot, "MODULEDIR");
if (getenv ("MES_DEBUG"))
{
eputs ("MODULEDIR reading boot-0:");
eputs (buf);
eputs ("\n");
}
g_stdin = open (buf, O_RDONLY);
} }
if (g_stdin < 0) if (g_stdin < 0)
{ {
strcpy (buf, "module/mes/"); strcpy (prefix, "module/mes/");
strcpy (buf + strlen (buf), boot); g_stdin = load_boot (prefix, boot, ".");
if (getenv ("MES_DEBUG"))
{
eputs (". reading boot-0:");
eputs (buf);
eputs ("\n");
}
g_stdin = open (buf, O_RDONLY);
} }
if (g_stdin < 0) if (g_stdin < 0)
{ {
if (getenv ("MES_DEBUG")) prefix[0] = 0;
{ g_stdin = load_boot (prefix, boot, "<boot>");
eputs (". reading boot-0:");
eputs (boot);
eputs ("\n");
}
g_stdin = open (boot, O_RDONLY);
} }
if (g_stdin < 0) if (g_stdin < 0)
{ {
@ -2310,7 +2306,7 @@ bload_env (SCM a) ///((internal))
eputs (mo); eputs (mo);
eputs ("\n"); eputs ("\n");
return 1; return 1;
} }
assert (getchar () == 'M'); assert (getchar () == 'M');
assert (getchar () == 'E'); assert (getchar () == 'E');
assert (getchar () == 'S'); assert (getchar () == 'S');
@ -2377,7 +2373,7 @@ main (int argc, char *argv[])
char *p; char *p;
if (p = getenv ("MES_DEBUG")) if (p = getenv ("MES_DEBUG"))
g_debug = atoi (p); g_debug = atoi (p);
if (g_debug) if (g_debug > 1)
{ {
eputs (";;; MODULEDIR="); eputs (";;; MODULEDIR=");
eputs (MODULEDIR); eputs (MODULEDIR);