/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/

static char sccsid_search_accep[] = "@(#)search_accep.c	1.12 10/20/92 05:54:48 LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		James A. Guse
			Network Systems Division

	DATE WRITTEN:	7/2/90

	ROUTINE:	search_accepttable

PURPOSE:
	This routine obtains the ROSE header.  This consists of cracking the
	ROSE value and returning everything but the argument value.

IN:
	oidvalue - value to search for
	oidtree - Table of information necessary to translate incoming
		operation number into a sequential internal integer
		suitable for use in switching by the caller.

OUT:
	internal - this is the internal number obtained from 'oidtree' which
		identifies the operation to the caller.


CALLED ROUTINES:

	
MODIFICATION HISTORY:


*/

#include <elros/instance.h>
#include <elros/typecodes.h>
#include <elros/typetags.h>
#include <elros/oidtree.h>

int __ROr_search_accepttable(oidvalue,oidtree,internal)

   struct __RO_oid_skeleton *oidvalue;
   __RO_Accept_table_Entry *	oidtree;
   int *			internal;


{
   int level;
   int lo,hi,index;

   level = 0;
   lo = oidtree[0].childlow;
   hi = oidtree[0].childhigh;
   do
   {
      index = (lo+hi)/2;
      if (oidvalue->comp[level] == oidtree[index].identifier_value)
         if (level+1 >= oidvalue->size)
         {
#ifndef __RO_PRODUCTION
            if (level+1 != oidvalue->size)
               return(__ROx_SAT_CONSISTENCY2);
#endif
            *internal = oidtree[index].internal_number;
            if (*internal == -1)
               return(__ROx_SAT_NOTFOUND);
            else
               return(SUCCESS);
         } 
         else
         {
            lo = oidtree[index].childlow;
            hi = oidtree[index].childhigh;
            level++;
            if (lo == -1)
               return(__ROx_SAT_NOTFOUND);
#ifndef __RO_PRODUCTION
            if (lo<1 || lo>oidtree[0].identifier_value ||
               hi < 1 || hi>oidtree[0].identifier_value ||
               hi<lo)
               return(__ROx_SAT_CONSISTENCY);
#endif
         }
      else if (oidvalue->comp[level] > oidtree[index].identifier_value)
         lo = index+1;
      else
         hi = index-1;

      if (lo > hi)
         return(__ROx_SAT_NOTFOUND);
   } while (1);		/* Loop Indefinitely, return()'s exit */

}


