;-*-Midas-*-

	Title :FDIR - Fast DIRectory listing.

A=1	;G. Porp.
B=2
C=3
D=4
E=5

T1=6
T2=7
T3=10

J=11
M=12
AR=13

P=17

Call=<PUSHJ P,>
Return=<POPJ P,>

TTYi==1
TTYo==2
UFDi==3
MFDi==4

PDLen==10
JCLen==10

 ;;;
;;;;;
 ;;;

.INSRT SYSTEM;FSDEFS >

.INSRT KP;MACROS >

 ;;;
;;;;;
 ;;;

PDList:	-PDLen,,.
	Block PDLen

JCLbuf:	Block JCLen
	-1

Tsint:	Loc 42
	-TsintL,,Tsint
	Loc Tsint
	P
	0 ? 1_TTYi ? -1 ? 1_TTYo ? Intrup
	0 ? 1_TTYo ? 0 ? 0 ? More
TsintL==.-Tsint

Device:	Sixbit /DSK/
Sname:	0
FN1:	0
FN2:	Sixbit /(DIR)/

SWild:	0
SFree:	Block 6
SChar:	Block 6

DFree:	Block 6
DChar:	Block 6

ArWild:	0
LoseOK:	0

FDefs:	Block 4

Free:	Block 6
Char:	Block 6

NPairs:	0

 ;;;
;;;;;
 ;;;

Begin:	Move P,PDList
	Syscal OPEN,[%Clbit,,.uao\%TJDIS
		     %Climm,,TTYo
		     [Sixbit /TTY/]]
	  .Lose %LsFil
	Syscal OPEN,[%Clbit,,.uai
		     %Climm,,TTYi
		     [Sixbit /TTY/]]
	  .Lose %LsFil
	.Suset [.sOPTION,,[Optint,,]]	;New-style interrupts
	.Suset [.sMSK2,,[1_TTYi+1_TTYo]]
	Syscal TTYVAR,[%Climm,,TTYo
		       [Sixbit /WIDTH/]
		       %Clout,,T1]
	  .Lose %LsSys
	Addi T1,2
	IDivi T1,16.
	Movem T1,NPairs
	.Break 12,[..rJCL,,JCLbuf]
	Skipn JCLbuf
	  Jrst dFalt
	Move J,[440700,,JCLbuf]

Parse:	Setzb A,D		;Word, # *'s
	Setzb B,Free
	Move T1,[Free,,Free+1]
	BLT T1,Char+5
	Move C,[440600,,A]
PgChar:	Ildb T1,J
	Caie T1,^M
	  Cain T1,^C
	    Jrst Check
	Caie T1,40	;<Space>
	  Cain T1,";
	    Jrst Check
	Caie T1,":
	  Cain T1,^_
	    Jrst Check
	Cail B,6	;Only 1st 6 character per word are significant
	  Jrst PgChar
	Cain T1,"*
	  Jrst [Setom Free(B)	;Flag this char as W*I*L*D
		Aoja D,Pg2]
	Cail T1,"a
	  Trz T1,40	;lc -> UC
Pg2:	Subi T1,40	;7bit -> 6bit
	Idpb T1,C
	Movem T1,Char(B)
	Aoja B,PgChar

Check:	Jumpe A,dFalt
	Caie T1,":
	  Jrst Check1
	Jumpn D,[And A,[777700,,0]	;Only look at two two letters
		 Came A,[Sixbit /AR/]
		  .Value [Ascii /: Can't wildcard that device? KILL /]
		 Setom ArWild
		 Move T1,[Free,,DFree]
		 BLT T1,DChar+5
		 Jrst Parse]
	Movem A,Device
	Jrst Parse
Check1:	Cain T1,";
	  Jrst [Movem A,Sname
		Move T1,[Free,,SFree]
		BLT T1,SChar+5
		Movem D,SWild
		Jrst Parse]
	Movei T2,FN1
	Skipe FN1
	  Movei T2,FN2
	Movem A,(T2)
	Caie T1,^M
	  Cain T1,^C
	    Skipa
	Jrst Parse

dFalt:	Skipn FN1
	  Jrst [Move T1,[Sixbit /.FILE./]
		Movem T1,FN1
		Jrst .+1]
	Skipn Sname
	  Jrst [.Break 12,[6,,FDefs]
		Move A,FDefs+1
		Movem A,Sname
		Jrst .+1]

Transl:	Syscal TRANS,[Device ? FN1 ? FN2 ? Sname
		      %Clout,,Device
		      %Clout,,FN1
		      %Clout,,FN2
		      %Clout,,Sname]
	  .Lose %LsSys

One:	Skipn SWild
	  Jrst [Call UFDprt
		Jrst Die]

Wild:	Syscal OPEN,[%Clbit,,.uii
		     %Climm,,MFDi
		     [Sixbit /DSK/]
		     [Sixbit /M.F.D./]
		     [Sixbit /(FILE)/]]
	  .Value [Ascii /: Can't open MFD? KILL /]
	Syscal SIOT,[%Climm,,MFDi
		     [444400,,MFDbuf]
		     [2000]]
	  .Value [Ascii /: Can't read in MFD? KILL /]

	Move M,MFDbuf+1	;Start of names (offset)

Wild1:	Move T1,MFDbuf(M)
	Jumpe T1,WNext
	Setz C,
	Move B,[440600,,T1]
Wild2:	Ildb T2,B
	Skipe SFree(C)
	  Jrst Wild3
	Came T2,SChar(C)
	  Jrst WNext
Wild3:	Aoj C,
	Caie C,6
	  Jrst Wild2
	Movem T1,Sname
	Call UFDprt
WNext:	Addi M,2
	Caie M,2000
	  Jrst Wild1

 ;;;
;;;;;
 ;;;

Die:	.Logout 1,

FilTyp:	Move T1,Device
	Call 6Type
	.Iot TTYo,[":]
	Move T1,Sname
	Call 6Type
	.Iot TTYo,[";]
	Move T1,FN1
	Camn T1,[Sixbit /.FILE./]
	  Return
	Call 6Type
	.Iot TTYo,[" ]
	Move T1,FN2
	Call 6Type
	Return

6Type:	Setz T2,
	Rotc T1,6
	Addi T2,40
	.Iot TTYo,T2
	Jumpn T1,6Type
	Return

UFDprt:	Syscal OPEN,[%Clbit,,.uii
		     %Climm,,UFDi
		     Device ? FN1 ? FN2 ? Sname]
	  Jrst [Skipe LoseOK
		  Return
		Type ,"No such directory as "
		Call FilTyp
		Jrst Die]
	Movei T1,UFDbuf
	Skipe ArWild
	  Movei T1,ARCbuf
	Hrli T1,444400
	Movei T2,2000
	Syscal SIOT,[%Climm,,UFDi ? T1 ? T2]
	  Jrst [Type ,"?Can't read in UFD"
		Return]
	.Close UFDi,
	Skipn ArWild
	  Jrst UFDp0

ArLook:	Move AR,ARCbuf+1	;Start of names (offset)
	Cail AR,2000
	  Jrst [Type ,"ADirectory empty?"
		Return]
	Setzm ArWild
	Setom LoseOK
ArL1:	Move T1,ARCbuf(AR)
	Move T2,T1
	And T2,[777700,,0]
	Came T2,[Sixbit /AR/]
	  Jrst NextAr
	Movei C,2
	Move B,[300600,,T1]
ArL2:	Ildb T2,B
	Skipe DFree(C)
	  Jrst ArL3
	Came T2,DChar(C)
	  Jrst NextAr
ArL3:	Aoj C,
	Caie C,6
	  Jrst ArL2
	Movem T1,Device
	Call UFDprt
	.Iot TTYo,[^M]

NextAr:	Addi AR,5
	Caie AR,2000
	  Jrst ArL1
	Setom ArWild
	Move T1,[Sixbit /DSK/]
	Movem T1,Device
	Return

UFDp0:	Call FilTyp
	Setz E,			;# files
	Move A,UFDbuf+UDNAMP
	Cail A,2000
	  Jrst [Type ," is Empty"
		Return]
	Move T1,Device
	Came T1,[Sixbit /DSK/]
	  Jrst UFDp1
;;;
;;;	This section of code swiped from DSKUSE
;;;
UFULL0:	MOVE	D,UDESCP+UFDbuf
	MOVEI	C,UDDESC+UFDbuf	; D/ desc count
	HRLI	C,440600	; "BYTE PTR"
	SETZ	T2,		; "COUNT"
NEXTA:	SETZ	T1,
NEXTB:	SOJL	D,FEND
	ILDB	C
	JUMPE	NBYTE		; "ZERO BYTE?"
	SETO	T1,		; "NON-ZERO BYTE"
	JRST	NEXTB		; "LOOP"
NBYTE:	JUMPN	T1,NEXTA	; "ZERO, WAS LAST ZERO?"
	SETZ	T1,
	AOJA	T2,NEXTB		; "AOS NULL COUNT"
FEND:	MOVE	T1,UDESCP+UFDbuf
	SUB	T1,T2
	IDIVI	T1,6		; "NUMBER OF WORDS"
	ADDI	T1,2000
	SUB	T1,UDNAMP+UFDbuf
;;;
;;;	End of code stolen from DSKUSE
;;;
	.Iot TTYo,[" ]
	.Iot TTYo,["(]
	IMuli T1,100.
	IDivi T1,2000-UDDESC
	Move T3,T2	;Save fractional part for now
	IDivi T1,10.
	Addi T1,"0
	Caie T1,"0
	  .Iot TTYo,T1
	Addi T2,"0
	.Iot TTYo,T2
	.Iot TTYo,[".]
	Move T1,T3
	IMuli T1,10.
	IDivi T1,2000-UDDESC
	Addi T1,"0
	.Iot TTYo,T1
	Type ,"% used)"

UFDp1:	.Iot TTYo,[^M]
	Move B,NPairs

UFDp2:	.Iot TTYo,[" ]
	Move T1,UFDbuf(A)
	Call 6Type
	.Iot TTYo,[^I]
	Move T1,UFDbuf+1(A)
	Call 6Type
	Addi A,5
	Cail A,2000
	  Jrst [.Iot TTYo,[^P]
		.Iot TTYo,["A]
		Return]
	Soj B,
	Jumpe B,UFDp1
	.Iot TTYo,[^I]
	Jrst UFDp2

Intrup:	.Reset TTYo,
	.Reset TTYi,
	Syscal TTYFLS,[%Clbit,,1 ? %Climm,,1]
	  .Lose %LsSys
	Jrst Flush

More:	Type ,"--More--"
	.Iot TTYi,T1
	Cain T1,40	;space
	  Jrst [.Iot TTYo,[^M]
		Syscal DISMIS,[P]
		  .Lose]
Flush:	Type ," Flushed"
	Jrst Die

 ;;;
;;;;;
 ;;;

UFDbuf:	Block 2000
MFDbuf:	Block 2000
ARCbuf:	Block 2000

Variables
Constants

	END Begin