/*****************************************************************/
/**                                                             **/
/**             (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_conv_int[] = "@(#)conv_int.c	1.14 10/20/92 05:36:33  LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		James A. Guse
			Network Systems Division

	DATE WRITTEN:	11/6/90

	ROUTINE:	__ROr_convert_Integer_const


PURPOSE:
	This routine converts a digit string into an Integer

IN:
	valuelength - length in bytes of value variable
	constant - string of value expression
	type_lengths - parameters vector for lengths of this type

OUT:
	value - value specified by the constant argument


CALLED ROUTINES:

	
MODIFICATION HISTORY:


*/

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


int __ROr_convert_Integer_const(value,valuelength,maxlength,maxlength2,constant,type_info)

	void *value;
	unsigned long valuelength;
	unsigned long maxlength;
	unsigned long maxlength2;
	char *constant;
	__RO_Type_Info *type_info;

{
   unsigned char *byteptr = (unsigned char *)value;
   int little_endian;
   int i,stop;
   char *constant_string;

   constant_string = (char *)malloc(strlen(constant));

   no_underscores(constant,constant_string);

   re_comp("^[0-9][0-9]*$");
   if (!re_exec(*constant=='+' || *constant=='-' ? constant+1 : constant))
      return(__ROx_CONST_INTEGERERROR);

   if (__RO_IS_NATIVE_TYPE(type_info,Integer_lengths,maxlength,valuelength))
      little_endian = (maxlength=valuelength,LITTLE_ENDIAN);
   else
      little_endian = type_info->non_native_endianness == __ROm_LITTLE_ENDIAN;

   if (atoI(constant,byteptr,maxlength))
      return(__ROx_CONST_INTEGEROVERFLOW);

   if (!little_endian)
      swapends(byteptr,maxlength);
      
   free(constant_string);

   return(SUCCESS);
}


