From fb3616e06ca20ffe78dfb00b962a2599a46b2a5f Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 29 Jun 2019 18:51:00 +0200 Subject: Clean up 1992 post processing --- src/export/extract_version_1.c | 16 +++++++++------- src/export/mystdlib.c | 4 +++- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/export') 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[] = { }; static struct { - int outfiles[15]; - uint8_t *outbuf[15]; - size_t outfill[15]; + int outfiles[16]; + uint8_t *outbuf[16]; + size_t outfill[16]; char * vorwahl; char ort[1024]; size_t ort_len; @@ -101,11 +101,13 @@ static void split_to_files( uint8_t *entries, int num_entries ) *( g_state.outbuf[0] + g_state.outfill[0]++ ) = num_entries > 1 ? '1' : '0'; 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; + strcpy( g_state.outbuf[14] + g_state.outfill[14], g_state.vorwahl); g_state.outfill[14] += strlen(g_state.vorwahl); } *( g_state.outbuf[0 ] + g_state.outfill[0 ]++ ) = '\n'; *( g_state.outbuf[12] + g_state.outfill[12]++ ) = '\n'; *( g_state.outbuf[13] + g_state.outfill[13]++ ) = '\n'; + *( g_state.outbuf[14] + g_state.outfill[14]++ ) = '\n'; if( !end ) return; } @@ -178,7 +180,7 @@ static void act_on_file( uint8_t *file ) g_state.zip_len = snprintf( g_state.zip, sizeof(g_state.zip), "%s", zip ); g_state.vorwahl = vorwahl; - /* printf( "Working on a %04d page and %06d records file, city: %4s %-32s with prefix %s\n", num_pages, num_records, zip, ort, vorwahl ); */ + printf( "Working on a %04d page and %06d records file, city: %4s %-32s with prefix %s\n", num_pages, num_records, zip, ort, vorwahl ); (void)num_records; /* silence warning about unused variable */ for( page = 0; page < num_pages; ++page ) @@ -193,7 +195,7 @@ int main( ) ssize_t temp = 0; int i; - for( i=0; i<14; ++i ) + for( i=0; i<15; ++i ) { sprintf( filename, "%02d_unknown", i+1 ); g_state.outfiles[i] = open( filename, O_WRONLY | O_APPEND | O_CREAT, 0644 ); @@ -209,14 +211,14 @@ int main( ) unmap_file( &f ); /* Write out results */ - for( i=0; i<14; ++i ) { + for( i=0; i<15; ++i ) { /* if( g_state.outfill[i] > 1024*1024*6 ) printf( "Large: %s %zd\n", g_state.ort, g_state.outfill[i] ); */ temp += write( g_state.outfiles[i], g_state.outbuf[i], g_state.outfill[i] ); g_state.outfill[i] = 0; } } - for( i=0; i<14; ++i ) { + for( i=0; i<15; ++i ) { temp += write( g_state.outfiles[i], g_state.outbuf[i], g_state.outfill[i] ); close( g_state.outfiles[i] ); } 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 ) if( ( map->fh = open( filename, readonly ? O_RDONLY : O_RDWR ) ) >= 0 ) { fstat( map->fh, &fstatus ); - if( ( map->addr = mmap( NULL, map->size = (size_t)fstatus.st_size, + map->size = (size_t)fstatus.st_size; + if (!map->size) return map; + if( ( map->addr = mmap( NULL, map->size, PROT_READ | ( readonly ? 0 : PROT_WRITE), (readonly ? MAP_PRIVATE : MAP_SHARED), map->fh, 0) ) == MAP_FAILED ) { fprintf( stderr, "Mapping file '%s' failed\n", filename ); -- cgit v1.2.3