diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/splitold.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/splitold.c b/src/splitold.c index 847eb2c..bd85775 100644 --- a/src/splitold.c +++ b/src/splitold.c | |||
@@ -1,4 +1,3 @@ | |||
1 | #include "mystdlib.h" | ||
2 | #include <stdint.h> | 1 | #include <stdint.h> |
3 | #include <stdio.h> | 2 | #include <stdio.h> |
4 | #include <unistd.h> | 3 | #include <unistd.h> |
@@ -6,31 +5,37 @@ | |||
6 | #include <stdlib.h> | 5 | #include <stdlib.h> |
7 | #include <string.h> | 6 | #include <string.h> |
8 | 7 | ||
9 | int main() { | 8 | int main( int argc, char **args ) { |
10 | char table[64]; | 9 | char table[64], f[1024*1024*16]; |
11 | int outfiles[64], i, off; | 10 | int outfiles[64], i, off, base = 0; |
11 | uint32_t fixed_columns = 0; | ||
12 | |||
13 | if( argc > 1 ) base = atol( args[1] ); | ||
14 | if( argc > 2 ) fixed_columns = atol( args[2] ); | ||
12 | 15 | ||
13 | for( i=0; i<64; ++i ) outfiles[i] = -1; | 16 | for( i=0; i<64; ++i ) outfiles[i] = -1; |
14 | while( fgets( table, sizeof(table), stdin ) ) { | 17 | while( fgets( table, sizeof(table), stdin ) ) { |
15 | int off = ( table[strlen(table)-1] = 0 ); /* fgets sucks */ | 18 | int off = ( table[strlen(table)-1] = 0 ); /* fgets sucks */ |
16 | MAP f = map_file( table, 1 ); | 19 | int f_in = open( table, O_RDONLY ); |
17 | uint32_t *p = (uint32_t*)(f->addr); | 20 | size_t s_in = read( f_in, f, sizeof(f)); |
18 | uint32_t count = p[0], columns = p[1] / 4 - 1; | 21 | uint32_t *p = (uint32_t*)f; |
22 | uint32_t count = p[0], columns = fixed_columns ? fixed_columns : p[1] / 4 - 1; | ||
19 | unsigned int file, strnr; | 23 | unsigned int file, strnr; |
20 | 24 | ||
25 | close(f_in); | ||
26 | |||
21 | for( file=0; file<columns; ++file ) { | 27 | for( file=0; file<columns; ++file ) { |
22 | /* Create outfile, if it is not yet there */ | 28 | /* Create outfile, if it is not yet there */ |
23 | if( outfiles[file] == -1 ) { | 29 | if( outfiles[file] == -1 ) { |
24 | sprintf( table, "%02d_unknown", file+4 ); | 30 | sprintf( table, "%02d_unknown", file+base ); |
25 | outfiles[file] = open( table, O_WRONLY | O_APPEND | O_CREAT, 0644 ); | 31 | outfiles[file] = open( table, O_WRONLY | O_APPEND | O_CREAT, 0644 ); |
26 | if ( outfiles[file] == -1 ) exit(1); | 32 | if ( outfiles[file] == -1 ) exit(1); |
27 | } | 33 | } |
28 | off = p[file+1]; | 34 | off = p[file+1]; |
29 | /* Look for end of this chunk, which is <count> strings long */ | 35 | /* Look for end of this chunk, which is <count> strings long */ |
30 | for( strnr=0; strnr < count; ++strnr ) while( f->addr[off++] ); | 36 | for( strnr=0; strnr < count; ++strnr ) { while( f[off++] ) {}; f[off-1] = '\n'; } |
31 | write( outfiles[file], f->addr + p[file+1], off - p[file+1] ); | 37 | write( outfiles[file], f + p[file+1], off - p[file+1] ); |
32 | } | 38 | } |
33 | unmap_file(&f); | ||
34 | } | 39 | } |
35 | for( i=0; i<64; ++i ) close( outfiles[i] ); | 40 | for( i=0; i<64; ++i ) close( outfiles[i] ); |
36 | return 0; | 41 | return 0; |