/*****************************************************************/
/**                                                             **/
/**             (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_oid[] = "@(#)form_oid.c	1.9 10/20/92 05:45:48  LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		James A. Guse
			Network Systems Division

	DATE WRITTEN:	11/6/90

	ROUTINE:	__ROr_format_ObjectIdentifier


PURPOSE:
	This routine converts a logicalvector into printable format

IN:
	value - value to print
	valuelength - length in bytes of value variable
	maxlength - max number of components in oid
	maxlength2 - number of octets per component

OUT:
RETURNS malloc'ed character string

CALLED ROUTINES:

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


*/

#include <elros/exceptions.h>

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

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

	long *value; /* comp field of an oid */
	unsigned long valuelength; /* size field of an oid */
	unsigned long maxlength;
	unsigned long maxlength2;

{
   char *buffer,*bufptr;
   int i,count;
   char space[64];

   /* Error check for valid oid value */
   if (maxlength && valuelength > maxlength)
      return((char *)0);

   for (count=0,i=0; i<valuelength; i++)
   {
      if (count)
         count++;
      sprintf(space,"%lu",value[i]);
      count += strlen(space);
   }
   count++;
   bufptr = buffer = (char *)calloc(count+1,1);

   for (i=0; i<valuelength; i++)
   {
      sprintf(bufptr,"%lu.",value[i]);
      while (*bufptr)
         bufptr++;
   }
   bufptr--;
   *bufptr = 0;
   return(buffer);
}


