?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL Interpreter : Get Job Parameters for Pre-validation' ??
MODULE clm$get_job_parameters;

{
{ PURPOSE:
{   This module contains the procedure that is responsible for obtaining the parameters from the login
{   command in a file that has been submitted for processing as a batch job.
{

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc amv$nil_file_identifier
*copyc cle$ecc_command_processing
*copyc clt$file_contents
*copyc clt$parameter_list_text
*copyc clt$parameter_list_text_size
*copyc jmt$job_system_label
*copyc osd$virtual_address
*copyc ost$caller_identifier
*copyc ost$status
?? POP ??
*copyc clp$access_command_file
*copyc clp$close_command_file
*copyc clp$get_command_line
*copyc clp$get_login_parameters
*copyc clp$parse_command
*copyc clp$pop_input_stack
*copyc clp$pop_parameters
*copyc clp$push_input_file_block
*copyc clp$push_sub_parameters_block
*copyc clp$scan_any_lexical_unit
*copyc clp$scan_non_space_lexical_unit
*copyc clp$scan_unnested_cmnd_lex_unit
*copyc osp$disestablish_cond_handler
*copyc osp$establish_block_exit_hndlr
*copyc osp$set_status_abnormal

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

  PROCEDURE [XDCL] clp$get_job_parameters
    (    submitter_ring: ost$valid_ring;
         submitted_file_reference: fst$file_reference;
     VAR job_system_label: {input, output} jmt$job_system_label;
     VAR login_command_in_file: boolean;
     VAR status: ost$status);

?? NEWTITLE := 'abort_handler', EJECT ??

    PROCEDURE abort_handler
      (    condition: pmt$condition;
           ignore_condition_information: ^pmt$condition_information;
           ignore_save_area: ^ost$stack_frame_save_area;
       VAR handler_status: ost$status);

      VAR
        ignore_status: ost$status;


      clp$pop_input_stack (input_block, ignore_status);
      clp$close_command_file (file_id, opened_executable_file, ignore_status);

    PROCEND abort_handler;
?? OLDTITLE, EJECT ??

    VAR
      caller_id: ost$caller_identifier,
      can_be_echoed: boolean,
      command_name: clt$name,
      command_parse: clt$parse_state,
      device_class: rmt$device_class,
      empty_command: boolean,
      end_of_input: boolean,
      escaped_command: boolean,
      form: clt$command_reference_form,
      file_has_fap: boolean,
      file_id: amt$file_identifier,
      ignore_can_be_echoed: boolean,
      ignore_command_ref_parse: clt$parse_state,
      ignore_file: clt$file,
      ignore_file_contents: clt$file_contents,
      ignore_ring_attributes: amt$ring_attributes,
      ignore_sequence: ^SEQ ( * ),
      ignore_util_command_list_entry: ^clt$command_list_entry,
      input_block: ^clt$block,
      label: ost$name,
      line_layout: clt$line_layout,
      local_status: ost$status,
      opened_executable_file: boolean,
      parameter_list: ^record
        size: clt$parameter_list_text_size,
        text: clt$parameter_list_text,
      recend,
      parse: clt$parse_state,
      path_handle_name: fst$path_handle_name,
      prompting_requested: boolean,
      separator: clt$lexical_unit_kind;


    status.normal := TRUE;

    #CALLER_ID (caller_id);
    IF submitter_ring > caller_id.ring THEN
      caller_id.ring := submitter_ring;
    IFEND;

    file_id := amv$nil_file_identifier;
    #SPOIL (file_id);
    login_command_in_file := TRUE;
    input_block := NIL;
    #SPOIL (input_block);
    osp$establish_block_exit_hndlr (^abort_handler);

  /get_job_parameters/
    BEGIN
      clp$access_command_file (clc$submit_job, caller_id.ring, submitted_file_reference, file_id,
            ignore_sequence, opened_executable_file, ignore_can_be_echoed, line_layout, ignore_file_contents,
            ignore_ring_attributes, file_has_fap, device_class, path_handle_name, status);
      IF NOT status.normal THEN
        EXIT /get_job_parameters/;
      IFEND;
      clp$push_input_file_block (path_handle_name, file_id, osc$null_name, '', can_be_echoed, line_layout,
            device_class, file_has_fap, TRUE, input_block);

    /find_command/
      WHILE TRUE DO
        empty_command := TRUE;
        clp$get_command_line (parse, end_of_input, status);
        IF (NOT status.normal) OR end_of_input THEN
          EXIT /find_command/;
        IFEND;
        IF parse.unit.kind = clc$lex_beginning_of_line THEN
          clp$scan_any_lexical_unit (parse);
        IFEND;
        REPEAT
          command_parse := parse;
          clp$scan_unnested_cmnd_lex_unit (parse);
          command_parse.index_limit := parse.unit_index;
          clp$parse_command (command_parse, prompting_requested, escaped_command, label,
                ignore_command_ref_parse, ignore_file, form, command_name, ignore_util_command_list_entry,
                separator, empty_command, status);
          IF (NOT status.normal) OR (NOT empty_command) THEN
            EXIT /find_command/;
          IFEND;
          WHILE parse.unit.kind = clc$lex_semicolon DO
            clp$scan_non_space_lexical_unit (parse);
          WHILEND;
        UNTIL parse.unit.kind = clc$lex_end_of_line;
      WHILEND /find_command/;

      IF status.normal AND (NOT empty_command) AND (NOT prompting_requested) AND (NOT escaped_command) AND
            (label = osc$null_name) AND ((form = clc$name_only_command_ref) OR
            (form = clc$system_command_ref)) AND (command_name.value = 'LOGIN') AND
            (separator <> clc$lex_equal) THEN
        login_command_in_file := TRUE;

        clp$close_command_file (file_id, opened_executable_file, status);

        PUSH parameter_list: [command_parse.index_limit - command_parse.unit_index];
        parameter_list^.size := command_parse.index_limit - command_parse.unit_index;
        parameter_list^.text := command_parse.text^ (command_parse.unit_index, parameter_list^.size);

        clp$pop_input_stack (input_block, local_status);
        IF (NOT status.normal) OR (NOT local_status.normal) THEN
          IF status.normal THEN
            status := local_status;
          IFEND;
          EXIT /get_job_parameters/;
        IFEND;

        clp$push_sub_parameters_block ({ lookup_functions_and_variables } FALSE);
        clp$get_login_parameters (#SEQ (parameter_list^) ^, job_system_label, status);
        IF NOT status.normal THEN
          osp$set_status_abnormal ('CL', cle$bad_or_missing_login_in_job, path_handle_name, status);
          EXIT /get_job_parameters/;
        IFEND;

        clp$pop_parameters (local_status);
        IF status.normal AND (NOT local_status.normal) THEN
          status := local_status;
        IFEND;

      ELSE
        login_command_in_file := FALSE;
        osp$set_status_abnormal ('CL', cle$bad_or_missing_login_in_job, path_handle_name, status);
        clp$close_command_file (file_id, opened_executable_file, local_status);
        clp$pop_input_stack (input_block, local_status);
      IFEND;
    END /get_job_parameters/;

    osp$disestablish_cond_handler;

  PROCEND clp$get_job_parameters;

MODEND clm$get_job_parameters;
