From 73827ba1f4a50107272d6e465b92f356fb9e0abe Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Sun, 9 May 2004 14:53:42 +0000 Subject: initial --- src/splitfiles.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 src/splitfiles.c (limited to 'src/splitfiles.c') diff --git a/src/splitfiles.c b/src/splitfiles.c new file mode 100644 index 0000000..d49971b --- /dev/null +++ b/src/splitfiles.c @@ -0,0 +1,126 @@ +#include "mystdlib.h" + +#define NUMFIELDS 12 +#define PREFIX "teiln/" + +#define STREETFIELD 3 +#define HOUSENUMFIELD 4 +#define ZIPCODEFIELD 6 +#define TOWNFIELD 7 + +char **generate_index( MAP toindex ) +{ + off_t fileidx = 0, idxidx = 0; + char **index; + + while( fileidx < toindex->size ) + if( !toindex->addr[ fileidx++ ] ) idxidx++; + index = (char**)malloc( sizeof( char *) * idxidx ); + + fileidx = idxidx = 0; + if( index ) + { + while( fileidx < toindex->size ) + { + index[ idxidx++ ] = toindex->addr + fileidx; + while( (fileidx < toindex->size) && (toindex->addr[ fileidx++])); + } + } + return index; +} + +static int g_coordidxsize; + +int coordcmp( const void *s1, const void *s2 ) +{ + return strncmp( s1, s2, g_coordidxsize ); +} + +int main( ) +{ + int i = 0, j, k, leave = 0; + off_t in1, in2, in3; + char fname[32], **streetnames = NULL; + MAP streets = NULL, vnames, nnames, tables, coords = NULL; + + if( !(coords = map_file( "coords/list", true ))) goto cleanup_main; + if( !(streets = map_file( "streets/list",true ))) goto cleanup_main; + if( !(streetnames = generate_index( streets ))) goto cleanup_main; + + for( i=0; !leave; i+=3 ) + { + int fof[ NUMFIELDS ]; + char coordidx[160], *coordline; + vnames = nnames = tables = NULL; + + snprintf( fname, sizeof( fname ), PREFIX "%05d", i ); + if( !( tables = map_file( fname, true ) ) ) goto cleanup_loop; + snprintf( fname, sizeof( fname ), PREFIX "%05d", i+1 ); + if( !( nnames = map_file( fname, true ) ) ) goto cleanup_loop; + snprintf( fname, sizeof( fname ), PREFIX "%05d", i+2 ); + if( !( vnames = map_file( fname, true ) ) ) goto cleanup_loop; + + in1 = 0x34; in2 = 0x34; in3 = 0; + + for( j = 0; j < NUMFIELDS; ++j) + { + fof[ j ] = in1; + for( k = 0; k < 3000; ++k ) + while( tables->addr[ in1++ ]); + } + + for( j = 0; j < 3000; ++j ) + { + char *stringend; + int v = strtoul( tables->addr + fof[ STREETFIELD ], &stringend, 16 ); + char *currentstreet = ( stringend == (char*)(tables->addr + fof[ STREETFIELD ])) ? "" : streetnames[ v ]; + int xco= 0, yco= 0; + + printf( "%s\t%s", nnames->addr+in2, vnames->addr+in3 ); + while( nnames->addr[ in2++ ] ); + while( vnames->addr[ in3++ ] ); + + g_coordidxsize = snprintf( coordidx, sizeof( coordidx ), "%s;%s;%s;%s;", + tables->addr + fof [ ZIPCODEFIELD ], + tables->addr + fof [ TOWNFIELD ], + currentstreet, + tables->addr + fof [ HOUSENUMFIELD ] ); + + if( !(coordline = (char*)bsearch( coordidx, coords->addr, coords->size / 90, 90, coordcmp ))) coordline = ";;;;;;"; + v = 5; while( v--) { while( *coordline && *coordline++ != ';'); } + sscanf( coordline, "%d;%d", &xco, &yco ); + + for( k = 0; k < NUMFIELDS; ++k ) + { + if( k == STREETFIELD ) + { + printf( "\t%s", currentstreet); + } + else + printf( "\t%s", tables->addr + fof[ k ] ); + { + } + while( tables->addr [ fof[ k ]++] ); + } + + printf( "\t%d\t%d", xco, yco ); + putchar( 10 ); + } + + leave ^= 1; + + cleanup_loop: + leave ^= 1; + + unmap_file( &vnames ); + unmap_file( &nnames ); + unmap_file( &tables ); + } + + cleanup_main: + if( streetnames ) free( streetnames ); + unmap_file( &streets ); + unmap_file( &coords ); + + return 0; +} -- cgit v1.2.3