?? RIGHT := 110 ??
?? NEWTITLE := 'INSTALL_SOFTWARE Utility: RAP$RECORD_STEP_STATUS Interface.' ??
MODULE ram$record_step_status;

{ PURPOSE:
{   This module contains the interface that records the step and step
{   status.
{
{ DESIGN:
{   The compiled module resides in RAF$LIBRARY.
{
{ NOTES:
{

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clc$standard_file_names
*copyc rat$installation_control_record
?? POP ??
*copyc amp$flush
*copyc clp$convert_integer_to_string
*copyc clp$get_system_file_id
*copyc clp$put_job_command_response
*copyc clp$trimmed_string_size
*copyc pmp$get_compact_date_time
*copyc rap$convert_job_record_to_strs
*copyc osv$upper_to_lower
?? OLDTITLE ??
?? NEWTITLE := 'Global Declarations Declared by This Module', EJECT ??

?? OLDTITLE ??
?? NEWTITLE := '[XDCL] rap$record_step_status', EJECT ??

{ PURPOSE:
{   This interface updates the step and step status in the job status
{   record along with the date/time the update took place.
{
{ DESIGN:
{   If the step status is RAC$STARTED, the subproduct started and completed
{   counts are initialized along with the step number.  The updated job
{   status record is then displayed to $RESPONSE.
{
{ NOTES:
{

  PROCEDURE [XDCL] rap$record_step_status
    (    step: rat$steps;
         step_status: rat$step_status;
     VAR icr {input, output} : rat$installation_control_record;
     VAR status: ost$status);


    VAR
      date_time: ost$date_time;


    status.normal := TRUE;

    pmp$get_compact_date_time (date_time, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    icr.job_status_record_p^.date_time := date_time;
    icr.job_status_record_p^.step := step;
    icr.job_status_record_p^.step_status := step_status;

    IF icr.job_status_record_p^.step_status = rac$step_started THEN

      icr.job_status_record_p^.step_number := icr.job_status_record_p^.step_number + 1;
      icr.job_status_record_p^.started_subproduct_count := 0;
      icr.job_status_record_p^.completed_subproduct_count := 0;

    IFEND;

    display_job_status_record (icr.job_status_record_p^, icr.job_status_record_p^.step_status, status);

  PROCEND rap$record_step_status;

?? OLDTITLE ??
?? NEWTITLE := 'display_job_status_record', EJECT ??

{ PURPOSE:
{   This procedure displays the job status record to $RESPONSE.
{
{ DESIGN:
{   The record is first converted to string values for displaying.
{
{   The job START status line is formatted as follows:
{
{     <a> (step <b>) ...
{
{   The job COMPLETE status line is formatted as follows:
{
{        step completed.
{
{   The job COMPLETE (with subproducts failed) status line is formatted as
{   follows:
{
{        step completed (<c> subproducts failed).
{
{
{   where:
{     <a> is the step.
{     <b> is the step number.
{     <c> is the started subproduct count minus the completed subproduct count.
{
{   As an example the following status line could be created:
{
{    "Reconciling cycle conflicts (step 1) ... "
{    "   step completed (3 subproducts failed)."
{
{ NOTES:
{   The $RESPONSE output buffer must be flushed to get the line to display
{   immediately.
{

  PROCEDURE display_job_status_record
    (    job_status_record: rat$job_status_record;
         step_status: rat$step_status;
     VAR status: ost$status);


    VAR
      failed_subproduct_count: rat$subproduct_count,
      failed_subproduct_count_str: ost$string,
      length: integer,
      line: string (osc$max_string_size),
      job_status_strs: rat$job_status_record_strs,
      response_fid: amt$file_identifier,
      translated_string: string (osc$max_string_size);


    status.normal := TRUE;

    rap$convert_job_record_to_strs (job_status_record, job_status_strs, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    IF step_status = rac$step_started THEN

      #TRANSLATE (osv$upper_to_lower, job_status_strs.step.value (2, job_status_strs.step.size),
            translated_string);

      STRINGREP (line, length, ' ', job_status_strs.step.value (1, 1),
            translated_string (1, clp$trimmed_string_size (translated_string)), ' (step ',
            job_status_strs.step_number.value (1, job_status_strs.step_number.size), ') ... ');

    ELSE {step status = rac$step_completed}

      failed_subproduct_count := job_status_record.started_subproduct_count -
            job_status_record.completed_subproduct_count;

      IF failed_subproduct_count = 0 THEN

        line (1, * ) := '       step completed.';
        length := clp$trimmed_string_size (line);

      ELSE {some or all subproducts failed}

        clp$convert_integer_to_string (failed_subproduct_count, 10, FALSE, failed_subproduct_count_str,
              status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

        STRINGREP (line, length, '       step completed (', failed_subproduct_count_str.
              value (1, failed_subproduct_count_str.size), ' subproducts failed).');

      IFEND;
    IFEND;

    clp$put_job_command_response (line (1, length), status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    clp$get_system_file_id (clc$job_command_response, response_fid, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    amp$flush (response_fid, osc$nowait, status);

  PROCEND display_job_status_record;
MODEND ram$record_step_status;
