From: Jongware on
On 26-Jul-10 14:21 PM, Franz Bachler wrote:
> Hello,
>
> here's the DOC-Checking-Program.
>
<code snipped>

Excellent! I didn't compile it ;-) but it looks like it does the job.
I see you are checking the first 4K -- a good idea, I don't know how
much variation there is in the OLE header length.

A couple of possible improvements:

Your default char type seems to be unsigned. It would be safer to
declare the 'raw byte' values as unsigned char instead.

Your nfibsearch function could return a status (0 for error, -1 for ok;
or alternatively, 0 for error, >0 for an exact version identifier (or
some other scheme).

Rather than a long list of if..thens for all possible cases, you could have:
(a) used a switch .. case

switch ( ((unsigned char)(szPuffer[i+3]))<<8)+( (unsigned
char)(szPuffer[i+2])) )
{
case 0x21: strcpy(szId, "00 21"); strcpy(szVer, "1.0"); break;
.. (etc.)
default:
return 0; /* Error */
}

or possibly
(b) define a structure of IDs + version strings, like this:
struct {
unsigned short id;
char *version;
} WordVersion_t wordVersion[] = {
0x21, "WinWord 1.0",
0x23, "WinWord 2.0",
... (etc.)
};

-- the advantage of using a structure over code is it's easier to maintain.

Thanks for posting the code!

[Jw]
First  |  Prev  | 
Pages: 1 2
Prev: Shortcut to an URL
Next: U++ Tutoring Plan