?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Object Code Management: Change Function Description' ??
MODULE ocm$change_function_description;

{
{ PURPOSE:
{   To change a function description on an object library.
{

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clt$function_name
*copyc clt$parameter_list
*copyc llt$function_description
*copyc oce$library_generator_errors
*copyc oct$new_library_module_list
*copyc ost$status
?? POP ??
*copyc avp$get_capability
*copyc clp$evaluate_parameters
*copyc i#current_sequence_position
*copyc ocp$close_all_open_files
*copyc ocp$initialize_olg_working_heap
*copyc ocp$search_nlm_tree
*copyc osp$set_status_abnormal
*copyc osp$set_status_condition
*copyc pmp$continue_to_cause
*copyc pmp$disestablish_cond_handler
*copyc pmp$establish_condition_handler
*copyc pmp$get_date
*copyc pmp$get_time
*copyc ocv$olg_scratch_seq
*copyc ocv$olg_working_heap
*copyc ocv$open_file_list
?? OLDTITLE ??
?? NEWTITLE := '[XDCL] ocp$_change_function_descriptio', EJECT ??

  PROCEDURE [XDCL] ocp$_change_function_descriptio
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (ocm$creol_chafd) change_function_description,
{      change_function_descriptions, chafd (
{   name, names, n: any of
{       data_name
{       list of data_name
{     anyend = $required
{   starting_procedure, sp: (BY_NAME) program_name = $optional
{   library, l: (BY_NAME) any of
{       key
{         $unspecified, osf$current_library
{       keyend
{       file
{       string
{     anyend = $optional
{   availability, a: (BY_NAME) key
{       (normal_usage, nu)
{       (advanced_usage, au)
{       (hidden, h)
{     keyend = $optional
{   scope, s: (BY_NAME) key
{       (xdcl, x)
{       (gate, g)
{       (local, l)
{     keyend = $optional
{   status)

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

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 12] of clt$pdt_parameter_name,
      parameters: array [1 .. 6] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$union_type_qualifier,
        type_size_1: clt$type_specification_size,
        element_type_spec_1: record
          header: clt$type_specification_header,
        recend,
        type_size_2: clt$type_specification_size,
        element_type_spec_2: record
          header: clt$type_specification_header,
          qualifier: clt$list_type_qualifier,
          element_type_spec: record
            header: clt$type_specification_header,
          recend,
        recend,
      recend,
      type2: record
        header: clt$type_specification_header,
      recend,
      type3: record
        header: clt$type_specification_header,
        qualifier: clt$union_type_qualifier,
        type_size_1: clt$type_specification_size,
        element_type_spec_1: record
          header: clt$type_specification_header,
          qualifier: clt$keyword_type_qualifier,
          keyword_specs: array [1 .. 2] of clt$keyword_specification,
        recend,
        type_size_2: clt$type_specification_size,
        element_type_spec_2: record
          header: clt$type_specification_header,
        recend,
        type_size_3: clt$type_specification_size,
        element_type_spec_3: record
          header: clt$type_specification_header,
          qualifier: clt$string_type_qualifier,
        recend,
      recend,
      type4: record
        header: clt$type_specification_header,
        qualifier: clt$keyword_type_qualifier,
        keyword_specs: array [1 .. 6] of clt$keyword_specification,
      recend,
      type5: record
        header: clt$type_specification_header,
        qualifier: clt$keyword_type_qualifier,
        keyword_specs: array [1 .. 6] of clt$keyword_specification,
      recend,
      type6: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [89, 9, 12, 15, 22, 28, 894],
    clc$command, 12, 6, 1, 0, 0, 0, 6, 'OCM$CREOL_CHAFD'], [
    ['A                              ',clc$abbreviation_entry, 4],
    ['AVAILABILITY                   ',clc$nominal_entry, 4],
    ['L                              ',clc$abbreviation_entry, 3],
    ['LIBRARY                        ',clc$nominal_entry, 3],
    ['N                              ',clc$abbreviation_entry, 1],
    ['NAME                           ',clc$nominal_entry, 1],
    ['NAMES                          ',clc$alias_entry, 1],
    ['S                              ',clc$abbreviation_entry, 5],
    ['SCOPE                          ',clc$nominal_entry, 5],
    ['SP                             ',clc$abbreviation_entry, 2],
    ['STARTING_PROCEDURE             ',clc$nominal_entry, 2],
    ['STATUS                         ',clc$nominal_entry, 6]],
    [
{ PARAMETER 1
    [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, 42, clc$required_parameter, 0, 0],
{ PARAMETER 2
    [11, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_parameter, 0, 0],
{ PARAMETER 3
    [4, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 116, clc$optional_parameter, 0, 0],
{ PARAMETER 4
    [2, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 229, clc$optional_parameter, 0, 0],
{ PARAMETER 5
    [9, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 229, clc$optional_parameter, 0, 0],
{ PARAMETER 6
    [12, 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$union_type], [[clc$data_name_type,
    clc$list_type],
    FALSE, 2],
    3, [[1, 0, clc$data_name_type]],
    19, [[1, 0, clc$list_type], [3, 1, clc$max_list_size, FALSE],
        [[1, 0, clc$data_name_type]]
      ]
    ],
{ PARAMETER 2
    [[1, 0, clc$program_name_type]],
{ PARAMETER 3
    [[1, 0, clc$union_type], [[clc$file_type, clc$keyword_type,
    clc$string_type],
    FALSE, 3],
    81, [[1, 0, clc$keyword_type], [2], [
      ['$UNSPECIFIED                   ', clc$nominal_entry,
  clc$normal_usage_entry, 1],
      ['OSF$CURRENT_LIBRARY            ', clc$nominal_entry,
  clc$normal_usage_entry, 2]]
      ],
    3, [[1, 0, clc$file_type]],
    8, [[1, 0, clc$string_type], [0, clc$max_string_size, FALSE]]
    ],
{ PARAMETER 4
    [[1, 0, clc$keyword_type], [6], [
    ['ADVANCED_USAGE                 ', clc$nominal_entry,
  clc$normal_usage_entry, 2],
    ['AU                             ', clc$abbreviation_entry,
  clc$normal_usage_entry, 2],
    ['H                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 3],
    ['HIDDEN                         ', clc$nominal_entry,
  clc$normal_usage_entry, 3],
    ['NORMAL_USAGE                   ', clc$nominal_entry,
  clc$normal_usage_entry, 1],
    ['NU                             ', clc$abbreviation_entry,
  clc$normal_usage_entry, 1]]
    ],
{ PARAMETER 5
    [[1, 0, clc$keyword_type], [6], [
    ['G                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 2],
    ['GATE                           ', clc$nominal_entry,
  clc$normal_usage_entry, 2],
    ['L                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 3],
    ['LOCAL                          ', clc$nominal_entry,
  clc$normal_usage_entry, 3],
    ['X                              ', clc$abbreviation_entry,
  clc$normal_usage_entry, 1],
    ['XDCL                           ', clc$nominal_entry,
  clc$normal_usage_entry, 1]]
    ],
{ PARAMETER 6
    [[1, 0, clc$status_type]]];

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

    CONST
      p$name = 1,
      p$starting_procedure = 2,
      p$library = 3,
      p$availability = 4,
      p$scope = 5,
      p$status = 6;

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

    CONST
      unspecified = '$UNSPECIFIED';

    VAR
      date: ost$date,
      ignore_status: ost$status,
      member: ^SEQ ( * ),
      member_size: ost$segment_length,
      module_description: ^oct$module_description,
      module_does_exist: boolean,
      name: clt$function_name,
      name_node: ^clt$data_value,
      new_alias_list: ^pmt$module_list,
      new_function_desc_contents: ^llt$function_desc_contents,
      new_function_description_header: ^llt$library_member_header,
      new_library_parameter: ^fst$file_reference,
      new_library_path: ^fst$file_reference,
      nlm: ^oct$new_library_module_list,
      old_alias_list: ^pmt$module_list,
      old_function_desc_contents: ^llt$function_desc_contents,
      old_function_description_header: ^llt$library_member_header,
      old_library_path: ^fst$file_reference,
      old_member: ^SEQ ( * ),
      old_seq: ^SEQ ( * ),
      sequence: ^SEQ ( * ),
      size: ost$segment_length,
      time: ost$time;

    VAR
      established_conditions: pmt$condition,
      established_descriptor: pmt$established_handler;

?? NEWTITLE := 'condition_handler', EJECT ??

{ PURPOSE:
{   The purpose of this procedure is to handle the terminate break and
{   block exit conditions.

    PROCEDURE condition_handler
      (    condition: pmt$condition;
           condition_descriptor: ^pmt$condition_information;
           stack_frame_save_area_p: ^ost$stack_frame_save_area;
       VAR handler_status: ost$status);


      IF (condition.selector = ifc$interactive_condition) AND
            (condition.interactive_condition = ifc$terminate_break) THEN

{ Ignore the condition.

        RETURN;
      ELSEIF condition.selector = pmc$block_exit_processing THEN
        ocp$close_all_open_files (ocv$open_file_list);
        ocp$initialize_olg_working_heap;
        RESET ocv$olg_scratch_seq;
      ELSE
        pmp$continue_to_cause (pmc$execute_standard_procedure, handler_status);
      IFEND;

    PROCEND condition_handler;
?? OLDTITLE, EJECT ??

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

    established_conditions.selector := pmc$condition_combination;
    established_conditions.combination := $pmt$condition_combination
          [ifc$interactive_condition, pmc$block_exit_processing];
    pmp$establish_condition_handler (established_conditions, ^condition_handler, ^established_descriptor,
          status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

  /protect/
    BEGIN

      IF pvt [p$name].value^.kind = clc$list THEN
        name_node := pvt [p$name].value;
      ELSE
        PUSH name_node;
        name_node^.kind := clc$list;
        name_node^.element_value := pvt [p$name].value;
        name_node^.link := NIL;
        name_node^.generated_via_list_rest := FALSE;
      IFEND;
      WHILE (name_node <> NIL) DO
        name := name_node^.element_value^.data_name_value;

        ocp$search_nlm_tree (name, nlm, module_does_exist);
        IF NOT module_does_exist THEN
          osp$set_status_abnormal ('OC', oce$w_module_not_found, name, status);
          EXIT /protect/;
        ELSEIF nlm^.description^.kind <> occ$function_description THEN
          osp$set_status_abnormal ('OC', oce$e_module_not_a_func_desc, name, status);
          EXIT /protect/;
        IFEND;
        old_function_description_header := nlm^.description^.function_description_header;

        old_seq := nlm^.description^.file;
        RESET ocv$olg_scratch_seq;


        NEXT new_function_description_header IN ocv$olg_scratch_seq;
        IF new_function_description_header = NIL THEN
          osp$set_status_condition (oce$e_internal_olg_seg_overflow, status);
          RETURN;
        IFEND;

        new_function_description_header^ := old_function_description_header^;

        IF new_function_description_header^.number_of_aliases <> 0 THEN
          old_alias_list := #PTR (old_function_description_header^.aliases, old_seq^);
          NEXT new_alias_list: [1 .. new_function_description_header^.number_of_aliases] IN
                ocv$olg_scratch_seq;
          IF new_alias_list = NIL THEN
            osp$set_status_abnormal ('OC', oce$e_premature_eof_in_module, name, status);
            EXIT /protect/;
          IFEND;
          new_alias_list^ := old_alias_list^;
        IFEND;

        old_member := #PTR (old_function_description_header^.member, old_seq^);
        RESET old_member;
        NEXT old_function_desc_contents IN old_member;
        IF old_function_desc_contents = NIL THEN
          osp$set_status_condition (oce$e_internal_olg_seg_overflow, status);
          RETURN;
        IFEND;
        NEXT new_function_desc_contents IN ocv$olg_scratch_seq;
        IF new_function_desc_contents = NIL THEN
          osp$set_status_condition (oce$e_internal_olg_seg_overflow, status);
          RETURN;
        IFEND;
        new_function_desc_contents^ := old_function_desc_contents^;

        IF pvt [p$starting_procedure].specified THEN
          new_function_desc_contents^.starting_procedure := pvt [p$starting_procedure].value^.
                program_name_value;
        IFEND;

        NEXT old_library_path: [old_function_desc_contents^.library_path_size] IN old_member;
        IF old_library_path = NIL THEN
          osp$set_status_condition (oce$e_internal_olg_seg_overflow, status);
          RETURN;
        IFEND;
        IF pvt [p$library].specified THEN
          CASE pvt [p$library].value^.kind OF
          = clc$keyword =
            IF pvt [p$library].value^.keyword_value = unspecified THEN
              PUSH new_library_parameter: [0];
            ELSE {OSF$CURRENT_LIBRARY}
              new_library_parameter := ^pvt [p$library].value^.keyword_value;
            IFEND;
          = clc$file =
            new_library_parameter := pvt [p$library].value^.file_value;
          ELSE {clc$string}
            new_library_parameter := pvt [p$library].value^.string_value;
          CASEND;
          IF STRLENGTH (new_library_parameter^) >= fsc$max_path_size THEN
            new_function_desc_contents^.library_path_size := fsc$max_path_size;
          ELSE
            new_function_desc_contents^.library_path_size := STRLENGTH (new_library_parameter^);
          IFEND;
          NEXT new_library_path: [new_function_desc_contents^.library_path_size] IN ocv$olg_scratch_seq;
          IF new_library_path = NIL THEN
            osp$set_status_condition (oce$e_internal_olg_seg_overflow, status);
            RETURN;
          IFEND;
          new_library_path^ := new_library_parameter^;
        ELSEIF old_function_desc_contents^.library_path_size > 0 THEN
          NEXT new_library_path: [old_function_desc_contents^.library_path_size] IN ocv$olg_scratch_seq;
          IF new_library_path = NIL THEN
            osp$set_status_condition (oce$e_internal_olg_seg_overflow, status);
            RETURN;
          IFEND;
          new_library_path^ := old_library_path^;
        IFEND;

        IF pvt [p$availability].specified THEN
          IF pvt [p$availability].value^.keyword_value = 'NORMAL_USAGE' THEN
            new_function_description_header^.command_function_availability := clc$normal_usage_entry;
          ELSEIF pvt [p$availability].value^.keyword_value = 'ADVANCED_USAGE' THEN
            new_function_description_header^.command_function_availability := clc$advanced_usage_entry;
          ELSE {HIDDEN}
            new_function_description_header^.command_function_availability := clc$hidden_entry;
          IFEND;
        IFEND;

        IF pvt [p$scope].specified THEN
          IF pvt [p$scope].value^.keyword_value = 'XDCL' THEN
            new_function_description_header^.command_function_kind := llc$entry_point;
          ELSEIF pvt [p$scope].value^.keyword_value = 'GATE' THEN
            new_function_description_header^.command_function_kind := llc$gate;
          ELSE {LOCAL}
            new_function_description_header^.command_function_kind := llc$local_to_library;
          IFEND;
        IFEND;

        pmp$get_time (osc$hms_time, time, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        pmp$get_date (osc$mdy_date, date, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        new_function_description_header^.time_created := time;
        new_function_description_header^.date_created := date;

        ALLOCATE module_description IN ocv$olg_working_heap^;
        IF module_description = NIL THEN
          osp$set_status_condition (oce$e_internal_olg_seg_overflow, status);
          RETURN;
        IFEND;

        module_description^.name := new_function_description_header^.name;
        module_description^.source := occ$current;
        module_description^.kind := occ$function_description;

        size := i#current_sequence_position (ocv$olg_scratch_seq);
        RESET ocv$olg_scratch_seq;

        ALLOCATE module_description^.file: [[REP size OF cell]] IN ocv$olg_working_heap^;
        IF module_description^.file = NIL THEN
          osp$set_status_condition (oce$e_internal_olg_seg_overflow, status);
          RETURN;
        IFEND;

        IF #SEGMENT (nlm^.description^.file) = #SEGMENT (ocv$olg_working_heap) THEN
          FREE nlm^.description^.file IN ocv$olg_working_heap^;
        IFEND;
        nlm^.description := module_description;
        nlm^.description^.file := module_description^.file;

        RESET module_description^.file;

        NEXT module_description^.function_description_header IN module_description^.file;
        NEXT new_function_description_header IN ocv$olg_scratch_seq;
        module_description^.function_description_header^ := new_function_description_header^;
        IF module_description^.function_description_header^.number_of_aliases <> 0 THEN
          NEXT new_alias_list: [1 .. module_description^.function_description_header^.number_of_aliases] IN
                module_description^.file;
          module_description^.function_description_header^.aliases :=
                #REL (new_alias_list, module_description^.file^);
          NEXT old_alias_list: [1 .. module_description^.function_description_header^.number_of_aliases] IN
                ocv$olg_scratch_seq;
          new_alias_list^ := old_alias_list^;
        IFEND;

        member_size := size - i#current_sequence_position (module_description^.file);
        NEXT member: [[REP member_size OF cell]] IN module_description^.file;
        module_description^.function_description_header^.member := #REL (member, module_description^.file^);
        module_description^.function_description_header^.member_size := member_size;

        NEXT sequence: [[REP member_size OF cell]] IN ocv$olg_scratch_seq;
        member^ := sequence^;
        name_node := name_node^.link;
      WHILEND;

    END /protect/;
    pmp$disestablish_cond_handler (established_conditions, ignore_status);

  PROCEND ocp$_change_function_descriptio;

MODEND ocm$change_function_description
