
?? RIGHT := 110 ??
MODULE ofm$vedisplay_command;

{ PURPOSE:
{   This module contains the processor for the VEDISPLAY (VED) command which is temporary until the
{   real operator display commands come along.
{
?? PUSH (LISTEXT := ON) ??
*copyc amt$local_file_name
*copyc clt$parameter_list
*copyc ofc$page_width
*copyc ofd$type_definition
*copyc ofe$error_codes
*copyc oss$job_paged_literal
*copyc oss$task_shared
?? POP ??

?? NEWTITLE := 'Global Declarations Referenced by This Module' ??

{  Global procedures referenced by this module.

*copyc amp$get_file_attributes
*copyc amp$return
*copyc avp$system_displays
*copyc avp$system_operator
*copyc bap$file_command
*copyc clp$change_pdt
*copyc clp$evaluate_parameters
*copyc jmp$system_job
*copyc ofp$create_default_displays
*copyc ofp$execute_display_task
*copyc ofp$report_status_error
*copyc osp$append_status_parameter
*copyc osp$set_status_abnormal
*copyc osp$system_error
*copyc rmp$request_null_device
*copyc clp$include_line
*copyc ofv$displays_initialized

?? EJECT ??
*copyc clv$standard_files
?? TITLE := 'recreate_display_files', EJECT ??

{ PURPOSE:
{   This procedure recreates the display files DISPLAY_A and DISPLAY_B if they haved been destroyed.

  PROCEDURE recreate_display_files
    (VAR status: ost$status);

    CONST
      operator_file_page_length = 30;

    VAR
      contains_data: boolean,
      error_message: string (80),
      file: clt$standard_files,
      file_attributes: ARRAY [1 .. 5] OF amt$file_item,
      file_exists: boolean,
      file_name: string (16),
      file_previously_opened: boolean,
      gfa: ARRAY [1 .. 1] OF amt$get_item,
      message_length: integer;

    status.normal := TRUE;
    file_attributes [1].key := amc$file_contents;
    file_attributes [1].file_contents := amc$list;
    file_attributes [2].key := amc$page_format;
    file_attributes [2].page_format := amc$continuous_form;
    file_attributes [3].key := amc$user_info;
    file_attributes [3].user_info := 'LOG';
    file_attributes [4].key := amc$page_width;
    file_attributes [4].page_width := ofc$page_width - 1;
    file_attributes [5].key := amc$page_length;
    file_attributes [5].page_length := operator_file_page_length;

    gfa [1].key := amc$user_info;

    FOR file := clc$sf_display_a_file TO clc$sf_display_b_file DO
      IF file = clc$sf_display_a_file THEN
        file_name := '$local.display_a';
      ELSE
        file_name := '$local.display_b';
      IFEND;

      { Determine if the display file exists in the correct format.

      amp$get_file_attributes (file_name, gfa, file_exists, file_previously_opened, contains_data, status);
      IF NOT status.normal THEN
        STRINGREP (error_message, message_length, 'amp$get_file_attributes on file ', file_name);
        ofp$report_status_error (status, error_message (1, message_length));
        osp$system_error ('get failed', ^status);
        RETURN;
      IFEND;

      IF NOT file_exists OR (gfa [1].user_info <> 'LOG') THEN
        IF file_exists THEN
          amp$return (file_name, status);
          IF NOT status.normal THEN
            STRINGREP (error_message, message_length, 'amp$return on file ', file_name);
            ofp$report_status_error (status, error_message (1, message_length));
            osp$system_error ('return failed', ^status);
            RETURN;
          IFEND;
        IFEND;

        rmp$request_null_device (clv$standard_files [file].path_handle_name, status);
        IF NOT status.normal THEN
          STRINGREP (error_message, message_length, 'rmp$request_null_device on file ', file_name);
          ofp$report_status_error (status, error_message (1, message_length));
          osp$system_error ('request failed', ^status);
          RETURN;
        IFEND;

        bap$file_command (clv$standard_files [file].path_handle_name, ^file_attributes, status);
        IF NOT status.normal THEN
          STRINGREP (error_message, message_length, 'bap$file_command on file ', file_name);
          ofp$report_status_error (status, error_message (1, message_length));
          osp$system_error ('file command failed', ^status);
          RETURN;
        IFEND;
      IFEND;
    FOREND;

  PROCEND recreate_display_files;
?? TITLE := 'ofp$vedisplay_command', EJECT ??
*copyc ofh$ve_display_command

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


*copyc ofd$pdt_ved

    VAR
      display_file_p: ^fst$file_reference,
      pdt_changes: array [1 .. 2] of clt$pdt_change,
      pdt_keyword_availability: array [1 .. 2] of clt$type_change,
      pdt_p: ^SEQ ( * );

    VAR
      temp: ^SEQ ( * );

    VAR
      file_display_a: [STATIC, READ, oss$job_paged_literal] string (16) := '$local.display_a',
      file_display_b: [STATIC, READ, oss$job_paged_literal] string (16) := '$local.display_b',
      file_$output: [STATIC, READ, oss$job_paged_literal] string (7) := '$output';


    status.normal := TRUE;

    IF jmp$system_job () THEN
      pdt_p := #SEQ (pdt);
    ELSE

{     Make a copy of the PDT so that it can be modified to change the definition of the OUTPUT parameter.
{     Make $output the default and make the display_a and display_b keywords hidden.

      PUSH pdt_p: [[REP #SIZE (pdt) OF cell]];
      temp := #SEQ (pdt);
      pdt_p^ := temp^;
{!  Convert the preceding two lines to the following when CILB454 is answered.
{!    pdt_p^ := #SEQ (pdt)^;

      pdt_changes [1].number := 2;
      pdt_changes [1].kind := clc$pdtc_default_value;
      pdt_changes [1].default_value := ^file_$output;

      pdt_changes [2].number := 2;
      pdt_changes [2].kind := clc$pdtc_type;
      pdt_changes [2].type_changes := ^pdt_keyword_availability;
      pdt_keyword_availability [1].kind := clc$tc_keyword_availability;
      pdt_keyword_availability [1].keyword := 'DISPLAY_A';
      pdt_keyword_availability [1].availability := clc$hidden_entry;
      pdt_keyword_availability [2].kind := clc$tc_keyword_availability;
      pdt_keyword_availability [2].keyword := 'DISPLAY_B';
      pdt_keyword_availability [2].availability := clc$hidden_entry;

      clp$change_pdt (pdt_p, pdt_changes, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    IFEND;

    clp$evaluate_parameters (parameter_list, #SEQ (pdt), NIL, ^pvt, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    { Recreate the display files if necessary.

    IF jmp$system_job () THEN
      recreate_display_files (status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    IFEND;

    { Process the OUTPUT parameter.  If a keyword value is specified and this is the system job, then
    { convert to keyword to a file_reference for the appropriate $LOCAL file.  If a keyword value is
    { specified and this is NOT the system job, then return abnormal status.  If the OUTPUT parameter
    { is not specified, then send the display data to DISPLAY_A if this is the system job and to
    { $OUTPUT otherwise.

    IF pvt [p$output].specified THEN
      IF pvt [p$output].value^.kind = clc$file THEN
        display_file_p := pvt [p$output].value^.file_value;
      ELSE   {value is a keyword}
        IF jmp$system_job () THEN
          IF pvt [p$output].value^.keyword_value = 'DISPLAY_A' THEN
            display_file_p := ^file_display_a;
          ELSE
            display_file_p := ^file_display_b;
          IFEND;
        ELSE
          osp$set_status_abnormal (ofc$operator_facility_id, ofe$invalid_keyword_for_user,
              pvt [p$output].value^.keyword_value, status);
          osp$append_status_parameter (osc$status_parameter_delimiter, 'OUTPUT', status);
          RETURN;
        IFEND;
      IFEND;
    ELSE
      IF jmp$system_job () THEN
        display_file_p := ^file_display_a;
      ELSE
        display_file_p := ^file_$output;
      IFEND;
    IFEND;

    IF (avp$system_displays ()) OR (avp$system_operator ()) THEN
      ofp$create_default_displays (status);
    IFEND;
    IF status.normal THEN
      ofp$execute_display_task (display_file_p^,
               pvt [p$display_options].value^.name_value, status);
    IFEND;

    IF NOT status.normal THEN
      ofp$report_status_error (status, 'display execution');
    IFEND;

    IF NOT ofv$displays_initialized THEN
      clp$include_line ('VEDU ;QUIT', FALSE, osc$null_name, status);
    IFEND;

  PROCEND ofp$vedisplay_command;

MODEND ofm$vedisplay_command;
