begin ;  !INSTALL externals
!modded JHB 21/1/86 to avoid messy event 3 if file is inaccessible

include  "inc:dict.imp"
include  "inc:util.imp"

externalroutinespec  install module(string (255)module); !FE02

routine  oinstall(string (255)fname);                    !FE00
integer  i,j,k,kk,hold,fref,idref
string (31)id
{}printstring("File dict full") and  -> end if  fildict_lim-fildict_pos<=32
  fref = defname(fname,fildict,8)
  hold = fref
  fref = fref&16_7fffffff
  printstring("File dict full") and  ->end if  fref = 0
  cycle ;  !For each entry
    id = ""
    read symbol(j);  !string length
    for  i = 1,1,11 cycle 
      read symbol(k);  id = id.tostring(k) if  i<=j
    repeat 
{}  printstring("External dict full") and  ->end if  extdict_lim-extdict_pos<=32
    idref = defname(id,extdict,8)
    printstring("External dict full") and  ->end if  idref = 0
    if  idref < 0 start 
      idref = idref&16_7fffffff
      if  integer(idref) # fref start 
        printline("Replacing entry for ".id)
      else  if  hold>=0
        printline("Duplicate entry for ".id)
      finish 
    finish 
    skip symbol;  skip symbol
    skip symbol;  skip symbol;  !type
    skip symbol;  skip symbol
    skip symbol;  skip symbol;  !displacement
    integer(idref) = fref
  repeat  until  next symbol > 11;  !FE
  return 
end: printstring(" - cannot install ".fname); newline
end 

routine  install(string (255)module)
string (255)file
integer  i,j=0
bytename  k
  on  3 start 
     printline("Install fails: ".file." not found")
     return 
  finish 
  file = module
  k == charno(module,1)
  for  i = 1,1,length(module) cycle 
    k = k&95 if  'a'<=k<='z'
    j = j<<8+k
    k == k[1]
  repeat 
  file = file.".MOB" unless  j='.MOB'
  openinput(1,file); selectinput(1)
  readsymbol(i); ->no unless  i=16_fe
  readsymbol(i)
  if  i=2 start 
    closeinput
    install module(module)
  elseif  i=0
    oinstall(file)
    closeinput
  else 
no: closeinput
    printline("Install fails: ".file." is not an object file")
  finish 
end 

string (255)parm,module

  parm = cliparam.","
  install(module) while  parm -> module.(",").parm

endofprogram