; -*- MIDAS -*-

if1 Title TTLOC -- Tell where a terminal is located


a=1
b=2
c=3
d=4
e=5
dskc=10
p=17

define syscal op,args
       .call [setz ? sixbit /op/ ? args ((setz))]
termin

argi=1000,,0
val=2000,,0
cnti=5000,,0

ttsize=21			   ;80 characters + 1 word
datpag==2			   ;page we use for the database
tabloc=datpag*2000		   ;Start of the database

beg:	move p,[-7,,pdl]
	syscal OPEN,[ cnti .uii ? argi dskc ? [sixbit /DSK/]
		    [sixbit /TTLOC/] ? [sixbit /DATA/] ? [sixbit /SYSBIN/]]
	  jrst [ syscal OPEN,[ cnti .uio ? argi dskc ? [sixbit /DSK/]
			       [sixbit /TTLOC/] ? [sixbit /DATA/]
			       [sixbit /SYSBIN/]]
		   .lose %lsfil
		 move a,[-2,,datpag]
		 syscal CORBLK,[ argi %cbndw\%cbndr ? argi %jself
				 a ? argi %jsnew]
		   .lose %lsfil
		 move a,[444400,,<<datpag>*2000>]
		 movei b,4000
		 syscal SIOT,[ argi dskc ? a ? b]
		   .lose %lsfil
		 .close dskc,
		 jrst beg]	   ;  retry!
	move a,[-2,,datpag]
	movsi b,-2		   ;-2,,0
	syscal CORBLK,[ argi %cbndw\%cbndr ? argi %jself ? a
			argi dskc ? b]
	  .lose %lssys
	.close dskc,
	move c,[-3,,[ .rcnsl,,a ? .runame,,uname ? .rxjname,,b]]
	.suset c
	jumpl a,[.logout 1,]	   ;detached or something
	and b,[770000,,0]	   ;check the frist char of our JNAME
	camn b,[sixbit /S/]	   ;Is this a STYLOC?
	  jrst styloc		   ; yes, don't translate stys
	syscal STYGET,[ argi %jsnum(a) ? val b]	 ;get UIND of sty owner
	  .lose %lssys
	hrrzs b			   ;clear left half
	jumpe b,styloc		   ;If it's zero, this isn't a STY
	move c,[-4,,[ sixbit /CNSL/ ? movem b ? sixbit /UNAME/ ? movem d]]
	syscal USRVAR,[ argi %jsnum(b) ? c]  ;get that TTY# and his UNAME
	  .lose %lssys
	jumpl b,styloc		   ;No TTY, don't do it!
	jumpe d,styloc		   ;No uname??
	movei a,(b)		   ;use this TTYLOC
	movem d,uname		   ;and this uname
styloc:	imuli a,ttsize		   ;compute offset of TTY in table
	addi a,tabloc		   ;make it absolute
	move b,uname		   ;include the UNAME to note change of users
	movem b,(a)		   ;as the first word in the entry
	aos a			   ;next word starts the text area
	setzm (a)		   ;Must empty out the area for DDT to hack it
	hrli b,(a)		   ;from this word
	hrri b,1(a)		   ;to the next word
	blt b,ttsize-2(a)	   ;clearing all the buffer
	.break 12,[..rjcl,,jclbuf] ;get our JCL into the data area
	skipn jclbuf		   ;If there's no JCL
	  jrst flush
	ldb b,[350700,,jclbuf]	   ;Is the JCL null?
	cain b,33		   ;Magic escape?
	  jrst magesc		   ;  Don't flush it!
	caie b,^I		   ;Tab is space.
	  cail b,40		   ;  control char?
	    caia
	      jrst flush
magesc:	setz b,			   ;a null
	move c,[010700,,jclbuf+ttsize-2]  ;mark the end of the string
	dpb b,c
	hrli a,440700		   ;turn A into a Byte Pointer
	move c,[440700,,jclbuf]	   ;and get a Byte Pointer to our data
	move e,rooms		   ;get aobjn ptr to room definitions
roomck:	hlrz d,(e)		   ;get asciz abbrev for room
	hrli d,440700		   ;make it a Byte Pointer
	pushj p,streq		   ;equal?
	  caia
	    jrst [ hrrz c,(e)	   ;  yes, we found it!
		   hrli c,440700   ;  use the expansion instead of the JCL
		   jrst found]
	aobjn e,roomck		   ;next room
found:	pushj p,copy		   ;copy the string
	.logout 1,		   ;bye-bye

copy:	ildb b,c		   ;get a char
	cain b,^I		   ;Don't let TAB's confuse NAME
	  movei b,40		   ;  use a space instead!
	cain b,33		   ;magic escape?
	  jrst copy1
	cail b,40		   ;And if it's a control-character,
	  cain b,177		   ;  or rubout?
	    popj p,		   ;    that's the end

copy1:	idpb b,a		   ;otherwise send it out
	jrst copy		   ;and do another one

flush:	setzm (a)		   ;clear out first word
	setzm -1(a)		   ;clear out UNAME (overkill)
	.logout 1,
	
streq:	push p,a
	push p,b
	push p,c
streq1:	ildb a,d		   ;get char of match string
	ildb b,c		   ;get a char of string being tested
	cain a,^I		   ;Tab?
	  movei a,40		   ;  That's a space here
	cain b,^I		   ;Tab?
	  movei a,40		   ;  That's a space here!

	jumpe a,[ caie b,177
		    caige b,40	   ;  End of the tested string?
		      aos -3(p)	   ;    yes, it's a match
		  jrst strext]	   ;  In any event, there's no more

	caige b,40		   ;If this is a terminating char
	  cain b,33		   ;Magic escape is OK, goes in
	    caia
	      jrst strext	   ;if it's the end already can't be equal
	cail b,"a		   ;uppercasify
	  caile b,"z
	    caia
	      subi b,40
	cail a,"a
	  cail a,"z
	    caia
	      subi a,40
	cain b,(a)		   ;are they the same?
	  jrst streq1		   ;  yes, try next
strext:	pop p,c
	pop p,b
	pop p,a
	popj p,			   ;no, fail return

uname:	0
pdl:	block 10		   ;very short pdl
jclbuf:	block ttsize-1
	-1			   ;mark the end of the buffer

roomct==0
define room [name],-info
  roomct==roomct+1
  foo=[asciz énfoÝ
  irp loc,,name
    [asciz ìocÝ,,foo
  termin
  expunge foo
termin

rooms:	-rmsize,,.+1

	;; Secretary(-ies)

	room [803,CYNTHI,Cynthia]  ,803 Cynthia's Office, x5869

	;; Mathlab Group

	room [800F]		   ,800F Lisp Machines x6026

	room [831,JM,MERMAN]	   ,831 Goodine x5891

	room [833,RLB,CWH,SOLEY]   ,833 Hoffman, Soley x5887

	room [834,KMP,WGD,BIL,BILD],834 Dubuque x7834

	room [839,CEL]		   ,839 Leiserson x5833

	;; 7th floor

	room [723,Alan,HQM]	   ,723 x8843 Alan, HQM

	;; 5 floor people
	room [540,JNC,Chiappa],540 Chiappa, x3-6018
	room [537,Bisbee,Feingold,OAF],537 Bisbee,Feingold x3-6013
	room [513,Reed,DPR],513 Reed
	room [512,Fagin,Clark,DCLARK],512 Fagin,Clark x3-6002
	room [510,Gramlich,Greenwald,Goldfarb],510 Gramlich,Greenwald,Goldfarb x3-6042
	room [509,Sollins,Theriault,Frankel],509 Sollins,Theriault,Frankel x3-6006
	room [508,Koile,Topolcic,Zhang],508 Koile,Topolcic,Zhang x3-6005
	room [507,Svobodova,Lopez,Estrin],507 Svobodova,Lopez,Estrin
	room [506,Webber],506 Webber x3-6023
	room [505,Saltzer],505 Saltzer x3-6016
	room [503,Ludwig,Baldwin],503 Ludwig, Baldwin x3-6020
	room [502,Cooper,Plotnick,Allen,Patton],502 Cooper,Plotnick,Allen,Patton x3-6061
	room [501,Martin,Thomas],501 Martin, Thomas
	room [206,HP2640],206 HP2640 x3-1419
	room [RTS,UNIX,4th],4th floor x3-6048
	room [433,JAR,DAM],433 JAR, DAM x3-8581

	;; cdmg

	room [369,TAR]		   ,369 Russ x3533
	room [304,CIA]             ,No Such Room
	room [368,WJL]             ,368 Long x3508
	room [372,CRE,BEN]         ,372 Kuipers, Eliot x3510
	room [365,PSZ]		   ,365 Szolovits x3476
	room [366,ROSIE] ,366 Rosie's Office, x5860
	room [367,RAMESH,Patil]    ,367 Patil x3539
	room [355,GSB]             ,355 Burke, Randoms x3546

	;; Random LCS 

	room [hell,hades]	    ,833 Hades x5887
	room [800D,coke]	    ,800D Consoles
	room [9th,9mc]              ,9th Floor VT52 by MC x6765
	room [9ai]                  ,9th Floor next to AI x6765

	room [shit,barf,piss]       ,Men's room, third stall

	;; Delphi

	room [delphi]				      ,Delphi (38-376) x4650
	room [staff,6.031ta,6.031tas,6-031ta,6-031tas],Delphi (Staff) x2737
	room [utas,6.030ta,6.030tas,6-030ta,6-030tas] ,Delphi (38-376) x1965

	;; Personal options

	room [CBF]                 ,CBF at home
	room [KRNZ]		   ,835 Krnz' Office, x5217
	room [LIZZY]		   ,Central NJ Cookoff 201-463-3109
	room [PSZH]		   ,Melrose Hackers Home  662-8257
	room [wer]		   ,WER's H19, 225-6242
	room [WJLH]		   ,WJL in Waltham, 899-0180
	room [AlanHome]		   ,Bear's House (492-7274)
	room [BANDY]		   ,knocking 'em dead
	room [Ellis]		   ,ELLIS.DEC.COM: Boston 423-3953

	;; Impersonal Options

	room [esg],ESG (x3-7787)
	room [studc,library,studctr],Student Center (x5-9187)
	room [random]		    ,Basement of Random Hall
	room [srf]		    ,Atlantis
	room [teco]		    ,Teco Madness
        room [txi]		    ,Theta Xi (x3-3154)
room [prt,pritchet,pritch,prittchet,pritchett],Pritchett Lounge, Out to Lunch
	room [lunch]		    ,Out to Lunch
	room [lsc,movie]	    ,Gone to the LSC movie
	room [rolm]		    ,Rolm Data Frobozz

	;; SIPB

	room [SIPB,orifice]         ,SIPB, 11-205, x3-7788

	;; Architecture Machine Group

	room [9532,9-532,spg,amg]   ,MIT-AMG, 9-532, x5156
	room [9550,9-550]	    ,MIT-AMG, 9-550, x7920

	;; Nonlocal sites

	room [sdrc]		    ,SDRC: Ridgefield, CT
	room [s1,amber]	    	    ,LLL: S1 Palace
	room [lextip,lextac]	    ,LEXINGTON-TAC#259: 862-0921
	room [lex] 		    ,Lexiphage, 862-0921
	room [hitech]		    ,High Tech 267-0191
	room [sym]		    ,At home, having fun
	room [crg,gluteus]	    ,LLL: Gluteus Vaximus
	room [foggy,sf,berkeley]    ,FOGBOUND: in the hills
	room [cooler]		    ,in the cooler

rmsize==.-rooms-1

;; note that the "random" ! in the text of the PRINTX is necessary to break up
;; the define part so it's not thought to be part of a TERMIN

define roomsz size,#count
  define szroom #foobar
    printx |There are count rooms defi!ned, for a total of foobar abbreviations.
|
  termin
if2 szroom size
termin 

roomsz rmsize,roomct

end beg
