Announcement

Collapse
No announcement yet.

Strange behavior!

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

  • Strange behavior!

    I have a serious problem!

    I use a function to parse a text file (spearated by semicolon) in one of my projects and it works fine. When I use the same function in an other project with similar file then it doesn't work.

    Code:
     
    
    func LeftTrim(var wpstr)
    
    var lth, bpstrs, bpstrd, fnd, idx;
    
        bpstrs := str_Ptr(wpstr); // Raise string pointer for source string pointer
        bpstrd := bpstrs; // Take copy for destination string pointer
        lth := str_Length(wpstr); // Get length of string
    
        // Move source pointer to first non-space character
        fnd := 0;
        while(str_GetByte(bpstrs + fnd++) == ' ');
    
        // If space found then shift the remaining bytes left to overwrite the spaces
        if(fnd > 0)
            bpstrs := bpstrs + fnd - 1;
            idx := 0;
            repeat
                str_PutByte(bpstrd + idx, str_GetByte(bpstrs + idx));
            until(++idx >= lth);
        endif
    endfunc
    
    
    // Non overlapping byte memory copy
    func ByteCopy(var bpsrc, var bpdst, var bytes)
      var i;
      i := 0;
      repeat
        str_PutByte(bpdst + i, str_GetByte(bpsrc + i));
      until(++i >= bytes);
    endfunc
    
    
    //  Extract next delimited string
    //  bpstr = Byte pointer to user string being extracted from
    //  wpsub = Word pointer to location where user sub string is to be placed
    //  delim = character to use as a delimiter
    //
    func GetNextSub(var wpstr, var wpsub, var delim)
        var delimpos;
    
        if((delimpos := str_Find(&wpstr, &delim<<1)) != 0)
            delimpos := (delimpos - wpstr + 1 ); // Adjust char position (v1.05 PmmC str_Find() workround)
            ByteCopy(wpstr, wpsub<<1, delimpos - 1);
            //mem_Copy(wpstr>>1, wpsub, delimpos - 1);           // Copy string to user sub-string
            str_PutByte(wpsub<<1 + delimpos - 1, 0x00);     // Write null terminator
            wpstr := wpstr + delimpos;
        else
            wpstr := 0;
        endif
    
        return(wpstr);
    endfunc
    
    
    //This is the function that reads a record (recno) from the file
    
    func readCatalog()
    var bpnext; 
    var ind;
    
        file_Rewind(F);
        file_Index(F,0,FILE_RECL,recno+1);
        file_GetS(rec,130,F); Read one line into rec
        ind := 0;
    
        // Point to string to extract sub-strings from
        bpnext := str_Ptr(rec);
        repeat
            if((bpnext:=GetNextSub(bpnext, mysub, ';')) != 0)  //THIS WORKS!
                LeftTrim(mysub):
                to(ObjInfo[ind]); print([STR] mysub);
                ind++;
             else
               print("Error:",[DEC] ind,"\n");
             endif
        until(bpnext == 0);
    endfunc
    And this is the code that doesn't works in the other project.

    Code:
    // Parses menufile
    func BuildMenue(var Level, var item)
    var bpnext; 
    var ind;
    var p;
    var iLevel;
    var iItem;
    var cnt;
    
       ActMnuCnt:=0;
       cnt:=1;
       gfx_Cls();
    
    
    
      // repeat
      //  cnt++;  
        print("Count:",[DEC] cnt,"\n");   //debug
        print("Reclen:",[DEC] FILE_RECL,"\n"); //debug
    
    
        file_Rewind(F);     
        file_Index(F,0,FILE_RECL,cnt);    
        file_GetS(rec,130,F);    
        print([STR] rec,"\n");  //for debugging print the rec
    
    
        ind := 0;
        bpnext := str_Ptr (rec);             
        repeat                                                 
            if((bpnext:=GetNextSub(bpnext, mysub, ";")) != 0)
                LeftTrim(mysub):
                to(MnuInfo[ind]); print([STR] mysub);
                ind++;
            else
              print("ERROR:",[DEC] ind,"\n");  // I ALWAYS GET THIS PRINT
            endif
    
        until(bpnext == 0);
                                                                                
     // until (cnt>MnuMaxCount);
      
    endfunc
    It looks similar and was mostly produced by copy and paste.
    in the line
    if((bpnext:=GetNextSub(bpnext, mysub, ";")) != 0)
    always the result is false and therfor the rec isn't split into its parts.

  • #2


    I found it!

    if((bpnext:=GetNextSub(bpnext, mysub, ';')) != 0)
    instead of
    if((bpnext:=GetNextSub(bpnext, mysub, ";")) != 0)

    No warning from compiler.

    Comment

    Working...
    X