%include "managr:nsdefs.inc"
%include "inc:fs.imp"
%include "inc:util.imp"
%include "managr:ns.inc"

%conststring (31) %array peripheral(0:25) = %c
{A} "0.5Mb memory board",
{B} "68010 processor board",
{C} "8MHz processor board",
{D} "10MHz processor board",
{E} "2MHz Ethernet board",
{F} "10MHz Ethernet board",
{G} "Level 1 graphics",
{H} "Level 1.5 graphics",
{I} "?MHz processor board",
{J} "level 2 graphics",
{K} "K???",
{L} "2.0Mb memory board",
{M} "Mouse controller",
{N} "N???",
{O} "O???",
{P} "Laser Printer controller",
{Q} "QSART board",
{R} "RTS interface board",
{S} "Special board",
{T} "T???",
{U} "U???",
{V} "V???",
{W} "W???",
{X} "MIT graphics monitor",
{Y} "Unknown monitor",
{Z} "Twin Floppy-Dicks",
%begin
%integer xno,dte,i,j
%record (ns lfm) data
%string (255) param
%bytearray sname(0:8)

%integerfn hex(%string (*) %name s)
   %integer i,no,a
   no=0
   %for i=1,1,length(s) %cycle
      a=charno(s,i); a=a-' ' %if 'a'<=a<='z'; a=a-'0'
      a=a-7 %if a>9
      %exit %unless 0<=a<=15
      no=no<<4+a
   %repeat
   %result=no
%end


xno=0
param=cliparam
%if param="" %start
   dte = etherstation
%else
!   %if charno(param,1) = '@' %start
!      xno=open ns db
!      dte = get ns dte(param)
!   %else
      dte = hex(param)
!   %finish
%finish

printline("Funny value ".param) %and %stop %if dte<=0 %or dte>=128
xno = open ns db %if xno=0

i = read ns db(xno, dte!long, addr(data))
printline("No information on ".param.",".itos(i,-1)) %and %stop %if i<0
sname(0) = read ns db(xno, dte, addr(sname(1)))
sname(0) = sname(0)-1 %while sname(0) > 0 %and sname(sname(0)) <= ' '
close ns db(xno)
printstring("Station "); phex2(dte)
printstring(" (")
%if sname(0)>0 %start
   %for i=1,1,sname(0) %cycle; printsymbol(sname(i)); %repeat
%finish
printstring("): ")

%if data_inon = 'I' %start
   printstring("In ")
%elseif data_inon = 'O'
   printstring("On ")
%elseif data_inon = 'A'
   printstring("At ")
%finish

printstring("the ") %if data_room = 'T'

%for j=31,-1,1 %cycle; %exit %if data_lname(j) > ' '; %repeat
%for i=1,1,j %cycle; printsymbol(data_lname(i)); %repeat
printstring("'s room") %if data_room = 'R'
newline

printstring("   Case"); write(data_case,3); newline
printstring("   Location ")
%for i=1,1,4 %cycle; printsymbol(data_add(i)); %repeat; newline
printline("   Recorded Peripherals:")
%for i=1,1,18 %cycle
   %if data_bpmap(i) # '.' %and data_bpmap(i) # '*' %then %C
   printline("      ".peripheral(data_bpmap(i)-'A'))
%repeat
%endofprogram
