home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
TPKERMIT
/
CONNECT.PAS
next >
Wrap
Pascal/Delphi Source File
|
1987-03-25
|
15KB
|
329 lines
(* +FILE+ CONNECT.PASVT100 *)
(* ================================================================== *)
(* Global Var and Procedures for special key specifications. *)
(* ================================================================== *)
Const
Gversion = ' ' ;
TermType = ' VT100 ' ;
graph = '- Not applicable ' ;
Var
EscSeq : Array [1..$88,1..2] of char ;
KeyTableName : String[14] ;
KeyTable : Text ;
(*------------------------------------------------------------------- *)
Function hexinteger (chars : string2): byte ;
begin (* HexInteger *)
If chars[1] in ['A'..'F'] then chars[1]:=chr(ord(chars[1])+9);
If chars[2] in ['A'..'F'] then chars[2]:=chr(ord(chars[2])+9);
hexinteger := (ord(chars[1]) shl 4) + (ord(chars[2]) and $0F) ;
end ; (* HexInteger *)
(*------------------------------------------------------------------- *)
Procedure ReadKeytable ;
var I : integer ;
Newname : string[15] ;
comment : string[80] ;
label retry ;
Begin (* ReadKeytable *)
keytablename := 'KEYTABLE.DAT' ;
Assign(keytable,keytablename) ;
retry :
{$I-} Reset(keytable); {$I+}
If IORESULT = 0 then
Begin (* Initiate key table *)
For i := 1 to $88 do
Begin (* init EscSeq table *)
Readln(KeyTable,EscSeq[i,1],EscSeq[i,2],comment) ;
If copy(comment,2,2) <> ' ' then
EscSeq[i,1] := Chr(HexInteger(copy(comment,2,2))) ;
If copy(comment,4,2) <> ' ' then
EscSeq[i,2] := Chr(HexInteger(copy(comment,4,2))) ;
End ; (* init EscSeq table *)
Close(keytable);
End (* Initiate key table *)
else
Begin (* Warning *)
ClrScr ;
Writeln('*** File ',Keytablename,' not found on drive.');
Writeln(' Please specify drive or new name of keytable file. ');
Readln(newname);
If Length(Newname) = 1 then
keytablename := Newname + ':' + keytablename
else
keytablename := Newname ;
Assign(keytable,keytablename);
If length(keytablename)<3 then Running := false
else Goto Retry ;
End ; (* Warning *)
End ; (* ReadKeytable *)
const
APLTABLE : array [0..127] of byte =
{00} ($00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$0C,$0D,$0E,$0F, {0F}
{01} $10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$1A,$1B,$1C,$1D,$1E,$1F, {1F}
{02} $20,$05,$29,$3C,$F3,$3D,$3E,$5D,$FA,$5E,$86,$F6,$2C,$2B,$2E,$2F, {1F}
{03} $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$28,$5B,$3B,$78,$3A,$5C, {3F}
{04} $FD,$E0,$E6,$EF,$8F,$EE,$5F,$EC,$91,$E2,$F8,$27,$95,$FE,$E7,$F9, {4F}
{05} $2A,$3F,$FB,$8D,$7E,$19,$FC,$17,$0E,$18,$0B,$1B,$1D,$1A,$F2,$2D, {5F}
{06} $40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$4A,$4B,$4C,$4D,$4E,$4F, {6F}
{07} $50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$5A,$7B,$1C,$7D,$24,$2D); {7F}
Over1 = 'T('#$E5'T)'#$EA'GM'#$1F'HM'#$1E'OM'#$E8'O?'#$ED'O_'#$E9'OP'#$0F ;
Over2 = 'BN'#$15'GT'#$13'BJ'#$F5'NJ'#$F4'?_'#$A7'/_'#$EB'CJ'#$A6'KL'#$97 ;
Over3 = 'K.'#$21'L+'#$98 ;
Over4 = 'aFabFbcFcdFdeFefFfgFghFhiFijFjkFklFlmFmnFnoFopFpqFqrFrsFs' ;
Over5 = 'tFtuFuvFvwFwxFxyFyzFz' ;
(* ================================================================== *)
(* Connection - Connect to the other computer and simulates *)
(* a VT100 type terminal . *)
(* *)
(* ================================================================== *)
Procedure Connection ;
VAR
achar,bchar : byte ;
i : integer ;
overchar : string[2] ;
overchars : string[160] ;
EscapeFlag : boolean ;
(* -------------------------------------------------------- *)
Procedure Escape ;
Var Pn,Pc : byte ;
Function PNumber (var achar : byte) : integer ;
var Numstr : string[3];
Num,result : integer ;
Begin (* PNumber *)
Numstr := '' ;
While chr(achar) in ['0'..'9'] do
Begin (* get number *)
Numstr := Numstr + chr(achar) ;
If Readchar(achar) then ;
End ; (* get number *)
Val(Numstr,Num,Result);
PNumber := Num ;
End ; (* PNumber *)
Begin (* Escape Sequence *)
If Readchar(achar) then
CASE chr(achar) of (* First Level *)
'[':
If Readchar(achar) then
CASE chr(achar) of (* Second level *)
'C': CursorRight ;
'D': CursorLeft ;
'J': ClrScr ; (* Erase End of Display *)
'K': ClrEol ; (* Erase End of Line *)
'?': ; (* Special functions - not yet implemented *)
'H': GoToXY(0,0); (* Cursor Home *)
'm':(* NormVideo*) ; (* Exit all attribute modes *)
else
Begin (* Esc [ Pn x functions *)
Pn := PNumber(achar);
CASE chr(achar) of (* third level *)
'A': For i := 1 to Pn do Cursorup ;
'B': For i := 1 to Pn do Cursordown ;
'C': For i := 1 to Pn do CursorRight ;
'D': For i := 1 to Pn do CursorLeft ;
';': Begin (* Direct cursor addressing *)
If readchar(achar) then ;
Pc := PNumber (achar);
GoToXY(Pc,Pn);
If (pn<1) or (pc<1) then
writeln('***',pn,' ',pc,'***');
End ; (* Direct cursor addressing *)
'q': FatCursor(Pn=1) ;
'm',
'}':
Case Pn of (* Field specs *)
0: begin (* Normal *)
TextColor(LightGray);
Textbackground(black);
end ;
1: begin (* High Intensity *)
TextColor(White);
Textbackground(black);
end ;
4: begin (* Underline *)
TextColor(White);
Textbackground(black);
end ;
5: begin (* Blink *)
TextColor(White+ blink);
Textbackground(black);
end ;
7: begin (* Reverse *)
TextColor(Black);
Textbackground(white);
end ;
8: begin (* Invisible *)
TextColor(Black);
Textbackground(black);
end ;
30: Textcolor(Black);
31: Textcolor(Red);
32: Textcolor(Green);
33: Textcolor(yellow);
34: Textcolor(Blue);
35: Textcolor(Magenta);
36: Textcolor(Cyan);
37: Textcolor(White);
40: Textbackground(Black);
41: Textbackground(Red);
42: Textbackground(Green);
43: Textbackground(Yellow);
44: Textbackground(Blue);
45: Textbackground(Magenta);
46: Textbackground(Cyan);
47: Textbackground(White);
End ; (* case of Field specs *)
'J': Case Pn of
0: ClrScr ;
1: ClrScr ; (* clear to beginning *)
2: ClrScr ;
End ; (* J - Pn Case *)
'K': Case Pn of
1: ClrEol ; (* clear to beginning *)
2: ClrEol ; (* clear line *)
End ; (* J - Pn Case *)
'L': For i := 1 to Pn do InsLine ; (* Insert Line *)
'M': For i := 1 to Pn do DelLine ; (* Delete Line *)
'@': For i := 1 to Pn do (* InsertChar *) ;
'P': For i := 1 to Pn do (* DeleteChar *) ;
End ; (* Case third level *)
End ; (* Esc [ Pn x functions *)
End ; (* second level Case *)
'D': CursorDown ; (* Index *)
'M': CursorUp ; (* Reverse Index *)
'H': ; (* Set Tab Stop *)
'(': ; (* G0 *)
')': ; (* G1 *)
End ; (* First Level Case *)
End ; (* Escape Sequence *)
(* -------------------------------------------------------- *)
Procedure RemoteCommand ;
Var
i : integer ;
Filename : Comstring ;
Begin (* RemoteCommand procedure *)
GotSOH := true ;
If RecvPacket then
Begin (* Got a Packet *)
If InPacketType = Ord('S') then (* Send Packet *)
Begin (* Receive *)
writeln('Got a Send request ');
Filename := '' ;
RecvFile(filename);
End (* Receive *)
else
If InPacketType = Ord('R') then (* Receive Packet *)
Begin (* Receive *)
writeln('Got a receive request ');
for i := 1 to InCount-3 do
filename[i] := chr(RecvData[i]);
Filename[0] := chr(InCount-3) ;
waitxon := XonXoff ;
SendFile(filename);
End (* Receive *)
else
If InPacketType = Ord('G') then (* General Packet *)
Begin (* Receive *)
writeln('Got a General request ');
SendPacketType('Y');
End (* Receive *)
else
Begin (* Unknow packet Type *)
OutCount := 15 ;
Outseq := 0 ;
OutPacketType := Ord('E');
(* SendData := 'Unknow Command'; *)
End; (* Unknown packet Type *)
End (* Got a Packet *)
End ; (* RemoteCommand Procedure *)
(* -------------------------------------------------------- *)
Begin (* Connection *)
DialModem ;
Overchars := Over1+Over2+Over3+Over4+Over5 ;
RemoteScreen ; (* Save local screen, restore remote screen *)
While KeyChar(achar,bchar) do ; (* Empty keyboard buffer *)
While connected do
Begin (* connected *)
If RecvChar(achar) then
if achar < $20 then
Begin (* Control Character *)
if achar = StartChar then RemoteCommand
else
if achar = EOT then connected := false
else
if achar = ESC then Escape
else
if (achar=BS) and AplFlag then
Begin (* Overstrick character *)
overchar[0] := chr(2) ;
If Readchar(achar) then overchar[2]:=chr(achar);
i:=Pos(overchar,overchars);
If i > 0 then achar := ord(overchars[i+2])
else
begin (* reverse order *)
overchar[2] := overchar[1] ;
overchar[1] := chr(achar);
i:=Pos(overchar,overchars);
If i>0 then achar := ord(overchars[i+2])
else achar := AplTable[ord(overchar[2])];
end ; (* reverse order *)
write(chr(BS),chr(achar));
End (* Overstrick character *)
else
if achar in [7,8,10,13] then write(chr(achar));
End (* Control Character *)
else
If achar <> DEL then
if AplFlag then begin (* APL char *)
write(chr(APLTABLE[achar]));
overchar[1] := chr(achar) ;
end
else write(chr(achar));
if KeyChar(achar,bchar) then
Begin (* key input *)
if bchar = $70 then connected := false else (* Alt F9 *)
if bchar = $71 then SendBreak else (* Alt F10 *)
If ((achar=0) or (EscSeq[bchar,1]<>' ')
or (EscSeq[bchar,2]<>' ') ) and
(achar <> $09) then
Begin (* Send escape sequence *)
If EscSeq[Bchar,1]<>' ' then SendChar(Esc);
If EscSeq[Bchar,1]<>' ' then
SendChar(Ord(EscSeq[bchar,1])) ;
If EscSeq[bchar,2]<>' ' then
SendChar(Ord(EscSeq[bchar,2])) ;
End (* Send Escape Sequence *)
else
Begin (* Normal Key *)
If EscapeFlag then
if achar = $7B then AplFlag := true else
if achar = $7D then AplFlag := false ;
Escapeflag := achar = ESC ;
if achar = LocalChar then connected := false else
if achar = BreakChar then SendBreak
else Sendchar(achar);
if LocalEcho and connected then
if AplFlag then write(chr(APLTABLE[achar]))
else write(chr(achar));
End ; (* Normal Key *)
End; (* key input *)
End; (* connected *)
LocalScreen ; (* save remote screen , restore local screen *)
End ; (* Connection *)