source: buchla-68k/prolog/croot.c@ e225e77

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

Added missing includes and declarations.

  • Property mode set to 100644
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 int16_t open(int8_t *name, int16_t flag, int16_t mode);
30extern int16_t creat(int8_t *name, int16_t mode);
31
32extern void InitFS(void);
33extern void _fd_cls(void);
34extern void xtrap15(void);
35
36extern void main(void);
37
38int16_t (*_clsall)();
39
40/*
41
42*/
43
44static int16_t Argc;
45static int8_t *Argv[MAXARGS];
46
47/*
48
49*/
50
51/*
52 ============================================================================
53 exit() -- return control to the BIOS
54 ============================================================================
55*/
56
57void exit(void)
58{
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
72static
73_eredir(name)
74char *name;
75{
76 char buff[200];
77
78 strcpy(buff, "Can't open file for redirection: ");
79 strcat(buff, name);
80 strcat(buff, "\n");
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
94 ============================================================================
95*/
96
97void Croot(int8_t *cp)
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 */
126redir:
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 }
161
162#endif
163
164 main(); /* call application */
165 exit(); /* exit in case the application didn't */
166}
Note: See TracBrowser for help on using the repository browser.