/*****************************************************************/
/**                                                             **/
/**             (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_cmpP_bitstr[] = "@(#)cmpP_bitstr.c	1.8 10/19/92 13:52:49  LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		James A. Guse
			Network Systems Division

	DATE WRITTEN:	9/14/90

	ROUTINES:	__ROr_cmpP_BitString

PURPOSE:
	Compare two BitString values


IN:
	value1 - lhs value
	value2 - rhs value
	maxlength - maximum length.
	maxlength2 - maximum length aux.

OUT:
	RETURNs a boolean comparison flag


CALLED ROUTINES:
	

	
MODIFICATION HISTORY:


*/

#include <elros/instance.h>

 
int __ROr_cmpP_BitString(value1, value2, maxlength, maxlength2)

   __RO_ByteString *	value1;
   __RO_ByteString *	value2;
   unsigned long *	maxlength;
   unsigned long *	maxlength2;

{
   int i;
   int partial;
   unsigned int bits;
   unsigned long reallength = value1->len;
   unsigned char *val1, *val2;

   if (*maxlength && (reallength > *maxlength || value2->len > *maxlength))
      return (0); /* NOT EQUAL */

   if (reallength != value2->len)
      return (0); /* NOT EQUAL */

   if (*maxlength) {
      val1 = value1->val; 
      val2 = value2->val;
   }
   else {
      val1 = ((__RO_ByteString_indef *)value1)->val;
      val2 = ((__RO_ByteString_indef *)value2)->val;
   }

   partial = memcmp(val1,val2,reallength/8);

   if (!partial && reallength%8 > 0)
   {
      bits = 0xFF << (8 - reallength%8);
      return ((val1[reallength/8] & bits)==
              (val2[reallength/8] & bits));
   }
   else
      return(!partial);
}


