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