@@ -188,7 +188,7 @@ int main( int argc, char *argv[] )
188188 printf ("Need: short=%d int=%d long=%d long long=%d bytes\n" ,2 ,4 ,4 ,8 );
189189 exit (1 );
190190 }
191-
191+
192192 /*printf("Sizeof qwhs = %d\n",sizeof(qwhs));*/
193193
194194 /******************************************************************/
@@ -448,39 +448,50 @@ int main( int argc, char *argv[] )
448448 if (recordType == 116 || recordType == 115 )
449449 {
450450 /*******************************************************************/
451- /* The first triplet past the standard header points at a */
451+ /* The first triplet past the standard header usually points at a */
452452 /* QWHS structure. */
453453 /* */
454454 /* This has various pieces of information about the record. */
455455 /* Most important here is to say how many data sections are */
456456 /* in it, which says how many further triplets should be */
457- /* used. */
457+ /* used. If there is no valid QWHS, then we assume that there */
458+ /* is only one further triplet so force that value. */
458459 /* */
459460 /* Also pick up the STCK value that may be useful */
460461 /* for sorting. */
461462 /*******************************************************************/
462463 p = & dataBuf [conv32 (pSMFRecord -> s [0 ].offset )];
463- pqwhs = (qwhs * )p ;
464- sectionCount = pqwhs -> qwhsnsda [0 ];
465- strcpy (commonF .stckFormat ,convDate (pqwhs -> qwhsstck ));
466- if (recordType == 115 )
464+ if (conv16 (pSMFRecord -> s [0 ].l ) == 4 ) /* There is no QWHS */
467465 {
468- if (conv16 (pqwhs -> qwhslen ) >= 52 )
469- {
470- /* This structure changes size on different platforms because */
471- /* of how the compiler deals with bitfields. So have to do it */
472- /* explicitly with known offsets after the structure changes. */
473- char * t = (char * )& (pqwhs -> qwhsflag1 );
474- t += 4 ;
475- memcpy (& commonF .intstart ,t ,8 );
476- t += 8 ;
477- memcpy (& commonF .intduration ,t ,8 );
478- }
479- else
466+ sectionCount = 2 ; /* 1 extra triplet beyond the QWHS location */
467+ pqwhs = NULL ;
468+ commonF .intstart = 0 ;
469+ commonF .intduration = 0 ;
470+ }
471+ else
472+ {
473+ pqwhs = (qwhs * )p ;
474+ sectionCount = pqwhs -> qwhsnsda [0 ];
475+ strcpy (commonF .stckFormat ,convDate (pqwhs -> qwhsstck ));
476+ if (recordType == 115 )
480477 {
481- /* These fields were added after V701 so ignore for old SMF */
482- commonF .intstart = 0 ;
483- commonF .intduration = 0 ;
478+ if (conv16 (pqwhs -> qwhslen ) >= 52 )
479+ {
480+ /* This structure changes size on different platforms because */
481+ /* of how the compiler deals with bitfields. So have to do it */
482+ /* explicitly with known offsets after the structure changes. */
483+ char * t = (char * )& (pqwhs -> qwhsflag1 );
484+ t += 4 ;
485+ memcpy (& commonF .intstart ,t ,8 );
486+ t += 8 ;
487+ memcpy (& commonF .intduration ,t ,8 );
488+ }
489+ else
490+ {
491+ /* These fields were added after V701 so ignore for old SMF */
492+ commonF .intstart = 0 ;
493+ commonF .intduration = 0 ;
494+ }
484495 }
485496 }
486497 }
@@ -837,6 +848,7 @@ FILE * fopenext(const char * basename, const char *ext, BOOL *newFile)
837848
838849 fseek (fp ,0 ,SEEK_END );
839850 pos = ftell (fp );
851+ /*setbuf(fp,0); */ /* useful to have this line when debugging */
840852
841853 if (pos == 0 ) /* Have we just created the file, even for "append" mode */
842854 * newFile = TRUE;
0 commit comments