summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2015-05-12 03:53:03 +0200
committerDirk Engling <erdgeist@erdgeist.org>2015-05-12 03:53:03 +0200
commit0aa86c5517397a635ca1e63747dd1eefad944960 (patch)
tree974774570aa6f89666048c66453696dfbc689d25
parent08a9f406a0e18e0902bdf4f50b4f5ecad9fe2588 (diff)
Split continuation records into files, too.
-rw-r--r--src/export/split_version_2.c98
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
1101_unknown => 01_Flags
1217_unknown => 02_Nachname
1308_unknown => 03_Vorname
1412_unknown => 04_Zusaetze
15 14_unknown => 05_Zusaetze (sw)
16 15_unknown => 05_Zusaetze (no)
1713_unknown => 06_Ortszusatz
1809_unknown => 07_Strasse
1911_unknown => 08_Hausnummer
20 15_unknown => 09_Verweise (sw)
21 14_unknown => 09_Verweise (no)
2204_unknown => 10_Postleitzahl
2310_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
304003 01 01 01
314007 - - 5:"0"
324009 - *:"0" -
33400B - - 6:"0"
34400C - !!! - => in 1996_Q1: 04_Namenszusatz
35400E 15 07 -
36400F 06 06 14
374010 - - 07
384011 17 - 17
394012 07 17 06
404013 14 09 09
414014 13 11 11
424015 09 15 04
434016 11 04 10
444017 04 10 13
454018 10 14 -
46401A - 13 15
47401B 08 08 08
48401C 12 12 12
49
50*/
51
9enum { g_outfiles = 17 }; 52enum { g_outfiles = 17 };
53static enum { CD_NO = 0, CD_S = 1, CD_W = 2 } g_cd;
54static 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
11static struct { 60static 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
17static int g_northern_version;;
18static uint8_t cp437_to_iso8859_1_table[] = { 66static 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
37static void dump_string( uint8_t *start, size_t len, int file ) { 85static 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
44static void dump_field( uint8_t **end, int file ) { 90static 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
50static void finish_record( ) { 95static 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
56static uint16_t load_word( uint8_t *table_start, uint16_t base, int offset ) { 101static 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
69static void dump_primary( uint8_t *end, uint32_t flags ) { 113static 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 */