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

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

Added include files for global functions and variables.

  • Property mode set to 100644
File size: 3.3 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 "all.h"
20
21#define REDIRECT 0 /* non-zero for command line stuff */
22
23#define MAXARGS 30 /* maximum number of command line arguments */
24
25extern int16_t open(int8_t *name, int16_t flag, int16_t mode);
26extern int16_t creat(int8_t *name, int16_t mode);
27
28extern void InitFS(void);
29extern void _fd_cls(void);
30extern void xtrap15(void);
31
32extern void main(void);
33
34int16_t (*_clsall)();
35
36/*
37
38*/
39
40static int16_t Argc;
41static int8_t *Argv[MAXARGS];
42
43/*
44
45*/
46
47/*
48 ============================================================================
49 exit() -- return control to the BIOS
50 ============================================================================
51*/
52
53void exit(void)
54{
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
68static
69_eredir(name)
70char *name;
71{
72 char buff[200];
73
74 strcpy(buff, "Can't open file for redirection: ");
75 strcat(buff, name);
76 strcat(buff, "\n");
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
90 ============================================================================
91*/
92
93void Croot(int8_t *cp)
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 */
122redir:
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 }
157
158#endif
159
160 main(); /* call application */
161 exit(); /* exit in case the application didn't */
162}
163
Note: See TracBrowser for help on using the repository browser.