kevin%UUCP@YALE.ARPA@zeke.UUCP (02/17/87)
Question -- I need to access command line arguments in pascal -
why can't I do it in one step as this example shows?
program t;
%include '/sys/ins/base.ins.pas';
%include '/sys/ins/streams.ins.pas';
%include '/sys/ins/pgm.ins.pas';
var argc,i,j : integer;
argv : pgm_$argv_ptr;
argvp : pgm_$argv;
arg : ^pgm_$arg;
begin
pgm_$get_args(argc,argv);
argc := argc - 1;
writeln(argc:1,' arguments found. They are :');
for i:=1 to argc do
begin
{ why can't I de-reference the structure in one step
as this line does ??
******* bad line ***** - error = argv not a pointer ******
writeln(argv^[i]^.chars[1]);
}
arg := argv^[i];
write(i:1,' : ');
for j := 1 to arg^.len do write(arg^.chars[j]);
writeln;
end;
end.
Kevin Buchs 3500 Zycad Dr. Oakdale, MN 55109 (612)779-5548
Zycad Corp. {rutgers,ihnp4,amdahl,umn-cs}!meccts!zeke!kevin
nazgul@EDDIE.MIT.EDU@apollo.UUCP (02/21/87)
In article <333589cd.44e6@apollo.uucp> Kevin Buchs <kevin@zeke> writes: > > Question -- I need to access command line arguments in pascal - > why can't I do it in one step as this example shows? ... > argv : pgm_$argv_ptr; ... > > { why can't I de-reference the structure in one step > as this line does ?? > > ******* bad line ***** - error = argv not a pointer ****** > > writeln(argv^[i]^.chars[1]); > > } argv is a pointer to an array of univ_ptr's. Those in fact do point to pgm_$arg's, but of course you can dereference a univ_ptr, you have to assign it to something else. The real solution is probably to define your own type which is a pointer to an array of pgm_$arg pointers and use that. "But wait," you say, "why wasn't it done that way in the first place?". Because the original thought was that you might want to pass things other than strings to programs (e.g. some arbitrary data or strange data structure). In fact no one (to my knowlege) has ever used this ability, but the data structures still allow for it. -nazgul