perm filename IFN.SAI[S,AIL]1 blob sn#000817 filedate 1971-05-22 generic text, type T, neo UTF8
COMMENT ⊗   VALID 00006 PAGES
RECORD PAGE   DESCRIPTION
 00001 00001
 00002 00002	BEGIN "IFN"
 00004 00003	
 00005 00004	DEFINE NUMFLGS="11"
 00008 00005	RECURSIVE PROCEDURE DOIFN(INTEGER INSIDE,ONSW
 00012 00006	MAIN LOOP
 00013 ENDMK
⊗;
BEGIN "IFN"
COMMENT  IN A CONDITIONALLY ASSEMBLED FAIL FILE, CLEAN UP
THE TEXT BY REMOVING SECTIONS WHICH ARE UNDER FALSE CONDITIONAL 
ASSEMBLY FLAGS. THE IFN'S SURROUNDING THE TRUE PARTS ARE
ALSO REMOVED.

FOR A FLAG TO BE FOUND, ITS USE MUST BE FORMATTED CORRECTLY.
AS AN EXAMPLE, IN THE FOLLOWING:

GAG < $NEED THIS IN `GOGOL'
	LINE1
	LINE2
	LINE3
>$GAG
NOGAG <$NEED THIS IN `SAIL'
	LINE4
	LINE5
	LINE6
>$NOGAG

WHERE $ MEANS SEMI-COLON, IF GAG IS A MACRO WHICH TESTS
GAGSW TO SEE IF IT IS ON, AND IF WE WANT TO RETAIN `GAG'GED CODE
THE RESULT WOULD BE:

	LINE1
	LINE2
	LINE3

.
IF `GAG'GED CODE WERE TO BE REMOVED, WE WOULD GET THE OTHER THREE
LINES IN THE UPDATED FILE.  
 A CHANGE FILE IS ALSO CREATED, CONTAINING ALL CODE UNDER ANY OF
THESE SWITCHES OR THEIR COMPLEMENTS.;

REQUIRE   "CMDSCN[1,DCS]" LOAD_MODULE;

EXTERNAL INTEGER WANTBIN,WANTLST,SRCBRK,SRCEOF,CMDBRK,RELMODE,LSTMODE,SRCMODE;
EXTERNAL INTEGER RPGSW,ON_ETIME,NX_TFIL;

EXTERNAL STRING PROCESSOR, LSTEXT, RELEXT, SRCEXT, BINFIL;
EXTERNAL PROCEDURE COMMAND_SCAN;
DEFINE NUMFLGS="11";

COMMENT THESE ARE THE NAMES OF THE SWITCHES ;
PRELOAD_WITH "COM2","GAG","EXPO","GLOB","LEP","UP","LOW","GLOC","WOM","SLS","KNT";
SAFE STRING ARRAY FLAGS[1:NUMFLGS];

COMMENT THESE ARE THE WAYS YOU WOULD LIKE TO HAVE THE SWITCHES SET;
PRELOAD_WITH TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE;
SAFE INTEGER ARRAY STATES[1:NUMFLGS];

COMMENT IF THESE ARE TRUE, THE SWITCH WILL BE IGNORED;
PRELOAD_WITH TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE;
INTEGER ARRAY IGNORE[1:NUMFLGS];

PRELOAD_WITH TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,TRUE;

SAFE INTEGER ARRAY CHGS[1:NUMFLGS];

INTEGER I,J,K,LBRSW,RBRSW,ONFLG;
INTEGER SPCL;
STRING LINES,STR,ENDSTR1;

STRING CMPSTR,ST,ST1;

DEFINE SRC="1",UPD="2",CHG="3",CMND="4",DELCHNL="5";
DEFINE TOLINE="1",TOBRCR="2";


PROCEDURE INITIALIZE;
BEGIN
   WANTBIN←WANTLST←TRUE; RELMODE←LSTMODE←SRCMODE←0;
   PROCESSOR←"IFN"; LSTEXT←"CHG"; RELEXT←"UPD"; SRCEXT←NULL;
	NX_TFIL←FALSE;
   COMMAND_SCAN; "GET COMMAND, OPEN FILE"
   SETBREAK(TOLINE,'12&'14,'15,"IN");
   SETBREAK(TOBRCR,"<"&">",NULL,"I");
 SRCEOF←0;
END "INITIALIZE";

PROCEDURE OU(INTEGER CH;STRING LN; INTEGER FL);
 IF FL THEN OUT(CH,LN);
RECURSIVE PROCEDURE DOIFN(INTEGER INSIDE,ONSW;
				STRING ENDSTR);
NEEDNEXT WHILE ¬SRCEOF DO BEGIN 
  LABEL SPROULL;

LINES←INPUT(SRC,TOLINE);
NEXT;
SPROULL:
 IF SRCBRK='14 THEN BEGIN "OUT PGMK"
	OU(UPD,'15&'14,WANTBIN); "WRITE THE FOLLOW-UP"
	OU(CHG,'15&'14,WANTLST); "WRITE THE FOLLOW-UP"
	LINES←INPUT(SRC,TOLINE); "GET ANOTHER "
	NEXT;
	GO TO SPROULL;
 END "OUT PGMK";

 LBRSW←RBRSW←FALSE; ST←LINES;

WHILE LENGTH(ST) DO BEGIN "CHECK NEST"
	ST1←SCAN(ST,TOBRCR,SRCBRK);
	IF SRCBRK = "<" THEN LBRSW←TRUE ELSE
		IF SRCBRK=">" THEN RBRSW←TRUE
END "CHECK NEST";

"LBRSW AND RBRSW HAVE ONLY INITIAL SETTINGS, PENDING FURTHER TESTS"

IF LBRSW ∧ LENGTH(LINES)≥5 THEN BEGIN "CHECK MATCH"
	CMPSTR←LINES;
	IF EQU(CMPSTR[1 FOR 2],"NO") THEN BEGIN "NO FLAG"
		CMPSTR←CMPSTR[3 TO ∞];
		ONFLG←FALSE
	END "NO FLAG" ELSE ONFLG←TRUE;

	IF (K←LENGTH(CMPSTR))≥5  THEN
	BEGIN "COULD BE"
		LABEL FOUND, NOFOUND;
		FOR I←1 STEP 1 UNTIL NUMFLGS DO BEGIN
		 K←LENGTH(STR←FLAGS[I]);
		 IF EQU(CMPSTR[1 FOR K],STR) ∧ ¬("A"≤CMPSTR[K+1 FOR 1]≤"Z") 
			THEN IF IGNORE[I] THEN DONE ELSE GO FOUND;
		END;
		LBRSW←FALSE; "ALMOST"
		GO TO NOFOUND;

	  FOUND:
		ENDSTR1←(IF ONFLG THEN NULL ELSE "NO")&FLAGS[I];
		IF INCHRS≥0 THEN SPCL←TRUE;
		IF SPCL THEN BEGIN OUTSTR(ENDSTR1&"	"&CVS(ONSW)&"	"&CVS(INSIDE)); INCHWL END;
	  NOFOUND:
	END "COULD BE"

	ELSE LBRSW←FALSE;

END "CHECK MATCH" ELSE LBRSW←FALSE;

IF RBRSW∧LENGTH(LINES)≥LENGTH(ENDSTR)+2 ∧LENGTH(ENDSTR) THEN 
BEGIN "CHECK END"
	CMPSTR←LINES;
	WHILE CMPSTR=" " DO J←LOP(CMPSTR);
	IF ¬LENGTH(ENDSTR) ∨ LENGTH(CMPSTR)<LENGTH(ENDSTR)+2 ∨ 
	 ¬EQU(CMPSTR[1 FOR LENGTH(ENDSTR)+2],">;"&ENDSTR) THEN
		RBRSW←FALSE;
END "CHECK END" ELSE RBRSW←FALSE;

IF LBRSW∧RBRSW THEN USERERR(0,0,"THE IMPOSSIBLE HAPPENED");

IF ¬LBRSW∧¬RBRSW∧ONSW THEN 
	OU(UPD,LINES&'15&'12,WANTBIN);


IF ¬LBRSW∧INSIDE ∨ LBRSW∧CHGS[I] THEN
	OU(CHG,(IF LBRSW THEN "YES" ELSE NULL)&LINES&'15&'12,WANTLST);


IF LBRSW THEN DOIFN(CHGS[I],ONSW LAND (ONFLG EQV STATES[I]),ENDSTR1)
ELSE IF RBRSW THEN RETURN;

END "DOIFN";
COMMENT MAIN LOOP;
ON_ETIME←FALSE;
SPCL←FALSE;
WHILE TRUE DO BEGIN "REPEAT"
	INITIALIZE;
	DOIFN(FALSE,TRUE,NULL);
END "REPEAT";

END "IFN"