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