summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile9
-rw-r--r--src/mapcoords.c50
2 files changed, 56 insertions, 3 deletions
diff --git a/src/Makefile b/src/Makefile
index 8d1a66d..0ccb1f9 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,7 +1,10 @@
1all: decompress extractblocks 1all: decompress extractblocks mapcoords
2 2
3decompress: decompress.c mystdlib.c 3decompress: decompress.c mystdlib.c
4 gcc -O2 -o ../bin/decompress decompress.c mystdlib.c -lz 4 $(CC) -O2 -o ../bin/decompress decompress.c mystdlib.c -lz
5 5
6extractblocks: extractblocks_new.c mystdlib.c 6extractblocks: extractblocks_new.c mystdlib.c
7 gcc -o ../bin/extractblocks extractblocks_new.c mystdlib.c 7 $(CC) -o ../bin/extractblocks extractblocks_new.c mystdlib.c
8
9mapcoords: mapcoords.c mystdlib.c
10 $(CC) -o ../bin/mapcoords mapcoords.c mystdlib.c
diff --git a/src/mapcoords.c b/src/mapcoords.c
new file mode 100644
index 0000000..b7d19f6
--- /dev/null
+++ b/src/mapcoords.c
@@ -0,0 +1,50 @@
1#include "mystdlib.h"
2#include <stdlib.h>
3#include <stdio.h>
4#include <string.h>
5
6int find_offset( const void *key, const void *line )
7{
8 size_t l = strlen( *(char**)key );
9 return strncmp( *(char**)key, *(char**)line, l );
10}
11
12int qsort_cmp( const void *a, const void *b )
13{
14 return strcmp( *(char**)a, *(char**)b );
15}
16
17int main( int argc, char ** args )
18{
19 MAP coords = map_file( args[1], 1 );
20 int i, l, lines;
21 char *p, **offsets, *input = malloc(1024);
22 size_t input_length = 1024;
23
24 if( !coords ) exit( 111 );
25 p = (char *)coords->addr;
26 for ( i=0, lines=0; i<coords->size; ++i )
27 if( p[i] == 0x0a )
28 {
29 ++lines;
30 p[i] = 0;
31 }
32
33 offsets = malloc( lines * sizeof(char*));
34 if( !offsets ) exit( 111 );
35
36 offsets[0] = p; l = 1;
37 for ( i=0, lines=0; i<coords->size; ++i )
38 if( !p[i] )
39 offsets[l++] = p+i+1;
40
41 l--; qsort(offsets, l, sizeof(char*), qsort_cmp );
42
43 while( getline( &input, &input_length, stdin ) >= 0 )
44 {
45 char **coord_line = bsearch( input, offsets, l, sizeof(char*), find_offset );
46 printf( "%s\n", *coord_line + strlen( input ) );
47 }
48
49 return 0;
50}