summaryrefslogtreecommitdiff
path: root/src/postprocess/dumpindex2.c
blob: f49a32905e591cbe4651d8e66bc60c1a1394aedd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "mystdlib.h"
#include <sys/mman.h>
#include <fcntl.h>

static int indexed = -1;

int main( int argc, char **argv ) {
  MAP  index   = NULL;
  int  i,j;
  char out[50];

  if( argc != 3 )
  { fputs( "Syntax: sortindex <indexedfile> <indexfile>", stderr); exit( 1 ); }

  if( ( indexed = open( argv[1], O_RDONLY ) ) == -1 )
  { fprintf( stderr, "Could not open file: %s\n", argv[1] ); exit( 1 ); }

  if( !(index = map_file( argv[2], 0 ) ) ) exit( 1 );

  for( i = 0; i < index->size; i+= 16 ) {
    unsigned char *x = i + (unsigned char*)index->addr;
    unsigned long p = *(unsigned long*)x;

    pread( indexed, out, 40, (off_t)p );
    for( j=0;j<40;++j) if( out[j] == '\t' || out[j] == '\n' ) out[j] = 0; out[j] = 0;
    puts( out );
  }
    
  unmap_file( &index );
  close( indexed );

  return 0;
}