示例#1
0
static bool scriptinternalcmd()
{
    bool bContinue = true;
    LINEMAPENTRY cur = linemap.at(scriptIp - 1);
    if(cur.type == linecommand)
    {
        switch(scriptinternalcmdexec(cur.u.command))
        {
        case STATUS_CONTINUE:
            break;
        case STATUS_ERROR:
            bContinue = false;
            GuiScriptError(scriptIp, "Error executing command!");
            break;
        case STATUS_EXIT:
            bContinue = false;
            scriptIp = scriptinternalstep(0);
            GuiScriptSetIp(scriptIp);
            break;
        case STATUS_PAUSE:
            bContinue = false; //stop running the script
            scriptIp = scriptinternalstep(scriptIp);
            GuiScriptSetIp(scriptIp);
            break;
        }
    }
    else if(cur.type == linebranch)
    {
        if(cur.u.branch.type == scriptcall) //calls have a special meaning
            scriptstack.push_back(scriptIp);
        if(scriptinternalbranch(cur.u.branch.type))
            scriptIp = scriptlabelfind(cur.u.branch.branchlabel);
    }
    return bContinue;
}
示例#2
0
void scriptsetip(int line)
{
    if(line)
        line--;
    scriptIp = scriptinternalstep(line);
    GuiScriptSetIp(scriptIp);
}
示例#3
0
static DWORD WINAPI scriptRunThread(void* arg)
{
    int destline = (int)(uint)arg;
    if(!destline || destline > (int)linemap.size()) //invalid line
        destline = 0;
    if(destline)
    {
        destline = scriptinternalstep(destline - 1); //no breakpoints on non-executable locations
        if(!scriptinternalbpget(destline)) //no breakpoint set
            scriptinternalbptoggle(destline);
    }
    bAbort = false;
    if(scriptIp)
        scriptIp--;
    scriptIp = scriptinternalstep(scriptIp);
    bool bContinue = true;
    while(bContinue && !bAbort) //run loop
    {
        bContinue = scriptinternalcmd();
        if(scriptIp == scriptinternalstep(scriptIp)) //end of script
        {
            bContinue = false;
            scriptIp = scriptinternalstep(0);
        }
        if(bContinue)
            scriptIp = scriptinternalstep(scriptIp); //this is the next ip
        if(scriptinternalbpget(scriptIp)) //breakpoint=stop run loop
            bContinue = false;
        Sleep(1); //don't fry the processor
    }
    bIsRunning = false; //not running anymore
    GuiScriptSetIp(scriptIp);
    return 0;
}
示例#4
0
DWORD WINAPI scriptStepThread(void* param)
{
    if(bIsRunning) //already running
        return 0;
    scriptIp = scriptinternalstep(scriptIp - 1); //probably useless
    if(!scriptinternalcmd())
        return 0;
    if(scriptIp == scriptinternalstep(scriptIp)) //end of script
        scriptIp = 0;
    scriptIp = scriptinternalstep(scriptIp);
    GuiScriptSetIp(scriptIp);
    return 0;
}
示例#5
0
DWORD WINAPI scriptRunSync(void* arg)
{
    int destline = (int)(duint)arg;
    if(!destline || destline > (int)linemap.size()) //invalid line
        destline = 0;
    if(destline)
    {
        destline = scriptinternalstep(destline - 1); //no breakpoints on non-executable locations
        if(!scriptinternalbpget(destline)) //no breakpoint set
            scriptinternalbptoggle(destline);
    }
    bAbort = false;
    if(scriptIp)
        scriptIp--;
    scriptIp = scriptinternalstep(scriptIp);
    bool bContinue = true;
    bool bIgnoreTimeout = settingboolget("Engine", "NoScriptTimeout");
    unsigned long long kernelTime, userTime;
    FILETIME creationTime, exitTime; // unused
    while(bContinue && !bAbort) //run loop
    {
        bContinue = scriptinternalcmd();
        if(scriptIp == scriptinternalstep(scriptIp)) //end of script
        {
            bContinue = false;
            scriptIp = scriptinternalstep(0);
        }
        if(bContinue)
            scriptIp = scriptinternalstep(scriptIp); //this is the next ip
        if(scriptinternalbpget(scriptIp)) //breakpoint=stop run loop
            bContinue = false;
        if(bContinue && !bIgnoreTimeout && GetThreadTimes(GetCurrentThread(), &creationTime, &exitTime, reinterpret_cast<LPFILETIME>(&kernelTime), reinterpret_cast<LPFILETIME>(&userTime)) != 0)
        {
            if(userTime + kernelTime >= 10 * 10000000) // time out in 10 seconds of CPU time
            {
                if(GuiScriptMsgyn(GuiTranslateText(QT_TRANSLATE_NOOP("DBG", "The script is too busy. Would you like to terminate it now?"))) != 0)
                {
                    dputs(QT_TRANSLATE_NOOP("DBG", "Script is terminated by user."));
                    break;
                }
                else
                    bIgnoreTimeout = true;
            }
        }
    }
    bIsRunning = false; //not running anymore
    GuiScriptSetIp(scriptIp);
    return 0;
}
示例#6
0
bool scriptcmdexec(const char* command)
{
    switch(scriptinternalcmdexec(command))
    {
    case STATUS_ERROR:
        return false;
    case STATUS_EXIT:
        scriptIp = scriptinternalstep(0);
        GuiScriptSetIp(scriptIp);
        break;
    case STATUS_PAUSE:
    case STATUS_CONTINUE:
        break;
    }
    return true;
}
示例#7
0
static DWORD WINAPI scriptLoadThread(void* filename)
{
    GuiScriptClear();
    GuiScriptEnableHighlighting(true); //enable default script syntax highlighting
    scriptIp = 0;
    std::vector<SCRIPTBP>().swap(scriptbplist); //clear breakpoints
    std::vector<int>().swap(scriptstack); //clear script stack
    bAbort = false;
    if(!scriptcreatelinemap((const char*)filename))
        return 0;
    int lines = (int)linemap.size();
    const char** script = (const char**)BridgeAlloc(lines * sizeof(const char*));
    for(int i = 0; i < lines; i++) //add script lines
        script[i] = linemap.at(i).raw;
    GuiScriptAdd(lines, script);
    scriptIp = scriptinternalstep(0);
    GuiScriptSetIp(scriptIp);
    return 0;
}