Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Fgets
Message
De
02/08/2001 22:46:16
Kenneth Downs
Secure Data Software, Inc.
New York, États-Unis
 
 
À
01/08/2001 15:56:23
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Re: Fgets
Divers
Thread ID:
00538523
Message ID:
00539213
Vues:
9
William,

There are several ways to get around FGETS(), as I recall from my old job. You get a limit of 254 bytes in VFP 6 prior to SP3, and 8192 bytes after SP3. Nevertheless, I just hated to rely on it.

Different tricks work in different situations, but stay away from the tempting ALINES(FILETOSTR()) combo, as ALINES() drops blank lines. If you actually want to drop blanks, then it is fine, but the next gotcha is the limit of 65,000 or so memory variables, which translates into 65,000 array elements, or 65,000 lines of text.

One approach I used was to replace FGETS with my own. This slows performance and the source is back at my old job, but it works. I will try to reconstruct a little from memory here:
PROCEDURE sysFGets
LPARAM lnFileHandle,@pcBuffer,@FlagEOF

LOCAL lcRetVal,lnAT
lnBuffer = 10000  &&--bytes read in on each FREAD
lnLimit  = 1000   &&--minimum left to process before another FREAD

IF LEN(gcBuffer) < lnLimit AND NOT FEOF(lnFileHandle)
  pcBuffer = pcBuffer + FREAD(lnFileHandle,lnBuffer)

  *  With our luck, we'd split a CR/LF pair and fudge
  *  things up, so better safe than sorry
  IF RIGHT(pcBuffer,2) = CHR(13) + CHR(10) AND FEOF(lnFileHandle)
    pcBuffer = pcBuffer + FREAD(lnFileHandle,3)
  ENDIF
ENDIF

* Get the position of CR/LF.  Assume that we
*  always have CR/LF together, or monkey up code
*  to account for just one or the other. 
lnAT = AT(CHR(13),pcBuffer)
lcRetVal = LEFT(pcBuffer,lnAT-1)

*  Either flip FEOF flag or snip off the text we returned
IF lnAT = LEN(pcBuffer) - 1
  FlagFEOF = .t.
ELSE
  pcBuffer = SUBS(pcBuffer,lnAT+2)  &&-- assuming CR/LF pair
ENDIF

RETURN lcRetVal
Well, I'm sure I've missed more than one something, as it's been awhile, but that is the gist of it. Hope this helps.


>Has anyone had a problem with fgets(). We have a program that goes through a text file and sets the length of the string to 500.
>
>The problem is the function FGETS() function is only pulling 238 characters, but when you use the LEN() function in FOX it says the length is 500. The characters after 238 are geting truncated.
>
>Does fgets have a bug!!!
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform