summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/export/extract_version_1.c57
1 files changed, 29 insertions, 28 deletions
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:
29} 29}
30int 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); } 30int 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); }
31 31
32void act_on_record( int flag, uint8_t *page, uint16_t record_off ) 32void act_on_record( uint8_t *file, int flag, uint8_t *page, uint16_t record_off )
33{ 33{
34 uint8_t * record = page + record_off; 34 uint8_t outbuf[8192], *out_dest = outbuf, *record;
35 uint8_t outbuf[8192], * out_dest = outbuf; 35 int num_entries;
36 int num_entries = *(uint16_t*)record;
37 36
38 /* printf( " Found record with %d entries at %04x.\n", num_entries, record_off ); */
39 if( record_off > 0x1fff ) 37 if( record_off > 0x1fff )
40 return; /* Ignore deleted entries */ 38 {
41 39 /* Here comes the reference to a blob page */
42 if( !flag ) 40 int page_nr = *(uint16_t*)(page + ( record_off ^ 0xffff ) + 1);
43 { /* Flags says whether page has a prefix row */ 41 page = file + 0x800 + 0x2000 * page_nr;
44 record += 2; 42 num_entries = *(uint16_t*)page;
45 if( *(uint16_t*)record ) 43 record = page + 0x6;
46 { 44 }
47 decode_7bit_string( page + *(uint16_t*)record, outbuf ); 45 else
48 out_dest += strlen( (char*)outbuf ); 46 {
47 record = page + record_off;
48 num_entries = *(uint16_t*)record;
49 if( !flag )
50 { /* Flags says whether page has a prefix row */
51 record += 2;
52 if( *(uint16_t*)record )
53 {
54 decode_7bit_string( page + *(uint16_t*)record, outbuf );
55 out_dest += strlen( (char*)outbuf );
56 }
49 } 57 }
58 record += 2;
50 } 59 }
51 60
52 decode_7bit_string( record + 2, out_dest ); 61 decode_7bit_string( record, out_dest );
53 /* XXX TODO: Split record in 12 chunks each, mark continuation, if num_entries > 1 */ 62 /* XXX TODO: Split record in 12 chunks each, mark continuation, if num_entries > 1 */
54 puts( (char*)outbuf ); 63 puts( (char*)outbuf );
55} 64}
56 65
57/* Page is always 0x2000 */ 66/* Page is always 0x2000 */
58void act_on_page( uint8_t *page, int page_nr ) 67void act_on_page( uint8_t *file, uint8_t *page, int page_nr )
59{ 68{
60 int record, flag = page[0]; 69 int record, flag = page[0];
61 int blob_len = *(uint16_t*)(page + 0x2); 70 int blob_len = *(uint16_t*)(page + 0x2);
62 int num_records = *(uint16_t*)(page + 0x4); 71 int num_records = *(uint16_t*)(page + 0x4);
63 uint16_t * recs = (uint16_t*)(page + 0xe); 72 uint16_t * recs = (uint16_t*)(page + 0xe);
64 73
65 printf( " Acting on page %04d with flag %d and %04d records.\n", page_nr, flag, num_records ); 74 /* printf( " Acting on page %04d with flag %d and %04d records.\n", page_nr, flag, num_records ); */
66
67 if( blob_len )
68 {
69 uint8_t outbuf[8192];
70 /* printf( "-------- PAGE IS BLOB --------" ); */
71 75
72 decode_7bit_string( page + 0x6, outbuf ); 76 if( !blob_len ) /* Handle blob, pages when they're referenced */
73 /* XXX TODO: Split record in 12 chunks each, mark continuation */
74 puts( (char *)outbuf );
75 } else
76 for( record = 0; record < num_records; ++record ) 77 for( record = 0; record < num_records; ++record )
77 act_on_record( flag, page + 0xe, recs[record] ); 78 act_on_record( file, flag, page + 0xe, recs[record] );
78} 79}
79 80
80void act_on_file( uint8_t *file, size_t len ) 81void act_on_file( uint8_t *file, size_t len )
@@ -89,7 +90,7 @@ void act_on_file( uint8_t *file, size_t len )
89 /* printf( "Working on a %04d page and %06d records file, city: %4s %-32s with prefix %s\n", num_pages, num_records, zip, ort, vorwahl ); */ 90 /* printf( "Working on a %04d page and %06d records file, city: %4s %-32s with prefix %s\n", num_pages, num_records, zip, ort, vorwahl ); */
90 91
91 for( page = 0; page < num_pages; ++page ) 92 for( page = 0; page < num_pages; ++page )
92 act_on_page( file + 0x800 + 0x2000 * page, page ); 93 act_on_page( file, file + 0x800 + 0x2000 * page, page );
93} 94}
94 95
95int main( int args, char **argv ) 96int main( int args, char **argv )