summaryrefslogtreecommitdiff
path: root/src/export
diff options
context:
space:
mode:
Diffstat (limited to 'src/export')
-rw-r--r--src/export/extract_version_1.c16
-rw-r--r--src/export/mystdlib.c4
2 files changed, 12 insertions, 8 deletions
diff --git a/src/export/extract_version_1.c b/src/export/extract_version_1.c
index 8ec199e..6d67a5d 100644
--- a/src/export/extract_version_1.c
+++ b/src/export/extract_version_1.c
@@ -39,9 +39,9 @@ static uint8_t cp437_to_iso8859_1_table[] = {
39}; 39};
40 40
41static struct { 41static struct {
42 int outfiles[15]; 42 int outfiles[16];
43 uint8_t *outbuf[15]; 43 uint8_t *outbuf[16];
44 size_t outfill[15]; 44 size_t outfill[16];
45 char * vorwahl; 45 char * vorwahl;
46 char ort[1024]; 46 char ort[1024];
47 size_t ort_len; 47 size_t ort_len;
@@ -101,11 +101,13 @@ static void split_to_files( uint8_t *entries, int num_entries )
101 *( g_state.outbuf[0] + g_state.outfill[0]++ ) = num_entries > 1 ? '1' : '0'; 101 *( g_state.outbuf[0] + g_state.outfill[0]++ ) = num_entries > 1 ? '1' : '0';
102 memcpy( g_state.outbuf[12] + g_state.outfill[12], g_state.ort, g_state.ort_len ); g_state.outfill[12] += g_state.ort_len; 102 memcpy( g_state.outbuf[12] + g_state.outfill[12], g_state.ort, g_state.ort_len ); g_state.outfill[12] += g_state.ort_len;
103 memcpy( g_state.outbuf[13] + g_state.outfill[13], g_state.zip, g_state.zip_len ); g_state.outfill[13] += g_state.zip_len; 103 memcpy( g_state.outbuf[13] + g_state.outfill[13], g_state.zip, g_state.zip_len ); g_state.outfill[13] += g_state.zip_len;
104 strcpy( g_state.outbuf[14] + g_state.outfill[14], g_state.vorwahl); g_state.outfill[14] += strlen(g_state.vorwahl);
104 } 105 }
105 106
106 *( g_state.outbuf[0 ] + g_state.outfill[0 ]++ ) = '\n'; 107 *( g_state.outbuf[0 ] + g_state.outfill[0 ]++ ) = '\n';
107 *( g_state.outbuf[12] + g_state.outfill[12]++ ) = '\n'; 108 *( g_state.outbuf[12] + g_state.outfill[12]++ ) = '\n';
108 *( g_state.outbuf[13] + g_state.outfill[13]++ ) = '\n'; 109 *( g_state.outbuf[13] + g_state.outfill[13]++ ) = '\n';
110 *( g_state.outbuf[14] + g_state.outfill[14]++ ) = '\n';
109 if( !end ) 111 if( !end )
110 return; 112 return;
111 } 113 }
@@ -178,7 +180,7 @@ static void act_on_file( uint8_t *file )
178 g_state.zip_len = snprintf( g_state.zip, sizeof(g_state.zip), "%s", zip ); 180 g_state.zip_len = snprintf( g_state.zip, sizeof(g_state.zip), "%s", zip );
179 g_state.vorwahl = vorwahl; 181 g_state.vorwahl = vorwahl;
180 182
181 /* printf( "Working on a %04d page and %06d records file, city: %4s %-32s with prefix %s\n", num_pages, num_records, zip, ort, vorwahl ); */ 183 printf( "Working on a %04d page and %06d records file, city: %4s %-32s with prefix %s\n", num_pages, num_records, zip, ort, vorwahl );
182 (void)num_records; /* silence warning about unused variable */ 184 (void)num_records; /* silence warning about unused variable */
183 185
184 for( page = 0; page < num_pages; ++page ) 186 for( page = 0; page < num_pages; ++page )
@@ -193,7 +195,7 @@ int main( )
193 ssize_t temp = 0; 195 ssize_t temp = 0;
194 int i; 196 int i;
195 197
196 for( i=0; i<14; ++i ) 198 for( i=0; i<15; ++i )
197 { 199 {
198 sprintf( filename, "%02d_unknown", i+1 ); 200 sprintf( filename, "%02d_unknown", i+1 );
199 g_state.outfiles[i] = open( filename, O_WRONLY | O_APPEND | O_CREAT, 0644 ); 201 g_state.outfiles[i] = open( filename, O_WRONLY | O_APPEND | O_CREAT, 0644 );
@@ -209,14 +211,14 @@ int main( )
209 unmap_file( &f ); 211 unmap_file( &f );
210 212
211 /* Write out results */ 213 /* Write out results */
212 for( i=0; i<14; ++i ) { 214 for( i=0; i<15; ++i ) {
213 /* if( g_state.outfill[i] > 1024*1024*6 ) printf( "Large: %s %zd\n", g_state.ort, g_state.outfill[i] ); */ 215 /* if( g_state.outfill[i] > 1024*1024*6 ) printf( "Large: %s %zd\n", g_state.ort, g_state.outfill[i] ); */
214 temp += write( g_state.outfiles[i], g_state.outbuf[i], g_state.outfill[i] ); 216 temp += write( g_state.outfiles[i], g_state.outbuf[i], g_state.outfill[i] );
215 g_state.outfill[i] = 0; 217 g_state.outfill[i] = 0;
216 } 218 }
217 } 219 }
218 220
219 for( i=0; i<14; ++i ) { 221 for( i=0; i<15; ++i ) {
220 temp += write( g_state.outfiles[i], g_state.outbuf[i], g_state.outfill[i] ); 222 temp += write( g_state.outfiles[i], g_state.outbuf[i], g_state.outfill[i] );
221 close( g_state.outfiles[i] ); 223 close( g_state.outfiles[i] );
222 } 224 }
diff --git a/src/export/mystdlib.c b/src/export/mystdlib.c
index b65f63d..31c991e 100644
--- a/src/export/mystdlib.c
+++ b/src/export/mystdlib.c
@@ -21,7 +21,9 @@ MAP map_file( char *filename, int readonly )
21 if( ( map->fh = open( filename, readonly ? O_RDONLY : O_RDWR ) ) >= 0 ) 21 if( ( map->fh = open( filename, readonly ? O_RDONLY : O_RDWR ) ) >= 0 )
22 { 22 {
23 fstat( map->fh, &fstatus ); 23 fstat( map->fh, &fstatus );
24 if( ( map->addr = mmap( NULL, map->size = (size_t)fstatus.st_size, 24 map->size = (size_t)fstatus.st_size;
25 if (!map->size) return map;
26 if( ( map->addr = mmap( NULL, map->size,
25 PROT_READ | ( readonly ? 0 : PROT_WRITE), (readonly ? MAP_PRIVATE : MAP_SHARED), map->fh, 0) ) == MAP_FAILED ) 27 PROT_READ | ( readonly ? 0 : PROT_WRITE), (readonly ? MAP_PRIVATE : MAP_SHARED), map->fh, 0) ) == MAP_FAILED )
26 { 28 {
27 fprintf( stderr, "Mapping file '%s' failed\n", filename ); 29 fprintf( stderr, "Mapping file '%s' failed\n", filename );