PROCEDURE (ram$lispc) list_procedure_content, list_procedure_contents, lispc (
  procedure, procedures, p: any of
      key
        all
      keyend
      list 1..$max_list of any of
        integer radix 16
        name
        string
      anyend
    anyend = all
  from, f, library, l: file = $working_catalog.command_library
  output, o: file = $output
  page_length, pl: (BY_NAME, ADVANCED) integer 1..6000 = 60
  status)

" PURPOSE:
"   List the specified modules from a libaray or object file.
" DESIGN:
"   Scan every module name on the library for each specified value. Write the selected modules to the
"   output file in alphabetical order.
" NOTES:
"   An integer procedure value is hexadecimal, convenient when processing CDCNET configuration procedures.
"   Creation dates are suppressed for object files.

"$format=no
  VAR
    blank_line:          string = ' '
    current_library:     file= from//$file(from, cycle_number)
    current_module:      name
    creation:            string = ' '
    first_page:          integer = 0
    ignore:              status
    index:               file = $unique(:$local)
    index_page:          integer = 0
    lines_in_procedure:  integer = 0
    lines_to_print:      integer = 0
    list_of_all_modules: file= $unique(:$local)
    list_status:         status
    modules_on_file:     list 0..$max_list of string = ()
    modules_to_display:  list 0..$max_list of string = ()
    number_of_pages:     integer = 0
    number_of_procedures: integer = 0
    out:                 file= $unique(:$local)
    page_length_used:    integer = page_length-3
    page_number:         integer = 0
    pages:               string
    procfile:            file= $unique(:$local)
    procedure_content:   array 1..page_length_used of string
    specified_name:      string 1..31
    system_information:  string = $justify($string($processor(model, 0)//'/'//$processor(serial, 0)//..
'  '//$job(os_version)//'     '//$date(iso)//'  '//$time), 72, center)
    total_lines:         integer = 0
    index_entry: (DEFER) string = '  '//$justify($string(number_of_procedures),4, right)//$trim(module)//..
$justify(pages, 110-$size($string($trim(module))), left, '.')//' PAGE '//$justify($string(first_page), 4, right, ' ')
    index_line1: (DEFER) string = '1 TABLE OF CONTENTS                             '//system_information//..
'INDEX '//$justify($string(index_page), 5, left)
    index_line2: (DEFER) string = '        LIBRARY: '//$string(current_library)
    title_line1: (DEFER) string = '1 SOURCE LIST OF '//$justify($translate(upper_to_lower,$string(current_module)), 31, left)//..
system_information//'PAGE '//$justify($string(page_number), 5, left)
    title_line2: (DEFER) string = '        LIBRARY: '//$string(current_library)//creation
  VAREND
"$format=yes

  WHEN exit DO
    delete_file index status=ignore
    delete_file list_of_all_modules status=ignore
    delete_file out status=ignore
    delete_file procfile status=ignore
  WHENEND

"Set necessary file attributes
  set_file_attributes file=index file_content=list open_position=$eoi
  set_file_attributes file=list_of_all_modules page_format=untitled open_position=$boi
  set_file_attributes file=out file_content=list open_position=$asis
  set_file_attributes file=procfile page_format=continuous open_position=$asis file_content=legible

"Get a list of all of the modules on the command_library.
  display_object_library library=from display_option=date_time alphabetical_order=yes ..
        output=list_of_all_modules
  get_line variable=modules_on_file input=list_of_all_modules
  delete_file file=list_of_all_modules

"Determine which modules are to be displayed.
  IF $generic_type(procedure)= 'KEY' THEN "display all procedures
    modules_to_display=$select(modules_on_file, $size(x)>0)
  ELSE "select the modules to display
    FOR EACH procedure_specified IN procedures DO
      IF $generic_type(procedure_specified)= integer THEN "CDCNET config proc
        specified_name=$integer_string(procedure_specified, 16)
      ELSE "a substring of the procedure name was specified
        specified_name=$string(procedure_specified)
      IFEND
      modules_to_display=$union(modules_to_display, ..
            $select(modules_on_file, $scan_string(specified_name, $substring(x, 1, 31))>0))
    FOREND
  IFEND

  PUSH file_connections
  create_file_connection $response index

"Display the appropriate information based module type.
  CREATE_OBJECT_LIBRARY
    FOR EACH module IN modules_to_display DO
      number_of_procedures=number_of_procedures + 1
      current_module=$name(module(2, 31))
      add_module library=current_library module=current_module
      rewind_file file=procfile
      IF $scan_string('procedure', module)<> 0 THEN
        generate_library library=procfile format=scl_proc
      ELSE
        display_new_library module=current_module display_option=all output=procfile
        delete_module module=current_module
        IF $scan_string('program description', module)<> 0 THEN
          display_command_information from//current_module output=procfile status=ignore
        IFEND
      IFEND

"Format the output.
      IF $file(current_library, fs)= 'LIBRARY' THEN
        creation='     PROCEDURE CREATED: '//module(58, all)
      ELSE
        creation=' '
      IFEND
      lines_in_procedure=0
      first_page=page_number+1
      rewind_file file=procfile
      get_lines variable=procedure_content input=procfile line_count=lines_to_print
      WHILE lines_to_print > 0 DO
        page_number=page_number + 1
        put_lines (title_line1, title_line2, blank_line) o=out
        FOR line= 1 TO lines_to_print DO
          put_line line='  '//procedure_content(line) output=out
        FOREND
        lines_in_procedure=lines_in_procedure+line
        get_lines variable=procedure_content input=procfile line_count=lines_to_print
      WHILEND

"Make an entry in the index.
      IF $mod(number_of_procedures, page_length_used)= 1 THEN
        index_page=index_page+1
        put_lines (index_line1, index_line2, blank_line) o=$response
      IFEND
      number_of_pages=(page_number - first_page) + 1
      pages=', '//$justify($integer_string(lines_in_procedure), 5, right)//' lines '
      IF number_of_pages > 1 THEN
        pages=pages//'on '//number_of_pages//' pages '
      IFEND
      put_line line=index_entry output=$response
      total_lines=total_lines + lines_in_procedure
    FOREND
  QUIT

"Display final status.
  IF page_number = 0 THEN " set value of list_status to 'file missing', 'not object library', etc.
    display_object_library library=current_cycle module=current_module status=list_status
  ELSE
    put_line line=(' ', '  Listed '//page_number//' pages containing '//total_lines//' lines and '//..
number_of_procedures//' procedures to '//$string(output)) output=$response
    rewind_file out
    copy_file out index status=ignore
    copy_file index.$boi output status=ignore
  IFEND

  EXIT_PROC WITH list_status

PROCEND list_procedure_content
