Google
 

Trailing-Edge - PDP-10 Archives - AP-D471B-SB_1978 - iospec.bli
There are no other files named iospec.bli in the archive.
!***COPYRIGHT (C) 1974, 1975, 1976, 1977 DIGITAL EQUIPMENT CORP., MAYNARD, MASS.***
%%
%
	THIS MODULE IMPLEMENTS THE INPUT AND OUTPUT COMMANDS.
%
%%

MODULE IOSPEC (MLIST,FSAVE,TIMER=EXTERNAL(SIX12)) =
BEGIN
	REQUIRE COMMON.BLI;
	REQUIRE ENTRY.BLI;
COMMENT(FILESPEC);

! SUBROUTINE FILESPEC
! ========== ========

! THIS ROUTINE READS A FILE SPEC FROM THE TTY AND TRIES
! TO OPEN THE FILE. IT RETURNS FALSE IF THE FILE CANNOT
! BE OPENED OR THE FILE SPEC WAS BAD. IN ADDITION
! THE GLOBAL VARIABLE INCHNL OR OTCHNL IS SET TO THE
! CHANNEL NUMBER.
! LAST MODIFIED ON 16 AUG 74 BY JG.

ROUTINE FILESPEC (TYPE) =
BEGIN
	BIND CHOICE = PLIT(0,5,5,5,5,5,1,2,		! CHOICE IS A TRANSVECTOR OF SORTS
			   5,5,5,5,5,5,5,5,		! THAT ENABLES ALL THE POSIBLE KINDS
			   5,5,5,5,5,5,5,5,		! OF FILESPECS TO BE DETECTED. NOTE THAT
			   3,5,5,5,4,5,1,2);		! MOST WON'T OCCUR BECAUSE OF PRIVIOUS ERRORS
	LOCAL	DEV,FILE,EXT,PPN,RDEV,RCOLON,
		RFILE,RPERIOD,REXT,RPPN,ROLD,
		ATOM,SIXATOM,OLDATOM,RCOMMA,
		COMPOSITE,CHANNEL,BIN;
	MAP	VARYINGCHAR ATOM;
	LABEL	LOOP,READPPN;
	MACRO	ERETURN(ERRORCODE) =			! JUST SAVES TYPING
		BEGIN
			ERTEXT(ERRORCODE);
			SEMI();
			RETURN FALSE
		END$;


	DEV _ SIXBIT 'DSK';				! DEFAULT DEVICE
	FILE _ EXT _ PPN _ NULL;			! ALL THE REST ARE NUL
	RDEV _ RCOLON _ RFILE _ RPERIOD _ REXT _ RPPN _ ROLD _ RCOMMA _ FALSE; ! WE HAVEN'T SEEN ANYTHING

LOOP:	REPEAT BEGIN					! LOOP INFINITELY UNTIL A ;
		ATOM _ TTYINT();
		IF .ATOM[LANGTH] GTR 0			! CHARACTER TOKEN
		THEN BEGIN
			IF .ATOM[LANGTH] GTR 6		! CAN'T FIT IN FILESPEC
			THEN ERETURN(11);
			SIXATOM _ CNVSIX(ATOM[STRING]<FIRSTINCR>,.ATOM[LANGTH]);! CONVERT ATOM TO SIXBIT

			% HERE WE FORM A COMPOSITE NUMBER FROM 0 TO 31
			WHICH IS UNIQUE FOR ALL POSIBLE COMBINATIONS OF
			THINGS IN A FILE SPEC. PPN'S ARE NOT INCLUDED
			IN THIS COMPOSITE, SO EFFECTIVELY THEY MAY APPEAR
			ANYWHERE. NOTE THAT MOST OF THE ENTRIES IN CHOICE
			ARE NOT USED BECAUSE THEY CONSTITUTE ERROR CONDITIONS
			THAT INVOLVE TWO OR MORE ERRORS, AND PROCESSING
			STOPS AFTER DETECTION OF THE FIRST %

			COMPOSITE _ (((.RDEV*2 +.RCOLON)*2 + .RFILE)*2 + .RPERIOD)*2 + .REXT;

			CASE .CHOICE[.COMPOSITE] OF	! SEE WHAT PATTERN THE CURRENT FILESPEC MATCHES
			SET
			%(0) NOTHING SO FAR %
			BEGIN
				IF .ROLD THEN ERETURN(12);! TWO CHAR ATOMS W/O DELIMITER
				OLDATOM _ .SIXATOM;	! WAIT AND SEE IF DEVICE OR FILENAME
				ROLD _ TRUE
			END;

			%(1) FILE. OR DEV:FILE. %
			BEGIN
				IF .ATOM[LANGTH] GTR 3 THEN ERETURN(11);! MAX LENGTH FOR EXTENTIONS IS 3
				EXT _ .SIXATOM;		! EXTENSION DISCOVERED HERE
				REXT _ TRUE
			END;

			%(2) FILE.EXT OR DEV:FILE.EXT %
			ERETURN(13);			! DUPLICATE EXTENSION (?)

			%(3) DEV: %
			BEGIN
				FILE _ .SIXATOM;	! FILE DISCOVERED HERE
				RFILE _ TRUE;
			END;

			%(4) DEV:FILE %
			ERETURN(12);			! MISSING DELIMITER BETWEEN FILE AND EXT

			%(5) DUMMY - IS NEVER EXECUTED%	0;
			TES
		END
		ELSE BEGIN				! BREAK OR SUPER ATOM
			IF .ATOM[LANGTH] EQL -40 THEN ERETURN(11); ! SUPER ATOM - CHOKE
			SELECT .ATOM[STRING] OF		! DECODE THE BREAK CHAR
			NSET
			';':	IF NOT(.RDEV OR .RFILE)	! LONE FILENAME FOUND HERE
				THEN BEGIN
					IF .ROLD
					THEN BEGIN
						FILE _ .OLDATOM;
						LEAVE LOOP
					END;
					ERTEXT(8);	! MISSING ARGUMENT
					TTYOTS(0,IF .TYPE EQL INFILE ! WHO CALLED US?
							THEN PLIT ASCIZ 'INPUT'
							ELSE PLIT ASCIZ 'OUTPUT');
					ERTEXT(9);
					RETURN FALSE
				END
				ELSE LEAVE LOOP;

			':':	IF .ROLD		! DEVICE NAMES ARE FOUND HERE
				THEN IF NOT .RCOLON AND NOT .RPERIOD
					THEN BEGIN
						DEV _ .OLDATOM;
						RDEV _ TRUE;
						ROLD _ FALSE;
						RCOLON _ TRUE
					END
					ELSE ERETURN(14) ! CAN'T FIGURE IT OUT
				ELSE IF NOT .RCOLON
					THEN ERETURN(15) ! COLON AFTER EXT - WHERE WAS DEVICE?
					ELSE ERETURN(21);! TWO :'S IN FILE SPEC

			'.':	IF .ROLD		! FILE NAMES ARE FOUND HERE ALSO
				THEN IF NOT .RPERIOD
					THEN BEGIN
						FILE _ .OLDATOM;
						RFILE _ TRUE;
						RPERIOD _ TRUE;
						ROLD _ FALSE
					END
					ELSE ERETURN(14) ! REALLY MESSED UP
				ELSE IF .RFILE AND NOT .RPERIOD
					THEN RPERIOD _ TRUE
					ELSE IF .RPERIOD
						THEN ERETURN(22) ! TWO .'S IN FILE SPEC
						ELSE ERETURN(16);! MISSING FILE NAME

			'[':	IF .RPPN		! ONLY ALOW ONE PPN!
				THEN ERETURN(43)
				ELSE READPPN: REPEAT BEGIN ! LOOP UNTIL "]"
					RPPN _ TRUE;
					IF .ROLD	! MUST NOT FORGET THE FILE[PPN] POSIBILTY
					THEN BEGIN
						FILE _ .OLDATOM;
						RFILE _ TRUE;
						ROLD _ FALSE
					END;
					ATOM _ TTYINT();
					IF .ATOM[LANGTH] GTR 0 ! HOPEFULLY AN OCTAL NUM
					THEN BEGIN
						IF CNVBIN(.ATOM,8,BIN) IS FALSE 
							THEN ERETURN(41);! NOT QUITE
						IF .PPN<LH> IS NULL ! IS IT PROJ?
						THEN PPN<LH> _ .BIN ! YES
						ELSE IF .PPN<RH> IS NULL ! SHOULD BE PROG
							THEN PPN<RH> _ .BIN
							ELSE ERETURN(41) ! TOO MUCH OF SOMETHING
					END
					ELSE BEGIN
						IF .ATOM[LANGTH] IS -40
							THEN ERETURN(41);! SUPER ATOM
						SELECT .ATOM[STRING] OF
						NSET
						',':	BEGIN
								IF .RCOMMA
									THEN ERETURN(42);! UFD'S NOT SUPPORTED
								RCOMMA _ TRUE;
								IF .PPN<LH> IS NULL ! INSERT DEFAULT
									THEN PPN<LH> _ .USRPPN<LH>
							END;
						']':	BEGIN
								IF .PPN<LH> IS NULL ! INSERT DEFAULT
									THEN PPN<LH> _ .USRPPN<LH>;
								IF .PPN<RH> IS NULL ! SAME HERE
									THEN PPN<RH> _ .USRPPN<RH>;
								LEAVE READPPN
							END;
						';':	BEGIN
								ERTEXT(41);! MISSING "]"
								RETURN FALSE
							END;
						OTHERWISE: ERETURN(41);
						TESN
					END
				END;

			OTHERWISE: ERETURN(14);		! INVALID BREAK CHAR
			TESN
		END
	END;

	CHANNEL _ GETFIL(.TYPE, IF .TYPE EQL INFILE THEN IOIBN ELSE IOASC,
			.DEV,.FILE,.EXT,.PPN,-1);
	IF .CHANNEL LSS 0 THEN RETURN FALSE
	ELSE IF .TYPE EQL INFILE
		THEN INCHNL _ .CHANNEL
		ELSE OTCHNL _ .CHANNEL;
	TRUE
END;
COMMENT(INPUT);

! SUBROUTINE INPUT
! ========== =====

! THIS ROUTINE IMPLEMENTS THE INPUT COMMAND.
! LAST MODIFIED ON 17 JUL 74 BY JG.

GLOBAL ROUTINE INPUT =
BEGIN
	IF .INCHNL NEQ -1				! CLOSE THE FILE IF ONE ALREADY EXISTS
	THEN BEGIN
		CLOFIL(.INCHNL,NOSAVE);
		INCHNL _ -1
	END;
	FILESPEC(INFILE)				! READ IN FILE SPEC
END;
COMMENT(OUTPUT);

! SUBROUTINE OUTPUT
! ========== ======

! THIS ROUTINE IMPLEMENTS THE OUTPUT COMMAND.
! LAST MODIFIED ON 17 JUL 74 BY JG.

GLOBAL ROUTINE OUTPUT =
BEGIN
	IF .OTCHNL NEQ -1				! CLOSE THE FILE IF ONE ALREADY EXISTS
	THEN BEGIN
		CLOFIL(.OTCHNL,NOSAVE);
		OTCHNL _ -1
	END;
	FILESPEC(OUTFILE)				! READ IN FILE SPEC
END;

END ELUDOM; ! END OF INPUT/OUTPUT COMMAND MODULE ...