Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!hp4nl!tuegate.tue.nl!tuewsd!wsinpp From: wsinpp@lso.win.tue.nl (Peter Peters) Newsgroups: comp.lang.pascal Subject: Re: Turbo P V5.5--Receiving parameters from the command line. Message-ID: <1162@tuewsd.win.tue.nl> Date: 3 May 90 07:09:32 GMT References: <1990May2.114659.21404@aucs.uucp> Sender: wsinpp@win.tue.nl (Peter Peters) Distribution: comp Organization: Eindhoven University of Technology, The Netherlands Lines: 72 In article <1990Apr27.203354.993@watdragon.waterloo.edu> gcreesor@lotus.uwaterloo.ca (Glen Reesor) writes: >I would like to have a program compiled using TP5.5 read parameters on >the command line entered after the program name. > I've written a unit in TP which does a kind of GETOPT thing like there is available in C. If enough people are interested (and someone tell me the correct procedure) I'll upload it somewhere where it's ftp-able, or I'll mail it to someone who can upload it for me (volunteers ?). If you're only interested in getting a single parameter, it's a lot of overhead, otherwise I think it's nice... A code extract which uses this module follows.... ---------------------------------- Procedure ProcessParameters; Var Par : Char; Code : Integer; Begin (* There's a possibility to use a environment variable to preset parameters, I usually use the program name as environment variable *) SetEnvOpt ( ProgramName ); (* Here's how command line switches are processed... *) Repeat Par := GetOpt( 'lLhHs:S:' ); (* like in C-getopt *) Case Par Of 'l','L' : Begin (* some actions *) End; 's','S' : Begin (* The ":" in the getopt line above means a parameter is required *) (* some actions *) (* usage of current option argument *) If OptArg <> '' Then Begin Val(OptArg,BlankDelay,Code); If Code <> 0 Then ErrorExit ('Invalid blanking value : "'+OptArg+'"',1); End; End; 'h','H' : Begin Usage; Start := False; End; '?' : (* ? means an invalid switch is on the commandline *) ErrorExit ('Invalid switch : "'+Par+'"',1); End; Until Par = EofChar; If Argv[OptInd] = '?' Then Begin Usage; Start := False; End Else InName := Argv[OptInd]; End; ------------------------------------------------- See if it's of any use and let me know if I should upload it somewhere (or mail it to someone who will upload it). -- | Peter Peters | UUCP : wsinpp@lso.win.tue.nl | | Eindhoven University of Technology (TUE) | SURF : heithe5::wsdcpp | | Dept. of Mathematics and Computer Science | VHF : PA0PPE | | Disclaimer : I said WHAT ??? | TUE : HG 8.86 tst. 4283 | -- | Peter Peters | UUCP : wsinpp@lso.win.tue.nl | | Eindhoven University of Technology (TUE) | SURF : heithe5::wsdcpp | | Dept. of Mathematics and Computer Science | VHF : PA0PPE | | Disclaimer : I said WHAT ??? | TUE : HG 8.86 tst. 4283 |