-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl-sun.p
10391 lines (9257 loc) · 303 KB
/
cl-sun.p
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
program curlew;
{ %% Source generation dated : Wed, 04 May 88 13:37:49 BST %%%%%%% }
{ ****************************************************** curlew ***** }
{ * * }
{ * C U R L E W * }
{ * * }
{ ******************************************************************* }
{ %%%%%% update %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% cl-sun %%%%% }
{ % % }
{ % Updated for the UNIX time-sharing system, release 4.2bsd % }
{ % running on a SUN workstation. % }
{ % UNIX is a trademark of A.T.&T. Bell Laboratories, U.S.A. % }
{ % % }
{ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
{ ****************************************************** curlew ***** }
{ * * }
{ * A portable full-screen editor intended for use over a data * }
{ * communications network. The full-screen user interface is * }
{ * derived from that of the old NUMAC Screen Editor, "sc". * }
{ * The network virtual terminal support is that of the "The * }
{ * Simple Screen Management Protocol" (United Kingdom Joint * }
{ * Network Team, July 1985). * }
{ * * }
{ * The context editor and file buffer management facilities * }
{ * provided were inspired by and are modelled on "edit", by * }
{ * B.W.Kernighan and P.J.Plauger. See the book "Software Tools * }
{ * in Pascal" (Addison-Wesley, 1981). * }
{ * * }
{ * Screen editor code, SSMP network virtual terminal support, * }
{ * and other extensions by Alan Hunter, Computing Laboratory, * }
{ * University of Newcastle upon Tyne. * }
{ * * }
{ * This is PUBLIC DOMAIN SOFTWARE, by which is meant that it * }
{ * may be copied and used by individuals or institutions but * }
{ * any rights of commercial exploitation are retained by the * }
{ * University of Newcastle upon Tyne. * }
{ * * }
{ * CURLEW screen editor and SSMP virtual terminal coding is * }
{ * copyright (1987) by the University of Newcastle upon Tyne. * }
{ * The original source of the Software Tools Pascal routines is * }
{ * copyright (1981) by Bell Telephone Laboratories, * }
{ * Incorporated, and Whitesmiths, Ltd. * }
{ * * }
{ ******************************************************************* }
const
{ ****************************************************** iso646 ***** }
{ * * }
{ * International Standard 646 character set * }
{ * * }
{ ******************************************************************* }
blank = 32;
{ numerics }
dig0 = 48; dig1 = 49; dig2 = 50; dig3 = 51; dig4 = 52;
dig5 = 53; dig6 = 54; dig7 = 55; dig8 = 56; dig9 = 57;
{ lower case alphabetics }
leta = 97; letb = 98; letc = 99; letd = 100; lete = 101;
letf = 102; letg = 103; leth = 104; leti = 105; letj = 106;
letk = 107; letl = 108; letm = 109; letn = 110; leto = 111;
letp = 112; letq = 113; letr = 114; lets = 115; lett = 116;
letu = 117; letv = 118; letw = 119; letx = 120; lety = 121;
letz = 122;
{ upper case alphabetics }
capa = 65; capb = 66; capc = 67; capd = 68; cape = 69;
capf = 70; capg = 71; caph = 72; capi = 73; capj = 74;
capk = 75; capl = 76; capm = 77; capn = 78; capo = 79;
capp = 80; capq = 81; capr = 82; caps = 83; capt = 84;
capu = 85; capv = 86; capw = 87; capx = 88; capy = 89;
capz = 90;
{ other graphic symbols }
exclam = 33; dquote = 34; sharp = 35; dollar = 36;
percent = 37; amper = 38; squote = 39; lparen = 40;
rparen = 41; star = 42; plus = 43; comma = 44;
minus = 45; period = 46; slash = 47; colon = 58;
semicol = 59; less = 60; equals = 61; greater = 62;
question = 63; atsign = 64; lbrack = 91; backslash = 92;
rbrack = 93; cflex = 94; uscore = 95; grave = 96;
lbrace = 123; bar = 124; rbrace = 125; tilde = 126;
{ control characters }
nul = 0;
ctla = 1; ctlb = 2; ctlc = 3; ctld = 4; ctle = 5;
ctlf = 6; ctlg = 7; ctlh = 8; ctli = 9; ctlj = 10;
ctlk = 11; ctll = 12; ctlm = 13; ctln = 14; ctlo = 15;
ctlp = 16; ctlq = 17; ctlr = 18; ctls = 19; ctlt = 20;
ctlu = 21; ctlv = 22; ctlw = 23; ctlx = 24; ctly = 25;
ctlz = 26;
esc = 27; fs = 28; gs = 29; rs = 30; us = 31;
del = 127;
{ ****************************************************** gblcons **** }
{ * * }
{ * Software Tools :: Global constants * }
{ * * }
{ ******************************************************************* }
isomax = 255; { ISO 4873 (646 is a subset) max value }
maxstr = 512; { maximum characters for chstring type }
endstr = nul; { end of string marked with nul }
newline = ctlj; { end of line marked with line feed }
tab = ctli; { tab marked with horizontal tab }
backspace = ctlh; { back space output device character }
endfile = ctly; { end of file marked with em }
maxpat = maxstr; { maximum characters in a pattern }
closize = 1; { size of a closure entry }
nccl = exclam; { negated class is "!" (can't be negate) }
litchar = plus; { literal character flagged by "+" }
mkditto = ctlz; { ditto marker in string is sub }
ioerror = -1; { file descriptor not available indicator }
iomaxfd = 19; { maximum available stream number }
ioread = 1; { open mode for reading }
iowrite = 2; { open mode for writing }
ioappend = 3; { open mode for writing, append to end }
iomddeflt = 0; { normal file descriptor state }
iomdasis = 1; { "as is" : packets ready to write }
iomdmsg = 2; { "message" : no native mode networking }
maxarg = 10; { maximum number of command arguments }
idef = 0; { o/s default interrupt processing }
imask = 1; { mask interrupts -> just continue }
ikill = 2; { interrupt -> kill application }
{ following are for use with "getinf" }
sfnpfx = 1; { scratch filename prefix }
cmdpars = 2; { command parameter string }
timedate = 3; { time and date, #822 format }
username = 4; { username }
maxframe = 5; { frames per packet in SSMP, nul -> 2 }
sortdate = 6; { time and date, sortable format }
gspare2 = 7; { (not in use) }
litfchar = 8; { literal file initial character }
ffcrtn = 9; { "y" means "ffcopy" routine available }
ixcrtn = 10; { "y" means "ixcopy" routine available }
{ ****************************************************** ssmpcons *** }
{ * * }
{ * SSMP shared data structure constants * }
{ * * }
{ ******************************************************************* }
zmaxrow = 59; { allows a maximum of 60 rows }
zmaxcol = 131; { allows a maximum of 132 columns }
isospace = blank; { to fit with The Book }
zfieldlimit = 239; { allows a maximum of 240 fields }
{ mode array }
tlevel = 0; tmaxrow = 1; tmaxcol = 2;
dsinvalid = 3; notify = 4; selectgr = 5;
reqshift = 6; cursor = 7; icharmode = 8;
ilinerow = 9; intsignal = 10; kinthost = 11;
ksuspend = 12; krestart = 13; kenter = 14;
kcsrup = 15; kcsrdown = 16; kcsrleft = 17;
kcsrright = 18; knexttab = 19; kprevtab = 20;
kleftupd = 21; kfirstns = 22; kalastns = 23;
kinsmode = 24; keraright = 25; kinsspac = 26;
kdelchar = 27; keraprev = 28; kinsline = 29;
kdelline = 30; keraline = 31; kappline = 32;
ksplline = 33; knextfld = 34; kprevfld = 35;
khomefld = 36; knewline = 37;
{ ****************************************************** ssmpcons *** }
{ * * }
{ * SSMP network encoding and transmission constants * }
{ * * }
{ ******************************************************************* }
defrend = 0; { selectgr : default rendition }
bold = 1; { selectgr : bold, or increased intensity }
faint = 2; { selectgr : faint, or reduced intensity }
italicised = 3; { selectgr : italicised, or slanted }
underlined = 4; { selectgr : underlined }
slowblink = 5; { selectgr : slowly blinking (less than 150/min) }
rapidblink = 6; { selectgr : rapidly blinking (150/min or more) }
negative = 7; { selectgr : negative image (reverse video) }
concealed = 8; { selectgr : concealed (displayed as SPACEs) }
crossedout = 9; { selectgr : crossed out (marked for deletion) }
maxmode = knewline; { maximum allocated mode index }
framesize = 60; { characters per SSMP frame output }
type
{ ****************************************************** gbltype **** }
{ * * }
{ * Software Tools :: Global type declarations * }
{ * * }
{ ******************************************************************* }
isochar = nul..isomax;
chstring = packed array [1..maxstr] of isochar;
tablist = array [1..maxstr] of boolean;
byte = 0..255;
itable = packed array [byte] of byte;
chtable = packed array [byte] of char;
textlit = packed array [1..24] of char;
filedesc = ioerror..iomaxfd;
fdpointer = integer;
{ ****************************************************** lunixtyp *** }
{ * * }
{ * SSMP shared data structure types -- local UNIX version * }
{ * * }
{ ******************************************************************* }
toktype = (withhost, withterm);
rowtype = 0..zmaxrow; { in use, 0..maxrow }
coltype = 0..zmaxcol; { in use, 0..maxcol }
imtype = array[rowtype,coltype] of isochar;
savedfield = { each stored field definition }
record
fldtop, fldbottom : rowtype; { stored update limit rows }
fldleft, fldright : coltype { stored update limit cols }
end;
fieldindex = 0..zfieldlimit; { in use, 0..((maxrow+1)*4-1) }
modeindex = 0..63; { 37 is highest defined index }
smallint = 0..255; { parameter range }
modearray = packed array [modeindex]
of smallint; { terminal emulation status }
tabstop = (notab, tabset); { tabulation stop }
{ ****************************************************** lssmptyp *** }
{ * * }
{ * SSMP network encoding and transmission types * }
{ * * }
{ ******************************************************************* }
charstr = packed array [1..16] of isochar;
charlen = 0..16;
netbuff = packed array [1..256] of isochar;
primpar = array [1..4] of smallint;
rowtext = array [coltype] of isochar;
ncftype = (nocf, csrpend, fldpend);
var
{ ****************************************************** gblvar ***** }
{ * * }
{ * Software Tools :: Global variable declarations * }
{ * * }
{ ******************************************************************* }
envlocn : integer; { environment location }
littoiso : itable; { native to iso code conversions }
isotolit : chtable; { iso to native code conversions }
stdin : filedesc; { standard input file descriptor }
stdout : filedesc; { standard output file descriptor }
stderror : filedesc; { standard error file descriptor }
initin, initout : filedesc; { initial standard input & output }
cmdline : chstring; { command argument text }
nbrcmdargs : integer; { number of command arguments }
cmdargidx : array [0..maxarg] of integer; { argument offsets }
scan : isochar; { forward scan character }
backscan : isochar; { backward scan character }
escape : isochar; { escape special meanings }
closure : isochar; { closure }
bol : isochar; { begining of line }
eol : isochar; { end of line }
any : isochar; { wildcard }
ccl : isochar; { character class start }
cclend : isochar; { ... and end }
negate : isochar; { class negation }
anycase : isochar; { case sensitivity toggle }
ditto : isochar; { ditto character }
cssinit : boolean; { pattern start anycase state }
{ ****************************************************** lunixvar *** }
{ * * }
{ * SSMP shared data structure variables -- local UNIX version * }
{ * * }
{ ******************************************************************* }
token : toktype; { access control token }
row : rowtype; { cursor row }
col : coltype; { cursor column }
image : imtype; { screen image }
curfield, maxfield : fieldindex;
field : array [fieldindex]
of savedfield; { stored field definitions }
boxtop, boxbottom : rowtype; { update limits - rows }
boxleft, boxright : coltype; { update limits - columns }
mode : modearray; { terminal emulation status }
tabs : array [coltype] of tabstop; { tabulation stops array }
{ ****************************************************** lssmpvar *** }
{ * * }
{ * SSMP local action virtual terminal variables * }
{ * * }
{ ******************************************************************* }
ssmplocn : integer; { network environment pointer }
masterlevel : smallint; { session level after negotiation }
repainted : boolean; { true if screen refreshed }
cfstate : ncftype; { setcursor/setfield optimisation }
escaped : boolean; { true if previous keystroke was ESC }
defer : boolean; { true to stop t-?s changing image }
nqueued : integer; { number of t-primitives on queue }
qpcode : array [1..8] of isochar; { primitive q : code }
qpar1 : array [1..8] of smallint; { primitive q : par one }
qpar2 : array [1..8] of smallint; { primitive q : par two }
filter : itable; { strip parity table }
#include "st.h"
{ ****************************************************** stprim ***** }
{ * * }
{ * Software Tools :: Initialisation routines * }
{ * * }
{ ******************************************************************* }
{ setctk -- initialise pattern matching chicken track characters }
procedure setctk (alternate : boolean);
begin
{ set up Software Tools values }
scan := slash; { forward scan is "/" }
backscan := backslash; { backward scan is "\" }
escape := atsign; { escape special meanings with "@" }
closure := star; { closure signalled by "*" }
bol := percent; { begining of line by "%" }
eol := dollar; { end of line by "$" }
any := question; { wildcard by "?" }
ccl := lbrack; { character class starts with "[" }
cclend := rbrack; { ... and ends with "]" }
negate := cflex; { class negation signalled by "^" }
anycase := tilde; { case sensitivity toggle is "~" }
ditto := amper; { ditto character is "&" }
cssinit := true; { case sensitive scan default }
{ check for UNIX (tm) values preferred }
if alternate then
begin
backscan := question; { backward scan is "?" }
escape := backslash; { escape special meanings with "\" }
bol := cflex; { begining of line by "^" }
any := period; { wildcard by "." }
anycase := tilde; { case sensitivity toggle is "~" }
ditto := amper; { ditto character is "&" }
end
end; {setctk}
{ setint -- select interrupt (BREAK key) processing }
procedure setint (intcode : integer);
begin
SINTRPT(envlocn, intcode); { 0 = default, 1 = mask, 2 = kill exec }
end; {setint}
{ initsoft -- initialise software tools environment }
procedure initsoft (intcode : integer);
begin
{ initialise software tools environment, get translate tables }
SGETSTE(envlocn, littoiso, isotolit);
if intcode > 0 then
setint(intcode); { 1 = mask, 2 = kill exec }
stdin := 0; { standard input }
stdout := 1; { standard output }
stderror := 2; { standard error }
initin := stdin; initout := stdout; { save values }
nbrcmdargs := 0; { no command arguments yet }
cmdargidx[1] := 1; { ... keeps some compilers happy }
setctk(false) { set up chicken tracks }
end; {initsoft}
{ closesoft -- release resources for software tools environment }
procedure closesoft;
begin
SRELSTE(envlocn, 0) { return after clean up }
end; {closesoft}
{ errorexit -- emergency, stop program now }
procedure errorexit;
begin
SRELSTE(envlocn, 1) { don't return here ... }
end; {errorexit}
{ ****************************************************** stprim ***** }
{ * * }
{ * Software Tools :: Primitives * }
{ * * }
{ ******************************************************************* }
{ %% next routine name changed from "open" to avoid symbol clash }
{ openf -- open a file for reading or writing }
function openf (var name : chstring;
openmode : integer)
: filedesc;
var
fd : filedesc;
begin
SOPEN(envlocn, name, openmode, fd);
openf := fd
end; {openf}
{ create -- open a file for reading or writing, create if necessary }
function create (var name : chstring;
openmode : integer)
: filedesc;
var
fd : filedesc;
begin
SCREATE(envlocn, name, openmode, fd);
create := fd
end; {create}
{ iocontrol -- set state of opened file descriptor }
procedure iocontrol (newstate : integer;
fd : filedesc);
begin
SIOCTRL(envlocn, newstate, fd)
end; {iocontrol}
{ secure -- secure disk copy of opened file without closing it }
procedure secure (fd : filedesc);
begin
SSECURE(envlocn, fd)
end; {secure}
{ %% next routine name changed from "rewind" to avoid symbol clash }
{ rewindf -- rewind (read) or reset (write, append) file desc }
function rewindf (fd : filedesc)
: boolean;
var
rc : integer;
begin
SREWIND(envlocn, fd, rc);
rewindf := (rc = 0)
end; {rewindf}
{ %% next routine name changed from "close" to avoid symbol clash }
{ closef -- close a stream after input or output }
procedure closef (fd : filedesc);
begin
SCLOSE(envlocn, fd)
end; {closef}
{ remove -- remove (destroy) file }
function remove (var name : chstring)
: boolean;
var
rc : integer;
begin
SREMOVE(envlocn, name, rc);
remove := (rc = 0)
end; {remove}
{ %% next routine name changed from "rename" to avoid symbol clash }
{ renamf -- change name of file oldname to newname }
function renamf (var oldname : chstring;
var newname : chstring)
: boolean;
var
rc : integer;
begin
SRENAME(envlocn, oldname, newname, rc);
renamf := (rc = 0)
end; {renamf}
{ getline -- read one complete input record from stream fd }
function getline (var dest : chstring;
fd : filedesc;
maxlen : integer)
: boolean;
var
rc : integer;
begin
SGETLIN(envlocn, dest, fd, maxlen, rc);
getline := (rc = 0)
end; {getline}
{ getcf -- read one character from stream fd }
function getcf (var c : isochar;
fd : filedesc)
: isochar;
begin
SGETCF(envlocn, c, fd);
getcf := c
end; {getcf}
{ putstr -- write string src to file descriptor fd }
procedure putstr (var src : chstring;
fd : filedesc);
begin
SPUTSTR(envlocn, src, fd)
end; {putstr}
{ putcf -- put character c to file descriptor fd }
procedure putcf (c : isochar;
fd : filedesc);
begin
SPUTCF(envlocn, c, fd)
end; {putcf}
{ ffcopy -- copy from one file descriptor to another }
function ffcopy (fdin : filedesc;
fdout : filedesc;
var nrecds : integer)
: boolean;
var
rc : integer;
begin
SFFCOPY(envlocn, fdin, fdout, nrecds, rc);
if rc < 0 then nrecds := -nrecds; { truncation flag }
ffcopy := (rc <= 0)
end; {ffcopy}
{ ixcopy -- copy specified record from one f/d to another }
function ixcopy (fdx : fdpointer;
fdin : filedesc;
fdout : filedesc)
: boolean;
var
rc : integer;
begin
SIXCOPY(envlocn, fdx, fdin, fdout, rc);
ixcopy := (rc = 0)
end; {ixcopy}
{ getindex -- returns next get/put index for future seek }
function getindex (var fdidx : fdpointer;
fd : filedesc)
: boolean;
var
rc : integer;
begin
SGETIDX(envlocn, fdidx, fd, rc);
getindex := (rc = 0)
end; {getindex}
{ seek -- set next read pointer for fd }
procedure seek (fdidx : fdpointer;
fd : filedesc);
begin
SSEEK(envlocn, fdidx, fd)
end; {seek}
{ itoxpc -- internal to external file pointer conversion }
procedure itoxpc (var str : chstring;
sidx : integer;
fdx : fdpointer);
begin
SITOXPC(envlocn, str, sidx, fdx)
end; {itoxpc}
{ xtoipc -- external to internal file pointer conversion }
procedure xtoipc (var str : chstring;
sidx : integer;
var fdx : fdpointer);
begin
SXTOIPC(envlocn, str, sidx, fdx)
end; {xtoipc}
{ getfds -- get file descriptor status }
procedure getfds (var fdstat : integer;
fd : filedesc);
begin
SGETFDS(envlocn, fdstat, fd)
end; {getfds}
{ prompt -- set standard input prompt string }
procedure prompt (var pstr : chstring);
begin
SPROMPT(envlocn, pstr)
end; {prompt}
{ getinf -- return information according to index }
procedure getinf (index : integer;
var info : chstring;
maxlen : integer);
begin
SGETINF(envlocn, index, info, maxlen)
end; {getinf}
{ syscmd -- execute command line }
procedure syscmd (var newcmd : chstring;
var rc : integer);
begin
SSYSCMD(envlocn, newcmd, rc)
end; {syscmd}
{ mailer -- interface to e-mail spooler }
function mailer (index : integer;
var info : chstring)
: boolean;
var
rc : integer;
begin
SMAILER(envlocn, index, info, rc);
mailer := (rc = 0)
end; {mailer}
{ timewait -- wait for a given elapsed time interval }
procedure timewait (waittime : integer);
begin
STWAIT(envlocn, waittime)
end; {timewait}
{ loguse -- log use of software tools application }
procedure loguse (var name : chstring);
begin
SLOGUSE(envlocn, name);
end; {loguse}
#include "tp.h"
{ ****************************************************** lunixrtn *** }
{ * * }
{ * SSMP :: UNIX local action virtual terminal service routines * }
{ * * }
{ ******************************************************************* }
{ ****************************************************** lssmprtn *** }
{ * * }
{ * All SSMP service procedures are defined here. If this * }
{ * section is split into a separate module, the procedures and * }
{ * functions listed in the following explanatory text will * }
{ * need to be exported. Variables defined as "Shared data * }
{ * structure" or "Network encoding and transmission" are * }
{ * required by these SSMP routines only. * }
{ * * }
{ ******************************************************************* }
{ ****************************************************** lssmprtn *** }
{ * * }
{ * General description of the SSMP host routines * }
{ * --------------------------------------------- * }
{ * * }
{ * The following procedures service requests to generate the * }
{ * equivalent host primitives. With the exception of * }
{ * "reqtoken", they should only be called whilst the token is * }
{ * with the host application. * }
{ * * }
{ * Note that optimisation of H-SETCURSOR and H-SETFIELD is * }
{ * performed automatically. Only essential instances will be * }
{ * generated. * }
{ * * }
{ * textchar : H-CHARACTER to send text * }
{ * sendtoken : H-TOKEN to transfer token * }
{ * setcursor : H-SETCURSOR to set the cursor position * }
{ * setmode : H-SETMODE to set a mode array element value * }
{ * erasetoright : H-ERASETORIGHT to erase to end of row * }
{ * insertspace : H-INSERTSPACE to insert SPACE characters * }
{ * deletechar : H-DELETECHAR to delete characters * }
{ * soundalarm : H-SOUNDALARM to sound the audible alarm * }
{ * scrollup : H-SCROLLUP to scroll rows up * }
{ * scrolldown : H-SCROLLDOWN to scroll rows down * }
{ * erasedisplay : H-ERASEDISPLAY to erase screen image * }
{ * erasefields : H-ERASEFIELDS to erase all field defns * }
{ * setfield : H-SETFIELD to select new field definition * }
{ * setupdate : H-SETUPDATE to set update limits for field * }
{ * erasetabs : H-ERASETABS to erase all tabulation stops * }
{ * settab : H-SETTAB to set one tabulation stop * }
{ * session : H-SESSION to enter or exit session * }
{ * reqtoken : H-REQTOKEN to request early return of token * }
{ * * }
{ * The following procedures allow interrogation of the shared * }
{ * data structure variables. Use of functions and procedures * }
{ * for this purpose hides the data from the application so that * }
{ * all assignments are under the control of procedures in the * }
{ * SSMP module and can be vetted. The data returned for each * }
{ * procedure is: * }
{ * * }
{ * maxrow : session maximum row value * }
{ * maxcol : session maximum column value * }
{ * fieldlimit : session maximum field index * }
{ * getloc : current cursor position row and column * }
{ * getfield : current field index * }
{ * getmode : a copy of the mode array * }
{ * getrow : the text of the requested row * }
{ * * }
{ * The next two procedures are to allow convenient replacement * }
{ * of shared data structure values. * }
{ * * }
{ * putmode : makes mode array conform to that supplied * }
{ * putrow : replaces the text for the specified row * }
{ * * }
{ * Note that "putmode" will issue only those H-SETMODEs required * }
{ * to correct the mode array. A convenient way of quickly * }
{ * switching terminal operating modes is to keep a suitable copy * }
{ * of the mode array for each set required and use "putmode" to * }
{ * establish that state from any other. * }
{ * * }
{ * The second procedure, "putrow", will optimise generation of * }
{ * the required host primitives. It will use H-SETCURSOR to * }
{ * skip ten or more consecutive blanks where this is possible * }
{ * (that is, either default rendition set or mode[reqshift]=1). * }
{ * * }
{ * If the application requires to refresh the terminal copy of * }
{ * the shared data structure, the following procedure will do * }
{ * this. Note that since the graphic rendition of each * }
{ * character is not held in the data structure, any highlighting * }
{ * will be lost and must be separately re-established if * }
{ * required. * }
{ * * }
{ * refresh : refreshes the whole shared data structure * }
{ * * }
{ * The following procedures wrap up the session entry * }
{ * negotiation and the recommended generation of primitives at * }
{ * session close. * }
{ * * }
{ * startssmp : negotiate session start with terminal * }
{ * stopssmp : tidy up and close down session * }
{ * * }
{ * The key to use of the whole SSMP module is the last * }
{ * primitive: * }
{ * * }
{ * getprimitive : process input until primitive decoded * }
{ * * }
{ * This function should be repeatedly called to fetch each * }
{ * primitive from the terminal. Input frames will be fetched * }
{ * automatically as required. Each call returns exactly one * }
{ * terminal-generated primitive decoded into the primitive * }
{ * identifier and parameters. The primitive may be processed as * }
{ * appropriate. Only T-TOKEN must be processed, and only in * }
{ * response to this primitive may host primitives other than * }
{ * H-REQTOKEN be generated. * }
{ * * }
{ * When each primitive is presented by "getprimitive" the host * }
{ * copy of the shared data structure will already have been * }
{ * updated. The parser calls the relevant T-primitive semantic * }
{ * routine to perform this action before returning control. * }
{ * Calls to "getloc", "getfield", "getmode" and "getrow" at this * }
{ * point will therefore return correct values. * }
{ * * }
{ * The semantic routine called on recognition of T-TOKEN checks * }
{ * mode[TLEVEL] and mode[DSINVALID] for values consistent with * }
{ * the current SSMP session. If they are not consistent, the * }
{ * values are corrected and "refresh" is called to correct the * }
{ * terminal. On being presented with T-TOKEN, the application * }
{ * is freed from the necessity of checking session integrity and * }
{ * may act on the request code as appropriate. * }
{ * * }
{ * The master session level will be taken from the first * }
{ * T-SETMODE setting it. Note that it is the responsibility of * }
{ * the host application calling "getprimitive" to check the * }
{ * screen dimensions offered. This should be done at the first * }
{ * T-TOKEN; if the values are unsuitable a suitable text message * }
{ * should be output and "stopssmp" called. * }
{ * * }
{ ******************************************************************* }
{ initcoding -- initialise tables for SSMP primitive processing }
procedure initcoding;
var
j : smallint;
begin
{ i/o system and session initialisation }
masterlevel := 0;
cfstate := nocf;
repainted := false;
escaped := false;
defer := false;
nqueued := 0;
{ input filter table to strip parity }
for j := 0 to 127 do
begin
filter[j] := j;
filter[j+128] := j
end
end; {initcoding}
{ initshared -- initialise our copy of the shared data structure }
procedure initshared;
var
fidx : fieldindex;
trow : rowtype;
tcol : coltype;
midx : modeindex;
begin
token := withhost;
row := 0; col := 0;
{ stored field definitions }
for fidx := 0 to zfieldlimit do
with field[fidx] do
begin
fldtop := 0; fldbottom := 0;
fldleft := 0; fldright := 0;
end;
curfield := 0; maxfield := 0;
{ update limits }
boxtop := 0; boxbottom := 0;
boxleft := 0; boxright := 0;
{ mode array }
for midx := 0 to 63 do
mode[midx] := 0;
{ tabulation stops array}
for tcol := 0 to zmaxcol do
tabs[tcol] := notab;
{ not true ssmp, but assign all elements of the screen array
to avoid upsetting Pascal run time checking routines }
for trow := 0 to zmaxrow do
for tcol := 0 to zmaxcol do
image[trow,tcol] := grave
end; {initshared}
{ cftest -- issues pending H-SETCURSOR or H-SETFIELD as necessary }
procedure cftest (newcfstate : ncftype);
begin
if newcfstate <> cfstate then
begin
case cfstate of
nocf:
;
csrpend:
USETCURSOR(row, col);
fldpend:
USETCURSOR(row, col);
end; {case}
cfstate := newcfstate
end
end; {cftest}
{ maxrow -- returns current session maximum row value }
function maxrow : rowtype;
begin
maxrow := mode[tmaxrow]
end; {maxrow}
{ maxcol -- returns current session maximum column value }
function maxcol : coltype;
begin
maxcol := mode[tmaxcol]
end; {maxcol}
{ fieldlimit -- returns current session maximum field index }
function fieldlimit : fieldindex;
begin
fieldlimit := ((maxrow + 1) * 4) - 1
end; {fieldlimit}
{ eraserow -- erase part of one row to SPACE characters }
procedure eraserow (rowa : rowtype;
cola : coltype;
colb : coltype);
var
ctemp : coltype;
begin
for ctemp := cola to colb do
image[rowa,ctemp] := isospace;
UERASEROW(rowa, cola, colb);
USETCURSOR(row, col);
end; {eraserow}
{ erasebox -- erase a rectangle of positions to SPACE characters }
procedure erasebox (rowa : rowtype;
rowb : rowtype;
cola : coltype;
colb : coltype);
var
rtemp : rowtype;
begin
for rtemp := rowa to rowb do
eraserow(rtemp, cola, colb)
end; {erasebox}
{ rowcopy -- copy part of row to same column range of another row }
procedure rowcopy (rowa : rowtype;
rowb : rowtype;
cola : coltype;
colb : coltype);
var
ctemp : coltype;
begin
for ctemp := cola to colb do
image[rowb,ctemp] := image[rowa,ctemp];
UROWCOPY(rowa, rowb, cola, colb);
USETCURSOR(row, col);
end; {rowcopy}
{ rightshift -- shift row characters to right within column range }
procedure rightshift (rowa : rowtype;
cola : coltype;
colb : coltype;
ncols : smallint);
var
ctemp : coltype;
begin
if (colb - cola) < ncols then
eraserow(rowa, cola, colb)
else
begin
URIGHTSHIFT(rowa, cola, colb, ncols);
for ctemp := colb - ncols downto cola do
image[rowa,ctemp+ncols] := image[rowa,ctemp];