At 23:06 03.06.00 +0800, James Henstridge wrote:
>On Sat, 3 Jun 2000, Hans Breuer wrote:
>
>> There is structure packaging with M$VC as well and there is the 
>> #pragma pack directive to fix or produce problems with it.
>
>Generally, it is not a good idea to write structures directly to a file
>unless you will be reading them again on the same architecture.  If you
>are writing cross platform code, it is not really a good idea to rely on
>the structure packing rules of the compiler.
>

Agreed - but: It worked for me (tm). 
Now I've added another indirection to rely less on packing rules.
The remaining assumption are checked with g_assert(s).
The BIG_ENDIAN version should work, but isn't tested due to missing
hardware. 

Is there any (big endian) Dia user out there to test it ?

>> 
>> The main reason it appears to work here: it wasn't used, because it's
>> only needed for single objects with size > 32767 (My test bitmaps
>> were smaller). 
>> I'm still investigating a related documentation problem. There seems 
>> to be no way to detect if a WPGHead16 or WPGHead32 was used, while 
>> reading a wpg file. Maybe the 32 bit version was never used.
>
>The Encyclopedia of Graphics Formats (from oreilly) has a bit of sample
>code for reading the header of a WPG record.  The code looks like it is
>written for dos or windows use, so it requires a little modification to
>work correctly on both little endian and big endian machines (the
>GINT16_{TO,FROM}_LE macros (is it little endian?) should help):
>
>  BYTE RecordType;
>  DWORD RecordLength;
>  FILE *fp;
>
>  RecordType = GetByte(fp);      /* read RecordType */
>  RecordLength = GetByte(fp);    /* read RecordLength */
>  if (RecordLength == 0xFF) {    /* not a BYTE value */
>    RecordLength = GetWord(fp);  /* read next WORD */
>    if (RecordLength & 0x800) {  /* not a WORD value */
                        -----
                        0x8000 is 32768 (WORD is unsigned => 
                                         it is a word value.)

>      RecordLength <<= 16;         /* shift value to high WORD */
>      RecordLength += GetWord(fp); /* read in LOW word value */
>    }
>  }
>
As you may have noticed from the comment in wpg_defs.h, I'm using
the same resource, but for me the provided sample code appears to
be simply wrong.
Further investigation leds to segmentation, uglyness as usual 
on DOS - before the flat memory model was introduced. 
See newest source, if you want to know more ...
At least too large objects (bitmaps) are not saved anymore.
As a result the WPG files are valid but uncomplete.

Newest source is available at:
http://hans.breuer.org/dia/wpg-2000-06-04.zip

        Hans

-------- Hans "at" Breuer "dot" Org -----------
Tell me what you need, and I'll tell you how to 
get along without it.                -- Dilbert

Reply via email to