From ead065ba63899034fefc28d04a8496025c15508e Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Thu, 30 Apr 2015 20:32:16 +0200 Subject: Fix broken lines and a too short conversion table for cp437 --- src/export/extract_version_1.c | 43 +++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/export/extract_version_1.c b/src/export/extract_version_1.c index 8ab3190..c138784 100644 --- a/src/export/extract_version_1.c +++ b/src/export/extract_version_1.c @@ -32,6 +32,8 @@ static uint8_t cp437_to_iso8859_1_table[] = { 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9, 0xff, 0xd6, 0xdc, 0xa2, 0xa3, 0xa5, 0x2e, 0x2e, 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba, 0xbf, 0x2e, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, + 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, + 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0xdf, 0x2e, 0x2e, 0x2e, 0x2e, 0xb5, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0xb1, 0x2e, 0x2e, 0x2e, 0x2e, 0xf7, 0x2e, 0xb0, 0x2e, 0xb7, 0x2e, 0x2e, 0xb2, 0x2e, 0xa0 }; @@ -63,32 +65,39 @@ again: static void split_to_files( uint8_t *entries, int num_entries ) { int entry = 0, column; - char *e = (char*)entries; + char *end, *e = (char*)entries; for( entry = 0; entry < num_entries; ++entry ) { - /* mimic flags from telefonbuch v3 */ - memcpy( g_state.outbuf[0 ] + g_state.outfill[0 ], entry ? "02\n" : ( num_entries > 1 ? "01\n" : "00\n" ), 3 ); g_state.outfill[0] += 3; - memcpy( g_state.outbuf[12] + g_state.outfill[12], g_state.ort, g_state.ort_len ); g_state.outfill[12] += g_state.ort_len; - memcpy( g_state.outbuf[13] + g_state.outfill[13], g_state.zip, g_state.zip_len ); g_state.outfill[13] += g_state.zip_len; - for( column = 0; column < 11; ++column ) { - char * end = strchr( e, '\n' ); + end = strchr( e, '\n' ); if( !end ) { - fprintf( stderr, "Unexpected end of line in city: %s", g_state.ort ); - /* fprintf( stderr, "Failing String, (%d of %d entries, column %d): ###%s\n", entry, num_entries, column, entries ); */ - if( column ) for( ; column < 11; ++column) { - memcpy( g_state.outbuf[column+1] + g_state.outfill[column+1], "#\n", 2 ); - g_state.outfill[column+1] += 2; - } - return; + fprintf( stderr, "Unexpected end of line in city: %s", g_state.ort ); + /* fprintf( stderr, "Failing String, (%d of %d entries, column %d): ###%s\n", entry, num_entries, column, entries ); */ + if( !column ) + return; + + for( ; column < 11; ++column) { + memcpy( g_state.outbuf[column+1] + g_state.outfill[column+1], "#\n", 2 ); + g_state.outfill[column+1] += 2; + } + break; } - if( column == 9 && *e >= '0' && *e <= '9' ) *--e = '0'; /* Augment Vorwahl */ - memcpy( g_state.outbuf[column+1] + g_state.outfill[column+1], e, (size_t)(++end - e) ); g_state.outfill[column+1] += end - e; + if( column == 9 && *e >= '0' && *e <= '9' ) + *--e = '0'; /* Augment Vorwahl */ + memcpy( g_state.outbuf[column+1] + g_state.outfill[column+1], e, (size_t)(++end - e) ); + g_state.outfill[column+1] += end - e; e = end; } + + /* mimic flags from telefonbuch v3 */ + memcpy( g_state.outbuf[0 ] + g_state.outfill[0 ], entry ? "02\n" : ( num_entries > 1 ? "01\n" : "00\n" ), 3 ); g_state.outfill[0] += 3; + memcpy( g_state.outbuf[12] + g_state.outfill[12], g_state.ort, g_state.ort_len ); g_state.outfill[12] += g_state.ort_len; + memcpy( g_state.outbuf[13] + g_state.outfill[13], g_state.zip, g_state.zip_len ); g_state.outfill[13] += g_state.zip_len; + if( !end ) + return; } } @@ -152,7 +161,7 @@ static void act_on_file( uint8_t *file ) char *vorwahl = zip + 1 + strlen(zip); for(i=0; ort[i]; ++i ) - g_state.ort[i] = (char)cp437_to_iso8859_1_table[((uint8_t*)ort)[i]]; + g_state.ort[i] = (char)cp437_to_iso8859_1_table[(uint8_t)((uint8_t*)ort)[i]]; g_state.ort[i++] = '\n'; g_state.ort[i] = 0; g_state.ort_len = i; -- cgit v1.2.3