perm filename EADD4.2[EAL,HE]2 blob sn#704731 filedate 1983-04-04 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	{$NOMAIN	Editor: aux routines for addStmnt }
C00004 00003	procedure add1Aux (var l,lcur: integer nextLinep: cursorpp var sp: statementp
C00008 ENDMK
C⊗;
{$NOMAIN	Editor: aux routines for addStmnt }

%include eedit.hdr;

{ Externally defined routines from elsewhere: }

	(* XX From EEXTRA XX *)
function elseTest: boolean;					external;

	(* From EAUX1A *)
procedure pushStmnt(s: statementp; indent: integer);		external;

	(* From EAUX1C *)
procedure errPrnt;						external;

	(* From ETOKEN *)
procedure getToken;						external;

	(* From EAUX2B *)
procedure lastStmnt(i: integer; downp: boolean);		external;

	(* From EAUX2C *)
procedure insertLines(start,number,coff: integer);		external;

	(* From EAUX3C - addStmnt aux routines *)
function getEmptyStmnt(sp:statementp): statementp;		external;
procedure flushSemi(slabel: varidefp);				external;

	(* From PP *)
procedure ppLine; 						external;
procedure ppOutNow; 						external;
procedure ppChar(ch: ascii); 					external;
procedure pp5(ch: c5str; length: integer); 			external;
procedure pp10(ch: cstring; length: integer); 			external;
procedure pp10L(ch: cstring; length: integer);			external;
procedure pp20(ch: c20str; length: integer); 			external;
procedure pp20L(ch: c20str; length: integer); 			external;

procedure add1Aux (var l,lcur: integer; nextLinep: cursorpp; var sp: statementp;
	var slabel: varidefp; var emptyp,stok,clok,nogood,labp: boolean); external;
procedure add1Aux;
 var i,j: integer; b: boolean;
 begin
 with curToken do 
  if ttype = labeldeftype then
    begin                     (* a label *)
    slabel := lab;            (* copy pointer to label *)
    cursorLine := cursorLine + 1;
    getToken;                        (* move on to start of new statement? *)
    if not endOfLine then lcur := lcur + 1;
    b := (((rtype = filtype) and (filler = defertype)) or
	  ((rtype = stmnttype) and (stmnt = cmtype)));
    if not (stOk or nextLinep↑.stmntp or (clOk and (ttype = reswdtype) and b)) then
      begin
      pp20L(' Can''t have a label ',20); pp5('here ',4); errPrnt;
      if endOfLine then nogood := true;       (* maybe there's something else? *)
      end
    end
   else if (ttype = delimtype) and (ch = '[') then
    begin                     (* a case label *)
  (* *** worry about this case later *** *)
    end
   else if (ttype = reswdtype) and (rtype = filtype) then
    if filler = elsetype then
      begin (* must be after an if-then with no else, or in a labelled case stmnt *)
  (* *** code to handle labelled case case *** *)
      j := cursor;
      b := elseTest;
      if not b then
	begin			(* add an empty statement *)
	if not fparse then flushSemi(slabel);
	for i := j to cursor do  (* update part of cursor stack that was *)
	 with cursorStack[i] do  (* just added to the stack by elseTest *)
	  if stmntp then st↑.nlines := st↑.nlines + 1;
	sp := cursorStack[cursor].st;
	sp↑.els := getEmptyStmnt(sp);
	sp := sp↑.els;
	curline := cursorLine;        (* & update cursor stack *)
	pushStmnt(sp,2);
	nextLinep↑.st := sp;
	nextLinep↑.stmntp := true;
	sp := nil;
	lcur := lcur + 1;
	cursorLine := cursorLine + 1;
	insertLines(cursorLine,1,1);
	emptyp := true;
	stOk := true;
	clOk := false;
	end;
      labp := not b;
      if b then
	begin
	pp20L(' Can''t have an "ELSE',20); pp10('" here    ',6); errPrnt;
	nogood := true;
	end
       else
	begin
	getToken;
	if endOfLine then cursorLine := cursorLine - 1;
	end
      end;
 end;