PROCEDURE ParseCommand { ( command: str80; VAR cmd: str8; VAR param: integer; VAR pri: integer; VAR qnt: integer) }; CONST debug=false; VAR cmdline: str80; errcode: integer; Xparam, Xpri, Xqnt : str8; iqnt: integer; label 10; FUNCTION NextWord: str80; VAR k: byte; BEGIN cmdline:= trim( cmdline) + ' '; if length( cmdline) = 1 then NextWord:= '' else begin k:= pos(' ', cmdline); NextWord:= copy( cmdline, 1, k-1); delete( cmdline, 1, k); end; END; BEGIN {ParseCommand} {set default values} param:= 0; pri:= default_priority; qnt:= default_quantum; cmdline:= command; cmd:= NextWord; Xparam:= NextWord; Xpri:= NextWord; Xqnt:= NextWord; if length( Xparam )>0 then begin Val( Xparam, param , errcode); if errcode <> 0 then begin writeln('Invalid parameter field "'+cmd+'".'); goto 10; (*exit;*) end; end; if length(Xpri)>0 then begin Val( Xpri, pri, errcode); if errcode <> 0 then begin writeln('Invalid priority field "'+cmd+'".'); goto 10; (*exit;*) end; end; if length(Xqnt)>0 then begin Val( Xqnt, iqnt, errcode); qnt:= iqnt; if errcode <> 0 then begin writeln('Invalid quantum field "'+cmd+'".'); goto 10 (*exit;*) end; end; 10: END; {ParseCommand} {$V-} PROCEDURE execCommand { ( cmd: str8; param: word; pri: integer; qnt: byte) } ; {-------------------- Execute a single, legal shell command } { For now, the only legal shell commands are: "H" or "Q" -- terminate SOS "T" -- toggle trace mode "S" -- toggle step mode name of a task, possibly followed by an integer parameter, a task priority, and a task quantum. The result of this is to run the task.} CONST debug=false; VAR TaskNum: PCB_ptr; errcode: integer; err: boolean; BEGIN {execCommand} if debug then writeln( '[execCommand]: cmd = "', cmd, '"'); if (cmd = 'H') or (cmd = 'Q') then abortOS( 'HALT REQUEST.') else if (cmd = 'T') then begin CPU.trace:= not CPU.trace; if not CPU.trace then NormWindow; fetch; end else if (cmd = 'S') then begin CPU.single_step:= not CPU.single_step; fetch; end else begin { cmd string should be the name of a .pco code file} TaskNum := 1; CreateTask( cmd, TaskNum); StartTask( TaskNum, pri, qnt, param ); end; END; {execCommand} PROCEDURE extract { ( VAR cmd, cmdlin: str80) } ; {----------------EXTRACT THE NEXT COMMAND FROM A COMMAND LINE} CONST debug=false; VAR k: byte; BEGIN cmdlin:= trimLeft( cmdlin); k:= pos(';', cmdlin); IF k>0 THEN BEGIN cmd:= copy( cmdlin,1, k-1); delete( cmdlin, 1, k); END ELSE BEGIN cmd:= cmdlin; cmdlin:= ''; END; cmd := UPS( cmd); if debug then writeln('Extract: cmd = "', cmd, '", rest of line = "', cmdlin,'".'); END; {extract} PROCEDURE ExecCommandLine { ( cmdline: str80) } ; {-------------------------execute a user command line} CONST debug=false; VAR command: str80; cmd: str8; param: integer; pri: integer; qnt: integer; BEGIN {ExecCommandLine} while length( cmdLine) > 0 do begin extract( command, cmdLine); if debug then writeln( 'Command is: "', command, '"'); ParseCommand( command, cmd, param, pri, qnt ); if pri < 0 then pri:= 0; if qnt > 255 then qnt:= 255; if qnt < 0 then qnt:= 0; execCommand( cmd, param, pri, qnt); end; END; {ExecCommandLine} {$V+} PROCEDURE InterpretCommandLine; {----------------------------- fetch and execute a user command line. } CONST debug=false; VAR cmdLine: str80; BEGIN {InterpretCommandLine} cmdLine:= ''; while length( cmdLine) = 0 do begin write('SOS Shell: '); readln( cmdLine); cmdLine:= UPS( cmdLine); if debug then writeln( 'from UPS: cmdLine = "', cmdLine, '"'); end; ExecCommandLine( cmdLine); END; {InterpretCommandLine}