WWFixed, Size of File

Edward Di Geronimo Jr. (edwdig@bergen.gov)
Sat, 29 Jun 1996 12:24:02 -0400

I took Nate's Text Editor code and I'm playing with it, trying to get some
kind of formatting on the text you're editing. Right now I'm just trying to
get some basic HTML codes to work, as that was the easiest thing I could
think of to get started. Later I want to move to source code formatting, but
I thought I understood WWFixed better than ColorQuads, so I tried to do
something useful with <Hx> tags. Anyway, I'm putting this in the beginning
of DOCUMENT.GOC, after the includes. The compiler is complaining about every
line I put in here after the declarations. It complains:

Error DOCUMENT.GOC 40: Type mismatch in redeclaration of 'currentPoint'
Error DOCUMENT.GOC 40: Declaration syntax error

Every other line I printed gets the same errors. It stops because of too
many errors because of these statements. What am I doing wrong? As I don't
have my own SDK yet I can't look things up, and Clemens is doing the
compiling for me, so I can't do a million tests.

#define DEFAULT_SIZE 12

WWFixed currentPoint, header[6];
currentPoint.WWF_int = DEFAULT_SIZE;
currentPoint.WWF_frac = 0;

header[1].WWF_int = DEFAULT_SIZE + 1;
header[2].WWF_int = DEFAULT_SIZE + 2;
header[3].WWF_int = DEFAULT_SIZE + 3;
header[4].WWF_int = DEFAULT_SIZE + 4;
header[5].WWF_int = DEFAULT_SIZE + 5;
header[6].WWF_int = DEFAULT_SIZE + 6;

header[1].WWF_frac = 0;
header[2].WWF_frac = 0;
header[3].WWF_frac = 0;
header[4].WWF_frac = 0;
header[5].WWF_frac = 0;
header[6].WWF_frac = 0;

Also, I want to send the entire file at once to ProcessString. This is what
I'm doing now. Basically, I read through the file a kb at time and total up
the number of bytes read until it doesn't read any more. Then I deallocate
dataBlockPointer and reallocate it to the size read from the file. I then
move to the beginning of the file and reread it all at once. There's got to
be an easier way. Basically, what I need is a call to find out the size of
the file. Any ideas to improve this?

dataBlockHandle = MemAlloc( DOC_BLOCK_SIZE, HF_SWAPABLE, 0 );
dataBlockPtr = (char*)MemLock( dataBlockHandle );

totalCharsRead = 0;

do { /* Find out file size */
numCharsRead = FileRead( file_p, dataBlockPtr, DOC_BLOCK_SIZE, FALSE );
if ( numCharsRead <= DOC_BLOCK_SIZE ) {
/* the old call - ProcessString( numCharsRead, ourText_p, dataBlockPtr ); */
totalCharsRead += numCharsRead;
}
} while( numCharsRead == DOC_BLOCK_SIZE );

MemFree( dataBlockHandle ); /* Unallocate the data block */

/*Reallocate a block big enough to hold the entire file*/

dataBlockHandle = MemAlloc( totalCharsRead, HF_SWAPABLE, 0 );
dataBlockPtr = (char*)MemLock( dataBlockHandle );

FilePos( file_p, 0L, FILE_POS_START ); /* Move back to the beginning */
/* of the file */

/* Process the entire file at once */

numCharsRead = FileRead( file_p, dataBlockPtr, totalCharsRead, FALSE );
ProcessString( numCharsRead, ourText_p, dataBlockPtr );

- -------------------------------------------------------------------
| "You never really understand a person until you consider things |
| from his point of view----until you climb into his skin and |
| walk around in it." |
| -- Atticus Finch, Harper Lee's "To Kill a Mockingbird" |
- -------------------------------------------------------------------
| Edward Di Geronimo Jr. edwdig@bergen.gov |
- -------------------------------------------------------------------