source: buchla-68k/orig/ROM/CROOT.C@ 62340ef

Last change on this file since 62340ef was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 3.4 KB
Line 
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
29extern int open(), creat();
30
31extern int InitFS();
32extern int _fd_cls();
33extern int xtrap15();
34
35int (*_clsall)();
36
37/*
38
39*/
40
41static int Argc;
42static char *Argv[MAXARGS];
43
44/*
45
46*/
47
48/*
49 ============================================================================
50 exit(code) -- return control to the BIOS
51 ============================================================================
52*/
53
54exit(code)
55{
56 (*_clsall)(); /* close all open files */
57 xtrap15(code); /* return to the BIOS */
58}
59
60
61#if REDIRECT
62
63/*
64 ============================================================================
65 _eredir(name) -- output I/O redirection error message to stderr
66 ============================================================================
67*/
68
69static
70_eredir(name)
71char *name;
72{
73 char buff[200];
74
75 strcpy(buff, "Can't open file for redirection: ");
76 strcat(buff, name);
77 strcat(buff, "\n");
78 write(2, buff, strlen(buff));
79 exit(EINVAL);
80}
81
82#endif
83
84/*
85
86*/
87
88/*
89 ============================================================================
90 Croot(cp) -- C root module for the Buchla 700
91 ============================================================================
92*/
93
94Croot(cp)
95register char *cp;
96{
97 register char *fname;
98 register int 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 */
124redir:
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
160#endif
161
162 main(Argc,Argv); /* call application */
163 exit(0); /* exit in case the application didn't */
164}
Note: See TracBrowser for help on using the repository browser.