home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hacker Chronicles 2
/
HACKER2.BIN
/
155.TEXTOPS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1988-06-30
|
10KB
|
312 lines
UNIT TextOps;
INTERFACE
USES
{$IFDEF DOSCrt}
DOSCrt,
{$ELSE}
Crt,
{$ENDIF}
Extended_Reals;
CONST
BELL = #7;
BACKSPACE = #8;
ENTER = #13;
ESC = #27;
NULL = #0; { first code of extended scan codes }
Left = #75; { second code of extended scan code }
Right = #77; { second code of extended scan code }
Up = #72; { second code of extended scan code }
Down = #80; { second code of extended scan code }
PgUp = #73; { second code of extended scan code }
PgDn = #81; { second code of extended scan code }
F1 = #59; { second code of F1 function key }
F2 = #60; { second code of F2 function key }
F3 = #61; { second code of F3 function key }
F4 = #62; { second code of F4 function key }
F5 = #63; { second code of F5 function key }
F6 = #64; { second code of F6 function key }
F7 = #65; { second code of F7 function key }
F8 = #66; { second code of F8 function key }
F9 = #67; { second code of F9 function key }
F10 = #68; { second code of F10 function key }
PROCEDURE WriteXY (s:string; x,y:integer);
PROCEDURE VertLine (x0,y1,y2 : INTEGER);
PROCEDURE HorizLine (x1,x2,y0 : INTEGER);
PROCEDURE frame (leftx, uppery, rightx, lowery: INTEGER);
PROCEDURE String_To_Value ( st : string;
VAR value : REAL;
VAR units : string);
PROCEDURE Value_To_String ( value : REAL;
NumDig : byte;
VAR st : string);
PROCEDURE DrawBorder ( x1 : BYTE;
y1 : BYTE;
x2 : BYTE;
y2 : BYTE);
FUNCTION EXIST (filename : string) : BOOLEAN;
(****************************************************************************)
IMPLEMENTATION
PROCEDURE WriteXY (s:string; x,y:integer);
BEGIN {WriteXY}
GotoXY (x,y);
Write (s);
END; {WriteXY}
{----------------------------------------------------------------------------}
PROCEDURE VertLine (x0,y1,y2 : INTEGER);
CONST
Vertical = '│'; { char (179) }
VAR
i : INTEGER;
BEGIN {VertLine}
FOR i:=y1 TO y2 DO BEGIN
GotoXY (x0,i);
Write (Vertical);
END; {FOR}
END; {VertLine}
{----------------------------------------------------------------------------}
PROCEDURE HorizLine (x1,x2,y0 : INTEGER);
CONST
Horizontal = '─'; { char (196) }
VAR
i : INTEGER;
BEGIN {NorizLine}
GotoXY (x1,y0);
FOR i:=x1 TO x2 DO BEGIN
Write (Horizontal);
END; {FOR}
END; {HorizLine}
CONST
windows = 2;
wtab : array [0..windows,1..4] of byte {x0,y0,x1,y1}
= (( 1, 1, 80, 25 ),
( 20, 5, 60, 20 ),
( 1, 2, 80, 22 ));
{----------------------------------------------------------------------------}
PROCEDURE frame (leftx, uppery, rightx, lowery: integer);
VAR
i : integer;
BEGIN {frame}
GotoXY (leftx,uppery);
WriteXY ('┌',leftx,uppery); {char(218)}
FOR i:=(leftx+1) TO (rightx-1) DO
Write ('─'); {char(196)}
Write ('┐'); {char(191)}
FOR i:=(uppery+1) TO (lowery-1) DO BEGIN
WriteXY ('│',leftx,i); {char(179)}
WriteXY ('│',rightx,i); {char(179)}
END; {FOR}
GotoXY (leftx,lowery);
WriteXY ('└',leftx,lowery); {char(192)}
FOR i:=(leftx+1) TO (rightx-1) DO
Write ('─'); {char(196)}
Write ('┘'); {char(217)}
END; {frame}
{----------------------------------------------------------------------------}
PROCEDURE String_To_Value ( st : string;
VAR value : REAL;
VAR units : string
);
CONST blank = ' ';
VAR
j : integer;
code : integer;
i : 0..1;
factor : REAL;
BEGIN {String_To_Value}
IF st[1] = '.'
THEN st:='0'+st
ELSE IF (st[1] = '-') AND (st[2] = '.')
THEN BEGIN
st[1]:='0';
st:='0'+st;
END;
Val (st,value,code);
IF code = 0
THEN units:=blank
ELSE BEGIN
i:=0;
CASE st[code] of
'p': factor:=1e-12; (* pico *)
'n': factor:=1e-09; (* nano *)
'u': factor:=1e-06; (* micro *)
'm': factor:=1e-03; (* milli *)
'c': factor:=1e-02; (* centi *)
'k': factor:=1e+03; (* kilo *)
'M': factor:=1e+06; (* Mega *)
'G': factor:=1e+09; (* Giga *)
'T': factor:=1e+12; (* Tera *)
ELSE BEGIN
factor:=1.0;
units[1]:=st[code];
i:=1;
END; {ELSE}
END; {CASE}
Delete (st,code,1);
Val (st,value,code);
IF code <> 0
THEN BEGIN
FOR j:=1 TO length(st)-code+1 DO
units [j+i]:=st[j+code-1];
Delete (st,code,length(st)-code+1);
Val (st,value,code);
END {THEN}
ELSE units:=blank;
value:=value*factor;
END; {ELSE}
END; {String_To_Value}
{----------------------------------------------------------------------------}
PROCEDURE Value_To_String ( value : REAL; (* Value to be converted *)
NumDig : byte; (* Precision to be shown *)
VAR st : string (* Converted value *)
);
VAR
mult : STRING [1]; (* Multiplier; i.e. p,n,u,m, ,k,M,G,T *)
x : INTEGER; (* Position of exponent in string *)
factor : REAL;
negative : BOOLEAN;
BEGIN {Value_To_String}
IF NumDig < 4 then NumDig:=4;
IF value < 0
THEN negative:=true
ELSE negative:=false;
factor:=ABS(value);
x:=-15;
IF value = 0
THEN x:=0
ELSE IF (factor*exp(-x*ln(10)) >= 1000)
THEN REPEAT
INC (x,3);
factor:=abs(value)*exp(-x*ln(10));
UNTIL (((1 <= factor) AND (factor < 1000)) OR (x = 15));
CASE x OF
-12: mult:='p';
-9: mult:='n';
-6: mult:='u';
-3: mult:='m';
0: mult:='';
3: mult:='k';
6: mult:='M';
9: mult:='G';
12: mult:='T';
END; {CASE}
CASE x OF
-12..12: BEGIN
IF factor < 10
THEN x:=NumDig-2
ELSE IF factor < 100
THEN x:=NumDig-3
ELSE x:=NumDig-4;
str (factor:NumDig:x,st);
IF negative
THEN st:='-'+st+' '+mult
ELSE st:= st+' '+mult;
END; {CASE -12..12}
ELSE BEGIN
str (value:(NumDig+6),st);
st:=st+' ';
END; {CASE-ELSE}
END; {CASE}
END; {Value_To_String}
{----------------------------------------------------------------------------}
PROCEDURE DrawBorder ( x1 : BYTE;
y1 : BYTE;
x2 : BYTE;
y2 : BYTE
);
CONST
TopLeft = '╔'; {char(201)}
BottomLeft = '╚'; {char(200)}
TopRight = '╗'; {char(187)}
BottomRight = '╝'; {char(188)}
Vertical = '║'; {char(186)}
Horizontal = '═'; {char(205)}
VAR
i : integer;
BEGIN {DrawBorder}
GotoXY (x1,y1); WriteXY (TopLeft,x1,y1);
GotoXY (x1,y2); Write (BottomLeft);
FOR i:=x1+1 TO x2-1 DO BEGIN
GotoXY (i,y1); Write (Horizontal);
GotoXY (i,y2); Write (Horizontal);
END; {FOR}
GotoXY (x2,y1); Write (TopRight);
GotoXY (x2,y2); Write (BottomRight);
FOR i:=y1+1 TO y2-1 DO BEGIN
GotoXY (x1,i); Write (Vertical);
GotoXY (x2,i); Write (Vertical);
END; {FOR}
END; {DrawBorder}
{----------------------------------------------------------------------------}
FUNCTION EXIST (filename : string) : boolean;
VAR
OK : boolean; (* temporary variable, equal to exist *)
Name : text;
BEGIN {EXIST}
IF length (filename) > 0
THEN BEGIN
Assign (Name,filename);
{$I-} Reset (Name); {$I+}
OK:=(IOresult=0);
exist:=OK;
IF OK THEN Close (Name);
END {THEN}
ELSE EXIST:=false;
END; {EXIST}
(****************************************************************************)
BEGIN {Initialization}
END. {UNIT Text}