1 | /*
|
---|
2 | ============================================================================
|
---|
3 | croot.c -- Root for Buchla 700 C programs
|
---|
4 | Version 8 -- 1987-06-29 -- D.N. Lynx Crowe
|
---|
5 |
|
---|
6 | This version can be setup for I/O redirection or not, depending on the
|
---|
7 | value of REDIRECT. If redirection is supported, so are command line
|
---|
8 | arguments, which must be passed to Croot() at 'cp' by the startup code.
|
---|
9 |
|
---|
10 | Normally, this won't be selected, as this is a dedicated application
|
---|
11 | that doesn't expect command line arguments or I/O redirection.
|
---|
12 | ============================================================================
|
---|
13 | */
|
---|
14 |
|
---|
15 | #define ROOTMSG "{Buchla 700 Croot - Version 8 - 1987-06-29}"
|
---|
16 |
|
---|
17 | #include "ram.h"
|
---|
18 |
|
---|
19 | #define REDIRECT 0 /* non-zero for command line stuff */
|
---|
20 |
|
---|
21 | #define MAXARGS 30 /* maximum number of command line arguments */
|
---|
22 |
|
---|
23 | void (*_clsall)(void);
|
---|
24 |
|
---|
25 | /* |
---|
26 |
|
---|
27 | */
|
---|
28 |
|
---|
29 | static int16_t Argc;
|
---|
30 | static int8_t *Argv[MAXARGS];
|
---|
31 |
|
---|
32 | /* |
---|
33 |
|
---|
34 | */
|
---|
35 |
|
---|
36 | /*
|
---|
37 | ============================================================================
|
---|
38 | exit() -- return control to the BIOS
|
---|
39 | ============================================================================
|
---|
40 | */
|
---|
41 |
|
---|
42 | void exit(void)
|
---|
43 | {
|
---|
44 | (*_clsall)(); /* close all open files */
|
---|
45 | xtrap15(); /* return to the BIOS */
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | #if REDIRECT
|
---|
50 |
|
---|
51 | /*
|
---|
52 | ============================================================================
|
---|
53 | _eredir(name) -- output I/O redirection error message to stderr
|
---|
54 | ============================================================================
|
---|
55 | */
|
---|
56 |
|
---|
57 | static
|
---|
58 | _eredir(name)
|
---|
59 | char *name;
|
---|
60 | {
|
---|
61 | char buff[200];
|
---|
62 |
|
---|
63 | strcpy(buff, "Can't open file for redirection: ");
|
---|
64 | strcat(buff, name);
|
---|
65 | strcat(buff, "\n");
|
---|
66 | write(2, buff, strlen(buff));
|
---|
67 | exit();
|
---|
68 | }
|
---|
69 |
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | /* |
---|
73 |
|
---|
74 | */
|
---|
75 |
|
---|
76 | /*
|
---|
77 | ============================================================================
|
---|
78 | Croot(cp) -- C root module for the Buchla 700
|
---|
79 | ============================================================================
|
---|
80 | */
|
---|
81 |
|
---|
82 | void Croot(int8_t *cp)
|
---|
83 | {
|
---|
84 | register int8_t *fname;
|
---|
85 | register int16_t k;
|
---|
86 |
|
---|
87 | Argv[0] = ROOTMSG;
|
---|
88 | Argc = 1;
|
---|
89 |
|
---|
90 | _clsall = _fd_cls;
|
---|
91 | InitFS();
|
---|
92 |
|
---|
93 | #if REDIRECT
|
---|
94 |
|
---|
95 | while (Argc < MAXARGS) { /* handle command line arguments */
|
---|
96 |
|
---|
97 | while (*cp EQ ' ' OR *cp EQ '\t') /* skip whitespace */
|
---|
98 | ++cp;
|
---|
99 |
|
---|
100 | if (*cp EQ 0) /* check for end of line */
|
---|
101 | break;
|
---|
102 |
|
---|
103 | if (*cp EQ '>') { /* > - redirect output */
|
---|
104 |
|
---|
105 | k = 1; /* stdout */
|
---|
106 | goto redir;
|
---|
107 |
|
---|
108 | } else if (*cp EQ '<') { /* < - redirect input */
|
---|
109 |
|
---|
110 | k = 0; /* stdin */
|
---|
111 | redir:
|
---|
112 | while (*++cp EQ ' ' OR *cp EQ '\t') /* skip whitespace */
|
---|
113 | ;
|
---|
114 |
|
---|
115 | fname = cp; /* pointer to start of name */
|
---|
116 |
|
---|
117 | while (*++cp) /* skip to whitespace */
|
---|
118 | if (*cp EQ ' ' OR *cp EQ '\t') {
|
---|
119 |
|
---|
120 | *cp++ = 0;
|
---|
121 | break;
|
---|
122 | }
|
---|
123 |
|
---|
124 | close(k); /* close old assignment */
|
---|
125 |
|
---|
126 | if (k)
|
---|
127 | k = creat(fname, 0666); /* stdout */
|
---|
128 | else
|
---|
129 | k = open(fname, O_RDONLY); /* stdin */
|
---|
130 |
|
---|
131 | if (k EQ -1)
|
---|
132 | _eredir(fname);
|
---|
133 |
|
---|
134 | } else { /* collect a command line argument */
|
---|
135 |
|
---|
136 | Argv[Argc++] = cp;
|
---|
137 |
|
---|
138 | while (*++cp) /* find end of argument */
|
---|
139 | if (*cp EQ ' ' OR *cp EQ '\t') {
|
---|
140 |
|
---|
141 | *cp++ = 0;
|
---|
142 | break;
|
---|
143 | }
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | #endif
|
---|
148 |
|
---|
149 | main(); /* call application */
|
---|
150 | exit(); /* exit in case the application didn't */
|
---|
151 | }
|
---|
152 |
|
---|