home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
pascal
/
library
/
dos
/
bix
/
strings.sys
< prev
next >
Wrap
Text File
|
1986-08-04
|
8KB
|
251 lines
{$V-}
(************************************************************************)
(* *)
(* STRINGS.LIB *)
(* *)
(* A compendium of string utilitys, including: *)
(* *)
(* --NAME-- -TYPE- --DESCRIPTION-- *)
(* *)
(* Noise -P- Procedure to generate sound. *)
(* Beep -P- Short, High pitched sound. *)
(* Burp -P- Short, Low pitched sound. *)
(* ConstStr -F- Function to return a string of characters. *)
(* UpcaseStr -F- Function to convert a string to Upper Case. *)
(* KeyFlush -P- Procedure to clear the keyboard buffer. *)
(* ReadKey -F- Reads a key from the keyboard, no echo. *)
(* InputStr -P- Allows for editing and input of a string. *)
(* Strip -P- Procedure to remove leading chars from a string. *)
(* Parse -F- Returns a portion of a string. *)
(* *)
(* *)
(* *)
(* compiled by John Leonard 4/6/1986 *)
(* *)
(* NOT FOR SALE WITHOUT WRITTEN PERMISSION *)
(************************************************************************)
procedure noise( freq,dura : integer);
begin
sound(freq);delay(dura);nosound;
end;
procedure beep;
begin
noise(1000,200);
end;
procedure burp;
begin
noise(256,200);
end;
function conststr( n: integer;c:char):longstring;
var s : longstring;
begin
if n<0 then n:=0;
s[0] := chr(n);
fillchar(s[1],n,c);
conststr := s;
end;
function UpcaseStr(S : Str80) : Str80;
var P : Integer;
begin
for P := 1 to Length(S) do S[P] := Upcase(S[P]);
UpcaseStr := S;
end;
procedure keyflush;
var ch:char;
begin
while keypressed do read(kbd,ch);
end;
function readkey( var Special : Boolean ) : char;
var ch : char;
quit:boolean;
begin
Special := false;
quit := false;
repeat
if keypressed then begin
quit := true;
read(kbd,ch);
if ( ch = #27) and keypressed then begin
read(kbd,ch);
Special := true;
end;
end;
until quit;
readkey := ch;
end;
procedure InputStr(var S : str80;
L,X,Y : Integer;
Term : CharSet;
var esc : boolean;
var TC : Char );
var
P : Integer;
special : boolean;
Ch : Char;
begin
GotoXY(X ,Y ); Write(S,ConstStr(L - Length(S),'_'));
P := 0;esc := false;
repeat
GotoXY(X + P ,Y );
ch := readkey(special);
if special then
case ch of
#75 : if P > 0 then
P := P - 1
else Beep;
#77 : if P < Length(S) then
P := P + 1
else Beep;
#83 : if p < length(s) then
begin
Delete(S,P+1,1);
Write(copy(s,p+1,l),'_');
end;
#72 : begin
esc := true;
tc := #72;
P := Length(S);
GotoXY(X + P ,Y );
Write('' :L - P);
exit;
end;
#80 : begin
esc := true;
tc := #80;
P := Length(S);
GotoXY(X + P ,Y );
Write('' :L - P);
exit;
end;
#115 : begin
esc := true;
tc := #115;
P := Length(S);
GotoXY(X + P ,Y );
Write('' :L - P);
exit;
end;
#116 : begin
esc := true;
tc := #116;
P := Length(S);
GotoXY(X + P ,Y );
Write('' :L - P);
exit;
end;
#160 : begin
esc := true;
tc := #160;
P := Length(S);
GotoXY(X + P ,Y );
Write('' :L - P);
exit;
end;
#164 : begin
esc := true;
tc := #164;
P := Length(S);
GotoXY(X + P ,Y );
Write('' :L - P);
exit;
end;
else Beep;
end
else case Ch of
#27 : begin
esc := true;
tc := #27;
P := Length(S);
GotoXY(X + P ,Y );
Write('' :L - P);
exit;
end;
#32..#126 : if P < L then
begin
if Length(S) = L then
Delete(S,L,1);
P := P + 1;
Insert(Ch,S,P);
Write(Copy(S,P,L));
end
else Beep;
^S : if P > 0 then
P := P - 1
else Beep;
^D : if P < Length(S) then
P := P + 1
else Beep;
^A : P := 0;
^F : P := Length(S);
^G : if P < Length(S) then
begin
Delete(S,P + 1,1);
Write(Copy(S,P + 1,L),'_');
end;
^H,#127 : if P > 0 then
begin
Delete(S,P,1);
Write(^H,Copy(S,P,L),'_');
P := P - 1;
end
else Beep;
^Y : begin
Write(ConstStr(Length(S) - P,'_'));
Delete(S,P + 1,L);
end;
else if not (Ch in Term) then Beep;
end; {of case}
until (Ch in Term) ;
P := Length(S);
GotoXY(X + P ,Y );
Write('' :L - P );
TC := Ch;
end;
procedure Strip(var s : longstring;Break : charset);
var done:boolean;
begin
done := false;
repeat
if( s[1] in break) then delete(s,1,1) else done:=true;
until done;
end;
function parse(var Line: longstring;
Break : charset ) : longstring;
var
Len,Indx : Integer;
begin
parse := '';
Strip(Line,Break);
len := length(line);
if Len = 0 then Exit;
Indx := 0;
while not (Line[Indx+1] in Break) and (Indx < Len) do
Indx := Indx + 1;
parse := Copy(Line,1,Indx);
Delete(Line,1,Indx);
Strip(Line,Break)
end;
{$V+}