/*****************************************************************/
/**                                                             **/
/**             (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_octstr[] = "@(#)form_octstr.c	1.14 10/20/92 05:45:46  LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		James A. Guse
			Network Systems Division

	DATE WRITTEN:	11/6/90

	ROUTINE:	__ROr_format_OctetString


PURPOSE:
	This routine converts hex-formatted types into printable format

IN:
	value - value to print
	valuelength - length in bytes of value variable
	maxlength - length parameter for this type
	maxlength2 - unused

OUT:
	RETURNS malloc'ed character string

CALLED ROUTINES:

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


*/

#include <elros/exceptions.h>
#include <elros/enc_dcd.h>
#include <elros/typeinfo.h>
#include <elros/extend_arith.h>

#ifdef __STDC__
#include <stdlib.h>
#else
#include <malloc.h>
#include <memory.h>
#endif

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

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

{
   char *buffer = malloc(valuelength*2+3);
   char *bufptr = buffer;
   int i;



   *bufptr++ = '0';
   *bufptr++ = 'x';
   for (i=0; i<valuelength; i++)
   {
      *bufptr++ = DIGITTOHEX(value[i]/16);
      *bufptr++ = DIGITTOHEX(value[i]%16);
   }

   *bufptr = 0;
   return(buffer);
}


