%begin
   %include "SYSINC:COMMAND.INC"
   %integer col
   %constinteger h = X'FFFF'
   %string(63) file, output
   %recordformat parmfm(%shortinteger dsno, dact, ssno, sact, %c
                        %integer p1,p2,p3,p4,p5,p6)
   %recordformat  pgmfm(%integer  limit,stack,gla,code base,ep,code,   %c
                                                %shortinteger  options)
   %ownrecord(parmfm) p, q
   %recordformat loadfm(%integer code, gla, specs, defs, when, file)
   %recordformat textfm(%integer n1, n2)
   %recordformat specfm(%integer gla, code, ep)
   %recordformat hdfm(%shortinteger base, n)
   %recordformat headfm(%shortinteger pure size, gla size, code disp, %C
                                      lit disp, registers, mainep, %C
                        %record(hdfm) reloc, defs, specs, ldiag, vdiag)
   %recordformat deffm(%shortinteger link, ep, %integer n1, n2)
   %ownrecord(headfm)%name head
   %record(specfm)%name spec
   %record(deffm)%name def
   %record(textfm)%name sp
   %integer base, code, gla, specs, defs

   %routine qsort(%string(15)%array %name p, %integer a, b)
      %string(15) dump
      %integer l, u
      %while a < b %cycle
         l = a;  u = b
         dump = p(u);  ->find

up:      l = l+1;  ->found %if l = u
find:    ->up %unless p(l) > dump
         p(u) = p(l)
down:    u = u-1;  ->found %if l = u
         ->down %unless p(u) < dump
         p(l) = p(u)
         ->up

found:   p(u) = dump
         l = l-1;  u = u+1
         %if l-a > b-l %start
            qsort(p,u, b);  b = l
         %else
            qsort(p,a, l);  a = u
         %finish
      %repeat
   %end

%string(15) %fn entry(%integer n1, n2)
   %string(15) s
   %integerfn  ch(%integer  n)
      %result = n-1+'A' %if n <= 26
      %result = n-27+'0' %if n <= 36
      %result = n-37+'#'
   %end
   %routine unpack(%integer k)
      %return %if k = 0
      unpack(k//40)
      k = rem(k, 40)
      s = s. to string(ch(k)) %unless k = 0
   %end
   s = ""
   unpack(n1>>16);  unpack(n1&X'FFFF')
   unpack(n2>>16);  unpack(n2&X'FFFF')
   %result = s
%end

   %integer max = (free space - 1024) >> 4
   %string(15) %array slots(1:max)
   %integer used = 0, j

   %routine Print slots
      %integer j, col = 0
      Spaces (4)
      %for j = 1,1,used %cycle
         Print string (slots(j))
         Spaces (14 - length(slots(j)))
         col = col + 1
         newline %and spaces(4) %if col&3 = 0
      %repeat
   %end

   file = command_in1
   file = file.".exe" %unless file -> (".")
   output = command_out1
   string(addr(p_sact)) = file
   svc(10, p)
   %if p_p1 # 0 %start
      printstring("Cannot load ".file)
      newline
      %stop
   %finish
   code = p_p2;  base = code-16
   gla = p_p3
   %if shortinteger(base+4) # X'4321' %start
      printstring(file." is an old format file")
      newline
      %stop
   %finish
   output = "T:" %if output = ""
   open output(1, output)
   select output(1)
   head == record(code)
   code = code+head_code disp&H*2
   specs = head_specs_n
   defs = head_defs_n

!!!   %if specs # 0 %start
!!!      printstring("External references:")
!!!      newline
!!!      %cycle
!!!         spec == record(gla+2*specs)
!!!         sp == record(base+spec_code>>16*2+16)
!!!         print entry(sp_n1, sp_n2)
!!!         specs = spec_gla&h
!!!         %exit %if specs = 0
!!!      %repeat
!!!      newline
!!!   %finish
   %if defs # 0 %start
      printstring("External entry points:");  newline
      %cycle
         def == record(base+2*defs+16)
         used = used + 1
         %if used > max %start
            Print string ("Too many entries")
            Newline
            %stop
         %finish
         slots(used) = entry(def_n1, def_n2)
         defs = def_link&h
      %repeat %until defs = 0
      Qsort (slots,1,used) %if command_modifier = 0
      Print slots
      newline
   %finish
%endofprogram
