|
|
DataMuseum.dkPresents historical artifacts from the history of: CP/M |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about CP/M Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 7680 (0x1e00)
Types: TextFile
Names: »READCMD.P«
└─⟦dd59903ef⟧ Bits:30005887 Klub diskette for udveksling af software
└─⟦this⟧ »READCMD.P«
PROCEDURE readcmd(VAR arg: wrdarray; VAR numargs: byte);
æ
+------------------------------------------------------------+
øWRITTEN FOR ZUG USE. PASCAL Z, version 4.0 ø
øBY Clif Kinne DATE: 12/15/82 ø
ø ø
øPURPOSE This procedure was designed to read and parse the ø
ø command tail on a program call. ø
ø ø
øCALL: Readcmd(name,nargs) - typical. ø
ø ø
øINPUT Reads a string, LINE, of up to 80 characters from ø
øDATA from the console. ø
ø ø
øRETURNS: 1. The words from LINE in an array, ARGÆ1..maxargsÅø
ø 2. NARGS, the actual number of words found. ø
ø 3. Dummy 1-character arguments to pad out the ø
ø array from numargs to maxargs. ø
ø ø
øGLOBALS CONST maxword = Max. no. of characters in a word ø
øREQUIRED maxargs = Max. no. of arguments allowed ø
ø maxline = 80; ø
ø ø
ø TYPE wrdtype = string maxword; ø
ø wrdarray = ARRAYÆ1..maxargsÅ OF wrdtype; ø
ø byte = 0..255; ø
ø ø
ø VAR <argname>: wrdarray; ø
ø ø
øFEATURES 1. Truncates long words to MAXWORD characters. ø
ø 2. If command tail is empty, invites operator to ø
ø enter arguments, continue without arguments, ø
ø or quit. ø
ø 3. Trailing dummy arguments can signal calling ø
ø program it has asked for unavailable argument.ø
ø 4. Can have up to 5 14-character or 38 1-characterø
ø arguments, or any mixture up to 77 characters.ø
ø 5. Even though MAXARGS arguments are allowed, any ø
ø lesser no. of arguments, including none, may beø
ø entered. If none are needed, the command shouldø
ø be followed by 2 spaces to avoid the reminder. ø
ø ø
øBUGS Does not handle tab characters satisfactorily. ø
+------------------------------------------------------------+
.paå
CONST blank = ' ';
dummy = 'Ø';
TYPE linetype = string maxline;
string0 = string 0;
string255 = string 255;
VAR pos,i : byte;
line : linetype;
FUNCTION length(x: string255): INTEGER; external;
PROCEDURE reminder;
æ +------------------------------------------------------+
øThis procedure is intended for use with the procedure,ø
øREADCMD. It can be made external to READCMD so that itø
ømay be tailored to the calling program. ø
+------------------------------------------------------+
å
BEGIN æ----------------------------reminder-----------------------------å
WRITELN(margin,
'You neglected to include any arguments with the program call.');
WRITELN; WRITELN(margin,
'Please enter them now (or enter "Q" to quit, or RETURN to');
WRITELN; WRITELN(margin,'continue without arguments).');
WRITELN; WRITELN; WRITE(margin,'===> ')
END; æ----------------------------reminder-----------------------------å
PROCEDURE linetoolong;
BEGIN æ---------------------------linetoolong---------------------------å
WRITELN(margin,'Command line is too long.'); WRITELN;
WRITELN(margin,'Reenter arguments here. Do not exceed',
(maxline - 3):3,' characters.');
WRITELN; READLN(line)
END; æ---------------------------linetoolong---------------------------å
æ.p.aå
PROCEDURE getword(VAR word: string0; VAR line: linetype; VAR pos: byte);
æ +----------------------------------------------------------+
øThis procedure receives a string, LINE, and a character ø
øposition, POS. ø
øIt extracts the first group of non-space characters after ø
øPOS, and returns it to the calling program as WORD. ø
øLong words will be truncated at MAXWORD characters. ø
øPOS is returned to the calling program so that additional ø
øwords may be extracted. ø
+----------------------------------------------------------+
å
CONST blank = ' ';
PROCEDURE setlength(VAR x: string0; y: INTEGER); external;
BEGIN æ-----------------------------getword-----------------------------å
WHILE ((lineÆposÅ = blank) OR (lineÆposÅ= CHR(9))) AND (pos<maxline) DO
pos := pos+1; æSKIPBLANKSå
setlength(word,0); æINITIALIZES word TO A NULL STRING.å
WHILE (lineÆposÅ <> blank) AND (lineÆposÅ <> CHR(9)) AND
(length(word) < maxword) DO
BEGIN
APPEND(word,lineÆposÅ); æBUILDS THE STRING, word. å
pos := pos + 1
END;
WHILE (lineÆposÅ <> blank) AND (lineÆposÅ <> CHR(9)) DO
pos := pos + 1 æSKIPS OVER ANY EXTRA NON-BLANK CHARACTERS IN wordå
END; æ-----------------------------getword-----------------------------å
BEGIN æ-------------------------------readcmd-----------------------------å
pos := 1;
IF EOLN THEN reminder; æREPORT NO COMMAND LINE ARGUMENTS AT ALL å
READLN(line); WRITELN;
WHILE length(line) > (maxline - 3) DO linetoolong;
APPEND(line,blank); æAPPEND DUMMY ARGUMENT TO SIGNIFY NO MOREå
APPEND(line,dummy); æARGUMENTS IN THE COMMAND LINE å
FOR i := length(line) TO maxline - 1 DO append(line,blank);
æNEEDED SO THAT getword WILL BEHAVE AFTER DUMMY ARGUMENTå
numargs := 0;
REPEAT æGET ACTUAL ARGUMENTS IN ARRAY, arg, AND å
numargs := numargs + 1; æTHE COUNT OF THE ARGUMENTS IN numargs: å
getword(argÆnumargsÅ,line,pos)
UNTIL (argÆnumargsÅ = dummy) OR (numargs = maxargs);
FOR i := numargs + 1 TO maxargs DO argÆiÅ := dummy; æPAD ARGUMENT LIST å
æOUT TO maxargs WITH DUMMY ARGUMENTSå
IF argÆnumargsÅ = dummy THEN numargs := numargs - 1; æADJUST numargså
END; æ-----------------------------readcmd ------------------------------å
«eof»