?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL Interpreter : Storage Module for IDentifiers of Special Files' ??
MODULE clm$system_file_identifiers;

{
{ PURPOSE:
{   This module provides for storage and retrieval of file_identifiers for "special files".
{   A "special file" is one that, for certain operations, is (implicitly) opened the first time it is used
{   in a task, has that instance of opened used for subsequent accesses in taht task, and is closed as part
{   of task termination.
{

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc amt$local_file_name
*copyc clc$compiling_for_test_harness
*copyc clc$standard_file_names
*IF NOT $true(osv$unix)
*copyc cle$user_already_logged_in
*ELSE
*copyc amc_standard_files
*copyc amv$nil_file_identifier
*IFEND
*copyc clt$standard_file
*copyc clt$standard_files
*copyc clt$system_file_identifiers
*IF NOT $true(osv$unix)
*copyc fst$path_handle_name
*copyc jmv$job_attributes
*copyc osc$timesharing_terminal_file
*copyc oss$job_paged_literal
*copyc oss$task_private
*copyc oss$task_shared
*IFEND
?? POP ??
*IF NOT $true(osv$unix)
*copyc clp$convert_str_to_path_handle
*copyc osp$set_status_condition
*copyc pmp$find_prog_options_and_libs
*IFEND
?? TITLE := 'IDentifiers for Special Files', EJECT ??

  VAR
*IF NOT $true(osv$unix)
    standard_file_names: [STATIC, READ, oss$job_paged_literal] array [clt$standard_files] of
          amt$local_file_name := [clc$job_log, clc$null_file, clc$job_input, clc$standard_input,
          clc$job_output, clc$standard_output, clc$error_output, clc$listing_output, clc$echoed_commands,
          clc$job_command_response, clc$job_command_input, osc$timesharing_terminal_file, osc$display_a,
          osc$display_b, osc$null_name];
*ELSE
    standard_file_names: [STATIC, READ] array [clt$standard_files] of
          amt$local_file_name := [clc$null_file, clc$job_input, clc$standard_input,
          clc$job_output, clc$standard_output, clc$error_output,
          clc$job_command_input, osc$null_name];
*IFEND

  VAR
*IF NOT $true(osv$unix)
    clv$system_file_identifiers: [XDCL, oss$task_private] clt$system_file_identifiers :=
          [[FALSE], [FALSE], [FALSE], [FALSE]];
*ELSE
    clv$system_file_identifiers: [XDCL] clt$system_file_identifiers :=
          [[FALSE], [FALSE]];
*IFEND

  VAR
*IF NOT $true(osv$unix)
    clv$standard_files: [XDCL, #GATE, oss$task_shared] array
          [clt$standard_files] of clt$standard_file := [[osc$null_name, [0, 0, [FALSE]]],
          [osc$null_name, [0, 0, [FALSE]]], [osc$null_name, [0, 0, [FALSE]]],
          [osc$null_name, [0, 0, [FALSE]]], [osc$null_name, [0, 0, [FALSE]]],
          [osc$null_name, [0, 0, [FALSE]]], [osc$null_name, [0, 0, [FALSE]]],
          [osc$null_name, [0, 0, [FALSE]]], [osc$null_name, [0, 0, [FALSE]]],
          [osc$null_name, [0, 0, [FALSE]]], [osc$null_name, [0, 0, [FALSE]]],
          [osc$null_name, [0, 0, [FALSE]]], [osc$null_name, [0, 0, [FALSE]]],
          [osc$null_name, [0, 0, [FALSE]]], [osc$null_name, [0, 0, [FALSE]]]];
*ELSE
    clv$standard_files: [XDCL, #GATE] array
          [clt$standard_files] of clt$standard_file := [[amc_null, -1],
          [amc_stdin, amc_stdin_fid], [amc_stdin, amc_stdin_fid],
          [amc_stdout, amc_stdout_fid], [amc_stdout, amc_stdout_fid],
          [amc_stderr, amc_stderr_fid], [amc_stdin, amc_stdin_fid],
          [' ', -1]];
*IFEND

*IF NOT $true(osv$unix)
  VAR
    clv$local_catalog_handle_name: [XDCL, #GATE, oss$task_shared] fst$path_handle_name := osc$null_name;

  VAR
    clv$already_logged_in: [STATIC, oss$task_shared] boolean := FALSE;

  CONST
    osc$display_a = 'DISPLAY_A                      ',
    osc$display_b = 'DISPLAY_B                      ';

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

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


    status.normal := TRUE;
    IF clv$already_logged_in OR (NOT jmv$job_attributes.login_command_supplied) THEN
      osp$set_status_condition (cle$user_already_logged_in, status);
    ELSE
      clv$already_logged_in := TRUE;
    IFEND;

  PROCEND clp$login_command_ring_3;
?? TITLE := 'clp$store_path_handle_names', EJECT ??

  PROCEDURE [XDCL, #GATE] clp$store_std_path_handle_names
    (    operator_job: boolean;
         first_time: boolean;
     VAR status: ost$status);

    VAR
      evaluated_file_reference: fst$evaluated_file_reference,
      file: clt$standard_files,
      path_handle_name: fst$path_handle_name,
      prog_options_and_libraries: ^pmt$prog_options_and_libraries;


    status.normal := TRUE;
    pmp$find_prog_options_and_libs (prog_options_and_libraries);

    IF first_time THEN

    /initialize_files/
      FOR file := clc$sf_job_log_file TO clc$sf_display_b_file DO
        IF ((file = clc$sf_display_a_file) OR (file = clc$sf_display_b_file)) AND NOT operator_job THEN
          CYCLE /initialize_files/;
        IFEND;
        IF file = clc$sf_command_file THEN
          CYCLE /initialize_files/;
        IFEND;
        clp$convert_str_to_path_handle (standard_file_names [file], FALSE, TRUE, FALSE, path_handle_name,
              evaluated_file_reference, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

        clv$standard_files [file].path_handle_name := path_handle_name;
        clv$standard_files [file].path_handle := evaluated_file_reference.path_handle_info.path_handle;
      FOREND /initialize_files/;

      ?IF clc$compiling_for_test_harness THEN

        clp$convert_str_to_path_handle (':$LOCAL', FALSE, TRUE, FALSE, path_handle_name,
              evaluated_file_reference, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

        clv$local_catalog_handle_name := path_handle_name;

      ?IFEND

      prog_options_and_libraries^.default_options^.debug_input :=
            clv$standard_files [clc$sf_command_file].path_handle_name;
      prog_options_and_libraries^.default_options^.debug_output :=
            clv$standard_files [clc$sf_standard_output_file].path_handle_name;
      prog_options_and_libraries^.default_options^.abort_file :=
            clv$standard_files [clc$sf_null_file].path_handle_name;

    ELSE {NOT first_time}
      file := clc$sf_command_file;
      clp$convert_str_to_path_handle (standard_file_names [file], FALSE, TRUE, FALSE, path_handle_name,
            evaluated_file_reference, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

      clv$standard_files [file].path_handle_name := path_handle_name;
      clv$standard_files [file].path_handle := evaluated_file_reference.path_handle_info.path_handle;

      prog_options_and_libraries^.default_options^.debug_input :=
            clv$standard_files [clc$sf_command_file].path_handle_name;
    IFEND;

  PROCEND clp$store_std_path_handle_names;
*IFEND
?? TITLE := 'clp$fetch_system_file_id', EJECT ??

  PROCEDURE [XDCL, #GATE] clp$fetch_system_file_id
    (    file_name: amt$local_file_name;
     VAR file_id: amt$file_identifier;
     VAR file_id_defined: boolean);


*IF NOT $true(osv$unix)
    IF file_name = clc$echoed_commands THEN
      file_id_defined := clv$system_file_identifiers.echoed_commands.id_defined;
      IF file_id_defined THEN
        file_id := clv$system_file_identifiers.echoed_commands.id;
      IFEND;
    ELSEIF file_name = clc$job_command_response THEN
      file_id_defined := clv$system_file_identifiers.job_command_response.id_defined;
      IF file_id_defined THEN
        file_id := clv$system_file_identifiers.job_command_response.id;
      IFEND;
    ELSEIF file_name = clc$error_output THEN
*ELSE
    IF file_name = clc$error_output THEN
*IFEND
      file_id_defined := clv$system_file_identifiers.error_output.id_defined;
      IF file_id_defined THEN
        file_id := clv$system_file_identifiers.error_output.id;
      IFEND;
    ELSEIF file_name = clc$job_output THEN
      file_id_defined := clv$system_file_identifiers.job_output.id_defined;
      IF file_id_defined THEN
        file_id := clv$system_file_identifiers.job_output.id;
      IFEND;
    ELSE
      file_id_defined := FALSE;
    IFEND;

  PROCEND clp$fetch_system_file_id;
?? TITLE := 'clp$store_system_file_id', EJECT ??

  PROCEDURE [XDCL, #GATE] clp$store_system_file_id
    (    file_name: amt$local_file_name;
         file_id: amt$file_identifier);


*IF NOT $true(osv$unix)
    IF file_name = clc$echoed_commands THEN
      clv$system_file_identifiers.echoed_commands.id_defined := TRUE;
      clv$system_file_identifiers.echoed_commands.id := file_id;
    ELSEIF file_name = clc$job_command_response THEN
      clv$system_file_identifiers.job_command_response.id_defined := TRUE;
      clv$system_file_identifiers.job_command_response.id := file_id;
    ELSEIF file_name = clc$error_output THEN
*ELSE
    IF file_name = clc$error_output THEN
*IFEND
      clv$system_file_identifiers.error_output.id_defined := TRUE;
      clv$system_file_identifiers.error_output.id := file_id;
    ELSEIF file_name = clc$job_output THEN
      clv$system_file_identifiers.job_output.id_defined := TRUE;
      clv$system_file_identifiers.job_output.id := file_id;
*IF $true(osv$unix)
    ELSEIF file_name = clc$null_file THEN
      clv$standard_files [clc$sf_null_file].file_id := file_id;
*IFEND
    IFEND;

  PROCEND clp$store_system_file_id;

MODEND clm$system_file_identifiers;
