Category : Pascal Source Code
Archive   : CLP30.ZIP
Filename : CLPDEMO.PAS
(* Program: EXAMPLE.EXE *)
(* *)
(* Sample program included with the CLPARSER.TPU Package. *)
(* *)
(* Greg Truesdell 07/26/88 10:46pm *)
(*--------------------------------------------------------------------------*)
program EXAMPLE;
uses DOS, CLPARSER;
const
NormalChars : set of char = [#32..#127];
SwitchChars : set of char = ['/','-','+'];
SpecialChars: set of char = ['_','&'];
var
i : integer;
ta : string;
{ object pointers }
ArgumentPtr : ^ Argument;
SwitchPtr : ^ Switch;
WildPtr : ^ Wild;
(*-----------------------------------------------------------*)
(* DisplayList( ListObject, Message ) *)
(* *)
(* Displays the list of items in ListObject. Prints *)
(* the message at the end of the list. *)
(* *)
(*-----------------------------------------------------------*)
procedure DisplayList ( ListObject : Argument; Message: string );
var
ta : string;
Add_OK : boolean;
begin
{ exit if no items in the list }
if ListObject.Count = 0 then exit;
{ write a header for the list }
WriteLn;
WriteLn(Message+':');
WriteLn('Item# Position# Item');
WriteLn('----- --------- ---------------------------------------');
Add_OK := ListObject.Add( 'End of '+Message,0);
for i := 1 to ListObject.Count do
begin
ta := ListObject.Next;
writeln( i:5,ListObject.Position:10,' ',ta );
end;
{ report if the list was overflowed }
if ListObject.Overflow then Writeln('Overflow!');
{ let us know if the add was not successful }
if not Add_OK then WriteLn('Couldn''t add comment!');
end;
(*-----------------------------------------------------------*)
(* Do_Demo *)
(* *)
(* This procedure demonstrates how the CLPARSER unit *)
(* works. Every object is demo-ed, but not all methods *)
(* are used. *)
(* *)
(*-----------------------------------------------------------*)
procedure Do_Demo;
begin
{ display the primary lists }
DisplayList( Parse_Argument, 'Argument List');
DisplayList( Parse_Switch, 'Switch List');
DisplayList( Parse_Environ, 'Environment List');
{ search for a specific item in a list }
if Parse_Environ.Find('path=') <> '' then
begin
writeln;
writeln('Found PATH Environment Variable ---');
writeln(' ',Parse_Environ.Find('path=') );
end;
{ Release the current switch list and parse for special switches }
Parse_Switch.Erase;
Parse_Switch.Init( SpecialChars );
DisplayList( Parse_Switch, 'Special List');
{ get the volume id }
Parse_Wild.Init('\*.*',VolumeID);
{ if found, display it }
if Parse_Wild.Count > 0 then
begin
ta := Parse_Wild.Next;
delete(ta,9,1);
writeln;
writeln('Volume ID: ', ta);
end;
{ check for _f= switch for file mask ( ie. CLPDEMO _F=*.PAS )}
{ if it is there, use it }
ta := Parse_Switch.Find('_f');
if ta <> ''
then ta := copy(ta,4,length(ta)-3)
{ otherwise assume all files }
else ta := '*.*';
{ clear the current wild list and parse for new list }
Parse_Wild.Erase;
{ fill the list with matching files (not directories or the volume id }
Parse_Wild.Init(ta,AnyFile-Directory-VolumeID);
{ display the new list }
DisplayList( Parse_Wild , 'Wildcard List ('+ ta + ')');
{ erase the current wild list and parse for directories }
Parse_Wild.Erase;
Parse_Wild.Init( ta, Directory );
DisplayList( Parse_Wild, 'Directory List ('+ ta + ')');
DisplayList( Parse_File, 'Parameter File List (CLPDEMO.DAT)');
end;
(*-----------------------------------------------------------*)
(* Initialize_List *)
(* *)
(* This procedure re-initializes the argument list to *)
(* exclude arguments starting with special characters. *)
(* These special characters will be used later as switch *)
(* indicators. *)
(* *)
(* The Environ list is also initialized since it is not *)
(* automatic on start-up. *)
(* *)
(* The demo parameter file is loaded into the file list. *)
(* (CLPDEMO.DAT) *)
(* *)
(*-----------------------------------------------------------*)
procedure Initialize_Lists;
begin
{ release auto-loaded arguments }
Parse_Argument.Erase;
{ parse for arguments - switches - specials }
Parse_Argument.Init( NormalChars-SwitchChars-SpecialChars );
{ fill the environ list }
Parse_Environ.Init;
{ fill the parameter file list }
Parse_File.Init('CLPDEMO.DAT',[';','*']);
end;
(*-----------------------------------------------------------*)
(* Erase_Lists *)
(* *)
(* Erases lists and reclaims memory used. *)
(* *)
(*-----------------------------------------------------------*)
procedure Erase_Lists;
begin
Parse_Argument.Erase;
Parse_Switch.Erase;
Parse_Wild.Erase;
Parse_Environ.Erase;
Parse_File.Erase;
end;
(*-------------------------------------------------------*)
(* *)
(* M A I N *)
(* *)
(*-------------------------------------------------------*)
BEGIN
{ turn redirection on }
Assign(Output, ''); Rewrite(Output);
Assign(Input, ''); Reset(Input);
Initialize_Lists;
Do_Demo;
Erase_Lists;
END.
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/