PROCEDURE dum$locate_global_file_name, locate_global_file_name, locgfn (
  global_file_name, gfn: name = $optional
  file, f: file = $optional
  status
  )

  IF $specified(global_file_name) AND $specified(file) THEN
    EXIT_PROC WITH $status(false 'us' 0 'cannot specify both gfn and file')
  ELSEIF (NOT $specified(global_file_name)) AND (NOT $specified(file)) THEN
    EXIT_PROC WITH $status(false 'us' 0 'must specify either gfn or file')
  IFEND

  "$FORMAT=OFF"
  VAR

" The following constant is found in the deck GFC$CONSTANTS.

    gfc$fde_size: integer = $mem($sa(gfv$fde_size) 8)

    gfc$fde_table_base: integer = $mem($sa(gfv$fde_table_base) 8)
    gfc$max_file_descriptor_index: integer = 0ffff(16) "maximum value of gft$file_descriptor_index"

    global_name_offset: integer = 17(16)
    local_gfn: string
    sft: integer
  VAREND
  "$FORMAT=ON"

  IF $specified(global_file_name) THEN

" Convert the Global_File_Name input parameter into a representation that would be found in memory.

    local_gfn = $convert_unique_name($string(gfn))
  ELSE
    "$FORMAT=OFF"
    VAR
      attributes: any
    VAREND
    "$FORMAT=ON"

" Determine the Global_File_Name from the File input parameter and convert it into a representation that would
" be found in memory.

    attributes = $file_attributes(file,unique_data_name)(1)
    IF $field(attributes,unique_data_name,specified)
      putl ' Global File Name = '//attributes.unique_data_name
      local_gfn = $convert_unique_name(attributes.unique_data_name)
    ELSE
      put_line,l=' Unknown file: '//file
      exit_proc
    IFEND
  IFEND

  sft = 100000000(16) + gfc$fde_table_base
  FOR i = 0 TO gfc$max_file_descriptor_index DO
    fde = sft + (i * gfc$fde_size)
    IF local_gfn = $ms(fde+global_name_offset, 11) THEN
      putl ' File entry {FDE} '//$strrep(i, 16)//'(16) matches.'
      EXIT_PROC " <------------ "
    IFEND
  FOREND

  putl ' No SFT entry found for the specified global file name.'

PROCEND dum$locate_global_file_name
