From f784fc3b3356109aecd7b44486513f7f5a2dcce9 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 2 Jun 2015 19:44:38 +0200 Subject: Add join tool to use after the makelam script --- src/postprocess/join.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/postprocess/join.c (limited to 'src') diff --git a/src/postprocess/join.c b/src/postprocess/join.c new file mode 100644 index 0000000..9782ec8 --- /dev/null +++ b/src/postprocess/join.c @@ -0,0 +1,81 @@ +#include +#include +#include "mystdlib.h" + +#define HUGEBLOCK (1024*1024*256) +#define ZIP_FIELD 3 +#define STREET_FIELD 5 + +int rt_strcmp( uint8_t *a, uint8_t *b ) { + while( ( *a != '\n' ) && ( *b != '\n' ) && ( *a == *b ) ) ++a, ++b; + if( *a == *b ) return 0; + return -1; +} + +size_t rt_strcpy( uint8_t *dest, uint8_t *src ) { + uint8_t *d = dest; + while( *src != '\n' ) + *dest++ = *src++; + *dest++ = '\n'; + return dest - d; +} + +size_t rt_strlen( uint8_t *str ) { + uint8_t *s = str; + while( *str++ != '\n' ); + return str - s; +} + +int main( int argc, char **argv ) { + MAP file = map_file( argv[1], 1 ); + uint8_t *out, *in; + size_t last = 3, off = 0, out_off = 0; + int start, end, copy; + + (void)argc; + + out = malloc( HUGEBLOCK ); + + if( !file || !out ) + exit(1); + + in = file->addr; + start = 10 * ( in[off] - '0' ) + in[off+1] - '0'; + end = start - 1; + + while( off < file->size ) { + int issue = 10 * ( in[off] - '0' ) + in[off+1] - '0'; + off += 3; + copy = 1; + +// fprintf( stderr, "issue: %02d start %02d end %02d last %08d off %08d", issue, start, end, last, off ); + switch ( rt_strcmp( in + last, in + off ) ) { + case 1: + last = off; + case 0: + case 2: + if (issue == end + 1 ) copy = 0, end++; + if (issue == end ) copy = 0; + break; + default: + break; + } +// fprintf( stderr, " copy: %d\n", copy ); + + if( copy) { + out_off += sprintf( (char*)out + out_off, "%02d%02d\a", start, end ); + out_off += rt_strcpy( out + out_off, in + last ); + start = issue; end = issue; + last = off; + } + + off += rt_strlen( in + off ); + + if( out_off + 8192 * 2 > HUGEBLOCK ) { + fwrite( out, out_off, 1, stdout ); + out_off = 0; + } + } + + return 0; +} -- cgit v1.2.3