summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2015-04-30 20:32:16 +0200
committerDirk Engling <erdgeist@erdgeist.org>2015-04-30 20:32:16 +0200
commitead065ba63899034fefc28d04a8496025c15508e (patch)
tree602fead95590a5b6dc1f0731c987a55c11567ece /src
parent19361ed933b4f1ccbb865520e5e5f3bf24cbd063 (diff)
Fix broken lines and a too short conversion table for cp437
Diffstat (limited to 'src')
-rw-r--r--src/export/extract_version_1.c43
1 files changed, 26 insertions, 17 deletions
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[] = {
32 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9, 0xff, 0xd6, 0xdc, 0xa2, 0xa3, 0xa5, 0x2e, 0x2e, 32 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9, 0xff, 0xd6, 0xdc, 0xa2, 0xa3, 0xa5, 0x2e, 0x2e,
33 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba, 0xbf, 0x2e, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb, 33 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba, 0xbf, 0x2e, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb,
34 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 34 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
35 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
36 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
35 0x2e, 0xdf, 0x2e, 0x2e, 0x2e, 0x2e, 0xb5, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 37 0x2e, 0xdf, 0x2e, 0x2e, 0x2e, 0x2e, 0xb5, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
36 0x2e, 0xb1, 0x2e, 0x2e, 0x2e, 0x2e, 0xf7, 0x2e, 0xb0, 0x2e, 0xb7, 0x2e, 0x2e, 0xb2, 0x2e, 0xa0 38 0x2e, 0xb1, 0x2e, 0x2e, 0x2e, 0x2e, 0xf7, 0x2e, 0xb0, 0x2e, 0xb7, 0x2e, 0x2e, 0xb2, 0x2e, 0xa0
37}; 39};
@@ -63,32 +65,39 @@ again:
63static void split_to_files( uint8_t *entries, int num_entries ) 65static void split_to_files( uint8_t *entries, int num_entries )
64{ 66{
65 int entry = 0, column; 67 int entry = 0, column;
66 char *e = (char*)entries; 68 char *end, *e = (char*)entries;
67 69
68 for( entry = 0; entry < num_entries; ++entry ) 70 for( entry = 0; entry < num_entries; ++entry )
69 { 71 {
70 /* mimic flags from telefonbuch v3 */
71 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;
72 memcpy( g_state.outbuf[12] + g_state.outfill[12], g_state.ort, g_state.ort_len ); g_state.outfill[12] += g_state.ort_len;
73 memcpy( g_state.outbuf[13] + g_state.outfill[13], g_state.zip, g_state.zip_len ); g_state.outfill[13] += g_state.zip_len;
74
75 for( column = 0; column < 11; ++column ) 72 for( column = 0; column < 11; ++column )
76 { 73 {
77 char * end = strchr( e, '\n' ); 74 end = strchr( e, '\n' );
78 if( !end ) { 75 if( !end ) {
79 fprintf( stderr, "Unexpected end of line in city: %s", g_state.ort ); 76 fprintf( stderr, "Unexpected end of line in city: %s", g_state.ort );
80 /* fprintf( stderr, "Failing String, (%d of %d entries, column %d): ###%s\n", entry, num_entries, column, entries ); */ 77 /* fprintf( stderr, "Failing String, (%d of %d entries, column %d): ###%s\n", entry, num_entries, column, entries ); */
81 if( column ) for( ; column < 11; ++column) { 78 if( !column )
82 memcpy( g_state.outbuf[column+1] + g_state.outfill[column+1], "#\n", 2 ); 79 return;
83 g_state.outfill[column+1] += 2; 80
84 } 81 for( ; column < 11; ++column) {
85 return; 82 memcpy( g_state.outbuf[column+1] + g_state.outfill[column+1], "#\n", 2 );
83 g_state.outfill[column+1] += 2;
84 }
85 break;
86 } 86 }
87 87
88 if( column == 9 && *e >= '0' && *e <= '9' ) *--e = '0'; /* Augment Vorwahl */ 88 if( column == 9 && *e >= '0' && *e <= '9' )
89 memcpy( g_state.outbuf[column+1] + g_state.outfill[column+1], e, (size_t)(++end - e) ); g_state.outfill[column+1] += end - e; 89 *--e = '0'; /* Augment Vorwahl */
90 memcpy( g_state.outbuf[column+1] + g_state.outfill[column+1], e, (size_t)(++end - e) );
91 g_state.outfill[column+1] += end - e;
90 e = end; 92 e = end;
91 } 93 }
94
95 /* mimic flags from telefonbuch v3 */
96 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;
97 memcpy( g_state.outbuf[12] + g_state.outfill[12], g_state.ort, g_state.ort_len ); g_state.outfill[12] += g_state.ort_len;
98 memcpy( g_state.outbuf[13] + g_state.outfill[13], g_state.zip, g_state.zip_len ); g_state.outfill[13] += g_state.zip_len;
99 if( !end )
100 return;
92 } 101 }
93} 102}
94 103
@@ -152,7 +161,7 @@ static void act_on_file( uint8_t *file )
152 char *vorwahl = zip + 1 + strlen(zip); 161 char *vorwahl = zip + 1 + strlen(zip);
153 162
154 for(i=0; ort[i]; ++i ) 163 for(i=0; ort[i]; ++i )
155 g_state.ort[i] = (char)cp437_to_iso8859_1_table[((uint8_t*)ort)[i]]; 164 g_state.ort[i] = (char)cp437_to_iso8859_1_table[(uint8_t)((uint8_t*)ort)[i]];
156 g_state.ort[i++] = '\n'; 165 g_state.ort[i++] = '\n';
157 g_state.ort[i] = 0; 166 g_state.ort[i] = 0;
158 g_state.ort_len = i; 167 g_state.ort_len = i;