#include <stdio.h>
#include "defines.h"
#include "lxt2_read.h"
#include "util.h"
|
|
|
|
||||||||||||||||||||||||
|
00533 { PROFILE(LXT2_RD_BUILD_RADIX);
00534
00535 unsigned int i;
00536 int offset;
00537
00538 for( i=0; i<(LXT2_RD_GRANULE_SIZE+1); i++ ) { /* +1 because tzc returns 33/65 when its arg == 0 */
00539 lt->radix_sort[i] = NULL; /* each one is a linked list: we get fac number based on address of item from lt->next_radix */
00540 }
00541
00542 for( i=strtfac; i<endfac; i++ ) {
00543
00544 granmsk_t x;
00545 int process_idx = i / 8;
00546 int process_bit = i & 7;
00547
00548 /*@-shiftnegative@*/
00549 if( lt->process_mask[process_idx] & (1 << process_bit) ) {
00550 /*@=shiftnegative@*/
00551
00552 if( (x = lt->fac_map[i]) ) {
00553 if( !granule && (x & LXT2_RD_GRAN_1VAL) ) {
00554 lxt2_rd_iter_radix0( lt, b, i ); /* emit vcd only if it's unique */
00555 x &= ~LXT2_RD_GRAN_1VAL; /* clear out least sig bit */
00556 lt->fac_map[i] = x;
00557 if( !x ) {
00558 continue;
00559 }
00560 }
00561 offset = lxt2_rd_tzc( x ); /* get "which time" bucket number of new least sig one bit */
00562 lt->next_radix[i] = lt->radix_sort[offset]; /* insert item into head of radix sorted "which time" buckets */
00563 lt->radix_sort[offset] = <->next_radix[i];
00564 }
00565
00566 }
00567
00568 }
00569
00570 PROFILE_END;
00571
00572 }
|
|
|
01125 { PROFILE(LXT2_RD_CLOSE);
01126
01127 if( lt ) {
01128
01129 struct lxt2_rd_block* b;
01130 struct lxt2_rd_block* bt;
01131 unsigned int i;
01132
01133 if( lt->value != NULL ) {
01134 for( i=0; i<lt->numfacs; i++ ) {
01135 free_safe( lt->value[i], (strlen( lt->value[i] ) + 1) );
01136 lt->value[i] = NULL;
01137 }
01138 free_safe( lt->value, (lt->numfacs * sizeof( char* )) );
01139 lt->value = NULL;
01140 }
01141
01142 free_safe( lt->process_mask, ((lt->numfacs / 8) + 1) );
01143 free_safe( lt->process_mask_compressed, ((lt->numfacs / LXT2_RD_PARTIAL_SIZE) + 1) );
01144 free_safe( lt->rows, (lt->numfacs * sizeof( lxtint32_t )) );
01145 free_safe( lt->msb, (lt->numfacs * sizeof( lxtint32_t )) );
01146 free_safe( lt->lsb, (lt->numfacs * sizeof( lxtint32_t )) );
01147 free_safe( lt->flags, (lt->numfacs * sizeof( lxtint32_t )) );
01148 free_safe( lt->len, (lt->numfacs * sizeof( lxtint32_t )) );
01149 free_safe( lt->next_radix, (lt->numfacs * sizeof( void* )) );
01150
01151 lt->process_mask = NULL;
01152 lt->process_mask_compressed = NULL;
01153 lt->rows = NULL;
01154 lt->msb = NULL;
01155 lt->lsb = NULL;
01156 lt->flags = NULL;
01157 lt->len = NULL;
01158 lt->next_radix = NULL;
01159
01160 free_safe( lt->zfacnames, lt->zfacname_predec_size );
01161 lt->zfacnames = NULL;
01162
01163 if( lt->faccache ) {
01164
01165 free_safe( lt->faccache->bufprev, (lt->longestname + 1) );
01166 free_safe( lt->faccache->bufcurr, (lt->longestname + 1) );
01167
01168 lt->faccache->bufprev = NULL;
01169 lt->faccache->bufcurr = NULL;
01170
01171 free_safe( lt->faccache, sizeof( struct lxt2_rd_facname_cache ) );
01172 lt->faccache = NULL;
01173
01174 }
01175
01176 free_safe( lt->fac_map, lt->numfacs * sizeof( granmsk_t ) );
01177 lt->fac_map = NULL;
01178 free_safe( lt->fac_curpos, lt->numfacs * sizeof( char* ) );
01179 lt->fac_curpos = NULL;
01180
01181 b = lt->block_head;
01182 while( b ) {
01183
01184 bt = b->next;
01185
01186 free_safe( b->mem, b->uncompressed_siz );
01187 free_safe( b->string_pointers, (b->num_dict_entries * sizeof( char* )) );
01188 free_safe( b->string_lens, (b->num_dict_entries * sizeof( unsigned int)) );
01189
01190 b->mem = NULL;
01191 b->string_pointers = NULL;
01192 b->string_lens = NULL;
01193
01194 free_safe( b, sizeof( struct lxt2_rd_block ) );
01195
01196 b = bt;
01197
01198 }
01199
01200 lt->block_head = lt->block_curr = NULL;
01201
01202 #ifdef HAVE_LIBZ
01203 if( lt->zhandle ) {
01204 unsigned int rv = gzclose( lt->zhandle );
01205 assert( rv == Z_OK );
01206 lt->zhandle = NULL;
01207 }
01208 #endif
01209
01210 if( lt->handle ) {
01211 unsigned int rv = fclose( lt->handle );
01212 assert( rv == 0 );
01213 lt->handle = NULL;
01214 }
01215
01216 free_safe( lt, sizeof( struct lxt2_rd_trace ) );
01217
01218 }
01219
01220 PROFILE_END;
01221
01222 }
|
|
||||||||||||
|
01482 {
01483
01484 int rc = 0;
01485
01486 if( lt ) {
01487
01488 lt->process_mask_dirty = 1;
01489
01490 if( facidx < lt->numfacs) {
01491 int idx = facidx / 8;
01492 int bitpos = facidx & 7;
01493 /*@-shiftnegative@*/
01494 lt->process_mask[idx] &= ~(1 << bitpos);
01495 /*@=shiftnegative@*/
01496 }
01497
01498 rc = 1;
01499
01500 }
01501
01502 return( rc );
01503
01504 }
|
|
|
01520 {
01521
01522 int rc = 0;
01523
01524 if( lt ) {
01525 lt->process_mask_dirty = 1;
01526 memset( lt->process_mask, 0x00, ((lt->numfacs + 7) / 8) );
01527 rc = 1;
01528 }
01529
01530 return( rc );
01531
01532 }
|
|
||||||||||||
|
00213 { PROFILE(LXT2_RD_EXPAND_BITS_TO_INTEGER);
00214
00215 unsigned int v = 0;
00216 int i;
00217
00218 for( i=0; i<len; i++ ) {
00219 v <<= 1;
00220 v |= ((*s) & 1);
00221 s++;
00222 }
00223
00224 PROFILE_END;
00225
00226 return( v );
00227
00228 }
|
|
||||||||||||
|
00189 { PROFILE(LXT2_RD_EXPAND_INTEGER_TO_BITS);
00190
00191 static char s[33];
00192 char* p = s;
00193 int i;
00194 int len2 = len - 1;
00195
00196 for( i=0; i<len; i++ ) {
00197 /*@-shiftnegative@*/
00198 *(p++) = '0' | ((value & (1 << (len2 - i))) != 0);
00199 /*@=shiftnegative@*/
00200 }
00201
00202 *p = 0;
00203
00204 PROFILE_END;
00205
00206 return( s );
00207
00208 }
|
|
||||||||||||
|
00097 {
00098
00099 unsigned char* nn = (unsigned char*)mm + offset;
00100 unsigned int m1 =* ((unsigned char*)(nn++));
00101 unsigned int m2 =* ((unsigned char*)nn);
00102
00103 return( (m1 << 8) | m2 );
00104
00105 }
|
|
||||||||||||
|
00107 {
00108
00109 unsigned char* nn = (unsigned char*)mm + offset;
00110 unsigned int m1 =* ((unsigned char*)(nn++));
00111 unsigned int m2 =* ((unsigned char*)(nn++));
00112 unsigned int m3 =* ((unsigned char*)nn);
00113
00114 return( (m1 << 16) | (m2 << 8) | m3 );
00115
00116 }
|
|
||||||||||||
|
00118 {
00119
00120 unsigned char* nn = (unsigned char*)mm+offset;
00121 unsigned int m1 =* ((unsigned char*)(nn++));
00122 unsigned int m2 =* ((unsigned char*)(nn++));
00123 unsigned int m3 =* ((unsigned char*)(nn++));
00124 unsigned int m4 =* ((unsigned char*)nn);
00125
00126 return( (m1 << 24) | (m2 << 16) | (m3 << 8) | m4 );
00127
00128 }
|
|
||||||||||||
|
00130 {
00131
00132 return( (((lxtint64_t)lxt2_rd_get_32( mm, offset )) << 32) | ((lxtint64_t)lxt2_rd_get_32( mm, (offset + 4))) );
00133
00134 }
|
|
||||||||||||
|
01314 {
01315
01316 if( lt && (facidx < lt->numfacs) ) {
01317
01318 while( lt->flags[facidx] & LXT2_RD_SYM_F_ALIAS ) {
01319 facidx = lt->rows[facidx]; /* iterate to next alias */
01320 }
01321
01322 return( facidx );
01323
01324 } else {
01325
01326 return( ~((lxtint32_t)0) );
01327
01328 }
01329
01330 }
|
|
|
01547 {
01548
01549 return( lt->block_mem_consumed );
01550
01551 }
|
|
|
01341 {
01342
01343 return( lt ? lt->end : LXT2_RD_GRAN_0VAL );
01344
01345 }
|
|
||||||||||||
|
|
|
||||||||||||
|
01242 {
01243
01244 if( lt && (facidx < lt->numfacs) ) {
01245 lt->geometry.rows = lt->rows[facidx];
01246 lt->geometry.msb = lt->msb[facidx];
01247 lt->geometry.lsb = lt->lsb[facidx];
01248 lt->geometry.flags = lt->flags[facidx];
01249 lt->geometry.len = lt->len[facidx];
01250 return( <->geometry );
01251 } else {
01252 return( NULL );
01253 }
01254
01255 }
|
|
||||||||||||
|
|
|
||||||||||||
|
|
|
||||||||||||
|
|
|
||||||||||||
|
01439 {
01440
01441 if( lt ) {
01442
01443 if( facidx < lt->numfacs ) {
01444 int process_idx = facidx / 8;
01445 int process_bit = facidx & 7;
01446 /*@-shiftnegative@*/
01447 return( (lt->process_mask[process_idx] & (1 << process_bit)) != 0 );
01448 /*@=shiftnegative@*/
01449 }
01450
01451 }
01452
01453 return( 0 );
01454
01455 }
|
|
||||||||||||
|
|
|
||||||||||||
|
01361 { PROFILE(LXT2_RD_GET_FACNAME);
01362
01363 char* pnt;
01364 unsigned int clone, j;
01365
01366 if( lt ) {
01367
01368 if( (facidx == (lt->faccache->old_facidx + 1)) || !facidx ) {
01369
01370 if( !facidx ) {
01371 lt->faccache->n = lt->zfacnames;
01372 lt->faccache->bufcurr[0] = 0;
01373 lt->faccache->bufprev[0] = 0;
01374 }
01375
01376 if( facidx != lt->numfacs ) {
01377
01378 pnt = lt->faccache->bufcurr;
01379 lt->faccache->bufcurr = lt->faccache->bufprev;
01380 lt->faccache->bufprev = pnt;
01381
01382 clone = lxt2_rd_get_16( lt->faccache->n, 0 );
01383 lt->faccache->n += 2;
01384 pnt = lt->faccache->bufcurr;
01385
01386 for( j=0; j<clone; j++ ) {
01387 *(pnt++) = lt->faccache->bufprev[j];
01388 }
01389
01390 while( (*(pnt++) = lxt2_rd_get_byte( lt->faccache->n++, 0 )) );
01391
01392 lt->faccache->old_facidx = facidx;
01393
01394 return( lt->faccache->bufcurr );
01395
01396 } else {
01397
01398 return( NULL ); /* no more left */
01399
01400 }
01401
01402 } else {
01403
01404 if( facidx < lt->numfacs ) {
01405
01406 int strt;
01407
01408 if( facidx == lt->faccache->old_facidx ) {
01409 return( lt->faccache->bufcurr );
01410 }
01411
01412 if( facidx > (lt->faccache->old_facidx + 1) ) {
01413 strt = lt->faccache->old_facidx + 1;
01414 } else {
01415 strt = 0;
01416 }
01417
01418 for( j=strt; j<facidx; j++ ) {
01419 (void)lxt2_rd_get_facname( lt, j );
01420 }
01421
01422 return( lxt2_rd_get_facname( lt, j ) );
01423
01424 }
01425
01426 }
01427
01428 }
01429
01430 PROFILE_END;
01431
01432 return( NULL );
01433
01434 }
|
|
|
01565 {
01566
01567 int blk = 0;
01568
01569 if( lt ) {
01570
01571 struct lxt2_rd_block* b = lt->block_head;
01572
01573 while( b ) {
01574 if( !b->short_read_ignore && !b->exclude_block ) {
01575 blk++;
01576 }
01577 b = b->next;
01578 }
01579
01580 }
01581
01582 return( blk );
01583
01584 }
|
|
|
01556 {
01557
01558 return( lt->numblocks );
01559
01560 }
|
|
|
01229 {
01230
01231 return( lt ? lt->numfacs : 0 );
01232
01233 }
|
|
|
01335 {
01336
01337 return( lt ? lt->start : LXT2_RD_GRAN_0VAL );
01338
01339 }
|
|
|
01347 {
01348
01349 return( lt ? lt->timescale : 0 );
01350
01351 }
|
|
|
01814 {
01815
01816 if( lt ) {
01817 return( lt->user_callback_data_pointer );
01818 } else {
01819 return( NULL );
01820 }
01821
01822 }
|
|
|
00829 { PROFILE(LXT2_RD_INIT);
00830
00831 struct lxt2_rd_trace* lt = (struct lxt2_rd_trace*)calloc_safe( 1, sizeof( struct lxt2_rd_trace ) );
00832 unsigned int i;
00833
00834 if( !(lt->handle = fopen( name, "rb" )) ) {
00835
00836 lxt2_rd_close( lt );
00837 lt = NULL;
00838
00839 } else {
00840
00841 lxtint16_t id = 0, version = 0;
00842 lxtint16_t foo;
00843 unsigned int rv;
00844
00845 /* Cutoff after this number of bytes and force flush */
00846 lt->block_mem_max = LXT2_RD_MAX_BLOCK_MEM_USAGE;
00847
00848 /* Keeps gzip from acting weird in tandem with fopen */
00849 rv = setvbuf( lt->handle, (char*)NULL, _IONBF, 0 );
00850 assert( rv == 0 );
00851
00852 (void)fread( &id, 2, 1, lt->handle );
00853 (void)fread( &version, 2, 1, lt->handle );
00854 (void)fread( <->granule_size, 1, 1, lt->handle );
00855
00856 if( (foo = lxt2_rd_get_16( &id, 0 )) != LXT2_RD_HDRID ) {
00857
00858 print_output( "File specified with -lxt is not an LXT formatted dumpfile", FATAL, __FILE__, __LINE__ );
00859 lxt2_rd_close( lt );
00860 lt = NULL;
00861
00862 } else if( (version = lxt2_rd_get_16( &version, 0 )) > LXT2_RD_VERSION ) {
00863
00864 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT dumpfile is version %u which is not supported by Covered", (unsigned int)version );
00865 assert( rv < USER_MSG_LENGTH );
00866 print_output( user_msg, FATAL, __FILE__, __LINE__ );
00867 lxt2_rd_close( lt );
00868 lt = NULL;
00869
00870 } else if( lt->granule_size > LXT2_RD_GRANULE_SIZE ) {
00871
00872 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT dumpfile contains granule size of %u (>%d) which is not supported by Covered",
00873 (unsigned int)lt->granule_size, LXT2_RD_GRANULE_SIZE );
00874 assert( rv < USER_MSG_LENGTH );
00875 print_output( user_msg, FATAL, __FILE__, __LINE__ );
00876 lxt2_rd_close( lt );
00877 lt = NULL;
00878
00879 } else {
00880
00881 unsigned int rc;
00882 char* m;
00883 off_t pos, fend;
00884 unsigned int t;
00885 struct lxt2_rd_block* b;
00886 unsigned int rv;
00887
00888 (void)fread( <->numfacs, 4, 1, lt->handle );
00889 lt->numfacs = lxt2_rd_get_32( <->numfacs, 0 );
00890
00891 (void)fread( <->numfacbytes, 4, 1, lt->handle );
00892 lt->numfacbytes = lxt2_rd_get_32( <->numfacbytes, 0 );
00893
00894 (void)fread( <->longestname, 4, 1, lt->handle );
00895 lt->longestname = lxt2_rd_get_32( <->longestname, 0 );
00896
00897 (void)fread( <->zfacnamesize, 4, 1, lt->handle );
00898 lt->zfacnamesize = lxt2_rd_get_32( <->zfacnamesize, 0 );
00899
00900 (void)fread( <->zfacname_predec_size, 4, 1, lt->handle );
00901 lt->zfacname_predec_size = lxt2_rd_get_32( <->zfacname_predec_size, 0 );
00902
00903 (void)fread( <->zfacgeometrysize, 4, 1, lt->handle );
00904 lt->zfacgeometrysize = lxt2_rd_get_32( <->zfacgeometrysize, 0 );
00905
00906 (void)fread( <->timescale, 1, 1, lt->handle ); /* No swap necessary */
00907
00908 #ifdef DEBUG_MODE
00909 if( debug_mode ) {
00910 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT: %d facilities", lt->numfacs );
00911 assert( rv < USER_MSG_LENGTH );
00912 print_output( user_msg, DEBUG, __FILE__, __LINE__ );
00913 }
00914 #endif
00915
00916 pos = ftello( lt->handle );
00917
00918 lt->process_mask = calloc_safe( 1, ((lt->numfacs / 8) + 1) );
00919 lt->process_mask_compressed = calloc_safe( 1, ((lt->numfacs / LXT2_RD_PARTIAL_SIZE) + 1) );
00920
00921 /* Open and read the name section of the file that is compressed */
00922 lt->zhandle = gzdopen( dup( fileno( lt->handle ) ), "rb" );
00923 m = (char*)malloc_safe_nolimit( lt->zfacname_predec_size );
00924 rc = gzread( lt->zhandle, m, lt->zfacname_predec_size );
00925 rv = gzclose( lt->zhandle );
00926 assert( rv == Z_OK );
00927 lt->zhandle = NULL;
00928
00929 if( rc != lt->zfacname_predec_size ) {
00930 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT: Name section mangled %u (actual) vs %u (expected)", rc, (unsigned int)lt->zfacname_predec_size );
00931 assert( rv < USER_MSG_LENGTH );
00932 print_output( user_msg, FATAL, __FILE__, __LINE__ );
00933 free_safe( m, lt->zfacname_predec_size );
00934 lxt2_rd_close( lt );
00935 lt = NULL;
00936 return( lt );
00937 }
00938
00939 lt->zfacnames = m;
00940
00941 lt->faccache = calloc_safe( 1, sizeof( struct lxt2_rd_facname_cache ) );
00942 lt->faccache->old_facidx = lt->numfacs; /* Causes lxt2_rd_get_facname to initialize its unroll ptr as this is always invalid */
00943 lt->faccache->bufcurr = malloc_safe_nolimit( lt->longestname + 1 );
00944 lt->faccache->bufprev = malloc_safe_nolimit( lt->longestname + 1 );
00945
00946 fseeko( lt->handle, (pos = (pos + lt->zfacnamesize)), SEEK_SET );
00947 lt->zhandle = gzdopen( dup( fileno( lt->handle ) ), "rb" );
00948
00949 t = lt->numfacs * 4 * sizeof( lxtint32_t );
00950 m = (char*)malloc_safe_nolimit( t );
00951 rc = gzread( lt->zhandle, m, t );
00952 rv = gzclose( lt->zhandle );
00953 assert( rv == Z_OK );
00954 lt->zhandle = NULL;
00955
00956 if( rc != t ) {
00957 unsigned int rv;
00958 #ifdef DEBUG_MODE
00959 if( debug_mode ) {
00960 rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT: Geometry section mangled %d (actual) vs %d (expected)", rc, t );
00961 assert( rv < USER_MSG_LENGTH );
00962 print_output( user_msg, DEBUG, __FILE__, __LINE__ );
00963 }
00964 #endif
00965 rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT: No LXT dumpfile information available in file %s", name );
00966 assert( rv < USER_MSG_LENGTH );
00967 print_output( user_msg, FATAL, __FILE__, __LINE__ );
00968 free_safe( m, t );
00969 lxt2_rd_close( lt );
00970 lt = NULL;
00971 return( lt );
00972 }
00973
00974 pos = pos + lt->zfacgeometrysize;
00975
00976 lt->rows = malloc_safe_nolimit( lt->numfacs * sizeof( lxtint32_t ) );
00977 lt->msb = malloc_safe_nolimit( lt->numfacs * sizeof( lxtint32_t ) );
00978 lt->lsb = malloc_safe_nolimit( lt->numfacs * sizeof( lxtint32_t ) );
00979 lt->flags = malloc_safe_nolimit( lt->numfacs * sizeof( lxtint32_t ) );
00980 lt->len = malloc_safe_nolimit( lt->numfacs * sizeof( lxtint32_t ) );
00981 lt->value = malloc_safe_nolimit( lt->numfacs * sizeof( char* ) );
00982 lt->next_radix = malloc_safe_nolimit( lt->numfacs * sizeof( void* ) );
00983
00984 for( i=0; i<lt->numfacs; i++ ) {
00985 unsigned int j;
00986 lt->rows[i] = lxt2_rd_get_32( m + i * 16, 0 );
00987 lt->msb[i] = lxt2_rd_get_32( m + i * 16, 4 );
00988 lt->lsb[i] = lxt2_rd_get_32( m + i * 16, 8 );
00989 lt->flags[i] = lxt2_rd_get_32( m + i * 16, 12 );
00990
00991 if( !(lt->flags[i] & LXT2_RD_SYM_F_INTEGER) ) {
00992 lt->len[i] = (lt->msb[i] <= lt->lsb[i]) ? (lt->lsb[i] - lt->msb[i] + 1) : (lt->msb[i] - lt->lsb[i] + 1);
00993 } else {
00994 lt->len[i] = 32;
00995 }
00996 lt->value[i] = calloc_safe( (lt->len[i] + 1), sizeof( char ) );
00997 for( j=0; j<lt->len[i]; j++ ) {
00998 lt->value[i][j] = 'a';
00999 }
01000 lt->value[i][j] = '\0';
01001 }
01002
01003 for( lt->numrealfacs=0; lt->numrealfacs<lt->numfacs; lt->numrealfacs++ ) {
01004 if( lt->flags[lt->numrealfacs] & LXT2_RD_SYM_F_ALIAS ) {
01005 break;
01006 }
01007 }
01008
01009 if( lt->numrealfacs > lt->numfacs ) {
01010 lt->numrealfacs = lt->numfacs;
01011 }
01012
01013 lt->prev_time = ~(LXT2_RD_GRAN_0VAL);
01014 free_safe( m, t );
01015
01016 lt->fac_map = malloc_safe_nolimit( lt->numfacs * sizeof( granmsk_t ) );
01017 lt->fac_curpos = malloc_safe_nolimit( lt->numfacs * sizeof( char* ) );
01018
01019 for( ; ; ) {
01020
01021 fseeko( lt->handle, 0L, SEEK_END );
01022 fend = ftello( lt->handle );
01023
01024 if( pos >= fend ) {
01025 break;
01026 }
01027
01028 fseeko( lt->handle, pos, SEEK_SET );
01029
01030 b = calloc_safe( 1, sizeof( struct lxt2_rd_block ) );
01031
01032 (void)fread( &b->uncompressed_siz, 4, 1, lt->handle );
01033 b->uncompressed_siz = lxt2_rd_get_32( &b->uncompressed_siz, 0 );
01034
01035 (void)fread( &b->compressed_siz, 4, 1, lt->handle );
01036 b->compressed_siz = lxt2_rd_get_32( &b->compressed_siz, 0 );
01037
01038 (void)fread( &b->start, 8, 1, lt->handle );
01039 b->start = lxt2_rd_get_64( &b->start, 0 );
01040
01041 (void)fread( &b->end, 8, 1, lt->handle );
01042 b->end = lxt2_rd_get_64( &b->end, 0 );
01043
01044 pos = ftello( lt->handle );
01045 fseeko( lt->handle, pos, SEEK_SET );
01046
01047 if( pos >= fend ) {
01048 free_safe( b, 0 ); /* TBD */
01049 break;
01050 }
01051
01052 /* Mark startpos for later in case we purge it from memory */
01053 b->filepos = pos;
01054
01055 if( b->uncompressed_siz && b->compressed_siz && b->end ) {
01056 fseeko(lt->handle, b->compressed_siz, SEEK_CUR);
01057 lt->numblocks++;
01058 if( lt->block_curr ) {
01059 lt->block_curr->next = b;
01060 lt->block_curr = b;
01061 lt->end = b->end;
01062 } else {
01063 lt->block_head = lt->block_curr = b;
01064 lt->start = b->start;
01065 lt->end = b->end;
01066 }
01067 } else {
01068 free_safe( b, 0 ); /* TBD */
01069 break;
01070 }
01071
01072 pos += b->compressed_siz;
01073
01074 }
01075
01076 if( lt->numblocks ) {
01077
01078 #ifdef DEBUG_MODE
01079 if( debug_mode ) {
01080 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT: Read %d block header%s OK", lt->numblocks, ((lt->numblocks != 1) ? "s" : "") );
01081 assert( rv < USER_MSG_LENGTH );
01082 print_output( user_msg, DEBUG, __FILE__, __LINE__ );
01083
01084 rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT: Start time = "LXT2_RD_LLD"", lt->start );
01085 assert( rv < USER_MSG_LENGTH );
01086 print_output( user_msg, DEBUG, __FILE__, __LINE__ );
01087
01088 rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT: End time = "LXT2_RD_LLD"", lt->end );
01089 assert( rv < USER_MSG_LENGTH );
01090 print_output( user_msg, DEBUG, __FILE__, __LINE__ );
01091 }
01092 #endif
01093
01094 lt->value_change_callback = lxt2_rd_null_callback;
01095
01096 } else {
01097
01098 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "No blocks exist in LXT dumpfile %s", name );
01099 assert( rv < USER_MSG_LENGTH );
01100 print_output( user_msg, FATAL, __FILE__, __LINE__ );
01101 lxt2_rd_close( lt );
01102 lt = NULL;
01103
01104 }
01105
01106 }
01107
01108 }
01109
01110 PROFILE_END;
01111
01112 return( lt );
01113
01114 }
|
|
||||||||||||||||
|
01607 { PROFILE(LXT2_RD_ITER_BLOCKS);
01608
01609 struct lxt2_rd_block* b;
01610 int blk = 0;
01611 int blkfinal = 0;
01612 int processed = 0;
01613 struct lxt2_rd_block* bcutoff = NULL;
01614 struct lxt2_rd_block* bfinal = NULL;
01615 int striped_kill = 0;
01616 unsigned int real_uncompressed_siz = 0;
01617 unsigned char gzid[2];
01618
01619 if( lt ) {
01620
01621 lt->value_change_callback = value_change_callback ? value_change_callback : lxt2_rd_null_callback;
01622 lt->user_callback_data_pointer = user_callback_data_pointer;
01623
01624 b = lt->block_head;
01625 blk = 0;
01626
01627 while( b ) {
01628
01629 if( !b->mem && !b->short_read_ignore && !b->exclude_block ) {
01630
01631 int rc;
01632
01633 if( processed < 5 ) {
01634 int gate = (processed == 4) && b->next;
01635 #ifdef DEBUG_MODE
01636 if( debug_mode ) {
01637 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT block [%d] processing "LXT2_RD_LLD" / "LXT2_RD_LLD"%s",
01638 blk, b->start, b->end, (gate ? " ..." : "") );
01639 assert( rv < USER_MSG_LENGTH );
01640 print_output( user_msg, DEBUG, __FILE__, __LINE__ );
01641 }
01642 #endif
01643 if( gate ) {
01644 bcutoff = b;
01645 }
01646 }
01647
01648 processed++;
01649
01650 fseeko( lt->handle, b->filepos, SEEK_SET );
01651 gzid[0] = gzid[1] = 0;
01652 (void)fread( &gzid, 2, 1, lt->handle );
01653 fseeko( lt->handle, b->filepos, SEEK_SET );
01654
01655 if( (striped_kill = (gzid[0] != 0x1f) || (gzid[1] != 0x8b)) ) {
01656
01657 lxtint32_t clen, unclen, iter = 0;
01658 unsigned char* pnt;
01659 off_t fspos = b->filepos;
01660 unsigned int rc;
01661 unsigned char* zbuff = NULL;
01662 unsigned int zlen = 0;
01663 struct z_stream_s strm;
01664
01665 real_uncompressed_siz = b->uncompressed_siz;
01666 pnt = b->mem = (unsigned char*)malloc_safe_nolimit( b->uncompressed_siz );
01667 b->uncompressed_siz = 0;
01668
01669 lxt2_rd_regenerate_process_mask( lt );
01670
01671 while( iter != 0xFFFFFFFF ) {
01672
01673 clen = unclen = iter = 0;
01674
01675 (void)fread( &clen, 4, 1, lt->handle );
01676 clen = lxt2_rd_get_32( &clen, 0 );
01677
01678 (void)fread( &unclen, 4, 1, lt->handle );
01679 unclen = lxt2_rd_get_32( &unclen, 0 );
01680
01681 (void)fread( &iter, 4, 1, lt->handle );
01682 iter = lxt2_rd_get_32( &iter, 0 );
01683
01684 fspos += 12;
01685
01686 if( (iter == 0xFFFFFFFF) || lt->process_mask_compressed[iter/LXT2_RD_PARTIAL_SIZE] ) {
01687
01688 if( clen > zlen ) {
01689 free_safe( zbuff, 0 ); /* TBD */
01690 zbuff = (unsigned char*)malloc_safe_nolimit( zlen = (clen * 2) );
01691 }
01692
01693 (void)fread( zbuff, clen, 1, lt->handle );
01694
01695 strm.avail_in = clen - 10;
01696 strm.avail_out = unclen;
01697 strm.total_in = strm.total_out = 0;
01698 strm.zalloc = NULL;
01699 strm.zfree = NULL;
01700 strm.opaque = NULL;
01701 strm.next_in = zbuff + 10;
01702 strm.next_out = pnt;
01703
01704 rc = inflateInit2( &strm, -MAX_WBITS );
01705
01706 while (Z_OK == (rc = inflate( &strm, Z_NO_FLUSH )) );
01707
01708 rc = inflateEnd( &strm );
01709
01710 if( strm.total_out != unclen ) {
01711 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT: Short read on subblock %lu vs %u (expected), ignoring...",
01712 strm.total_out, (unsigned int)unclen );
01713 assert( rv < USER_MSG_LENGTH );
01714 print_output( user_msg, WARNING, __FILE__, __LINE__ );
01715 free_safe( b->mem, 0 ); /* TBD */
01716 b->mem = NULL;
01717 b->short_read_ignore = 1;
01718 b->uncompressed_siz = real_uncompressed_siz;
01719 break;
01720 }
01721
01722 b->uncompressed_siz += strm.total_out;
01723 pnt += strm.total_out;
01724 fspos += clen;
01725
01726 } else {
01727
01728 fspos += clen;
01729 fseeko( lt->handle, fspos, SEEK_SET );
01730
01731 }
01732
01733 }
01734
01735 free_safe( zbuff, 0 ); /* TBD */
01736
01737 } else {
01738
01739 unsigned int rv;
01740 b->mem = malloc_safe_nolimit( b->uncompressed_siz );
01741 lt->zhandle = gzdopen( dup( fileno( lt->handle ) ), "rb" );
01742 rc = gzread( lt->zhandle, b->mem, b->uncompressed_siz );
01743 rv = gzclose( lt->zhandle );
01744 assert( rv == Z_OK );
01745 lt->zhandle = NULL;
01746
01747 if( rc != b->uncompressed_siz ) {
01748 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT: Short read on block %d vs %u (expected), ignoring...", rc, (unsigned int)b->uncompressed_siz );
01749 assert( rv < USER_MSG_LENGTH );
01750 print_output( user_msg, WARNING, __FILE__, __LINE__ );
01751 free_safe( b->mem, 0 ); /* TBD */
01752 b->mem = NULL;
01753 b->short_read_ignore = 1;
01754 } else {
01755 lt->block_mem_consumed += b->uncompressed_siz;
01756 }
01757
01758 }
01759
01760 bfinal = b;
01761 blkfinal = blk;
01762
01763 }
01764
01765 if( b->mem ) {
01766
01767 Try {
01768 (void)lxt2_rd_process_block( lt, b );
01769 } Catch_anonymous {
01770 free_safe( b->mem, 0 ); /* TBD */
01771 Throw 0;
01772 }
01773
01774 if( striped_kill ) {
01775 free_safe( b->mem, 0 ); /* TBD */
01776 b->mem = NULL;
01777 b->uncompressed_siz = real_uncompressed_siz;
01778 } else if( lt->numblocks > 1 ) { /* no sense freeing up the single block case */
01779 if( lt->block_mem_consumed > lt->block_mem_max ) {
01780 lt->block_mem_consumed -= b->uncompressed_siz;
01781 free_safe( b->mem, 0 ); /* TBD */
01782 b->mem = NULL;
01783 }
01784 }
01785
01786 }
01787
01788 blk++;
01789 b = b->next;
01790
01791 }
01792
01793 }
01794
01795 #ifdef DEBUG_MODE
01796 if( debug_mode ) {
01797 if( bcutoff && (bfinal != bcutoff) ) {
01798 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "LXT: Block [%d] processed "LXT2_RD_LLD" / "LXT2_RD_LLD"", blkfinal, bfinal->start, bfinal->end );
01799 assert( rv < USER_MSG_LENGTH );
01800 print_output( user_msg, DEBUG, __FILE__, __LINE__ );
01801 }
01802 }
01803 #endif
01804
01805 return( blk );
01806
01807 }
|
|
||||||||||||
|
00241 { PROFILE(LXT2_RD_ITER_RADIX);
00242
00243 unsigned int which_time;
00244 int offset;
00245 void** top_elem;
00246 granmsk_t msk = ~LXT2_RD_GRAN_1VAL;
00247 lxtint32_t x;
00248
00249 for( which_time=0; which_time<lt->num_time_table_entries; which_time++, msk <<= 1 ) {
00250
00251 while( (top_elem = lt->radix_sort[which_time]) ) {
00252
00253 lxtint32_t idx = top_elem - lt->next_radix;
00254 unsigned int vch;
00255 unsigned int i;
00256
00257 switch( lt->fac_curpos_width ) {
00258 case 1 : vch = lxt2_rd_get_byte( lt->fac_curpos[idx], 0 ); break;
00259 case 2 : vch = lxt2_rd_get_16( lt->fac_curpos[idx], 0 ); break;
00260 case 3 : vch = lxt2_rd_get_24( lt->fac_curpos[idx], 0 ); break;
00261 case 4 :
00262 default : vch = lxt2_rd_get_32( lt->fac_curpos[idx], 0 ); break;
00263 }
00264
00265 lt->fac_curpos[idx] += lt->fac_curpos_width;
00266
00267 /* Offset = next "which time" for this fac */
00268 offset = lxt2_rd_tzc( lt->fac_map[idx] &= msk );
00269
00270 /* Get next list item for this "which time" bucket */
00271 lt->radix_sort[which_time] = lt->next_radix[idx];
00272
00273 /* Promote fac to its next (higher) possible bucket (if any) */
00274 lt->next_radix[idx] = lt->radix_sort[offset];
00275
00276 /* ... and put it at the head of that list */
00277 lt->radix_sort[offset] = <->next_radix[idx];
00278
00279 switch( vch ) {
00280 case LXT2_RD_ENC_0:
00281 case LXT2_RD_ENC_1:
00282 memset( lt->value[idx], ('0' + (vch - LXT2_RD_ENC_0 )), lt->len[idx] );
00283 break;
00284 case LXT2_RD_ENC_INV:
00285 for( i=0; i<lt->len[idx]; i++ ) {
00286 lt->value[idx][i] ^= 1;
00287 }
00288 break;
00289 case LXT2_RD_ENC_LSH0:
00290 case LXT2_RD_ENC_LSH1:
00291 memmove( lt->value[idx], (lt->value[idx] + 1), (lt->len[idx] - 1) );
00292 lt->value[idx][lt->len[idx]-1] = '0' + (vch - LXT2_RD_ENC_LSH0);
00293 break;
00294 case LXT2_RD_ENC_RSH0:
00295 case LXT2_RD_ENC_RSH1:
00296 memmove( (lt->value[idx] + 1), lt->value[idx], (lt->len[idx] - 1) );
00297 lt->value[idx][0] = '0' + (vch - LXT2_RD_ENC_RSH0);
00298 break;
00299 case LXT2_RD_ENC_ADD1:
00300 case LXT2_RD_ENC_ADD2:
00301 case LXT2_RD_ENC_ADD3:
00302 case LXT2_RD_ENC_ADD4:
00303 x = lxt2_rd_expand_bits_to_integer( lt->len[idx], lt->value[idx] );
00304 x += (vch - LXT2_RD_ENC_ADD1 + 1);
00305 memcpy( lt->value[idx], lxt2_rd_expand_integer_to_bits( lt->len[idx], x ), lt->len[idx] );
00306 break;
00307 case LXT2_RD_ENC_SUB1:
00308 case LXT2_RD_ENC_SUB2:
00309 case LXT2_RD_ENC_SUB3:
00310 case LXT2_RD_ENC_SUB4:
00311 x = lxt2_rd_expand_bits_to_integer( lt->len[idx], lt->value[idx] );
00312 x -= (vch - LXT2_RD_ENC_SUB1 + 1);
00313 memcpy( lt->value[idx], lxt2_rd_expand_integer_to_bits( lt->len[idx], x ), lt->len[idx] );
00314 break;
00315 case LXT2_RD_ENC_X:
00316 memset( lt->value[idx], 'x', lt->len[idx] );
00317 break;
00318 case LXT2_RD_ENC_Z:
00319 memset( lt->value[idx], 'z', lt->len[idx] );
00320 break;
00321 case LXT2_RD_ENC_BLACKOUT:
00322 lt->value[idx][0] = 0;
00323 break;
00324 default:
00325 vch -= LXT2_RD_DICT_START;
00326 if( vch >= b->num_dict_entries ) {
00327 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Internal error: vch(%u) >= num_dict_entries(%u)", vch, (unsigned int)b->num_dict_entries );
00328 assert( rv < USER_MSG_LENGTH );
00329 print_output( user_msg, FATAL, __FILE__, __LINE__ );
00330 Throw 0;
00331 }
00332 if( lt->flags[idx] & (LXT2_RD_SYM_F_DOUBLE | LXT2_RD_SYM_F_STRING) ) {
00333 free_safe( lt->value[idx], (strlen( lt->value[idx] ) + 1) );
00334 lt->value[idx] = strdup_safe( (char*)b->string_pointers[vch] );
00335 break;
00336 }
00337 if( lt->len[idx] == b->string_lens[vch] ) {
00338 memcpy( lt->value[idx], b->string_pointers[vch], lt->len[idx] );
00339 } else if( lt->len[idx] > b->string_lens[vch] ) {
00340 int lendelta = lt->len[idx] - b->string_lens[vch];
00341 memset( lt->value[idx], ((b->string_pointers[vch][0] != '1') ? b->string_pointers[vch][0] : '0'), lendelta );
00342 strcpy( (lt->value[idx] + lendelta), (char*)b->string_pointers[vch] );
00343 } else {
00344 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Internal error: %u ('%s') vs %u ('%s')",
00345 (unsigned int)lt->len[idx], lt->value[idx], (unsigned int)b->string_lens[vch], (char*)b->string_pointers[vch] );
00346 assert( rv < USER_MSG_LENGTH );
00347 print_output( user_msg, FATAL, __FILE__, __LINE__ );
00348 Throw 0;
00349 }
00350 break;
00351 }
00352
00353 if( lt->time_table[which_time] != lt->prev_time ) {
00354 lt->prev_time = lt->time_table[which_time];
00355 }
00356
00357 lt->value_change_callback(<, <->time_table[which_time], &idx, <->value[idx]);
00358
00359 }
00360
00361 }
00362
00363 PROFILE_END;
00364
00365 }
|
|
||||||||||||||||
|
00378 { PROFILE(LXT2_RD_ITER_RADIX0);
00379
00380 unsigned int vch;
00381 unsigned int which_time;
00382 unsigned int i;
00383 int uniq = 0;
00384
00385 switch( lt->fac_curpos_width ) {
00386 case 1: vch = lxt2_rd_get_byte( lt->fac_curpos[idx], 0 ); break;
00387 case 2: vch = lxt2_rd_get_16( lt->fac_curpos[idx], 0 ); break;
00388 case 3: vch = lxt2_rd_get_24( lt->fac_curpos[idx], 0 ); break;
00389 case 4:
00390 default: vch = lxt2_rd_get_32( lt->fac_curpos[idx], 0 ); break;
00391 }
00392
00393 lt->fac_curpos[idx] += lt->fac_curpos_width;
00394 which_time = 0;
00395
00396 switch( vch ) {
00397 case LXT2_RD_ENC_0:
00398 for( i=0; i<lt->len[idx]; i++ ) {
00399 if( lt->value[idx][i] != '0' ) {
00400 memset( (lt->value[idx] + i), '0', (lt->len[idx] - i) );
00401 uniq = 1;
00402 break;
00403 }
00404 }
00405 break;
00406 case LXT2_RD_ENC_1:
00407 for( i=0; i<lt->len[idx]; i++) {
00408 if( lt->value[idx][i] != '1' ) {
00409 memset( (lt->value[idx] + i), '1', (lt->len[idx] - i) );
00410 uniq = 1;
00411 break;
00412 }
00413 }
00414 break;
00415 case LXT2_RD_ENC_INV:
00416 case LXT2_RD_ENC_LSH0:
00417 case LXT2_RD_ENC_LSH1:
00418 case LXT2_RD_ENC_RSH0:
00419 case LXT2_RD_ENC_RSH1:
00420 case LXT2_RD_ENC_ADD1:
00421 case LXT2_RD_ENC_ADD2:
00422 case LXT2_RD_ENC_ADD3:
00423 case LXT2_RD_ENC_ADD4:
00424 case LXT2_RD_ENC_SUB1:
00425 case LXT2_RD_ENC_SUB2:
00426 case LXT2_RD_ENC_SUB3:
00427 case LXT2_RD_ENC_SUB4:
00428 print_output( "Internal error in granule 0 position 0", FATAL, __FILE__, __LINE__ );
00429 Throw 0;
00430 /*@-unreachable@*/
00431 break;
00432 /*@=unreachable@*/
00433 case LXT2_RD_ENC_X:
00434 for( i=0; i<lt->len[idx]; i++ ) {
00435 if( lt->value[idx][i] != 'x' ) {
00436 memset( (lt->value[idx] + i), 'x', (lt->len[idx] - i) );
00437 uniq = 1;
00438 break;
00439 }
00440 }
00441 break;
00442 case LXT2_RD_ENC_Z:
00443 for( i=0; i<lt->len[idx]; i++ ) {
00444 if( lt->value[idx][i] != 'z' ) {
00445 memset( (lt->value[idx] + i), 'z', (lt->len[idx] - i) );
00446 uniq = 1;
00447 break;
00448 }
00449 }
00450 break;
00451 case LXT2_RD_ENC_BLACKOUT:
00452 if( lt->value[idx] ) {
00453 lt->value[idx][0] = 0;
00454 uniq = 1;
00455 }
00456 break;
00457 default:
00458 vch -= LXT2_RD_DICT_START;
00459 if( vch >= b->num_dict_entries ) {
00460 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Internal error: vch(%u) >= num_dict_entries(%u)", vch, (unsigned int)b->num_dict_entries );
00461 assert( rv < USER_MSG_LENGTH );
00462 print_output( user_msg, FATAL, __FILE__, __LINE__ );
00463 Throw 0;
00464 }
00465 if( lt->flags[idx] & (LXT2_RD_SYM_F_DOUBLE | LXT2_RD_SYM_F_STRING) ) {
00466 if( strcmp( lt->value[idx], (char*)b->string_pointers[vch] ) ) {
00467 free_safe( lt->value[idx], ((lt->len[idx] + 1) * sizeof( char )) );
00468 lt->value[idx] = strdup_safe( (char*)b->string_pointers[vch] );
00469 uniq = 1;
00470 }
00471 break;
00472 }
00473 if( lt->len[idx] == b->string_lens[vch] ) {
00474 for( i=0; i<lt->len[idx]; i++ ) {
00475 if( lt->value[idx][i] != b->string_pointers[vch][i] ) {
00476 memcpy( (lt->value[idx] + i), (b->string_pointers[vch] + i), (lt->len[idx] - i) );
00477 uniq = 1;
00478 }
00479 }
00480 } else if( lt->len[idx] > b->string_lens[vch] ) {
00481 unsigned int lendelta = lt->len[idx] - b->string_lens[vch];
00482 int fill = (b->string_pointers[vch][0] != '1') ? b->string_pointers[vch][0] : '0';
00483 for( i=0; i<lendelta; i++ ) {
00484 if( lt->value[idx][i] != fill ) {
00485 memset( (lt->value[idx] + i), fill, (lendelta - i) );
00486 strcpy( (lt->value[idx] + lendelta), (char*)b->string_pointers[vch] );
00487 uniq = 1;
00488 goto fini;
00489 }
00490 }
00491 for( i=lendelta; i<lt->len[idx]; i++ ) {
00492 if( lt->value[idx][i] != b->string_pointers[vch][i-lendelta] ) {
00493 memcpy( (lt->value[idx] + i), (b->string_pointers[vch] + i - lendelta), (lt->len[idx] - i) );
00494 uniq = 1;
00495 }
00496 }
00497 } else {
00498 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Internal error: %u ('%s') vs %u ('%s')",
00499 (unsigned int)lt->len[idx], lt->value[idx], (unsigned int)b->string_lens[vch], (char*)b->string_pointers[vch] );
00500 assert( rv < USER_MSG_LENGTH );
00501 print_output( user_msg, FATAL, __FILE__, __LINE__ );
00502 Throw 0;
00503 }
00504 break;
00505 }
00506
00507 fini:
00508 if( uniq ) {
00509 if( lt->time_table[which_time] != lt->prev_time ) {
00510 lt->prev_time = lt->time_table[which_time];
00511 }
00512 lt->value_change_callback( <, <->time_table[which_time], &idx, <->value[idx] );
00513 }
00514
00515 PROFILE_END;
00516
00517 }
|
|
||||||||||||||||
|
01833 { PROFILE(LXT2_RD_LIMIT_TIME_RANGE);
01834
01835 lxtint64_t tmp_time;
01836 int blk = 0;
01837
01838 if( lt ) {
01839
01840 struct lxt2_rd_block* b = lt->block_head;
01841 struct lxt2_rd_block* bprev = NULL;
01842 int state = 0;
01843
01844 if( strt_time > end_time ) {
01845 tmp_time = strt_time;
01846 strt_time = end_time;
01847 end_time = tmp_time;
01848 }
01849
01850 while( b ) {
01851
01852 switch( state ) {
01853 case 0 :
01854 if( b->end >= strt_time ) {
01855 state = 1;
01856 if( (b->start > strt_time) && bprev ) {
01857 bprev->exclude_block = 0;
01858 blk++;
01859 }
01860 }
01861 break;
01862 case 1 :
01863 if( b->start > end_time ) {
01864 state = 2;
01865 }
01866 break;
01867 default: break;
01868 }
01869
01870 if( (state == 1) && !b->short_read_ignore ) {
01871 b->exclude_block = 0;
01872 blk++;
01873 } else {
01874 b->exclude_block = 1;
01875 }
01876
01877 bprev = b;
01878 b = b->next;
01879
01880 }
01881
01882 }
01883
01884 PROFILE_END;
01885
01886 return( blk );
01887
01888 }
|
|
||||||||||||||||||||
|
00812 {
00813 }
|
|
|
00146 {
00147
00148 x -= ((x >> 1) & LXT2_RD_ULLDESC(0x5555555555555555));
00149 x = (((x >> 2) & LXT2_RD_ULLDESC(0x3333333333333333)) + (x & LXT2_RD_ULLDESC(0x3333333333333333)));
00150 x = (((x >> 4) + x) & LXT2_RD_ULLDESC(0x0f0f0f0f0f0f0f0f));
00151
00152 return( (x * LXT2_RD_ULLDESC(0x0101010101010101)) >> 56 );
00153
00154 }
|
|
||||||||||||
|
00632 { PROFILE(LXT2_RD_PROCESS_BLOCK);
00633
00634 char vld;
00635 unsigned char* pnt;
00636 unsigned int i;
00637 int granule = 0;
00638 char sect_typ;
00639 lxtint32_t strtfac_gran = 0;
00640 char granvld = 0;
00641
00642 b->num_map_entries = lxt2_rd_get_32( b->mem, (b->uncompressed_siz - 4) );
00643 b->num_dict_entries = lxt2_rd_get_32( b->mem, (b->uncompressed_siz - 12) );
00644
00645 #if LXT2_RD_GRANULE_SIZE > 32
00646 if( lt->granule_size == LXT2_RD_GRANULE_SIZE ) {
00647 b->map_start = (b->mem + b->uncompressed_siz - 12) - sizeof( granmsk_t ) * b->num_map_entries;
00648 } else {
00649 b->map_start = (b->mem + b->uncompressed_siz - 12) - sizeof( granmsk_smaller_t ) * b->num_map_entries;
00650 }
00651 #else
00652 b->map_start = (b->mem + b->uncompressed_siz - 12) - sizeof( granmsk_t ) * b->num_map_entries;
00653 #endif
00654
00655 b->dict_start = b->map_start - lxt2_rd_get_32( b->mem, (b->uncompressed_siz - 8) );
00656
00657 vld = lxt2_rd_get_byte( (b->dict_start - 1), 0 );
00658
00659 if( vld != LXT2_RD_GRAN_SECT_DICT ) {
00660 print_output( "Malformed section", FATAL, __FILE__, __LINE__ );
00661 Throw 0;
00662 }
00663
00664 if( b->num_dict_entries ) {
00665 b->string_pointers = malloc_safe_nolimit( b->num_dict_entries * sizeof( char* ) );
00666 b->string_lens = malloc_safe_nolimit( b->num_dict_entries * sizeof( unsigned int ) );
00667 pnt = b->dict_start;
00668 for( i=0; i<b->num_dict_entries; i++ ) {
00669 b->string_pointers[i] = pnt;
00670 b->string_lens[i] = strlen( (char*)pnt );
00671 pnt += (b->string_lens[i] + 1);
00672 }
00673 if( pnt != b->map_start ) {
00674 print_output( "Dictionary corrupt, exiting...", FATAL, __FILE__, __LINE__ );
00675 free_safe( b->string_pointers, (b->num_dict_entries * sizeof( char* )) );
00676 free_safe( b->string_lens, (b->num_dict_entries * sizeof( unsigned int )) );
00677 Throw 0;
00678 }
00679 }
00680
00681 pnt = b->mem;
00682
00683 while( ((sect_typ=*pnt) == LXT2_RD_GRAN_SECT_TIME) || (sect_typ == LXT2_RD_GRAN_SECT_TIME_PARTIAL) ) {
00684
00685 lxtint32_t strtfac, endfac;
00686
00687 if( sect_typ == LXT2_RD_GRAN_SECT_TIME_PARTIAL ) {
00688
00689 lxtint32_t sublen;
00690
00691 lxt2_rd_regenerate_process_mask( lt );
00692 strtfac = lxt2_rd_get_32( pnt, 1 );
00693 sublen = lxt2_rd_get_32( pnt, 5 );
00694
00695 if( !granvld ) {
00696 granvld = 1;
00697 strtfac_gran = strtfac;
00698 } else {
00699 granule += (strtfac == strtfac_gran);
00700 }
00701
00702 if( !lt->process_mask_compressed[strtfac/LXT2_RD_PARTIAL_SIZE] ) {
00703 pnt += 9;
00704 pnt += sublen;
00705 continue;
00706 }
00707
00708 endfac = strtfac + LXT2_RD_PARTIAL_SIZE;
00709
00710 if( endfac > lt->numrealfacs ) {
00711 endfac = lt->numrealfacs;
00712 }
00713
00714 pnt += 8;
00715
00716 } else {
00717
00718 strtfac = 0;
00719 endfac = lt->numrealfacs;
00720
00721 }
00722
00723 pnt++;
00724 lt->num_time_table_entries = lxt2_rd_get_byte( pnt, 0 );
00725 pnt++;
00726 for( i=0; i<lt->num_time_table_entries; i++ ) {
00727 lt->time_table[i] = lxt2_rd_get_64( pnt, 0 );
00728 pnt += 8;
00729 }
00730
00731 lt->fac_map_index_width = lxt2_rd_get_byte( pnt, 0 );
00732 if( !lt->fac_map_index_width || (lt->fac_map_index_width > 4) ) {
00733 /*@-formatcode@*/
00734 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Map index width of %hhu is illegal, exiting...", lt->fac_map_index_width );
00735 /*@=formatcode@*/
00736 assert( rv < USER_MSG_LENGTH );
00737 print_output( user_msg, FATAL, __FILE__, __LINE__ );
00738 Throw 0;
00739 }
00740 pnt++;
00741
00742 for( i=strtfac; i<endfac; i++ ) {
00743
00744 lxtint32_t mskindx;
00745
00746 switch( lt->fac_map_index_width ) {
00747 case 1 : mskindx = lxt2_rd_get_byte( pnt, 0 ); break;
00748 case 2 : mskindx = lxt2_rd_get_16( pnt, 0 ); break;
00749 case 3 : mskindx = lxt2_rd_get_24( pnt, 0 ); break;
00750 case 4 :
00751 default: mskindx = lxt2_rd_get_32( pnt, 0 ); break;
00752 }
00753
00754 pnt += lt->fac_map_index_width;
00755
00756 #if LXT2_RD_GRANULE_SIZE > 32
00757 if( lt->granule_size==LXT2_RD_GRANULE_SIZE ) {
00758 lt->fac_map[i] = get_fac_msk( b->map_start, (mskindx * sizeof( granmsk_t )) );
00759 } else {
00760 lt->fac_map[i] = get_fac_msk_smaller( b->map_start, (mskindx * sizeof( granmsk_smaller_t )) );
00761 }
00762 #else
00763 lt->fac_map[i] = get_fac_msk( b->map_start, (mskindx * sizeof( granmsk_t )) );
00764 #endif
00765
00766 }
00767
00768 lt->fac_curpos_width = lxt2_rd_get_byte( pnt, 0 );
00769 if( !lt->fac_curpos_width || (lt->fac_curpos_width > 4) ) {
00770 /*@-formatcode@*/
00771 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Curpos index width of %hhu is illegal, exiting...", lt->fac_curpos_width );
00772 /*@=formatcode@*/
00773 assert( rv < USER_MSG_LENGTH );
00774 print_output( user_msg, FATAL, __FILE__, __LINE__ );
00775 Throw 0;
00776 }
00777 pnt++;
00778
00779 for( i=strtfac; i<endfac; i++ ) {
00780 lt->fac_curpos[i] = pnt;
00781 if( lt->fac_map[i] ) {
00782 pnt += (lxt2_rd_ones_cnt( lt->fac_map[i] ) * lt->fac_curpos_width);
00783 }
00784 }
00785
00786 lxt2_rd_build_radix( lt, b, granule, strtfac, endfac );
00787 lxt2_rd_iter_radix( lt, b );
00788
00789 if( sect_typ != LXT2_RD_GRAN_SECT_TIME_PARTIAL ) {
00790 granule++;
00791 }
00792
00793 }
00794
00795 PROFILE_END;
00796
00797 return( 1 );
00798
00799 }
|
|
|
00581 { PROFILE(LXT2_RD_REGENERATE_PROCESS_MASK);
00582
00583 unsigned int i, j, lim, idx;
00584
00585 if( lt && lt->process_mask_dirty ) {
00586
00587 lt->process_mask_dirty = 0;
00588 idx = 0;
00589
00590 for( i=0; i<lt->numrealfacs; i+=LXT2_RD_PARTIAL_SIZE ) {
00591
00592 if( (i + LXT2_RD_PARTIAL_SIZE) > lt->numrealfacs ) {
00593 lim = lt->numrealfacs;
00594 } else {
00595 lim = i + LXT2_RD_PARTIAL_SIZE;
00596 }
00597
00598 lt->process_mask_compressed[idx] = 0;
00599 for( j=i; j<lim; j++ ) {
00600 int process_idx = j / 8; /* no need to optimize this */
00601 int process_bit = j & 7;
00602 /*@-shiftnegative@*/
00603 if( lt->process_mask[process_idx] & (1 << process_bit) ) {
00604 /*@=shiftnegative@*/
00605 lt->process_mask_compressed[idx] = 1;
00606 break;
00607 }
00608 }
00609
00610 idx++;
00611
00612 }
00613
00614 }
00615
00616 PROFILE_END;
00617
00618 }
|
|
||||||||||||
|
01457 {
01458
01459 int rc = 0;
01460
01461 if( lt ) {
01462
01463 lt->process_mask_dirty = 1;
01464
01465 if( facidx < lt->numfacs ) {
01466 int idx = facidx / 8;
01467 int bitpos = facidx & 7;
01468 /*@-shiftnegative@*/
01469 lt->process_mask[idx] |= (1 << bitpos);
01470 /*@=shiftnegative@*/
01471 }
01472
01473 rc = 1;
01474
01475 }
01476
01477 return( rc );
01478
01479 }
|
|
|
01506 {
01507
01508 int rc = 0;
01509
01510 if( lt ) {
01511 lt->process_mask_dirty = 1;
01512 memset( lt->process_mask, 0xff, ((lt->numfacs + 7) / 8) );
01513 rc = 1;
01514 }
01515
01516 return( rc );
01517
01518 }
|
|
||||||||||||
|
01537 {
01538
01539 lxtint64_t rc = lt->block_mem_max;
01540
01541 lt->block_mem_max = block_mem_max;
01542
01543 return( rc );
01544
01545 }
|
|
|
00177 {
00178 return( lxt2_rd_ones_cnt( (x & -x) - LXT2_RD_GRAN_1VAL ) );
00179 }
|
|
|
01897 { PROFILE(LXT2_RD_UNLIMIT_TIME_RANGE);
01898
01899 int blk = 0;
01900
01901 if( lt ) {
01902
01903 struct lxt2_rd_block *b = lt->block_head;
01904
01905 while( b ) {
01906 b->exclude_block = 0;
01907 if( !b->short_read_ignore ) {
01908 blk++;
01909 }
01910 b = b->next;
01911 }
01912
01913 }
01914
01915 PROFILE_END;
01916
01917 return( blk );
01918
01919 }
|
|
|
If set to TRUE, causes debug information to be spewed to screen. |
|
|
Holds some output that will be displayed via the print_output command. This is created globally so that memory does not need to be reallocated for each function that wishes to use it. |
1.3.4