?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL Interpreter : Log Message from Display_Message Command' ??
MODULE clm$log_comment;

{
{ PURPOSE:
{   This module contains the procedure that performs the bulk of the processing
{   for the display_message command.
{
?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc cll$comment_command
*copyc jmc$job_management_id
*copyc jml$user_id
*copyc jmt$system_supplied_name
*copyc jmt$user_supplied_name
*copyc ost$name
*copyc ost$status
*copyc jme$job_history_conditions
*copyc pme$logging_exceptions
?? POP ??
*copyc avp$accounting_administrator
*copyc avp$configuration_administrator
*copyc avp$get_capability
*copyc avp$system_operator
*copyc ofp$display_status_message
*copyc osp$set_status_abnormal
*copyc pmp$get_job_names
*copyc pmp$log_ascii
*copyc sfp$activate_job_statistic
*copyc sfp$deactivate_job_statistic
*copyc sfp$emit_statistic
*copyc jmv$job_history_active

?? TITLE := 'clp$log_comment', EJECT ??
*copy clh$log_comment

  PROCEDURE [XDCL, #GATE] clp$log_comment
    (    message: string ( * );
         log_name_selections: array [ * ] of ost$name;
     VAR status: ost$status);

    VAR
      data_size: 1 .. osc$max_string_size,

{ The length of history_message_size is the length of the descriptive data minus the job name.

      history_message_size: 0 .. osc$max_string_size - jmc$system_supplied_name_size,
      log_array_index: integer,
      message_size: 0 .. ofc$max_display_message,
      engineering_oper_capability: boolean,
      statistic_data: string (osc$max_string_size),
      system_job_name: jmt$system_supplied_name,
      user_job_name: jmt$user_supplied_name;

    status.normal := TRUE;
    FOR log_array_index := LOWERBOUND (log_name_selections) TO UPPERBOUND (log_name_selections) DO

      IF log_name_selections [log_array_index] = 'SYSTEM' THEN
        IF avp$system_operator () THEN
          pmp$log_ascii (message, $pmt$ascii_logset [pmc$system_log], pmc$msg_origin_program, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        ELSE
          osp$set_status_abnormal ('PM', pme$cannot_write_in_system_log, '', status);
          RETURN;
        IFEND;

      ELSEIF log_name_selections [log_array_index] = 'STATISTIC' THEN
        IF (avp$system_operator () OR avp$configuration_administrator ()) THEN
          sfp$activate_job_statistic (cll$comment_command, $sft$binary_logset [pmc$statistic_log], status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          sfp$emit_statistic (cll$comment_command, message, NIL, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          sfp$deactivate_job_statistic (cll$comment_command, $sft$binary_logset [pmc$statistic_log], status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        ELSE
          osp$set_status_abnormal ('PM', pme$cannot_write_to_log, 'STATISTIC_LOG', status);
          RETURN;
        IFEND;

      ELSEIF log_name_selections [log_array_index] = 'ENGINEERING' THEN
        IF NOT avp$system_operator () THEN
          avp$get_capability (avc$engineering_operation, avc$user, engineering_oper_capability,
              status);
          IF NOT status.normal THEN
            RETURN;
          ELSEIF NOT engineering_oper_capability THEN
            osp$set_status_abnormal ('PM', pme$cannot_write_to_log, 'ENGINEERING_LOG', status);
            RETURN;
          IFEND;
        IFEND;
        sfp$activate_job_statistic (cll$comment_command, $sft$binary_logset [pmc$engineering_log], status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        sfp$emit_statistic (cll$comment_command, message, NIL, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        sfp$deactivate_job_statistic (cll$comment_command, $sft$binary_logset [pmc$engineering_log],
            status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

      ELSEIF log_name_selections [log_array_index] = 'ACCOUNT' THEN
        IF (avp$system_operator () OR avp$accounting_administrator ()) THEN
          sfp$activate_job_statistic (cll$comment_command, $sft$binary_logset [pmc$account_log], status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          sfp$emit_statistic (cll$comment_command, message, NIL, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          sfp$deactivate_job_statistic (cll$comment_command, $sft$binary_logset [pmc$account_log], status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        ELSE
          osp$set_status_abnormal ('PM', pme$cannot_write_to_log, 'ACCOUNT_LOG', status);
          RETURN;
        IFEND;

      ELSEIF log_name_selections [log_array_index] = 'JOB' THEN
        pmp$log_ascii (message, $pmt$ascii_logset [pmc$job_log], pmc$msg_origin_program, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

      ELSEIF log_name_selections [log_array_index] = 'JOB_ACCOUNT' THEN
        IF (avp$system_operator () OR avp$accounting_administrator ()) THEN
          sfp$activate_job_statistic (cll$comment_command, $sft$binary_logset [pmc$job_account_log], status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          sfp$emit_statistic (cll$comment_command, message, NIL, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          sfp$deactivate_job_statistic (cll$comment_command, $sft$binary_logset [pmc$job_account_log],
                status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        IFEND;

      ELSEIF log_name_selections [log_array_index] = 'JOB_STATISTIC' THEN
        sfp$activate_job_statistic (cll$comment_command, $sft$binary_logset [pmc$job_statistic_log], status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        sfp$emit_statistic (cll$comment_command, message, NIL, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        sfp$deactivate_job_statistic (cll$comment_command, $sft$binary_logset [pmc$job_statistic_log],
              status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

      ELSEIF log_name_selections [log_array_index] = 'JOB_MESSAGE' THEN
        IF STRLENGTH (message) <= ofc$max_display_message THEN
          message_size := STRLENGTH (message);
        ELSE
          message_size := ofc$max_display_message;
        IFEND;
        ofp$display_status_message (message (1, message_size), status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

      ELSEIF log_name_selections [log_array_index] = 'HISTORY' THEN
        IF jmv$job_history_active THEN
          pmp$get_job_names (user_job_name, system_job_name, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          data_size := 1;
          statistic_data (data_size, jmc$system_supplied_name_size) :=
                system_job_name (1, jmc$system_supplied_name_size);
          data_size := data_size + jmc$system_supplied_name_size;
          IF STRLENGTH (message) <= osc$max_string_size - jmc$system_supplied_name_size THEN
            history_message_size := STRLENGTH (message);
          ELSE
            history_message_size := osc$max_string_size - jmc$system_supplied_name_size;
          IFEND;
          statistic_data (data_size, history_message_size) := message (1, history_message_size);
          data_size := data_size + history_message_size - 1;
          sfp$emit_statistic (jml$job_history_message, statistic_data (1, data_size), NIL, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        ELSE
          osp$set_status_abnormal (jmc$job_management_id, jme$jh_job_history_not_active, '', status);
          RETURN;
        IFEND;

      ELSE
        ;
      IFEND;
    FOREND;

  PROCEND clp$log_comment;

MODEND clm$log_comment;
