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

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

Point of no return.

  • 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 "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(char *name, int flag, int mode);
30extern int creat(char *name, int mode);
31
32extern void InitFS(void);
33extern void _fd_cls(void);
34extern void xtrap15(void);
35
36int (*_clsall)();
37
38/*
39
40*/
41
42static int Argc;
43static char *Argv[MAXARGS];
44
45/*
46
47*/
48
49/*
50 ============================================================================
51 exit() -- return control to the BIOS
52 ============================================================================
53*/
54
55void exit(void)
56{
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
70static
71_eredir(name)
72char *name;
73{
74 char buff[200];
75
76 strcpy(buff, "Can't open file for redirection: ");
77 strcat(buff, name);
78 strcat(buff, "\n");
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
92 ============================================================================
93*/
94
95void Croot(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(); /* exit in case the application didn't */
164}
Note: See TracBrowser for help on using the repository browser.