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
133
134
135
136
137
138
139
140
141
142
|
include <fset.h>
# T_TEST2 -- Test Doug's idea of how to access a piece of memory as a
# binary file using the pushback technique. This works but is a bit
# inefficient.
procedure t_test2()
pointer inbuf, outbuf
int i, fd, nchars, ntimes
int open(), read()
begin
# Allocate a char array.
call malloc (inbuf, 1000, TY_CHAR)
call malloc (outbuf, 200, TY_CHAR)
do i = 1, 1000
Memc[inbuf+i-1] = i
# Open char array as a binary file.
fd = open ("dev$null", READ_ONLY, BINARY_FILE)
call fseti (fd, F_PBBSIZE, 1008)
call unread (fd, Memc[inbuf], 1000)
# Try to read the data.
ntimes = 1
nchars = read (fd, Memc[outbuf], 200)
while (nchars != EOF) {
call printf ("ntimes=%d nchars=%d firstchar = %d\n")
call pargi (ntimes)
call pargi (nchars)
call pargi (int(Memc[outbuf]))
nchars = read (fd, Memc[outbuf], 200)
ntimes = ntimes + 1
}
call close (fd)
# Free char array.
call mfree (inbuf, TY_CHAR)
call mfree (outbuf, TY_CHAR)
end
# T_TEST3 -- Test Doug's idea of how to access a piece of memory as a
# binary file using the spool file technique. This works but is still a bit
# inefficient.
procedure t_test3()
pointer inbuf, outbuf
int i, fd, ntimes, nchars
int open(), read()
begin
# Allocate a char array.
call malloc (inbuf, 1000, TY_CHAR)
call malloc (outbuf, 200, TY_CHAR)
do i = 1, 1000
Memc[inbuf+i-1] = i
# Open char array as a binary file.
fd = open ("dev$null", READ_WRITE, SPOOL_FILE)
call write (fd, Memc[inbuf], 1000)
call seek (fd, BOF)
# Try to read the data.
ntimes = 1
nchars = read (fd, Memc[outbuf], 200)
while (nchars != EOF) {
call printf ("ntimes=%d nchars=%d firstchar = %d\n")
call pargi (ntimes)
call pargi (nchars)
call pargi (int(Memc[outbuf]))
nchars = read (fd, Memc[outbuf], 200)
ntimes = ntimes + 1
}
call close (fd)
# Free char array.
call mfree (inbuf, TY_CHAR)
call mfree (outbuf, TY_CHAR)
end
# T_TEST5 -- Test Doug's idea of how to access a piece of memory as a
# text file using the spool file technique. This works but is still a bit
# inefficient.
procedure t_test5()
pointer inbuf, outbuf
int i, fd, ntimes, nchars
long note()
int open(), getline()
begin
# Allocate a char array.
call malloc (inbuf, 1000, TY_CHAR)
call malloc (outbuf, 200, TY_CHAR)
do i = 1, 200
Memc[inbuf+i-1] = 'a'
Memc[inbuf+199] = '\n'
do i = 201, 400
Memc[inbuf+i-1] = 'b'
Memc[inbuf+399] = '\n'
do i = 401, 600
Memc[inbuf+i-1] = 'c'
Memc[inbuf+599] = '\n'
do i = 601, 800
Memc[inbuf+i-1] = 'd'
Memc[inbuf+799] = '\n'
do i = 801, 1000
Memc[inbuf+i-1] = 'e'
Memc[inbuf+999] = '\n'
# Open char array as a binary file.
fd = open ("dev$null", READ_WRITE, SPOOL_FILE)
call write (fd, Memc[inbuf], 1000)
call seek (fd, BOF)
# Try to read the data.
ntimes = 1
#nchars = read (fd, Memc[outbuf], 200)
nchars = getline (fd, Memc[outbuf])
while (nchars != EOF) {
call printf ("ntimes=%d nchars=%d firstchar = %c seek=%d\n")
call pargi (ntimes)
call pargi (nchars)
call pargc (Memc[outbuf])
call pargl (note(fd))
#nchars = read (fd, Memc[outbuf], 200)
nchars = getline (fd, Memc[outbuf])
ntimes = ntimes + 1
}
call close (fd)
# Free char array.
call mfree (inbuf, TY_CHAR)
call mfree (outbuf, TY_CHAR)
end
|