perm filename SAILOG.SAI[S,AIL] blob sn#013169 filedate 1972-11-18 generic text, type T, neo UTF8
COMMENT ⊗   VALID 00008 PAGES 
RECORD PAGE   DESCRIPTION
 00001 00001
 00002 00002	BEGIN "SAILOG"
 00005 00003	INTEGER ARRAY MONTH[1:12]
 00007 00004	INTEGER I,J,DATE,FN,NUM1,NUM2,NUM,MODE
 00010 00005	DUN:
 00012 00006	
 00015 00007	WRITE:
 00018 00008	EOF← 0
 00021 ENDMK
⊗;
BEGIN "SAILOG"


DEFINE  TAB="'11", LF="'12", FORM="'14", CR="'15", BB="&"" ""&",
 	ALT="'33", DEL="'177", ↓="&'15&'12", CREEP="(CR&DEL&'21)";

DEFINE  α="COMMENT", TIL="STEP 1 UNTIL", LN="LENGTH",
	SAY="OUTSTR", PROC="SIMPLE PROCEDURE";

INTEGER INCH,OUCH,CNT,BRK,EOF,FLAG;	α INPUT/OUTPUT GLOBALS;

FORWARD STRING PROCEDURE UPPER(STRING S);
STRING PROC ASK(STRING S);
	BEGIN  OUTSTR(S);  RETURN(UPPER(INCHWL))  END;

STRING T;
DEFINE DSKI="OPEN(INCH←GETCHAN,""DSK"",1,4,0,CNT←200,BRK,EOF)",
	DSKO="OPEN(OUCH←GETCHAN,""DSK"",1,0,4,0,0,0)",
	FILI(FILED)="BEGIN LABEL TRY;
 	            TRY: LOOKUP(INCH,T← FILED,FLAG);
		    IF FLAG THEN  BEGIN FILED←ASK(""FILE NOT FOUND. AGAIN PLEASE:""); GO TRY; END;
	    	    END",
	FILO(FILE)="ENTER(OUCH,FILE,FLAG)",
	LPTO="OPEN(OUCH←GETCHAN,""LPT"",1,0,2,0,0,EOF←0)",
	TTYI="OPEN(INCH←GETCHAN,""TTY"",1,2,0,CNT←200,BRK,EOF)",
	TTYO="OPEN(OUCH←GETCHAN,""TTY"",1,0,2,0,0,0)";

PROC FILIN(STRING F);  BEGIN  DSKI; FILI(F) END;

PROC FILOUT(STRING F);  BEGIN DSKO; FILO(F) END;


STRING BLANKS;
DEFINE PREPARE="STDBRK(GETCHAN);  SETBREAK(13,TAB&"":"",NULL,""INS"");
BLANKS←""                                                                                                                        """,
	INLINE="INPUT(INCH,1)",  TOTAB(S)="SCAN(S,13,BRK)";

STRING PROC LEFT(INTEGER L; STRING S);
	RETURN(IF LN(S)<L THEN S&BLANKS[1 TO L-LN(S)] ELSE S[1 TO L]);

STRING PROC RIGHT(INTEGER L; STRING S);
	RETURN(IF LN(S)<L THEN BLANKS[1 TO L-LN(S)]&S  ELSE S[1 TO L]);

STRING PROC CENTER(INTEGER L; STRING S);
	RETURN(IF LN(S)<L THEN BLANKS[1 TO (L-LN(S))DIV 2]&
		S & BLANKS[1 TO (L-LN(S)+1)DIV 2] ELSE S[1 TO L]);

INTEGER ARRAY MONTH[1:12];

DEFINE SCN="18",CHAR="16",FOO="17";	α BREAK TABLES;

EXTERNAL PROCEDURE SPOOL(STRING S;  INTEGER IOCHAN,FLAGS);

INTEGER PROC DATI(STRING DATE);  BEGIN
	INTEGER D,I,BR;
	D←0;
	WHILE LN(DATE) DO BEGIN "SCAN"
		I←SCAN(DATE,FOO,BR);  α FLUSH SPACES, ETC. ;
		IF "1"≤ DATE ≤"9" THEN BEGIN "DAY OR YEAR"
			I←INTSCAN(DATE,BR);
			IF I<32 THEN D←D+I-1 ELSE BEGIN "YEAR"
				IF I<100 THEN I←I+1900;
				D←D+(I-1964)*372
				END
			END
		ELSE BEGIN "MONTH"
			INTEGER MI;
			MI← CVSIX(DATE[1 FOR 3]);
			FOR I← 1 TIL 12 DO IF MI=MONTH[I] THEN DONE;
			IF I>12 THEN RETURN(-1);
			D←D+(I-1)*31;
			I←SCAN(DATE,6,BR);  α FLUSH MONTH;
			END;
		END;
	IF D<372 THEN BEGIN
		INTEGER T;  T←CALL(0,"DATE");
		D←D+372*(T%372-(IF D>(T MOD 372) THEN 1 ELSE 0))
		END;
	RETURN(D)
	END;

BOOLEAN PROC CONTAINS(STRING LARGE,SMALL);
	BEGIN INTEGER I,L,VAL,S;
	VAL← 0;
	IF (S←LN(SMALL))=0 THEN RETURN(TRUE);
	IF (L←LN(LARGE))=1 THEN RETURN (LARGE=SMALL)
	ELSE FOR I← 1 TIL L DO VAL← VAL ∨ (LARGE[I FOR 1]=SMALL);
	RETURN(VAL);
	END;
INTEGER I,J,DATE,FN,NUM1,NUM2,NUM,MODE;
INTEGER DAY,YEAR,HOUR,MINUTE,LE,MNO;
STRING  F,S,TYPE,HWSW,DEV,LNAME,PP,PN;
STRING  ARRAY M[1:21];
BOOLEAN GOOD,SPL,FOUND;
LABEL   BACK,WRITE,TYPI,HSI,DEVI,EXIT,START,INP,MSG;
DEFINE BARF(S)= "BEGIN CLRBUF; SAY(""S""↓); GO BACK; END";

BOOLEAN PROCEDURE DECIDE(INTEGER MODE; STRING V);
	BEGIN 
	CASE MODE OF
		BEGIN 
		RETURN(TRUE); α PLACE KEEPER;
		RETURN(NUM1 = (NUM← CVD(V)));
		RETURN((NUM1 MAX (NUM← CVD(V)) MIN NUM2)=NUM);
		RETURN(TRUE);
		END;
	END;


PROCEDURE SEARCH(INTEGER MDE,DAYTE;STRING TY,HW,DE);
	BEGIN
	LABEL DUN;
	GOOD← FOUND← EOF← 0;
	FILIN("LOG[S,AIL]");

	WHILE ¬EOF DO
	   BEGIN
	   IF (S←INLINE)="π" ∧ (GOOD← DECIDE(MDE,TOTAB(T←S[2 TO ∞]))
				  ∧ (DAYTE≤DATI(TOTAB(T)))
				  ∧ CONTAINS(TOTAB(T),TY[1 FOR 1])
				  ∧ CONTAINS(TOTAB(T),HW[1 FOR 1])
				  ∧ CONTAINS(TOTAB(T),DE[1 FOR 1])  ) THEN
		BEGIN
		IF ¬FOUND THEN 
			BEGIN
			FOUND← TRUE;
			IF SPL THEN FILOUT(F← "LOG"&(FN←FN+1)&".TMP") ELSE TTYO;
			END;
		OUT(OUCH,""↓&"******************************************"↓);
		END
	   ELSE CASE MDE OF
		BEGIN
		I← 0; α PLACE KEEPER;
		IF NUM1<NUM THEN GO DUN;
		IF NUM2<NUM THEN GO DUN;
		I← 0;      α JUST TO KEEP THE PLACE;
		END;

  	   IF GOOD THEN OUT(OUCH,(IF S="π" THEN S[2 TO ∞] ELSE S) ↓);
	   END;

DUN:
	RELEASE(INCH);
	SAY("" ↓ ↓);
	IF FOUND THEN
		BEGIN 
		RELEASE(OUCH);
		IF SPL THEN SPOOL(F,GETCHAN,1);
		END
	ELSE OUTSTR("None found."↓);
	END;


STRING PROCEDURE UPPER(STRING S);
	BEGIN INTEGER J; STRING T;
	T← NULL;
	WHILE LN(S) DO
	  T← T & (IF (J←LOP(S))≥'141 THEN (J XOR '40) ELSE J);
	RETURN (T);
	END;


PROCEDURE SENDSG(STRING ARRAY MESS; INTEGER I);
	BEGIN STRING HACKER,F; INTEGER J;
       	FOR HACKER← "RHT","JRL","DCS","HJS"
	 DO
		BEGIN
		FILOUT(F← "   "&HACKER&".MSG[2,2]");
		DSKI;
		LOOKUP(INCH,F,FLAG);
		IF ¬FLAG THEN WHILE ¬EOF DO OUT(OUCH,INLINE ↓);
		IF ¬FLAG THEN OUT(OUCH,"" ↓ ↓);
		RELEASE(INCH);   EOF← 0;
		FOR J← 1 TIL I DO IF MESS[J] THEN OUT(OUCH,MESS[J] ↓);
	        OUT(OUCH,RIGHT(65,CVS(DAY) BB CVXSTR(MONTH[MNO]) BB PP &","& PN) ↓);
		OUT(OUCH, ""↓);
		RELEASE (OUCH);
		END;
	END;

PREPARE;
SETBREAK(SCN,LF&ALT,CR&FORM,"INS");
SETBREAK(FOO,TAB&LF&", ",CR&FORM,"XNR");

SAY(""↓ ↓ & CENTER(65,"SAIL SYSTEM LOG") ↓ & CENTER(65,"***************") ↓ ↓ );
FILIN("LOG[S,AIL]");
SAY("LATEST ENTRY IS NUMBER "&CVS(LE← CVD(INLINE)) ↓ ↓);
RELEASE(INCH);
FN← "0";
I←0;
FOR S← "JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP",
       "OCT","NOV","DEC" DO MONTH[I←I+1]← CVSIX(S);

START:  IF (S←ASK("Read,Write,Instructions,Message, or Exit?"))="W" THEN GO WRITE ELSE
	IF S="I" THEN
		BEGIN
		FILIN("LOG[S,AIL]");
		S← INLINE;  α IGNORE THE LATEST ENTRY NUMBER;
		S← INLINE; α IGNORE THE CATEGORY LINE ALSO;
		TTYO;
		FOR I← 1 TIL 58 DO OUT(OUCH,INLINE ↓);
		OUT(OUCH,NULL ↓ ↓ ↓);
		RELEASE(INCH);
		RELEASE(OUCH);
		GO START;
		END
ELSE IF S="M" THEN
	BEGIN TYPE← "M"; GO MSG; END 
	ELSE IF S="E" THEN GO EXIT;




BACK: NUM1←NUM2←NUM← 0;
S←ASK("#(s)    Date    Type    HW/SW   Dev     * to spool"↓);


IF SPL←(S[∞ FOR 1]="π") THEN S←S[1 TO ∞-1];
IF (F←TOTAB(S)) THEN IF ((NUM1← CVD(F))≤0) THEN BARF("Bad entry number.");
IF (BRK=":") THEN IF (NUM2←CVD(TOTAB(S)))≤0 THEN BARF("Bad entry number after colon.");
MODE← IF NUM1 THEN IF NUM2 THEN 2 ELSE 1 ELSE 3;
IF (DATE←DATI(TOTAB(S)))<0 THEN BARF("Bad date.");
IF (TYPE← TOTAB(S)) THEN IF ¬CONTAINS("TRCNXW",TYPE[1 FOR 1]) THEN BARF("Bad entry type.");
IF (HWSW←TOTAB(S)) THEN IF ¬CONTAINS("HS?",HWSW[1 FOR 1]) THEN BARF("Bad HW/SW choice.");
IF (DEV←TOTAB(S)) THEN IF ¬CONTAINS("ACSL", DEV[1 FOR 1])  THEN BARF("Bad device name.");


SEARCH(MODE,DATE,UPPER(TYPE),UPPER(HWSW),UPPER(DEV));


GO START;

WRITE:

TYPI: IF ¬CONTAINS("TRNCMW",TYPE←ASK("" ↓ &"Entry type [Trouble,Repair,Change,New,Warning]?")) THEN
	BEGIN  SAY("Bad type."); GO TYPI; END;
HSI:  IF ¬CONTAINS("HS?",HWSW←ASK("HW, SW,or '?'")) THEN
	BEGIN  SAY("Bad choice."); GO HSI; END;
DEVI: IF ¬CONTAINS("ACSL",DEV←ASK("Device [Arm,Cohu,Sierra,Library]?")) THEN
	BEGIN  SAY("Bad device."); GO DEVI; END;
IF DEV[1 FOR 1]="L" THEN LNAME←ASK("Which program?") ELSE LNAME← NULL;
IF (S← ASK(""↓&"Entry to be labeled   "BB TYPE BB HWSW BB DEV BB LNAME &
	    ",   OK [Y or N]?"))  = "N" THEN GO WRITE;


MSG:
HOUR← (I← CALL(0,"TIMER")) DIV 216000;
MINUTE← (I MOD 216000) DIV 3600;
IF ((S← CVXSTR(CALL(0,"GETPPN")))="  SAIL") THEN 
	BEGIN LABEL DUMMY;
DUMMY:	S←ASK("" ↓&"You are logged in as S,AIL. Please give real P,PN[include comma]:");
	SETBREAK(15,",",NULL,"INS");
	PP← SCAN(S,15,BRK); PN← S;
	IF S=NULL THEN 
		BEGIN
		SAY("You were supposed to include the comma, dummy. Try again." ↓);
		GO DUMMY;
		END;
	END
ELSE
	BEGIN
	PP← S[1 FOR 3];
	PN← S[4 FOR 3];
	END;

DATE← CALL(0,"DATE");
DAY← DATE MOD 31 + 1;
MNO← ((J←((DATE-DAY+1) DIV 31)) MOD 12) + 1;
YEAR← (J - MNO + 1) DIV 12 + 64;

IF TYPE[1 FOR 1]="R" THEN
	BEGIN
	SAY("" ↓&"In the last two weeks the following entries referred to problems"&
	    " of this category."↓&"Please refer to the one you are fixing by"&
	    " giving the entry number when requested"↓&"below..." ↓ ↓);
	SPL← FALSE;
	SEARCH(3,DATE-14,"T",HWSW,DEV);
	J← CVD(ASK("Type the number of the trouble report being repaired:"));
	IF J≠0 THEN TYPE← "X";
	END
ELSE IF TYPE[1 FOR 1]="M" THEN GO INP;
EOF← 0;
FILIN("LOG[S,AIL]");
LE← CVD(INLINE);
FILOUT("LOG[S,AIL]");
OUT(OUCH,CVS(LE+1) ↓);
WHILE ¬EOF DO 
   IF TYPE[1 FOR 1]="X" THEN 
    IF ((S←INLINE)="π") ∧ (J=CVD(TOTAB(T←S[2 TO ∞])))
		THEN BEGIN OUT(OUCH,TOTAB(S)&TAB&TOTAB(S)&TAB&"X"&TAB);
			   T←TOTAB(S);OUT(OUCH,S ↓); END
		ELSE OUT(OUCH,S ↓) ELSE OUT(OUCH,INLINE ↓);
RELEASE(INCH);

OUT(OUCH,"π"&CVS(LE+1)&TAB&CVS(DAY) BB CVXSTR(MONTH[MNO])[1 FOR 3] BB CVS(YEAR)&TAB&TYPE&TAB
 		 &HWSW[1 FOR 1]&TAB&DEV[1 FOR 1] &(IF LNAME THEN "  ["& LNAME &"]" ELSE NULL) ↓);
INP:
IF ASK("Entry/Message on File or to be Typed [F or T]?")= "T" THEN
	BEGIN
	TTYI;
	SAY("Type message followed by <control><meta><line>:"↓);
	END
ELSE  
	BEGIN
	FILIN(ASK("Give file name: "));
	IF (S←INLINE)[1 TO 17]="COMMENT ⊗   VALID" THEN
		BEGIN
		α IGNORE PAGE 1 OF TV FILE;
		SETBREAK(14,FORM,NULL,"INS");
		INPUT(INCH,14);
		END
	ELSE
		BEGIN α RESTART SOS FILE FROM TOP;
		RELEASE(INCH);
		FILIN(T);
 		END;
	END;	

I← EOF← 0;
IF TYPE[1 FOR 1]≠"M" THEN
  BEGIN	WHILE ¬EOF DO IF (S←INLINE)≠NULL THEN OUT(OUCH,S ↓); END
ELSE 
	BEGIN
	WHILE ¬EOF DO
		BEGIN
		M[I←I+1]← INLINE;
		IF I=20 THEN  BEGIN SAY("Messages limited to 20 lines. Sorry"); EOF← TRUE; END;
		END;
    	SENDSG(M,I);
	SAY("" ↓ ↓);
	GO START;
	END;


SETFORMAT(-2,7);
OUT(OUCH,RIGHT(65,CVS(HOUR)&":"&CVS(MINUTE)&"   "& PP &","& PN) ↓ ↓ ↓);
RELEASE(OUCH);
SAY("" ↓ ↓);

IF TYPE[1 FOR 1]="W" THEN
	BEGIN
	M[1]←"There's a new Warning entry in the SAIL log, number "&
	     CVS(LE+1) ↓;
	SENDSG(M,1);
	END;
GO START;

EXIT: 
END;