aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/rc/main.c
blob: b4a355e00e29f97fdf89b80f7d9774ad5694cb6e (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "rc.h"

/* globals */
Thread *shell = nil;
int     ntrap = 0;
Io     *errio;

/* main execution */

void
dotrap(void)
{
    exit(1);
}

void
bootup(Code *c, int off, Var *vars)
{
    Thread *sh;

    alloc(sh);
    sh->code  = c, c->i++;
    sh->ip    = sh->code + off;
    sh->local = vars;
    sh->stack = nil;

    sh->link = shell, shell = sh;
}

int
main(int argc, char *argv[])
{
    int  i;
    Code *ip, sh[32];

    ARGBEGIN {
    } ARGEND;

    errio = openfd(2);

    initkw();

    ip = sh;
    memset(sh, 0, sizeof(sh));
    /* 
     * NOTE: first element of code is a reference count 
     * bootup runs:
     * 1. *=argv[1:]
     * 2. . rcmain $*
     */ 
#if 0
    ip++->i = 1;
    ip++->f = Xmark;
    ip++->f = Xword;
    ip++->s = "*";
    ip++->f = Xassign;
    ip++->f = Xmark;
    ip++->f = Xmark;
    ip++->s = "*";
    ip++->f = Xdol;
    ip++->s = "rcmain";
    ip++->f = Xword;
    ip++->s = ".";
    ip++->f = Xsimple;
    ip++->f = Xexit;
    ip++->i = 0;

    bootup(sh, 1, nil);
    pushlist();
    for (i = argc-1; i != 0; i--)
        pushword(argv[i]);

    for (;;) {
        shell->ip++->f();
        if (ntrap)
            dotrap();
    }
#else
    bootup(sh, 1, nil);
    shell->cmd.io = openfd(0);
    while (parse())
        ;

#endif
    exit(0);
}