From 89bd63b861309eabce0cf7e7fc9f7963e64e9b8a Mon Sep 17 00:00:00 2001
From: Dirk Engling <erdgeist@erdgeist.org>
Date: Tue, 11 Feb 2014 17:11:58 +0100
Subject: Splitting up the old table file needs some speedup

---
 src/splitold.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 src/splitold.c

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 @@
+#include "mystdlib.h"
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main() {
+  char table[64];
+  int  outfiles[64], i, off;
+
+  for( i=0; i<64; ++i ) outfiles[i] = -1;
+  while( fgets( table, sizeof(table), stdin ) ) {
+    int off = ( table[strlen(table)-1] = 0 ); /* fgets sucks */
+    MAP f = map_file( table, 1 );
+    uint32_t *p = (uint32_t*)(f->addr);
+    uint32_t count = p[0], columns = p[1] / 4 - 1;
+    unsigned int file, strnr;
+
+    for( file=0; file<columns; ++file ) {
+      /* Create outfile, if it is not yet there */
+      if( outfiles[file] == -1 ) {
+        sprintf( table, "%02d_unknown", file+4 );
+        outfiles[file] = open( table, O_WRONLY | O_APPEND | O_CREAT, 0644 );
+        if ( outfiles[file] == -1 ) exit(1);
+      }
+      off = p[file+1];
+      /* Look for end of this chunk, which is <count> strings long */
+      for( strnr=0; strnr < count; ++strnr ) while( f->addr[off++] );
+      write( outfiles[file], f->addr + p[file+1], off - p[file+1] );
+    }
+    unmap_file(&f);
+  }
+  for( i=0; i<64; ++i ) close( outfiles[i] );
+  return 0;
+}
-- 
cgit v1.2.3