%begin;!Combined PRELOAD and INSTALL

%recordformat DICT(%integer a,b,c,d)
%record(dict)%spec(16_3FC0) FILDICT
%record(dict)%spec(16_3FD0) EXTDICT
%integerfnspec(16_117C) DEFNAME(%string(255)s,%record(dict)%name d,%integer size)
%integerfnspec(16_1180) REFNAME(%string(255)s,%record(dict)%name d)
%routinespec(16_1184)   TRANSNAME(%integer ref,%string(255)%name s)
%integer i,k,hold,fref,idref,p,l
%externalstring(255)%fnspec cliparam
@16_408 %integerfn loadfile(%string(255)what,%integer where)
@16_3ff0 %integer freebot
%string(255)parm = cliparam
%string(31) fname,id
  parm = parm.","
  %while parm -> fname.(",").parm %cycle
    %for i = 1,1,length(fname) %cycle
      k = charno(fname,i)
      charno(fname,i) = k+('A'-'a') %if k>='a'
    %repeat
    fname = fname.".MOB"
    p = freebot; l = loadfile(fname,p)
    fref = defname(fname,fildict,8)
    hold = fref
    fref = fref&16_7FFFFFFF %if fref < 0
    printstring("File dict full") %and %stop %if fref = 0
    integer(fref) = p; integer(fref+4) = p+l; freebot = (p+l+3)&\3
    %unless shortinteger(p)=16_fffffe00 %start{16_fe00 %start
      printstring(fname." does not contain externals")
      newline
    %else
      p = p+2
      %cycle;  !For each entry
        id = string(p); p = p+20
        idref = defname(id,extdict,8)
        printstring("External dict full") %and %stop %if idref = 0
        %if idref < 0 %start
          idref = idref&16_7FFFFFFF
          %if integer(idref) # fref %start
            printstring("Re-defined entry-point: ".id);  newline
          %else %if hold>=0
            printstring("Duplicate entry for ".id); newline
          %finish
        %finish
        integer(idref) = fref
      %repeat %until byteinteger(p) > 11;  !FE
    %finish
    %if hold<0 %start
      printstring(fname." re-installed"); newline
    %else
      printstring(fname." installed"); newline
    %finish
  %repeat
%endofprogram
