Announcement

Collapse
No announcement yet.

this string parsing code USED to work in 2011 ...same code today, does not

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • this string parsing code USED to work in 2011 ...same code today, does not

    title kind of says it. Now how do I fix it. Seems str_Match has changed how it does things.

    Code:
    #platform "Gen4-uLCD-32PT"
    
    #STACK 500
    var P_unit_start[5];
    
    func fieldg(var buf, var field_no, var seperator, var my_field_ptr,var b_size)
        var char, char_p, my_f, dex,  m_error;
    
        char := str_Ptr( buf );
        my_f := str_Ptr( my_field_ptr );
        mem_Set(my_field_ptr, 0, b_size);                    // clear the buffer
        char_p := 1;
    
        for(dex := 1; (dex < field_no) && (char_p != 0); dex++) // find seperator n
            char_p := str_Match( &char, &seperator );
        next
    
        if(char_p == 0)
            m_error := 1;
        else
            while(str_GetByte(char) != seperator)
                str_CatN(my_f, char,1);
                char++;
            wend
        endif
        return m_error;
    endfunc
    
    func Get_Punit()
    
        var my_buff[25];
        var my_field[10];
        var ptr1;
        var ptr2;
                                                                                                          
        mem_Set(my_buff, 0, 50);                  // init the buffer
        mem_Set(my_field, 0, 20);                 // init the buffer
        ptr1 := str_Ptr(my_field);
        ptr2 := str_Ptr(my_field);
    
        to(my_buff); print("one|two|three|four|five|six|seven|eight");
    
        if(fieldg(my_buff,2,'|',my_field,sizeof(my_buff)))
            mem_Set(P_unit_start, 0, sizeof(P_unit_start));        // init the buffer
            to(P_unit_start); print([STR]my_field);
        else
            print("not found");
        endif
    endfunc
    
    func setup()
        gfx_Set(SCREEN_MODE, LANDSCAPE);
        gfx_Cls();
    endfunc
    func main()
        setup();
        Get_Punit();
        print("p_unit=",[STR]P_unit_start, "\n");
    repeat
    forever
    endfunc

    Last edited by Dancy; 22 March 2018, 11:14 AM.

  • #2
    You mean as per the documented fix in PmmC 4.3? https://www.4dsystems.com.au/downloa...leaseNotes.txt

    Maybe you want to use str_Find()?
    Mark

    Comment


    • #3
      Perhaps I missed something in my program (it's quite large) but when compiled for a µLCD-32PT(SGC) using 4D_WS3_rev3.1.0.14 back in 2011-2012, I fielded roughly ten systems to customers and all are working today. When that same code is compiled for a Gen4-uLCD-32PT using WORKSHOP4 INSTALLER.4.5.0.17b the system no longer functions properly. In tracing the problem down, one of the areas failing is the above posted string parsing function. I know I am missing SOME key item or syntax but I have not been able to identify where. I also re-wrote the parser using different functions (posted in an adjacent thread)
      https://forum.4dsystems.com.au/forum...orks-sometimes
      The new function behaves as though there is a memory leak somewhere. It will fail simply by commenting out an un-used variable.

      My question is in asking if you see anything in either code body I am missing that may be obvious to you.

      Dan

      edit. I did just check the release note. I had a ref to srt_Match().
      "Fixed str_Match(+I) matching DEF to ABCDEF" ....sorry! have no idea what that means
      Last edited by Dancy; 23 March 2018, 11:11 AM.

      Comment


      • #4
        str_Match, used to function like a 'string find' back in 2012, it was fixed in the 4.3 PmmC to be a proper str_Match (i.e. like a 'string compare').

        Your original code was probably written for a pre 4.3 PmmC and your new displays have a newer PmmC and that is why they no longer work.

        So the suggestion was to change your code so that it uses str_Find where it formerly used str_Match, unless, in some places it was using str_Match correctly.
        Mark

        Comment

        Working...
        X