-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcondrv.c
More file actions
132 lines (112 loc) · 6.13 KB
/
condrv.c
File metadata and controls
132 lines (112 loc) · 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**************************************************************************************************/
/* CONSOLE DRIVER */
/* */
/* Part of GCCLIB - VM/370 CMS Native Std C Library; A Historic Computing Toy */
/* */
/* Contributors: See contrib memo */
/* */
/* Released to the public domain. */
/**************************************************************************************************/
#include <cmsruntm.h>
#include <cmssys.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
/**************************************************************************************************/
/* open driver */
/* int open(char **filespecwords, int accessMode) */
/* returns 0 on error */
/* -1 if the driver does not support the filespec */
/* 1 success */
/**************************************************************************************************/
static int open(char filespecwords[][10], FILE *theFile) {
/* Am I the right driver? */
if (filespecwords[1][0]) return -1; /* More than one word - nothing to do with me! */
if (strcmp(filespecwords[0], "CONSOLE") &&
strcmp(filespecwords[0],
"+CONSOLE+") /* +CONSOLE+ is for stdin/out/err */
)
return -1; /* Nothing to do with me */
if (theFile->access & ACCESS_READWRITE) {
errno = EINVAL;
return 0;
}
if (strcmp(filespecwords[0],
"+CONSOLE+")) { /* We don't check for duplicates for +CONSOLE+ */
if (_isopen(filespecwords[0])) {
errno = EEXIST;
return 0;
}
}
theFile->filemaxreclen = 130;
theFile->maxreclen = 130;
theFile->buffer = malloc(theFile->filemaxreclen + 2); /* \n and NULL */
strcpy(theFile->name, filespecwords[0]);
strcpy(theFile->fileid, filespecwords[0]);
theFile->reclen = -1; /* Empty Buffer */
theFile->recpos = 0;
theFile->recnum = -1;
theFile->records = -1;
return 1;
}
/**************************************************************************************************/
/* close driver */
/* returns 0 on success */
/**************************************************************************************************/
static int close(FILE *file) {
if (file->buffer) {
free(file->buffer);
file->buffer = 0;
}
return 0;
}
/**************************************************************************************************/
/* write driver */
/* returns 0 on success */
/**************************************************************************************************/
static int write(FILE *file) {
file->buffer[file->reclen] = 0;
if (file->access & ACCESS_TEXT) CMSconsoleWrite(file->buffer, CMS_EDIT);
else
CMSconsoleWrite(file->buffer, CMS_NOEDIT);
file->recnum = -1;
/* Always returns zero */
return 0;
}
/**************************************************************************************************/
/* read (record) driver */
/**************************************************************************************************/
static int read(FILE *file) {
file->reclen = CMSconsoleRead(file->buffer);
file->recnum = -1;
return 0;
}
/**************************************************************************************************/
/* getpos driver */
/* returns position on success, -1 on error */
/**************************************************************************************************/
static int getpos(FILE *file) {
errno = EBADF;
return -1;
}
/**************************************************************************************************/
/* getend driver */
/* returns position on success, -1 on error */
/**************************************************************************************************/
static int getend(FILE *file) {
errno = EBADF;
return -1;
}
/**************************************************************************************************/
/* setpos driver */
/* returns position on success, -1 on error */
/**************************************************************************************************/
static int setpos(FILE *file, int pos) {
errno = EBADF;
return -1;
}
/**************************************************************************************************/
/* Driver Structure */
/**************************************************************************************************/
CMSDRIVER coniodrv = {open, close, getpos, getend, setpos, write, read, NULL};