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 | static int16_t Argc;
|
---|
26 | static int8_t *Argv[MAXARGS];
|
---|
27 |
|
---|
28 | /*
|
---|
29 | ============================================================================
|
---|
30 | exit() -- return control to the BIOS
|
---|
31 | ============================================================================
|
---|
32 | */
|
---|
33 |
|
---|
34 | void exit(void)
|
---|
35 | {
|
---|
36 | (*_clsall)(); /* close all open files */
|
---|
37 | xtrap15(); /* return to the BIOS */
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | #if REDIRECT
|
---|
42 |
|
---|
43 | /*
|
---|
44 | ============================================================================
|
---|
45 | _eredir(name) -- output I/O redirection error message to stderr
|
---|
46 | ============================================================================
|
---|
47 | */
|
---|
48 |
|
---|
49 | static
|
---|
50 | _eredir(name)
|
---|
51 | char *name;
|
---|
52 | {
|
---|
53 | char buff[200];
|
---|
54 |
|
---|
55 | strcpy(buff, "Can't open file for redirection: ");
|
---|
56 | strcat(buff, name);
|
---|
57 | strcat(buff, "\n");
|
---|
58 | write(2, buff, strlen(buff));
|
---|
59 | exit();
|
---|
60 | }
|
---|
61 |
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | /*
|
---|
65 | ============================================================================
|
---|
66 | Croot(cp) -- C root module for the Buchla 700
|
---|
67 | ============================================================================
|
---|
68 | */
|
---|
69 |
|
---|
70 | void Croot(int8_t *cp)
|
---|
71 | {
|
---|
72 | register int8_t *fname;
|
---|
73 | register int16_t k;
|
---|
74 |
|
---|
75 | Argv[0] = ROOTMSG;
|
---|
76 | Argc = 1;
|
---|
77 |
|
---|
78 | _clsall = _fd_cls;
|
---|
79 | InitFS();
|
---|
80 |
|
---|
81 | #if REDIRECT
|
---|
82 |
|
---|
83 | while (Argc < MAXARGS) { /* handle command line arguments */
|
---|
84 |
|
---|
85 | while (*cp EQ ' ' OR *cp EQ '\t') /* skip whitespace */
|
---|
86 | ++cp;
|
---|
87 |
|
---|
88 | if (*cp EQ 0) /* check for end of line */
|
---|
89 | break;
|
---|
90 |
|
---|
91 | if (*cp EQ '>') { /* > - redirect output */
|
---|
92 |
|
---|
93 | k = 1; /* stdout */
|
---|
94 | goto redir;
|
---|
95 |
|
---|
96 | } else if (*cp EQ '<') { /* < - redirect input */
|
---|
97 |
|
---|
98 | k = 0; /* stdin */
|
---|
99 | redir:
|
---|
100 | while (*++cp EQ ' ' OR *cp EQ '\t') /* skip whitespace */
|
---|
101 | ;
|
---|
102 |
|
---|
103 | fname = cp; /* pointer to start of name */
|
---|
104 |
|
---|
105 | while (*++cp) /* skip to whitespace */
|
---|
106 | if (*cp EQ ' ' OR *cp EQ '\t') {
|
---|
107 |
|
---|
108 | *cp++ = 0;
|
---|
109 | break;
|
---|
110 | }
|
---|
111 |
|
---|
112 | close(k); /* close old assignment */
|
---|
113 |
|
---|
114 | if (k)
|
---|
115 | k = creat(fname, 0666); /* stdout */
|
---|
116 | else
|
---|
117 | k = open(fname, O_RDONLY); /* stdin */
|
---|
118 |
|
---|
119 | if (k EQ -1)
|
---|
120 | _eredir(fname);
|
---|
121 |
|
---|
122 | } else { /* collect a command line argument */
|
---|
123 |
|
---|
124 | Argv[Argc++] = cp;
|
---|
125 |
|
---|
126 | while (*++cp) /* find end of argument */
|
---|
127 | if (*cp EQ ' ' OR *cp EQ '\t') {
|
---|
128 |
|
---|
129 | *cp++ = 0;
|
---|
130 | break;
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | #endif
|
---|
136 |
|
---|
137 | main(); /* call application */
|
---|
138 | exit(); /* exit in case the application didn't */
|
---|
139 | }
|
---|
140 |
|
---|