UNIX Free Pascal


wallko.ru

smallsh - 4


const

special:array [0..5] of char = (' ', #9, '&', ';', #$a, #0);

function inarg(c:char):boolean;

var

wrk:pchar;

begin

wrk := special;

while wrk^<>#0 do

begin

if c = wrk^ then

begin

inarg:=false;

exit;

end;

inc(wrk);

end;

inarg:=true;

end;

, . procline , gettok, . , runcommand. , userin.

{$i smallsh.inc}

function procline:integer; (* *)

var

arg:array [0..MAXARG] of pchar; (* runcommand *)

toktype:integer; (* *)

narg:integer; (* *)

_type:integer; (* *)

begin

narg := 0;

while true do (* *)

begin

(* *)

toktype := gettok (@arg[narg]);

case toktype of

2://ARG

if narg < MAXARG then

inc(narg);

1,3,4://EOL,SEMICOLON, AMPERSAND:

begin

if toktype = AMPERSAND then

_type := BACKGROUND

else

_type := FOREGROUND;

if narg <> 0 then

begin

arg[narg] := nil;

runcommand (arg, _type);

end;

if toktype = EOL then

exit;

narg := 0;

end;

end;

end;

end;

runcommand, . runcommand , docommand, .