perm filename EADD3.2[EAL,HE]3 blob
sn#706585 filedate 1983-04-21 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 addSetup(nextLinep: cursorpp var emptyp,stok,clok: boolean
C00010 ENDMK
C⊗;
{$NOMAIN Editor: aux routines for addStmnt }
%include eedit.hdr;
{ Externally defined routines from elsewhere: }
(* From EAUX1A *)
procedure clearLine(i: integer); external;
(* From EEXPED *)
function exprEditor(line,lstart,llength,estart: integer;
var elength: integer; off: integer): ascii; external;
(* From EAUX2B *)
procedure lastStmnt(i: integer; downp: boolean); external;
(* From EAUX2C *)
procedure insertLines(start,number,coff: integer); external;
(* From ETOKEN *)
procedure getToken; external;
(* From EPUTST *)
procedure putstmnt(s: statementp; indent, plevel: integer); external;
(* From EAUX3C - addStmnt aux routines *)
procedure descend(st: statementp); external;
function elseTest(emptyp: boolean): boolean; external;
procedure restoreCursor; external;
procedure viaOk(i: integer; clOk: boolean; var viaCl: nodep;
var nextLinep: cursorpp); external;
(* From PP *)
procedure relLine(l: linerecp); external;
procedure addSetup(nextLinep: cursorpp; var emptyp,stok,clok: boolean;
var l,elen: integer; firstTime: boolean;
var echar: ascii; var viaCl: nodep); external;
procedure addSetup;
var b: boolean;
begin
with cursorStack[cursor] do (* don't point at a proc def node *)
if (not stmntp) and (nd↑.ntype = procdefnode) then cursor := cursor - 1;
with cursorStack[cursor] do
begin (* figure out where we are *)
nextLinep↑.ind := ind; (* copy current cursor info *)
nextLinep↑.stmntp := stmntp;
nextLinep↑.st := st; (* also copies nd pointer *)
emptyp := false; (* assume we need to add a new line *)
if stmntp then emptyp := st↑.stype = emptytype; (* unless we can use current one *)
end;
viaCl := nil;
if emptyp then
begin
if not fParse then
begin
l := cursorLine - topDline + 1; (* offset into line array *)
relLine(lines[l]); (* release old empty line *)
lines[l] := nil;
clearLine(l-firstDline+1); (* clear line *)
end;
clOk := false; (* only accept a statement *)
stOk := true;
end
else
begin (* need to insert a new line *)
insertLines(cursorLine,1,1);
if not nextLinep↑.stmntp then
begin (* if it isn't a statement neither are we *)
stOk := nextLinep↑.nd↑.ntype = clistnode; (* unless it's a case label *)
clOk := not stOk;
with nextLinep↑.nd↑ do
if ((ntype = viaptnode) or (ntype = byptnode)) and (fieldNum > 1) then
viaCl := nextLinep↑.nd
else viaOk(1,clOk,viaCl,nextLinep);
end
else if sParse and (cursor <= sCursor) then
begin (* if last is a motion statement then clause is ok *)
descend(cursorStack[sCursor].st);
with cursorStack[cursor].st↑ do
clOk := (movetype <= stype) and (stype <= floattype);
stOk := false; (* statements are no good here *)
viaOk(0,clOk,viaCl,nextLinep);
cursor := sCursor; (* pop back *)
end
else
begin (* see if it's in a block, coblock or case *)
with cursorStack[cursor-1] do
if stmntp then
stOk := (st↑.stype = blocktype) or (st↑.stype = coblocktype) or
(st↑.stype = casetype)
else stOk := (nd↑.ntype = clistnode) or (nd↑.ntype = colistnode);
l := cursorLine;
lastStmnt(1,true); (* see if last statement can have clauses *)
with cursorStack[cursor].st↑ do
clOk := (movetype <= stype) and (stype <= floattype);
viaOk(0,clOk,viaCl,nextLinep);
cursorLine := l;
restoreCursor;
end
end;
if viaCl <> nil then
begin
b := true;
while b and (viaCl↑.next <> nil) do (* find correct VIA/BY node *)
with viaCl↑.next↑ do
if (ntype = viaCl↑.ntype) and vlist then viaCl := viaCl↑.next
else b := false;
end;
if firstTime then
begin (* get insertion *)
elen := 1;
listing[1] := ' ';
echar := exprEditor(cursorLine-topDline-firstDline+2,1,1,1,elen,0);
end;
if not fParse then flushcomments := false (* comments are ok here *)
else if clOk then flushcomments := true (* so don't loose any clauses *)
else if stOk then
begin
flushcomments := true; (* assume comments are no good here *)
with cursorStack[cursor-1] do
if stmntp then
if st↑.stype = blocktype then (* comments have to be in block *)
if nextLinep↑.stmntp then
begin
flushcomments := not elseTest(emptyp);
restoreCursor;
end;
end;
(* figure out what we're inserting: statement, label, clause *)
with curToken do
repeat getToken until (ttype <> delimtype) or (ch <> ';'); (* skip semi's *)
flushcomments := true; (* don't allow comments anywhere else *)
end;