-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
52 lines (46 loc) · 1.24 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "extern.h"
#include "exp.h"
#include "env.h"
#include "prim.h"
static void initenv(void);
const char *progname;
int
main(int argc, char *argv[])
{
progname = sstrdup(basename(argv[0]));
initenv();
if (--argc) {
while (argc--)
if (load(*++argv, NINTER))
exit(EXIT_FAILURE);
} else {
load(NULL, INTER);
putchar('\n');
}
free((void *)progname);
exit(EXIT_SUCCESS);
}
/* Initialize the global environment */
static void
initenv(void)
{
char buf[BUFSIZ], *pref;
FILE *fp;
int ret;
initkeys();
globenv = newenv();
instcst(globenv);
instprim(globenv);
/* load the library */
if ((ret = (pref = getenv(PREFIX)) != NULL)) {
snprintf(buf, BUFSIZ, "%s/%s", pref, LOOTRC);
if ((ret = (fp = fopen(buf, "r")) != NULL)) {
fgets(buf, BUFSIZ, fp);
fclose(fp);
}
} else
warnx("environment variable %s not defined", PREFIX);
if (!ret)
snprintf(buf, BUFSIZ, "%s", LIBNAM);
load(buf, NINTER);
}