From 32c479fbab76ff25fb2836f6546f54da90067ec6 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 22 Feb 2014 22:56:29 +0100 Subject: Let blob pages appear at the place they're referenced --- src/export/extract_version_1.c | 57 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/export/extract_version_1.c b/src/export/extract_version_1.c index 8daec76..0d45a7d 100644 --- a/src/export/extract_version_1.c +++ b/src/export/extract_version_1.c @@ -29,52 +29,53 @@ again: } int fromhex( uint8_t a ) { if(a >='0'&&a<='9')return a-'0';if(a>='a'&&a<='f') return 10+a-'a'; if(a>='A'&&a<='F') return 10+a-'A'; exit(1); } -void act_on_record( int flag, uint8_t *page, uint16_t record_off ) +void act_on_record( uint8_t *file, int flag, uint8_t *page, uint16_t record_off ) { - uint8_t * record = page + record_off; - uint8_t outbuf[8192], * out_dest = outbuf; - int num_entries = *(uint16_t*)record; + uint8_t outbuf[8192], *out_dest = outbuf, *record; + int num_entries; - /* printf( " Found record with %d entries at %04x.\n", num_entries, record_off ); */ if( record_off > 0x1fff ) - return; /* Ignore deleted entries */ - - if( !flag ) - { /* Flags says whether page has a prefix row */ - record += 2; - if( *(uint16_t*)record ) - { - decode_7bit_string( page + *(uint16_t*)record, outbuf ); - out_dest += strlen( (char*)outbuf ); + { + /* Here comes the reference to a blob page */ + int page_nr = *(uint16_t*)(page + ( record_off ^ 0xffff ) + 1); + page = file + 0x800 + 0x2000 * page_nr; + num_entries = *(uint16_t*)page; + record = page + 0x6; + } + else + { + record = page + record_off; + num_entries = *(uint16_t*)record; + if( !flag ) + { /* Flags says whether page has a prefix row */ + record += 2; + if( *(uint16_t*)record ) + { + decode_7bit_string( page + *(uint16_t*)record, outbuf ); + out_dest += strlen( (char*)outbuf ); + } } + record += 2; } - decode_7bit_string( record + 2, out_dest ); + decode_7bit_string( record, out_dest ); /* XXX TODO: Split record in 12 chunks each, mark continuation, if num_entries > 1 */ puts( (char*)outbuf ); } /* Page is always 0x2000 */ -void act_on_page( uint8_t *page, int page_nr ) +void act_on_page( uint8_t *file, uint8_t *page, int page_nr ) { int record, flag = page[0]; int blob_len = *(uint16_t*)(page + 0x2); int num_records = *(uint16_t*)(page + 0x4); uint16_t * recs = (uint16_t*)(page + 0xe); - printf( " Acting on page %04d with flag %d and %04d records.\n", page_nr, flag, num_records ); - - if( blob_len ) - { - uint8_t outbuf[8192]; - /* printf( "-------- PAGE IS BLOB --------" ); */ + /* printf( " Acting on page %04d with flag %d and %04d records.\n", page_nr, flag, num_records ); */ - decode_7bit_string( page + 0x6, outbuf ); - /* XXX TODO: Split record in 12 chunks each, mark continuation */ - puts( (char *)outbuf ); - } else + if( !blob_len ) /* Handle blob, pages when they're referenced */ for( record = 0; record < num_records; ++record ) - act_on_record( flag, page + 0xe, recs[record] ); + act_on_record( file, flag, page + 0xe, recs[record] ); } void act_on_file( uint8_t *file, size_t len ) @@ -89,7 +90,7 @@ void act_on_file( uint8_t *file, size_t len ) /* printf( "Working on a %04d page and %06d records file, city: %4s %-32s with prefix %s\n", num_pages, num_records, zip, ort, vorwahl ); */ for( page = 0; page < num_pages; ++page ) - act_on_page( file + 0x800 + 0x2000 * page, page ); + act_on_page( file, file + 0x800 + 0x2000 * page, page ); } int main( int args, char **argv ) -- cgit v1.2.3