diff options
author | Dirk Engling <erdgeist@erdgeist.org> | 2014-02-20 22:42:56 +0100 |
---|---|---|
committer | Dirk Engling <erdgeist@erdgeist.org> | 2014-02-20 22:42:56 +0100 |
commit | 046857dfb88f05e6b310fe9ef07b9f2d3ac5922d (patch) | |
tree | 9ce854f9572168c3ec1fe6751276430fa4a79cd9 /src/mapcoords.c | |
parent | 64c85dfc1d3b546dd4b5f84168e9256817f3a741 (diff) |
Restructure project, make names more clear
Diffstat (limited to 'src/mapcoords.c')
-rw-r--r-- | src/mapcoords.c | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/src/mapcoords.c b/src/mapcoords.c deleted file mode 100644 index b46f1cf..0000000 --- a/src/mapcoords.c +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | #define _WITH_GETLINE | ||
2 | #include "mystdlib.h" | ||
3 | #include <stdlib.h> | ||
4 | #include <stdio.h> | ||
5 | #include <string.h> | ||
6 | #include <ctype.h> | ||
7 | |||
8 | int find_offset( const void *key, const void *line ) | ||
9 | { | ||
10 | size_t l = strlen( (char*)key ); | ||
11 | return strncmp( (char*)key, *(char**)line, l ); | ||
12 | } | ||
13 | |||
14 | int qsort_cmp( const void *a, const void *b ) | ||
15 | { | ||
16 | return strcmp( *(char**)a, *(char**)b ); | ||
17 | } | ||
18 | |||
19 | int main( int argc, char ** args ) | ||
20 | { | ||
21 | MAP coords = map_file( args[1], 1 ); | ||
22 | int i, l, lines; | ||
23 | char *p, **offsets, *input = malloc(1024); | ||
24 | ssize_t ll; | ||
25 | size_t input_length = 1024; | ||
26 | |||
27 | if( !coords ) exit( 111 ); | ||
28 | p = (char *)coords->addr; | ||
29 | for ( i=0, lines=0; i<coords->size; ++i ) | ||
30 | if( p[i] == 0x00 ) | ||
31 | ++lines; | ||
32 | |||
33 | offsets = malloc( lines * sizeof(char*)); | ||
34 | if( !offsets ) exit( 111 ); | ||
35 | |||
36 | offsets[0] = p; l = 1; | ||
37 | for ( i=0; i<coords->size; ++i ) | ||
38 | if( p[i] == 0x00 ) | ||
39 | offsets[l++] = p+i+1; | ||
40 | |||
41 | l--; qsort(offsets, l, sizeof(char*), qsort_cmp ); | ||
42 | |||
43 | while( ( ll = getline( &input, &input_length, stdin ) ) >= 0 ) | ||
44 | { | ||
45 | char **coord_line; | ||
46 | input[ll-1]='\t'; | ||
47 | coord_line = bsearch( input, offsets, l, sizeof(char*), find_offset ); | ||
48 | if( !coord_line && ll > 2 && isalpha( input[ll-2] ) ) | ||
49 | { | ||
50 | input[ll-2] = '\t'; input[ll-1]=0; | ||
51 | ll--; | ||
52 | coord_line = bsearch( input, offsets, l, sizeof(char*), find_offset ); | ||
53 | } | ||
54 | |||
55 | if( coord_line ) | ||
56 | printf( "%s\n", *coord_line + ll ); | ||
57 | else | ||
58 | puts( "\t" ); | ||
59 | } | ||
60 | |||
61 | return 0; | ||
62 | } | ||