PROCEDURE dum$search_sft, seasft (
  field, f: any of
    name
    string
  anyend = asid
  value, v: any  = $required
  type: key
    (natural, n)
    (integer, i)
  keyend = natural
  exit_on_first, eof: boolean = true
  display_option, do: key
      (full, f, all)
      (brief, b)
    keyend = brief
  ptl: integer = 0
  output: file = $output
  status)

  " Search the system file table for any field in the entry

  "$FORMAT=OFF"
  VAR
    any_found: boolean = FALSE
    asti: integer
    current: name = $current_module
    fde: integer
    fde_table: integer = 100000000(16) + $mem($sa(gfv$fde_table_base) 8)
    gfc$fde_size: integer = $mem($sa(gfv$fde_size) 8)
    gfc$max_file_descriptor_index: integer = 0ffff(16) "maximum value of gft$file_descriptor_index"
    local_field: name = field
    local_value: any = value
  VAREND
  "$FORMAT=ON"

  chadm dmm$file_table_manager

  IF local_field = asid THEN
    dum$asti xasid=local_value ptl=ptl xasti=asti
    local_field = $name('ASTI')
    local_value = asti
  IFEND

  FOR i = 0 TO gfc$max_file_descriptor_index DO
    fde = fde_table + (i * gfc$fde_size)
    IF $pv(?fde.gft$file_descriptor_control.file_hash) <> 0FF(16) THEN
      IF type = integer THEN
        any_found = ($pv(?fde.gft$file_descriptor_entry.?local_field,,,,,integer) = local_value)
      ELSE
        any_found = ($pv(?fde.gft$file_descriptor_entry.?local_field) = local_value)
      IFEND

      IF any_found THEN
        put_line ' -- File entry '//$strrep(i, 16)//'(16) matches.  GFN = '//..
$pv(?fde.gft$file_descriptor_entry.global_file_name) o=output.$eoi

        IF display_option = full THEN
          dispv ?fde.gft$file_descriptor_entry o=output.$eoi
          IF $pv(?fde.gft$file_descriptor_entry.media) = gfc$fm_mass_storage_file THEN
            p_disk_file_descriptor = 100000000(16) + ..
                  $pv(?fde.gft$file_descriptor_entry.disk_file_descriptor_p)
            dispv ?p_disk_file_descriptor.dmt$disk_file_descriptor o=output.$eoi
          ELSEIF $pv(?fde.gft$file_descriptor_entry.media) = gfc$fm_served_file THEN
            p_server_descriptor = 100000000(16) + ..
                  $pv(?fde.gft$file_descriptor_entry.served_file_descriptor_p)
            dispv ?p_server_descriptor.dft$server_descriptor o=output.$eoi
          IFEND
          put_line ' ------------------------ ' o=output.$eoi
        IFEND

        IF exit_on_first THEN
          chadm current
          EXIT_PROC
        IFEND
      IFEND
    IFEND
  FOREND

  IF NOT any_found THEN
    put_line ' -- No SFT entry found for field: '//field//', value = '//value  o=output
  IFEND

  chadm current

PROCEND dum$search_sft
