?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL Interpreter : Associate log files with the log device ' ??
MODULE clm$request_log_device;

{
{ PURPOSE:
{   This module contains a procedure to associate the log 'files' with the 'log device'.
{   It is called during SCL's initialization activities for a job.
{

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc fst$path_handle_name
*copyc oss$task_shared
*copyc pmd$system_log_interface
?? POP ??
*copyc clp$convert_str_to_path_handle
*copyc fmp$request_null_device
*copyc fsp$close_file
*copyc fsp$open_file
*copyc lgv$critical_log_name
*copyc lgv$log_names

  VAR
    clv$critical_log_path_handle: [XDCL, oss$task_shared] fst$path_handle_name := '',
    clv$log_name_path_handles: [XDCL, oss$task_shared] array [pmt$logs] of
          fst$path_handle_name := ['', '', '', '', '', '', '', '', ''];

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

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

    VAR
      attachment_option: array [1 .. 1] of fst$attachment_option,
      mandated_create_attributes: array [1 .. 2] of fst$file_cycle_attribute,
      file_identifier: amt$file_identifier,
      evaluated_file_reference: fst$evaluated_file_reference,
      path_handle_name: fst$path_handle_name,
      log_ordinal: pmt$logs;

    status.normal := TRUE;
    FOR log_ordinal := LOWERBOUND (lgv$log_names) TO UPPERBOUND (lgv$log_names) DO
      clp$convert_str_to_path_handle (lgv$log_names [log_ordinal], FALSE, TRUE, FALSE, path_handle_name,
            evaluated_file_reference, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
      clv$log_name_path_handles [log_ordinal] := path_handle_name;
      fmp$request_null_device (rmc$log_device, evaluated_file_reference, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    FOREND;

{ Convert critical window log to a path handle.

    clp$convert_str_to_path_handle (lgv$critical_log_name, FALSE, TRUE, FALSE, path_handle_name,
            evaluated_file_reference, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;
    clv$critical_log_path_handle := path_handle_name;
    fmp$request_null_device (rmc$log_device, evaluated_file_reference, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    attachment_option [1].selector := fsc$access_and_share_modes;
    attachment_option [1].access_modes.selector := fsc$specific_access_modes;
    attachment_option [1].access_modes.value := $fst$file_access_options [fsc$read];
    attachment_option [1].share_modes.selector := fsc$specific_share_modes;
    attachment_option [1].share_modes.value := $fst$file_access_options [];
    mandated_create_attributes [1].selector := fsc$ring_attributes;
    mandated_create_attributes [1].ring_attributes.r1 := osc$tsrv_ring;
    mandated_create_attributes [1].ring_attributes.r2 := osc$sj_ring_3;
    mandated_create_attributes [1].ring_attributes.r3 := osc$sj_ring_3;
    mandated_create_attributes [2].selector := fsc$file_contents_and_processor;
    mandated_create_attributes [2].file_processor := fsc$unknown_processor;
    mandated_create_attributes [2].file_contents := fsc$unknown_contents;
    fsp$open_file (lgv$critical_log_name, amc$record, ^attachment_option, NIL,
            ^mandated_create_attributes, NIL, NIL, file_identifier, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;
    fsp$close_file (file_identifier, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;
    FOR log_ordinal := LOWERVALUE(pmt$global_logs) TO UPPERVALUE (pmt$global_logs) DO
      IF log_ordinal = pmc$system_log THEN
        mandated_create_attributes [2].file_contents := fsc$unknown_contents;
      ELSE
        mandated_create_attributes [2].file_contents := fsc$binary_log;
      IFEND;
      fsp$open_file (lgv$log_names [log_ordinal], amc$record, ^attachment_option, NIL,
            ^mandated_create_attributes, NIL, NIL, file_identifier, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
      fsp$close_file (file_identifier, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    FOREND;
    mandated_create_attributes [1].ring_attributes.r1 := osc$user_ring_2;
    mandated_create_attributes [1].ring_attributes.r2 := osc$user_ring_2;
    mandated_create_attributes [1].ring_attributes.r3 := osc$user_ring_2;
    mandated_create_attributes [2].selector := fsc$file_contents_and_processor;
    mandated_create_attributes [2].file_contents := fsc$binary_log;
    mandated_create_attributes [2].file_processor := fsc$unknown_processor;
    FOR log_ordinal := pmc$job_account_log TO pmc$job_statistic_log DO
      fsp$open_file (lgv$log_names [log_ordinal], amc$record, ^attachment_option, NIL,
            ^mandated_create_attributes, NIL, NIL, file_identifier, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
      fsp$close_file (file_identifier, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    FOREND;

  PROCEND clp$request_log_device;

MODEND clm$request_log_device;
