PROCEDURE (ram$disp) display_procedure, display_procedures, disp (
  procedure, procedures, p: list of any of
      integer radix 16
      name
      string
    anyend = all
  from, f: file = $working_catalog.command_library
  output, o: file = $output
  display_option, do: key
      (date_time, dt, d)
      (name, names, n)
      (content, c)
      (scu_deck, sd, s)
    keyend = date_time
  prefix_string, ps: string = ''
  suffix_string, ss: string = ''
  status)

" PURPOSE:
"   Display the specified modules from a libaray or object file.
" DESIGN:
"   Scan every module name on the library for the specified value. Write the selected modules to the
"   output file in a format selected by the display_options parameter.
" NOTES:
"   An integer procedure value is hexadecimal, convenient when processing CDCNET configuration procedures.
"   The SCU_DECK display_option produces source for the SOURCE_CODE_UTILITY create_deck command. The NAMES
"   and SCU_DECK display options allow you to prefix or suffix each procedure name with strings of your
"   choice. Creation dates are suppressed for object files.

  VAR
    display_status : status
    format : name = scl_proc
    library_list : file = $unique(:$local)
    modules_on_file : list 0..$max_list of string = ()
    modules_to_display : list 0..$max_list of string = ()
    specified_name : string 1..31
    temp_output : file = $unique(:$local)
  VAREND

  IF ($file(from, fs)= 'LIBRARY') AND ($file(from, fc)= 'OBJECT') THEN
    format=library
  IFEND

  set_file_attributes file=library_list page_format=continuous file_contents=legible
  IF (display_option = date_time) AND (format = library) THEN
    display_object_library display_option=date_time library=from output=library_list alphabetical_order=true
  ELSE
    display_object_library display_option=none library=from output=library_list alphabetical_order=true
  IFEND

  get_line variable=modules_on_file input=library_list
  delete_file file=library_list

  FOR EACH procedure_specified IN procedures DO " select a list of modules to display
    IF $generic_type(procedure_specified)= integer THEN " a CDCNET configuration procedure reference
      specified_name=$integer_string(procedure_specified, 16)
    ELSE " a substring of the procedure name was specified
      specified_name=$string(procedure_specified)
    IFEND
    IF specified_name = 'ALL' THEN " display all modules
      modules_to_display=$union(modules_to_display, $select(modules_on_file, $size(x)>0))
    ELSE " display specified modules
      modules_to_display=$union(modules_to_display, ..
            $select(modules_on_file, $scan_string(specified_name, ' '//$substring(x, 1, 32))>0))
    IFEND
  FOREND

  IF $nil(modules_to_display) THEN " assign appropriate display_library status
    display_object_library modules=$apply(procedures, $range_of($program_name(x))) library=from ..
          status=display_status
  ELSE
    put_line line=' Displaying procedures from     '//from output=$response
    IF display_option = date_time THEN
      put_line $apply(modules_to_display, ' '//x) output=temp_output.$eoi
    ELSEIF display_option = names THEN
      put_line $apply(modules_to_display, ' '//prefix_string//x//suffix_string) output=temp_output.$eoi
    ELSE
      FOR EACH selected_module IN modules_to_display DO
        IF display_option = scu_deck THEN
          deck_name=prefix_string // selected_module // suffix_string
          IF $size(deck_name)> 31 THEN
            deck_name=deck_name(1, 31)
            put_line ' ***** WARNING ***** - DECK NAME TRUNCATED TO '//deck_name output=$response
          IFEND
          put_line '*DECK DECK='//deck_name output=temp_output.$eoi
        IFEND
        CREATE_OBJECT_LIBRARY
          add_module module=selected_module library=from
          generate_library library=temp_output.$eoi format=scl_proc status=display_status
        QUIT
      FOREND
    IFEND
    copy_file temp_output output.$eoi
    delete_file temp_output
    put_line line=' Displayed '//$justify($integer_string($size(modules_to_display)), 4, right)//..
' procedures from '//from output=$response
  IFEND

  EXIT_PROC WITH display_status

PROCEND display_procedure
