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

{
{ PURPOSE:
{   This module contains the processors of the CREATE_MESSAGE_MODULE utility subcommands.
{

?? NEWTITLE := 'GLOBAL DECLARATIONS', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clc$standard_file_names
*copyc cle$ecc_miscellaneous
*copyc cle$ecc_mt_generator
*copyc cle$ecc_parameter_list
*copyc clt$command_line_size
*copyc csc$max_menu_items
*copyc cst$class_name
*copyc cst$key_type
*copyc cst$menu_class
*copyc cst$menu_item
*copyc cst$menu_item_number
*copyc cst$menu_list
*copyc cst$screen_events
*copyc cst$standard_functions
*copyc llt$object_library_header
*copyc osc$max_status_condition_number
*copyc osc$max_status_message
*copyc osd$virtual_address
*copyc oss$job_paged_literal
*copyc ost$message_template
*copyc ost$message_template_index
*copyc ost$message_template_module
*copyc ost$mtm_menu_header
?? POP ??
*copyc clp$begin_utility
*copyc clp$convert_integer_to_string
*IF NOT $true(osv$unix_tools_on_ve)
*copyc clp$define_application_menu
*IFEND
*copyc clp$end_include
*copyc clp$end_utility
*copyc clp$evaluate_parameters
*IF $true(osv$unix_tools_on_ve)
*copyc clp$extract_message_module
*copyc fsp$close_file
*copyc fsp$open_file
*IFEND
*copyc clp$get_line_from_command_file
*copyc clp$include_file
*copyc clp$trimmed_string_size
*copyc i#current_sequence_position
*IF NOT $true(osv$unix_tools_on_ve)
*copyc ocp$generate_message
*IFEND
*copyc osp$append_status_parameter
*copyc osp$get_status_condition_string
*copyc osp$set_status_abnormal
*copyc osp$status_condition_code
?? EJECT ??

  TYPE
    menu_record = record
      name: ost$status_condition_name,
      number_of_classes: cst$max_classes,
      number_of_items: cst$menu_item_number,
    recend;

  TYPE
    message_record = record
      code: ost$status_condition_code,
      name: ost$status_condition_name,
      severity: ost$message_module_severity,
      size: 0 .. osc$max_status_message,
    recend;

  CONST
    prompt_string = 'CMM',
    prompt_string_size = 3;

  VAR
    create_module: boolean,
    in_create_message_module: [STATIC] boolean := FALSE,
    message_module_name: pmt$program_name,
    module_has_errors: boolean,
    number_of_application_menus: ost$message_template_index,
    number_of_codes: ost$message_template_index,
    number_of_names: ost$message_template_index,
    store_info_status: ost$status,
    total_number_of_classes: ost$message_template_index,
    total_number_of_items: ost$message_template_index,
    total_template_size: ost$segment_length,
    utility_name: [STATIC, READ, oss$job_paged_literal] ost$name := 'CREATE_MESSAGE_MODULE',
    work_area_ptr: ^SEQ ( * );

?? TITLE := 'collect_template', EJECT ??

  PROCEDURE collect_template
    (    kind: ost$message_template_kind;
         sub_command: string ( * <= osc$max_name_size);
         name: ost$name;
         until_string: ^clt$string_value;
     VAR template_size: 0 .. osc$max_status_message;
     VAR status: ost$status);

    VAR
      converted_integer: ost$string,
      culprit: ost$name,
      beginning_of_template: ^ost$message_template,
      line: ^clt$command_line,
      line_size: clt$command_line_size,
      local_status: ost$status,
      number_of_classes: cst$max_classes,
      number_of_items: cst$menu_item_number,
      message_status: ost$status,
      template_too_long: boolean,
      template_pointer: ^ost$message_template;

    status.normal := TRUE;
    template_size := 0;
    template_too_long := FALSE;

    IF store_info_status.normal THEN
      NEXT template_pointer: [0] IN work_area_ptr;
      beginning_of_template := template_pointer;
      IF (number_of_names + 1) > osc$max_status_condition_code THEN
        clp$convert_integer_to_string (osc$max_status_condition_code, 10, FALSE, converted_integer,
              store_info_status);
        osp$set_status_abnormal ('CL', cle$too_many_entries_for_module, converted_integer.
              value (1, converted_integer.size), store_info_status);
        osp$append_status_parameter (osc$status_parameter_delimiter, message_module_name, store_info_status);
      ELSE
        number_of_names := number_of_names + 1;
        IF kind = osc$status_message THEN
          number_of_codes := number_of_codes + 1;
        IFEND;
      IFEND;
    IFEND;

  /collect_template_loop/
    WHILE TRUE DO
      clp$get_line_from_command_file ('? ', line, local_status);
      IF status.normal AND (NOT local_status.normal) THEN
        status := local_status;
      ELSEIF NOT status.normal THEN
        EXIT /collect_template_loop/;
      ELSEIF line = NIL THEN
        IF status.normal THEN
          osp$set_status_abnormal ('CL', cle$encountered_eoi, sub_command, status);
        IFEND;
        EXIT /collect_template_loop/;
      ELSEIF (STRLENGTH (line^) = STRLENGTH (until_string^)) AND (line^ = until_string^) THEN
        EXIT /collect_template_loop/;
      ELSEIF (NOT template_too_long) AND store_info_status.normal THEN
        line_size := STRLENGTH (line^);
        IF line_size > 0 THEN
          IF (line_size > 1) AND (line^ (STRLENGTH (line^) - 1, 2) = '..') THEN
            WHILE (line_size >= 1) AND (line^ (line_size) = '.') DO
              line_size := line_size - 1;
            WHILEND;
          IFEND;
          IF line_size > 0 THEN
            template_too_long := (template_size + line_size) > osc$max_status_message;
            IF template_too_long THEN
              IF kind = osc$brief_help THEN
                culprit := 'BRIEF HELP MESSAGE';
              ELSEIF kind = osc$full_help THEN
                culprit := 'FULL HELP MESSAGE';
              ELSE
                culprit := name;
              IFEND;
              NEXT template_pointer: [osc$max_status_message - template_size] IN work_area_ptr;
              IF template_pointer = NIL THEN
                osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
              ELSE
                template_pointer^ := line^ (1, osc$max_status_message - template_size);
                template_size := osc$max_status_message;
                clp$convert_integer_to_string (osc$max_status_message, 10, FALSE, converted_integer,
                      message_status);
                osp$set_status_abnormal ('CL', cle$template_too_long, culprit, message_status);
                osp$append_status_parameter (osc$status_parameter_delimiter, message_module_name,
                      message_status);
                osp$append_status_parameter (osc$status_parameter_delimiter, converted_integer.value,
                      message_status);
*IF NOT $true(osv$unix_tools_on_ve)
                ocp$generate_message (message_status);
*IFEND
                module_has_errors := TRUE;
              IFEND;
            ELSE
              template_size := template_size + line_size;
              NEXT template_pointer: [line_size] IN work_area_ptr;
              IF template_pointer = NIL THEN
                osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
              ELSE
                template_pointer^ (1, line_size) := line^ (1, line_size);
              IFEND;
            IFEND;
          IFEND;
        IFEND;
      IFEND;
    WHILEND /collect_template_loop/;

    IF store_info_status.normal THEN
      RESET work_area_ptr TO beginning_of_template;
      NEXT template_pointer: [template_size] IN work_area_ptr;
      total_template_size := total_template_size + template_size;
    ELSE
      IF status.normal THEN
        status := store_info_status;
      IFEND;
    IFEND;

  PROCEND collect_template;
?? TITLE := 'clp$_create_status_message', EJECT ??

  PROCEDURE clp$_create_status_message
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (ocm$cremm_cresm) create_status_message, cresm (
{   name, n: name = $required
{   code, c: integer 0..0ffffffffff(16) = $required
{   identifier, i: string 2 = $optional
{   severity, s: key
{       (informative, i)
{       (warning, w)
{       (error, e)
{       (fatal, f)
{       (catastrophic, c)
{       (non_standard, ns)
{       (dependent, d)
{     keyend = error
{   collect_template_until, ctu: string literal = '**'
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 11] of clt$pdt_parameter_name,
      parameters: array [1 .. 6] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$name_type_qualifier,
      recend,
      type2: record
        header: clt$type_specification_header,
        qualifier: clt$integer_type_qualifier,
      recend,
      type3: record
        header: clt$type_specification_header,
        qualifier: clt$string_type_qualifier,
      recend,
      type4: record
        header: clt$type_specification_header,
        qualifier: clt$keyword_type_qualifier,
        keyword_specs: array [1 .. 14] of clt$keyword_specification,
        default_value: string (5),
      recend,
      type5: record
        header: clt$type_specification_header,
        qualifier: clt$string_type_qualifier,
        default_value: string (4),
      recend,
      type6: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [89, 11, 30, 17, 21, 43, 698],
    clc$command, 11, 6, 2, 0, 0, 0, 6, 'OCM$CREMM_CRESM'], [
    ['C                              ',clc$abbreviation_entry, 2],
    ['CODE                           ',clc$nominal_entry, 2],
    ['COLLECT_TEMPLATE_UNTIL         ',clc$nominal_entry, 5],
    ['CTU                            ',clc$abbreviation_entry, 5],
    ['I                              ',clc$abbreviation_entry, 3],
    ['IDENTIFIER                     ',clc$nominal_entry, 3],
    ['N                              ',clc$abbreviation_entry, 1],
    ['NAME                           ',clc$nominal_entry, 1],
    ['S                              ',clc$abbreviation_entry, 4],
    ['SEVERITY                       ',clc$nominal_entry, 4],
    ['STATUS                         ',clc$nominal_entry, 6]],
    [
{ PARAMETER 1
    [8, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 5, clc$required_parameter, 0, 0],
{ PARAMETER 2
    [2, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 20, clc$required_parameter, 0, 0],
{ PARAMETER 3
    [6, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 8, clc$optional_parameter, 0, 0],
{ PARAMETER 4
    [10, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 525, clc$optional_default_parameter, 0, 5],
{ PARAMETER 5
    [3, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 8, clc$optional_default_parameter, 0, 4],
{ PARAMETER 6
    [11, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$name_type], [1, osc$max_name_size]],
{ PARAMETER 2
    [[1, 0, clc$integer_type], [0, 0ffffffffff(16), 10]],
{ PARAMETER 3
    [[1, 0, clc$string_type], [2, 2, FALSE]],
{ PARAMETER 4
    [[1, 0, clc$keyword_type], [14], [
    ['C                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 5],
    ['CATASTROPHIC                   ', clc$nominal_entry,
  clc$normal_usage_entry, 5],
    ['D                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 7],
    ['DEPENDENT                      ', clc$nominal_entry,
  clc$normal_usage_entry, 7],
    ['E                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 3],
    ['ERROR                          ', clc$nominal_entry,
  clc$normal_usage_entry, 3],
    ['F                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 4],
    ['FATAL                          ', clc$nominal_entry,
  clc$normal_usage_entry, 4],
    ['I                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 1],
    ['INFORMATIVE                    ', clc$nominal_entry,
  clc$normal_usage_entry, 1],
    ['NON_STANDARD                   ', clc$nominal_entry,
  clc$normal_usage_entry, 6],
    ['NS                             ', clc$abbreviation_entry,
  clc$normal_usage_entry, 6],
    ['W                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 2],
    ['WARNING                        ', clc$nominal_entry,
  clc$normal_usage_entry, 2]]
    ,
    'error'],
{ PARAMETER 5
    [[1, 0, clc$string_type], [0, clc$max_string_size, TRUE],
    '''**'''],
{ PARAMETER 6
    [[1, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$name = 1,
      p$code = 2,
      p$identifier = 3,
      p$severity = 4,
      p$collect_template_until = 5,
      p$status = 6;

    VAR
      pvt: array [1 .. 6] of clt$parameter_value;

    VAR
      code: ost$status_condition_code,
      message_info_p: ^message_record,
      message_kind_p: ^ost$message_template_kind,
      severity: ost$message_module_severity,
      template_size: 0 .. osc$max_status_message,
      until_string_p: ^clt$string_value;

    status.normal := TRUE;

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

    IF pvt [p$code].value^.integer_value.value <= osc$max_status_condition_number THEN
      IF NOT pvt [p$identifier].specified THEN
        osp$set_status_abnormal ('CL', cle$required_parameter_omitted, 'IDENTIFIER', status);
        RETURN;
      IFEND;
      code := osp$status_condition_code (pvt [p$identifier].value^.string_value^, pvt [p$code].
            value^.integer_value.value);
    ELSE
      code := pvt [p$code].value^.integer_value.value;
    IFEND;

    IF pvt [p$severity].value^.keyword_value = 'INFORMATIVE' THEN
      severity := osc$mm_informative_severity;
    ELSEIF pvt [p$severity].value^.keyword_value = 'WARNING' THEN
      severity := osc$mm_warning_severity;
    ELSEIF pvt [p$severity].value^.keyword_value = 'ERROR' THEN
      severity := osc$mm_error_severity;
    ELSEIF pvt [p$severity].value^.keyword_value = 'FATAL' THEN
      severity := osc$mm_fatal_severity;
    ELSEIF pvt [p$severity].value^.keyword_value = 'CATASTROPHIC' THEN
      severity := osc$mm_catastrophic_severity;
    ELSEIF pvt [p$severity].value^.keyword_value = 'NON_STANDARD' THEN
      severity := osc$mm_non_standard_severity;
    ELSE {pvt [p$severity].value^.keyword_value = 'DEPENDENT'
      severity := osc$mm_dependent_severity;
    IFEND;

    until_string_p := pvt [p$collect_template_until].value^.string_value;

    NEXT message_kind_p IN work_area_ptr;
    IF message_kind_p = NIL THEN
      osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
    ELSE
      message_kind_p^ := osc$status_message;
    IFEND;

    IF store_info_status.normal THEN
      NEXT message_info_p IN work_area_ptr;
      IF message_info_p = NIL THEN
        osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
      IFEND;
    IFEND;
    collect_template (osc$status_message, 'CREATE_STATUS_MESSAGE', pvt [p$name].value^.name_value,
          until_string_p, template_size, status);

    IF store_info_status.normal THEN
      message_info_p^.name := pvt [p$name].value^.name_value;
      message_info_p^.code := code;
      message_info_p^.severity := severity;
      message_info_p^.size := template_size;
    IFEND;

    IF NOT status.normal THEN
      RESET work_area_ptr TO message_kind_p;
    IFEND;

  PROCEND clp$_create_status_message;
?? TITLE := 'clp$_create_brief_help_message', EJECT ??

  PROCEDURE clp$_create_brief_help_message
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (ocm$cremm_crebhm) create_brief_help_message, crebhm (
{   collect_template_until, ctu: string literal = '**'
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 3] of clt$pdt_parameter_name,
      parameters: array [1 .. 2] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$string_type_qualifier,
        default_value: string (4),
      recend,
      type2: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [89, 11, 30, 17, 23, 8, 219],
    clc$command, 3, 2, 0, 0, 0, 0, 2, 'OCM$CREMM_CREBHM'], [
    ['COLLECT_TEMPLATE_UNTIL         ',clc$nominal_entry, 1],
    ['CTU                            ',clc$abbreviation_entry, 1],
    ['STATUS                         ',clc$nominal_entry, 2]],
    [
{ PARAMETER 1
    [1, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 8, clc$optional_default_parameter, 0, 4],
{ PARAMETER 2
    [3, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$string_type], [0, clc$max_string_size, TRUE],
    '''**'''],
{ PARAMETER 2
    [[1, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$collect_template_until = 1,
      p$status = 2;

    VAR
      pvt: array [1 .. 2] of clt$parameter_value;

    VAR
      message_info_p: ^message_record,
      message_kind_p: ^ost$message_template_kind,
      template_size: 0 .. osc$max_status_message,
      until_string_p: ^clt$string_value;

    status.normal := TRUE;

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

    until_string_p := pvt [p$collect_template_until].value^.string_value;

    NEXT message_kind_p IN work_area_ptr;
    IF message_kind_p = NIL THEN
      osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
    ELSE
      message_kind_p^ := osc$brief_help;
    IFEND;

    IF store_info_status.normal THEN
      NEXT message_info_p IN work_area_ptr;
      IF message_info_p = NIL THEN
        osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
      IFEND;
    IFEND;

    collect_template (osc$brief_help, 'CREATE_BRIEF_HELP_MESSAGE', { name = } osc$null_name, until_string_p,
          template_size, status);

    IF store_info_status.normal THEN
      message_info_p^.name := osc$null_name;
      message_info_p^.code := 0; { not used for brief help message
      message_info_p^.severity := osc$mm_informative_severity; { not used for brief help message
      message_info_p^.size := template_size;
    IFEND;

    IF NOT status.normal THEN
      RESET work_area_ptr TO message_kind_p;
    IFEND;

  PROCEND clp$_create_brief_help_message;
?? TITLE := 'clp$_create_full_help_message', EJECT ??

  PROCEDURE clp$_create_full_help_message
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (ocm$cremm_crefhm) create_full_help_message, crefhm (
{   collect_template_until, ctu: string literal = '**'
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 3] of clt$pdt_parameter_name,
      parameters: array [1 .. 2] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$string_type_qualifier,
        default_value: string (4),
      recend,
      type2: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [89, 11, 30, 17, 24, 27, 728],
    clc$command, 3, 2, 0, 0, 0, 0, 2, 'OCM$CREMM_CREFHM'], [
    ['COLLECT_TEMPLATE_UNTIL         ',clc$nominal_entry, 1],
    ['CTU                            ',clc$abbreviation_entry, 1],
    ['STATUS                         ',clc$nominal_entry, 2]],
    [
{ PARAMETER 1
    [1, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 8, clc$optional_default_parameter, 0, 4],
{ PARAMETER 2
    [3, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$string_type], [0, clc$max_string_size, TRUE],
    '''**'''],
{ PARAMETER 2
    [[1, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$collect_template_until = 1,
      p$status = 2;

    VAR
      pvt: array [1 .. 2] of clt$parameter_value;

    VAR
      message_info_p: ^message_record,
      message_kind_p: ^ost$message_template_kind,
      template_size: 0 .. osc$max_status_message,
      until_string_p: ^clt$string_value;

    status.normal := TRUE;

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

    until_string_p := pvt [p$collect_template_until].value^.string_value;

    NEXT message_kind_p IN work_area_ptr;
    IF message_kind_p = NIL THEN
      osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
    ELSE
      message_kind_p^ := osc$full_help;
    IFEND;

    IF store_info_status.normal THEN
      NEXT message_info_p IN work_area_ptr;
      IF message_info_p = NIL THEN
        osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
      IFEND;
    IFEND;

    collect_template (osc$full_help, 'CREATE_FULL_HELP_MESSAGE', { name = } osc$null_name, until_string_p,
          template_size, status);

    IF store_info_status.normal THEN
      message_info_p^.name := osc$null_name;
      message_info_p^.code := 0; { not used for full help message
      message_info_p^.severity := osc$mm_informative_severity; { not used for full help message
      message_info_p^.size := template_size;
    IFEND;

    IF NOT status.normal THEN
      RESET work_area_ptr TO message_kind_p;
    IFEND;

  PROCEND clp$_create_full_help_message;
?? TITLE := 'clp$_create_application_menu', EJECT ??

  PROCEDURE clp$_create_application_menu
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (ocm$cremm_cream) create_application_menu, cream (
{   name, n: name = $required
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 3] of clt$pdt_parameter_name,
      parameters: array [1 .. 2] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$name_type_qualifier,
      recend,
      type2: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [89, 11, 30, 15, 59, 50, 759],
    clc$command, 3, 2, 1, 0, 0, 0, 2, 'OCM$CREMM_CREAM'], [
    ['N                              ',clc$abbreviation_entry, 1],
    ['NAME                           ',clc$nominal_entry, 1],
    ['STATUS                         ',clc$nominal_entry, 2]],
    [
{ PARAMETER 1
    [2, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 5, clc$required_parameter, 0, 0],
{ PARAMETER 2
    [3, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$name_type], [1, osc$max_name_size]],
{ PARAMETER 2
    [[1, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$name = 1,
      p$status = 2;

    VAR
      pvt: array [1 .. 2] of clt$parameter_value;

    VAR
      converted_integer: ost$string,
      message_kind_p: ^ost$message_template_kind,
      number_of_classes: cst$max_classes,
      number_of_items: cst$menu_item_number;

    status.normal := TRUE;

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

*IF NOT $true(osv$unix_tools_on_ve)
    NEXT message_kind_p IN work_area_ptr;
    IF message_kind_p = NIL THEN
      osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, status);
      RETURN;
    ELSE
      message_kind_p^ := osc$application_menu;
    IFEND;

  /store_info/
    BEGIN
      clp$define_application_menu (work_area_ptr, pvt [p$name].value^.name_value, message_module_name,
            number_of_classes, number_of_items, status);
      IF NOT status.normal THEN
        EXIT /store_info/;
      IFEND;

      IF (number_of_names + 1) > osc$max_status_condition_code THEN
        clp$convert_integer_to_string (osc$max_status_condition_code, 10, FALSE, converted_integer, status);
        osp$set_status_abnormal ('CL', cle$too_many_entries_for_module, converted_integer.
              value (1, converted_integer.size), status);
        osp$append_status_parameter (osc$status_parameter_delimiter, message_module_name, status);
        EXIT /store_info/;
      ELSE
        number_of_names := number_of_names + 1;
        total_number_of_classes := total_number_of_classes + number_of_classes;
        total_number_of_items := total_number_of_items + number_of_items;
        number_of_application_menus := number_of_application_menus + 1;
        RETURN;
      IFEND;
    END /store_info/;
    RESET work_area_ptr TO message_kind_p;
*IFEND

  PROCEND clp$_create_application_menu;
?? TITLE := 'clp$_create_parameter_prompt_me', EJECT ??

  PROCEDURE clp$_create_parameter_prompt_me
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (ocm$cremm_creppm) create_parameter_prompt_message, creppm (
{   name, n: name = $required
{   collect_template_until, ctu: string literal = '**'
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 5] of clt$pdt_parameter_name,
      parameters: array [1 .. 3] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$name_type_qualifier,
      recend,
      type2: record
        header: clt$type_specification_header,
        qualifier: clt$string_type_qualifier,
        default_value: string (4),
      recend,
      type3: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [89, 11, 30, 17, 25, 59, 214],
    clc$command, 5, 3, 1, 0, 0, 0, 3, 'OCM$CREMM_CREPPM'], [
    ['COLLECT_TEMPLATE_UNTIL         ',clc$nominal_entry, 2],
    ['CTU                            ',clc$abbreviation_entry, 2],
    ['N                              ',clc$abbreviation_entry, 1],
    ['NAME                           ',clc$nominal_entry, 1],
    ['STATUS                         ',clc$nominal_entry, 3]],
    [
{ PARAMETER 1
    [4, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 5, clc$required_parameter, 0, 0],
{ PARAMETER 2
    [1, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 8, clc$optional_default_parameter, 0, 4],
{ PARAMETER 3
    [5, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$name_type], [1, osc$max_name_size]],
{ PARAMETER 2
    [[1, 0, clc$string_type], [0, clc$max_string_size, TRUE],
    '''**'''],
{ PARAMETER 3
    [[1, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$name = 1,
      p$collect_template_until = 2,
      p$status = 3;

    VAR
      pvt: array [1 .. 3] of clt$parameter_value;

    VAR
      message_info_p: ^message_record,
      message_kind_p: ^ost$message_template_kind,
      template_size: 0 .. osc$max_status_message,
      until_string_p: ^clt$string_value;

    status.normal := TRUE;

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

    until_string_p := pvt [p$collect_template_until].value^.string_value;

    NEXT message_kind_p IN work_area_ptr;
    IF message_kind_p = NIL THEN
      osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
    ELSE
      message_kind_p^ := osc$parameter_prompt;
    IFEND;

    IF store_info_status.normal THEN
      NEXT message_info_p IN work_area_ptr;
      IF message_info_p = NIL THEN
        osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
      IFEND;
    IFEND;

    collect_template (osc$parameter_prompt, 'CREATE_PARAMETER_PROMPT_MESSAGE', pvt [p$name].value^.name_value,
          until_string_p, template_size, status);

    IF store_info_status.normal THEN
      message_info_p^.name := pvt [p$name].value^.name_value;
      message_info_p^.code := 0; { not used for parameter prompt message
      message_info_p^.severity := osc$mm_informative_severity; { not used for parameter prompt message
      message_info_p^.size := template_size;
    IFEND;

    IF NOT status.normal THEN
      RESET work_area_ptr TO message_kind_p;
    IFEND;

  PROCEND clp$_create_parameter_prompt_me;
?? TITLE := 'clp$_create_parameter_assist_me', EJECT ??

  PROCEDURE clp$_create_parameter_assist_me
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (ocm$cremm_crepam) create_parameter_assist_message, crepam (
{   name, n: name = $required
{   collect_template_until, ctu: string literal = '**'
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 5] of clt$pdt_parameter_name,
      parameters: array [1 .. 3] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$name_type_qualifier,
      recend,
      type2: record
        header: clt$type_specification_header,
        qualifier: clt$string_type_qualifier,
        default_value: string (4),
      recend,
      type3: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [89, 11, 30, 17, 27, 3, 102],
    clc$command, 5, 3, 1, 0, 0, 0, 3, 'OCM$CREMM_CREPAM'], [
    ['COLLECT_TEMPLATE_UNTIL         ',clc$nominal_entry, 2],
    ['CTU                            ',clc$abbreviation_entry, 2],
    ['N                              ',clc$abbreviation_entry, 1],
    ['NAME                           ',clc$nominal_entry, 1],
    ['STATUS                         ',clc$nominal_entry, 3]],
    [
{ PARAMETER 1
    [4, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 5, clc$required_parameter, 0, 0],
{ PARAMETER 2
    [1, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 8, clc$optional_default_parameter, 0, 4],
{ PARAMETER 3
    [5, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$name_type], [1, osc$max_name_size]],
{ PARAMETER 2
    [[1, 0, clc$string_type], [0, clc$max_string_size, TRUE],
    '''**'''],
{ PARAMETER 3
    [[1, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$name = 1,
      p$collect_template_until = 2,
      p$status = 3;

    VAR
      pvt: array [1 .. 3] of clt$parameter_value;

    VAR
      message_info_p: ^message_record,
      message_kind_p: ^ost$message_template_kind,
      template_size: 0 .. osc$max_status_message,
      until_string_p: ^clt$string_value;

    status.normal := TRUE;

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

    until_string_p := pvt [p$collect_template_until].value^.string_value;

    NEXT message_kind_p IN work_area_ptr;
    IF message_kind_p = NIL THEN
      osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
    ELSE
      message_kind_p^ := osc$parameter_assistance_prompt;
    IFEND;

    IF store_info_status.normal THEN
      NEXT message_info_p IN work_area_ptr;
      IF message_info_p = NIL THEN
        osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
      IFEND;
    IFEND;

    collect_template (osc$parameter_assistance_prompt, 'CREATE_PARAMETER_ASSIST_MESSAGE',
          pvt [p$name].value^.name_value, until_string_p, template_size, status);

    IF store_info_status.normal THEN
      message_info_p^.name := pvt [p$name].value^.name_value;
      message_info_p^.code := 0; { not used for parameter assist message
      message_info_p^.severity := osc$mm_informative_severity; { not used for parameter assist message
      message_info_p^.size := template_size;
    IFEND;

    IF NOT status.normal THEN
      RESET work_area_ptr TO message_kind_p;
    IFEND;

  PROCEND clp$_create_parameter_assist_me;
?? TITLE := 'clp$_create_parameter_help_mess', EJECT ??

  PROCEDURE clp$_create_parameter_help_mess
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (ocm$cremm_crephm) create_parameter_help_message, crephm (
{   name, n: name = $required
{   collect_template_until, ctu: string literal = '**'
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 5] of clt$pdt_parameter_name,
      parameters: array [1 .. 3] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$name_type_qualifier,
      recend,
      type2: record
        header: clt$type_specification_header,
        qualifier: clt$string_type_qualifier,
        default_value: string (4),
      recend,
      type3: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [89, 11, 30, 17, 28, 23, 868],
    clc$command, 5, 3, 1, 0, 0, 0, 3, 'OCM$CREMM_CREPHM'], [
    ['COLLECT_TEMPLATE_UNTIL         ',clc$nominal_entry, 2],
    ['CTU                            ',clc$abbreviation_entry, 2],
    ['N                              ',clc$abbreviation_entry, 1],
    ['NAME                           ',clc$nominal_entry, 1],
    ['STATUS                         ',clc$nominal_entry, 3]],
    [
{ PARAMETER 1
    [4, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 5, clc$required_parameter, 0, 0],
{ PARAMETER 2
    [1, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 8, clc$optional_default_parameter, 0, 4],
{ PARAMETER 3
    [5, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$name_type], [1, osc$max_name_size]],
{ PARAMETER 2
    [[1, 0, clc$string_type], [0, clc$max_string_size, TRUE],
    '''**'''],
{ PARAMETER 3
    [[1, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$name = 1,
      p$collect_template_until = 2,
      p$status = 3;

    VAR
      pvt: array [1 .. 3] of clt$parameter_value;

    VAR
      message_info_p: ^message_record,
      message_kind_p: ^ost$message_template_kind,
      template_size: 0 .. osc$max_status_message,
      until_string_p: ^clt$string_value;

    status.normal := TRUE;

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

    until_string_p := pvt [p$collect_template_until].value^.string_value;

    NEXT message_kind_p IN work_area_ptr;
    IF message_kind_p = NIL THEN
      osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
    ELSE
      message_kind_p^ := osc$parameter_help;
    IFEND;

    IF store_info_status.normal THEN
      NEXT message_info_p IN work_area_ptr;
      IF message_info_p = NIL THEN
        osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, store_info_status);
      IFEND;
    IFEND;

    collect_template (osc$parameter_help, 'CREATE_PARAMETER_HELP_MESSAGE', pvt [p$name].value^.name_value,
          until_string_p, template_size, status);

    IF store_info_status.normal THEN
      message_info_p^.name := pvt [p$name].value^.name_value;
      message_info_p^.code := 0; { not used for parameter help message
      message_info_p^.severity := osc$mm_informative_severity; { not used for parameter help message
      message_info_p^.size := template_size;
    IFEND;

    IF NOT status.normal THEN
      RESET work_area_ptr TO message_kind_p;
    IFEND;

  PROCEND clp$_create_parameter_help_mess;
?? TITLE := 'clp$_quit', EJECT ??

  PROCEDURE clp$_quit
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (ocm$cremm_endmm) end_message_module, endmm (
{   create_module, cm: boolean = YES
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 3] of clt$pdt_parameter_name,
      parameters: array [1 .. 2] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        default_value: string (3),
      recend,
      type2: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [89, 11, 30, 16, 12, 49, 385],
    clc$command, 3, 2, 0, 0, 0, 0, 2, 'OCM$CREMM_ENDMM'], [
    ['CM                             ',clc$abbreviation_entry, 1],
    ['CREATE_MODULE                  ',clc$nominal_entry, 1],
    ['STATUS                         ',clc$nominal_entry, 2]],
    [
{ PARAMETER 1
    [2, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_default_parameter, 0, 3],
{ PARAMETER 2
    [3, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$boolean_type],
    'YES'],
{ PARAMETER 2
    [[1, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$create_module = 1,
      p$status = 2;

    VAR
      pvt: array [1 .. 2] of clt$parameter_value;

    VAR
      value: clt$value;

    status.normal := TRUE;

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

    create_module := pvt [p$create_module].value^.boolean_value.value;

    clp$end_include (utility_name, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

  PROCEND clp$_quit;
?? TITLE := 'clp$define_message_module', EJECT ??

  PROCEDURE [XDCL] clp$define_message_module
*IF NOT $true(osv$unix_tools_on_ve)
    (    module_name: pmt$program_name;
         natural_language: ost$natural_language;
         online_manual_name: ost$online_manual_name;
         work_area: ^SEQ ( * );
     VAR message_module: ^ost$message_template_module;
     VAR status: ost$status);
*ELSE
    (VAR status: ost$status);
*IFEND

?? NEWTITLE := 'sort_condition_codes', EJECT ??

    PROCEDURE sort_condition_codes
      (    codes: ^ost$mtm_condition_codes);

      VAR
        converted_integer: ost$string,
        code_string: ost$string,
        current: integer,
        gap: integer,
        message_status: ost$status,
        ignore_status: ost$status,
        index: ost$message_template_index,
        start: ost$message_template_index,
        last_duplicate: integer,
        swap: ost$mtm_condition_code;

      gap := UPPERBOUND (codes^) + 1;
      WHILE gap > 1 DO
        gap := 2 * (gap DIV 4) + 1;
        FOR start := 0 TO UPPERBOUND (codes^) - gap DO
          current := start;
          WHILE (current > LOWERBOUND (codes^) - 1) AND (codes^ [current].code > codes^ [current + gap].
                code) DO
            swap := codes^ [current];
            codes^ [current] := codes^ [current + gap];
            codes^ [current + gap] := swap;
            current := current - gap;
          WHILEND;
        FOREND;
      WHILEND;

      last_duplicate := -1;

    /find_duplicates/
      FOR index := 1 TO UPPERBOUND (codes^) DO
        IF codes^ [index].code = codes^ [index - 1].code THEN
          IF codes^ [index].code <> last_duplicate THEN
            osp$get_status_condition_string (codes^ [index].code, code_string, ignore_status);
            osp$set_status_abnormal ('CL', cle$duplicate_condition_codes, code_string.
                  value (1, code_string.size), message_status);
            osp$append_status_parameter (osc$status_parameter_delimiter, message_module_name, message_status);
*IF NOT $true(osv$unix_tools_on_ve)
            ocp$generate_message (message_status);
*IFEND
            module_has_errors := TRUE;
            last_duplicate := codes^ [index].code;
          IFEND;
        IFEND;
      FOREND /find_duplicates/;

    PROCEND sort_condition_codes;
?? TITLE := 'sort_condition_names', EJECT ??

    PROCEDURE sort_condition_names
      (    names: ^ost$mtm_condition_names;
           codes: ^ost$mtm_condition_codes);

      VAR
        message_kinds: [READ] array [ost$message_template_kind] of record
          size: 21 .. 35,
          value: string (35),
        recend := [[21, 'CREATE_STATUS_MESSAGE'], [25, 'CREATE_BRIEF_HELP_MESSAGE'], [24,
              'CREATE_FULL_HELP_MESSAGE'], [23, 'CREATE_APPLICATION_MENU'], [31,
              'CREATE_PARAMETER_PROMPT_MESSAGE'], [35, 'CREATE_PARAMETER_ASSISTANCE_MESSAGE'], [29,
              'CREATE_PARAMETER_HELP_MESSAGE']];

      VAR
        current: integer,
        gap: integer,
        index: ost$message_template_index,
        message_status: ost$status,
        start: ost$message_template_index,
        last_duplicate: ost$mtm_condition_name,
        swap: ost$mtm_condition_name;

      gap := UPPERBOUND (names^) + 1;
      WHILE gap > 1 DO
        gap := 2 * (gap DIV 4) + 1;
        FOR start := 0 TO UPPERBOUND (names^) - gap DO
          current := start;
          WHILE (current > LOWERBOUND (names^) - 1) AND (names^ [current].name >= names^ [current + gap].
                name) DO
            IF (names^ [current].name > names^ [current + gap].name) OR
                  (names^ [current].kind > names^ [current + gap].kind) THEN
              swap := names^ [current];
              names^ [current] := names^ [current + gap];
              names^ [current + gap] := swap;
              IF codes <> NIL THEN
                FOR index := 0 TO UPPERBOUND (codes^) DO
                  IF codes^ [index].code = names^ [current].code THEN
                    codes^ [index].name_index := current;
                  ELSEIF codes^ [index].code = names^ [current + gap].code THEN
                    codes^ [index].name_index := current + gap;
                  IFEND;
                FOREND;
              IFEND;
            IFEND;
            current := current - gap;
          WHILEND;
        FOREND;
      WHILEND;

      last_duplicate.name := '?';

    /find_duplicates/
      FOR index := 1 TO UPPERBOUND (names^) DO
        IF (names^ [index].name = names^ [index - 1].name) AND (names^ [index].kind = names^ [index - 1].kind)
              THEN
          IF (names^ [index].name <> last_duplicate.name) OR (names^ [index].kind <> last_duplicate.kind) THEN

          /form_error_message/
            BEGIN
              CASE names^ [index].kind OF
              = osc$status_message, osc$application_menu, osc$parameter_prompt,
                    osc$parameter_assistance_prompt, osc$parameter_help =
                osp$set_status_abnormal ('CL', cle$duplicate_names, message_kinds [names^ [index].kind].value,
                      message_status);
              = osc$brief_help, osc$full_help =
                osp$set_status_abnormal ('CL', cle$duplicate_help_messages,
                      message_kinds [names^ [index].kind].value, message_status);
                EXIT /form_error_message/;
              ELSE
                osp$set_status_abnormal ('CL', cle$duplicate_names, 'UNKNOWN_MESSAGE_KIND', message_status);
              CASEND;
              osp$append_status_parameter (osc$status_parameter_delimiter, names^ [index].name,
                    message_status);
            END /form_error_message/;
            osp$append_status_parameter (osc$status_parameter_delimiter, message_module_name, message_status);
*IF NOT $true(osv$unix_tools_on_ve)
            ocp$generate_message (message_status);
*IFEND
            module_has_errors := TRUE;
            last_duplicate := names^ [index];
          IFEND;
        IFEND;
      FOREND /find_duplicates/;

    PROCEND sort_condition_names;
?? TITLE := 'generate_message_module', EJECT ??

    PROCEDURE generate_message_module
      (VAR status: ost$status);

      VAR
        codes_pointer: ^ost$mtm_condition_codes,
        names_pointer: ^ost$mtm_condition_names,
        template_pointer: ^ost$message_template,
        index: ost$message_template_index,
        j: ost$message_template_index,
        code_index: ost$message_template_index,
        local_status: ost$status,
        menu_classes: cst$menu_class,
        menu_header: ^ost$mtm_menu_header,
        menu_items: cst$menu_list,
        retrieved_classes: ^array [1 .. * ] of record
          name: cst$class_name,
          number_of_items: 0 .. csc$max_items_per_class,
        recend,
        retrieved_items: cst$menu_list,
        retrieved_kind: ^ost$message_template_kind,
        retrieved_menu_info: ^menu_record,
        retrieved_message_info: ^message_record,
        retrieved_template: ^ost$message_template,
        header: ost$mtm_header;

      status.normal := TRUE;
      code_index := 0;

      IF number_of_names = 0 THEN
        osp$set_status_abnormal ('CL', cle$no_module_created, message_module_name, status);
        RETURN;
      IFEND;

      header.version := llc$object_library_version;
      header.language := natural_language;
      header.online_manual_name := online_manual_name;
      header.number_of_codes := number_of_codes;
      header.number_of_names := number_of_names;

      module_size := #SIZE (ost$mtm_header) + number_of_codes *
            #SIZE (ost$mtm_condition_code) + number_of_names *
            #SIZE (ost$mtm_condition_name) + total_template_size + number_of_application_menus *
            #SIZE (ost$mtm_menu_header) + total_number_of_classes *
            #SIZE (cst$class_name) + total_number_of_items * #SIZE (cst$menu_item);
      NEXT result_module: [[REP module_size OF cell]] IN work_area_ptr;
      IF result_module = NIL THEN
        osp$set_status_abnormal ('CL', cle$module_too_large, message_module_name, status);
        RETURN;
      IFEND;
      RESET result_module;
      RESET work_area_ptr;
      NEXT header_pointer IN result_module;
      header_pointer^ := header;

      IF number_of_codes > 0 THEN
        NEXT codes_pointer: [0 .. number_of_codes - 1] IN result_module;
      ELSE
        codes_pointer := NIL;
      IFEND;

      NEXT names_pointer: [0 .. number_of_names - 1] IN result_module;

      FOR index := 0 TO number_of_names - 1 DO
        NEXT retrieved_kind IN work_area_ptr;
        names_pointer^ [index].kind := retrieved_kind^;
        IF retrieved_kind^ = osc$application_menu THEN
          NEXT retrieved_menu_info IN work_area_ptr;
          NEXT menu_header IN result_module;
          menu_header^.number_of_classes := retrieved_menu_info^.number_of_classes;
          menu_header^.number_of_menu_items := retrieved_menu_info^.number_of_items;
          NEXT retrieved_classes: [1 .. csc$max_classes] IN work_area_ptr;
          NEXT retrieved_items: [1 .. retrieved_menu_info^.number_of_items] IN work_area_ptr;
          NEXT menu_classes: [1 .. retrieved_menu_info^.number_of_classes] IN result_module;
          NEXT menu_items: [1 .. retrieved_menu_info^.number_of_items] IN result_module;
          FOR j := 1 TO retrieved_menu_info^.number_of_classes DO
            menu_classes^ [j] := retrieved_classes^ [j].name;
          FOREND;
          menu_items^ := retrieved_items^;
          names_pointer^ [index].name := retrieved_menu_info^.name;
          names_pointer^ [index].menu_header := #REL (menu_header, result_module^);
        ELSE
          NEXT retrieved_message_info IN work_area_ptr;
          NEXT retrieved_template: [retrieved_message_info^.size] IN work_area_ptr;
          NEXT template_pointer: [retrieved_message_info^.size] IN result_module;
          IF names_pointer^ [index].kind = osc$status_message THEN
            codes_pointer^ [code_index].code := retrieved_message_info^.code;
            codes_pointer^ [code_index].name_index := index;
            code_index := code_index + 1;
          IFEND;
          names_pointer^ [index].name := retrieved_message_info^.name;
          names_pointer^ [index].template := #REL (template_pointer, result_module^);
          IF names_pointer^ [index].kind = osc$status_message THEN
            names_pointer^ [index].code := retrieved_message_info^.code;
            names_pointer^ [index].severity := retrieved_message_info^.severity;
          IFEND;
          template_pointer^ := retrieved_template^;
        IFEND;
      FOREND;

      IF number_of_codes > 0 THEN
        sort_condition_codes (codes_pointer);
      IFEND;
      sort_condition_names (names_pointer, codes_pointer);

    PROCEND generate_message_module;
?? OLDTITLE, EJECT ??

{ table command_table sn=oss$job_paged_literal
{ command (create_status_message,cresm) p=clp$_create_status_message cm=local
{ command (create_brief_help_message,crebhm) ..
{   p=clp$_create_brief_help_message cm=local
{ command (create_full_help_message,crefhm) ..
{   p=clp$_create_full_help_message cm=local
{ command (create_application_menu,cream) p=clp$_create_application_menu ..
{   cm=local
{ command (create_parameter_prompt_message,creppm) ..
{   p=clp$_create_parameter_prompt_me cm=local
{ command (create_parameter_assist_message,crepam) ..
{   p=clp$_create_parameter_assist_me cm=local
{ command (create_parameter_help_message,crephm) ..
{   p=clp$_create_parameter_help_mess cm=local
{ command (end_message_module,quit,qui,endmm) p=clp$_quit cm=local
{ tablend

?? PUSH (LISTEXT := ON) ??

VAR
  command_table: [STATIC, READ, oss$job_paged_literal]
      ^clt$command_table := ^command_table_entries,

  command_table_entries: [STATIC, READ, oss$job_paged_literal] array [1
      .. 18] of clt$command_table_entry := [
  {} ['CREAM                          ', clc$abbreviation_entry,
        clc$normal_usage_entry, 4, clc$automatically_log, clc$linked_call,
        ^clp$_create_application_menu],
  {} ['CREATE_APPLICATION_MENU        ', clc$nominal_entry,
        clc$normal_usage_entry, 4, clc$automatically_log, clc$linked_call,
        ^clp$_create_application_menu],
  {} ['CREATE_BRIEF_HELP_MESSAGE      ', clc$nominal_entry,
        clc$normal_usage_entry, 2, clc$automatically_log, clc$linked_call,
        ^clp$_create_brief_help_message],
  {} ['CREATE_FULL_HELP_MESSAGE       ', clc$nominal_entry,
        clc$normal_usage_entry, 3, clc$automatically_log, clc$linked_call,
        ^clp$_create_full_help_message],
  {} ['CREATE_PARAMETER_ASSIST_MESSAGE', clc$nominal_entry,
        clc$normal_usage_entry, 6, clc$automatically_log, clc$linked_call,
        ^clp$_create_parameter_assist_me],
  {} ['CREATE_PARAMETER_HELP_MESSAGE  ', clc$nominal_entry,
        clc$normal_usage_entry, 7, clc$automatically_log, clc$linked_call,
        ^clp$_create_parameter_help_mess],
  {} ['CREATE_PARAMETER_PROMPT_MESSAGE', clc$nominal_entry,
        clc$normal_usage_entry, 5, clc$automatically_log, clc$linked_call,
        ^clp$_create_parameter_prompt_me],
  {} ['CREATE_STATUS_MESSAGE          ', clc$nominal_entry,
        clc$normal_usage_entry, 1, clc$automatically_log, clc$linked_call,
        ^clp$_create_status_message],
  {} ['CREBHM                         ', clc$abbreviation_entry,
        clc$normal_usage_entry, 2, clc$automatically_log, clc$linked_call,
        ^clp$_create_brief_help_message],
  {} ['CREFHM                         ', clc$abbreviation_entry,
        clc$normal_usage_entry, 3, clc$automatically_log, clc$linked_call,
        ^clp$_create_full_help_message],
  {} ['CREPAM                         ', clc$abbreviation_entry,
        clc$normal_usage_entry, 6, clc$automatically_log, clc$linked_call,
        ^clp$_create_parameter_assist_me],
  {} ['CREPHM                         ', clc$abbreviation_entry,
        clc$normal_usage_entry, 7, clc$automatically_log, clc$linked_call,
        ^clp$_create_parameter_help_mess],
  {} ['CREPPM                         ', clc$abbreviation_entry,
        clc$normal_usage_entry, 5, clc$automatically_log, clc$linked_call,
        ^clp$_create_parameter_prompt_me],
  {} ['CRESM                          ', clc$abbreviation_entry,
        clc$normal_usage_entry, 1, clc$automatically_log, clc$linked_call,
        ^clp$_create_status_message],
  {} ['ENDMM                          ', clc$abbreviation_entry,
        clc$normal_usage_entry, 8, clc$automatically_log, clc$linked_call,
        ^clp$_quit],
  {} ['END_MESSAGE_MODULE             ', clc$nominal_entry,
        clc$normal_usage_entry, 8, clc$automatically_log, clc$linked_call,
        ^clp$_quit],
  {} ['QUI                            ', clc$alias_entry,
        clc$normal_usage_entry, 8, clc$automatically_log, clc$linked_call,
        ^clp$_quit],
  {} ['QUIT                           ', clc$alias_entry,
        clc$normal_usage_entry, 8, clc$automatically_log, clc$linked_call,
        ^clp$_quit]];

?? POP ??

    VAR
*IF $true(osv$unix_tools_on_ve)
      module_name: pmt$program_name,
      natural_language: ost$natural_language,
      online_manual_name: ost$online_manual_name,
      work_area: ^SEQ ( * ),
      message_module: ^ost$message_template_module,
*IFEND
      header_pointer: ^ost$mtm_header,
      module_size: ost$segment_length,
      result_module: ^ost$message_template_module,
      seq_position: ost$segment_length,
      utility_attributes: array [1 .. 3] of clt$utility_attribute;

*IF $true(osv$unix_tools_on_ve)
    VAR
      attachment_options: array [1 .. 3] of fst$attachment_option,
      default_creation_attributes: array [1 .. 2] of fst$file_cycle_attribute,
      file_id: amt$file_identifier,
      validation_attributes: array [1 .. 4] of fst$file_cycle_attribute;
*IFEND


    status.normal := TRUE;
    store_info_status.normal := TRUE;
*IF $true(osv$unix_tools_on_ve)
    module_name := osc$null_name;
    natural_language := osc$us_english;
    online_manual_name := osc$null_name;
    ALLOCATE work_area: [[REP 1000000(16) OF cell]];
    RESET work_area;
*IFEND

    IF in_create_message_module THEN
      osp$set_status_abnormal ('CL', cle$no_nested_message_modules, message_module_name, status);
      RETURN;
    ELSE
      in_create_message_module := TRUE;
    IFEND;

    number_of_application_menus := 0;
    number_of_codes := 0;
    number_of_names := 0;
    total_number_of_classes := 0;
    total_number_of_items := 0;
    total_template_size := 0;
    module_has_errors := FALSE;
    work_area_ptr := work_area;
    RESET work_area_ptr;
    message_module := NIL;
    message_module_name := module_name;

    utility_attributes [1].key := clc$utility_command_search_mode;
    utility_attributes [1].command_search_mode := clc$global_command_search;
    utility_attributes [2].key := clc$utility_command_table;
    utility_attributes [2].command_table := command_table;
    utility_attributes [3].key := clc$utility_prompt;
    utility_attributes [3].prompt.value := prompt_string;
    utility_attributes [3].prompt.size := prompt_string_size;

  /create_message_module/
    BEGIN

      clp$begin_utility (utility_name, utility_attributes, status);
      IF NOT status.normal THEN
        EXIT /create_message_module/;
      IFEND;

      clp$include_file (clc$current_command_input, prompt_string, utility_name, status);
      IF NOT status.normal THEN
        EXIT /create_message_module/;
      ELSEIF status.normal AND (NOT store_info_status.normal) THEN
        status := store_info_status;
        EXIT /create_message_module/;
      IFEND;

      clp$end_utility (utility_name, status);
      IF NOT status.normal THEN
        EXIT /create_message_module/;
      IFEND;

      IF create_module THEN
        generate_message_module (status);
        IF NOT status.normal THEN
          EXIT /create_message_module/;
        IFEND;

        RESET result_module TO header_pointer;
        NEXT message_module: [[REP module_size OF cell]] IN result_module;
        RESET message_module;

        IF module_has_errors THEN
          osp$set_status_abnormal ('CL', cle$errors_in_module, message_module_name, status);
          EXIT /create_message_module/;
        IFEND;
      IFEND;
    END /create_message_module/;

    in_create_message_module := FALSE;

*IF $true(osv$unix_tools_on_ve)
    attachment_options [1].selector := fsc$access_and_share_modes;
    attachment_options [1].access_modes.selector := fsc$specific_access_modes;
    attachment_options [1].access_modes.value := $fst$file_access_options [fsc$append, fsc$shorten];
    attachment_options [1].share_modes.selector := fsc$specific_share_modes;
    attachment_options [1].share_modes.value := $fst$file_access_options [];
    attachment_options [2].selector := fsc$access_and_share_modes;
    attachment_options [2].access_modes.selector := fsc$specific_access_modes;
    attachment_options [2].access_modes.value := $fst$file_access_options [fsc$append];
    attachment_options [2].share_modes.selector := fsc$specific_share_modes;
    attachment_options [2].share_modes.value := $fst$file_access_options [];
    attachment_options [3].selector := fsc$open_share_modes;
    attachment_options [3].open_share_modes := -$fst$file_access_options [];
    validation_attributes [1].selector := fsc$file_contents_and_processor;
    validation_attributes [1].file_contents := fsc$legible_data;
    validation_attributes [1].file_processor := osc$null_name;
    validation_attributes [2].selector := fsc$file_contents_and_processor;
    validation_attributes [2].file_contents := amc$legible;
    validation_attributes [2].file_processor := osc$null_name;
    validation_attributes [3].selector := fsc$file_contents_and_processor;
    validation_attributes [3].file_contents := fsc$data;
    validation_attributes [3].file_processor := osc$null_name;
    validation_attributes [4].selector := fsc$file_contents_and_processor;
    validation_attributes [4].file_contents := fsc$unknown_contents;
    validation_attributes [4].file_processor := osc$null_name;
    default_creation_attributes [1].selector := fsc$file_contents_and_processor;
    default_creation_attributes [1].file_contents := fsc$legible_data;
    default_creation_attributes [1].file_processor := osc$null_name;
    default_creation_attributes [2].selector := fsc$page_format;
    default_creation_attributes [2].page_format := amc$untitled_form;
    fsp$open_file ('$wc.message_template_module', amc$record, ^attachment_options,
          ^default_creation_attributes, NIL, ^validation_attributes, NIL, file_id, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;


    clp$extract_message_module (file_id, module_name, message_module, status);

    fsp$close_file (file_id, status);
*IFEND

  PROCEND clp$define_message_module;

MODEND clm$define_message_module;
