wmlslib.c

来自「WAP browser is based on the Wireless App」· C语言 代码 · 共 625 行 · 第 1/2 页

C
625
字号
    rs->type = scriptTypeFloat;
    MathLibSqrt(gP->MathLibRef, p->value.f, &rs->value.f);//rs->value.f = sqrt(p->value.f);
    return 0;
}

// <number> Float.maxFloat()
//
static Err Float_maxFloat(ScriptLibGlobals *gP, ScriptSlot *sp, ScriptSlot *rs)
{
    //rs->type = scriptTypeInteger;//scriptTypeInvalid;
    //rs->value.n = FLP_MAX;
    rs->type = scriptTypeFloat;//scriptTypeInvalid;
    rs->value.f = 3.40282347E+38;//FLP_MAX;
    return 0;
}

// <number> Float.minFloat()
//
static Err Float_minFloat(ScriptLibGlobals *gP, ScriptSlot *sp, ScriptSlot *rs)
{
    //rs->type = scriptTypeInteger;//scriptTypeInvalid;
    //rs->value.n = FLP_MIN;
    rs->type = scriptTypeFloat;
    rs->value.f = 1.17549435E-38;//FLP_MIN;
    return 0;
}


//////////////////////////////////////////////////////////////////////////////////
// String

// <number> String.length(<string>)
//
static Err String_length(ScriptSlot *sp, ScriptSlot *rs)
{
    SlotToString(sp);

    if(sp->type == scriptTypeString)
    {
        rs->type = scriptTypeInteger;
        rs->value.n = sp->value.s ? StrLen(sp->value.s) : 0;
    }
    else
        rs->type = scriptTypeInvalid;

    return 0;
}

// <number> String.isEmpty(<string>)
//
static Err String_isEmpty(ScriptSlot *sp, ScriptSlot *rs)
{
    SlotToString(sp);

    if(sp->type == scriptTypeString)
    {
        rs->type = scriptTypeBoolean;
        rs->value.n = (sp->value.s && StrLen(sp->value.s)) ? WMLS_TRUE : WMLS_FALSE;
    }
    else
        rs->type = scriptTypeInvalid;

    return 0;
}

// <string> String.charAt(<string>, <number>)
//
static Err String_charAt(ScriptSlot *sp, ScriptSlot *rs)
{
    ScriptSlot *p1 = SlotToString(sp + 1);
    ScriptSlot *p2 = SlotToInteger(sp);

    if(p1->type == scriptTypeString && p2->type == scriptTypeInteger)
    {
        rs->type = scriptTypeString;
        rs->value.s = (p1->value.s && p2->value.n >= 0 && p2->value.n < StrLen(p1->value.s)) ?
            ScriptStrCopyEx(p1->value.s + p2->value.n, 1) : NULL;
    }
    else
        rs->type = scriptTypeInvalid;

    return 0;
}

// <string> String.subString(<string>, <number>, <number>)
//
static Err String_subString(ScriptSlot *sp, ScriptSlot *rs)
{
    // TODO: implement me!!!
    return scriptErrNotImplemented;
}

// <number> String.find(<string>, <string>)
//
static Err String_find(ScriptSlot *sp, ScriptSlot *rs)
{
    // TODO: implement me!!!
    return scriptErrNotImplemented;
}

// <string> String.replace(<string>, <string>, <string>)
//
static Err String_replace(ScriptSlot *sp, ScriptSlot *rs)
{
    // TODO: implement me!!!
    return scriptErrNotImplemented;
}

// <number> String.elements(<string>, <string>)
//
static Err String_elements(ScriptSlot *sp, ScriptSlot *rs)
{
    // TODO: implement me!!!
    return scriptErrNotImplemented;
}

// <string> String.elementAt(<string>, <number>, <string>)
//
static Err String_elementAt(ScriptSlot *sp, ScriptSlot *rs)
{
    // TODO: implement me!!!
    return scriptErrNotImplemented;
}

// <string> String.removeAt(<string>, <number>, <string>)
//
static Err String_removeAt(ScriptSlot *sp, ScriptSlot *rs)
{
    // TODO: implement me!!!
    return scriptErrNotImplemented;
}

// <string> String.replaceAt(<string>, <string>, <number>, <string>)
//
static Err String_replaceAt(ScriptSlot *sp, ScriptSlot *rs)
{
    // TODO: implement me!!!
    return scriptErrNotImplemented;
}

// <string> String.insertAt(<string>, <string>, <number>, <string>)
//
static Err String_insertAt(ScriptSlot *sp, ScriptSlot *rs)
{
    // TODO: implement me!!!
    return scriptErrNotImplemented;
}

// <string> String.squeeze(<string>)
//
static Err String_squeeze(ScriptSlot *sp, ScriptSlot *rs)
{
    // TODO: implement me!!!
    return scriptErrNotImplemented;
}

// <string> String.trim(<string>)
//
static Err String_trim(ScriptSlot *sp, ScriptSlot *rs)
{
    // TODO: implement me!!!
    return scriptErrNotImplemented;
}

// <number> String.compare(<string>, <string>)
//
static Err String_compare(ScriptSlot *sp, ScriptSlot *rs)
{
    ScriptSlot *p1 = SlotToString(sp + 1);
    ScriptSlot *p2 = SlotToString(sp);

    if(p1->type == scriptTypeString && p2->type == scriptTypeString)
    {
        rs->type = scriptTypeInteger;
        rs->value.n = StrCompare(p1->value.s ? p1->value.s : "", p2->value.s ? p2->value.s : "");
    }
    else
        rs->type = scriptTypeInvalid;

    return 0;
}

// <string> String.toString(<any>)
//
static Err String_toString(ScriptSlot *sp, ScriptSlot *rs)
{
    SlotToString(sp);

    rs->value.a = sp->value.a;
    rs->type    = sp->type;
    sp->type    = scriptTypeInvalid;
    return 0;
}

// <string> String.format(<string>, <any>)
//
static Err String_format(ScriptSlot *sp, ScriptSlot *rs)
{
    // TODO: implement me!!!
    return scriptErrNotImplemented;
}

// <string> String.replaceChars(<string>, <string>, <number>)
//
static Err String_replaceChars(ScriptSlot *sp, ScriptSlot *rs)
{
    ScriptSlot *p1 = SlotToString(sp + 2);
    ScriptSlot *p2 = SlotToString(sp + 1);
    ScriptSlot *p3 = SlotToInteger(sp);

    if(p1->type == scriptTypeString &&
       p2->type == scriptTypeString &&
       p3->type == scriptTypeInteger)
    {
        Int32 l1, l2;

        if(p1->value.s && p2->value.s && (l1 = (Int32)StrLen(p1->value.s) - p3->value.n - 1) > 0)
        {
            l2 = StrLen(p2->value.s);

            StrNCopy(p1->value.s + p3->value.n, p2->value.s, MIN(l1, l2));
        }

        // move value to result
        rs->value.a = p1->value.a;
        rs->type    = p1->type;
        p1->type    = scriptTypeInvalid;
    }
    else
        rs->type = scriptTypeInvalid;

    return 0;
}


//////////////////////////////////////////////////////////////////////////////////
// Standard built-in library API table initialization

Err ScriptStdFuncCall(ScriptLibGlobals *gP, UInt16 lindex, UInt8 findex, UInt16 *argcP, ScriptSlot *sp, ScriptSlot *rp)
{
    Err err;

    switch(lindex)
    {
    case 0:
        switch(findex)
        {
        case  0: *argcP = 1; err = Lang_abs(sp, rp); break;
        case  1: *argcP = 2; err = Lang_min(sp, rp); break;
        case  2: *argcP = 2; err = Lang_max(sp, rp); break;
        case  3: *argcP = 1; err = Lang_parseInt(sp, rp); break;
        case  4: *argcP = 1; err = Lang_parseFloat(sp, rp); break;
        case  5: *argcP = 1; err = Lang_isInt(sp, rp); break;
        case  6: *argcP = 1; err = Lang_isFloat(sp, rp); break;
        case  7: *argcP = 0; err = Lang_maxInt(sp, rp); break;
        case  8: *argcP = 0; err = Lang_minInt(sp, rp); break;
        case  9: *argcP = 0; err = Lang_float(sp, rp); break;
        case 10: *argcP = 1; err = Lang_exit(sp, rp); break;
        case 11: *argcP = 1; err = Lang_abort(sp, rp); break;
        case 12: *argcP = 1; err = Lang_random(sp, rp); break;
        case 13: *argcP = 1; err = Lang_seed(sp, rp); break;
        case 14: *argcP = 0; err = Lang_characterSet(sp, rp); break;
        default: return scriptErrFunctionNotFound;
        }
        break;

    case 1:
        switch(findex)
        {
        case  0: *argcP = 1; err = Float_int(gP, sp, rp); break;
        case  1: *argcP = 1; err = Float_floor(gP, sp, rp); break;
        case  2: *argcP = 1; err = Float_ceil(gP, sp, rp); break;
        case  3: *argcP = 2; err = Float_pow(gP, sp, rp); break;
        case  4: *argcP = 1; err = Float_round(gP, sp, rp); break;
        case  5: *argcP = 1; err = Float_sqrt(gP, sp, rp); break;
        case  6: *argcP = 0; err = Float_maxFloat(gP, sp, rp); break;
        case  7: *argcP = 0; err = Float_minFloat(gP, sp, rp); break;
        default: return scriptErrFunctionNotFound;
        }
        break;

    case 2:
        switch(findex)
        {
        case  0: *argcP = 1; err = String_length(sp, rp); break;
        case  1: *argcP = 1; err = String_isEmpty(sp, rp); break;
        case  2: *argcP = 2; err = String_charAt(sp, rp); break;
        case  3: *argcP = 3; err = String_subString(sp, rp); break;
        case  4: *argcP = 2; err = String_find(sp, rp); break;
        case  5: *argcP = 3; err = String_replace(sp, rp); break;
        case  6: *argcP = 2; err = String_elements(sp, rp); break;
        case  7: *argcP = 3; err = String_elementAt(sp, rp); break;
        case  8: *argcP = 3; err = String_removeAt(sp, rp); break;
        case  9: *argcP = 4; err = String_replaceAt(sp, rp); break;
        case 10: *argcP = 4; err = String_insertAt(sp, rp); break;
        case 11: *argcP = 1; err = String_squeeze(sp, rp); break;
        case 12: *argcP = 1; err = String_trim(sp, rp); break;
        case 13: *argcP = 2; err = String_compare(sp, rp); break;
        case 14: *argcP = 1; err = String_toString(sp, rp); break;
        case 15: *argcP = 2; err = String_format(sp, rp); break;
        case 16: *argcP = 3; err = String_replaceChars(sp, rp); break;
        default: return scriptErrFunctionNotFound;
        }
        break;

    default:
        return scriptErrLibraryNotFound;
    }

    return err;
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?