为什么我的程序一段时间后开始返回错误?

问题描述

好吧,我尝试为用 TIGCC 编写的 TI-89 Titanium 编写显示程序。它按预期工作,但多次移动表达式后,它开始只显示字符串“错误”,可能是由 push_parse_text() 在 try-catch 块中引起的。这是因为我没有从 estack 刷新内存吗?我错过了什么吗?

这是代码(请注意,我没有发布 void DrawExpressionUp() 的实现,因为它几乎与 void DrawExpressionDown() 相同 - 以缩短代码):

    #define USE_TI89              // Compile for TI-89

    #define MIN_AMS 101           // Compile for AMS 1.01 or higher
    #define SAVE_SCREEN           // Save/Restore LCD Contents

    #include <tigcclib.h>         // Include All Header Files
    #include <args.h>         // Include All Header Files
    #include <graph.h>


    enum { Up,Down } Mode;

    const XDownDefault = 10; //Define X boundary for second display row
    const YDownDefault = 50;

    const XUpDefault = 5; //Define X boundary for first display row
    const YUpDefault = 30;



   

   void main(void)
 {

    ESI ap = top_estack; //Initialize ap pointer
    int a = ArgCount();

    int IsStr1 = GetArgType(ap);

    ap = next_expression_index(ap);
    int IsStr2 = GetArgType(ap);

    if (a != 2 || IsStr1 != STR_TAG || IsStr2 != STR_TAG)
    {
        clrscr();
        if (a > 2)
        {
            printf("Too many args!");
        }
        else if (a < 2)
        {
            printf("Too few args!");
        }
        else if (IsStr1 != STR_TAG || IsStr2 != STR_TAG)
        {
            printf("Args must be strings!");
        }

        goto end;

    }
    clrscr();

    ap = top_estack;
    char* text = GetStrnArg(ap);
    char* text2 = GetStrnArg(ap);

    int key = 0;
    int mode = Down;

    int xx = XDownDefault;
    int yy = YDownDefault;



    //First display
    DrawExpressionDown(ap,xx,yy,text2,text); //Display expression first time

    while (1)
    {
        DrawLine(-50,15,200,A_NORMAL); //Draw upper bound line
        DrawLine(-50,93,A_NORMAL); //Draw bottom bound line
        DrawMode(ap,mode);

        key = ngetchx();

        if (key == 344) //Right arrow
        {
            xx += 5;
        }
        else if (key == 338) //Left arrow
        {
            xx -= 5;
        }
        else if (key == 4440) //Right arrow + 2ND
        {
            xx += 15;
        }
        else if (key == 4434) //Left arrow + 2ND
        {
            xx -= 15;
        }
        else if (key == 337) //Up arrow
        {
            yy -= 5;
        }
        else if (key == 340) //Down arrow
        {
            yy += 5;
        }
        else if (key == 4433) //Up arrow + 2ND
        {
            yy -= 15;
        }
        else if (key == 4436) //Down arrow + 2ND
        {
            yy += 15;
        }
        else if (key == 16721) //Up arrow + diamond !Change mode!
        {
            mode = Up; //Change mode to up
            xx = XUpDefault;
            yy = YUpDefault;
        }
        else if (key == 16724) //Down arrow + diamond !Change mode!
        {
            mode = Down; //Change mode to down
            xx = XDownDefault;
            yy = YDownDefault;
        }
        else if (key == KEY_ESC)
        {
            break; //Exit from program
        }

        //Check which mode we are in (by default we are in Down mode - controlling bottom display line)
        if (mode == Up)
        {

            DrawExpressionUp(ap,text); //Draw method when controlling upper display line
        }
        else
        {
            DrawExpressionDown(ap,text); //Draw method when controlling bottom display 
            //line
        }

    }

    end:
    ngetchx();
 }


   

    void DrawMode(ESI ap,int mode)
     {

    if (mode == Up)
    {
        ScrRectFill(&(SCR_RECT) { {0,85,90} },& (SCR_RECT){ {0,90}},A_REVERSE); //Blank 
        //filled rectangle

        ap = top_estack;
        TRY
            push_END_TAG();
        push_parse_text("1");
        Print2DExpr(Parse2DExpr(top_estack,TRUE),DeskTop,85);
        ONERR
            printf("Error!");
        ENDTRY
    }
    else
    {
        ScrRectFill(&(SCR_RECT) { {0,A_REVERSE); //Blank filled rectangle

        ap = top_estack;
        TRY
            push_END_TAG();
        push_parse_text("2");
        Print2DExpr(Parse2DExpr(top_estack,85);
        ONERR
            printf("Error!");
        ENDTRY
    }

 }





    void DrawExpressionDown(ESI ap,int xx,int yy,char* text2,char* text)
      {
    
     //Draw expression

    ap = top_estack;
    TRY
        push_END_TAG();
    push_parse_text(text2);
    WinClr(DeskTop);
    Print2DExpr(Parse2DExpr(top_estack,yy);
    ONERR
        text2 = "Error parsing";
    ENDTRY

        ScrRectFill(&(SCR_RECT) { {0,170,35} },35}},A_REVERSE); //Blank filled rectangle

    ap = top_estack;
    TRY
        push_END_TAG();
    push_parse_text(text);
    Print2DExpr(Parse2DExpr(top_estack,XUpDefault,YUpDefault);
    ONERR
        text = "Error parsing";
    ENDTRY

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...