home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
549a.lha
/
M2P_v1.0
/
mods.lzh
/
Args.mod
next >
Wrap
Text File
|
1991-08-10
|
3KB
|
257 lines
IMPLEMENTATION MODULE Args;
IMPORT
SYSTEM;
IMPORT
Strings,FStorage;
(* insert machine specific imports here *)
(*----------------------------------------------------------------------*)
VAR
WM: POINTER TO Workbench.WBStartup;
process: ProcessPtr;
(*----------------------------------------------------------------------*)
PROCEDURE AddArgs(string: ARRAY OF CHAR);
VAR
buffer : ARRAY [0..MaxArgSize] OF CHAR;
len,i,j: CARDINAL;
BEGIN
i:=0;
j:=0;
len:=Strings.Length(string);
WHILE (j<MaxArgSize) AND (i<=len) AND (argc<=MaxArg) DO
j:=0;
WHILE (string[i]=" ") OR (string[i]=11C) DO
INC(i);
END;
IF string[i]<" " THEN
RETURN;
END;
IF string[i]='"' THEN
INC(i);
WHILE (string[i]#'"') AND (j<MaxArgSize) AND (i<len) DO
IF (string[i] = CHR(92)) AND (string[i+1]='"') THEN
INC(i);
END;
buffer[j]:=string[i];
INC(j);
INC(i);
END;
IF string[i]='"' THEN
INC(i);
END;
ELSE
IF (string[i]>='!') AND (string[i]<='-') THEN
buffer[j]:=string[i];
INC(i);
INC(j);
ELSE
REPEAT
buffer[j]:=string[i];
INC(j);
INC(i);
UNTIL (string[i]<="-") OR (j>=MaxArgSize) OR (i>=len);
END;
END;
buffer[j]:=0C;
FStorage.ALLOCATE(argv[argc],LONGCARD(j+1));
Strings.Assign(buffer,argv[argc]^);
INC(argc);
END;
END AddArgs;
(*----------------------------------------------------------------------*)
(* Get the command name. If this is not an Amiga, make an empty string *)
(*----------------------------------------------------------------------*)
PROCEDURE AddCmdName;
VAR
charptr : POINTER TO CHAR;
stringptr: POINTER TO ARRAY [0..MaxArgSize] OF CHAR;
toolptr : POINTER TO SYSTEM.ADDRESS;
buffer : ARRAY [0..MaxArgSize] OF CHAR;
len,i : CARDINAL;
cli : CommandLineInterfacePtr;
numargs: INTEGER;
arglist: Workbench.WBArgPtr;
diskobj: Workbench.DiskObjectPtr;
lock: FileLock;
BEGIN
i:=0;
(* started from CLI *)
(* started from WorkBench *)
(* insert compiler dependency here *)
buffer[i]:=0C;
FStorage.ALLOCATE(argv[argc],LONGCARD(i+1));
Strings.Assign(buffer,argv[argc]^);
INC(argc);
END AddCmdName;
(*----------------------------------------------------------------------*)
(* Add the command line arguments from the shell (or CLI) *)
(*----------------------------------------------------------------------*)
PROCEDURE AddCmdArgs;
VAR
stringptr: POINTER TO ARRAY [0..MaxArgSize] OF CHAR;
BEGIN
IF SYSTEM.ADDRESS(WM) = SYSTEM.ADDRESS(0) THEN
(* insert compiler dependent stuff here *)
AddArgs(stringptr^);
END;
(* insert OS dependent stuff here *)
END AddCmdArgs;
(*----------------------------------------------------------------------*)
(* Termination procedure, call this to clean things up. *)
(*----------------------------------------------------------------------*)
PROCEDURE TermProc;
BEGIN
Libraries.CloseLibrary(IconBase);
END TermProc;
(************************************************************************)
BEGIN
(* insert compiler dependent stuff here *)
IF SYSTEM.ADDRESS(process^.prCLI) = SYSTEM.ADDRESS(0) THEN
WM:=SYSTEM.ADDRESS(0);
(* insert Workbench message initialization here *)
END;
(* insert compiler dependent OpenLibrary here *)
FOR argc:= 0 TO MaxArg DO
argv[argc]:=NIL;
END;
argc:=0;
AddCmdName;
AddCmdArgs;
END Args.