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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
PACKET free channel DEFINES (* Autor: J.Liedtke *)
(* Stand: 10.06.86 *)
FCHANNEL ,
:= ,
free channel ,
open ,
close ,
out ,
in ,
dialogue ,
save ,
fetch :
LET ack = 0 ,
nak = 1 ,
error nak = 2 ,
empty message code = 256 ,
long message code = 257 ,
file send code = 1024 ,
file receive code = 2048 ,
open code = 1000 ,
close code = 1001 ,
file type = 1003 ;
INT CONST task not existing := - 1 ;
TYPE FCHANNEL = STRUCT (TASK server, TEXT input buffer, server name) ;
INT VAR message code , response code ;
TASK VAR partner ;
DATASPACE VAR ds ;
BOUND TEXT VAR msg ;
TEXT VAR response, char, esc char , record ;
FILE VAR file ;
OP := (FCHANNEL VAR dest, FCHANNEL CONST source) :
dest.server := source.server ;
dest.input buffer := "" ;
dest.server name := source.server name ;
open (dest)
ENDOP := ;
FCHANNEL PROC free channel (TEXT CONST channel name) :
FCHANNEL:(niltask,"", channel name)
ENDPROC free channel ;
PROC open (FCHANNEL VAR channel) :
INT VAR receipt ;
initialize message dataspace ;
send open code ;
IF receipt <> ack
THEN errorstop ("channel not free")
FI .
initialize message dataspace :
forget (ds) ;
ds := nilspace .
send open code :
ping pong (channel.server, open code, ds, receipt) ;
IF receipt = task not existing
THEN channel.server := task (channel.server name) ;
ping pong (channel.server, open code, ds, receipt)
FI .
ENDPROC open ;
PROC close (FCHANNEL VAR channel) :
forget (ds) ;
ds := nilspace ;
call (channel.server, close code, ds, response code)
ENDPROC close ;
PROC close (TEXT CONST channel server) :
forget (ds) ;
ds := nilspace ;
call (task (channel server), close code, ds, response code)
ENDPROC close ;
PROC out (FCHANNEL VAR channel, TEXT CONST message) :
send message ;
get response .
send message :
IF message = ""
THEN call (channel.server, empty message code, ds, response code)
ELSE msg := ds ;
CONCR (msg) := message ;
call (channel.server, long message code, ds, response code)
FI .
get response :
IF response code < 0
THEN errorstop ("channel not ready")
ELIF response code < 256
THEN channel.input buffer CAT code (response code)
ELIF response code = long message code
THEN msg := ds ;
channel.input buffer CAT CONCR (msg)
FI .
ENDPROC out ;
PROC in (FCHANNEL VAR channel, TEXT VAR response) :
out (channel, "") ;
response := channel.input buffer ;
channel.input buffer := ""
ENDPROC in ;
PROC save (FCHANNEL VAR channel, TEXT CONST file name, control chars) :
prepare ds ;
call (channel.server, file send code, ds, response code) ;
IF response code = error nak
THEN BOUND TEXT VAR error msg := ds ;
errorstop (error msg)
FI .
prepare ds :
forget (ds) ;
ds := old (file name, file type) ;
FILE VAR f := sequential file (modify, ds) ;
headline (f, control chars) .
ENDPROC save ;
PROC fetch (FCHANNEL VAR channel, TEXT CONST file name, control chars) :
IF NOT exists (file name) COR yes ("""" + file name + """ loeschen")
THEN fetch first part ;
WHILE more to fetch REP
fetch next part
PER
FI .
fetch first part :
INT VAR part := 0 ;
receive file (channel, file name, control chars) .
fetch next part :
part INCR 1 ;
receive file (channel, file name + "." + text (part), control chars) .
more to fetch : response code = file receive code .
ENDPROC fetch ;
PROC receive file (FCHANNEL VAR channel,TEXT CONST file name, control chars):
prepare ds ;
call (channel.server, file receive code, ds, response code);
IF response code = error nak
THEN BOUND TEXT VAR error msg := ds ;
errorstop (error msg)
ELSE forget (file name, quiet) ;
copy (ds, file name) ;
forget (ds) ;
ds := nilspace ;
FI .
prepare ds :
forget (ds) ;
ds := nilspace ;
BOUND TEXT VAR ctl := ds ;
ctl := control chars .
ENDPROC receive file ;
PROC dialogue (FCHANNEL CONST channel, TEXT CONST esc) :
forget (ds) ;
ds := nilspace ;
partner := channel.server ;
esc char := esc ;
enable stop ;
response code := empty message code ;
REP
get and send message charety ;
out response option
PER .
get and send message charety :
IF response code = empty message code
THEN char := incharety (10)
ELSE char := incharety
FI ;
IF char = ""
THEN call (partner, empty message code, ds, response code)
ELIF char = esc char
THEN LEAVE dialogue
ELSE call (partner, code (char), ds, response code)
FI .
out response option :
IF response code < 256
THEN out (code (response code))
ELIF response code = long message code
THEN msg := ds ;
out (CONCR (msg))
FI .
ENDPROC dialogue ;
PROC free channel (INT CONST nr) :
INT CONST my channel := nr ;
break ;
disable stop ;
REP
wait (ds, message code, partner) ;
IF message code = open code
THEN connect to my channel ;
use channel ;
break (quiet)
ELIF message code >= 0
THEN send (partner, nak, ds)
FI
PER .
use channel :
ping pong (partner, ack, ds, message code) ;
WHILE message code <> close code AND message code >= 0 REP
IF message code <= long message code THEN dialogue
ELIF message code = file receive code THEN receive file
ELIF message code = file send code THEN send file
ELIF message code = open code THEN ignore open
ELSE errorstop ("falsche Sendung")
FI
UNTIL is error PER ;
IF is error
THEN send error message
ELSE send handshake ack
FI .
dialogue :
IF message code < 256
THEN out (code (message code))
ELIF message code = long message code
THEN msg := ds ;
out (CONCR (msg))
FI ;
response := incharety (1) ;
IF response = ""
THEN ping pong (partner, empty message code, ds, message code)
ELSE short or long response
FI .
short or long response :
char := incharety ;
IF char = ""
THEN short response
ELSE long response
FI .
short response :
ping pong (partner, code (response), ds, message code) .
long response :
msg := ds ;
response CAT char ;
msg := response ;
REP
cat input (msg, char) ;
msg CAT char
UNTIL char = "" OR LENGTH msg > 500 PER ;
ping pong (partner, long message code, ds, message code) .
connect to my channel :
continue (my channel) ;
WHILE is error REP
clear error ;
pause (100) ;
continue (my channel)
PER .
send handshake ack :
send (partner, ack, ds) .
send error message :
forget (ds) ;
ds := nilspace ;
BOUND TEXT VAR error msg := ds ;
error msg := error message ;
clear error ;
send (partner, error nak, ds) .
ignore open :
ping pong (partner, ack, ds, message code) .
ENDPROC free channel ;
PROC send file :
enable stop ;
file := sequential file (input,ds) ;
get control chars ;
skip chars ;
REP
getline (file, record) ;
out (record) ;
end of line
UNTIL eof (file) PER ;
end of transmission ;
send ack reply .
get control chars :
TEXT CONST
control chars := headline (file) ,
end of file char := control chars SUB 1 ,
end of line char := control chars SUB 2 ,
handshake char := control chars SUB 3 .
end of line :
out (end of line char) ;
IF handshake char <> ""
THEN wait for handshake
FI .
wait for handshake :
REP
char := incharety (300) ;
IF char = ""
THEN errorstop ("timeout")
FI
UNTIL char = handshake char PER .
end of transmission :
skip chars ;
out (end of file char) .
skip chars :
WHILE incharety (3) <> "" REP PER .
send ack reply :
forget (ds) ;
ds := nilspace ;
ping pong (partner, ack, ds, message code) .
ENDPROC send file ;
PROC receive file :
enable stop ;
get control chars ;
open file ;
INT VAR line no := 0 ;
REP
receive line ;
IF eof received
THEN ping pong (partner, ack, ds, message code) ;
LEAVE receive file
FI ;
putline (file, record) ;
line no INCR 1
UNTIL near file overflow PER ;
ping pong (partner, file receive code, ds, message code) .
get control chars :
BOUND TEXT VAR control chars := ds ;
TEXT CONST
end of file char := control chars SUB 1 ,
end of line char := control chars SUB 2 ,
handshake char := control chars SUB 3 ,
handshake prompt := control chars SUB 4 .
open file :
forget (ds) ;
ds := nilspace ;
file := sequential file (output, ds) .
receive line :
record := "" ;
REP
cat input (record, char) ;
IF char = ""
THEN wait for char
FI ;
IF char = handshake prompt THEN out (handshake char)
ELIF char = ""9"" THEN expand tabs
ELIF char = ""12"" THEN page
FI
UNTIL char = end of line char OR char = end of file char PER .
wait for char :
char := incharety (300) ;
IF char = ""
THEN errorstop ("timeout")
ELIF char >= ""32""
THEN record CAT char
FI .
expand tabs:
record CAT (8-(LENGTH record MOD 8)) * " " .
page:
record := "#page# " .
eof received :
char = end of file char OR (record SUB LENGTH record ) = end of file char .
near file overflow :
line no > 3999 OR (line no > 3800 AND record = "#page# ") .
ENDPROC receive file ;
ENDPACKET free channel ;
|