wmlslib.c
来自「WAP browser is based on the Wireless App」· C语言 代码 · 共 625 行 · 第 1/2 页
C
625 行
/*
* Copyright (c) 2004, TapTarget. All rights reserved.
* Copyright (c) 2002-2004, Yuri Plaksyuk (york@noir.crocodile.org).
*
* http://www.taptarget.com/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* - All advertising materials mentioning features or use of this
* software must display the following acknowledgement: This
* product includes software developed by TapTarget.
*
* - The name of TapTarget may not be used to endorse or
* promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TAPTARGET "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL TAPTARGET BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: wmlslib.c,v 1.2 2004/04/21 16:28:36 york Exp $
*/
#include "wmls.h"
#include "MathLib.h"
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
//////////////////////////////////////////////////////////////////////////////////
// Lang
// <number> Lang.abs(<number>)
//
static Err Lang_abs(ScriptSlot *sp, ScriptSlot *rs)
{
SlotToInteger(sp);
rs->type = sp->type;
rs->value.n = (sp->value.n >= 0) ? sp->value.n : -sp->value.n;
return 0;
}
// <number> Lang.min(<number>, <number>)
//
static Err Lang_min(ScriptSlot *sp, ScriptSlot *rs)
{
SlotToInteger(sp);
SlotToInteger(sp + 1);
if(sp->type == scriptTypeInteger && (sp + 1)->type == scriptTypeInteger)
{
rs->type = scriptTypeInteger;
rs->value.n = (sp->value.n < (sp + 1)->value.n) ? sp->value.n : (sp + 1)->value.n;
}
else
rs->type = scriptTypeInvalid;
return 0;
}
// <number> Lang.max(<number>, <number>)
//
static Err Lang_max(ScriptSlot *sp, ScriptSlot *rs)
{
SlotToInteger(sp);
SlotToInteger(sp + 1);
if(sp->type == scriptTypeInteger && (sp + 1)->type == scriptTypeInteger)
{
rs->type = scriptTypeInteger;
rs->value.n = (sp->value.n > (sp + 1)->value.n) ? sp->value.n : (sp + 1)->value.n;
}
else
rs->type = scriptTypeInvalid;
return 0;
}
// <number> Lang.parseInt(<string>)
//
static Err Lang_parseInt(ScriptSlot *sp, ScriptSlot *rs)
{
SlotToInteger(sp);
SlotMove(rs, sp);
return 0;
}
// <number> Lang.parseFloat(<string>)
//
static Err Lang_parseFloat(ScriptSlot *sp, ScriptSlot *rs)
{
SlotToFloat(sp);
SlotMove(rs, sp);
return 0;
}
// <boolean> Lang_isInt(<any>)
//
static Err Lang_isInt(ScriptSlot *sp, ScriptSlot *rs)
{
if(sp->type != scriptTypeInvalid)
{
rs->type = scriptTypeBoolean;
rs->value.n = (sp->type == scriptTypeInteger) ? WMLS_TRUE : WMLS_FALSE;
}
else
{
rs->type = scriptTypeInvalid;
}
return 0;
}
// <boolean> Lang_isFloat(<any>)
//
static Err Lang_isFloat(ScriptSlot *sp, ScriptSlot *rs)
{
if(sp->type != scriptTypeInvalid)
{
rs->type = scriptTypeBoolean;
rs->value.n = (sp->type == scriptTypeFloat) ? WMLS_TRUE : WMLS_FALSE;
}
else
{
rs->type = scriptTypeInvalid;
}
return 0;
}
// <number> Lang.maxInt()
//
static Err Lang_maxInt(ScriptSlot *sp, ScriptSlot *rs)
{
rs->type = scriptTypeInteger;
rs->value.n = 0x7FFFFFFFL;
return 0;
}
// <number> Lang.minInt()
//
static Err Lang_minInt(ScriptSlot *sp, ScriptSlot *rs)
{
rs->type = scriptTypeInteger;
rs->value.n = 0x80000000L;
return 0;
}
// <boolean> Lang.float()
//
static Err Lang_float(ScriptSlot *sp, ScriptSlot *rs)
{
rs->type = scriptTypeBoolean;
rs->value.n = WMLS_TRUE;//WMLS_FALSE;
return 0;
}
// <none> Lang.exit(<any>)
//
static Err Lang_exit(ScriptSlot *sp, ScriptSlot *rs)
{
return scriptErrExited;
}
// <none> Lang.abort(<any>)
//
static Err Lang_abort(ScriptSlot *sp, ScriptSlot *rs)
{
return scriptErrAborted;
}
// <number> Lang.random(<number>)
//
static Err Lang_random(ScriptSlot *sp, ScriptSlot *rs)
{
SlotToInteger(sp);
if(sp->type == scriptTypeInteger)
{
if(sp->value.n > 0)
{
Int32 v1 = SysRandom(0);
Int32 v2 = SysRandom(0);
rs->type = scriptTypeInteger;
rs->value.n = ((v1 << 15) ^ v2) % (sp->value.n + 1);
return 0;
}
}
rs->type = scriptTypeInvalid;
return 0;
}
// <string> Lang.seed(<number>)
//
static Err Lang_seed(ScriptSlot *sp, ScriptSlot *rs)
{
SlotToInteger(sp);
if(sp->type == scriptTypeInteger)
{
SysRandom((sp->value.n >= 0) ? sp->value.n : TimGetSeconds());
rs->type = scriptTypeString;
rs->value.s = NULL;
}
else
rs->type = scriptTypeInvalid;
return 0;
}
// <number> Lang.characterSet()
//
static Err Lang_characterSet(ScriptSlot *sp, ScriptSlot *rs)
{
rs->type = scriptTypeInteger;
rs->value.n = 4; // latin1
return 0;
}
//////////////////////////////////////////////////////////////////////////////////
// Float
// <number> Float.int(<number>)
//
static Err Float_int(ScriptLibGlobals *gP, ScriptSlot *sp, ScriptSlot *rs)
{
ScriptSlot *p = SlotToInteger(sp);
rs->type = scriptTypeInteger;
rs->value.n = p->value.n;
//rs->type = scriptTypeInvalid;
return 0;
}
// <number> Float.floor(<number>)
//
static Err Float_floor(ScriptLibGlobals *gP, ScriptSlot *sp, ScriptSlot *rs)
{
ScriptSlot *p = SlotToFloat(sp);
//rs->type = scriptTypeFloat;
//rs->value.f = floor(p->value.f);
rs->type = scriptTypeFloat;
MathLibFloor(gP->MathLibRef, p->value.f, &rs->value.f);//rs->value.n = floor(p->value.f);
return 0;
}
// <number> Float.ceil(<number>)
//
static Err Float_ceil(ScriptLibGlobals *gP, ScriptSlot *sp, ScriptSlot *rs)
{
ScriptSlot *p = SlotToFloat(sp);
//rs->type = scriptTypeFloat;
//rs->value.f = ceil(p->value.f);
rs->type = scriptTypeFloat;
MathLibCeil(gP->MathLibRef, p->value.f, &rs->value.f);//rs->value.n = ceil(p->value.f);
return 0;
}
// <number> Float.pow(<number>, <number>)
//
static Err Float_pow(ScriptLibGlobals *gP, ScriptSlot *sp, ScriptSlot *rs)
{
ScriptSlot *p1 = SlotToFloat(sp + 1);
ScriptSlot *p2 = SlotToFloat(sp);
rs->type = scriptTypeFloat;
//rs->value.f = pow(p1->value.f, p2->value.f);
MathLibPow(gP->MathLibRef, p1->value.f, p2->value.f, &rs->value.f);
return 0;
}
// <number> Float.round(<number>)
//
static Err Float_round(ScriptLibGlobals *gP, ScriptSlot *sp, ScriptSlot *rs)
{
rs->type = scriptTypeInvalid;
return 0;
}
// <number> Float.sqrt(<number>)
//
static Err Float_sqrt(ScriptLibGlobals *gP, ScriptSlot *sp, ScriptSlot *rs)
{
ScriptSlot *p = SlotToFloat(sp);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?