; -*- Midas -*-
;
; To create new binary file after munging text definitions (see
; last 2 pages of this file) just assemble into desired filename.
; e.g. :MIDAS INQUIR;DIRS BIN_DMUNCH

ife .fnam1-.ifnm1,[	; Conditional true if file not being .INSRT'd.
title DMUNCH
.decsav		; to avoid cretinous sblk loader etc.
nosyms
insrtd==0
]
.else [
.begin hsname
insrtd==1
]

comment |

HSNAME TABLE:
	0: -<# entries>,,# wds/entry
	1-n: MACH entries

=================================================================
Sub-tables

	mach wd 0: <machine name>	; 6bit returned by SSTATU
	mach wd 1: <site #>		; Arpanet site #.
	mach wd 2: <addr of sub-table>	; Addr is rel to start of HSNAME-table.
	mach wd 3: <addr of tourist subtable>

Each sub-table is simply:
	0: -<# entries>,,# wds per entry	; RH is currently 2.
	1-n: NAME entries

	entry wd 0: UNAME	; For all unames => this but < next entry,
	entry wd 1: HSNAME	; this is the HSNAME.

|

	; HSNAME table indices
hx$mch==:0	; wd 0 of mach-table entry is mach name, as per SSTATU call.
hx$hst==:1	; wd 1 is arpanet host #.
hx$nrm==:2	; wd 2 is sub-table ptr for normal unames.
hx$tur==:3	; wd 3 is sub-table ptr for tourists.
hx$ail==:4
hx$len==:5	; # wds per mach-table entry

	; Sub-table indices
hs$unm==:0	; wd 0 of sub-table entry is UNAME
hs$hsn==:1	; wd 1 is HSNAME for range.
hs$len==:2	; # wds per sub-table entry


ife insrtd,[

if2 word -<%nmach>,,hx$len
%loc==1
%nmach==0

define mach abr,mname,host,list
%sav==%loc
word sixbit /mname/	; store name of mach
word host		; and site #
%loc==%loc+2
irp d,,[0,1,2,3,4,5,6]	; then various args for mach.
  ifle <hx$len-hx$nrm>-d, .istop
  ifdef s%!d!!abr, word s%!d!!abr
	.else word 0
  %loc==%loc+1
  termin
%sav==hx$len-<%loc-%sav>
ifg %sav, repeat %sav,[ word 0 ? %loc==%loc+1 ? ]
%nmach==%nmach+1
termin

define subtab abr,idx,list
s%!idx!abr==%loc		; note loc of subtable
word -<c%!idx!abr>,,hs$len	; set <# entries>,,<# wds per entry>
%loc==%loc+1
%ecnt==0
irp pair,,[list]
  irp uname,hsname,[pair]
    ife %ecnt,[ifnb [uname][		; Make sure 1st entry has zero uname.
			word setz
			word sixbit |hsname|
			%ecnt==%ecnt+1
			%loc==%loc+hs$len
			]]
    word <sixbit |uname|>#setz
    word sixbit |hsname|
    %ecnt==%ecnt+1
    %loc==%loc+hs$len
    .istop
    termin
  termin
c%!idx!abr==%ecnt	; set # entries.
termin

] ; ife insrtd,


; MACHINE definitions - Syntax is
;	MACH <abbrev>,<sixbit sitename>,<host>,<list>
;	where <abbrev> must be 3 letters or less, and <sitename> must be what
;	a SSTATU call returns, and <host> is the arpanet site #.

MACH AI,AI,206,[[3,USERS1]]
MACH MC,MC,354,[[4,USERS1],[3,GUEST1]]
MACH MX,MX,-1,[[4,USERS1],[3,GUEST1]]
MACH MD,MD,-1,[[2,USERS1]]
MACH ML,ML,-1,[[3,USERS1]]
;MACH ML,ML,306,[[3,USERS1]]
;MACH DM,DM,106,[[2,USERS1]]

;;; This is not the most flexible kludge in the world.
;;; Users are divided into directory groups, each of which has a subtable.
;;;  #0 is for normal users (who don't have their own dir).
;;;  #1 is for tourists.
;;;  #2 is defined on MC and ML for AI lab users.
;;; 
;;; User group mapping information is procedurally embedded in the LSRTNS"LSRSNN routine.

; DIRECTORY SUBTABLE definitions - syntax is:
;	SUBTAB <abbrev>,<table #>,<directory list>
;	<abbrev> is one of those defined by MACH,
;	<table #> is 0 for normal, 1 for tourist.
;	<dir list> is a list of paired names; the first
;		name is the start of a UNAME range extending up to
;		but not including the next pair, and the second
;		name is the HSNAME for that range.
;		NOTE: the first name of the first pair should be null.
; e.g.
; SUBTAB AI,0,[[,GUEST0],[K,GUEST1],[P,GUEST2]]
;	which defines the "normal" (0) subtable for AI to have 3 directories,
;	GUEST0 for UNAMES from null to "L_____" inclusive,
;	GUEST1 for UNAMES from "K" to "O_____" inclusive, and
;	GUEST2 for UNAMES from "P" to "______" inclusive.
;

SUBTAB AI,0,[[,USERS1],[GS,USERS2],[MP,USERS3]]

SUBTAB MC,0,[[,USERS0],[DA,USERS1],[F,USERS2],[J,USERS3],[JO,USERS4],[KJ,USERS5],[NR,USERS6],[R,USERS7],[RL,USERS8],[SR,USERS9]]
SUBTAB MC,1,[[,GUEST0],[D,GUEST1],[I,GUEST2],[LJ,GUEST3],[PD,GUEST4],[T,GUEST5]]
SUBTAB MC,2,[[,AI0]]

SUBTAB MX,0,[[,USERS0],[DA,USERS1],[F,USERS2],[J,USERS3],[JO,USERS4],[KJ,USERS5],[NR,USERS6],[R,USERS7],[RL,USERS8],[SR,USERS9]]
SUBTAB MX,1,[[,GUEST0],[D,GUEST1],[I,GUEST2],[LJ,GUEST3],[PD,GUEST4],[T,GUEST5]]
SUBTAB MX,2,[[,AI0]]

SUBTAB MD,0,[[,USERS1],[KK,USERS2]]

SUBTAB ML,0,[[,USERS1],[GS,USERS2],[MP,USERS3]]
SUBTAB ML,2,[[,AIRAN]]

;SUBTAB DM,0,[[,USERS1],[KK,USERS2]]


ifn insrtd, .end hsname
ife insrtd, end
