/* In this procedure, the arguments in the command line are assumed */ /* to be separated by one or more blanks. */ /* Arguments may be enclosed in apostrophes or in quotation marks. */ /* This entry point returns the N-th argument from the command line. */ /* Copyright (c) 2003, 2001 by R. A. Vowels. Date written 7/11/2001.*/ /* Revised 29 December 2003. */ GETARG: PROCEDURE (N) RETURNS (CHARACTER(100) VARYING BYADDR); /* INCOMING: N = the number of the argument required from command line. */ /* RETURNS: Argument = the N-th argument from the command line. */ DECLARE Argument CHARACTER(*) VARYING; DECLARE N FIXED BINARY; DECLARE Text CHARACTER (101) VARYING; DECLARE Arguments (50) CHARACTER (100) VARYING STATIC INITIAL ((50)(1)'' ); DECLARE No_arguments FIXED BINARY; DECLARE (J, K) FIXED BINARY (7); RETURN ( Arguments(N) ); /* This entry point returns the number of arguments in the command line. */ NARGS: ENTRY (Argument) RETURNS (FIXED BINARY BYADDR); /* INCOMING: The command line arguments. */ /* RETURNS: The number of arguments. */ Text = Argument; Text=TRIM(Text) || ' '; No_arguments = 0; DO WHILE (Text ^= ''); /* loop to extract file names */ No_arguments = No_arguments + 1; /* from the command line. */ IF SUBSTR(Text, 1, 1) = '"' THEN DO; K = INDEX(Text, '"', 2); Arguments(No_arguments) = TRIM(SUBSTR(Text, 2, K-2)); END; ELSE IF SUBSTR(Text, 1, 1) = '''' THEN DO; K = INDEX(Text, '''', 2); Arguments(No_arguments) = TRIM(SUBSTR(Text, 2, K-2)); END; ELSE DO; K = INDEX(Text, ' '); Arguments(No_arguments) = TRIM(SUBSTR(Text, 1, K)); END; Text = TRIM(SUBSTR(Text, K+1), ' ', '\'); END; RETURN (No_arguments); END GETARG;