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