/*****************************************************************/
/**                                                             **/
/**             (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_form_bitstr[] = "@(#)form_bitstr.c	1.11 10/20/92 05:45:36  LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		James A. Guse
			Network Systems Division

	DATE WRITTEN:	11/6/90

	ROUTINE:	__ROr_format_BitString


PURPOSE:
	This routine converts a BitString value into printable format

IN:
	value - value to print
	valuelength - length in bytes of value variable
	type_info - parameters vector for lengths of this type

OUT:
RETURNS malloc'ed character string

CALLED ROUTINES:

	
MODIFICATION HISTORY:
	920817  Modified to use len field of BitString to determine value
		to be formatted.  (ls)


*/

#include <elros/exceptions.h>

#include <malloc.h>
#include <memory.h>

char *__ROr_format_BitString(value,valuelength,maxlength,maxlength2)

	unsigned char *value; /* val field of BitString */
	unsigned long valuelength; /* len field of BitString */
	unsigned long maxlength;
	unsigned long maxlength2;

{
   char *buffer = malloc(valuelength+1);
   char *bufptr = buffer;
   int i,j,k;

   /* Check for valid BitString value */
   if (maxlength && valuelength > maxlength)
      return (char *)0;

   for (i=0,k=0; k<valuelength; i++)
      for (j=7; j>=0 && k<valuelength; j--,k++)
         *bufptr++ = (value[i] & (1 << j)) ? '1' : '0';

   *bufptr = 0;
   return(buffer);
}


