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