PROCEDURE qcp$list_catalog (
  catalog, c: file = $required
  file_list, fl: file = $null
  depth, d: integer 1..$max_integer = 1
  file_count, fc: (VAR) integer = $optional
  status)



"  The purpose of this request is to create a file listing of all the files
"under the specified catalog and it's subcatalogs.  Each file is listed by
"it's complete path name and a count is kept on the total number of files
"found if parameter file_count is specified.  NOTE: File_count must be initialized
"to '0' by the caller in order to work properly.


  VAR
    ignore_status: status
    local_status: status
    scratch_file: file = $LOCAL//$name($unique)
    new_catalog: file
  VAREND


"  A catalog listing is obtained and processed line by line.
"An end of list marker is placed at the bottom of the list to
"determine when to stop list processing.  The DEPTH parameter
"is used to indicate how many subcatalog level to traverse
"looking for files.  The procedure decrements it by one.
"When the depth parameter = 0, subsequent catalogs are not searched.


  depth = depth - 1
  $system.set_file_attributes f=scratch_file fc=legible pf=continuous pw=65000
  $system.display_catalog c=catalog do=identifier o=scratch_file status=local_status
  IF NOT local_status.normal THEN
    $system.delete_file f=scratch_file status=ignore_status
    EXIT procedure WITH local_status
  IFEND

  $system.rewind_file f=scratch_file status=ignore_status
  LOOP
    line = ' '
    $system.accept_line v=line i=scratch_file//$name('$asis') status=local_status
    EXIT WHEN (NOT local_status.normal) OR (line = ' ')
    index = $scan_string('CATALOG:', line)

    IF (index <> 0) AND (depth > 0) THEN


"  The catalog contains a subcatalog that is to be processed before
"continuing with the current catalog and the current catalog depth has
"not been exceeded.


      new_catalog = catalog//$name($substring(line, index+9, $size(line)-(index+8)))
      IF $specified(file_count) THEN
        qcp$list_catalog new_catalog file_list depth file_count status=local_status
      ELSE
        qcp$list_catalog new_catalog file_list depth status=local_status
      IFEND
      EXIT WHEN NOT local_status.normal
    ELSE

      index = $scan_string('FILE:', line) + 6
      IF index > 6 THEN


"  The catalog contains a file.  Construct the path and add it to the file list.


        $system.put_line $string(catalog)//'.'//$substring(line, index, $size(line)-index+1) ..
              o=file_list//$name('$eoi') status=local_status
        EXIT WHEN NOT local_status.normal
        IF $specified(file_count) THEN
          file_count = file_count + 1
        IFEND
      IFEND
    IFEND

  LOOPEND
  $system.delete_file f=scratch_file status=ignore_status

  EXIT procedure WITH local_status WHEN NOT local_status.normal

PROCEND qcp$list_catalog

