?? RIGHT := 110 ??
?? NEWTITLE := 'System_Prolog_Command_Module' ??
MODULE clm$system_prolog_command;

{
{ Purpose:
{    This module contains the system prolog contents to be
{    executed as a command.
{

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clc$compiling_for_test_harness
*copyc cle$ecc_miscellaneous
*copyc clt$parameter_list
*copyc fst$path
*copyc oss$job_paged_literal
*copyc ost$caller_identifier
?? POP ??
*copyc clp$add_file_to_command_list
*copyc clp$convert_cyc_ref_to_cyc_sel
*copyc clp$convert_str_to_path_handle
*copyc clp$create_environment_variable
*copyc clp$establish_sys_command_lib
*copyc clp$trimmed_string_size
*copyc fsp$convert_fs_structure_to_pf
*copyc jmp$system_job
*copyc osp$generate_log_message
*copyc osp$set_status_abnormal
*copyc pfp$attach
*copyc pmp$change_debug_library_list
*copyc pmp$change_job_library_list


  TYPE
    prolog_files = (cyf$run_time_library, flf$library, cbf$4dd_library, dbf$library, mlf$library, smf$library,
          lsf$library,
          aaf$4dd_library, aaf$44d_library, bcf$library, paf$library, osf$system_library, tuf$library,
          tuf$terminal_definitions, ftf$library, adf$library, c2f$library, c2f$libc, c2f$libm,
          c2f$run_time_library, c2f$libmalloc, vcf$library, vcf$libc, vcf$libm, fdf$library,
          xwf$xterm_library),

    debug_list_prolog_files = (debug_bound_product, unused_debug_library);

  VAR
    local_catalog: [STATIC, READ, oss$job_paged_literal] string (7) := ':$LOCAL',
    system_command_library: [STATIC, READ, oss$job_paged_literal] string (36)  :=
          ':$SYSTEM.$SYSTEM.OSF$COMMAND_LIBRARY',
    local_library_list: [STATIC, READ, oss$job_paged_literal] array [prolog_files] of
          ost$name := ['CYF$RUN_TIME_LIBRARY', 'FLF$LIBRARY         ', 'CBF$4DD_LIBRARY     ',
          'DBF$LIBRARY         ', 'MLF$LIBRARY         ', 'SMF$LIBRARY         ', 'LSF$LIBRARY         ',
          'AAF$4DD_LIBRARY     ',
          'AAF$44D_LIBRARY     ', 'BCF$LIBRARY         ', 'PAF$LIBRARY         ', 'OSF$SYSTEM_LIBRARY  ',
          'TUF$LIBRARY         ', 'TUF$TERMINAL_DEFINITIONS', 'FTF$LIBRARY     ', 'ADF$LIBRARY         ',
          'C2F$LIBRARY         ', 'C2F$LIBC            ', 'C2F$LIBM            ', 'C2F$RUN_TIME_LIBRARY',
          'C2F$LIBMALLOC       ', 'VCF$LIBRARY         ', 'VCF$LIBC            ', 'VCF$LIBM            ',
          'FDF$LIBRARY         ', 'XWF$XTERM_LIBRARY   '],
    library_list: [STATIC, READ, oss$job_paged_literal] array [prolog_files] of string (46) :=
          [':$SYSTEM.$SYSTEM.CYBIL.CYF$RUN_TIME_LIBRARY   ', ':$SYSTEM.$SYSTEM.FORTRAN.FLF$LIBRARY          ',
          ':$SYSTEM.$SYSTEM.COBOL.CBF$4DD_LIBRARY        ', ':$SYSTEM.$SYSTEM.DEBUG.DBF$LIBRARY            ',
          ':$SYSTEM.$SYSTEM.COMMON.MLF$LIBRARY           ', ':$SYSTEM.$SYSTEM.SORT.SMF$LIBRARY             ',
          ':$SYSTEM.$SYSTEM.LANGUAGE_SERVICES.LSF$LIBRARY',
          ':$SYSTEM.$SYSTEM.AAM.AAF$4DD_LIBRARY          ', ':$SYSTEM.$SYSTEM.AAM.AAF$44D_LIBRARY          ',
          ':$SYSTEM.$SYSTEM.BASIC.BCF$LIBRARY            ', ':$SYSTEM.$SYSTEM.PASCAL.PAF$LIBRARY           ',
          ':$SYSTEM.$SYSTEM.OSF$SYSTEM_LIBRARY           ', ':$SYSTEM.$SYSTEM.TDU.BOUND_PRODUCT            ',
          ':$SYSTEM.$SYSTEM.TDU.TERMINAL_DEFINITIONS     ', ':$SYSTEM.$SYSTEM.FORTRAN_VERSION_2.FTF$LIBRARY',
          ':$SYSTEM.$SYSTEM.ADA.ADF$LIBRARY              ', ':$SYSTEM.$SYSTEM.C.VCF$LIBRARY                ',
          ':$SYSTEM.$SYSTEM.CV2.C2F$LIBC                 ', ':$SYSTEM.$SYSTEM.CV2.C2F$LIBM                 ',
          ':$SYSTEM.$SYSTEM.CV2.C2F$RUN_TIME_LIBRARY     ', ':$SYSTEM.$SYSTEM.CV2.C2F$LIBMALLOC            ',
          ':$SYSTEM.$SYSTEM.C.VCF$LIBRARY                ', ':$SYSTEM.$SYSTEM.C.LIBC                       ',
          ':$SYSTEM.$SYSTEM.C.LIBM                       ', ':$SYSTEM.$SYSTEM.FDF$LIBRARY                  ',
          ':$SYSTEM.$SYSTEM.X11R4.BIN.XTERM              '],
    debug_library_list: [STATIC, READ, oss$job_paged_literal] array [debug_list_prolog_files] of
          string (36) := [':$SYSTEM.$SYSTEM.DEBUG.BOUND_PRODUCT', ''];

?? TITLE := 'clp$system_prolog_command', EJECT ??

  PROCEDURE [XDCL, #GATE] clp$system_prolog_command
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{The functions performed by this command are now invoked automatically
{by clp$system_prolog_phase_1 and clp$system_prolog_phase_2, which are
{called by clp$job_boot and clp$interpret_commands.

    VAR
      executing_within_system_job: boolean;


    status.normal := TRUE;
    executing_within_system_job := jmp$system_job ();

    IF executing_within_system_job THEN
      clp$system_prolog_phase_1 (status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
      clp$system_prolog_phase_2 (status);
    IFEND;

  PROCEND clp$system_prolog_command;
?? TITLE := 'clp$system_prolog_phase_1', EJECT ??

  PROCEDURE [XDCL, #GATE] clp$system_prolog_phase_1
    (VAR status: ost$status);

{ TYPE
{   file = file

    VAR
      type_specification: [STATIC, READ, cls$declaration_section] record
        header: clt$type_specification_header,
      recend := [[1, 0, clc$file_type]];

{ TYPEND

    VAR
      file_var_init_value_p: ^clt$data_value,
      ignore_status: ost$status,
      index: prolog_files;


    ?IF NOT clc$compiling_for_test_harness THEN

      PUSH file_var_init_value_p;
      file_var_init_value_p^.kind := clc$file;

    /process_system_file_list/
      FOR index := LOWERVALUE (prolog_files) TO UPPERVALUE (prolog_files) DO
        file_var_init_value_p^.file_value := ^library_list [index];
        clp$create_environment_variable (local_library_list [index], clc$job_scope, clc$read_write,
              clc$immediate_evaluation, #SEQ (type_specification), file_var_init_value_p, status);
        IF NOT status.normal THEN
          osp$generate_log_message ($pmt$ascii_logset [pmc$job_log], status, ignore_status);
          CYCLE /process_system_file_list/;
        IFEND;
      FOREND /process_system_file_list/;
    ?IFEND;

  PROCEND clp$system_prolog_phase_1;
?? TITLE := 'clp$system_prolog_phase_2', EJECT ??

  PROCEDURE [XDCL, #GATE] clp$system_prolog_phase_2
    (VAR status: ost$status);

    VAR
      add_libraries: ^pmt$object_library_list,
      caller_id: ost$caller_identifier,
      command_list_file: clt$command_list_entry_file,
      delete_libraries: ^pmt$object_library_list,
      executing_within_system_job: boolean,
      ignore_status: ost$status,
      usage_selections: pft$usage_selections,
      share_selections: pft$share_selections,
      evaluated_file_reference: fst$evaluated_file_reference,
      cycle_selector: clt$cycle_selector,
      path_handle_name: fst$path_handle_name,
      pf_path: ^pft$path,
      local_library: fst$path;


    executing_within_system_job := jmp$system_job ();

    ?IF NOT clc$compiling_for_test_harness THEN
      #CALLER_ID (caller_id);

      PUSH add_libraries: [1 .. 1];
      clp$convert_str_to_path_handle (library_list [aaf$4dd_library], FALSE, TRUE, TRUE, path_handle_name,
            evaluated_file_reference, status);
      IF NOT status.normal THEN
        osp$generate_log_message ($pmt$ascii_logset [pmc$job_log], status, ignore_status);
      IFEND;
      add_libraries^ [1] := path_handle_name;
      delete_libraries := NIL;
      pmp$change_job_library_list (delete_libraries, add_libraries, status);
      IF NOT status.normal THEN
        osp$generate_log_message ($pmt$ascii_logset [pmc$job_log], status, ignore_status);
      IFEND;

      IF NOT executing_within_system_job THEN
        clp$convert_str_to_path_handle (debug_library_list [debug_bound_product], FALSE, FALSE, TRUE,
              path_handle_name, evaluated_file_reference, status);
        IF NOT status.normal THEN
          osp$generate_log_message ($pmt$ascii_logset [pmc$job_log], status, ignore_status);
        IFEND;
        add_libraries^ [1] := path_handle_name;
        delete_libraries := NIL;
        pmp$change_debug_library_list (delete_libraries, add_libraries, status);
        IF NOT status.normal THEN
          osp$generate_log_message ($pmt$ascii_logset [pmc$job_log], status, ignore_status);
        IFEND;

        command_list_file.kind := clc$command_list_entry_$system;
        command_list_file.path := ^system_command_library;
        clp$establish_sys_command_lib (command_list_file.path, status);
        IF NOT status.normal THEN
          osp$generate_log_message ($pmt$ascii_logset [pmc$job_log], status, ignore_status);
        IFEND;
      IFEND;
    ?IFEND;

    IF NOT executing_within_system_job THEN
      command_list_file.kind := clc$command_list_entry_path;
      command_list_file.path := ^local_catalog;
      clp$add_file_to_command_list (command_list_file, FALSE, status);
      IF NOT status.normal THEN
        osp$generate_log_message ($pmt$ascii_logset [pmc$job_log], status, ignore_status);
      IFEND;
    IFEND;

  PROCEND clp$system_prolog_phase_2;

MODEND clm$system_prolog_command;
