Пример #1
0
extern	Bool
SetValueDateTime(
	ValueStruct	*val,
	struct	tm	tval)
{
	Bool	rc;
	char	str[SIZE_NUMBUF+1];

	if		(  val  ==  NULL  ) {
		fprintf(stderr,"no ValueStruct\n");
		rc = FALSE;
	} else {
		ValueIsNonNil(val);
		switch	(ValueType(val)) {
		  case	GL_TYPE_CHAR:
		  case	GL_TYPE_VARCHAR:
		  case	GL_TYPE_DBCODE:
		  case	GL_TYPE_TEXT:
		  case	GL_TYPE_SYMBOL:
		  case	GL_TYPE_NUMBER:
			sprintf(str,"%04d%02d%02d%02d%02d%02d",
					tval.tm_year,
					tval.tm_mon + 1,
					tval.tm_mday,
					tval.tm_hour,
					tval.tm_min,
					tval.tm_sec);
			rc = SetValueString(val,str,NULL);
			break;
		  case	GL_TYPE_INT:
			rc = ( ( ValueInteger(val) = (int)mktime(&tval) ) < 0 ) ? FALSE : TRUE;
			break;
		  case	GL_TYPE_FLOAT:
			rc = ( ( ValueFloat(val) = (double)mktime(&tval) ) < 0 ) ? FALSE : TRUE;
			break;
		  case	GL_TYPE_BOOL:
			rc = ( ValueBool(val) = ( mktime(&tval) == 0 ? FALSE : TRUE ) < 0 ) ? FALSE : TRUE;
			break;
		  case	GL_TYPE_TIMESTAMP:
		  case	GL_TYPE_DATE:
		  case	GL_TYPE_TIME:
			memcpy(&ValueDateTime(val),&tval,sizeof(struct tm));
			rc = (  mktime(&ValueDateTime(val))  < 0 ) ? FALSE : TRUE;
			break;
		  default:
			ValueIsNil(val);
			rc = FALSE;	  
		}
	}
	return	(rc);
}
Пример #2
0
extern	Bool
SetValueFloat(
	ValueStruct	*val,
	double		fval)
{
	time_t	wt;
	Bool	rc;
	char	str[SIZE_NUMBUF+1];

	if		(  val  ==  NULL  ) {
		fprintf(stderr,"no ValueStruct\n");
		rc = FALSE;
	} else {
		ValueIsNonNil(val);
		switch	(ValueType(val)) {
		  case	GL_TYPE_CHAR:
		  case	GL_TYPE_VARCHAR:
		  case	GL_TYPE_DBCODE:
		  case	GL_TYPE_TEXT:
		  case	GL_TYPE_SYMBOL:
			sprintf(str,"%f",fval);
			rc = SetValueString(val,str,NULL);
			break;
		  case	GL_TYPE_NUMBER:
			FloatToFixed(&ValueFixed(val),fval);
			rc = TRUE;
			break;
		  case	GL_TYPE_INT:
			ValueInteger(val) = (int)fval;
			rc = TRUE;
			break;
		  case	GL_TYPE_FLOAT:
			ValueFloat(val) = fval;
			rc = TRUE;
			break;
		  case	GL_TYPE_BOOL:
			ValueBool(val) = ( fval == 0 ) ? FALSE : TRUE;
			rc = TRUE;
			break;
		  case	GL_TYPE_TIMESTAMP:
		  case	GL_TYPE_DATE:
		  case	GL_TYPE_TIME:
			wt = (time_t)fval;
			rc = (  localtime_r(&wt,&ValueDateTime(val))  !=  NULL  ) ? TRUE : FALSE;
			break;
		  default:
			ValueIsNil(val);
			rc = FALSE;
			break;
		}
	}
	return	(rc);
}
Пример #3
0
extern	struct	tm
ValueToDate(
	ValueStruct	*val)
{
	struct	tm	ret;
	Fixed	*xval;
	char	*str;

	memclear(&ret,sizeof(struct tm));
	if		(  val  ==  NULL  ) {
	} else
	switch	(ValueType(val)) {
	  case	GL_TYPE_CHAR:
	  case	GL_TYPE_VARCHAR:
	  case	GL_TYPE_TEXT:
	  case	GL_TYPE_SYMBOL:
		str = ValueString(val);
		ret.tm_year = StrToInt(str,4);		str += 4;
		ret.tm_mon = StrToInt(str,2) - 1;	str += 2;
		ret.tm_mday = StrToInt(str,2);		str += 2;
		ret.tm_hour = 0;
		ret.tm_min = 0;
		ret.tm_sec = 0;
		mktime(&ret);
		break;
	  case	GL_TYPE_NUMBER:
		xval = &ValueFixed(val);
		str = xval->sval;
		ret.tm_year = StrToInt(str,4);		str += 4;
		ret.tm_mon = StrToInt(str,2) - 1;	str += 2;
		ret.tm_mday = StrToInt(str,2);		str += 2;
		ret.tm_hour = 0;
		ret.tm_min = 0;
		ret.tm_sec = 0;
		mktime(&ret);
		break;
	  case	GL_TYPE_TIMESTAMP:
	  case	GL_TYPE_DATE:
		memcpy(&ret,&ValueDateTime(val),sizeof(struct tm));
		ret.tm_hour = 0;
		ret.tm_min = 0;
		ret.tm_sec = 0;
		mktime(&ret);
		break;
	  default:
		break;
	}
	return	(ret);
}
Пример #4
0
extern	int
ValueToInteger(
	ValueStruct	*val)
{
	int		ret;

	if		(  val  ==  NULL  ) {
		ret = 0;
	} else
	switch	(ValueType(val)) {
	  case	GL_TYPE_CHAR:
	  case	GL_TYPE_VARCHAR:
	  case	GL_TYPE_TEXT:
	  case	GL_TYPE_SYMBOL:
		ret = StrToInt(ValueString(val),strlen(ValueString(val)));
		break;
	  case	GL_TYPE_NUMBER:
		ret = FixedToInt(&ValueFixed(val));
		break;
	  case	GL_TYPE_INT:
		ret = ValueInteger(val);
		break;
	  case	GL_TYPE_FLOAT:
		ret = (int)ValueFloat(val);
		break;
	  case	GL_TYPE_BOOL:
		ret = ValueBool(val);
		break;
	  case	GL_TYPE_OBJECT:
		ret = ValueObjectId(val);
		break;
	  case	GL_TYPE_TIMESTAMP:
	  case	GL_TYPE_DATE:
	  case	GL_TYPE_TIME:
		ret = (int)mktime(&ValueDateTime(val));
		break;
	  default:
		ret = 0;
	}
	return	(ret);
}
Пример #5
0
extern	double
ValueToFloat(
	ValueStruct	*val)
{
	double	ret;

	if		(  val  ==  NULL  ) {
		ret = 0;
	} else
	switch	(ValueType(val)) {
	  case	GL_TYPE_CHAR:
	  case	GL_TYPE_VARCHAR:
	  case	GL_TYPE_TEXT:
	  case	GL_TYPE_SYMBOL:
		ret = atof(ValueString(val));
		break;
	  case	GL_TYPE_NUMBER:
		ret = FixedToFloat(&ValueFixed(val));
		break;
	  case	GL_TYPE_INT:
		ret = (double)ValueInteger(val);
		break;
	  case	GL_TYPE_FLOAT:
		ret = ValueFloat(val);
		break;
	  case	GL_TYPE_BOOL:
		ret = (double)ValueBool(val);
		break;
	  case	GL_TYPE_TIMESTAMP:
	  case	GL_TYPE_DATE:
	  case	GL_TYPE_TIME:
		ret = (double)mktime(&ValueDateTime(val));
		break;
	  default:
		ret = 0;
	}
	return	(ret);
}
Пример #6
0
extern	Bool
SetValueFixed(
	ValueStruct	*val,
	Fixed		*fval)
{
	Bool	rc;
	char	*str;

	if		(  val  ==  NULL  ) {
		fprintf(stderr,"no ValueStruct\n");
		rc = FALSE;
	} else {
		ValueIsNonNil(val);
		switch	(ValueType(val)) {
		  case	GL_TYPE_CHAR:
		  case	GL_TYPE_VARCHAR:
		  case	GL_TYPE_DBCODE:
		  case	GL_TYPE_TEXT:
		  case	GL_TYPE_SYMBOL:
			rc = SetValueString(val,fval->sval,NULL);
			break;
		  case	GL_TYPE_NUMBER:
			FixedRescale(&ValueFixed(val),fval);
			rc = TRUE;
			break;
		  case	GL_TYPE_INT:
			ValueInteger(val) = FixedToInt(fval);
			rc = TRUE;
			break;
		  case	GL_TYPE_FLOAT:
			ValueFloat(val) = FixedToFloat(fval);
			rc = TRUE;
			break;
		  case	GL_TYPE_TIMESTAMP:
			str = fval->sval;
			ValueDateTimeYear(val) = StrToInt(str,4);		str += 4;
			ValueDateTimeMon(val) = StrToInt(str,2) - 1;	str += 2;
			ValueDateTimeMDay(val) = StrToInt(str,2);		str += 2;
			ValueDateTimeHour(val) = StrToInt(str,2);		str += 2;
			ValueDateTimeMin(val) = StrToInt(str,2);		str += 2;
			ValueDateTimeSec(val) = StrToInt(str,2);		str += 2;
			rc = mktime(&ValueDateTime(val)) >= 0 ? TRUE : FALSE;
			break;
		  case	GL_TYPE_DATE:
			str = fval->sval;
			ValueDateTimeYear(val) = StrToInt(str,4);		str += 4;
			ValueDateTimeMon(val) = StrToInt(str,2) - 1;	str += 2;
			ValueDateTimeMDay(val) = StrToInt(str,2);		str += 2;
			ValueDateTimeHour(val) = 0;
			ValueDateTimeMin(val) = 0;
			ValueDateTimeSec(val) = 0;
			rc = mktime(&ValueDateTime(val)) >= 0 ? TRUE : FALSE;
			break;
		  case	GL_TYPE_TIME:
			str = fval->sval;
			ValueDateTimeYear(val) = 0;
			ValueDateTimeMon(val) = 0;
			ValueDateTimeMDay(val) = 0;
			ValueDateTimeHour(val) = StrToInt(str,2);	str += 2;
			ValueDateTimeMin(val) = StrToInt(str,2);	str += 2;
			ValueDateTimeSec(val) = StrToInt(str,2);	str += 2;
			rc = TRUE;
			break;
#if	0
		  case	GL_TYPE_BOOL:
			val->body.BoolData = ( *fval->sval == 0 ) ? FALSE : TRUE;
			rc = TRUE;
			break;
#endif
		  default:
			ValueIsNil(val);
			rc = FALSE;
			break;
		}
	}
	return	(rc);
}
Пример #7
0
extern	Bool
SetValueInteger(
	ValueStruct	*val,
	int			ival)
{
	Bool	rc;
	char	str[SIZE_NUMBUF+1];
	Bool	fMinus;

	if		(  val  ==  NULL  ) {
		fprintf(stderr,"no ValueStruct\n");
		rc = FALSE;
	} else {
		ValueIsNonNil(val);
		switch	(ValueType(val)) {
		  case	GL_TYPE_CHAR:
		  case	GL_TYPE_VARCHAR:
		  case	GL_TYPE_DBCODE:
		  case	GL_TYPE_TEXT:
		  case	GL_TYPE_SYMBOL:
			sprintf(str,"%d",ival);
			rc = SetValueString(val,str,NULL);
			break;
		  case	GL_TYPE_NUMBER:
			if		(  ival  <  0  ) {
				ival = - ival;
				fMinus = TRUE;
			} else {
				fMinus = FALSE;
			}
			sprintf(str,"%0*d",(int)ValueFixedLength(val),ival);
			if		(  fMinus  ) {
				*str |= 0x40;
			}
			rc = SetValueString(val,str,NULL);
			break;
		  case	GL_TYPE_INT:
			ValueInteger(val) = ival;
			rc = TRUE;
			break;
		  case	GL_TYPE_FLOAT:
			ValueFloat(val) = ival;
			rc = TRUE;
			break;
		  case	GL_TYPE_BOOL:
			ValueBool(val) = ( ival == 0 ) ? FALSE : TRUE;
			rc = TRUE;
			break;
		  case	GL_TYPE_OBJECT:
			ValueObjectId(val) = ival;
			if		(  ValueObjectFile(val)  !=  NULL  ) {
				xfree(ValueObjectFile(val));
				ValueObjectFile(val) = NULL;
			}
			rc = TRUE;
			break;
		  case	GL_TYPE_TIMESTAMP:
		  case	GL_TYPE_DATE:
		  case	GL_TYPE_TIME:
			rc = (  localtime_r((time_t *)&ival,&ValueDateTime(val))  !=  NULL  ) ? TRUE : FALSE;
			break;
		  default:
			ValueIsNil(val);
			rc = FALSE;	  
		}
	}
	return	(rc);
}
Пример #8
0
extern	Bool
SetValueStringWithLength(
	ValueStruct	*val,
	char		*str,
	size_t		slen,
	char		*codeset)
{
	Bool	rc
	,		fMinus
	,		fPoint;
	size_t	len;
	byte	*p;
	byte	buff[SIZE_NUMBUF+1]
		,	sbuff[SIZE_LONGNAME+1];
	Fixed	from;
	size_t	size;
#ifdef	WITH_I18N
	byte	*q;
	iconv_t	cd;
	size_t	sob
	,		sib;
	char	*istr;
#endif

ENTER_FUNC;
	if		(  val  ==  NULL  ) {
		fprintf(stderr,"no ValueStruct\n");
		rc = FALSE;
	} else
	if		(	(  str   ==  NULL      )
			||	(  *str  ==  CHAR_NIL  ) ) {
		ValueIsNil(val);
		rc = TRUE;
	} else {
		ValueIsNonNil(val);
		switch	(ValueType(val)) {
		  case	GL_TYPE_CHAR:
		  case	GL_TYPE_VARCHAR:
		  case	GL_TYPE_DBCODE:
		  case	GL_TYPE_TEXT:
		  case	GL_TYPE_SYMBOL:
#ifdef	WITH_I18N
			if		(	(  codeset  !=  NULL  )
					&&	(	(  stricmp(codeset,"utf8")   ==  0  )
						||	(  stricmp(codeset,"utf-8")  ==  0  ) ) )	{
				codeset = NULL;
			}
			if		(  codeset  !=  NULL  ) {
				if		(  IS_VALUE_EXPANDABLE(val)  ) {
					len = slen;
				} else {
					len = ValueStringLength(val) < slen ?
						ValueStringLength(val) : slen;
				}
				cd = iconv_open("utf8",codeset);
				while	(TRUE) {
					istr = str;
					sib = len;
					sob = ValueStringSize(val);
					if		(  ( q = ValueString(val) )  !=  NULL  ) {
						memclear(ValueString(val),ValueStringSize(val));
						if		(  iconv(cd,&istr,&sib,(void*)&q,&sob)  ==  0  )	break;
						if		(  errno  ==  E2BIG ) {
							xfree(ValueString(val));
							ValueStringSize(val) *= 2;
						} else
							break;
					} else {
						ValueStringSize(val) = 1;
					}
					ValueString(val) = (byte *)xmalloc(ValueStringSize(val));
				};
				iconv_close(cd);
				*q = 0;
				len = ValueStringSize(val) - sob;
			} else {
#endif
				size = slen + 1;
				len = slen;
				if		(  size  >  ValueStringSize(val)  ) {
					if		(  ValueString(val)  !=  NULL  ) {
						xfree(ValueString(val));
					}
					ValueStringSize(val) = size;
					ValueString(val) = (byte *)xmalloc(size);
				}
				memclear(ValueString(val),ValueStringSize(val));
				strcpy(ValueString(val),str);
#ifdef	WITH_I18N
			}
#endif
			if		(  IS_VALUE_EXPANDABLE(val)  ) {
				ValueStringLength(val) = len;
			}
			rc = TRUE;
			break;
		  case	GL_TYPE_BYTE:
			DecodeStringToBinary(ValueByte(val),ValueByteLength(val),str);
			rc = TRUE;
			break;
		  case	GL_TYPE_BINARY:
#ifdef	BINARY_IS_BASE64
			p = (byte *)xmalloc(strlen(str));
			size = strlen(str);
			size = DecodeBase64(p,size,str,size);
			if		(  ValueByte(val)  !=  NULL  ) {
				xfree(ValueByte(val));
			}
			ValueByteSize(val) = strlen(str);
			ValueByte(val) = p;
#else
			size = 0;
			for	( p = str ; *p != 0 ; ) {
				if		(  *p  ==  '\\'  ) {
					p ++;
					if		(  *p  ==  'u'  ) {
						p += 3;
					} else {
						p ++;
					}
				} else {
					p ++;
				}
				size ++;
			}
			if		(  size  >  ValueByteSize(val)  ) {
				if		(  ValueByte(val)  !=  NULL  ) {
						xfree(ValueByte(val));
				}
				ValueByteSize(val) = size;
				ValueByte(val) = (byte *)xmalloc(size);
			}
			memclear(ValueByte(val),ValueByteSize(val));
			DecodeStringToBinary(ValueByte(val),size,str);
#endif
			ValueByteLength(val) = size;
			rc = TRUE;
			break;
		  case	GL_TYPE_OBJECT:
			ValueObjectId(val) = 0;
			for	( ; slen > 0 ; slen -- )	{
				if		(  isdigit(*str)  )	{
					ValueObjectId(val) = ValueObjectId(val) * 10 + ( *str - '0' );
				}
				str ++;
			}
			if		(  ValueObjectFile(val)  !=  NULL  ) {
				xfree(ValueObjectFile(val));
				ValueObjectFile(val) = NULL;
			}
			rc = TRUE;
			break;
		  case	GL_TYPE_NUMBER:
		  case	GL_TYPE_INT:
		  case	GL_TYPE_FLOAT:
		  case	GL_TYPE_BOOL:
		  case	GL_TYPE_TIMESTAMP:
		  case	GL_TYPE_DATE:
		  case	GL_TYPE_TIME:
#ifdef	WITH_I18N
			if		(  codeset  !=  NULL  ) {
				cd = iconv_open("utf8",codeset);
				istr = str;
				sib = slen;
				sob = SIZE_NUMBUF;
				p = sbuff;
				iconv(cd,&istr,&sib,(void*)&p,&sob);
				iconv_close(cd);
				*p = 0;
				str = sbuff;
			} else {
#endif
				strncpy(sbuff,str,SIZE_NUMBUF);
				str = sbuff;
#ifdef	WITH_I18N
			}
#endif
			switch	(ValueType(val)) {
			  case	GL_TYPE_NUMBER:
				p = buff;
				from.flen = 0;
				from.slen = 0;
				from.sval = buff;
				fPoint = FALSE;
				fMinus = FALSE;
				while	(  *str  !=  0  ) {
					if		(  fPoint  ) {
						from.slen ++;
					}
					if		(  *str  ==  '-'  ) {
						fMinus = TRUE;
					} else
					if	(  isdigit(*str)  ) {
						*p ++ = *str;
						from.flen ++;
					} else
					if		(  *str  ==  '.'  ) {
						fPoint = TRUE;
					}
					str ++;
				}
				*p = 0;
				if		(  fMinus  ) {
					*buff |= 0x40;
				}
				FixedRescale(&ValueFixed(val),&from);
				rc = TRUE;
				break;
			  case	GL_TYPE_INT:
				ValueInteger(val) = StrToInt(str,slen);
				rc = TRUE;
				break;
			  case	GL_TYPE_FLOAT:
				ValueFloat(val) = atof(str);
				rc = TRUE;
				break;
			  case	GL_TYPE_BOOL:
				ValueBool(val) = ( toupper(*str) == 'T' ) ? TRUE : FALSE;
				rc = TRUE;
				break;
			  case	GL_TYPE_TIMESTAMP:
				ValueDateTimeYear(val) = StrToInt(str,4);		str += 4;
				ValueDateTimeMon(val) = StrToInt(str,2) - 1;	str += 2;
				ValueDateTimeMDay(val) = StrToInt(str,2);		str += 2;
				ValueDateTimeHour(val) = StrToInt(str,2);		str += 2;
				ValueDateTimeMin(val) = StrToInt(str,2);		str += 2;
				ValueDateTimeSec(val) = StrToInt(str,2);		str += 2;
				rc = mktime(&ValueDateTime(val)) >= 0 ? TRUE : FALSE;
				break;
			  case	GL_TYPE_DATE:
				ValueDateTimeYear(val) = StrToInt(str,4);		str += 4;
				ValueDateTimeMon(val) = StrToInt(str,2) - 1;	str += 2;
				ValueDateTimeMDay(val) = StrToInt(str,2);		str += 2;
				ValueDateTimeHour(val) = 0;
				ValueDateTimeMin(val) = 0;
				ValueDateTimeSec(val) = 0;
				rc = mktime(&ValueDateTime(val)) >= 0 ? TRUE : FALSE;
				break;
			  case	GL_TYPE_TIME:
				ValueDateTimeYear(val) = 0;
				ValueDateTimeMon(val) = 0;
				ValueDateTimeMDay(val) = 0;
				ValueDateTimeHour(val) = StrToInt(str,2);	str += 2;
				ValueDateTimeMin(val) = StrToInt(str,2);	str += 2;
				ValueDateTimeSec(val) = StrToInt(str,2);	str += 2;
				rc = TRUE;
				break;
			  default:
				rc = TRUE;
				break;
			}
			break;
		  default:
			ValueIsNil(val);
			rc = FALSE;	  
		}
	}
LEAVE_FUNC;
	return	(rc);
}
Пример #9
0
extern	struct	tm
ValueToTime(
	ValueStruct	*val)
{
	time_t	wt;
	struct	tm	ret;
	Fixed	*xval;
	char	*str;

	memclear(&ret,sizeof(struct tm));
	if		(  val  ==  NULL  ) {
	} else
	switch	(ValueType(val)) {
	  case	GL_TYPE_CHAR:
	  case	GL_TYPE_VARCHAR:
	  case	GL_TYPE_TEXT:
	  case	GL_TYPE_SYMBOL:
		str = ValueString(val);
		ret.tm_year = 0;
		ret.tm_mon = 0;
		ret.tm_mday = 0;
		ret.tm_hour = StrToInt(str,2);	str += 2;
		ret.tm_min = StrToInt(str,2);	str += 2;
		ret.tm_sec = StrToInt(str,2);	str += 2;
		break;
	  case	GL_TYPE_NUMBER:
		xval = &ValueFixed(val);
		str = xval->sval;
		ret.tm_year = 0;
		ret.tm_mon = 0;
		ret.tm_mday = 0;
		ret.tm_hour = StrToInt(str,2);	str += 2;
		ret.tm_min = StrToInt(str,2);	str += 2;
		ret.tm_sec = StrToInt(str,2);	str += 2;
		break;
	  case	GL_TYPE_INT:
		wt = (time_t)ValueInteger(val);
		localtime_r(&wt,&ret);
		ret.tm_year = 0;
		ret.tm_mon = 0;
		ret.tm_mday = 0;
		break;
	  case	GL_TYPE_FLOAT:
		wt = (time_t)ValueFloat(val);
		localtime_r(&wt,&ret);
		ret.tm_year = 0;
		ret.tm_mon = 0;
		ret.tm_mday = 0;
		break;
	  case	GL_TYPE_TIMESTAMP:
	  case	GL_TYPE_TIME:
		memcpy(&ret,&ValueDateTime(val),sizeof(struct tm));
		ret.tm_year = 0;
		ret.tm_mon = 0;
		ret.tm_mday = 0;
		break;
	  default:
		break;
	}
	return	(ret);
}
Пример #10
0
extern	byte	*
ValueToBinary(
	ValueStruct	*val)
{
	byte	*ret;
ENTER_FUNC;

	if		(  val  ==  NULL  ) {
		ret = NULL;
	} else {
		dbgprintf("type = %X\n",(int)ValueType(val));
		if		(  ValueStr(val)  ==  NULL  ) {
			ValueStr(val) = NewLBS();
		}
		LBS_EmitStart(ValueStr(val));
		if		(  IS_VALUE_NIL(val)  ) {
			LBS_EmitChar(ValueStr(val),CHAR_NIL);
		} else {
			switch	(ValueType(val)) {
			  case	GL_TYPE_CHAR:
			  case	GL_TYPE_VARCHAR:
			  case	GL_TYPE_DBCODE:
			  case	GL_TYPE_TEXT:
			  case	GL_TYPE_SYMBOL:
				if		(  ValueString(val)  !=  NULL  ) {
					LBS_ReserveSize(ValueStr(val),strlen(ValueString(val))+1,FALSE);
					strcpy(ValueStrBody(val),ValueString(val));
				} else {
					LBS_EmitChar(ValueStr(val),CHAR_NIL);
				}
				break;
			  case	GL_TYPE_BYTE:
			  case	GL_TYPE_BINARY:
				LBS_ReserveSize(ValueStr(val),ValueByteLength(val),FALSE);
				memcpy(ValueStrBody(val),ValueByte(val),ValueByteLength(val));
				break;
			  case	GL_TYPE_NUMBER:
				LBS_ReserveSize(ValueStr(val),sizeof(Fixed),FALSE);
				memcpy(ValueStrBody(val),&ValueFixed(val),sizeof(Fixed));
				break;
			  case	GL_TYPE_INT:
				LBS_ReserveSize(ValueStr(val),sizeof(int),FALSE);
				memcpy(ValueStrBody(val),&ValueInteger(val),sizeof(int));
				break;
			  case	GL_TYPE_OBJECT:
				LBS_ReserveSize(ValueStr(val),sizeof(MonObjectType),FALSE);
				memcpy(ValueStrBody(val),&ValueObject(val),sizeof(MonObjectType));
				break;
			  case	GL_TYPE_FLOAT:
				LBS_ReserveSize(ValueStr(val),sizeof(double),FALSE);
				memcpy(ValueStrBody(val),&ValueFloat(val),sizeof(double));
				break;
			  case	GL_TYPE_BOOL:
				LBS_ReserveSize(ValueStr(val),sizeof(Bool),FALSE);
				memcpy(ValueStrBody(val),&ValueBool(val),sizeof(Bool));
				break;
			  case	GL_TYPE_TIMESTAMP:
			  case	GL_TYPE_DATE:
			  case	GL_TYPE_TIME:
				LBS_ReserveSize(ValueStr(val),sizeof(int)*9,FALSE);
				memcpy(ValueStrBody(val),&ValueDateTime(val),sizeof(int)*9);
				break;
			  default:
				break;
			}
		}
		ret = ValueStrBody(val);
	}
LEAVE_FUNC;
	return	(ret);
}
Пример #11
0
extern	Bool
SetValueBinary(
	ValueStruct	*val,
	byte		*str,
	size_t		slen)
{
	Bool	rc;
	size_t	size;

ENTER_FUNC;
	if		(  val  ==  NULL  ) {
		fprintf(stderr,"no ValueStruct\n");
		rc = FALSE;
	} else {
		if		(	(  str   ==  NULL      )
				||	(  slen  ==  0         ) ) {
			ValueIsNil(val);
			rc = TRUE;
		} else {
			ValueIsNonNil(val);
		}
		switch	(ValueType(val)) {
		  case	GL_TYPE_CHAR:
		  case	GL_TYPE_VARCHAR:
		  case	GL_TYPE_DBCODE:
		  case	GL_TYPE_TEXT:
		  case	GL_TYPE_SYMBOL:
			if		(  *str  ==  CHAR_NIL  ) {
				ValueIsNil(val);
			} else {
				size = slen + 1;
				if		(  size  >  ValueStringSize(val)  ) {
					if		(  ValueString(val)  !=  NULL  ) {
						xfree(ValueString(val));
					}
					ValueStringSize(val) = size;
					ValueString(val) = (byte *)xmalloc(size);
				}
				memclear(ValueString(val),ValueStringSize(val));
				if		(  str  !=  NULL  ) {
					strcpy(ValueString(val),str);
				}
				if		(  ValueType(val)  ==  GL_TYPE_TEXT  ) {
					ValueStringLength(val) = slen;
				}
			}
			rc = TRUE;
			break;
		  case	GL_TYPE_BYTE:
			size = ValueByteLength(val) < slen ? ValueByteLength(val) : slen;
			memclear(ValueByte(val),ValueByteSize(val));
			if		(  str  !=  NULL  ) {
				memcpy(ValueByte(val),str,size);
			}
			rc = TRUE;
			break;
		  case	GL_TYPE_BINARY:
			if		(  slen  >  ValueByteSize(val)  ) {
				if		(  ValueByte(val)  !=  NULL  ) {
					xfree(ValueByte(val));
				}
				ValueByteSize(val) = slen;
				ValueByte(val) = (byte *)xmalloc(slen);
			}
			memclear(ValueByte(val),ValueByteSize(val));
			if		(  str  !=  NULL  ) {
				memcpy(ValueByte(val),str,slen);
			}
			ValueByteLength(val) = slen;
			rc = TRUE;
			break;
		  case	GL_TYPE_NUMBER:
			if		(  str  !=  NULL  ) {
				memcpy(&ValueFixed(val),str,sizeof(Fixed));
			} else {
				memclear(&ValueFixed(val),sizeof(Fixed));
			}
			rc = TRUE;
			break;
		  case	GL_TYPE_INT:
			if		(  str  !=  NULL  ) {
				memcpy(&ValueInteger(val),str,sizeof(int));
			} else {
				memclear(&ValueInteger(val),sizeof(int));
			}
			rc = TRUE;
			break;
		  case	GL_TYPE_OBJECT:
			if		(  str  !=  NULL  ) {
				memcpy(&ValueObjectId(val),str,sizeof(MonObjectType));
			} else {
				ValueObjectId(val) = 0;
			}
			if		(  ValueObjectFile(val)  !=  NULL  ) {
				xfree(ValueObjectFile(val));
				ValueObjectFile(val) = NULL;
			}
			rc = TRUE;
			break;
		  case	GL_TYPE_FLOAT:
			if		(  str  !=  NULL  ) {
				memcpy(&ValueFloat(val),str,sizeof(double));
			} else {
				memclear(&ValueFloat(val),sizeof(double));
			}
			rc = TRUE;
			break;
		  case	GL_TYPE_BOOL:
			if		(  str  !=  NULL  ) {
				memcpy(&ValueBool(val),str,sizeof(Bool));
			} else {
				memclear(&ValueBool(val),sizeof(Bool));
			}
			rc = TRUE;
			break;
		  case	GL_TYPE_TIMESTAMP:
		  case	GL_TYPE_DATE:
		  case	GL_TYPE_TIME:
			if		(  str  !=  NULL  ) {
				memcpy(&ValueDateTime(val),str,sizeof(struct tm));
				rc = mktime(&ValueDateTime(val)) >= 0 ? TRUE : FALSE;
			} else {
				memclear(&ValueDateTime(val),sizeof(struct tm));
				rc = TRUE;
			}
			break;
		  default:
			ValueIsNil(val);
			rc = FALSE;
			break;
		}
	}
LEAVE_FUNC;
	return	(rc);
}
Пример #12
0
extern size_t OpenCOBOL_UnPackValue(CONVOPT *opt, unsigned char *p,
                                    ValueStruct *value) {
  int32_t i;
  char buff[SIZE_NUMBUF + 1];
  unsigned char *q;
  ValueStruct *child;

  q = p;
  if (value != NULL) {
    ValueIsNonNil(value);
    switch (ValueType(value)) {
    case GL_TYPE_INT:
      i = *(int32_t*)p;
      IntegerCobol2C(opt, &i);
      SetValueInteger(value, (int64_t)i);
      p += sizeof(int32_t);
      break;
    case GL_TYPE_FLOAT:
      ValueFloat(value) = *(double *)p;
      p += sizeof(double);
      break;
    case GL_TYPE_BOOL:
      SetValueBool(value,(*(char *)p == 'T') ? TRUE : FALSE);
      p++;
      break;
    case GL_TYPE_OBJECT:
      StringCobol2C(p, SIZE_UUID);
      memcpy(ValueBody(value), p, SIZE_UUID);
      p += SIZE_UUID;
      break;
    case GL_TYPE_BYTE:
      memcpy(ValueByte(value), p, ValueByteLength(value));
      p += ValueByteLength(value);
      break;
    case GL_TYPE_BINARY:
      SetValueBinary(value, p, opt->textsize);
      p += opt->textsize;
      break;
    case GL_TYPE_TEXT:
    case GL_TYPE_SYMBOL:
      StringCobol2C(p, opt->textsize);
      SetValueStringWithLength(value, p, opt->textsize, ConvCodeset(opt));
      p += opt->textsize;
      break;
    case GL_TYPE_CHAR:
    case GL_TYPE_VARCHAR:
    case GL_TYPE_DBCODE:
      StringCobol2C(p, ValueStringLength(value));
      SetValueStringWithLength(value, p, ValueStringLength(value),
                               ConvCodeset(opt));
      p += ValueStringLength(value);
      break;
    case GL_TYPE_NUMBER:
      memcpy(buff, p, ValueFixedLength(value));
      FixedCobol2C(buff, ValueFixedLength(value));
      strcpy(ValueFixedBody(value), buff);
      p += ValueFixedLength(value);
      break;
    case GL_TYPE_TIMESTAMP:
      ValueDateTimeYear(value) = StrToInt(p, 4);
      p += 4;
      ValueDateTimeMon(value) = StrToInt(p, 2) - 1;
      p += 2;
      ValueDateTimeMDay(value) = StrToInt(p, 2);
      p += 2;
      ValueDateTimeHour(value) = StrToInt(p, 2);
      p += 2;
      ValueDateTimeMin(value) = StrToInt(p, 2);
      p += 2;
      ValueDateTimeSec(value) = StrToInt(p, 2);
      p += 2;
      mktime(ValueDateTime(value));
      break;
    case GL_TYPE_TIME:
      ValueDateTimeYear(value) = 0;
      ValueDateTimeMon(value) = 0;
      ValueDateTimeMDay(value) = 0;
      ValueDateTimeHour(value) = StrToInt(p, 2);
      p += 2;
      ValueDateTimeMin(value) = StrToInt(p, 2);
      p += 2;
      ValueDateTimeSec(value) = StrToInt(p, 2);
      p += 2;
      break;
    case GL_TYPE_DATE:
      ValueDateTimeYear(value) = StrToInt(p, 4);
      p += 4;
      ValueDateTimeMon(value) = StrToInt(p, 2) - 1;
      p += 2;
      ValueDateTimeMDay(value) = StrToInt(p, 2);
      p += 2;
      ValueDateTimeHour(value) = 0;
      ValueDateTimeMin(value) = 0;
      ValueDateTimeSec(value) = 0;
      mktime(ValueDateTime(value));
      break;
    case GL_TYPE_ARRAY:
      for (i = 0; i < ValueArraySize(value); i++) {
        child = ValueArrayItem(value, i);
        if (child != NULL) {
          p += OpenCOBOL_UnPackValue(opt, p, child);
          ValueParent(child) = value;
        }
      }
      break;
    case GL_TYPE_ROOT_RECORD:
    case GL_TYPE_RECORD:
      for (i = 0; i < ValueRecordSize(value); i++) {
        child = ValueRecordItem(value, i);
        if (child != NULL) {
          p += OpenCOBOL_UnPackValue(opt, p, child);
          ValueParent(child) = value;
        }
      }
      break;
    default:
      ValueIsNil(value);
      break;
    }
  }
  return (p - q);
}