diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/export/split_version_2.c | 98 |
1 files changed, 73 insertions, 25 deletions
diff --git a/src/export/split_version_2.c b/src/export/split_version_2.c index 7a6f04e..3ed1bbd 100644 --- a/src/export/split_version_2.c +++ b/src/export/split_version_2.c | |||
@@ -6,7 +6,56 @@ | |||
6 | 6 | ||
7 | #include "mystdlib.h" | 7 | #include "mystdlib.h" |
8 | 8 | ||
9 | /* | ||
10 | |||
11 | 01_unknown => 01_Flags | ||
12 | 17_unknown => 02_Nachname | ||
13 | 08_unknown => 03_Vorname | ||
14 | 12_unknown => 04_Zusaetze | ||
15 | 14_unknown => 05_Zusaetze (sw) | ||
16 | 15_unknown => 05_Zusaetze (no) | ||
17 | 13_unknown => 06_Ortszusatz | ||
18 | 09_unknown => 07_Strasse | ||
19 | 11_unknown => 08_Hausnummer | ||
20 | 15_unknown => 09_Verweise (sw) | ||
21 | 14_unknown => 09_Verweise (no) | ||
22 | 04_unknown => 10_Postleitzahl | ||
23 | 10_unknown => 11_Ort | ||
24 | 06_unknown => 12_Vorwahl (sw) | ||
25 | 07_unknown => 12_Vorwahl (no) | ||
26 | 07_unknown => 13_Rufnummer (sw) | ||
27 | 06_unknown => 13_Rufnummer (no) | ||
28 | |||
29 | no s w | ||
30 | 4003 01 01 01 | ||
31 | 4007 - - 5:"0" | ||
32 | 4009 - *:"0" - | ||
33 | 400B - - 6:"0" | ||
34 | 400C - !!! - => in 1996_Q1: 04_Namenszusatz | ||
35 | 400E 15 07 - | ||
36 | 400F 06 06 14 | ||
37 | 4010 - - 07 | ||
38 | 4011 17 - 17 | ||
39 | 4012 07 17 06 | ||
40 | 4013 14 09 09 | ||
41 | 4014 13 11 11 | ||
42 | 4015 09 15 04 | ||
43 | 4016 11 04 10 | ||
44 | 4017 04 10 13 | ||
45 | 4018 10 14 - | ||
46 | 401A - 13 15 | ||
47 | 401B 08 08 08 | ||
48 | 401C 12 12 12 | ||
49 | |||
50 | */ | ||
51 | |||
9 | enum { g_outfiles = 17 }; | 52 | enum { g_outfiles = 17 }; |
53 | static enum { CD_NO = 0, CD_S = 1, CD_W = 2 } g_cd; | ||
54 | static int g_outfilemap[3][29] = { | ||
55 | {-1,-1,-1, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,14, 5,-1,16, 6,13,12, 8,10, 3, 9,-1, 7,11 }, | ||
56 | {-1,-1,-1, 0,-1,-1,-1,-1,-1,-1,-1,-1,11,-1, 6, 5,-1,-1,16, 8,10,14, 3, 9,13,12, 7,11 }, | ||
57 | {-1,-1,-1, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,13, 6,16, 5, 8,10, 3, 9,12,-1,14, 7,11 } | ||
58 | }; | ||
10 | 59 | ||
11 | static struct { | 60 | static struct { |
12 | int outfiles[g_outfiles]; | 61 | int outfiles[g_outfiles]; |
@@ -14,7 +63,6 @@ static struct { | |||
14 | size_t outfill [g_outfiles]; | 63 | size_t outfill [g_outfiles]; |
15 | } g_state; | 64 | } g_state; |
16 | 65 | ||
17 | static int g_northern_version;; | ||
18 | static uint8_t cp437_to_iso8859_1_table[] = { | 66 | static uint8_t cp437_to_iso8859_1_table[] = { |
19 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | 67 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
20 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, | 68 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
@@ -35,22 +83,19 @@ static uint8_t cp437_to_iso8859_1_table[] = { | |||
35 | }; | 83 | }; |
36 | 84 | ||
37 | static void dump_string( uint8_t *start, size_t len, int file ) { | 85 | static void dump_string( uint8_t *start, size_t len, int file ) { |
38 | uint8_t *dest = g_state.outbuf[file] + g_state.outfill[file]; | 86 | while( len-- && *start ) |
39 | g_state.outfill[file] += len; | 87 | g_state.outbuf[file][g_state.outfill[file]++] = cp437_to_iso8859_1_table[*start++]; |
40 | while( len-- ) | ||
41 | *(dest++) = cp437_to_iso8859_1_table[ *(start++) ]; | ||
42 | } | 88 | } |
43 | 89 | ||
44 | static void dump_field( uint8_t **end, int file ) { | 90 | static void dump_field( uint8_t **end, int file ) { |
45 | uint8_t len = (*end)[-1]; | 91 | uint8_t len = (*end)[-1]; |
46 | *end -= len + 1; | 92 | dump_string( *end -= len + 1, len, file); |
47 | dump_string( *end, len, file); | ||
48 | } | 93 | } |
49 | 94 | ||
50 | static void finish_record( ) { | 95 | static void finish_record( ) { |
51 | int i; | 96 | int file; |
52 | for( i=0; i<g_outfiles; ++i ) | 97 | for( file=0; file<g_outfiles; ++file ) |
53 | *( g_state.outbuf[i] + g_state.outfill[i]++ ) = '\n'; | 98 | g_state.outbuf[file][g_state.outfill[file]++] = '\n'; |
54 | } | 99 | } |
55 | 100 | ||
56 | static uint16_t load_word( uint8_t *table_start, uint16_t base, int offset ) { | 101 | static uint16_t load_word( uint8_t *table_start, uint16_t base, int offset ) { |
@@ -59,11 +104,10 @@ static uint16_t load_word( uint8_t *table_start, uint16_t base, int offset ) { | |||
59 | /* If a word(subflag, t_off) would span over the end of a 0x4000 | 104 | /* If a word(subflag, t_off) would span over the end of a 0x4000 |
60 | byte page, it is placed on the next page. All other words are | 105 | byte page, it is placed on the next page. All other words are |
61 | shifted backwards, as well. */ | 106 | shifted backwards, as well. */ |
62 | table_start += 4; | ||
63 | if( base + 4 + 4 * dword_offset > 0x1ffc ) | 107 | if( base + 4 + 4 * dword_offset > 0x1ffc ) |
64 | table_start += 3 & ( 4 - ( base & 3 ) ); | 108 | table_start += 3 & ( 4 - ( base & 3 ) ); |
65 | 109 | ||
66 | return ((uint16_t*)table_start)[offset]; | 110 | return ((uint16_t*)table_start)[offset + 2]; |
67 | } | 111 | } |
68 | 112 | ||
69 | static void dump_primary( uint8_t *end, uint32_t flags ) { | 113 | static void dump_primary( uint8_t *end, uint32_t flags ) { |
@@ -74,7 +118,7 @@ static void dump_primary( uint8_t *end, uint32_t flags ) { | |||
74 | dump_string( end -= 5, 5, 1 ); | 118 | dump_string( end -= 5, 5, 1 ); |
75 | 119 | ||
76 | /* Dump first 5 chars of prefix, they're always here in s and w */ | 120 | /* Dump first 5 chars of prefix, they're always here in s and w */ |
77 | if( !g_northern_version ) | 121 | if( g_cd != CD_NO ) |
78 | dump_string( end -= 5, 5, 2 ); | 122 | dump_string( end -= 5, 5, 2 ); |
79 | 123 | ||
80 | /* There is another version of the zip code present, if this bit is set */ | 124 | /* There is another version of the zip code present, if this bit is set */ |
@@ -83,9 +127,8 @@ static void dump_primary( uint8_t *end, uint32_t flags ) { | |||
83 | /* There is an unclear X present, if this bit is set */ | 127 | /* There is an unclear X present, if this bit is set */ |
84 | if( flags & 0x0040 ) dump_string( end -= 1, 1, 4 ); | 128 | if( flags & 0x0040 ) dump_string( end -= 1, 1, 4 ); |
85 | 129 | ||
86 | /* There is another version of the prefix present, if this bit is set */ | ||
87 | if( flags & 0x0020 ) { | 130 | if( flags & 0x0020 ) { |
88 | if( !g_northern_version ) | 131 | if( g_cd != CD_NO ) |
89 | dump_string( end -= 5, 5, 5 ); | 132 | dump_string( end -= 5, 5, 5 ); |
90 | else | 133 | else |
91 | dump_field( &end, 5 ); | 134 | dump_field( &end, 5 ); |
@@ -104,7 +147,7 @@ static void dump_primary( uint8_t *end, uint32_t flags ) { | |||
104 | dump_field( &end, 15 ); | 147 | dump_field( &end, 15 ); |
105 | 148 | ||
106 | /* Dump first 5 chars of prefix, they're always here in no */ | 149 | /* Dump first 5 chars of prefix, they're always here in no */ |
107 | if( g_northern_version ) | 150 | if( g_cd == CD_NO ) |
108 | dump_field( &end, 2 ); | 151 | dump_field( &end, 2 ); |
109 | dump_field( &end, 16 ); | 152 | dump_field( &end, 16 ); |
110 | } | 153 | } |
@@ -117,23 +160,22 @@ static void act_on_record( uint8_t * end, uint16_t base ) { | |||
117 | uint32_t flags = 0; | 160 | uint32_t flags = 0; |
118 | int i; | 161 | int i; |
119 | 162 | ||
120 | for (i=0; i<flagbytes; ++i) flags = (flags<<8) | *--end; | 163 | while(flagbytes--) flags = (flags<<8) | *--end; |
121 | 164 | ||
122 | // printf( "-------- %03d: %06X\n", num_dwords, flags ); | 165 | // printf( "-------- %03d: %06X\n", num_dwords, flags ); |
123 | for (i = 0; i < num_dwords; i++ ) { | 166 | for (i = 0; i < num_dwords; i++ ) { |
124 | uint16_t subflag = load_word( e, base, 2*i ); | 167 | uint16_t subflag = load_word( e, base, 2*i ); |
125 | uint16_t t_off = load_word( e, base, 2*i+1 ); | 168 | uint16_t t_off = load_word( e, base, 2*i+1 ); |
126 | uint8_t *rec_start = end - t_off; | 169 | uint8_t *rec_start = end - t_off; |
127 | 170 | ||
128 | if (i == 0) | 171 | if (i == 0) |
129 | dump_primary( rec_start, flags ); | 172 | dump_primary( rec_start, flags ); |
130 | else { | 173 | else { |
131 | uint8_t * rec_end = end - ( ( i+1 == num_dwords ) ? 0 : load_word( e, base, 2*i+3 ) ); | 174 | uint8_t * rec_end = end - ( ( i+1 == num_dwords ) ? 0 : load_word( e, base, 2*i+3 ) ); |
132 | printf( "(%04X): ", subflag ); | 175 | int file = g_outfilemap[g_cd][subflag&0x1F]; |
133 | // dump_string( rec_start, rec_end, file ); | 176 | if( subflag == 0x4003 ) finish_record(); |
134 | while ( rec_start < rec_end ) | 177 | if( file >= 0 ) |
135 | putchar( cp437_to_iso8859_1_table[ *(rec_start++) ] ); | 178 | dump_string( rec_start, rec_end - rec_start, g_outfilemap[g_cd][subflag&0x1F] ); |
136 | putchar(10); | ||
137 | } | 179 | } |
138 | } | 180 | } |
139 | finish_record(); | 181 | finish_record(); |
@@ -165,7 +207,13 @@ int main( int args, char **argv ) { | |||
165 | if( !data || !index ) | 207 | if( !data || !index ) |
166 | exit( 1 ); | 208 | exit( 1 ); |
167 | 209 | ||
168 | g_northern_version = data->addr[0x21e] != 5; | 210 | switch( data->addr[0x228] ) { |
211 | case 0x07: g_cd = CD_NO; break; | ||
212 | case 0x0d: g_cd = CD_S; break; | ||
213 | case 0x0e: g_cd = CD_W; break; | ||
214 | default: fprintf( stderr, "Unknown CD version\n" ); | ||
215 | exit(1); | ||
216 | } | ||
169 | 217 | ||
170 | /* Each entry in outfile[0] is flag + \n, i.e. 3 bytes | 218 | /* Each entry in outfile[0] is flag + \n, i.e. 3 bytes |
171 | We want to flush at ever percent progress */ | 219 | We want to flush at ever percent progress */ |