Accessing command line arguments example doesn't work

Thomas Tan Thomas_Tan at fc.choate.edu
Sat Nov 1 18:34:10 CET 1997


I get wierd errors when I try to compile the command line argument example. 
First it had a problem with the line (ParamStr := ";), so I changed the " to "
" 
Then it said ( cmdline.pas(36) Error: undeclared identifier `Arg_num'" )about
the line
(     Success := _p_paramstr (arg_num, Str);) I don't know what's wrong.


Here's the text I found in the Documentation of GPC:
<********** begin text here *************>


Accessing command line arguments:

The following module accesses the command line with ParamStr and ParamCount
functions. 

These follow the Un*x semantics, so that 

     arg[0] == program name, 
     arg[1] .. arg[ParamCount-1] are the arguments. 

MODULE command_line interface;

EXPORT cmdline = (Max_length, Arg_type, ParamStr, ParamCount);

CONST
   Max_length = 255;     { Max length of each argument.
                           If some arg is longer, the run time system
                           traps it. }

TYPE
  Arg_type = String(Max_length);

  FUNCTION ParamCount: Integer;

  FUNCTION ParamStr (arg_num: integer): Arg_type;
END. { command_line interface }

MODULE command_line implementation;

  { These are in the GPC runtime library }
  FUNCTION _p_paramcount : Integer; C;
  FUNCTION _p_paramstr (num: Integer; VAR str: String): Boolean; C;

  FUNCTION ParamCount;
  BEGIN
     ParamCount := _p_paramcount;
  END; { ParamCount }

  FUNCTION ParamStr;
  
  VAR
   Str       : Arg_type;
   Success     : Boolean;

  BEGIN
     Success := _p_paramstr (arg_num, Str);

     (* Should perhaps do something else on failure.
      *
      * Now it returns the empty string, which is also a valid
      * parameter.
      *)
     IF Success THEN
        ParamStr := Str
     else
        ParamStr := ";
  END; { ParamStr }
END. { command_line implementation }

{ The program below, when compiled with the interface module and
  linked with the implementation module, accesses the command
  line arguments. }     

program zap (output);

import cmdline;

var
   counter : integer;

begin
   writeln ('Program fetches command line arguments and outputs one per line');
   writeln ('Max length of each argument is ',Max_Length:1,' characters');

   for counter := 0 to ParamCount-1 do
      writeln ('Command line arg ',counter:1,' is "',paramstr(counter),'"');
end.


<******************end text here****************>

------------------------------------------------------
This message sent using the FirstClass SMTP/NNTP Gateway.
From:
Choate Rosemary Hall
333 Christian St.
Wallingford, CT. 06492




More information about the Gpc mailing list