home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d1xx
/
d183
/
pcq.lha
/
PCQ
/
Examples
/
ChopCL.p
next >
Wrap
Text File
|
1989-02-26
|
3KB
|
82 lines
external;
{
This procedure simply chops up the commandline into strings.
These strings are actually just pointers into the array CommandLine,
so you shouldn't mess with them, especially if you change their length.
Use strcpy to copy them to your own storage. Of course you can't use
CommandLine until you've extracted what you want from these. The
maximum number of arguments you want should be placed in argc before
the call. After the call, argc will hold the actual number read.
This is designed to be compiled and assembled, then called
using the external reference facility. This has a benefit I'll talk
about in a second. The process goes like this:
1. Compile this file using
Pascal ChopCL.p ChopCL.s
2. Assemble it using
A68k ChopCL.s ChopCL.o
3. In a program that can use this sort of program, include:
type
argvtype = array [1..whatever] of string;
procedure ChopCL(var a : argvtype; var m : Integer);
forward;
4. When you go to link your program, include ChopCL.o in
your list of object files. For example if your file
is called prog.o, you would write:
Blink prog.o chopcl.o small.lib to prog library pcq.lib
5. You're done.
The benefit I mentioned earlier is that, in your own program,
you can make any size array of arguments you need. If your program
only needs two arguments, make the array just two elements, then set
argc to 2 before you send it. Since there is no checking done between
modules, you can simply use a forward declaration that works for you.
This is known as cheating.
There is a program called ChopTest.p in this archive that
will test this routine.
}
type
argvtype = array [0..100] of string;
procedure ChopCL(var argv : argvtype; var argc : Integer);
var
clindex : Integer;
max : Integer;
begin
max := argc - 1;
argc := 0;
if max <= 0 then
return;
clindex := 1;
while (clindex < 128) and (argc <= max) do begin
while ((ord(commandline[clindex]) <= ord(' ')) or
(ord(commandline[clindex]) > ord(127))) and
(clindex < 128) do begin
if commandline[clindex] = chr(0) then
return;
clindex := succ(clindex);
end;
if clindex >= 128 then
return;
argv[argc] := string(adr(commandline[clindex]));
while (ord(commandline[clindex]) > ord(' ')) and
(ord(commandline[clindex]) < 127) and
(clindex < 128) do
clindex := succ(clindex);
argc := succ(argc);
if commandline[clindex] = chr(0) then
return;
commandline[clindex] := chr(0);
clindex := succ(clindex);
end;
end;