?? RIGHT := 110 ??
?? NEWTITLE := 'INSTALL_SOFTWARE Utility: RAP$LOCATE_DIRECTORY_RECORD Interface.' ??
MODULE ram$locate_directory_record;

{ PURPOSE:
{   This module contains the interface that locates a record for a
{   subproduct in the IDB directory.
{
{ DESIGN:
{   The compiled module resides in RAF$LIBRARY.
{
{ NOTES:
{

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc rat$idb_directory_pointers
?? POP ??
?? OLDTITLE ??
?? NEWTITLE := '[XDCL] rap$locate_directory_record', EJECT ??

{ PURPOSE:
{   This interface searches the IDB Directory for a subproduct's directory
{   record.  A pointer to the record is returned when found.  A NIL pointer
{   is returned when not found.
{
{ DESIGN:
{   The directory is maintained sorted by a sort key which is made up of the
{   licensed product and subproduct name fields.  This procedure performs a
{   binary search for the sort key in the directory.
{
{ NOTES:
{

  PROCEDURE [XDCL] rap$locate_directory_record
    (    subproduct_name: rat$subproduct_name;
         licensed_product: rat$licensed_product;
         directory_pointers: rat$idb_directory_pointers;
     VAR directory_record_p: ^rat$directory_record);


    VAR
      temp: integer,
      lower: rat$directory_size,
      mid: rat$directory_size,
      sort_key: rat$directory_sort_key,
      upper: rat$directory_size;


    directory_record_p := NIL;
    lower := 1;
    upper := directory_pointers.header_p^.directory_size;

    { Construct the sort key which is licensed product concatenated with subproduct name without removing
    { the blanks between.

    sort_key (1, * ) := licensed_product;
    sort_key (#SIZE (licensed_product) + 1, * ) := subproduct_name;

  /locate_in_directory/
    WHILE lower <= upper DO
      temp := lower + upper;
      mid := temp DIV 2;
      IF sort_key > directory_pointers.directory_p^ [mid].sort_key THEN
        lower := mid + 1;
      ELSEIF sort_key < directory_pointers.directory_p^ [mid].sort_key THEN
        upper := mid - 1;
      ELSE {directory entry for subproduct exits}
        directory_record_p := ^directory_pointers.directory_p^ [mid];
        EXIT /locate_in_directory/;
      IFEND;
    WHILEND /locate_in_directory/;

  PROCEND rap$locate_directory_record;
MODEND ram$locate_directory_record;
