Home AMX User Forum AMX General Discussion

No compiler error? The second switch is with in the same brace as the case's.

DEFINE_FUNCTION fnJSON_Process_Actions(CHAR iAddAction[],CHAR iAction[],CHAR iObjTag[],CHAR iCopy[],INTEGER iFBIndx) 

     {//note iCopy is already a copy duh
     STACK_VAR INTEGER i;
     STACK_VAR INTEGER nLVL;
     STACK_VAR _FB_Single sMyFB;
     STACK_VAR INTEGER nRecognized;
     
     nRecognized = 1;
     nLVL = sSBS.sBrowseState.nLevel;
     
     sMyFB.cTopTag = iAddAction;
     sMyFB.cTag = iAction;
     sMyFB.cObjTag = iObjTag;
     
     WHILE(find_string(iCopy,'":',1))
      {
      STACK_VAR INTEGER nFBS;
      
      sMyFB.cFB_Tag = REMOVE_STRING(iCopy,'":',1);
      sMyFB.cFB_Tag = fnJSON_TrimLeadChars('"}{[,',sMyFB.cFB_Tag);
      sMyFB.cFB_Tag = fnJSON_TrimEndChars('":',sMyFB.cFB_Tag);
      SWITCH(iCopy[1])
           {
           CASE '"':
            {
            GET_BUFFER_CHAR(iCopy);
            nFBS = find_string(iCopy,'"',1);
            if(nFBS)
             {
             sMyFB.cFB_VAL = GET_BUFFER_STRING(iCopy,nFBS);
             sMyFB.cFB_VAL = fnJSON_TrimLeadChars('"',sMyFB.cFB_VAL);
             sMyFB.cFB_VAL = fnJSON_TrimEndChars('"',sMyFB.cFB_VAL);
             }
            }
           CASE '{':
            {
            GET_BUFFER_CHAR(iCopy);
            nFBS = fnJSON_FindEndTag(iCopy,'{','}',1);
            sMyFB.cFB_VAL = GET_BUFFER_STRING(iCopy,nFBS);
            }
           CASE '[':
            {
            nFBS = fnJSON_FindEndTag(iCopy,'[',']',1);
            sMyFB.cFB_VAL = GET_BUFFER_STRING(iCopy,nFBS);
            }
           DEFAULT://an interger?
            {
            STACK_VAR INTEGER n;
            
            nFBS = 0;
            for(n=1;n<=10;n++)
             {
             if(iCopy[n] >= '0' && iCopy[n] <= '9')
                  {
                  nFBS = n;
                  }
             else
                  {
                  BREAK;
                  }
             }
            if(nFBS)
             {
             sMyFB.cFB_VAL = GET_BUFFER_STRING(iCopy,nFBS);
             sMyFB.cFB_VAL = fnJSON_TrimLeadChars('"',sMyFB.cFB_VAL);
             sMyFB.cFB_VAL = fnJSON_TrimEndChars('",',sMyFB.cFB_VAL);
             }
            }
           SWITCH(sMyFB.cFB_Tag)
            {
            CASE 'cmd':        {sLevelList[nLVL].cCmd[iFBIndx] = sMyFB.cFB_VAL;}
            CASE 'params':    {sLevelList[nLVL].cParams[iFBIndx] = sMyFB.cFB_VAL;}
            
            DEFAULT:
             {
             nRecognized = 0;
             fnJSON_DEBUG("'Process_Actions, !!, AddAction-[ ',sMyFB.cTopTag,' ], Action-[ ',sMyFB.cTag,' ], FBTAG-[ ',sMyFB.cFB_Tag,' ], VAL-[ ',sMyFB.cFB_Val,' ], FBIndx-[ ',itoa(iFBIndx),' ] :DEBUG<',ITOA(__LINE__),'>'",3);
             }
            }
           }

      if(length_string(iCopy))
           {
           fnJSON_DEBUG("'Process_Actions, ERROR, AddAction-[ ',sMyFB.cTopTag,' ], Action-[ ',sMyFB.cTag,' ],DUMPING-[ ',iCopy,' ], FBIndx-[ ',itoa(iFBIndx),' ] :DEBUG<',ITOA(__LINE__),'>'",1);
           
           }
      if(nRecognized)
           {
           fnJSON_DEBUG("'Process_Actions, $$, AddAction-[ ',sMyFB.cTopTag,' ], Action-[ ',sMyFB.cTag,' ], FBTAG-[ ',sMyFB.cFB_Tag,' ], VAL-[ ',sMyFB.cFB_Val,' ], FBIndx-[ ',itoa(iFBIndx),' ] :DEBUG<',ITOA(__LINE__),'>'",3);
           nRecognized = 0;
           }
      }
     }

Comments

  • GregGGregG Posts: 251
    I just noticed this a few days ago when someone sent me a bit of code that wouldn't compile and I found they were missing a closing brace at the end of a button event. So I added one and compiled to check it and sent it back. Then realized I didn't add it at the right place and ended up with something like this compiling just fine:
    Button_Event[dvaTPs,nButtons]
    {
        Push:
        {
        Stack_Var Integer nTp
            nTp = Get_Last(dvaTPs)
            Switch(nTp)
            {
                Case 1:
                {
                    send_string 0,'one'
                }
                Case 2:
                {
                    send_string 0,'two'
                }
                send_string 0,'infinity'
            }
        }
    }
    
Sign In or Register to comment.