Google
 

Trailing-Edge - PDP-10 Archives - decus_20tap2_198111 - decus/20-0052/uflip.lib
There are 2 other files named uflip.lib in the archive. Click here to see a list.
keI>kee:xkeG6 G$:G6 ke[Y?=J8[IY`[aJ8[G$:[keg#
HIN\@UFLIP LIBRARIES CONSIST OF THREE TYPES OF BLOCKS: INDEX BLOCKS,
RIB BLOCKS, AND DATA BLOCKS.  THE LIBRARY BEGINS WITH
ONE OR MORE INDEX BLOCKS CONSISTING OF A SET OF TWO WORD ENTRIES, ONE
ENTRY FOR EACH FILE IN THE LIBRARY DENOTING ITS NAME, EXTENSION AND 
LENGTH IN BLOCKS.  THE INDEX IS FOLLOWED BY THE EXTENDED LOOKUP TABLE
(RIB) FOR THE FIRST FILE IN THE LIBRARY. THIS BLOCK IS THEN
FOLLOWED BY THE FIRST FILE.  RIBS AND DATA THEN ALTERNATE THROUGGHOUT
THE LIBRARY AND ARE IN THE SAME ORDER AS THE ENTRIES IN THE INDEX.

TO ASSEMBLE, LOAD, AND SAVE THE REENTRANT UFLIP TYPE

LOAD @UFLIP
SSAVE UFLIP


WHEN UFLIP APPENDS TO A LIBRARY, IT USES THE UPDATE MODE.
THIS CAN BE A PROBLEM IF THE DISK IS NEARLY FULL AND THE LIBRARY
FILE BECOMES BADLY FRAGMENTED.  THE PROBLEM IS THAT THE INDEX OF THE
LIBRARY FILE GETS UPDATED BEFORE THE APPEND IS ATTEMPTED AND IF THE ATTEMPT
FAILS THE INDEX AND THE LAST FEW BLOCKS OF THE LIBRARY ARE
MESSED UP.  THIS CAN BE ALLEVIATED BY PREVENTING A SIMPLE APPEND, BUT
INSTEAD REQUIRING THE ENTIRE LIBRARY TO BE RECOPIED ON EACH APPEND.
THEN WHEN THE FRAGMENTATION PROBLEM OCCURS, A RESET WITHIN UFLIP
WILL NEGATE THE ENTIRE APPEND.  OF COURSE IN THIS MODE UFLIP
RUNS CONSIDERABLY SLOWER, WHILE APPENDING, AND MORE DISK SPACE
IS TIED UP DURING THE APPEND IN THAT MULTIPLE COPIES EXIST.
TO CREATE THE VERSION REQUIRING COPYING DURING AN APPEND USE

LOAD @CATCH
SSAVE UFLIP
.SP 1
.TIT ^^UFLIP A\\ ^USER ^FILE ^LIBRARY ^IMPLEMENTATION ^PROGRAM
.C
^^UFLIP A\\ ^USER ^FILE ^LIBRARY ^IMPLEMENTATION ^PROGRAM
.C
^J.^B. ^MOORHEAD
.C
17 ^JUNE 1972
.SK 2
.L 6
.ND -5
^GENERAL
.SK 1
^THE PROGRAM ^^UFLIP\\ HAS ONE PRIMARY PURPOSE: TO PROVIDE ^^PDP\\-10
USERS WITH THE CAPABILITY OF COMBINING SEVERAL SMALL DISK FILES INTO
ONE LARGER FILE (LIBRARY) IN HIS OWN AREA WITH THE PROVISION FOR
SUBSEQUENT UPDATING AND EXTRACTION.  ^THE REASONS FOR SUCH A CAPABILITY ARE:
1) TO ALLOW FOR A NUMBER OF FILES
TO BE STORED ON ^^DEC\\-TAPE, IN EXCESS OF THE NUMBER WHICH CAN BE
CONTAINED IN A ^^DEC\\-TAPE DIRECTORY, 2) TO REDUCE THE DISK BLOCK 
OVERHEAD CAUSED BY FILES OCCUPYING AN INTEGRAL NUMBER OF DISK CLUSTERS,
AND 3) TO ALLOW USERS TO CATEGORIZE GROUPS OF FILES PERTAINING TO COMMON
TASKS OR SUBJECTS.
.SK 2
.ND -5
^FUNCTIONS
.SK 1
^ALL FILES AND LIBRARIES INVOLVED MUST RESIDE ON DISK TO BE MANIPULATED
BY ^^UFLIP\\. ^IT CAN BE USED TO CREATE LIBRARIES, TO ADD FILES TO
OR DELETE FILES FROM THEM, REPLACE (UPDATE)
COPIES OF FILES IN THEM, EXTRACT FILES FROM THEM, AND LIST THEIR 
CONTENTS.
.SK 1
.L 11
.ND -5
^CREATION:####^CREATING A LIBRARY CAUSES A NEW LIBRARY,
CONSISTING OF FILES IN THE USER'S DIRECTORY OR DIRECTORIES, WHICH
MATCH FILES IN THE LIST (SEE DESCRIPTION OF LIST BELOW), TO BE FORMED.
^THE LIBRARY FILE CREATED REPLACES ANY
PREVIOUS VERSION OF A FILE WITH THE SAME NAME IN THE USER'S 
DIRECTORY.
.SK 1
.ND -5
^ADDITION:####^ADDING TO A LIBRARY CAUSES ALL FILES IN THE USER'S
DIRECTORY OR DIRECTORIES, WHICH MATCH ENTRIES IN THE LIST,
TO BE APPENDED TO THE LIBRARY FILE REGARDLESS OF THE PRIOR EXISTENCE
OF SUCH A FILE IN THE LIBRARY.  ^SHOULD THERE BE NO LIBRARY IN EXISTANCE,
ADDITION WOULD REDUCE TO CREATION.
.SK 1
.ND -5
^DELETION:####^DELETING CAUSES ALL COPIES OF ALL
FILES IN A LIBRARY, WHICH MATCH
LIST ENTRIES, TO BE DELETED FROM THE LIBRARY.
.SK 1
.ND -5
^REPLACEMENT:#^REPLACING CAUSES ALL COPIES
OF ALL FILES IN A LIBRARY, WHICH MATCH ENTRIES IN THE
LIST, TO BE REPLACED BY FILES FROM THE USER'S DIRECTORY.
^IF REPLACEMENTS ARE NOT AVAILABLE FOR ALL FILES TO BE REPLACED, THE
OLD COPY OR COPIES REMAIN IN THE LIBRARY AND IF THE USER
HAS COPIES OF A REPLACEMENT FILE ON MORE THAN ONE
STRUCTURE, THE FIRST ONE ENCOUNTERED WILL BE USED.
.SK 1
.ND -5
^EXTRACTION:##^EXTRACTING CAUSES THE LAST COPY OF EACH FILE IN A LIBRARY,
WHICH MATCHES A LIST ENTRY, TO BE CREATED OR TO REPLACE A COPY IN 
THE USER'S DIRECTORY.
.L 6
.ND -5
.SK 2
^USING ^^UFLIP\\
.SK 1
^TO RUN ^^UFLIP\\ THE USER TYPES ^^R UFLIP\\ TO THE MONITOR AND 
^^UFLIP\\ RESPONDS WITH AN "*", WHENEVER IT IS READY TO ACCEPT COMMANDS.
^THE USER THEN TYPES ONE OF THE FOLLOWING COMMANDS TO
ASK ^^UFLIP\\ TO PERFORM A DESIRED FUNCTION:
.SK 1
.NOJ
.NOF
.TAB 11,35
	LIBNAM.EXT/^C__LIST	TO CREATE A LIBRARY
	LIBNAM.EXT/^A__LIST	TO ADD TO A LIBRARY
	LIBNAM.EXT/^D__LIST	TO DELETE FROM A LIBRARY
	LIBNAM.EXT/^R__LIST	TO UPDATE A LIBRARY
	/^L__LIBNAM.EXT	TO LIST A LIBRARY (^^LONG
		##################FORM\\)
	/^F__LIBNAM.EXT	TO LIST A LIBRARY (^^SHORT
		##################FORM\\)
	LIST/^E__LIBNAM.EXT	TO EXTRACT FROM A LIBRARY
	/^H	TO TYPE ^^HELP\\ MESSAGE
.FIL
.JUS
.SK 1
WHERE LIBNAM IS THE NAME OF THE LIBRARY TO BE MANIPULATED
AND EXT IS ITS EXTENSION (THE EXTENSION MAY BE A NULL).  ^THE COMMAND
MUST BE TERMINATED BY A <^^CRLF\\> OR
<^^ALT MODE\\>.  ^THE LIST REPRESENTS THE FILE OR FILES THE USER WANTS TO
ACCESS WITHIN THE LIBRARY.  ^IT IS IN THE FORM
.SK 1
.ND 5
F1.EX1,F2.EX2,F3.EX3,...FN.EXN
.SK 1
^WILD CARDS MAY BE USED FOR FILE NAMES, EXTENSIONS, OR CHARACTERS
WITHIN THEM.  ^A "?" AT A CHARACTER POSITION WITHIN A LIST FILE NAME OR
EXTENSION CAN BE USED TO ALLOW ANY CHARACTER IN THAT POSITION TO BE CONSIDERED
AS A MATCH BY ^^UFLIP\\. ^AN "*" WITHIN A LIST FILE NAME OR EXTENSION
WOULD CAUSE ALL OF THE REMAINING CHARACTERS IN THAT NAME OR
EXTENSION TO BE CONSIDERED A MATCH BY ^^UFLIP\\.
.SK 1
^CONSIDER A LIBRARY OR USER DIRECTORY, AS APPLICABLE,
CONSISTING OF THE FOLLOWING FILES:
.L 25
.SK 1
^^PASSA
.NOF
.NOJ
PASSB
PARLIP.MAC
PARLIP.F4
PARLIP.BAK
DLIP.REL
TIME.F4
TONE.F4
TONE.REL\\
.SK 1
.JUS
.FIL
.L 6
^THE FOLLOWING LISTS WOULD BE IDENTICAL:
.SK 1
.L 11
^^P*.?A?\\ AND ^^PARLIP.MAC,PARLIP.BAK
.NOJ
.NOF
PAS*\\ AND ^^PAS*.*\\ AND ^^PASSA,PASSB
?LIP.*\\ AND ^^?LIP.REL\\ AND ^^DLIP.REL
?O*.*\\ AND ^^TONE.F4,TONE.REL
T*.F4\\ AND ^^TONE.F4,TIME.F4\\
.L 6
.JUS
.FIL
.SK 2
.ND -5
^RESTRICTIONS
.SK 1
1.###^THE NUMBER OF LIST ENTRIES SEPARATED BY COMMAS
 IN A COMMAND SPECIFICATION
MUST NOT EXCEED 64.
.SK 1
2.###^THE RESULTANT EFFECTIVE LIST FOR A COMMAND STRING MUST NOT
EXCEED 128.
.SK 1
3.###^THE NUMBER OF FILES IN A LIBRARY IS NOT LIMITED BY ^^UFLIP\\.
.SK 1
4.###^AN ATTEMPT TO INCLUDE IN A LIBRARY A FILE WITH THE SAME NAME
AND EXTENSION AS THE LIBRARY WILL USUALLY YIELD AN ERROR, WHICH IS NOT
IMMEDIATELY DETECTED.
.SK 1
5.###^WHENEVER AN ERROR OCCURS DURING THE EXECUTION OF ^^UFLIP\\,
ALL FILES REVERT TO THE FORM THEY HAD AT THE BEGINNING OF THE
EXECUTION OF THE COMMAND CAUSING THE ERROR, WITH ONE EXCEPTION:
FILES WHICH HAVE BEEN EXTRACTED
BEFORE THE ERROR EXIST IN THEIR EXTRACTED FORM.
.SK 2
.ND -5
^ERROR ^MESSAGES
.SK 1
^^UFLIP\\ TYPES THE FOLLOWING ERROR MESSAGES:
.SK 1
.L 11
.ND -5
^^SYNTAX ERROR CHARACTER\\ X:##^A GROSS SYNTAX ERROR OCCURRED
IN THE COMMAND STRING.  ^THE ILLEGAL CHARACTER WILL BE TYPED IF IT IS DETECTED
BEFORE THE END OF LINE.
.SK 1
.ND -5
^^SPECIFICATION TOO LARGE\\:##^MORE THAN 64 ENTRIES WERE IN THE COMMAND STRING.
.SK 1
.ND -5
^^SPECIFICATION ERROR\\:##^ALTHOUGH NO GROSS SYNTAX ERRORS OCCURRED, THE
COMMAND STRING WAS NOT IN ONE OF THE ACCEPTABLE FORMATS.
.SK 1
.ND -5
^^TOO MANY FILES IN LIST\\:##^MORE THAN 128 ENTRIES WERE IN THE EFFECTIVE LIST
DERIVED FROM THE COMMAND STRING.
.SK 1
.ND -5
^^LST EMPTY, NOTHING TO DO\\:##^THE EFFECTIVE LIST WAS EMPTY.
.SK 1
.ND -5
^^COULD NOT ENTER FILE\\ X:##^THERE WAS AN ERROR IN THE ATTEMPT TO ENTER THE SPECIFIED FILE
IN THE USER'S DIRECTORY.
.SK 1
.ND -5
^^INPUT ERROR ON LIBRARY FILE\\ X:##^THERE WAS AN ERROR READING THE SPECIFIED LIBRARY FILE.
.SK 1
.ND -5
^^OUTPUT ERROR ON FILE\\ X:##^THERE WAS AN ERROR WHILE WRITING THE SPECIFIED FILE.
.SK 1
.ND -5
^^ERROR READING FILE\\ X:##^THERE WAS AN ERROR READING THE SPECIFIED NON-LIBRARY FILE.
.SK 1
.ND -5
^^BAD FORM IN FILE\\ X:##^THE FORM OF THE SPECIFIED LIBRARY FILE WAS NOT IN THE PROPER
FORM FOR LIBRARY FILES.
.SK 1
.ND -5
^^SYSTEM ERROR  GAK!\\:##^AN UNEXPLAINABLE ERROR OCCURRED. ^THIS IS USUALLY
THE RESULT OF TWO LOOKUPS ON THE SAME FILE, THE SECOND OF WHICH 
FAILS.
PARLIP+LOWLIP+UFLIP
CATCH+PARLIP+LOWLIP+UFLIP
	CS
CLOUT:	RELEAS	L.,		;CLOSE OUT OUT IF WE HAVEN'T ALREADY
UFLIP:	MOVE	P,[IOWD PLEN,PDLIST] ;SET UP PUSH DOWN POINTER
	RESET			;RESET THE WORLD
	MOVE	T,.JBFF		;WHAT IS THE END OF LOW SEGMENT
	CORE	T,		;CORE DOWN TO THAT POINT
	HALT	.+1		;HALT IF WE CAN'T CORE DOWN
	SETZM	LHED		;WE HAD BETTER ZERO THIS HERE
	OUTCHR	["*"]		;SEND OUT AN ASTERISK
	INIT	D.,1		;INITIALIZE A CHANNEL FOR TTY INPUT
	SIXBIT	/TTY/
	EXP	DHED
	CAI
	INBUF	D.,1
	SETZB	S,V		;CLEAR THE WORLD
	ON	S,DOT+CMA+SLA+ARO+EOL
	SETOM	LIST		;SET LIST TO -1
	MOVE	I,[XWD LIST,LIST+1] ;SET UP FOR BLT
	BLT	I,LIST+VMAX-1	;SET ENTIRE LIST TO -1
NAMSCN:	MOVE	T,[POINT 6,R]	;GET POINTER FOR FN CHARACTERS
	SETZM	(T)		;ZERO OUT FILE NAME
	SETZM	1(T)		;ZERO OUT EXTENSION
	MOVEI	U,6		;THERE WILL BE 6 IN A FILE NAME
	JRST	NXTSCN		;GO PICK UP THE CHARACTERS
EXTSCN:	MOVE	T,[POINT 6,C]	;GET POINTER FOR EXTENSION
	MOVEI	U,3		;THERE WILL BE 3 CHARACTERS IN EXT
NXTSCN:	PUSHJ	P,INCHR		;GO GET A CHARACTER
	CAIL	W,"0"		;IS IT A NUMBER 
	CAILE	W,"Z"		;OR A LETTER
	JRST	SPECHR		;NO LOOK FOR SPECIAL CHARACTERS
	CAIGE	W,"A"		;MORE CHECKING
	CAIG	W,"9"
	CAIA
	JRST	SPECHR		;A FEW BAD CHARS IN BETWEEN
	SUBI	W,40		;YES CONVERT IT TO SIXBIT
NEEDCR:	SOJL	U,NXTSCN	;HAVE WE GOT ENOUGH CHARACTERS
DEPCHR:	IDPB	W,T		;NO PACK THIS ONE
	JRST	NXTSCN		;GO LOOK FOR MORE CHARACTERS
DONSCN:	CAIL	V,VMAX		;IS V TOO BIG
	JRST	BIGERR		;YES IT'S ALL OVER MAKE HIM TRY AGAIN
	CAIE	V,		;ALLOW NULL FIRST ENTRY
	JUMPE	R,NONE		;IS IT A NULL NAME
	MOVEM	R,LIST(V)	;PUT FILE NAME
	MOVEM	C,LIST+1(V)	;AND EXTENSION
	ADDI	V,2		;INTO FILE LIST
NONE:	FOF	S,ARO+EOL,FUN	;HAVE WE FINISHED THE LINE
	FONZ	S,FNC		;DO WE NEED A FENCE 
	ADDI	V,2		;YES PUT ONE IN BETWEEN SRCS AND DESTS
	ON	S,DOT		;ALLOW FOR A DOT AGAIN
	JRST	NAMSCN		;GO GET NEXT FILENAME
FUN:	RESET			;WHO NEEDS TTY CHAN NOW?
	FON	S,LIS,LISFIL	;GO LIST IF IT IS TO BE
	FON	S,EXT,EXTFIL	;GO EXTRACT IF IT IS TO BE
	FON	S,DEL,DELFIL	;GO DELETE IF IT IS TO BE
	FON	S,ADF,ADDFIL	;GO ADD IF IT IS TO BE
; ROUTINE TO PROCESS SPECIAL CHARACTERS
SPECHR:	CAIE	W,"."		;IS IT A DOT
	JRST	NODOT		;NO TRY SOMETHING ELSE
	FOFZ	S,DOT,SYNERR	;YES IS IT ALLOWED
	JRST	EXTSCN		;THE EXTENSION SHOULD FOLLOW
NODOT:	CAIE	W,"*"		;IS IT AN ASTERISK
	JRST	NOAST		;NO TRY SOMETHING ELSE
	MOVEI	W,77		;ENTER WILD CARD CHARACTER
	SOJL	U,NXTSCN	;DO WE NEED MORE CHARACTERS
	IDPB	W,T		;YES PUT IN A WILD CARD
	JRST	.-2		;GET MORE IF NECESSARY
NOAST:	CAIE	W,"?"		;IS IT A QUESTION MARK
	JRST	NOQST		;NO TRY SOMETHING ELSE
	MOVEI	W,77		;YES ENTER THE WILD CARD 
	JRST	NEEDCR		;GO DEPOSIT IF WE NEED IT
NOQST:	CAIE	W,"/"		;IS IT A SLASH
	JRST	NOSLA		;NO TRY SOMETHING ELSE
	FOFZ	S,SLA,SYNERR	;YES CAN WE USE A SLASH
	PUSHJ	P,INCHR		;GO GET NEXT CHARACTER
	CAIN	W,"C"		;DOES HE WANT TO CREATE A LIB
	ON	S,ADF+EOF	;YES SET UP CREATE FUNCTION
	CAIN	W,"A"		;IS  IT AN A
	ON	S,ADF+RAD	;YES SET UP ADD FUNCTION
	CAIN	W,"E"		;IS IT AN E
	ON	S,EXT		;YES SET UP EXTRACT FUNCTION
	CAIN	W,"D"		;IS IT A DELETE FUNCTION
	ON	S,DEL		;YES SET UP DELETE FUNCTION
	CAIN	W,"R"		;IS IT A REPLACE FUNCTION
	ON	S,DEL+ADF	;SET UP ADD AND DELETE FUNCTIONS
	CAIN	W,"L"		;IS IT A L
	ON	S,LIS+LNG	;YES SET UP LIST FUNCTION
	CAIN	W,"F"		;IS IT AN F
	ON	S,LIS		;YES SET UP SHORT LIST FUNCTION
	CAIE	W,"H"		;IS IT A HELP
	JRST	DONSCN		;NO NOW RETURN FILE NAME
	OUTSTR	HELP		;YES TYPE HELP MESSAGE
	JRST	CRLF		;NOW RETURN
NOSLA:	CAIE	W,"_"		;IS IT AN ARROW
	JRST	NOARO		;NO TRY SOMETHING ELSE
	FOFZ	S,ARO,SYNERR	;HAVE WE HAD AN ARROW YET
	ON	S,EOL+FNC	;NEXT WE WILL LOOK FOR AN END OF LINE
	JRST	DONSCN		;GO BACK HAVING COMPLETED SCAN
NOARO:	CAIE	W,","		;IS IT A COMMA
	JRST	NOCMA		;NO TRY SOMETHING ELSE
	FOF	S,CMA,SYNERR	;ARE THEY LEGAL
	JRST	DONSCN		;YES RETURN FILE NAME
NOCMA:	CAILE	W,15		;IS IT A  FEED CHARACTER
	CAIL	W,175		;OR AN $
	FOFZ	S,EOL,SYNERR	;ARE WE LOOKING FOR END OF LINE
	CAIN	V,		;HAVE WE ALREADY GOT SOME WORDS
	CAME	T,[POINT 6,R]	;OR PART OF A WORD
	JRST	DONSCN		;RETURN LAST FILE NAME
	EXIT			;EXIT IF A SIMPLE EOL
; ROUTINE TO LIST A LIBRARY FILE
LISFIL:	MOVE	U,LIST+3	;GET FENCE EXT
	FOF	U,1,SPCERR	;IS IT A FENCE EXTENSION
	SKIPN	N,LIST		;IS OUTPUT TO A FILE
	JRST	LISTTY		;NO USE USER'S TTY
	MOVE	E,LIST+1	;GET EXTENSION
	SETZB	R,C		;ZERO OUT DATES AND PPN
	INIT	L.,0		;INIT A DSK CHAN FOR OUTPUT
	SIXBIT	/DSK/
	XWD	LHED,0
	CAI
	ENTER	L.,N
	CAI
	JRST	LISGO		;GO START LISTING
LISTTY:	INIT	L.,0		;INIT A TTY CHANNEL FOR OUTPUT
	SIXBIT	/TTY/
	XWD	LHED,0
	CAI
LISGO:	SETZ	T,		;ZERO OUT BLOCK COUNTER
	OUTBUF	L.,2		;GET A PAIR OF OUTPUT BUFFERS
	SKIPN	N,LIST+4	;GET NAME OF LIBRARY FILE
	JRST	SPCERR		;IF ZERO THIS IS A SPCERR ERROR
	MOVE	E,LIST+5	;GET EXTIESION
	SETZB	R,C		;CLEAR OUT DATES AND PPN
	PUSHJ	P,INIDIR	;DO INIT ON DIRECTORY
	FON	S,EOF,SPCERR	;TILT IF NO LIBRARY
LISNXT:	PUSHJ	P,NXTDIR
	JUMPE	R,.-1		;WAS THIS ENTRY EMPTY
	CAIN	R,LLEN		;ARE WE INTO A FILE
	JRST	LISLNG		;YES CLOSE OUT LISTING
	FON	S,LNG,LISNXT	;NO ARE WE DOING SHORT LISTING
	MOVE	X,[POINT 6,R]	;YES GET FILE NAME POINTER
	PUSHJ	P,LISOUT	;GO LIST THE FILE NAME
	MOVEI	W,"."		;GET A DOT
	FON	C,777777000000	;IS IT A NULL EXTENSION
	PUSHJ	P,LISPEC	;NO SEND OUT A DOT
	HRRI	C,151200	;PUT CRLF INTO EXTENSION
	PUSHJ	P,LISOUT	;GO LIST EXTENSION
	JRST	LISNXT		;GO GET NEXT NAME AND EXT
LISCLS:	RELEAS	L.,		;DO A RELEASE ON THE OUTPUT CHANNEL
	JRST	UFLIP		;GO GET NEXT SET OF COMMANDS
LISOUT:	ILDB	W,X		;GET ANOTHER CHARACTER
	JUMPE	W,LISCYC	;IS IT A NULL
	FON	X,100000000,LISPEC	;IS IT ALREADY ASCII
	CAILE	W,15		;NO IS IT A SPEC CHR
	ADDI	W,40		;NO CONVERT IT TO ASCII
LISPEC:	SUBI	J,1		;KEEP TRACK OF CHARACTERS
	SOSG	LHED+2		;IS THERE SPACE IN THE BUFFER
	OUTPUT	L.,		;NO OUTPUT THE BUFFER
	IDPB	W,LHED+1	;NOW THERE IS STASH IT
LISCYC:	FON	X,760000000000,LISOUT ;ARE WE DONE WITH THIS WORD
	POPJ	P,		;YES RETURN
LISLNG:	FOF	S,LNG,LISCLS	;CLOSE IF DOING SHORT LISTING
	MOVEI	J,12		;FILE + EXT + . TAKES 10 CHARS
	MOVE	Y,DHED		;GET START OF FLE'S RIB
	MOVE	X,[POINT 6,.RBNAM(Y)] ;SET TO GET NAME
	PUSHJ	P,LISOUT	;GO SEND OUT NAME
	MOVEI	W,"."		;PICK UP A DOT
	SKIPN	.RBEXT(Y)	;IS THERE AN EXTENSION
	JRST	LISBLK		;NO FORGET IT
	PUSHJ	P,LISPEC	;YES SEND OUT THE DOT
	PUSHJ	P,LISOUT	;AND THE EXTENSION
LISBLK:	MOVE	V,.RBSIZ(Y)	;GET THE NO OF BWORDS IN FILE
	ADDI	V,177		;ROUND UP
	LSH	V,-7		;CONVERT TO BLOCKS
	ADDI	T,1(V)		;REMEMBER WHERE NEXT FILE IS
	ADDI	J,5		;NEED 5 SPACES + EMPTY IN FN AND EXT
	PUSHJ	P,LISDE2	;GO LIST BLOCKS
	MOVE	Y,.RBPRV(Y)	;PICK UP DATE
	ROTC	Y,-^D12		;SAVE DATE
	ANDI	Y,3777		;GET TIME
	SETZ	X,		;ZERO OUT X
	DIVI	X,^D60		;PUT HRS INTO X AND MINS INTO Y
	MOVEI	V,(X)		;HRS TO V ALSO
	MOVEI	J,3		;WILL NEED 3 CHARS FOR IT
	PUSHJ	P,LISDE2	;GO PRINT IT
	MOVEI	W,":"		;NEED A COLON TOO
	PUSHJ	P,LISPEC	;PRINT IT
	EXCH	U,Y		;PUT MINS IN U
	MOVEI	W,"0"		;GET A 0
	CAIG	U,^D9		;MORE THAN 9 MINS
	PUSHJ	P,LISPEC	;NO PRINT A 0
	PUSHJ	P,LISDEC	;GO PRINT MINS
	ROTC	Y,^D12		;GET THE DATE
	MOVEI	J,3		;THERE WILL BE 3 CHARS IN DAY
	SETZ	X,
	DIVI	X,^D31		;PUT DAY -1 INTO Y
	MOVEI	V,1(Y)		;PUT DAY INTO V
	PUSHJ	P,LISDE2	;GO PRINT IT
	MOVEI	Y,(X)
	SETZ	X,
	DIVI	X,^D12		;PUT MONTH -1 INTO Y
	MOVEI	V,100(X)	;AND YEAR INTO V
	MOVE	X,[POINT 7,MON(Y)] ;GET A MONTH POINTER
	PUSHJ	P,LISOUT	;GO PRINT MONTH
	PUSHJ	P,LISDE2	;GO PRINT YEAR
	MOVEI	W,15		;LOAD A CR
	PUSHJ	P,LISPEC	;GO PRINT IT
	MOVEI	W,12		;LOAD A LF
	PUSHJ	P,LISPEC	;PRINT IT TOO
	USETI	D.,(T)		;SET TO READ NEXT RIB
	PUSHJ	P,EXTCLR	;GO CLEAR OUT INPUT BUFFERS
	PUSHJ	P,LIBIN1	;GO GET IT
	FON	S,EOF,LISCLS	;START OVER IF AT END OF FILE
	JRST	LISLNG		;OK GO PRINT ENTRY
LISDEC:	MOVEI	V,(U)		;PUT NO INTO RIGHT PLACE
LISDE2:	SETZ	U,		;ZERO OUT U
	DIVI	U,^D10		;DIVIDE BY 10
	ADDI	V,60		;CONVERT TO ASCII
	SUBI	J,1		;NOTE A CHARACTER
	PUSH	P,V		;SAVE IT
	PUSH	P,LISDE3	;SAVE A LOOP PLACE
	JUMPN	U,LISDEC	;GO BACK FOR ANOTHER DIVISION
	MOVEI	W," "		;GET A SPACE
	CAIA
	PUSHJ	P,LISPEC	;GO PRINT ONE
	JUMPG	J,.-1	;ANY SPACES LEFT
	POPJ	P,		;JUMP  TO LISDE1
LISDE1:	POP	P,W		;PICK UP CHARACTER
	JRST	LISPEC		;GO PRINT IT
LISDE3:	EXP	LISDE1		;WE NEED A LOC WITH LISDE1 IN IT
; ROUTINE TO ADD A FILE TO A LIBRARY
ADDFIL:	GETPPN	N,		;GET USER'S PPN
	HRLZI	E,(SIXBIT /UFD/) ;USE UFD AS EXTENSION
	PUSHJ	P,SEEDIR	;SEARCH HIS DIRECTORY FOR MATCHES
	RESET			;CLOSE OUT THE DIRECTORY
	SKIPN	N,LIST		;GET NAME OF LIBRARY FILE
	JRST	SPCERR		;TILT IF NO NAME
	HLLZ	E,LIST+1	;GET EXTENSION
	FOF	S,RAD,ADDSET	;ARE WE DOING RANDOM IO
	PUSHJ	P,SETDIR	;YES GO SET UP LIBRARY FOR READING
	SETZ	T,		;CLEAR BLOCK COUNTER
ADDCYC:	PUSHJ	P,NXTDIR	;GO GET A DIR ENTRY
	CAIN	R,LLEN		;ARE WE AT THE END OF A BUFFER INDEX
	JRST	ADDCPY		;YES WE HAVE TO COPY INSTEAD OF SIMPLE APPEND
	JUMPN	R,ADDCYC	;HAVE WE LOOKED AT ALL INDEX YET
	MOVE	W,DHED+2	;GET WORDS LEFT TO READ
	ADDI	W,2		;WE HAVE TO FORGET THE 2 ZERO WORDS
	CAILE	U,(W)		;DO WE HAVE TOO MANY ITEMS LEFT IN LST
	JRST	ADDCPY		;NO, GO DO COPY
	SUBI	W,203
	ADDM	W,DHED+1	;FIX INPUT POINTER
	CLOSE	D.,		;CLOSE OUT READ
	MOVEI	W,200
	MOVEM	W,DHED+2	;FIX WORD COUNT
	JRST	ADDRND		;GO DO RANDOM ADD (APPEND)
ADDCPY:	RESET			;WE HAVE TO COPY, START OVER
	OF	S,RAD		;NOTE WE CAN'T APPEND
ADDSET:	PUSHJ	P,SETDIR	;GO RESET INPUT
ADDRND:	SETZB	R,C		;ZERO OUT PPN AND DATES
	PUSHJ	P,LIBINI	;GO SET UP OUTPUT OF LIBRARY
	PUSHJ	P,ADDINI	;GO SET UP INPUT OF FILE(S) TO BE ADDED
	SETZ	W,		;CLEAR A LST COUNTER NOW
	FON	S,EOF,ADDLST	;ARE WE CREATING
ADDNXT:	PUSHJ	P,NXTDIR	;NO GET A FILE NAME FROM LIBRARY INDEX
	JUMPE	R,.-1		;IS IT AN EMPTY ENTRY
	CAIN	R,LLEN		;NO IS IT THE END OF THE INDEX
	JRST	ADDLST		;YES GO ADD LST TO INDEX
	PUSHJ	P,ADDOUT	;NO JUST COPY THIS ENTRY TO OUTPUT
	JRST	ADDNXT		;GO BACK AND GET ANOTHER ENTRY
ADDLST:	CAIL	W,(U)		;ARE WE DONE WITH THE LST
	JRST	DARFIL		;YES GO ADD THE FILE(S)
	MOVE	R,LST(W)	;NO GET A LST FILE NAME
	MOVE	C,LST+1(W)	;GET A LST EXTENSION
	PUSHJ	P,ADDOUT	;WRITE IT IN NEW INDEX
	ADDI	W,2		;GO UP IN THE LST
	JRST	ADDLST		;GO BACK FOR ANOTHER ENTRY
ADDOUT:	SOSG	LHED+2	;IS OUTPUT BUFFER FULL
	PUSHJ	P,LIBOUT	;YES GO WRITE IT OUT
	IDPB	R,LHED+1	;NOT NOW, DEPOSIT FILE NAME
	SOS	LHED+2
	IDPB	C,LHED+1	;AND EXTENSION
	POPJ	P,		;RETURN
ADDLKP:	SKIPA	Z,.+1		;NOTE WE ONLY WANT TO LOOKUP
ADDINI:	SETZ	Z,		;NOTE WE WILL NEED BUFFERS TOO
	INIT	A.,10		;INIT A CHANNEL FOR ADDING FILES
	SIXBIT	/DSK/
	EXP	AHED
	CAI
	CAIN	Z,		;DO WE NEED BUFFERS
	INBUF	A.,ABUFS	;PICK UP A FEW
	POPJ	P,		;RETURN
ADDIN:	IN	A.,		;INPUT A RECORD
	POPJ	P,		;GOOD READ,RETURN
	GETSTS	A.,I		;ERROR FIND OUT WHAT
	FOF	I,EOFBIT,ADDERR ;TILT IF NOT EOF
	POPJ	P,		;LEAVE IF EOF
; ROUTINE TO EXTRACT FILES FROM LIBRARY
EXTFIL:	SKIPN	N,LIST-2(V)	;IS IT A NULL LIBRARY
	JRST	SPCERR		;YES THATS A NONO
	MOVE	E,LIST-1(V)	;GET EXTENSION
	PUSHJ	P,SETDIR	;GO SET UP INDEX FOR READING
	FON	S,EOF,SPCERR	;TILT IF NO LIBRARY
	MOVEI	W,LIST		;WE WILL START AT BEGINNING
	MOVEI	V,LIST-4(V)	;AND END BEFORE FENCE
	PUSHJ	P,MAKLST	;GO MAKE A LST OF FILES TO EXTRACT
	SETZ	V,		;ZERO FILE COUNTER
	MOVEI	Z,(T)		;GET START COUNTER
	MOVEI	K,LLEN		;GET TABLE LENGTH
EXTNXT:	CAIL	V,(U)		;ARE WE DONE EXTRACTING
	JRST	CLOUT		;YES START IT ALL UP AGAIN
	PUSHJ	P,EXTCLR	;GO CLEAR INPUT BUFFERS
	HRRZ	W,LST+1(V)	;GET BLOCK NO OF THIS FILE
	ADDI	V,2		;GET READY FOR NEXT ONE LATER
	ADDI	W,(Z)		;ADD IN THE BLOCK OF START OF FILES
	USETI	D.,(W)		;READY THE RIB BLOCK
	PUSHJ	P,LIBIN		;GO GET IT
	HRRZ	Y,DHED		;FIND THE BUFFER
	CAME	K,.RBCNT(Y)	;IS IT A RIB
	JRST	RIBERR		;GO TYPE RIB ERROR MESSAGE
	MOVE	N,.RBNAM(Y)	;SAVE NAME OF FILE
	HLLZ	E,.RBEXT(Y)	;AND EXTENSION
	MOVE	R,.RBPRV(Y)	;GET THE PRV WORD
	SETZ	C,		;ZERO OUT PPN
	MOVE	X,.RBSIZ(Y)	;GET THE NO OF WORDS IN FILE
	ADDI	X,177		;ROUND UP
	LSHC	X,-7		;CONVERT TO BLOCKS
	LSH	Y,-35		;KEEP REMAINDER-1
	MOVEI	J,1(Y)		;SAVE REMAINDER
	PUSHJ	P,LIBINI	;GO SET UP OUTPUT OF FILE
	PUSHJ	P,LIBOUT	;DO DUMMY OUTPUT
EXTCYC:	SOJL	X,EXTNXT	;HAVE WE WRITTEN OUT THE FILE
	PUSHJ	P,LIBIN		;NO GET A RECORD
	CAIN	X,		;ARE WE WRITING LAST RECORD
	MOVEM	J,LHED+2	;YES FIX WORD COUNT
	PUSHJ	P,DARBLT	;MOVE RECORD TO OUTPUT BUFFER
	PUSHJ	P,LIBOUT	;SEND IT OUT
	JRST	EXTCYC		;GO TRY FOR ANOTHER RECORD
EXTCLR:	WAIT	D.,		;WAIT TILL ALL INPUT DONE
	MOVE	Y,DHED		;PICK UP BUFFER HEADER
	MOVEI	J,DBUFS		;GET NO OF BUFFERS
	HRLZI	I,400000	;LOAD A HIGH BIT
	ANDCAM	I,(Y)		;MAKE BUFFER NOT USED
	MOVE	Y,(Y)		;GET NEXT BUFFER
	SOJG	J,.-2		;HAVE WE FIXED ALL BUFFERS
	IORM	I,DHED		;FIX HEADER TOO
	POPJ	P,		;RETURN
; ROUTINE TO DELETE FILES FROM A LIBRARY
DELFIL:	SKIPN	N,LIST		;CAN'T HAVE A NULL NAME
	JRST	SPCERR		;GAK! WE DO
	MOVE	E,LIST+1	;OK GET EXTENSION
	SETZB	R,C		;ZERO OUT PPN AND DATES
	PUSHJ	P,LIBINI	;SET UP LIBRARY FOR OUTPUT
	PUSHJ	P,SEEDIR	;GO FIX INDEX
	JRST	DARFIL		;GO DELETE FILES FROM  LIBRARY
DARFIL:	PUSHJ	P,LIBOUT	;WRITE OUT LAST RECORD OF DIRECTORY
	MOVEI	W,LLEN		;SET UP TABLE LENGTH
	SETO	V,		;CLEAR THE LST COUNTER
	FOF	S,RAD,DARNXT	;ARE WE APPENDING
	ON	S,EOF		;YES SET EOF BIT
	USETO	L.,(K)		;SET TO APPEND
	HLRM	X,(X)		;RESTORE THE FULL BUFFER RING
DARNXT:	ADDI	V,2		;GET NEXT LST ENTRY
	CAIGE	V,(U)		;ARE WE AT END OF LST
	JRST	DARLST		;NO GET NEXT ENTRY
	FON	S,EOF,CLOUT	;YES AND HAVE WE REACHED AN EOF TOO
	OF	S,ADF+DEL	;NO BUT NOW WE'RE ONLY COPYING
DARLST:	HLLZ	C,LST(V)	;NO PICK UP EXTENSION
	MOVE	R,LST-1(V)	;AND FILE NAME
DARLOP:	FON	S,EOF,DARNCP	;DON'T COPY IF NO INPUT
	PUSHJ	P,DARBLT	;MOVE FROM DHED TO LHED
	CAME	W,.RBCNT(Y)	;IS IT A RIB
	JRST	RIBERR		;NO GO TYPE RIB ERROR MESSAGE
	MOVE	X,.RBSIZ(Y)	;GET NO OF WORDS IN FILE
	ADDI	X,377		;ROUND UP AND ADD 1
	LSH	X,-7		;CONVERT TO BLOCKS
	FOF	S,DEL,DARCPY	;MUST COPY IF NOT DELETING
	CAMN	R,.RBNAM(Y)	;DO FILE NAMES MATCH
	CAME	C,.RBEXT(Y)	;AND DO EXTENSIONS MATCH
	JRST	DARCPY		;NO JUST COPY THIS PART OF FILE
DARNCP:	FOF	S,ADF,DARDEL	;ARE WE ADDING FILES
	FON	S,DEL,DARREP	;YES  REPLACING FILES ?
	HRRZ	Y,LHED		;GET BUFFER HEADER
	HRRI	I,3(Y)		;GET SECOND WORD OF BUFFER
	HRLI	I,2(Y)		;AND FIRST WORD
	SETZM	2(Y)		;ZERO IT OUT
	BLT	I,LLEN+2(Y)	;ZERO AN EXTENDED LOOKUP TABLE
	MOVEM	W,.RBCNT(Y)	;NO SET UP COUNT OF RIB SIZE
	MOVEM	R,.RBNAM(Y)	;AND FILE NAME
	HLLZM	C,.RBEXT(Y)	;AND EXTENSION
DARREP:	SETZM	.RBPPN(Y)	;ZERO OUT PPN (MAYBE NOT HIS)
	LOOKUP	A.,.RBCNT(Y)	;FILL RIB WITH NEW STUFF
	JRST	SYSERR		;WE CANNOT GET AN ERROR HERE
	HLLZS	.RBEXT(Y)	;ZERO OUT EXTENSION RH
	HRRZ	Z,LST(V)	;GET BLOCK COUNT FOR THIS FILE
DARADD:	PUSHJ	P,LIBOUT	;WRITE OUT THE RECORD
	PUSHJ	P,ADDIN		;READ A RECORD
	SOJLE	Z,DARDEL	;ARE WE DONE WITH THIS ENTRY
	HRRZ	I,AHED		;NO 
	PUSHJ	P,DARBLA	;MOVE ANOTHER RECORD FROM DBUF TO LHED
	JRST	DARADD		;GO BACK AND SEND IT OUT
DARDEL:	FOF	S,DEL,DARNXT	;ARE WE DELETING
	ADDI	T,-1(X)		;ADD TO RECORD COUNT
	PUSHJ	P,EXTCLR	;GO CLEAR BUFFER
	USETI	D.,1(T)		;SET TO READ NEXT FILE
	PUSHJ	P,LIBIN		;YES SKIP A RECORD
	JRST	DARNXT		;NOW GO FOR NEXT ENTRY
DARCPY:	PUSHJ	P,LIBOUT	;WRITE A RECORD
	PUSHJ	P,LIBIN		;READ NEXT RECORD
	SOJLE	X,DARLOP	;HAVE WE COPIED A FILE
	PUSHJ	P,DARBLT	;NO MOVE ANOTHER RECORD FROM DHED TO LHED
	JRST	DARCPY		;GO BACK AND SEND IT OUT
DARBLT:	HRRZ	I,DHED		;GET ADDRESS OF DHED RING
DARBLA:	HRRZ	Y,LHED		;GET ADDRESS OF OUTPUT BUFFER RING
	HRLI	I,2(I)		;GET 1ST WORD OF INPUT BUFFER
	HRRI	I,2(Y)		;GET 1ST WORD OF LHED BUFFER
	BLT	I,201(Y)	;COPY 200 WORDS
	POPJ	P,		;RETURN
; ROUTINE TO COMPARE LIST WITH DIR TO GET LST
MAKLST:	SETZB	U,T		;ZERO THE FILE COUNTER
CHDLST:	PUSHJ	P,NXTDIR	;GET ANOTHER NAME AND EXTENSION
	JUMPE	R,.-1		;IS IT AN EMPTY ENTRY
	CAIN	R,LLEN		;IS IT THE END OF THE DIRECTORY
	JRST	ENDLST		;YES LEAVE
	MOVEI	Z,(W)		;NO BEGINNING OF LIST
	FOF	S,EXT,CHLLST	;ARE WE EXTRACTING
	HRLZI	X,(C)		;YES PICK UP BLOCK COUNT FOR FILE
	HLR	C,T		;SAVE TOTAL UP TO NOW
	ADD	T,X		;MAKE NEW BLOCK COUNT TOTAL
CHLLST:	MOVE	X,[POINT 6,(Z)]	;GET LIST POINTER FOR FN.EXT
	MOVE	Y,[POINT 6,R]	;GET DIR POINTER FOR FN.EXT
	MOVEI	I,11		;WE WANT TO LOOK AT 9 CHARS
NXTLST:	SOJL	I,MATLST	;FOUND A MATCH?
	ILDB	J,Y		;GET A DIR CHAR
	ILDB	K,X		;GET A LIST CHAR TOO
	CAIE	K,77		;IS IT A WILD CARD
	CAIN	K,(J)		;OR DO CHARS MATCH
	JRST	NXTLST		;YES GO GET NEXT SET OF CHARS
	ADDI	Z,2		;NO MOVE UP IN LIST
	CAIGE	Z,(V)		;HAVE WE EXHAUSTED LIST
	JRST	CHLLST		;NO WE'RE OK
CPYLST:	FOF	S,DEL,CHDLST	;YES ARE WE DELETING FILES
	SOSG	LHED+2		;YES WE HAVE TO OUTPUT THIS ENTRY NOW
	PUSHJ	P,LIBOUT
	IDPB	R,LHED+1	;PUT IT IN THE BUFFER
	SOS	LHED+2
	IDPB	C,LHED+1	;ALSO EXTENSION
	JRST	CHDLST		;GO TO NEXT DIRECTORY ENTRY
MATLST:	CAIL	U,UMAX		;ANY MORE SPACE
	JRST	SPAERR		;NO GIVE HIM A SPACE ERROR
	MOVEM	R,LST(U)	;YES SAVE FN IN LST
	MOVEM	C,LST+1(U)	;SAVE EXT IN LST
	FOF	S,ADF,PUTLST	;ARE WE ADDING FILES
	MOVEI	Y,5
	MOVEM	Y,LIST-6	;YES SET UP LOOKUP TABLE
	SETZM	LIST-5
	MOVEM	R,LIST-4
	MOVEM	C,LIST-3
	LOOKUP	A.,LIST-6

	JRST	NOLST		;CAN'T DELETE IF CAN'T REPLACE
	MOVE	Z,LIST-1	;GET WORD COUNT
	ADDI	Z,377		;ROUND UP AND ADD ONE
	LSH	Z,-7		;CONVERT TO BLOCKS
	HRRM	Z,LST+1(U)	;PUT IT IN BLOCK COUNTER
	HRRI	C,(Z)		;BOTH OF THEM
PUTLST:	ADDI	U,2		;INCREASE FILE COUNTER
NOLST:	FON	S,ADF,CPYLST	;ARE WE ADDING
	JRST	CHDLST		;NO GO GET NEXT ENTRY
ENDLST:	JUMPE	U,LSTERR	;IS THE LIST EMPTY
	POPJ	P,		;NORETURN
; ROUTINE TO GET AN INPUT CHARACTER
INCHR:	SOSG	DHED+2		;ARE THERE CHARACTERS IN THE BUFFER
	INPUT	D.,		;NO FILL IT
	ILDB	W,DHED+1	;GET A CHARACTER
	CAIN	W," "		;IS IT A SPACE
	JRST	INCHR		;YES FORGET IT
	POPJ	P,		;RETURN

; ROUTINE TO PROCESS A DIRECTORY
INIDIR:	INIT	D.,10		;INIT A DIRECTORY CHANNEL
	SIXBIT	/DSK/
	EXP	DHED
	CAI
	INBUF	D.,DBUFS	;YES GET A FEW INPUT BUFFERS
	LOOKUP	D.,N		;DO THE LOOKUP
	ON	S,EOF		;NOTE NO INPUT DIRECTORY
	POPJ	P,		;RETURN
NXTDIR:	MOVEI	R,LLEN		;SET FOR EOF ON DIRECTORY
	SOSG	DHED+2		;IS BUFFER EMPTY
	JRST	INDIR		;YES GO DO AN INPUT
RTNDIR:	ILDB	R,DHED+1	;FULL NOW, GET A FILE NAME
	SOS	DHED+2
	ILDB	C,DHED+1	;GET AN EXTENSION
	POPJ	P,		;RETURN
INDIR:	ADDI	T,1		;EXTFIL NEEDS THIS
	IN	D.,		;READ A RECORD
	JRST	RTNDIR		;GOOD RETURN
	POPJ	P,		;NO DONE
; ROUTINE TO SETUP A DIRECTORY FOR SCANNING
SETDIR:	FON	S,EXT		;IF EXTRACTING FILES
	SKIPA	I,LIST-4(V)	;FENCE SHOULD BE NEAR THE END
	MOVE	I,LIST+3	;GET FENCE EXTENSION
	FOF	I,1,SPCERR	;IS IT REALLY A FENCE
	SETZB	R,C		;YES CLEAR OUT PPN AND DATES
	CAME	E,[SIXBIT /UFD/] ;IS IT A UFD
	JRST	INIDIR		;NO GO INITIATE DIRECTORY
	AOBJP	C,INIDIR	;SET 1,1 AS PPN
; ROUTINE FOR ADD AND DEL TO  SET UP SEARCHES
SEEDIR:	PUSHJ	P,SETDIR	;GO SET UP USER'S DIRECTORY FOR READING
	MOVEI	W,LIST+4	;START AFTER FENCE IN LIST
	MOVEI	V,LIST(V)	;NOTE END OF LIST
	FON	S,ADF		;IF WE'RE ADDING THEN
	PUSHJ	P,ADDLKP	;INITIALIZE CHAN FOR LOOKUPS
	PUSHJ	P,MAKLST	;GO FIND FILES TO ADD TO LIBRARY
	POPJ	P,		;RETURN
; ROUTINE TO INITIALIZE LIBRARY OUTPUT
LIBINI:	RELEAS	L.,		;RELEASE THE GD THING FIRST
	MOVE	I,LHED		;SAVE HEADER FOR EXTRACTING
	INIT	L.,10
	SIXBIT	/DSK/
	XWD	LHED,0
	CAI
	CAIE	I,		;IF WE HAD BUFFERS
	MOVEM	I,LHED		;RESTORE THEM
	FOF	S,RAD,LIBENT	;ARE WE DOING AN APPEND
	MOVEI	K,5		;YES PREPARE TO LOOKUP
	SETZ	J,
	LOOKUP	L.,K		;LOOKUP UP THE FILE
	ON	S,EOF		;TILT THE FILE ISN'T THERE
	FON	S,EOF,ADDCPY	;LEAVE, WE CAN'T DO IT THIS WAY
	ADDI	C,377		;ROUND UP WORDS AND ADD 1
	LSH	C,-7		;CONVERT TO WORDS
	MOVEI	K,(C)		;SAVE IN REG K
	SETZB	R,C		;ZERO OUT DATES AND PRVS
	HRRI	E,		;CLEAR ACCESS DATE
LIBENT:	ENTER	L.,N		;GO ENTER THE FILE
	JRST	ENTERR		;TILT ON ERROR HERE
	CAIN	I,		;DO WE HAVE BUFFERS
	OUTBUF	L.,LBUFS	;NO GET A FEW
	FOF	S,RAD		;ARE WE APPENDING
	POPJ	P,		;NO RETURN
	HRR	X,LHED		;GET ADDRESS OF FIRST BUFFER IN RING
	HRL	X,(X)		;SAVE ADDRESS OF SECOND BUFFER
	HRRM	X,(X)		;REPLACE WITH TAHT OF FIRST
	USETO	L.,(T)		;SET TO OUTPUT TO LAST INDEX BLOCK
	POPJ	P,		;RETURN
; ROUTINE TO PUT A RECORD OUT TO LIBRARY FILE
LIBOUT:	SKIPL	I,LHED+2	;GET NO OF WORDS LEFT TO BE WRITTEN
	ADDM	I,LHED+1	;FIX THE POINTER
	OUT	L.,		;OUTPUT A RECORD
	POPJ	P,		;GOOD WRITE, RETURN
	JRST	OUTERR		;BAD ONE, TILT!
;ROUTINE TO GET AN INCOMING LIBRARY RECORD
LIBIN:	ADDI	T,1		;ADD ONE TO BLOCK COUNT
LIBIN1:	IN	D.,		;READ A RECORD
	POPJ	P,		;GOOD READ, RETURN
	GETSTS	D.,I		;ERROR FIND OUT WHAT
	FOF	I,EOFBIT,LIBERR ;IF NOT EOF TILT
	ON	S,EOF		;NOTE NO MORE LIBRARY
	POPJ	P,		;IF EOF LEAVE
; ROUTINES TO PRINT ASSORTED ERROR MESSSAGES
LSTERR:	OUTSTR	ERRLST
	JRST	UFLIP
SYSERR:	OUTSTR	ERRSYS
	JRST	UFLIP
SYNERR:	OUTSTR	ERRSYN
	OUTCHR	W
	JRST	CRLF
BIGERR:	OUTSTR	ERRBIG
	JRST	UFLIP
SPCERR:	OUTSTR	ERRSPC
	JRST	UFLIP
SPAERR:	OUTSTR	ERRSPA
	JRST	UFLIP
OUTERR:	OUTSTR	ERROUT
	JRST	TYPERR
LIBERR:	OUTSTR	ERRLIB
	JRST	TYPERR
ADDERR:	OUTSTR	ERRADD
	MOVE	N,R
	HLLZ	E,C
	JRST	TYPERR
RIBERR:	OUTSTR	ERRRIB
	JRST	TYPERR
ENTERR:	OUTSTR	ERRENT
TYPERR:	MOVE	W,[POINT 6,N]	;GET POINTER TO FN
	HRRI	E,		;SET RH OF E TO 0
	PUSHJ	P,NAMERR	;GO SEND OUT FN
	OUTCHR	["."]		;AND A DOT
	PUSHJ	P,NAMERR	;SEND OUT EXTENSION
CRLF:	OUTSTR	[ASCIZ /
/]
	JRST	UFLIP
NAMERR:	ILDB	V,W		;PICK UP A CHARACTER
	JUMPE	V,CYCERR	;IF NULL FORGET IT
	ADDI	V," "		;CONVERT TO ASCII
	OUTCHR	V		;SEND IT OUT
CYCERR:	FON	W,770000000000,NAMERR ;SENT OUT 6 CHARS?
	POPJ	P,		;YES RETURN
; THE MONTHS OF THE YEAR
MON:	ASCII	/-JAN--FEB--MAR--APR--MAY--JUN--JUL--AUG-/
	ASCII	/-SEP--OCT--NOV--DEC-/
; VARIOUS MESSAGES
HELP:	ASCIZ	?TYPE ONE OF THE FOLLOWING:
           libnam.ext/C_list       to create a library
           libnam.ext/A_list       to add to a library
           libnam.ext/D_list       to delete from a library
           libnam.ext/R_list       to update a library
           /L_libnam.ext           to list a library (LONG
                                                     FORM)
           /F_libnam.ext           to list a library (SHORT
                                                     FORM)
           list/E_libnam.ext       to extract from a library
           /H                      to type this message?
ERRLST:	ASCIZ	/LST EMPTY, NOTHING TO DO
/
ERRSYS:	ASCIZ	/SYSTEM ERROR  GAK!
/
ERRSYN:	ASCIZ	/SYNTAX ERROR CHARACTER /
ERRBIG:	ASCIZ	/SPECIFICATION TOO LARGE
/
ERRSPC:	ASCIZ	/SPECIFICATION ERROR
/
ERRSPA:	ASCIZ	/TOO MANY FILES IN LIST
/
ERROUT:	ASCIZ	/OUTPUT ERROR ON FILE /
ERRLIB:	ASCIZ	/INPUT ERROR ON LIBRARY FILE /
ERRADD:	ASCIZ	/ERROR READING FILE /
ERRRIB:	ASCIZ	/BAD FORM IN FILE /
ERRENT:	ASCIZ	/COULD NOT ENTER FILE /
; SOME LITERALS AND THE BIG END
CLIT:	LIT
CDEND:	END	UFLIP

; HERE IS THE SPACE FOR ALL LOW SEGMENT TABLES
BK PDLIST,PLEN
BK LIST,VMAX
BK LST,UMAX
BK AHED,3
BK DHED,3
BK LHED,3
DEBUG=1

KIN\@TITLE UFLIP A PROGRAM TO ENABLE USER FILE LIBRARIES
DEFINE ND(A,B)<IFNDEF A,<A=B>>
; SOME ASSEMBLY PARAMETERS
ND CATCH,0
ND .JBFF,121
ND NODUPS,1
ND PLEN,30
ND VMAX,100
ND UMAX,200
ND LLEN,32
ND ABUFS,4
ND DBUFS,4
ND LBUFS,4
ND DEBUG,0
IFE	DEBUG,<
DEFINE CS,<RELOC 400000>
TWOSEG>
IFN	DEBUG,<DEFINE	CS,<>>
DEFINE BK(A,B)<
IFDIF <B><>,<A: BLOCK B>
IFIDN<B><>,<A: Z>>
DEFINE	IC(A,B)<
IFIDN	<A><>,<.X'B=0>
IFDIF	<A><>,<
A=.X'B
.X'B=.X'B+1
>>
EOFBIT=20000
; ACCUMULATORS
IC ,1
IC S,1
IC I,1
IC K,1
IC J,1
IC N,1
IC E,1
IC R,1
IC C,1
IC X,1
IC Y,1
IC Z,1
IC T,1
IC U,1
IC V,1
IC W,1
IC P,1
.X.=1
DEFINE BT(A),<
A=.X.
.X.=.X._1>

BT RAD
BT EOL
BT EOF
BT ADF
BT ARO
BT CMA
BT DEL
BT DOT
BT EXT
BT FNC
BT LIS
BT LNG
BT SLA

IFN	CATCH,<RAD=0>	;REDEFINE RAD IF NECESSARY TO PREVENT THE SIMPLE APPEND

; CHANNEL DEFINITIONS
A.=0
D.=1
L.=2

; SOME EXTENDED LOOKUP/ENTER WORDS
.RBCNT=2
.RBPPN=3
.RBNAM=4
.RBEXT=5
.RBPRV=6
.RBSIZ=7

	DEFINE	HALF(A,B,C,D),<
.Y.=<B>_-^D18
	IFE	.Y.,<TR'D A,B>
	IFN	.Y.,<TL'D A,.Y.>
	IFDIF	<C><>,<JRST C>>
	DEFINE	ON(A,B),<HALF A,B,,O>
	DEFINE	OF(A,B),<HALF A,B,,Z>
	DEFINE	FON(A,B,C),<HALF A,B,C,NE>
	DEFINE	FOF(A,B,C),<HALF A,B,C,NN>
	DEFINE	FONZ(A,B,C),<HALF A,B,C,ZE>
	DEFINE	FOFO(A,B,C),<HALF A,B,C,ON>
	DEFINE	FONO(A,B,C),<HALF A,B,C,OE>
	DEFINE	FOFZ(A,B,C),<HALF A,B,C,ZN>
CATCH=1

+3hke$ 	` (	v+@@
""iSH0*"[ @@X@@X}8+$@8,z0<0|-+!1<1|1+!/<<8\+0:+)0Z4LzLh<!Nh<.:a@	+d@.:l@+)l$1\&l
1\#l0\$+
&>+40\/+7e@+'l+0\+:a@+'+0|0<>e@+'1Z2V+	` =aX+*7H<+E 
<@l$INXp0d0+G$iSHp0@
>@l,}`@+*,4LK1LVX.R@,S+K$+4\X`p +V0|.</&?`,v H)2zA2@'0 :@ &,v <,V* <1x,V,u)2 &@'0 :H,v 2@@'0 :@  ,S,v <,V <,VX,4,"`@+R+Z :`@'8.:/&,>,>}5Xu <1,V5fz,~,^+V|	h
S*YR,	`7H<+*R
<a@+,@,1L
5L .<0xp+
/<A.\0<@+\+	`d,@l,,@`@+,4L1L
p\p\,.<+?` ,L> N,~7@ INX01T
@aB +.,~7Hh;+* 
h;,`@+*<<:h:,p@4X$H+0 HR
H 
H@ H.0?)P|(Rq &H,,<0%,!1P F ,\,+0	b  &S"BBH H=f6GB,~7H<+* 
<@l,,+<,<1:`+C`@+d$Rh\ 
h[`@+J,\2\H+0H.0(P|a@+Y3LH2NH+Ya@+V`@+PZX"HQ"H@@H*"H\HLHRNH@@H@H+&R`HZh\,,<tVZ,\+Sa@+@.6G,4X,!+@,,!<pD,\+YZZQ"X"H*"H@,~@x,4L1L
>,~.6B+,~`@7h: =aB+*@l2J+}*N}, <> :h<`@,,_,~$ $INXp00B Ba@+ $@Dl`@+
..(N|~$8@lX*d+11B" .Bd,~+,.6B,~
BaB +-l,~
&|+
&+
&
"+4
&+
&+
&
+
&
+1
&+1
& R
+1
&+1
& X*,5
",5
&+4Z7.:
"`|p+5,~-JAN--FEB--MAR--APR--MAY--JUN--JUL--AUG--SEP--OCT--NOV--DEC-TYPE ONE OF THE FOLLOWING:
           libnam.ext/C_list       to create a library
           libnam.ext/A_list       to add to a library
           libnam.ext/D_list       to delete from a library
           libnam.ext/R_list       to update a library
           /L_libnam.ext           to list a library (LONG
                                                     FORM)
           /F_libnam.ext           to list a library (SHORT
                                                     FORM)
           list/E_libnam.ext       to extract from a library
           /H                      to type this messageLST EMPTY, NOTHING TO DO
SYSTEM ERROR  GAK!
SYNTAX ERROR CHARACTER SPECIFICATION TOO LARGE
SPECIFICATION ERROR
TOO MANY FILES IN LIST
OUTPUT ERROR ON FILE INPUT ERROR ON LIBRARY FILE ERROR READING FILE BAD FORM IN FILE COULD NOT ENTER FILE ~@/@<HHHHHL8HPk H