;-*-Midas-*-

	Title :DDTDOC - DDT Documentation from .INFO.;DDTORD >

Z=0

A=1	;General porpoise
B=2
C=3
D=4
E=5

T1=6	;Transient
T2=7
T3=10

JCL=11
Help=12

Alt=14
Col=15

P=17

TTYo==1
TTYi==2
DSKi==3		;DDTORD
TEMPi==4

PDLen==10
JCLen==10

Bottom==0		;Which pages of DDTORD to map in
   Top==22.
Length==Top-Bottom+1

Call=<Pushj P,>
Return=<Popj P,>

 ;;;
;;;;;
 ;;;

.INSRT GREN;MACROS >

 ;;;
;;;;;
 ;;;

OTOp:	0	;One Time Only?  True means running off JCL
Echop:	0	;SLINE echoes what it skips?
Allowp:	0	;True if allowing Got-TTY-Back interrupts to do something

String:	Block 2	;What you're looking for

ColBP:	0	;Pointer to start of :-command doc
CtrlBP:	0	;Pointer to start of control commands
hTemp:	0
CLen:	0

HSName:	0
	Sixbit /SYS/
	Sixbit /SYS1/
	Sixbit /SYS2/
	Sixbit /SYS3/
NDirs==.-HSName

Inhale:	.Iot TTYi,A

JCLbuf:	Block JCLen
	-1

PDList:	-PDLen,,.
	Block PDLen

Tsint:	Loc 42
	-TsintL,,Tsint
Loc Tsint
	P
	0 ? 1_TTYi ? 0 ? 0 ? Flush
	%PiATY ? 0 ? %PiATY ? 0 ? ReAsk
TsintL==.-Tsint

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Begin:	Move P,PDList
	.Suset [-4,,[.sOPTION,,[Optint,,]	;New-style interrupts
		     .sMSK2,,[1_TTYi]
		     .sMASK,,[%PjATY,,]		;Got-TTY-Back interrupt
		     .rHSNAME,,HSName]]
	Syscal OPEN,[%Clbit,,.uai
		     %Climm,,TTYi
		     [Sixbit /TTY/]]
	  .Lose %LsFil
	Move T1,[424642,,424242]	;lc -> UC
	Move T2,[234242,,420242]	;^S, ^G intrup
	Syscal TTYSET,[%Climm,,TTYi
		       T1 ? T2]
	  .Lose %LsSys
	Syscal OPEN,[%Clbit,,.uao\%TJDIS
		     %Climm,,TTYo
		     [Sixbit /TTY/]]
	  .Lose %LsFil

JCLp:	.Break 12,[..rJCL,,JCLbuf]
	Skipn JCLbuf
	  Jrst Intro
	Move JCL,[440700,,JCLbuf]

sChaff:	Ildb A,JCL
	Caie A,40
	  Cain A,^I
	    Jrst sChaff
	DBP JCL
	Move T1,[Ildb A,JCL]
	Movem T1,Inhale
	Setom OTOp
	Call gFile
	Jrst doIt

;;;
;;;	You get here for interactive mode
;;;

Intro:	Type ,"
Welcome to DDTDOC.  At the prompt enter any DDT command (either colon
or control/escape type) and it will be described more fully than you
had ever dreamed possible.  Use only vanilla forms, i.e. ^A and not
0^A, $$U and not $$1U, $O and not $$O, etc.  Type Q to quit.
î"
	Call gFile

Prompt:	Syscal FINISH,[%Climm,,TTYo]
	  .Lose %LsSys
	.Reset TTYi,
	Type ,"A[Command?] "
	Setom Allowp

doIt:	Move B,[440700,,String]
	Setzm String
	Setzm String+1
	Movei C,6
	Setzb Col,Alt
	Setzm Echop

GetCC:	XCT Inhale	;Into ac A
	Andi A,177	;Snuff fancy bits
	Caie A,^M
	  Cain A,^C
	    Jrst [Jumpn Alt,Save
		  Jumpe Col,Save
		  Caie C,6
		    Jrst Search
		  Movei A,":
		  Setz Col,
		  Jrst Save]
	Caie A,177
	  Jrst notRub
	Jumpn Alt,[.Iot TTYo,[^P]
		   .Iot TTYo,["X]
		   Soja Alt,GetCC]
	Jumpe Col,[Type ," RUBOUT does what you'd expect it to do!"
		   Jrst Error]
	.Iot TTYo,[^P]
	.Iot TTYo,["X]
	Dpb Z,B
	DBP B
	Caie C,6
	  Aoja C,GetCC
	Setz Col,
	Jrst GetCC

notRUB:	Caie A,^[	;Escape
	  Jrst NonEsc
	Jumpn Col,[Type ," Colon commands do not have escapes!"
		   Jrst Error]
	Cail Alt,2
	  Jrst [Type ," DDT commands have a maximum of two escapes!"
		Jrst Error]
	Movei T1,"$
	Idpb T1,B
	Aoja Alt,GetCC

NonEsc:	Caie A,":
	  Jrst nonCol
	Jumpn Alt,[Idpb A,B
		   Jrst Search]
	Jumpn Col,[Type ," Only one colon in :-commands!"
		   Jrst Error]
	Aoja Col,GetCC

nonCol:	Cail A,"a
	  Trz A,40
	Jumpn Col,[Cain A,40
		     Jrst [Caie C,6
			     Jrst Search
			   Setz Col,
			   Movei A,":
			   Jrst Save]
		   Jumpe C,GetCC
		   Caige A,"!
		     Jrst [Type ," No control chars allowed in :-commands!"
			   Jrst Error]
		   Idpb A,B
		   Soja C,GetCC]
	Jumpn Alt,Save
	Cain A,"Q
	  Jrst Die

Save:	Caige A,40
	  Jrst [Movei T1,"^
		Idpb T1,B
		Tro A,100
		Jrst .+1]
	Idpb A,B

Search:	Skipn String
	  Jrst Error
	.Iot TTYo,[^P]
	.Iot TTYo,["A]
	Jumpn Col,fColon
	Move T1,[440700,,String]

TStrin:	Ildb T2,T1
	Jumpe T2,InitBP
	.Iot TTYo,T2
	Jrst TStrin

InitBP:	Move C,CtrlBP
	Move B,[440700,,D]
	Setzb D,T2

Match:	Ildb A,C
	Caie A,^I
	  Cain A,^M
	    Jrst Compar
	Cain A,40
	  Jrst [Cain T2,"$
		  Jrst tag
		Jrst Compar]
	Cain A,":
	  Jrst [Skipe T2
		  Cain T2,"$
		    Jrst tag
		Jrst Compar]
   tag:	Idpb A,B
	Move T2,A
	Jrst Match

Compar:	Camn D,String
	  Jrst Indeed
Nope:	Call Sline	;No match... skip ahead to next
	Ildb A,C
	Caie A,^I
	  Cain A,"<
	    Jrst Nope
	Caie A,"0
	  Cain A,40
	    Jrst Nope
	Cain A,^M
	  Jrst Nope
	Cain A,^L
	  Jrst [Type ," - Not found"
		Jrst Error]
	Move B,[440700,,D]
	Setz D,
	Move T2,A
	Idpb A,B
	Jrst Match

Indeed:	Setom Echop	;Indeedy!  We have a match....

Tell:	.Iot TTYo,A
Skipln:	Call Sline
 gchar:	Ildb A,C
	Caie A,^I
	  Cain A,^M
	    Jrst Tell
	Caie A,"0
	  Cain A,"<
	    Jrst AskMor
	Caie A,40
	  Jrst GoOnp

AskMor:	Type ,"--("
	Caie A,40
atchar:	  .Iot TTYo,A
	Ildb A,C
	Caie A,^I
	  Cain A,^M
	    Skipa
	Jrst atchar
	Type ,")?--"
	.Iot TTYi,T1
	Caie T1,40
	  Jrst [Type ," Flushedî"
		Jrst GoOnp]
	.Iot TTYo,[^M]
	Caie A,^M
	  Jrst Tell
	Jrst Skipln

Sline:	Ildb T1,C
	Cain T1,^J
	  Return
	Skipe Echop
	  .Iot TTYo,T1
	Jrst Sline

 ;;;
;;;;;
 ;;;

fColon:	Move Help,ColBP	;Initial BP
	Ibp Help
	Movei T1,6
	Sub T1,C
	Movem T1,CLen

cStrin:	Move A,[440700,,String]
	Movem Help,hTemp
	Move T3,CLen

cW1:	Ildb T1,Help
	Ildb T2,A
	Camle T1,T2
	  Jrst DirChk
	Came T1,T2
	  Jrst Lose
	Sojn T3,cW1
	Jrst Win

Lose:	Ildb T1,Help
	Caie T1,^J
	  Jrst Lose
	Ildb T1,Help
	Cain T1,^L
	  Jrst DirChk
	Cain T1,^M
	  Jrst [Ildb T1,Help
		Ildb T1,Help
		Cain T1,":
		  Jrst cStrin
		.Value [Ascii /: File disordered - Can't parse KILL /]]
	Jrst Lose

Win:	Setom Echop
	.Iot TTYo,[":]
Win2:	Ildb T1,hTemp
	Cain T1,^J
	  Jrst [Ildb T1,hTemp
		Caie T1,^M
		  Cain T1,^L
		    Jrst GoOnp
		Jrst .+1]
	.Iot TTYo,T1
	Jrst Win2

DirChk:	Move T1,[440600,,B]
	Setz B,
	Move T2,[440700,,String]
	Ildb A,T2
	Jumpe A,SDir1
	Subi A,40
	Idpb A,T1
	Jrst .-4

SDir1:	Movsi A,-NDirs
SDir2:	Move D,HSName(A)
	Syscal OPEN,[%Clbit,,.uii
		     %Climm,,TEMPi
		     [Sixbit /DSK/]
		     [Sixbit /TS/]
		     B ? D]
	  Jrst [Aobjn A,SDir2
		Jrst NFound]
	.Close TEMPi,
	.Iot TTYo,[":]
	Move T1,B
	Call 6Type
	Type ," is a program residing in "
	Move T1,D
	Call 6Type
	Type ,";
I don't know WHAT it does."
	Jrst GoOnp

NFound:	Type ,"No such command as :"
	Move A,[440700,,String]
	Ildb T1,A
	Skipn T1
	  Jrst Error
	.Iot TTYo,T1
	Jrst .-4

GoOnp:
Error:	Skipn OTOp
	  Jrst Prompt

Die:	.Logout 1,

;;;
;;;	TTY interrupt - Flush output on a ^S
;;;

Flush:	Movei T3,TTYi
	.ITYIC T3,
	  .Lose
	Skipe Echop
	  Caie T3,^S
	    Jrst Dismis
	.Reset TTYo,
	Type ,"Flushedî"
	.Reset TTYi,
	Skipe OTOp
	  Jrst Die
	Jrst ReProm

ReAsk:	Skipn Allowp
	  Jrst Dismis

ReProm:	Syscal DISMIS,[P ? %Climm,,Prompt]
	  .Lose

Dismis:	Syscal DISMIS,[P]
	  .Lose

;;;	Suboroutines

gFile:	Syscal OPEN,[%Clbit,,.uai
		     %Climm,,DSKi
		     [Sixbit /DSK/]
		     [Sixbit /DDTORD/]
		     [Sixbit />/]
		     [Sixbit /.INFO./]]
	  .Value [Ascii /: Can't find DDTORD? KILL /]
	.Access DSKi,[Bottom*5*2000]
	Syscal CORBLK,[%Climm,,%Cbprv
		       %Climm,,%JSelf
		     [-Length,,hPage]
		       %Climm,,DSKi]
	  .Value [Ascii /: Can't map in file? KILL /]
	Move A,[440700,,hLoc]

F0:	Ildb T1,A
	Caie T1,"^
	  Jrst F0
	DBP A
	Movem A,CtrlBP

	Move A,[440700,,13.*2000]
F1:	Move T2,T1
	Ildb T1,A
	Caie T1,"6
	  Jrst F1
	Caie T2,":
	  Jrst F1
	DBP A
	DBP A
	Movem A,ColBP
	Return

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

 ;;;
;;;;;
 ;;;

Variables
Constants

HPage==._-12+1
HLoc=HPage*2000

	END Begin