-
Notifications
You must be signed in to change notification settings - Fork 19
/
wandsys.c
executable file
·125 lines (108 loc) · 2.24 KB
/
wandsys.c
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
#include <stdio.h>
#include "wanddef.h"
/*
** WANDSYS -- System dependent routines for Wander
** Interfaces to stdio routines to keep track of file position
** on V6 systems without tell().
** Copyright (c) by Peter S. Langston - New York, N.Y.
*/
/*#define NOFTELL /* uncomment this for systems without tell() */
#ifdef NOFTELL
static char *whatwand = "@(#)wandsys.c 1.1 WITHOUT FTELL() 2/22/84 -- (c) psl";
#else
static char *whatwand = "@(#)wandsys.c 1.1 with ftell() 2/22/84 -- (c) psl";
#endif
static char *wand_h = H_SCCS;
extern FILE *fpungot;
#ifdef NOFTELL
#define NUMWTELL 2
struct wtellstr {
FILE *wt_fp; /* associated file pointer */
long wt_addr; /* wtell() address */
} wt[NUMWTELL + 1];
#endif
FILE *
wopen(file, rwflg) /* interface to fopen */
char *file, *rwflg;
{
#ifdef NOFTELL
register int i;
FILE *fp;
if ((fp = fopen(file, rwflg)) != (FILE *) NULL) {
i = wtfind((FILE *) NULL);
wt[i].wt_fp = fp;
wt[i].wt_addr = 0L;
}
return(fp);
#else
return(fopen(file, rwflg));
#endif
}
wseek(fp, addr, mode) /* interface to fseek() */
FILE *fp;
long addr;
{
#ifdef NOFTELL
register int i;
i = wtfind(fp);
if (mode == 0)
wt[i].wt_addr = addr;
else if (mode == 1)
wt[i].wt_addr += addr;
else if (mode == 2)
printf("Illegal wseek(%d, %D, %d)\n", fp, addr, mode);
#endif
if (fpungot == fp)
fpungot = (FILE *) NULL;
return(fseek(fp, addr, mode));
}
wgetc(fp) /* interface to getc() */
FILE *fp;
{
#ifdef NOFTELL
register int i;
if (fp != stdin) {
i = wtfind(fp);
wt[i].wt_addr++;
}
#endif
return(getc(fp));
}
long
wtell(fp)
FILE *fp;
{
#ifdef NOFTELL
register int i;
if (fp == stdin)
return(0L);
i = wtfind(fp);
return(wt[i].wt_addr);
#else
extern long ftell();
return(ftell(fp));
#endif
}
wclose(fp) /* interface to fclose() */
FILE *fp;
{
#ifdef NOFTELL
register int i;
i = wtfind(fp);
#endif
if (fpungot == fp)
fpungot = (FILE *) NULL;
return(fclose(fp));
}
#ifdef NOFTELL
wtfind(fp) /* find record for specified file pointer */
FILE *fp;
{
register int i;
for (i = 0; i < NUMWTELL; i++)
if (fp == wt[i].wt_fp)
return(i);
printf("wtfind(%d): Couldn't find a record\n", fp);
return(NUMWTELL);
}
#endif