Repository navigation
Expand file tree
/
Copy pathpundrv.c
More file actions
131 lines (111 loc) · 6 KB
/
Copy pathpundrv.c
File metadata and controls
131 lines (111 loc) · 6 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
/**************************************************************************************************/
/* PUNCH 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], "PUNCH"))
return -1; /* Nothing to do with me */
if (_isopen("PUNCH")) {
errno = EEXIST;
return 0;
}
if (!(theFile->access & ACCESS_READ)) {
theFile->filemaxreclen = 80;
theFile->maxreclen = 80;
theFile->buffer = malloc(theFile->filemaxreclen + 2); /* \n and NULL */
strcpy(theFile->name, "PUNCH");
strcpy(theFile->fileid, "PUNCH");
theFile->recnum = -1;
theFile->records = -1;
} else {
errno = EINVAL;
return 0;
}
return 1;
}
/**************************************************************************************************/
/* close driver */
/* returns 0 on success */
/**************************************************************************************************/
static int close(FILE *file) {
if (file->buffer) {
free(file->buffer);
file->buffer = 0;
}
return CMScommand("CP CLOSE PUNCH", CMS_COMMAND);
}
/**************************************************************************************************/
/* write driver */
/* returns 0 on success */
/**************************************************************************************************/
static int write(FILE *file) {
file->recnum = -1;
if (file->reclen < file->filemaxreclen) { /* PAD */
memset(file->buffer + file->reclen, (int) ' ',
file->filemaxreclen - file->reclen);
file->reclen = file->filemaxreclen;
}
file->reclen = file->filemaxreclen;
file->error = CMScardPunch(file->buffer);
if (file->error != 0) {
errno = EIO;
return file->error;
}
return 0;
}
/**************************************************************************************************/
/* read (record) driver */
/**************************************************************************************************/
static int read(FILE *file) {
file->error = 9;
errno = EBADF;
return EOF;
}
/**************************************************************************************************/
/* 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 Strusture */
/**************************************************************************************************/
CMSDRIVER puniodrv = {open, close, getpos, getend, setpos, write, read, NULL};