PROC create_prolog_file, crepf (
  prolog_name, pn : name = $name($mainframe(identifier))
  file, f         : key lcu_mainframe_subcommands, lms, ..
                        lcu_network_subcommands, lns, pcu_subcommands, ps, ..
                        keyend = $required
  until, u        : string = '**'
  status          : var of status = $optional
  )

  create_variable osv$configuration_prolog_name k=(string $max_name) ..
        scope=xref
  create_variable ignore_status k=status
  create_variable line kind=(string 256)
  create_variable count kind=integer
  create_variable file kind=(string 31)

  IF osv$configuration_prolog_name <> '' THEN
    target_catalog_name = $string($name(osv$configuration_prolog_name))
  ELSE
    target_catalog_name = $mainframe(identifier)
  IFEND


  IF target_catalog_name <> $string($value(prolog_name)) THEN
  ignore_text: ..
    REPEAT
      accept_line variable=line input=$command_of_caller line_count=count
    UNTIL count = 0 OR line = $value(until)
    prolog_file_name = '$null'
  ELSE
    create_variable cmv$prolog_path k=string scope=xref

    catalog_name = cmv$prolog_path // '.' // target_catalog_name
    create_catalog $fname(catalog_name) status=ignore_status

    IF $string($value(file)) = 'PS' THEN
      file = 'PCU_SUBCOMMANDS'
    ELSEIF $string($value(file)) = 'LMS' THEN
      file = 'LCU_MAINFRAME_SUBCOMMANDS'
    ELSEIF $string($value(file)) = 'LNS' THEN
      file = 'LCU_NETWORK_SUBCOMMANDS'
    ELSE
      file = $string($value(file))
    IFEND

    prolog_file_name = catalog_name // '.' // file

    display_value ' Installing configuration prolog file: '//..
target_catalog_name//'.'//file o=$output status=ignore_status

    IF file = 'LCU_MAINFRAME_SUBCOMMANDS' THEN
COLLECT_TEXT $fname(prolog_file_name) sm='~' until='end of proc'
PROC ~file~ (status)
    create_variable subcommand_status k=status
    WHEN any_fault interrupt DO
      display_value ('   The following error was detected in command: '//osv$command_name,   osv$status,..
'   Continuing prolog execution.') o=$output
      IF subcommand_status.normal then
        subcommand_status = osv$status
      IFEND
      CONTINUE
    WHENEND

end of proc
    ELSE
      delete_file $fname(prolog_file_name) status=ignore_status
    IFEND
    accept_line variable=line input=$command_of_caller line_count=count

  collect_text: ..
    WHILE count <> 0 AND line <> $value(until) DO
      put_line line output=$fname(prolog_file_name//'.$eoi')
      accept_line variable=line input=$command_of_caller line_count=count
    WHILEND collect_text
    IF file = 'LCU_MAINFRAME_SUBCOMMANDS' THEN
COLLECT_TEXT $fname(prolog_file_name//'.$eoi') sm='~' until='end of proc'
    exit_proc with subcommand_status
PROCEND ~file~
end of proc
    IFEND
    detach_file $fname(prolog_file_name) status=ignore_status

    IF $file($fname(catalog_name//'.pcu_subcommands'), assigned) AND $file(..
          $fname(catalog_name//'.lcu_mainframe_subcommands'), assigned) AND ..
          $file($fname(catalog_name//'.lcu_network_subcommands'), assigned) ..
          THEN
      EXIT_PROC WITH $status(false, 'CM', 9999, 'Prolog Found')
    IFEND
  IFEND

PROCEND create_prolog_file
