📄 si_libs.c
字号:
Var_Delete( &op1 );
Var_Delete( &op2 );
OpS_Push( si->RE->OpS, &result );
return ERR_WAE_WMLS_NONE;
}
enumErrorCode Call_Lang_max( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
pstructVar op2 = RE_Pop( si->RE );
pstructVar op1 = RE_Pop( si->RE );
pstructVar result = Var_New();
BOOL allOk = TRUE;
#ifdef HAS_FLOAT
FLOAT32 op1val;
FLOAT32 op2val;
#endif
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
if (result == NULL) {
Var_Delete( &op1 );
Var_Delete( &op2 );
return ERR_WAE_WMLS_LIB;
}
/* the type checks are ONLY to take care of the requirement: max(45.0 , 45) = 45.0 */
if (op1->type != typeFloat) {
allOk = Var_ConvertMethod( CONVERT_INT_FLOAT, op1, NULL );
}
if (allOk) {
if (op2->type != typeFloat) {
allOk = Var_ConvertMethod( CONVERT_INT_FLOAT, op2, NULL );
}
}
if (allOk) {
if ((op1->type == typeFloat) || (op2->type == typeFloat)) {
#ifdef HAS_FLOAT
op1val = (op1->type == typeFloat) ? (op1->val.theFloat):(op1->val.theInt);
op2val = (op2->type == typeFloat) ? (op2->val.theFloat):(op2->val.theInt);
if (op1val >= op2val) {
Var_AssignVar( result, op1 );
}
else {
Var_AssignVar( result, op2 );
}
#endif
}
else { /* both integers */
Var_AssignInt( result, (op1->val.theInt >= op2->val.theInt) ? (op1->val.theInt):(op2->val.theInt) );
}
}
if (!allOk) {
Var_AssignInvalid( result );
}
Var_Delete( &op1 );
Var_Delete( &op2 );
OpS_Push( si->RE->OpS, &result );
return ERR_WAE_WMLS_NONE;
}
enumErrorCode Call_Lang_parseInt( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
pstructVar op1 = RE_Pop( si->RE );
pstructVar result = Var_New();
INT32 theInt;
UINT8 notUsed;
BOOL isOverflow;
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
if (result == NULL)
{
Var_Delete( &op1 );
return ERR_WAE_WMLS_LIB;
}
if ( (VCR_OK == Var_Convert( op1, typeString )) && op1->val.theString &&
String2Int(op1->val.theString, ¬Used,
&theInt, &isOverflow) && (!isOverflow))
{
Var_AssignInt( result, theInt );
}
else
{
Var_AssignInvalid( result );
}
Var_Delete( &op1 );
OpS_Push( si->RE->OpS, &result );
return ERR_WAE_WMLS_NONE;
}
enumErrorCode Call_Lang_parseFloat( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
pstructVar op1 = RE_Pop( si->RE );
pstructVar result = Var_New();
#ifdef HAS_FLOAT
UINT8 notUsed;
BOOL isOverflow;
FLOAT32 theFloat;
if (result == NULL)
{
Var_Delete( &op1 );
return ERR_WAE_WMLS_LIB;
}
if ( (VCR_OK == Var_Convert( op1, typeString )) && op1->val.theString &&
String2Float (op1->val.theString, ¬Used, &theFloat, &isOverflow) &&
(!isOverflow))
{
Var_AssignFloat( result, theFloat );
}
else
{
Var_AssignInvalid( result );
}
#else
if (result == NULL)
{
Var_Delete( &op1 );
return ERR_WAE_WMLS_LIB;
}
Var_Delete( &op1 );
Var_AssignInvalid( result );
#endif
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
Var_Delete( &op1 );
OpS_Push( si->RE->OpS, &result );
return ERR_WAE_WMLS_NONE;
}
enumErrorCode Call_Lang_isInt( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
enumErrorCode errorCode;
pstructVar op1 = NULL;
enumVarType varType;
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
/* have to check if the var is invalid, then invalid will be the result */
op1 = RE_Pop( si->RE );
varType = op1->type;
OpS_Push( si->RE->OpS, &op1 );
if (varType == typeInvalid) {
return ERR_WAE_WMLS_NONE;
}
/* not invalid so check if parsable */
errorCode = CallLibraryFunction(si, 0, 3); /* Lang.parseInt */
if ( errorCode == ERR_WAE_WMLS_NONE ) {
op1 = RE_Pop( si->RE );
if (op1->type == typeInteger) {
Var_AssignBool( op1, TRUE );
}
else {
Var_AssignBool( op1, FALSE );
}
OpS_Push( si->RE->OpS, &op1 );
return ERR_WAE_WMLS_NONE;
}
else {
return errorCode;
}
}
enumErrorCode Call_Lang_isFloat( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
enumErrorCode errorCode;
pstructVar op1 = NULL;
enumVarType varType;
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
/* have to check if the var is invalid, then invalid will be the result */
op1 = RE_Pop( si->RE );
varType = op1->type;
OpS_Push( si->RE->OpS, &op1 );
if (varType == typeInvalid) {
return ERR_WAE_WMLS_NONE;
}
/* not invalid so check if parsable */
errorCode = CallLibraryFunction(si, 0, 4); /* Lang.parseFloat */
if ( errorCode == ERR_WAE_WMLS_NONE ) {
op1 = RE_Pop( si->RE );
if (op1->type == typeFloat) {
Var_AssignBool( op1, TRUE );
}
else {
Var_AssignBool( op1, FALSE );
}
OpS_Push( si->RE->OpS, &op1 );
return ERR_WAE_WMLS_NONE;
}
else {
return errorCode;
}
}
enumErrorCode Call_Lang_maxInt( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
pstructVar op1 = Var_New();
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
if (op1 == NULL) {
return ERR_WAE_WMLS_LIB;
}
Var_AssignInt( op1, INT32_MAX );
OpS_Push( si->RE->OpS, &op1 );
return ERR_WAE_WMLS_NONE;
}
enumErrorCode Call_Lang_minInt( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
pstructVar op1 = Var_New();
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
if (op1 == NULL) {
return ERR_WAE_WMLS_LIB;
}
Var_AssignInt( op1, INT32_MIN );
OpS_Push( si->RE->OpS, &op1 );
return ERR_WAE_WMLS_NONE;
}
enumErrorCode Call_Lang_Float( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
pstructVar op1 = Var_New();
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
if (op1 == NULL) {
return ERR_WAE_WMLS_LIB;
}
#ifdef HAS_FLOAT
Var_AssignBool( op1, TRUE );
#else
Var_AssignBool( op1, FALSE );
#endif
OpS_Push( si->RE->OpS, &op1 );
return ERR_WAE_WMLS_NONE;
}
enumErrorCode Call_Lang_exit( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
si = si; /* just to get rid of a compiler warning */
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
/* does not have to pop because the argument is the result */
return ERR_WAE_WMLS_EXIT;
}
enumErrorCode Call_Lang_abort( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
/* convert the argument to string */
CallLibraryFunction(si, 2, 14); /* Lang.toString */
/* the errorDescription argument is now the return value */
return ERR_WAE_WMLS_ABORT;
}
/* Help functions to Call_Lang_random */
#ifndef NO_GLOBAL_VARS
static UINT32 lib_rand_table[55];
static BYTE lib_rand_index1;
static BYTE lib_rand_index2;
static BYTE lib_rand_initialized = 0;
#endif
void lib_rand_seed (UINT32 j)
{
UINT32 k = 1;
BYTE i;
BYTE ii;
BYTE loop;
lib_rand_table[54] = j;
for (i = 0; i < 55; i++)
{
ii = 21 * i % 55;
lib_rand_table[ii] = k;
k = j - k;
j = lib_rand_table[ii];
}
for (loop = 0; loop < 4; loop++)
{
for (i = 0; i < 55; i++)
{
lib_rand_table[i] = lib_rand_table[i] - lib_rand_table[(1 + i + 30) % 55];
}
}
lib_rand_index1 = 0;
lib_rand_index2 = 31;
lib_rand_initialized++;
}
UINT32 lib_rand(UINT32 limit)
{
if (!lib_rand_initialized)
{
lib_rand_seed(161803398);
lib_rand_initialized++;
}
lib_rand_index1 = (lib_rand_index1 + 1) % 55;
lib_rand_index2 = (lib_rand_index2 + 1) % 55;
lib_rand_table[lib_rand_index1] = lib_rand_table[lib_rand_index1] - lib_rand_table[lib_rand_index2];
return lib_rand_table[lib_rand_index1] % limit;
}
/* - - - - - - - - - - - - - - - - - */
enumErrorCode Call_Lang_random( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
pstructVar op1 = RE_Pop( si->RE );
INT32 intValue;
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
if (Var_ConvertMethod( CONVERT_INT_FLOAT, op1, NULL )) {
if (op1->type == typeFloat) {
OpS_Push( si->RE->OpS, &op1 );
CallLibraryFunction( si, 1, 0 ); /* Float.int */
op1 = RE_Pop( si->RE );
}
if (op1->type == typeInteger)
{
intValue = op1->val.theInt;
if (intValue > 0)
{
Var_AssignInt( op1, lib_rand(intValue + 1) );
}
else if (intValue < 0)
{
Var_AssignInvalid( op1 );
}
/* else == 0 and then 0 will be the return value */
}
else
{
Var_AssignInvalid( op1 );
}
}
else {
Var_AssignInvalid( op1 );
}
OpS_Push( si->RE->OpS, &op1 );
return ERR_WAE_WMLS_NONE;
}
enumErrorCode Call_Lang_seed( pstructSI si, UINT16 libIndex, UINT8 funcIndex )
{
pstructVar op1 = RE_Pop( si->RE );
INT32 intValue;
libIndex=libIndex; /* just to get rid of a compiler warning */
funcIndex=funcIndex; /* just to get rid of a compiler warning */
if (Var_ConvertMethod( CONVERT_INT_FLOAT, op1, NULL ))
{
if (op1->type == typeFloat)
{
OpS_Push( si->RE->OpS, &op1 );
CallLibraryFunction( si, 1, 0 ); /* Float.int */
op1 = RE_Pop( si->RE );
}
if (op1->type == typeInteger)
{
intValue = op1->val.theInt;
if (intValue >= 0) {
lib_rand_seed( intValue );
}
else
{ /* 000808 (KHN) WAP 1.2.1 update */
lib_rand_seed( CLNTa_currentTime() + lib_rand_initialized );
}
Var_Delete( &op1 );
op1 = Var_New(); /* an empty string (success) */
}
else
{
Var_AssignInvalid( op1 );
}
}
else {
Var_AssignInvalid( op1 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -