From 28f818ad8313da4bec3d0bf1abfbc93da3df4f70 Mon Sep 17 00:00:00 2001 From: User Erdgeist Date: Thu, 13 Feb 2014 21:14:03 +0000 Subject: Make splitold usable for nname files, too. It now also converts \0 to \n. --- src/splitold.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src') 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 @@ -#include "mystdlib.h" #include #include #include @@ -6,31 +5,37 @@ #include #include -int main() { - char table[64]; - int outfiles[64], i, off; +int main( int argc, char **args ) { + char table[64], f[1024*1024*16]; + int outfiles[64], i, off, base = 0; + uint32_t fixed_columns = 0; + + if( argc > 1 ) base = atol( args[1] ); + if( argc > 2 ) fixed_columns = atol( args[2] ); 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; + int f_in = open( table, O_RDONLY ); + size_t s_in = read( f_in, f, sizeof(f)); + uint32_t *p = (uint32_t*)f; + uint32_t count = p[0], columns = fixed_columns ? fixed_columns : p[1] / 4 - 1; unsigned int file, strnr; + close(f_in); + for( file=0; file strings long */ - for( strnr=0; strnr < count; ++strnr ) while( f->addr[off++] ); - write( outfiles[file], f->addr + p[file+1], off - p[file+1] ); + for( strnr=0; strnr < count; ++strnr ) { while( f[off++] ) {}; f[off-1] = '\n'; } + write( outfiles[file], f + 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