?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL Interpreter : Extract_Message_Module' ??
MODULE clm$extract_message_module;

{
{  PURPOSE:
{    This module contains the code to extract the subcommands which produced the message module.
{
?? NEWTITLE := 'GLOBAL DECLARATIONS', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clc$page_widths
*copyc osc$max_status_message
*copyc osc$min_status_message_line
*copyc ost$message_template
*copyc ost$message_template_index
*copyc ost$message_template_module
*copyc osv$upper_to_lower
?? POP ??
*copyc amp$close
*copyc amp$fetch
*copyc amp$get_file_attributes
*copyc amp$put_next
*copyc clp$convert_integer_to_rjstring
*copyc clp$convert_integer_to_string
*copyc clp$extract_msg_module_contents
*copyc clp$get_value
*copyc clp$scan_parameter_list
*copyc clp$trimmed_string_size
*copyc osp$find_application_menu
*copyc osp$unpack_status_condition

  TYPE
    key_record = record
      size: 1 .. 21,
      value: string (21),
    recend;

  CONST
    clc$max_command_chunk = osc$max_string_size DIV 2,
    min_page_width = 64;

  TYPE
    chunk_array = array [1 .. clc$max_command_chunk] of record
      position: integer,
      length: integer,
    recend;

  VAR
    osv$message_module_severities: [READ, oss$job_paged_literal] array [ost$message_module_severity] of record
*IF NOT $true(osv$unix_tools_on_ve)
      size: 5 .. 12,
      value: string (12),
    recend := [[11, 'INFORMATIVE'], [7, 'WARNING'], [5, 'ERROR'], [5, 'FATAL'], [12, 'CATASTROPHIC'], [12,
          'NON_STANDARD'], [9, 'DEPENDENT']];
*ELSE
      size: 21 .. 28,
      value: string (28),
    recend := [[27, 'osc$mm_informative_severity'], [23, 'osc$mm_warning_severity'],
          [21, 'osc$mm_error_severity'], [21, 'osc$mm_fatal_severity'],
          [28, 'osc$mm_catastrophic_severity'], [28, 'osc$mm_non_standard_severity'],
          [25, 'osc$mm_dependent_severity']];
*IFEND

?? PUSH (LISTEXT := ON) ??
*copyc oss$job_paged_literal
*copyc ost$message_module_severity
?? POP ??
?? TITLE := 'clp$get_message_module_info', EJECT ??

  PROCEDURE [XDCL] clp$get_message_module_info
    (    message_template_module: ^ost$message_template_module;
     VAR natural_language: ost$natural_language;
     VAR online_manual_name: ost$online_manual_name;
     VAR help_module: boolean;
     VAR message_module: boolean;
     VAR lowest_message_code: ost$status_condition_code;
     VAR highest_message_code: ost$status_condition_code;
     VAR status: ost$status);

    VAR
      header: ^ost$mtm_header,
      names: ^ost$mtm_condition_names,
      codes: ^ost$mtm_condition_codes;

    status.normal := TRUE;

    clp$extract_msg_module_contents (message_template_module, header, codes, names);

    natural_language := header^.language;
    online_manual_name := header^.online_manual_name;
    message_module := header^.number_of_codes > 0;
    help_module := header^.number_of_names > header^.number_of_codes;
    CASE header^.number_of_codes OF
    = 0 =
      lowest_message_code := 0;
      highest_message_code := 0;
    ELSE
      lowest_message_code := codes^ [LOWERBOUND (codes^)].code;
      highest_message_code := codes^ [UPPERBOUND (codes^)].code;
    CASEND;

  PROCEND clp$get_message_module_info;
?? TITLE := 'extract_message_templates', EJECT ??

  PROCEDURE extract_message_templates
    (    file_id: amt$file_identifier;
         page_width: amt$page_width;
         module_name: pmt$program_name;
         language: ost$natural_language;
         online_manual_name: ost$online_manual_name;
         names: ost$mtm_condition_names;
*IF $true(osv$unix_tools_on_ve)
         header: ost$mtm_header;
         codes: ost$mtm_condition_codes;
*IFEND
         message_template_module: ^ost$message_template_module;
     VAR status: ost$status);

?? NEWTITLE := 'put_line', EJECT ??

    PROCEDURE [INLINE] put_line
      (    line: string ( * ));

      VAR
        ignore_byte_address: amt$file_byte_address;

      amp$put_next (file_id, ^line, clp$trimmed_string_size (line), ignore_byte_address, status);
      IF NOT status.normal THEN
        EXIT extract_message_templates;
      IFEND;

    PROCEND put_line;
?? TITLE := 'put_text', EJECT ??

    PROCEDURE put_text
      (    template: ost$message_template;
           template_text: boolean);

      CONST
*IF NOT $true(osv$unix_tools_on_ve)
        terminate_string = '..';
*ELSE
        terminate_string = ''' CAT';
*IFEND

      VAR
        break_at_elipses: boolean,
        space_found: boolean,
        other_character_found: boolean,
        chunk_end: 0 .. osc$max_status_message,
        current: 0 .. osc$max_status_message + clc$wide_page_width,
        number_of_periods: 0 .. osc$max_status_message,
        result_length: integer,
        result_line: string (clc$wide_page_width),
        start: 0 .. osc$max_status_message;

      IF STRLENGTH (template) > 0 THEN
*IF NOT $true(osv$unix_tools_on_ve)
        IF (STRLENGTH (template) <= page_width) AND (template (STRLENGTH (template)) <> ' ') THEN
          put_line (template);
*ELSE
        IF (STRLENGTH (template) + 2 <= page_width) THEN
          STRINGREP (result_line, result_length, '''', template, '''');
          put_line (result_line (1, result_length));
*IFEND
*IF NOT $true(osv$unix_tools_on_ve)
        ELSEIF (template (STRLENGTH (template)) = ' ') AND ((STRLENGTH (template) + 2) <= page_width) THEN
          STRINGREP (result_line, result_length, template, '..');
          put_line (result_line (1, result_length));
*IFEND
        ELSE
          start := 1;
*IF NOT $true(osv$unix_tools_on_ve)
          IF STRLENGTH (template) > (page_width - 2) THEN
            current := page_width - 2;
*ELSE
          IF STRLENGTH (template) > (page_width - 6) THEN
            current := page_width - 6;
*IFEND
          ELSE
            current := STRLENGTH (template);
          IFEND;

          WHILE current <= STRLENGTH (template) DO

          /find_break_point/
            BEGIN
              break_at_elipses := FALSE;
              other_character_found := FALSE;
              space_found := FALSE;
              chunk_end := current;
              number_of_periods := 0;

              FOR current := chunk_end DOWNTO start DO
                CASE template (current) OF
                = ' ' =
                  space_found := TRUE;
                  EXIT /find_break_point/;
                = '.' =
                  IF current = chunk_end THEN
                    break_at_elipses := TRUE;
                  IFEND;
                  IF (break_at_elipses) AND (NOT other_character_found) THEN
                    number_of_periods := number_of_periods + 1;
                  IFEND;
                ELSE
                  other_character_found := TRUE;
                CASEND;
              FOREND;
            END /find_break_point/;
            IF NOT space_found THEN
              IF break_at_elipses THEN
                current := chunk_end - number_of_periods;
              ELSE
                current := chunk_end;
              IFEND;
            IFEND;
*IF NOT $true(osv$unix_tools_on_ve)
            STRINGREP (result_line, result_length, template (start, (current - start + 1)), terminate_string);
*ELSE
            STRINGREP (result_line, result_length, '''', template (start, (current - start + 1)),
                  terminate_string);
*IFEND
            put_line (result_line (1, result_length));
            start := current + 1;
*IF NOT $true(osv$unix_tools_on_ve)
            current := current + page_width - 2;
*ELSE
            current := current + page_width - 6;
*IFEND
          WHILEND;
*IF NOT $true(osv$unix_tools_on_ve)
          IF template (STRLENGTH (template)) = ' ' THEN
            STRINGREP (result_line, result_length, template (start, * ), terminate_string);
            put_line (result_line (1, result_length));
          ELSE
            put_line (template (start, * ));
          IFEND;
*ELSE
          STRINGREP (result_line, result_length, '''', template (start, * ), '''');
          put_line (result_line (1, result_length));
*IFEND
        IFEND;
      IFEND;
      IF template_text THEN
        put_line ('**');
      IFEND;

    PROCEND put_text;
?? TITLE := 'put_command_line', EJECT ??

    PROCEDURE put_command_line
      (    line: string ( * );
*IF NOT $true(osv$unix_tools_on_ve)
           indentation: 0 .. 4);
*ELSE
           indentation: 0 .. 10);
*IFEND

      CONST
        continuation = 6;

      VAR
        chunk_index: 0 .. clc$max_command_chunk,
        command: string (osc$max_string_size),
        command_chunk_array: chunk_array,
        command_chunk_count: 0 .. clc$max_command_chunk,
        command_size: integer,
        command_length: integer,
        command_line: string (osc$max_string_size),
*IF NOT $true(osv$unix_tools_on_ve)
        indentation_string: string (10),
*ELSE
        indentation_string: string (16),
*IFEND
        terminate_string: string (2);

*IF NOT $true(osv$unix_tools_on_ve)
      terminate_string := '..';
*ELSE
      terminate_string := '  ';
*IFEND
      indentation_string := ' ';
      command := line;
      command_size := clp$trimmed_string_size (line);

      IF command_size <= (page_width - indentation) THEN
        STRINGREP (command_line, command_length, indentation_string (1, indentation),
              command (1, command_size));
        put_line (command_line (1, command_length));
        RETURN;
      IFEND;

      build_chunks (command, command_size, (page_width - (indentation + continuation + 2)),
            command_chunk_count, command_chunk_array);

      FOR chunk_index := 1 TO command_chunk_count DO
        IF chunk_index = command_chunk_count THEN
          terminate_string := ' ';
        IFEND;
        IF chunk_index = 1 THEN
          STRINGREP (command_line, command_length, indentation_string (1, indentation),
                command (command_chunk_array [chunk_index].position, command_chunk_array [chunk_index].
                length), terminate_string);
        ELSE

          STRINGREP (command_line, command_length, indentation_string (1, indentation + continuation),
                command (command_chunk_array [chunk_index].position, command_chunk_array [chunk_index].
                length), terminate_string);
        IFEND;
        put_line (command_line (1, command_length));

      FOREND;

    PROCEND put_command_line;
?? TITLE := 'build_chunks', EJECT ??

    PROCEDURE build_chunks
      (VAR line: string ( * );
           length: 1 .. osc$max_string_size;
           width: amt$page_width;
       VAR count: 0 .. clc$max_command_chunk;
       VAR line_array: chunk_array);

      VAR
        break_position: 0 .. osc$max_string_size,
        current_character_position: 0 .. osc$max_string_size,
        current_length: 0 .. osc$max_string_size,
        remaining_text: 0 .. osc$max_string_size,
        starting_position: 1 .. osc$max_string_size,
        number_of_quotes: integer,
        break_allowed: boolean;

      current_character_position := 0;
      break_position := 0;
      remaining_text := length;
      count := 0;
      starting_position := 1;

      WHILE remaining_text > 0 DO
        break_allowed := TRUE;
        number_of_quotes := 0;
        count := count + 1;
        IF remaining_text <= width THEN
          line_array [count].position := starting_position;
          line_array [count].length := remaining_text;
          RETURN;
        IFEND;

        REPEAT
          current_character_position := current_character_position + 1;
          IF line (current_character_position) = '''' THEN
            number_of_quotes := number_of_quotes + 1;
            break_allowed := (number_of_quotes MOD 2) = 0;
          IFEND;
          IF break_allowed AND (line (current_character_position) = ' ') THEN
            break_position := current_character_position + 1;
          IFEND;
        UNTIL (current_character_position - starting_position = width);

        IF break_position > 0 THEN
          current_character_position := break_position;
        IFEND;

        IF count <> 1 THEN
          WHILE line (starting_position) = ' ' DO
            starting_position := starting_position + 1;
          WHILEND;
        IFEND;

        current_length := current_character_position - starting_position;
        line_array [count].position := starting_position;
        line_array [count].length := current_length;
        starting_position := current_character_position;
        remaining_text := length - starting_position + 1;
      WHILEND;

    PROCEND build_chunks;
?? TITLE := 'edit_string', EJECT ??

    PROCEDURE [INLINE] edit_string
      (    string_line: string ( * );
       VAR edited_line: string (osc$max_string_size);
       VAR edited_line_size: integer);

      VAR
        i: integer,
        string_size: integer;

      string_size := STRLENGTH (string_line);
      edited_line_size := 0;
      edited_line := ' ';

      FOR i := 1 TO string_size DO
        edited_line_size := edited_line_size + 1;
        edited_line (edited_line_size) := string_line (i);
        IF string_line (i) = '''' THEN
          edited_line_size := edited_line_size + 1;
          edited_line (edited_line_size) := '''';
        IFEND;
      FOREND;

    PROCEND edit_string;
?? TITLE := 'put_classes_and_items', EJECT ??

    PROCEDURE put_classes_and_items;

      VAR
        command_line: string (osc$max_string_size),
        command_length: integer,
        edited_string: string (osc$max_string_size),
        edited_string_size: integer,
        edited_string2: string (osc$max_string_size),
        edited_string2_size: integer,
        menu_header: ^ost$mtm_menu_header,
        menu_classes: cst$menu_class,
        menu_items: cst$menu_list,
        module_pointer: ^ost$message_template_module,
        parameter_line: string (osc$max_string_size),
        parameter_length: integer,
        i: cst$max_classes,
        j: cst$menu_item_number,
        key: key_record,
        shift: boolean;

      module_pointer := message_template_module;
      menu_header := #PTR (names [index].menu_header, message_template_module^);
      RESET module_pointer TO menu_header;
      NEXT menu_header IN module_pointer;
      NEXT menu_classes: [1 .. menu_header^.number_of_classes] IN module_pointer;
      NEXT menu_items: [1 .. menu_header^.number_of_menu_items] IN module_pointer;

      FOR i := 1 TO UPPERBOUND (menu_classes^) DO
        edit_string (menu_classes^ [i] (1, clp$trimmed_string_size (menu_classes^ [i])),
              edited_string, edited_string_size);
        STRINGREP (command_line, command_length, 'CREATE_MENU_CLASS NAME=''',
              edited_string (1, edited_string_size), '''');
        put_command_line (command_line (1, command_length), 4);
      FOREND;

      FOR j := 1 TO UPPERBOUND (menu_items^) DO
        IF menu_items^ [j].item_assigned THEN
          CASE menu_items^ [j].menu_type OF
          = csc$standard_function =
            search_standard_functions (menu_items^ [j].standard_function, key, shift);
          = csc$application_function =
            search_application_functions (menu_items^ [j].application_function, key, shift);
          = csc$screen_function =
            search_screen_functions (menu_items^ [j].screen_function, key);
            shift := FALSE;
          ELSE
          CASEND;
          IF shift THEN
            STRINGREP (parameter_line, parameter_length, 'CREATE_MENU_ITEM', ' KEY=', key.value (1, key.size),
                  ' SHIFT=YES');
          ELSE
            STRINGREP (parameter_line, parameter_length, 'CREATE_MENU_ITEM', ' KEY=', key.
                  value (1, key.size));
          IFEND;
        ELSE
          parameter_line := 'CREATE_MENU_ITEM';
          parameter_length := 20;
        IFEND;

        edit_string (menu_classes^ [menu_items^ [j].menu_parent]
              (1, clp$trimmed_string_size (menu_classes^ [menu_items^ [j].menu_parent])),
              edited_string, edited_string_size);
        edit_string (menu_items^ [j].short_label (1, clp$trimmed_string_size (menu_items^ [j].short_label)),
              edited_string2, edited_string2_size);

        STRINGREP (command_line, command_length, parameter_line (1, parameter_length), ' CLASS=''',
              edited_string (1, edited_string_size), ''' SHORT_LABEL=''',
              edited_string2 (1, edited_string2_size), '''');

        IF menu_items^ [j].alternate_short_label <> menu_items^ [j].short_label THEN
          parameter_line := command_line;
          parameter_length := command_length;
          edit_string (menu_items^ [j].alternate_short_label
                (1, clp$trimmed_string_size (menu_items^ [j].alternate_short_label)), edited_string,
                edited_string_size);
          STRINGREP (command_line, command_length, parameter_line (1, parameter_length),
                ' ALTERNATE_SHORT_LABEL=''', edited_string (1, edited_string_size), '''');
        IFEND;

        IF menu_items^ [j].long_label <> menu_items^ [j].short_label THEN
          parameter_line := command_line;
          parameter_length := command_length;
          edit_string (menu_items^ [j].long_label (1, clp$trimmed_string_size (menu_items^ [j].long_label)),
                edited_string, edited_string_size);
          STRINGREP (command_line, command_length, parameter_line (1, parameter_length), ' LONG_LABEL=''',
                edited_string (1, edited_string_size), '''');
        IFEND;

        IF menu_items^ [j].alternate_long_label <> menu_items^ [j].long_label THEN
          parameter_line := command_line;
          parameter_length := command_length;
          edit_string (menu_items^ [j].alternate_long_label (1,
                clp$trimmed_string_size (menu_items^ [j].alternate_long_label)), edited_string,
                edited_string_size);
          STRINGREP (command_line, command_length, parameter_line (1, parameter_length),
                ' ALTERNATE_LONG_LABEL=''', edited_string (1, edited_string_size), '''');
        IFEND;

        IF menu_items^ [j].pair_with_previous THEN
          parameter_line := command_line;
          parameter_length := command_length;
          STRINGREP (command_line, command_length, parameter_line (1, parameter_length),
                ' PAIR_WITH_PREVIOUS=YES');
        IFEND;

        put_command_line (command_line (1, command_length), 4);
      FOREND;

      put_line ('  END_APPLICATION_MENU');

    PROCEND put_classes_and_items;
?? TITLE := 'search_standard_functions', EJECT ??

    PROCEDURE search_standard_functions
      (    standard_function: cst$standard_functions;
       VAR key: key_record;
       VAR shift: boolean);

      TYPE
        shifted_standard_fcns = set of cst$standard_functions;

      VAR
        shifted_standard_functions: shifted_standard_fcns;

      shifted_standard_functions := $shifted_standard_fcns
            [csc$sh_next, csc$sh_help, csc$sh_stop, csc$sh_back, csc$sh_down, csc$sh_forward, csc$sh_backward,
            csc$edit, csc$data, csc$sh_undo];

      CASE standard_function OF
      = csc$next, csc$sh_next =
        key.value := 'NEXT';
        key.size := 4;
      = csc$undo, csc$sh_undo =
        key.value := 'UNDO';
        key.size := 4;
      = csc$help, csc$sh_help =
        key.value := 'HELP';
        key.size := 4;
      = csc$stop, csc$sh_stop =
        key.value := 'STOP';
        key.size := 4;
      = csc$back, csc$sh_back =
        key.value := 'BACK';
        key.size := 4;
      = csc$up, csc$sh_up =
        key.value := 'UP';
        key.size := 2;
      = csc$down, csc$sh_down =
        key.value := 'DOWN';
        key.size := 4;
      = csc$forward, csc$sh_forward =
        key.value := 'FORWARD';
        key.size := 7;
      = csc$backward, csc$sh_backward =
        key.value := 'BACKWARD';
        key.size := 8;
      = csc$edit, csc$sh_edit =
        key.value := 'EDIT';
        key.size := 4;
      = csc$data, csc$sh_data =
        key.value := 'DATA';
        key.size := 4;
      ELSE
        key.value := 'NEXT';
        key.size := 4;
      CASEND;

      shift := standard_function IN shifted_standard_functions;

    PROCEND search_standard_functions;
?? TITLE := 'search_application_functions', EJECT ??

    PROCEDURE search_application_functions
      (    application_function: cst$application_functions;
       VAR key: key_record;
       VAR shift: boolean);

      TYPE
        shifted_application_fcns = set of cst$application_functions;

      VAR
        shifted_application_functions: shifted_application_fcns,
        ignore_status: ost$status,
        integer_string: ost$string;

      shifted_application_functions := $shifted_application_fcns
            [csc$sf1, csc$sf2, csc$sf3, csc$sf4, csc$sf5, csc$sf6, csc$sf7, csc$sf8, csc$sf9, csc$sf10,
            csc$sf11, csc$sf12, csc$sf13, csc$sf14, csc$sf15, csc$sf16];
      key.value (1) := 'F';

      clp$convert_integer_to_string ((($INTEGER (application_function) + 2) DIV 2), 10, FALSE, integer_string,
            ignore_status);
      key.value (2, integer_string.size) := integer_string.value (1, integer_string.size);
      key.size := integer_string.size + 1;
      shift := application_function IN shifted_application_functions;

    PROCEND search_application_functions;
?? TITLE := 'search_screen_functions', EJECT ??

    PROCEDURE search_screen_functions
      (    screen_function: cst$screen_events;
       VAR key: key_record);

      CASE screen_function OF
      = csc$insert_line =
        key.size := 11;
        key.value := 'INSERT_LINE';
      = csc$insert_char_menu_item =
        key.size := 21;
        key.value := 'INSERT_CHAR_MENU_ITEM';
      = csc$delete_char_menu_item =
        key.size := 21;
        key.value := 'DELETE_CHAR_MENU_ITEM';
      = csc$clear_eol_menu_item =
        key.size := 19;
        key.value := 'CLEAR_EOL_MENU_ITEM';
      = csc$delete_line =
        key.size := 11;
        key.value := 'DELETE_LINE';
      = csc$home =
        key.size := 4;
        key.value := 'HOME';
      = csc$clear =
        key.size := 5;
        key.value := 'CLEAR';
      ELSE
        key.size := 4;
        key.value := 'HOME';
      CASEND;

    PROCEND search_screen_functions;
?? OLDTITLE, EJECT ??

    VAR
      collect_until: string (osc$max_name_size),
      command: ost$name,
      command_length: integer,
      command_line: string (osc$max_string_size),
      identifier: ost$status_identifier,
      index: ost$message_template_index,
      manual_line: string (osc$max_string_size),
      manual_length: integer,
      name_parameter: string (6 + osc$max_string_size),
      name_parameter_length: integer,
      number_of_quotes: integer,
      number: ost$status_condition_number,
      number_string: ost$string,
      template: ^ost$message_template,
*IF $true(osv$unix_tools_on_ve)
      edited_line: string (osc$max_string_size),
      edited_line_size: integer,
      terminator: string (2),
*IFEND
      parameter_line: string (6 + osc$max_string_size),
      parameter_length: integer;

    status.normal := TRUE;

*IF NOT $true(osv$unix_tools_on_ve)
    IF online_manual_name = '' THEN
      manual_line := online_manual_name;
      manual_length := 0;
    ELSE
      STRINGREP (manual_line, manual_length, ' MANUAL=', online_manual_name
            (1, clp$trimmed_string_size (online_manual_name)));
    IFEND;

    STRINGREP (command_line, command_length, 'CREATE_MESSAGE_MODULE NAME=',
          module_name (1, clp$trimmed_string_size (module_name)), manual_line (1, manual_length),
          ' NATURAL_LANGUAGE=', language (1, clp$trimmed_string_size (language)));
    put_command_line (command_line (1, command_length), 0);

    FOR index := 0 TO UPPERBOUND (names) DO
      collect_until := ' COLLECT_TEMPLATE_UNTIL=''**''';
      command_line := ' ';
      template := #PTR (names [index].template, message_template_module^);
      STRINGREP (name_parameter, name_parameter_length, ' NAME=', names [index].
            name (1, clp$trimmed_string_size (names [index].name)));
      parameter_line := name_parameter;
      parameter_length := name_parameter_length;

      CASE names [index].kind OF
      = osc$status_message =
        command := 'CREATE_STATUS_MESSAGE';
        osp$unpack_status_condition (names [index].code, identifier, number);
        clp$convert_integer_to_string (number, 10, FALSE, number_string, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        STRINGREP (parameter_line, parameter_length, name_parameter (1, name_parameter_length),
              ' IDENTIFIER=''', identifier, ''' CODE=', number_string.value (1, number_string.size),
              ' SEVERITY=', osv$message_module_severities [names [index].severity].
              value (1, osv$message_module_severities [names [index].severity].size));
      = osc$brief_help =
        command := 'CREATE_BRIEF_HELP_MESSAGE';
        parameter_line := ' ';
        parameter_length := 0;
      = osc$full_help =
        command := 'CREATE_FULL_HELP_MESSAGE';
        parameter_line := ' ';
        parameter_length := 0;
      = osc$application_menu =
        command := 'CREATE_APPLICATION_MENU';
        collect_until := ' ';
      = osc$parameter_prompt =
        command := 'CREATE_PARAMETER_PROMPT_MESSAGE';
      = osc$parameter_assistance_prompt =
        command := 'CREATE_PARAMETER_ASSIST_MESSAGE';
      = osc$parameter_help =
        command := 'CREATE_PARAMETER_HELP_MESSAGE';
      CASEND;

      STRINGREP (command_line, command_length, command, ' ', parameter_line (1, parameter_length),
            collect_until (1, clp$trimmed_string_size (collect_until)));
      put_command_line (command_line (1, command_length), 2);

      IF names [index].kind = osc$application_menu THEN
        put_classes_and_items;
      ELSE
        put_text (template^, TRUE);
      IFEND;
    FOREND;
    put_text ('END_MESSAGE_MODULE CREATE_MODULE=YES', FALSE);
*ELSE
    put_command_line ('VAR', 4);
    put_command_line (
          'osv$built_in_templates: [XDCL, STATIC] record', 6);
    put_command_line ('header: ost$mtm_header,', 8);
    STRINGREP (command_line, command_length, 'condition_codes: array [0 .. ',
          UPPERBOUND (codes), '] of ost$mtm_condition_code,');
    put_command_line (command_line (1, command_length), 8);
    STRINGREP (command_line, command_length, 'condition_names: array [0 .. ',
          UPPERBOUND (names), '] of ost$mtm_condition_name,');
    put_command_line (command_line (1, command_length), 8);
    put_command_line ('recend :=[',6);
    STRINGREP (command_line, command_length, '[''', header.version,
          ''', ''', header.language, ''', ''', online_manual_name (
          1, clp$trimmed_string_size (online_manual_name)),
          ''', ', header.number_of_codes, ' ,', header.number_of_names, '],');
    put_command_line (command_line (1, command_length), 6);
    put_command_line ('[', 6);
    terminator := '],';
    FOR index:= 0 to UPPERBOUND (codes) DO
      IF index = UPPERBOUND (codes) THEN
        terminator := ']';
      IFEND;
      STRINGREP (command_line, command_length, '[', codes [index].code,
            ', ', codes [index].name_index, terminator);
      put_command_line (command_line (1, command_length), 6);
    FOREND;
    put_command_line ('],', 6);
    put_command_line ('[', 6);
    terminator := '],';
    FOR index:= 0 to UPPERBOUND (names) DO
      STRINGREP (command_line, command_length, '[''', names [index].name,
            ''', ', names [index].code, ', ',
osv$message_module_severities[ names [index].severity].value (1,
osv$message_module_severities[ names [index].severity].size), ',');
      put_command_line (command_line (1, command_length), 6);
      template := #PTR (names [index].template, message_template_module^);
      IF index = UPPERBOUND (names) THEN
        terminator := ']';
      IFEND;
      edit_string (template^, edited_line, edited_line_size);
      put_text (edited_line (1, edited_line_size), FALSE);
      put_command_line (terminator, 6);
    FOREND;
    put_command_line (']];', 6);
*IFEND

  PROCEND extract_message_templates;
?? TITLE := 'clp$extract_message_module', EJECT ??

  PROCEDURE [XDCL] clp$extract_message_module
    (    file_id: amt$file_identifier;
         module_name: pmt$program_name;
         message_module: ^ost$message_template_module;
     VAR status: ost$status);

    VAR
      codes: ^ost$mtm_condition_codes,
      file_attributes: array [1 .. 1] of amt$fetch_item,
      header: ^ost$mtm_header,
      page_width: amt$page_width,
      names: ^ost$mtm_condition_names;

    status.normal := TRUE;
    file_attributes [1].key := amc$page_width;

    amp$fetch (file_id, file_attributes, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

*IF NOT $true(osv$unix_tools_on_ve)
    IF file_attributes [1].page_width < min_page_width THEN
      page_width := min_page_width;
    ELSEIF file_attributes [1].page_width > clc$wide_page_width THEN
      page_width := clc$wide_page_width;
    ELSE
      page_width := file_attributes [1].page_width;
    IFEND;
*ELSE
    page_width := 110;
*IFEND

    clp$extract_msg_module_contents (message_module, header, codes, names);

    extract_message_templates (file_id, page_width, module_name, header^.language, header^.online_manual_name,
*IF NOT $true(osv$unix_tools_on_ve)
          names^, message_module, status);
*ELSE
          names^, header^, codes^, message_module, status);
*IFEND
    IF NOT status.normal THEN
      RETURN;
    IFEND;

  PROCEND clp$extract_message_module;

MODEND clm$extract_message_module;
