home *** CD-ROM | disk | FTP | other *** search
- (*--------------------------------------------------------------------------*)
- (* *)
- (* Program CLPDEMO.PAS *)
- (* *)
- (* Description Demonstrates the use of CLPARSER.TPU. *)
- (* *)
- (* The program will also look for the command line option *)
- (* _F=<filename mask>. If the special switch _F= is found, *)
- (* the resulting matching filenames is loaded into the WILD *)
- (* list and displayed. *)
- (* *)
- (* Modifications Released 07/26/88 v1.0 *)
- (* *)
- (* Author Greg Truesdell *)
- (* *)
- (* Copyright Unrestricted. *)
- (* *)
- (*--------------------------------------------------------------------------*)
-
- program CLPDEMO;
-
- uses
- dos, CLParser;
-
- const
- NormalChars : set of char = [#32..#127]; { ARGUMENT trigger }
- SwitchChars : set of char = ['/','-','+']; { SWITCH trigger }
- SpecialChars: set of char = ['_','&']; { Special SWITCH trigger }
-
- var
- i : integer; { the infamous interator }
- ta : string; { temporary argument string }
-
- { object pointers }
- ArgumentPtr : ^ Argument; { pointer to argument object }
- SwitchPtr : ^ Switch; { pointer to switch object }
- WildPtr : ^ Wild; { pointer to wild object }
-
- (*-----------------------------------------------------------*)
- (* 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; { temp string }
- Add_OK : boolean; { was-add-successful? flag }
-
- 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);
-
- { display all of the list entries }
- 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'); { returns '' if not found }
- if ta <> ''
- then ta := copy(ta,4,length(ta)-3) { get mask from command line }
- else ta := '*.*'; { otherwise assume all files }
-
- { 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 }
- Parse_Wild.Erase;
-
- { now parse the directory for directories }
- Parse_Wild.Init( ta, Directory );
-
- { display the resulting list, if any }
- DisplayList( Parse_Wild, 'Directory List ('+ ta + ')');
-
- { now display the list of parameters from the sample parameter file }
- 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 }
- { this ensures that the special switch char }
- { is not parsed as an argument }
- Parse_Argument.Init( NormalChars-SwitchChars-SpecialChars );
-
- { fill the environ list }
- Parse_Environ.Init;
-
- { fill the parameter file list using ';' and '*' as comment tokens }
- 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, which means you can redirect the output }
- { to a file, if you want to, with CLPDEMO > filename.ext }
- Assign(Output, ''); Rewrite(Output);
- Assign(Input, ''); Reset(Input);
-
- Initialize_Lists;
- Do_Demo;
- Erase_Lists;
- END.
-