diff options
author | Dirk Engling <erdgeist@erdgeist.org> | 2019-01-30 18:12:18 +0100 |
---|---|---|
committer | Dirk Engling <erdgeist@erdgeist.org> | 2019-01-30 18:12:18 +0100 |
commit | a187241f4e4cf8a592e0a3cc0b61f949e6184a9e (patch) | |
tree | ee6adb8733dd81698f4a50bf75aeadbd30f68464 /src/export/map_branches.c | |
parent | 0150806fbf0cc64e60984f8a99aa45ca734e0735 (diff) |
Add branch name mapper code for v3
Diffstat (limited to 'src/export/map_branches.c')
-rw-r--r-- | src/export/map_branches.c | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/src/export/map_branches.c b/src/export/map_branches.c deleted file mode 100644 index 160945d..0000000 --- a/src/export/map_branches.c +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | #define _WITH_GETLINE | ||
2 | #define _GNU_SOURCE | ||
3 | #include <stdlib.h> | ||
4 | #include <stdint.h> | ||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | #include <ctype.h> | ||
8 | |||
9 | typedef struct { | ||
10 | long code; | ||
11 | char *name; | ||
12 | } branchen_code; | ||
13 | |||
14 | enum { MAX_CODES = 128 * 1024 }; | ||
15 | branchen_code g_codes[MAX_CODES]; | ||
16 | long g_code_count; | ||
17 | |||
18 | static int find_code( const void *key, const void *bc) | ||
19 | { | ||
20 | return (long)key - ((branchen_code*)bc)->code; | ||
21 | } | ||
22 | |||
23 | static int qsort_cmp( const void *a, const void *b ) | ||
24 | { | ||
25 | return ((branchen_code*)a)->code - ((branchen_code*)b)->code; | ||
26 | } | ||
27 | |||
28 | int main( int argc, char ** args ) | ||
29 | { | ||
30 | FILE * map_file; | ||
31 | char *end_p, *input = malloc(1024); | ||
32 | size_t input_length = 1024; | ||
33 | ssize_t ll; | ||
34 | |||
35 | if( argc != 2 ) { fprintf( stderr, "Syntax: %s <branchcodes> < <branches_files>\n", args[0] ); exit(111); } | ||
36 | |||
37 | map_file = fopen( args[1], "r" ); | ||
38 | if (!map_file || !input) { fprintf( stderr, "Error allocating resources\n" ); exit( 111 ); } | ||
39 | |||
40 | /* Fill array with maps */ | ||
41 | while ( (ll = getline( &input, &input_length, map_file ) ) >= 0 ) { | ||
42 | char * r = strchr(input, 10); | ||
43 | if (r) *r = 0; | ||
44 | g_codes[g_code_count].code = strtoul(input, &end_p, 10); | ||
45 | asprintf(&g_codes[g_code_count].name, "%s", end_p + 1) ; | ||
46 | // printf( "%ld: %s\n", g_codes[g_code_count].code, g_codes[g_code_count].name); | ||
47 | g_code_count++; | ||
48 | } | ||
49 | |||
50 | qsort(g_codes, g_code_count, sizeof(branchen_code), qsort_cmp ); | ||
51 | |||
52 | /* Now scan lines from 09_Verweise for semicolon separated branchen codes */ | ||
53 | while ( (ll = getline( &input, &input_length, stdin ) ) >= 0 ) { | ||
54 | char *codes = input; | ||
55 | branchen_code *bc; | ||
56 | int multiple; | ||
57 | for (multiple = 0;; ++multiple) { | ||
58 | long code = strtoul(codes, &end_p, 10); | ||
59 | if (codes == end_p) break; | ||
60 | bc = (branchen_code*)bsearch((void *)(uintptr_t)code, g_codes, g_code_count, sizeof(branchen_code), find_code); | ||
61 | if (bc) { | ||
62 | if (multiple) putchar(';'); | ||
63 | printf("%s", bc->name); | ||
64 | } | ||
65 | if (*end_p != ';') break; | ||
66 | codes = end_p + 1; | ||
67 | } | ||
68 | putchar(10); | ||
69 | } | ||
70 | return 0; | ||
71 | } | ||