Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-03 - decus/20-0078/util/simed.sim
There are 2 other files named simed.sim in the archive. Click here to see a list.
! SIMED 2(6) ;
OPTIONS(/C/-Q/-A/-I/-D);   OPTIONS(/-W);

!   --- SIMULA Editor and Indentation program Version 2(6) ---


The SIMED program edits SIMULA source program files into  a  readable
form.

SIMED can be used to indent a SIMULA program (for better readability)
according to the BEGIN-END structure.  This is especially useful when
the program contains BEGIN-END nesting  errors,  which  usually  will
produce unhelpful compiler messages.

SIMED  may  also be used to convert reserved words, standard and user
identifiers to -
1) UPPER CASE 2) lower case 3) Edit Case (1st char.  upper case).

Lines  which  become  too  long  when indented will be split up at an
appropriate position.

If one of the following conditions holds, comments are not indented -
a) The start of the line is part of a comment or
b) The end of the line is part of an (unfinished) comment.


Command format for SIMED (example):

outfile=infile/i:4/r:80/e:13200

Default switches:
/I:4		Indent  step  4. A non-positive argument implies that
                leading  tabs  and  blanks  will  be  preserved   and
                indented according to Abs(arg).

/E:13200	Edit  Reserved words, standard ids, own ids, Comments
/E:UEL00	and Options, Text and Character constants resp. 1 (U)
                =  Upper CASE, 2 (L) = Lower Case, 3 (E) = Edit case,
                0 = no  change.                    Thus  /E:000  will
                suppress all editing.

/R:80		Outfile record length 80.

/TABS           Use tabs in indentation (default)

/C		Check for non-unique  identifiers  with  length  >=12
                (producing warnings).

Other switches:
/SIMSET		Recognize SIMSET identifiers (default for SIMSET  and
                SIMULATION blocks)
/-SIMSET        Do not recognize SIMSET ids
/SIMULATION	Recognize   SIMULATION   identifiers   (default   for
                SIMULATION blocks)
/-SIMULATION    Do not recognize SIMULATION ids
/-TABS          Do not use tabs
/NUMBERED:xx	Produce line numbers, incr. xx (def. 100) (default if
                input file has numbers).
/-NUMBERED	Suppress       line      numbers      on      output.
		(default if input file has no line numbers).
/-C             Do not check long id:s (5-20% cheaper).
/Z:n		Suppress indentation for n block levels. May be <  0,
                >=      -10,     assuming     surrounding     levels.
                Default /Z:0.
/G		Perform  last  COMPIL  command after processing, i.e.
                last COMPILE,  LOAD  or  EXECUTE  command.
!xxx		Run program xxx after processing. Thus  ABC!SOS  will
                return  to  SOS editing last file edited. The command
                NUL:!SOS is also legal.

Your own default switches can also be given in a file  SWITCH.INI  on
your area.   You need only have one or more lines of the form:

SIMED /switch/switch...

Example:  If you want files to be edited with reserved words in lower
case,  your  own  identifiers  in upper case, and standard identifiers
with  upper  case  initial  letter,  standard  indentation=2,   record
length=100, put the following line in SWITCH.INI:

SIMED /E:LEU/I:2/R:100

Trailing zeros in the E switch may be omitted -  the  system  default
will  be used in those positions.  You can always override the default
values in the command to SIMED.

Default extension is SIM.  Default outfile name is infile name. (NUL:
and TTY:  are accepted.)

If you want only default values, the command string to edit the  file
X.SIM with the same output file name is simply X.

The shortest possible command to apply SIMED to a file X.SIM is -

.R SIMED-X      (@SIMED -X in TOPS-20)

SIMED will take what follows after a minus sign as the first  command
and  exit  after  editing.   CONTINUE  will put SIMED in command mode,
expecting further commands.  START or START-<command-string> may  also
be used.

Just typing -
.R SIMED;					!

will  start  SIMED  editing the last TECO/SOS edited file (by reading
TMP:EDS) using default switches (possibly redefined in SWITCH.INI).

Exit from SIMED by entering ^Z or ^C.

Restrictions:

Split up lines will not be indented properly if they contain BEGIN or
END.

Also,  numerical  constants  containing  blanks  may  occasionally be
improperly split.  The programmer is recommended to start source  code
lines with BEGIN and END resp.

Additional feature:

If  a  text  constant  includes  <CR><LF> SIMED will ask the user for
permission to continue, in order to prevent a possible messing  up  of
the  file.   Otherwise  if one of the quotes is missing all subsequent
(correct) text  constants  might  be  destroyed  by  Upper/lower  case
editing.   "Proper" text constants containing <CR><LF> will be changed
to new concatenated text contants now allowed in SIMULA.

Author:
Mats Ohlin, Swedish Research Institute of National Defence
FOA 1, Fack, S-104 50 STOCKHOLM 80, SWEDEN
;

BEGIN
EXTERNAL TEXT PROCEDURE rest,skip,upcase,from,checkextension,
tmpin,tsub,storbokstav,conc,scanto,inline,compress,tagord;
EXTERNAL PROCEDURE exit,run,depchar;
EXTERNAL CHARACTER PROCEDURE findtrigger,fetchar;
EXTERNAL REF (Outfile) PROCEDURE findoutfile;
EXTERNAL REF (Infile) PROCEDURE findinfile;
EXTERNAL BOOLEAN PROCEDURE numbered,rescan,iashift,bokstav;
EXTERNAL INTEGER PROCEDURE scanint,search,scan;
EXTERNAL REAL PROCEDURE cptime;

TEXT initcommand,t;
INTEGER nkeys,lines,linesout;   REAL cputime,newtime;
nkeys:= 22;

IF rescan THEN
BEGIN
    Inimage; t:-Sysin.Image.Strip;
    scanto(t,'-');
    initcommand:- Copy(rest(t));
    IF initcommand = ";" OR
    (initcommand == NOTEXT AND fetchar(t,t.Length) = ';') THEN
    BEGIN   initcommand:- tmpin("EDS",FALSE);
	scanto(initcommand,' ');   initcommand:- scanto(initcommand,'/');
	initcommand:- scanto(initcommand,'%');
	WHILE initcommand.More DO
	IF initcommand.Getchar <= ' ' THEN
	BEGIN  initcommand:- initcommand.Sub(1,initcommand.Pos-2);
		initcommand.Setpos(0);
	END;
	initcommand:- initcommand.Strip;
    END tmp;
END;

Linesperpage(-1);
Outtext("SIMED - Version 2(6)");   Outimage;
BEGIN

    TEXT ARRAY key,arg,argdef[1:nkeys];   TEXT command,numfield,tbuf;
    INTEGER defkey,i,j,lineno,oldline,incr;
    REF (tree) reswdtree,standid,simsettree,simulationtree;
    REF (tree) ARRAY treearr[0:2];
    CHARACTER ctab,c;
    REF (Infile) prog;	REF (Outfile) outf;
    TEXT progname,outname,runprog;   BOOLEAN leftskip,num,longcheck;
    INTEGER proglength,indent,ma,margin,
    ind,inde,outlength,maxindent,
    begincount,endcount,zuppress;
    INTEGER ARRAY convert[2:8];
    BOOLEAN debug,tabs;
    CHARACTER ARRAY uppercase,lowercase[0:127];

    PROCEDURE inituppercase(ca);   CHARACTER ARRAY ca;
    BEGIN   INTEGER i;
	FOR i:= 1 STEP 1 UNTIL 95 DO ca[i]:= Char(i);
	FOR i:= 96 STEP 1 UNTIL 122 DO ca[i]:= ca[i-32];

	ca[123]:= ca[35];   ca[124]:= Char(124);   ca[125]:= ca[36]

    END OF INIT UPPERCASE;

    PROCEDURE initlowercase(ca);   CHARACTER ARRAY ca;
    BEGIN   INTEGER i;
	FOR i:= 1 STEP 1 UNTIL 63 DO ca[i]:= Char(i);
	FOR i:= 96 STEP 1 UNTIL 122 DO ca[i]:= ca[i-32]:= Char(i);
	FOR i:= 91 STEP 1 UNTIL 95 DO ca[i]:= Char(i);

	ca[123]:= ca[35]:= Char(123);
	ca[124]:= Char(124);
	ca[125]:= ca[36]:= Char(125)

    END OF INIT LOWERCASE;

    PROCEDURE warning(message,t);
    VALUE message,t;   TEXT message,t;
    BEGIN
	IF Pos > 1 THEN Outimage;
	Outtext("%SIMED - ");
	IF message.Length > Length THEN
	BEGIN   WHILE message.More DO Outchar(message.Getchar);
	END ELSE Outtext(message);
	t:- t.Strip;
	IF t.Length > Length THEN
	BEGIN
	    WHILE t.More DO Outchar(t.Getchar);
	    Outtext(" -")
	END ELSE Outtext(t);
	Outimage
    END OF WARNING;

    CLASS tree(case);   INTEGER case;
    BEGIN  TEXT tmain;   INTEGER h;
	! With current set of reserved words
	! and stand.id:s there will be max. 3 hits in
	! the same cell;
	TEXT ARRAY word[0:94, 1:IF case = 0 OR case = 4 THEN 1 ELSE
	!;				IF case = 3 THEN 2 ELSE 3];
	INTEGER maxhits;

	BOOLEAN PROCEDURE found(t);   TEXT t;
	BEGIN
	    h:= Rank(fetchar(t,1));
	    IF t.Length > 3 THEN
	    h:= h  +   8*Rank(fetchar(t,2)) +  64*Rank(fetchar(t,3));
	    h:= h  + 512*Rank(fetchar(t,t.Length)) + t.Length;
	    h:= Mod(h,95);
	    IF word[h,1] =/= NOTEXT THEN
	    BEGIN
		found:=
		IF maxhits = 1 THEN word[h,1] = t ELSE
		IF maxhits = 2 THEN
		(IF word[h,1] = t THEN TRUE ELSE word[h,2] = t) ELSE
		! Maxhits = 3;
		(IF word[h,1] = t THEN TRUE ELSE
		IF  word[h,2] = t THEN TRUE ELSE word[h,3] = t);
	    END not empty cell;
	END OF FOUND;

	IF case = 0 THEN
	BEGIN
	    tmain:- Copy(
	    "COMMENT"
	    "END"
	    "OTHERWISE"
	    "OPTIONS"
	    "BEGIN"
	    "WHEN"
	    "ELSE");
	    word[2,1]:- tmain.Sub(1,7);
	    word[23,1]:- tmain.Sub(8,3);
	    word[36,1]:- tmain.Sub(11,9);
	    word[53,1]:- tmain.Sub(20,7);
	    word[73,1]:- tmain.Sub(27,5);
	    word[84,1]:- tmain.Sub(32,4);
	    word[91,1]:- tmain.Sub(36,4);
	END ELSE
	IF case = 1 THEN
	BEGIN
	    tmain:- Copy(
	    "COMMENT"
	    "INSPECT"
	    "IF"
	    "NAME"
	    "REAL"
	    "IS"
	    "REF"
	    "IN"
	    "AND"
	    "END"
	    "EQV"
	    "CLASS"
	    "EQ"
	    "FALSE"
	    "OTHERWISE"
	    "LABEL"
	    "EXTERNAL"
	    "AT"
	    "DELAY"
	    "GT"
	    "THIS"
	    "DO"
	    "GO"
	    "ARRAY"
	    "OPTIONS"
	    "NOT"
	    "CHARACTER"
	    "BEFORE"
	    "STEP"
	    "GE"
	    "TO"
	    "LE"
	    "FOR"
	    "NE"
	    "NEW"
	    "BEGIN"
	    "OR"
	    "GOTO"
	    "NOTEXT"
	    "THEN"
	    "ACTIVATE"
	    "WHEN"
	    "PRIOR"
	    "SHORT"
	    "INTEGER"
	    "ELSE"
	    "TRUE"
	    "BOOLEAN"
	    "WHILE"
	    "AFTER"
	    "QUA"
	    "REACTIVATE"
	    "SWITCH"
	    "VALUE"
	    "LT"
	    "PROTECTED"
	    "LONG"
	    "UNTIL"
	    "TEXT"
	    "INNER"
	    "NONE"
	    "IMP"
	    "VIRTUAL"
	    "HIDDEN"
	    "PROCEDURE");
	    word[2,1]:- tmain.Sub(1,7);
	    word[4,1]:- tmain.Sub(8,7);
	    word[5,1]:- tmain.Sub(15,2);
	    word[8,1]:- tmain.Sub(17,4);
	    word[10,1]:- tmain.Sub(21,4);
	    word[11,1]:- tmain.Sub(25,2);
	    word[15,1]:- tmain.Sub(27,3);
	    word[16,1]:- tmain.Sub(30,2);
	    word[19,1]:- tmain.Sub(32,3);
	    word[23,1]:- tmain.Sub(35,3);
	    word[24,1]:- tmain.Sub(38,3);
	    word[26,1]:- tmain.Sub(41,5);
	    word[28,1]:- tmain.Sub(46,2);
	    word[32,1]:- tmain.Sub(48,5);
	    word[36,1]:- tmain.Sub(53,9);
	    word[37,1]:- tmain.Sub(62,5);
	    word[39,1]:- tmain.Sub(67,8);
	    word[40,1]:- tmain.Sub(75,2);
	    word[42,1]:- tmain.Sub(77,5);
	    word[46,1]:- tmain.Sub(82,2);
	    word[47,1]:- tmain.Sub(84,4);
	    word[48,1]:- tmain.Sub(88,2);
	    word[51,1]:- tmain.Sub(90,2);
	    word[52,1]:- tmain.Sub(92,5);
	    word[53,1]:- tmain.Sub(97,7);
	    word[54,1]:- tmain.Sub(104,3);
	    word[56,1]:- tmain.Sub(107,9);
	    word[57,1]:- tmain.Sub(116,6);
	    word[60,1]:- tmain.Sub(122,4);
	    word[61,1]:- tmain.Sub(126,2);
	    word[64,1]:- tmain.Sub(128,2);
	    word[66,1]:- tmain.Sub(130,2);
	    word[67,1]:- tmain.Sub(132,3);
	    word[68,1]:- tmain.Sub(135,2);
	    word[70,1]:- tmain.Sub(137,3);
	    word[73,1]:- tmain.Sub(140,5);
	    word[75,1]:- tmain.Sub(145,2);
	    word[76,1]:- tmain.Sub(147,4);
	    word[80,1]:- tmain.Sub(151,6);
	    word[81,1]:- tmain.Sub(157,4);
	    word[83,1]:- tmain.Sub(161,8);
	    word[84,1]:- tmain.Sub(169,4);
	    word[87,1]:- tmain.Sub(173,5);
	    word[88,1]:- tmain.Sub(178,5);
	    word[89,1]:- tmain.Sub(183,7);
	    word[91,1]:- tmain.Sub(190,4);
	    word[92,1]:- tmain.Sub(194,4);
	    word[2,2]:- tmain.Sub(198,7);
	    word[8,2]:- tmain.Sub(205,5);
	    word[15,2]:- tmain.Sub(210,5);
	    word[19,2]:- tmain.Sub(215,3);
	    word[42,2]:- tmain.Sub(218,10);
	    word[46,2]:- tmain.Sub(228,6);
	    word[48,2]:- tmain.Sub(234,5);
	    word[51,2]:- tmain.Sub(239,2);
	    word[52,2]:- tmain.Sub(241,9);
	    word[66,2]:- tmain.Sub(250,4);
	    word[67,2]:- tmain.Sub(254,5);
	    word[70,2]:- tmain.Sub(259,4);
	    word[83,2]:- tmain.Sub(263,5);
	    word[89,2]:- tmain.Sub(268,4);
	    word[91,2]:- tmain.Sub(272,3);
	    word[92,2]:- tmain.Sub(275,7);
	    word[15,3]:- tmain.Sub(282,6);
	    word[89,3]:- tmain.Sub(288,9);
	END ELSE
	IF case = 2 THEN
	BEGIN
	    tmain:- Copy(
	    "CALL"
	    "ABS"
	    "ENDFILE"
	    "SYSOUT"
	    "DIRECTFILE"
	    "BREAKOUTIMAGE"
	    "ARCCOS"
	    "POISSON"
	    "RANK"
	    "GETCHAR"
	    "ARCSIN"
	    "POS"
	    "EJECT"
	    "DETACH"
	    "INREAL"
	    "OUTREAL"
	    "LENGTH"
	    "BLANKS"
	    "ININT"
	    "TAN"
	    "GETFRAC"
	    "MOD"
	    "DRAW"
	    "OUTINT"
	    "OUTTEXT"
	    "NORMAL"
	    "STRIP"
	    "LINE"
	    "INFILE"
	    "INIMAGE"
	    "INCHAR"
	    "LINESPERPAGE"
	    "LOWTEN"
	    "OUTFILE"
	    "OUTIMAGE"
	    "ERLANG"
	    "OUTCHAR"
	    "PUTCHAR"
	    "SUB"
	    "MORE"
	    "HISTO"
	    "INFRAC"
	    "SETPOS"
	    "RANDINT"
	    "NEGEXP"
	    "SQRT"
	    "INTEXT"
	    "SYSIN"
	    "DISCRETE"
	    "OUTFRAC"
	    "PUTFRAC"
	    "GETREAL"
	    "MAIN"
	    "PRINTFILE"
	    "OUTFIX"
	    "GETINT"
	    "COPY"
	    "IMAGE"
	    "TANH"
	    "LOCATION"
	    "COS"
	    "SPACING"
	    "ARCTAN"
	    "LETTER"
	    "CLOSE"
	    "LASTITEM"
	    "SIGN"
	    "SIN"
	    "COSH"
	    "PUTINT"
	    "SIMULATION"
	    "DIGIT"
	    "OPEN"
	    "LINEAR"
	    "LOCATE"
	    "CHAR"
	    "SINH"
	    "SIMSET"
	    "UNIFORM"
	    "ENTIER"
	    "EXP"
	    "PUTFIX"
	    "PUTREAL"
	    "HISTD"
	    "RESUME");
	    word[2,1]:- tmain.Sub(1,4);
	    word[4,1]:- tmain.Sub(5,3);
	    word[5,1]:- tmain.Sub(8,7);
	    word[6,1]:- tmain.Sub(15,6);
	    word[8,1]:- tmain.Sub(21,10);
	    word[9,1]:- tmain.Sub(31,13);
	    word[11,1]:- tmain.Sub(44,6);
	    word[12,1]:- tmain.Sub(50,7);
	    word[13,1]:- tmain.Sub(57,4);
	    word[15,1]:- tmain.Sub(61,7);
	    word[16,1]:- tmain.Sub(68,6);
	    word[19,1]:- tmain.Sub(74,3);
	    word[20,1]:- tmain.Sub(77,5);
	    word[21,1]:- tmain.Sub(82,6);
	    word[23,1]:- tmain.Sub(88,6);
	    word[24,1]:- tmain.Sub(94,7);
	    word[25,1]:- tmain.Sub(101,6);
	    word[26,1]:- tmain.Sub(107,6);
	    word[27,1]:- tmain.Sub(113,5);
	    word[28,1]:- tmain.Sub(118,3);
	    word[30,1]:- tmain.Sub(121,7);
	    word[31,1]:- tmain.Sub(128,3);
	    word[32,1]:- tmain.Sub(131,4);
	    word[34,1]:- tmain.Sub(135,6);
	    word[35,1]:- tmain.Sub(141,7);
	    word[36,1]:- tmain.Sub(148,6);
	    word[38,1]:- tmain.Sub(154,5);
	    word[39,1]:- tmain.Sub(159,4);
	    word[41,1]:- tmain.Sub(163,6);
	    word[44,1]:- tmain.Sub(169,7);
	    word[45,1]:- tmain.Sub(176,6);
	    word[47,1]:- tmain.Sub(182,12);
	    word[48,1]:- tmain.Sub(194,6);
	    word[50,1]:- tmain.Sub(200,7);
	    word[51,1]:- tmain.Sub(207,8);
	    word[52,1]:- tmain.Sub(215,6);
	    word[56,1]:- tmain.Sub(221,7);
	    word[57,1]:- tmain.Sub(228,7);
	    word[58,1]:- tmain.Sub(235,3);
	    word[59,1]:- tmain.Sub(238,4);
	    word[61,1]:- tmain.Sub(242,5);
	    word[62,1]:- tmain.Sub(247,6);
	    word[63,1]:- tmain.Sub(253,6);
	    word[64,1]:- tmain.Sub(259,7);
	    word[65,1]:- tmain.Sub(266,6);
	    word[66,1]:- tmain.Sub(272,4);
	    word[67,1]:- tmain.Sub(276,6);
	    word[68,1]:- tmain.Sub(282,5);
	    word[70,1]:- tmain.Sub(287,8);
	    word[71,1]:- tmain.Sub(295,7);
	    word[72,1]:- tmain.Sub(302,7);
	    word[78,1]:- tmain.Sub(309,7);
	    word[84,1]:- tmain.Sub(316,4);
	    word[85,1]:- tmain.Sub(320,9);
	    word[87,1]:- tmain.Sub(329,6);
	    word[88,1]:- tmain.Sub(335,6);
	    word[91,1]:- tmain.Sub(341,4);
	    word[92,1]:- tmain.Sub(345,5);
	    word[94,1]:- tmain.Sub(350,4);
	    word[5,2]:- tmain.Sub(354,8);
	    word[6,2]:- tmain.Sub(362,3);
	    word[12,2]:- tmain.Sub(365,7);
	    word[16,2]:- tmain.Sub(372,6);
	    word[19,2]:- tmain.Sub(378,6);
	    word[24,2]:- tmain.Sub(384,5);
	    word[25,2]:- tmain.Sub(389,8);
	    word[26,2]:- tmain.Sub(397,4);
	    word[27,2]:- tmain.Sub(401,3);
	    word[34,2]:- tmain.Sub(404,4);
	    word[35,2]:- tmain.Sub(408,6);
	    word[36,2]:- tmain.Sub(414,10);
	    word[44,2]:- tmain.Sub(424,5);
	    word[45,2]:- tmain.Sub(429,4);
	    word[47,2]:- tmain.Sub(433,6);
	    word[50,2]:- tmain.Sub(439,6);
	    word[51,2]:- tmain.Sub(445,4);
	    word[62,2]:- tmain.Sub(449,4);
	    word[64,2]:- tmain.Sub(453,6);
	    word[67,2]:- tmain.Sub(459,7);
	    word[84,2]:- tmain.Sub(466,6);
	    word[87,2]:- tmain.Sub(472,3);
	    word[88,2]:- tmain.Sub(475,6);
	    word[25,3]:- tmain.Sub(481,7);
	    word[34,3]:- tmain.Sub(488,5);
	    word[50,3]:- tmain.Sub(493,6);
	END ELSE
	IF case = 3 THEN
	BEGIN
	    tmain:- Copy(
	    "SUC"
	    "CARDINAL"
	    "PRECEDE"
	    "FOLLOW"
	    "OUT"
	    "INTO"
	    "LINK"
	    "PRED"
	    "PREV"
	    "EMPTY"
	    "HEAD"
	    "FIRST"
	    "LAST"
	    "CLEAR");
	    word[0,1]:- tmain.Sub(1,3);
	    word[10,1]:- tmain.Sub(4,8);
	    word[17,1]:- tmain.Sub(12,7);
	    word[51,1]:- tmain.Sub(19,6);
	    word[55,1]:- tmain.Sub(25,3);
	    word[70,1]:- tmain.Sub(28,4);
	    word[71,1]:- tmain.Sub(32,4);
	    word[72,1]:- tmain.Sub(36,4);
	    word[73,1]:- tmain.Sub(40,4);
	    word[78,1]:- tmain.Sub(44,5);
	    word[84,1]:- tmain.Sub(49,4);
	    word[85,1]:- tmain.Sub(53,5);
	    word[90,1]:- tmain.Sub(58,4);
	    word[55,2]:- tmain.Sub(62,5);
	END ELSE
	BEGIN
	    ! Case 4;
	    tmain:- Copy(
	    "HOLD"
	    "PASSIVATE"
	    "WAIT"
	    "PROCESS"
	    "CANCEL"
	    "NEXTEV"
	    "EVTIME"
	    "ACCUM"
	    "TERMINATED"
	    "IDLE"
	    "TIME"
	    "CURRENT");
	    word[13,1]:- tmain.Sub(1,4);
	    word[19,1]:- tmain.Sub(5,9);
	    word[31,1]:- tmain.Sub(14,4);
	    word[35,1]:- tmain.Sub(18,7);
	    word[37,1]:- tmain.Sub(25,6);
	    word[45,1]:- tmain.Sub(31,6);
	    word[47,1]:- tmain.Sub(37,6);
	    word[48,1]:- tmain.Sub(43,5);
	    word[50,1]:- tmain.Sub(48,10);
	    word[58,1]:- tmain.Sub(58,4);
	    word[78,1]:- tmain.Sub(62,4);
	    word[85,1]:- tmain.Sub(66,7);
	END case 4;

	maxhits:=
	IF case = 0 OR case = 4 THEN 1 ELSE
	IF case = 3 THEN 2 ELSE 3;

    END OF TREE;
    REF (Infile) helpfile;

    TEXT PROCEDURE inl(t);   NAME t;   TEXT t;
    BEGIN   inl:- inline(t,Sysin);
	IF Sysin.Endfile THEN
	BEGIN   TEXT s;   s:- Sysin.Image;
	    Sysin.Close;   Sysin.Open(s);
	    s:- Sysout.Image;
	    Sysout.Close;   Sysout.Open(s);   inl:- NOTEXT;
	    Sysout.Linesperpage(-1);
	    IF t = "*" THEN
	    BEGIN   Outtext("Thank you!");   Outimage;   exit(0)   END;
	END
    END of inl;

    !***** Initial setup, continued ******;

    tbuf:- Blanks(60);
    FOR i:= 0,1,2 DO treearr[i]:- NEW tree(i);

    key[1]:- Copy("/SIMS");
    key[2]:- Copy("/SIMU");
    key[3]:- Copy("/E:");
    key[4]:- Copy("/E");
    key[5]:- Copy("=");
    key[6]:- Copy("/R:");
    key[7]:- Copy("/N:");
    key[8]:- Copy("/-T");
    key[9]:- Copy("/N");
    ! Avoiding explicit use of outfile definition switch[10]:;
    key[10]:- Blanks(1);   key[10].Putchar(Char(26));
    key[11]:- Copy("/I:");
    key[12]:- Copy("/I");
    key[13]:- Copy("/H");
    key[14]:- Copy("/T");
    key[15]:- Copy("/G");
    key[16]:- Copy("!");
    key[17]:- Copy("/-SIMS");
    key[18]:- Copy("/-SIMU");
    key[19]:- Copy("/Z:");
    key[20]:- Copy("/-N");
    key[21]:- Copy("/C");
    key[22]:- Copy("/-C");
    defkey:= 10;
    t:- Copy("13200 80 4");
    argdef[4]:- t.Sub(1,5);
    argdef[6]:- t.Sub(7,2);
    argdef[12]:- t.Sub(10,1);
    INSPECT findinfile("SWITCH.INI") DO
    BEGIN   Open(Blanks(132));
	Inimage;
	WHILE NOT Endfile DO
	BEGIN   t:- upcase(Image.Sub(IF numbered THEN 7 ELSE 1,5));
	    IF t = "SIMED" THEN
	    BEGIN
		t:- from(Image,6);
		scanto(t,'/');
		IF t.More THEN
		BEGIN   t.Setpos(t.Pos-1);
		    t:- rest(t);
		    IF scan(t,nkeys,arg,key,defkey) = 0 THEN
		    BEGIN   !Change defaults (not all switches possible);
			arg[5]:-arg[10]:-arg[13]:-NOTEXT;
			FOR i:= 1 STEP 1 UNTIL nkeys DO
			BEGIN   IF arg[i]=/=NOTEXT THEN
			    BEGIN
				argdef[i]:- arg[i];
				arg[i]:- NOTEXT;
	    END END END END END;
	    Inimage
	END WHILE NOT ENDFILE;
	Close
    END SWITCH.INI;
    IF argdef[3] =/= NOTEXT THEN
    BEGIN argdef[4]:- argdef[3]; argdef[3]:- NOTEXT END;
    IF argdef[4].Length<5 THEN
    BEGIN t:-Blanks(5); t:=argdef[4];
	argdef[4]:-t;
    END;
    IF argdef[11] =/= NOTEXT THEN
    BEGIN argdef[12]:- argdef[11]; argdef[11]:- NOTEXT END;
    IF initcommand =/= NOTEXT THEN
    command:- initcommand ELSE
    start:  command:- NOTEXT;
    FOR i:= 1 STEP 1 UNTIL nkeys DO
    arg[i]:- argdef[i];
    begincount:= endcount:= i:= lineno:= oldline:= linesout:=
    lines:= indent:= ma:= margin:= ind:= inde:= 0;
    ctab:= Char(9);   proglength:= 150;
    IF uppercase[Rank('a')] NE 'A' THEN
    BEGIN
	inituppercase(uppercase);   initlowercase(lowercase);
    END;

    margin:= 0;
    WHILE command == NOTEXT DO command:- inl("*");
    IF command = "?" THEN
    BEGIN
	help:	    Outtext("Command format: [outfile=]infile[/switches]");
	Outimage;
	command:- inl("For more help type ?:");
	IF command == NOTEXT THEN GOTO start;
	IF command.Getchar NE '?' THEN GOTO start;
	IF Sysout.Length < 80 THEN Sysout.Image:- Blanks(80);
	FOR helpfile:- findinfile("HLP:SIMED.HLP"),
	findinfile("SYS:SIMED.HLP"),findinfile("DSK:SIMED.HLP") DO
	INSPECT helpfile DO
	BEGIN
	    Open(Sysout.Image);
	    Inimage;
	    WHILE NOT Endfile DO
	    BEGIN   Outimage;   Inimage   END;
	    Image:= NOTEXT;   Close;   GO TO start;
	END;
	Outtext("? Cannot find HLP:/SYS:/DSK: SIMED.HLP");    Outimage;
	GO TO start;
    END ? OR /HELP ;
    i:= scan(command,nkeys,arg,key,defkey);
    IF i NE 0 THEN
    BEGIN   Outtext("? Multiple switch:");
	Outtext(key[i]);
	Outtext(" Please try again.");
	Outimage;   GO TO start;
    END loop;
    FOR i:= 1 STEP 1 UNTIL nkeys DO
    IF arg[i] == NOTEXT THEN arg[i]:- argdef[i];
    IF arg[13] =/= NOTEXT THEN
    BEGIN !/HELP switch;
	GOTO help
    END;
    arg[10]:- arg[10].Strip;
    IF arg[10] == NOTEXT THEN
    BEGIN   Outtext("? No file name entered. Please try again.");
	Outimage;   GO TO start
    END error;
    arg[10]:- checkextension(arg[10],".SIM");
    arg[5]:- arg[5].Strip;
    progname:-
    IF arg[5] == NOTEXT THEN arg[10] ELSE
    checkextension(arg[5],".SIM");
    outname:- arg[10];
    simsettree:-
    IF arg[1] == NOTEXT AND arg[2] == NOTEXT THEN NONE
    ELSE NEW tree(3);
    simulationtree:-
    IF arg[2] =/= NOTEXT THEN NEW tree(4) ELSE NONE;
    IF arg[3] == NOTEXT THEN
    arg[3]:- arg[4];
    IF arg[3] =/= NOTEXT THEN
    BEGIN
	t:- arg[3];
	IF t.Length < 5 THEN t:- conc(t,from(argdef[4],t.Length+1));
	upcase(t);
	i:= 0;   j:= 1;
	FOR j:= j + 1 WHILE t.Pos NE i AND j <= 6 DO
	BEGIN
	    i:= t.Pos;
	    c:=t.Getchar;
	    convert[j]:= IF Digit(c) THEN Rank(c)-Rank('0') ELSE
	    IF c='U' THEN 1 ELSE IF c='L' THEN 2 ELSE IF c='E' THEN 3
	    ELSE 0;
	END loop;
	FOR j:= 2,3,4,5,6 DO
	! Check that convert[2:4] are in [0:3] and [5:6] in [0:2];
	IF convert[j] < 0 OR convert[j] > (13-j)//3 THEN
	BEGIN   convert[j]:= 0;
	    Outtext("%SIMED - Edit code pos:");
	    Outint(j-1,1);   Outtext(" not correct. 0 assumed.");
	    Outimage;
	END illegal;
    END arg 3 = edit modes;
    IF arg[6] == NOTEXT THEN outlength:= 80 ELSE
    outlength:= scanint(arg[6]);
    IF outlength < 13 OR outlength > 135 THEN
    BEGIN   Outtext("%SIMED - Illegal Record length:");
	Outtext(arg[6]);   Outtext(" - 80 assumed.");
	Outimage;
	outlength:= 80;
    END;
    IF arg[11] == NOTEXT THEN arg[11]:- arg[12];
    IF arg[11] == NOTEXT THEN
    indent:= 4 ELSE
    BEGIN
	indent:= scanint(arg[11]);
	IF indent < -10000000000 THEN indent:= - 10000000000;
	IF Sign(indent)*indent > outlength//2 THEN
	BEGIN   Outtext("%SIMED - Illegal Indent value:");
	    Outtext(arg[11]);   Outtext("  - 4 assumed.");   Outimage;
	    indent:= 4;
	END error;
    END indent;
    leftskip:= indent > 0;   indent:= Sign(indent)*indent;
    maxindent:= outlength - 20;
    IF maxindent < indent THEN maxindent:= indent;

    tabs:= IF arg[14] == argdef[14] THEN arg[8] == NOTEXT ELSE
    IF arg[8] == argdef[8] THEN arg[14] =/= NOTEXT ELSE
    arg[8] == NOTEXT;

    longcheck:= IF arg[21] == argdef[21] THEN arg[22] == NOTEXT ELSE
    IF arg[22] == argdef[22] THEN arg[21] =/= NOTEXT ELSE
    arg[22] == NOTEXT;

    runprog:- arg[16];
    IF runprog =/= NOTEXT AND arg[15] =/= NOTEXT THEN
    BEGIN   Outtext("%SIMED - /G superseded by /RUN");
	Outimage
    END;
    IF arg[17] =/= NOTEXT THEN simsettree:- NONE;
    IF arg[18] =/= NOTEXT THEN simulationtree:- NONE;
    IF arg[19] =/= NOTEXT THEN
    BEGIN
	zuppress:= scanint(arg[19]);
	IF zuppress < -10 THEN
	BEGIN   Outtext("%SIMED - Illegal /Z value:");
	    Outtext(arg[19]);   Outtext(". 0 assumed.");
	    Outimage;   zuppress:= 0
	END ELSE
	ma:= margin:= - indent*Sign(indent)*zuppress;
    END 19;
    IF progname NE "TTY:" THEN BEGIN
	FOR prog:- findinfile(progname) WHILE prog == NONE DO
	BEGIN   Outtext("%SIMED - Cannot find Infile:");
	    Outtext(progname);   Outimage;
	    progname:- inl("Enter name of infile:");
	    progname:- checkextension(progname,".SIM");
	    IF arg[5] == NOTEXT THEN outname:- progname;
	END loop;
	prog.Open(Blanks(proglength));   prog.Inimage;
	num:= numbered;
    END not TTY ELSE
    BEGIN   prog:- Sysin;   Sysin.Image:- Blanks(proglength);   END;

    IF arg[9] =/= NOTEXT AND arg[7] == NOTEXT THEN
    BEGIN   t:- arg[9];   scanto(t,':');
	arg[7]:- IF t.More THEN rest(t) ELSE  Copy("100");
    END;
    IF arg[20] =/= NOTEXT THEN arg[7]:- NOTEXT;
    IF arg[7] =/= NOTEXT THEN
    BEGIN   incr:= scanint(arg[7]);
	IF incr <= 0 THEN
	BEGIN   Outtext("%SIMED - Illegal /N Increment:");
	    Outtext(arg[7]);   Outtext("  - 100 assumed.");
	    Outimage;   incr:= 100;
	END;
    END incr;
    IF outname NE "TTY:" THEN
    BEGIN
	IF num OR arg[7] =/= NOTEXT THEN
	outname:- conc(outname,"/NUMBERED");
	FOR outf:-
	findoutfile(outname)  WHILE outf == NONE DO
	BEGIN   Outtext("%SIMED - Cannot create Outfile:");
	    Outtext(outname);   Outimage;
	    outname:- inl("Enter name of outfile:");
	    outname:- checkextension(outname,".SIM");
	    IF num OR arg[7] =/= NOTEXT THEN
	    outname:- conc(outname,"/NUMBERED");
	END loop
    END ELSE outf:- Sysout;

    Outchar('[');
    outname.Setpos(1);   outname:- scanto(outname,'/');
    Outtext(outname);
    IF outname NE progname THEN
    BEGIN   Outtext(" <-- ");   Outtext(progname);   END;
    Outchar(':');   Breakoutimage;   Sysout.Setpos(2);

    INSPECT outf DO
    BEGIN	    	
	INSPECT prog DO
	BEGIN
	    	
	    PROCEDURE outim;
	    IF (IF arg[20] == NOTEXT THEN
	    num OR arg[7] =/= NOTEXT ELSE FALSE) THEN
	    BEGIN
		IF fetchar(outf.Image,
		(IF tabs THEN ind//8+Mod(ind,8) ELSE ind)+1) = Char(12) THEN
		BEGIN
		    outf.Image:=
		    from(outf.Image,(IF tabs THEN ind//8+Mod(ind,8) ELSE ind)+1);
		    outf.Image:- outf.Image.Main;
		    outf.Setpos(6);   outf.Image.Putchar(Char(13));
		    Breakoutimage;
		    depchar(outf.Image,6,Char(9));
		    outf.Image:- from(outf.Image,7);
		END ELSE
		BEGIN
		    linesout:= linesout + 1;
		    IF lineno < oldline OR contflag OR cutflag THEN
		    lineno:= oldline +
		    (IF arg[7] =/= NOTEXT THEN incr ELSE 1) ELSE
		    IF lineno = oldline THEN
		    lineno:= lineno +
		    (IF lineno < 50000 THEN incr ELSE
		    IF lineno < 60000 THEN 10 ELSE 2);
		    numfield.Putint(lineno);
		    numfield.Setpos(1);
		    WHILE numfield.Getchar = ' ' DO
		    depchar(numfield,numfield.Pos-1,'0');
		    outf.Image:- outf.Image.Main;
		    IF lineno > 65534 AND NOT warned THEN
		    BEGIN   warned:= TRUE;
			warning("Line number overflow at:",outf.Image);
		    END warning;
		    oldline:= lineno;
		    Outimage;
		    depchar(outf.Image,6,Char(9));
		    outf.Image:- from(outf.Image,7);
		END
	    END ELSE
	    BEGIN
		IF fetchar(outf.Image,1) = Char(12) THEN
		BEGIN   lines:= lines - 1;    Breakoutimage   END ELSE
		BEGIN   linesout:= linesout + 1;   Outimage   END;
	    END outim;

	    PROCEDURE printline(t);	 TEXT t;
	    BEGIN	 INTEGER i,j,k,olddisplay,displayi,tl;   CHARACTER c;
			
		tl:= IF oldtext THEN 0 ELSE 1;
		IF (cutflag AND textflag) OR cut_text THEN tl:= tl - 1;
		IF t.Length > outlength - outf.Pos  + tl THEN
		BEGIN   !NECESSARY TO CUT LINE;
		    FOR c:= csemicolon,cblank,ctab,ccomma DO
		    BEGIN
			j:= outlength - outf.Pos + cutpos;
			FOR i:= outlength-outf.Pos+tl STEP -1 UNTIL 2 DO
			BEGIN
			    IF (IF display[j] = 0 OR display[j] = 5
			    THEN
			    fetchar(t,i) = c ELSE FALSE) THEN GO TO cut;
			    j:= j - 1
			END  I LOOP
		    END C LOOP;
		    	
		    !FAILED:;  j:= outlength - outf.Pos + cutpos;
		    olddisplay:= display[j];
		    	
		    FOR i:= outlength-outf.Pos+tl STEP -1 UNTIL 2 DO
		    BEGIN
			IF display[j] = 5 THEN GO TO cut ELSE
			IF display[j] NE   olddisplay THEN GO TO cut;
			olddisplay:= display[j];   j:= j - 1
		    END;
		    	
		    !FAILED AGAIN:;
		    i:= outlength - outf.Pos + 1;
		    k:= cutpos+i-1;
		    cut_text:= display[k] = 6;
		    IF outf.Pos > 1 AND NOT cut_text THEN
		    BEGIN   outf.Setpos(1);   printline(t);   GO TO done   END;
		    	
		    IF NOT cut_text THEN
		    warning("Forced Cut at Line:",t);
		    	
		    cut:
		    IF oldtext THEN i:= i - 1;
		    IF (textflag AND cutflag) OR cut_text THEN i:= i - 1;
		    printline(t.Sub(1,i));   cutpos:= Pos;
		    inde:= ind;
		    IF NOT commentflag AND NOT oldcommentflag THEN
		    BEGIN
			IF tabs THEN
			WHILE inde >= 8 DO
			BEGIN Outchar(ctab);   inde:= inde - 8  END;
			outf.Setpos(outf.Pos+inde);
		    END indenting;
		    contflag:= TRUE;
		    oldtext:= oldtext OR cut_text;
		    printline(t.Sub(i+1,t.Length-i));
		    cut_text:= FALSE;
		END ELSE
		BEGIN
		    IF debug THEN
		    BEGIN   j:= cutpos;  Setpos(cutpos);
			FOR i:= 1 STEP 1 UNTIL t.Length DO
			BEGIN  Outint(display[j],1);  j:= j + 1   END;
			outim;
			inde:= ind;
			IF tabs THEN WHILE inde >= 8 DO
			BEGIN   Outchar(ctab);   inde:= inde - 8 END;
			outf.Setpos(outf.Pos+inde);
		    END Debug Output;
		    	
		    j:= cutpos + t.Length - 1;
		    IF \ cutflag AND contflag AND NOT oldtext THEN
		    BEGIN   WHILE More DO
			BEGIN   c:= Inchar;
			    IF c NE ' ' AND c NE ctab THEN GO TO skipped;
			    cutpos:= cutpos + 1
			END LOOP;
			outim;   GO TO done; !EMPTY LINE;
			skipped:
		    END ELIMINATING BLANKS AND TABS AT CUT;
		    Setpos(cutpos);
		    IF oldtext THEN  Outchar('"');
		    FOR i:= cutpos STEP 1 UNTIL j DO
		    BEGIN   displayi:= display[i];
			IF displayi <= 1 THEN Outchar(Inchar) ELSE
			BEGIN
			    IF convert[displayi] = 0 THEN Outchar(Inchar) ELSE
			    IF convert[displayi] = 1 THEN
			    Outchar(uppercase[Rank(Inchar)]) ELSE
			    IF convert[displayi] = 2 THEN
			    Outchar(lowercase[Rank(Inchar)]) ELSE
			    COMMENT CONVERT[DISPLAYI] = 3;
			    Outchar(IF displayi = olddisplay THEN
			    lowercase[Rank(Inchar)] ELSE
			    uppercase[Rank(Inchar)]);
			END CONVERSION;
			olddisplay:= displayi
		    END I LOOP;
		    IF (textflag AND cutflag) OR
		    (cut_text AND display[j] = 6) THEN
		    BEGIN
			IF fetchar(Image,j) = '"' THEN
			BEGIN
			    IF fetchar(Image,j+1) = '"' THEN
			    BEGIN
				warning("Lost "" at end of line:",outf.Image);
				Outchar('"');
			    END ELSE oldtext:= cut_text:= FALSE;
			END ELSE  Outchar('"');
		    END extra " ;
		    IF fetchar(outf.Image,outf.Pos-1) = Char(12) THEN
		    BEGIN
			IF arg[20] == NOTEXT AND
			(num OR arg[7] =/= NOTEXT) THEN outim ELSE
			BEGIN    outf.Image:- outf.Image.Sub(1,outf.Pos-1);
			    FOR c:= outf.Image.Getchar WHILE
			    c = ' ' OR c = Char(9) DO;
			    outf.Image:- outf.Image.Sub
			    (outf.Pos-1,outf.Length-outf.Pos+2);
			    Breakoutimage;   lines:= lines - 1;
			    outf.Image:- outf.Image.Main;
			END FF no line number in output;
		    END ELSE outim;
		END SHORT TEXT;
		done:
	    END OF PRINTLINE;
	    	
	    CHARACTER window,cblank,csemicolon,ccomma;   TEXT t,mainimage;
	    BOOLEAN endcommentflag,commentflag,cut_text,contflag,
	    oldcommentflag,textflag,cutflag,numericflag,
	    hit,warned,endwarn,oldtext;
	    INTEGER ARRAY display[0:proglength];
	    INTEGER i,p,markreswd,markstandid,markchar,marktext,markcomment,
	    marknumeric,markuserid,marksingle,cutpos,levelcount,level,block;
	    CLASS checker;
	    BEGIN   TEXT longid,u,s;  INTEGER p,l;
		INTEGER ARRAY blockpos[1:64];
		PROCEDURE newlevel;
		IF block > 0 AND block <= 64 THEN
		BEGIN   blockpos[block]:= p  END new *egin;

		PROCEDURE newend;
		IF block > 0 AND block <= 64 THEN
		BEGIN  longid.Sub(blockpos[block],
		    p-blockpos[block]+1):= NOTEXT;
		    p:= blockpos[block];
		    longid.Setpos(p);
		END new *nd;

		longid:- Blanks(80);
		next:  p:= longid.Pos;
		Detach;
		u:- storbokstav(conc(" ",t)).Sub(1,13);
		longid.Setpos(1);
		l:= search(longid.Sub(1,p),u);
		IF l <= p THEN
		BEGIN   u:- u.Main;
		    longid.Setpos(l+13);   s:- scanto(longid,' ');
		    u.Setpos(14);
		    IF s NE rest(u) THEN
		    warn:
		    warning("Identifier is not unique:",
		    conc(t.Sub(1,12),"[",t.Sub(13,t.length-12),"/",
		    s,"]"));
		    longid.Setpos(p);   GO TO next;
		END;
		u:- u.Main;
		! No "+1" because of the extra blank:;
		IF p + u.Length > longid.Length  THEN
		longid:- conc(longid,Blanks(80));
		longid.Sub(p,u.Length):= u;   longid.Setpos(p+u.Length);
		GO TO next;
	    END checker;

	    REF (checker) check;
	    	
	    IF longcheck THEN check:- NEW checker;
	    marknumeric:= 1;	markreswd:= 2;
	    markstandid:= 3;	markuserid:= 4;
	    markcomment:= 5;	marktext:= 6;
	    markchar:= 7;		marksingle:= 8;
	    	
	    IF outf =/= Sysout THEN outf.Open(Blanks(outlength)) ELSE
	    Sysout.Image:- Blanks(outlength);
	    numfield:- outf.Image.Sub(1,5);
	    reswdtree:- NONE;
	    IF convert[2] = convert[4] THEN
	    reswdtree:- treearr[0] ELSE
	    reswdtree:- treearr[1];
	    IF convert[3] NE convert[4] THEN
	    BEGIN   IF standid == NONE THEN standid:- treearr[2];
	    END ELSE standid:- NONE;
	    	
	    cblank:= ' ';   csemicolon:= ';';   ccomma:= ',';
	    level:= -1000;
	    IF incr <= 0 THEN incr:= 100;
	    mainimage:- Image;
	    Lastitem;   Image:- Image.Strip;
	    IF num THEN
	    BEGIN   lineno:= scanint(Image);
		IF lineno < 0 OR arg[7] =/= NOTEXT THEN
		lineno:= incr;
		Image:- from(Image,7);
	    END;
	    IF num OR arg[7] =/= NOTEXT THEN
	    BEGIN
		IF lineno = 0 THEN lineno:= incr;
		outlength:= outlength - 6;
		depchar(outf.Image,6,Char(9));
		outf.Image:- from(outf.Image.Main,7);
	    END;

	    WHILE \ Endfile DO
	    BEGIN   next:
			
		IF \ More THEN
		BEGIN

		    IF NOT oldtext AND leftskip AND Length > 1
		    AND NOT commentflag AND NOT oldcommentflag THEN
		    BEGIN   Setpos(1);   skip(Image,' ');

			WHILE More DO
			BEGIN   window:= Inchar;
			    IF window NE ' ' AND window NE ctab THEN GO TO
			    leftskipped
			END LOOP;
			leftskipped:   p:= Pos - 2;
			Image:- Image.Sub(Pos-1,Length-p);
			iashift(display,1,p+1,Length,TRUE);
		    END SKIPPING LEADING BLANKS AND TABS;
		    	
		    ind:= IF ind > 0 THEN ma ELSE margin;
		    ind:= inde:= Mod(ind,maxindent);
		    IF NOT commentflag AND NOT oldcommentflag THEN
		    BEGIN
			IF tabs THEN WHILE inde >= 8 DO
			BEGIN   Outchar(ctab);   inde:= inde - 8	 END;
			outf.Setpos(outf.Pos+inde);
		    END not comment;
		    cutflag:= textflag;   contflag:= FALSE;
		    cutpos:= 1;
		    printline(Image);
		    oldcommentflag:= commentflag;
		    ma:= margin;   ind:= 0;   oldtext:= textflag;
		    restore:  Image:- mainimage;   Inimage;
		    lines:= lines + 1;
		    IF Endfile THEN GO TO stop;
		    num:= numbered;
		    IF num THEN
		    BEGIN
			IF arg[7] =/= NOTEXT THEN
			lineno:= oldline + incr ELSE
			lineno:= scanint(Image);
			IF lineno < 0 THEN lineno:= oldline +
			(IF arg[7] =/= NOTEXT THEN incr ELSE 1);
			Image:- from(Image,7);
		    END;
		    Image:- Image.Strip;
		    IF Image == NOTEXT THEN
		    BEGIN
			IF (IF num THEN  fetchar(mainimage,6)
			= Char(12) ELSE FALSE) THEN
			BEGIN   lines:= lines - 1;   Outchar(Char(12))  END;
			outim;   GO TO restore
		    END;
		    IF levelcount = 0 AND begincount > 0 THEN
		    BEGIN   TEXT t;   levelcount:= -1000;
			t:- Blanks(5);   t.Putint(IF num THEN lineno ELSE lines+1);
			t.Setpos(1);
			WHILE t.Getchar = ' ' DO depchar(t,t.Pos-1,'0');
			t:- conc(t," ",Image);
			warning("Line(s) after last END:",t);
		    END;
		    iashift(display,1,1,0,TRUE);
		END NO MORE;
			
		IF endcommentflag THEN GO TO scanendcomment;
		IF textflag THEN GO TO scantext;
		IF commentflag THEN GO TO scancomment;
			
			
		skip(Image,' ');
		window:= Inchar;

		IF FALSE THEN
		scan:
		BEGIN   IF window = ' ' THEN
		    BEGIN   skip(Image,' ');
			IF More THEN window:= Inchar ELSE GO TO next
		    END
		END;
		IF window = ctab THEN !SKIP; ELSE
		IF window = csemicolon THEN !SKIP; ELSE
		IF bokstav(window) THEN
		BEGIN   Setpos(Pos-1);   p:= Pos;
		    t:- tagord(Image);
		    IF (IF longcheck THEN t.Length >= 12 ELSE FALSE)
		    THEN Resume(check);
		    window:= ' ';
		    IF t.Length > 1 AND t.Length < 11 THEN
		    BEGIN
			INSPECT reswdtree DO
			BEGIN   tbuf:- tbuf.Main.Sub(1,t.Length);   tbuf:= t;
			    upcase(tbuf);
			    window:= tbuf.Getchar;
			    hit:= found(tbuf)
			END
		    END ELSE
		    hit:= FALSE;
		    IF hit THEN
		    BEGIN
			FOR i:= Pos-1 STEP -1 UNTIL p DO display[i]:= 2;
			IF tbuf = "COMMENT" THEN GO TO scancomment;
			IF tbuf = "OPTIONS" THEN GO TO scancomment2;
			IF tbuf = "END" THEN
			BEGIN
			    moreends:
			    INSPECT check DO newend;
			    block:= block - 1;
			    endcount:= endcount + 1;
			    levelcount:= levelcount - 1;
			    IF levelcount = level THEN
			    BEGIN   level:= - 1000;
				simulationtree:- simsettree:- NONE
			    END;
			    IF endcount > begincount AND NOT endwarn THEN
			    BEGIN   TEXT t;
				t:- Blanks(5);
				t.Putint(IF num THEN lineno ELSE lines+1);
				t.Setpos(1);
				WHILE t.Getchar = ' ' DO depchar(t,t.Pos-1,'0');
				t:- conc(t," ",Image);
				warning("More ENDs than BEGINs at line:",t);
				endwarn:= TRUE
			    END ELSE
			    BEGIN   endwarn:= FALSE;
				margin:= margin - indent;   ind:= ind - 1;
			    END;
			    scanendcomment:
			    WHILE More DO
			    BEGIN   display[Pos]:= 5;
				window:= uppercase[Rank(Inchar)];
				IF window = ';' THEN
				BEGIN   endcommentflag:= FALSE;
				GO TO next END ELSE
				IF window = 'E' THEN
				BEGIN   p:= Pos - 1;    t:- tagord(Image);
				    tbuf:- tbuf.Main.Sub(1,t.Length);
				    tbuf:= t;
				    upcase(tbuf);
				    IF tbuf = "ND" THEN
				    BEGIN
					display[Pos-3]:= display[Pos-2]:=
					display[Pos-1]:= 2;
					GO TO moreends
				    END;
				    IF tbuf = "LSE" THEN
				    BEGIN   l4:
					display[Pos-4]:= display[Pos-3]:= 2;
					display[Pos-2]:= display[Pos-1]:= 2;
					endcommentflag:= FALSE;    GO TO next
				    END;
				    FOR i:= Pos-1 STEP -1 UNTIL p DO
				    display[i]:= 5;
				END ELSE
				IF window = 'O' THEN
				BEGIN   p:= Pos - 1;   t:- tagord(Image);
				    tbuf:- tbuf.Main.Sub(1,t.Length);
				    tbuf:= t;
				    upcase(tbuf);
				    IF tbuf = "THERWISE" THEN
				    BEGIN
					FOR i:= -9 STEP 1 UNTIL -1 DO
					display[Pos+i]:= 2;
					endcommentflag:= FALSE;   GO TO next
				    END;
				    FOR i:= Pos-1 STEP -1 UNTIL p DO
				    display[i]:= 5;
				END ELSE
				IF window = 'W' THEN
				BEGIN   p:= Pos - 1;   t:- tagord(Image);
				    tbuf:- tbuf.Main.Sub(1,t.Length);
				    tbuf:= t;
				    upcase(tbuf);
				    IF tbuf = "HEN" THEN GO TO l4;
				    FOR i:= Pos-1 STEP -1 UNTIL p DO
				    display[i]:= 5;
				END ELSE
				IF Letter(window) THEN
				BEGIN   p:= Pos - 1;   Setpos(p);   tagord(Image);
				    FOR i:= Pos-1 STEP -1 UNTIL p DO
				    display[i]:= 5;
				END OTHER WORD IN *ND-COMMENT
			    END  MORE LOOP;
			    endcommentflag:= TRUE;
			END *ND=T ELSE
			IF (IF window = 'B' THEN tbuf = "BEGIN" ELSE FALSE) THEN
			BEGIN   margin:= margin + indent;
			    begincount:= begincount + 1;
			    levelcount:= levelcount + 1;
			    block:= block + 1;
			    IF block <= 64 THEN BEGIN
			    INSPECT check DO newlevel END ELSE
			    warning("> 64 nested BEGINs:",Image);
			    IF ind < 0 THEN
			    BEGIN   ind:= 10000;
			    ma:= ma - indent   END ELSE ind:= ind+1;
			END
				
		    END RESWD ELSE
		    BEGIN
			IF t.Length > 2 AND t.Length < 14 THEN
			BEGIN
			    INSPECT standid DO
			    BEGIN
				IF window = ' ' THEN
				BEGIN
				    tbuf:- tbuf.Main.Sub(1,t.Length);   tbuf:= t;
				    upcase(tbuf);
				    window:= tbuf.Getchar;
				END;
				hit:= found(tbuf);
			    END inspect;
			    IF hit THEN
			    BEGIN
				IF window = 'S' AND convert[3] NE
				convert[4] THEN
				BEGIN
				    IF tbuf = "SIMSET" AND arg[17] == NOTEXT THEN
				    BEGIN   IF level = -1000 THEN level:=
					levelcount;
					simsettree:- NEW tree(3);
				    END tbuf = SIMSET ELSE
				    IF tbuf = "SIMULATION" AND arg[18] == NOTEXT THEN
				    BEGIN   IF level = -1000 THEN level:=
					levelcount;
					simulationtree:- NEW tree(4);
					IF simsettree == NONE THEN
					simsettree:- NEW tree(3)
				    END tbuf = SIMULATION
				END W = 'S'
			    END STANDID ELSE
			    BEGIN
				INSPECT simsettree DO hit:= found(tbuf);
				IF \ hit THEN
				INSPECT simulationtree DO hit:= found(tbuf);
			    END TESTING SYSTEM CLASS ID
			END REASONABLE TBUF.LENGTH ELSE
			BEGIN
			    IF window = ' ' THEN
			    BEGIN
				tbuf:- tbuf.Main.Sub(1,t.Length);
				tbuf:= t;   upcase(tbuf);
			    END;
			    hit:= tbuf = "LN";
			END;
				
			IF hit THEN BEGIN
			    FOR i:= Pos-1 STEP -1 UNTIL p DO display[i]:=
			markstandid END ELSE
			BEGIN
			    FOR i:= Pos-1 STEP -1 UNTIL p DO display[i]:=
			    markuserid
			END
		    END NOT RESWD
		END SOME LETTER(S) ELSE
		IF Digit(window) OR window = '&' THEN
		BEGIN   morenum:   display[Pos-1]:= 1;
		    numericflag:= window = '&';
		    IF More THEN
		    BEGIN   window:= Inchar;
			IF window = 'R' OR window = 'r' THEN window:= '0';
			WHILE (IF More THEN Digit(window) ELSE FALSE) DO
			BEGIN   display[Pos-1]:= 1;
			    numericflag:= FALSE;   window:= Inchar
			END;
			IF window = '.' THEN GO TO morenum;
			IF window = '&' THEN BEGIN  numericflag:= TRUE;
			GO TO morenum   END;
			GO TO
			IF (window = '+' OR window = '-') AND numericflag THEN
			morenum ELSE scan;
		    END MORE LOOP
		END DIGIT(S) ELSE
		IF window = ':' THEN
		BEGIN    display[Pos-1]:= 8;
		    IF More THEN
		    BEGIN   window:= Inchar;
			IF (IF window = '-' THEN TRUE ELSE window = '=') THEN
			BEGIN    display[Pos-1]:= 8;   GO TO next   END ELSE
			GO TO scan;
		    END more;
		END ELSE
		IF window = '*' THEN display[Pos-1]:= 8 ELSE
		IF window = '/' THEN display[Pos-1]:= 8 ELSE
		IF window = '=' THEN display[Pos-1]:= 8 ELSE
		IF window = '<' THEN display[Pos-1]:= 8 ELSE
		IF window = '>' THEN display[Pos-1]:= 8 ELSE
		IF window = '"' THEN
		BEGIN	 scantext:
		    window:= ' ';   display[Pos-1]:= 6;
		    WHILE (IF More THEN window NE '"' ELSE FALSE) DO
		    BEGIN     display[Pos]:= 6;	window:= Inchar   END;
		    	
		    IF window NE '"' THEN
		    BEGIN
			warning("<CR><LF> in text constant:",Image);
			warning("Type CONTINUE if OK,"
			" else correct before SIMED processing.",NOTEXT);
			exit(0);
			cutflag:= textflag:= TRUE
		    END
		    ELSE textflag:= FALSE;
		    	
		END ELSE
		IF window = ''' THEN
		BEGIN	 display[Pos-1]:= display[Pos]:= 7;
		    IF \ More THEN
		    w0: warning("Illegal character constant:",Image) ELSE
		    BEGIN   Setpos(Pos+1);
			IF \ More THEN GO TO w0;
			display[Pos]:= 7;
			window:= Inchar;
			IF window NE ''' THEN GO TO w0
		    END
		END ELSE
		IF window = '!' THEN
		BEGIN   scancomment:   p:= Pos;
		    Setpos(p);   scanto(Image,';');
		    FOR i:= Pos - 1 STEP -1 UNTIL p DO
		    display[i]:= 5;
		    commentflag:= fetchar(Image,Pos-1) NE ';';
		    IF FALSE THEN
		    scancomment2:
		    BEGIN
			textflag:= FALSE;  Setpos(Pos+1);
			WHILE (IF More THEN window NE ';' OR
			textflag   ELSE FALSE) DO
			BEGIN   IF window = '"' THEN
			    BEGIN   textflag:= NOT textflag;
				display[Pos-1]:= 6
			    END ELSE display[Pos-1]:=  IF textflag THEN 6 ELSE 5;
			    window:= Inchar
			END;
			commentflag:= window NE ';';
			display[Pos-1]:=  IF textflag THEN 6 ELSE 5;
		    END scancomment2
		END ELSE
		IF window = '\' THEN display[Pos-1]:= 8;
			
	    END BIG LOOP;
	    	
	    stop:
	    t:- prog.Image.Main;
	    Close;
	    IF prog == Sysin THEN
	    BEGIN    prog.Open(t);
		t:- Sysout.Image;   Sysout.Close;   Sysout.Open(t);
		Sysout.Linesperpage(-1);
	    END;
	END INSPECTING INPUT;
	IF outf =/= Sysout THEN Close
    END INSPECTING OUTPUT;

    IF Pos = 1 THEN BEGIN
    Outchar('[');
    outname.Setpos(1);   outname:- scanto(outname,'/');
    Outtext(outname);
    IF outname NE progname THEN
    BEGIN   Outtext(" <-- ");   Outtext(progname);   END;
    Outtext(": ");
    END;
    Outint(begincount,IF begincount < 100 THEN 2 ELSE 4);   Outtext(" BEGIN ");
    IF begincount NE endcount THEN
    BEGIN   Outtext(" ?");   Outint(endcount,4);   Outtext(" END!");   END;
    newtime:= cptime;
    Outfix(newtime-cputime,2,6);   Outtext(" Sec.");
    Outint(lines,5);
    IF lines NE linesout THEN
    BEGIN   Outtext(" In");   Outint(linesout,5);
	Outtext(" Out]");
    END ELSE Outtext(" Lines]");
    Outimage;
    cputime:= newtime;
    IF runprog =/= NOTEXT THEN
    run(runprog,1);
    IF arg[15] =/= NOTEXT THEN run("SYS:COMPIL",2);
    IF initcommand =/= NOTEXT THEN
    BEGIN   exit(0);   initcommand:- NOTEXT   END;
    GO TO start;
END
END OF PROGRAM