summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2015-06-02 19:44:38 +0200
committerDirk Engling <erdgeist@erdgeist.org>2015-06-02 19:44:38 +0200
commitf784fc3b3356109aecd7b44486513f7f5a2dcce9 (patch)
tree3dbd86f25748381c6334b657bf0aafd17e8201bc /src
parent4c3a31b1b03e72e65e080bfcb017ceb9619847a4 (diff)
Add join tool to use after the makelam script
Diffstat (limited to 'src')
-rw-r--r--src/postprocess/join.c81
1 files changed, 81 insertions, 0 deletions
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 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include "mystdlib.h"
4
5#define HUGEBLOCK (1024*1024*256)
6#define ZIP_FIELD 3
7#define STREET_FIELD 5
8
9int rt_strcmp( uint8_t *a, uint8_t *b ) {
10 while( ( *a != '\n' ) && ( *b != '\n' ) && ( *a == *b ) ) ++a, ++b;
11 if( *a == *b ) return 0;
12 return -1;
13}
14
15size_t rt_strcpy( uint8_t *dest, uint8_t *src ) {
16 uint8_t *d = dest;
17 while( *src != '\n' )
18 *dest++ = *src++;
19 *dest++ = '\n';
20 return dest - d;
21}
22
23size_t rt_strlen( uint8_t *str ) {
24 uint8_t *s = str;
25 while( *str++ != '\n' );
26 return str - s;
27}
28
29int main( int argc, char **argv ) {
30 MAP file = map_file( argv[1], 1 );
31 uint8_t *out, *in;
32 size_t last = 3, off = 0, out_off = 0;
33 int start, end, copy;
34
35 (void)argc;
36
37 out = malloc( HUGEBLOCK );
38
39 if( !file || !out )
40 exit(1);
41
42 in = file->addr;
43 start = 10 * ( in[off] - '0' ) + in[off+1] - '0';
44 end = start - 1;
45
46 while( off < file->size ) {
47 int issue = 10 * ( in[off] - '0' ) + in[off+1] - '0';
48 off += 3;
49 copy = 1;
50
51// fprintf( stderr, "issue: %02d start %02d end %02d last %08d off %08d", issue, start, end, last, off );
52 switch ( rt_strcmp( in + last, in + off ) ) {
53 case 1:
54 last = off;
55 case 0:
56 case 2:
57 if (issue == end + 1 ) copy = 0, end++;
58 if (issue == end ) copy = 0;
59 break;
60 default:
61 break;
62 }
63// fprintf( stderr, " copy: %d\n", copy );
64
65 if( copy) {
66 out_off += sprintf( (char*)out + out_off, "%02d%02d\a", start, end );
67 out_off += rt_strcpy( out + out_off, in + last );
68 start = issue; end = issue;
69 last = off;
70 }
71
72 off += rt_strlen( in + off );
73
74 if( out_off + 8192 * 2 > HUGEBLOCK ) {
75 fwrite( out, out_off, 1, stdout );
76 out_off = 0;
77 }
78 }
79
80 return 0;
81}