?? RIGHT := 110 ??
MODULE ocm$build_section_directory;
*copyc osd$default_pragmats
?? PUSH (LISTEXT := ON) ??
*copyc llt$load_module_header
*copyc llt$object_text_descriptor
*copyc llt$section_definition
*copyc occ$generate_predictor
*copyc oct$offset_change_list
*copyc oct$section_directory
*copyc oct$single_module_predictor_hdr
*copyc oct$offset_change_list
*copyc oct$section_offset_changes
*copyc oct$module_predictor_size
*copyc oce$metapatch_generator_errors
*copyc llt$section_address
*copyc osp$set_status_abnormal
?? POP ??

*copyc och$build_section_directory

  PROCEDURE [XDCL] ocp$build_section_directory (p_module_predictor: ^oct$module_predictor;
        module_header: ^llt$load_module_header;
        object_library: ^SEQ ( * );
    VAR section_directory: ^oct$section_directory);

    VAR
      binding_section_ocv: ^oct$offset_change_list,
      i: llt$section_ordinal,
      module_predictor: ^oct$module_predictor,
      module_predictor_header: ^oct$single_module_predictor_hdr,
      section_number_change_list: ^oct$new_ordinal_list,
      section_number_cv: ^oct$new_ordinal_list,
      section_offset_cv: ^oct$section_offset_changes,
      socv: ^oct$offset_change_list,
      socv_header: ^oct$section_info,
      status: ost$status;

    module_predictor := p_module_predictor;

    FOR i := 0 TO UPPERBOUND (section_directory^) DO
      section_directory^ [i].new_section_number := i;
      section_directory^ [i].section_offset_change_vector := NIL;
    FOREND;
    RESET module_predictor;
    NEXT module_predictor_header IN module_predictor;
    IF module_predictor_header^.last_section_ordinal <> occ$invalid_section_ordinal THEN
      section_number_cv := #PTR (module_predictor_header^.section_number_cv, module_predictor^);
      RESET module_predictor TO section_number_cv;
      NEXT section_number_change_list: [0 .. module_predictor_header^.last_section_ordinal] IN
            module_predictor;
      FOR i := 0 TO UPPERBOUND (section_directory^) DO
        section_directory^ [i].new_section_number := section_number_change_list^ [i];
      FOREND;
    IFEND;
    IF module_predictor_header^.length_normal_section_ocv > 0 THEN
      section_offset_cv := #PTR (module_predictor_header^.section_offset_cv, module_predictor^);
      RESET module_predictor TO section_offset_cv;
      FOR i := 1 TO module_predictor_header^.length_normal_section_ocv DO
        NEXT socv_header IN module_predictor;
        NEXT socv: [1 .. socv_header^.number_of_socv_items] IN module_predictor;
        section_directory^ [socv_header^.section_ordinal].section_offset_change_vector := socv;
      FOREND;
    IFEND;
    IF module_predictor_header^.length_binding_socv > 0 THEN
      binding_section_ocv := #PTR (module_predictor_header^.binding_section_ocv, module_predictor^);
      section_directory^ [module_predictor_header^.binding_section_ordinal].section_offset_change_vector :=
                    binding_section_ocv;
    IFEND;
  PROCEND ocp$build_section_directory;
MODEND ocm$build_section_directory;
