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