From 0aa86c5517397a635ca1e63747dd1eefad944960 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 12 May 2015 03:53:03 +0200 Subject: Split continuation records into files, too. --- src/export/split_version_2.c | 98 +++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 25 deletions(-) (limited to 'src') 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 @@ #include "mystdlib.h" +/* + +01_unknown => 01_Flags +17_unknown => 02_Nachname +08_unknown => 03_Vorname +12_unknown => 04_Zusaetze + 14_unknown => 05_Zusaetze (sw) + 15_unknown => 05_Zusaetze (no) +13_unknown => 06_Ortszusatz +09_unknown => 07_Strasse +11_unknown => 08_Hausnummer + 15_unknown => 09_Verweise (sw) + 14_unknown => 09_Verweise (no) +04_unknown => 10_Postleitzahl +10_unknown => 11_Ort + 06_unknown => 12_Vorwahl (sw) + 07_unknown => 12_Vorwahl (no) + 07_unknown => 13_Rufnummer (sw) + 06_unknown => 13_Rufnummer (no) + + no s w +4003 01 01 01 +4007 - - 5:"0" +4009 - *:"0" - +400B - - 6:"0" +400C - !!! - => in 1996_Q1: 04_Namenszusatz +400E 15 07 - +400F 06 06 14 +4010 - - 07 +4011 17 - 17 +4012 07 17 06 +4013 14 09 09 +4014 13 11 11 +4015 09 15 04 +4016 11 04 10 +4017 04 10 13 +4018 10 14 - +401A - 13 15 +401B 08 08 08 +401C 12 12 12 + +*/ + enum { g_outfiles = 17 }; +static enum { CD_NO = 0, CD_S = 1, CD_W = 2 } g_cd; +static int g_outfilemap[3][29] = { + {-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 }, + {-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 }, + {-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 } +}; static struct { int outfiles[g_outfiles]; @@ -14,7 +63,6 @@ static struct { size_t outfill [g_outfiles]; } g_state; -static int g_northern_version;; static uint8_t cp437_to_iso8859_1_table[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 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[] = { }; static void dump_string( uint8_t *start, size_t len, int file ) { - uint8_t *dest = g_state.outbuf[file] + g_state.outfill[file]; - g_state.outfill[file] += len; - while( len-- ) - *(dest++) = cp437_to_iso8859_1_table[ *(start++) ]; + while( len-- && *start ) + g_state.outbuf[file][g_state.outfill[file]++] = cp437_to_iso8859_1_table[*start++]; } static void dump_field( uint8_t **end, int file ) { uint8_t len = (*end)[-1]; - *end -= len + 1; - dump_string( *end, len, file); + dump_string( *end -= len + 1, len, file); } static void finish_record( ) { - int i; - for( i=0; i 0x1ffc ) table_start += 3 & ( 4 - ( base & 3 ) ); - return ((uint16_t*)table_start)[offset]; + return ((uint16_t*)table_start)[offset + 2]; } static void dump_primary( uint8_t *end, uint32_t flags ) { @@ -74,7 +118,7 @@ static void dump_primary( uint8_t *end, uint32_t flags ) { dump_string( end -= 5, 5, 1 ); /* Dump first 5 chars of prefix, they're always here in s and w */ - if( !g_northern_version ) + if( g_cd != CD_NO ) dump_string( end -= 5, 5, 2 ); /* 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 ) { /* There is an unclear X present, if this bit is set */ if( flags & 0x0040 ) dump_string( end -= 1, 1, 4 ); - /* There is another version of the prefix present, if this bit is set */ if( flags & 0x0020 ) { - if( !g_northern_version ) + if( g_cd != CD_NO ) dump_string( end -= 5, 5, 5 ); else dump_field( &end, 5 ); @@ -104,7 +147,7 @@ static void dump_primary( uint8_t *end, uint32_t flags ) { dump_field( &end, 15 ); /* Dump first 5 chars of prefix, they're always here in no */ - if( g_northern_version ) + if( g_cd == CD_NO ) dump_field( &end, 2 ); dump_field( &end, 16 ); } @@ -117,23 +160,22 @@ static void act_on_record( uint8_t * end, uint16_t base ) { uint32_t flags = 0; int i; - for (i=0; i= 0 ) + dump_string( rec_start, rec_end - rec_start, g_outfilemap[g_cd][subflag&0x1F] ); } } finish_record(); @@ -165,7 +207,13 @@ int main( int args, char **argv ) { if( !data || !index ) exit( 1 ); - g_northern_version = data->addr[0x21e] != 5; + switch( data->addr[0x228] ) { + case 0x07: g_cd = CD_NO; break; + case 0x0d: g_cd = CD_S; break; + case 0x0e: g_cd = CD_W; break; + default: fprintf( stderr, "Unknown CD version\n" ); + exit(1); + } /* Each entry in outfile[0] is flag + \n, i.e. 3 bytes We want to flush at ever percent progress */ -- cgit v1.2.3