{****************************************************************************** * * * Minimum executive * * * * Copyright (C) 2001 S. A. Moore * * * * Performs the minimum executive service, which is to read lines from the * * user (input) and execute each as a command. * * Usefull both as an example and as a diagnostic tool. * * Despite the small size, the program is fairly complete and parameterized. * * It features little or no dependencies on current os configuration, and in * * fact could be used with any os having an exec call. * * * * General function * * * * Prompts for and reads command lines from the input. When a non-blank line * * is input, the first word on the line is removed. This would be any * * characters after leading spaces, and ending with a space or the line end. * * Various extensions are tried with the command verb, and if one is found, * * the command is executed along with the rest of the command line after the * * verb, including the leading space. * * * * Problems * * * * Being very simplistic, os call errors could cause the exec to terminate on * * things like invalid characters in the command word. * * Also, since run commands would be unable to modify any evironment variables * * (current directory, permissions, etc.), functions to change these variables * * would be unworkable. * * * * Note * * * * This program was originally developed for OS/Z. * * * ******************************************************************************} program prmex(input, output); uses stddef, { extended defines } strlib, { strings library } extlib; { OS extentions } label 88; { abort current line } const linmax = 200; { number of characters in a command line } commax = 2; { number of valid command extensions } type lininx = 1..linmax; { index for line buffer } linbuf = packed array [lininx] of char; { command line } errcod = (efltl, { file name too long } ecmdnf, { command not found } eltl); { line too long } cominx = 0..commax; { index for extension table } { table of command extensions } fixed coms: packed array [1..commax, 1..3] of char = array 'com', 'exe' end; var inplin: linbuf; { command line } comfil: linbuf; { command file } com: cominx; { index for extension table } fnd: boolean; { command found } ovf: boolean; { input overflow flag } p, n, e: linbuf; { path components } r: integer; { command return } {******************************************************************************* Process error Prints an executive error and aborts the command. *******************************************************************************} procedure error(e: errcod); begin write('*** '); { print header } case e of efltl: writeln('Filename too long'); ecmdnf: writeln('Command not found'); eltl: writeln('Input line too long') end; goto 88 { abort to next line } end; {******************************************************************************* Get word Gets the first word from the given command line. This would be the first characters after any leading spaces, terminated by a space or line end. *******************************************************************************} procedure getword(var l: linbuf; var f: linbuf); var i, s: lininx; { indexes for line } begin s := index(l, ' '); { find 1st space in line } if s = 0 then error(efltl); { full line, too long } extract(f, l, 1, s-1); { get first word from string } for i := 1 to linmax-s do l[i] := l[i+s-1] { gap out word } end; begin writeln('Prmex primary executive vs. 1.0 Copyright (C) 2000 S. A. Moore'); writeln; 88: { loop next input line } repeat { read command lines and execute } repeat write('Prmex -> '); { output prompt } reads(input, inplin, ovf); { input line } readln; { terminate line } if ovf then error(eltl) { line too long } until inplin[1] <> ' '; { until line not null } getword(inplin, comfil); { strip command } com := 1; { initalize extension index } fnd := false; { set command not found } brknam(comfil, p, n, e); { break down name } repeat { search for command } copy(e, coms[com]); { add extention } maknam(comfil, p, n, e); if exists(comfil) then begin { execute command } cat(comfil, inplin); { construct full line } execw(comfil, r); { execute command } if r <> 0 then writeln('Program returned error: ', r:1); fnd := true { flag command found } end else if com <> commax then com := com + 1 { next extension } else com := 0 until fnd or (com = 0); { until found or out of extentions } if not fnd then error(ecmdnf) { error, command not found } until false { forever } end.