summaryrefslogtreecommitdiff
path: root/src/export
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2019-01-30 18:12:18 +0100
committerDirk Engling <erdgeist@erdgeist.org>2019-01-30 18:12:18 +0100
commita187241f4e4cf8a592e0a3cc0b61f949e6184a9e (patch)
treeee6adb8733dd81698f4a50bf75aeadbd30f68464 /src/export
parent0150806fbf0cc64e60984f8a99aa45ca734e0735 (diff)
Add branch name mapper code for v3
Diffstat (limited to 'src/export')
-rw-r--r--src/export/map_branches_v3.c79
-rw-r--r--src/export/map_branches_v4.c (renamed from src/export/map_branches.c)0
2 files changed, 79 insertions, 0 deletions
diff --git a/src/export/map_branches_v3.c b/src/export/map_branches_v3.c
new file mode 100644
index 0000000..22d0036
--- /dev/null
+++ b/src/export/map_branches_v3.c
@@ -0,0 +1,79 @@
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
9typedef struct {
10 long code;
11 char *name;
12} branchen_code;
13
14enum { MAX_CODES = 128 * 1024 };
15branchen_code g_codes[MAX_CODES];
16long g_code_count;
17
18static int find_code( const void *key, const void *bc)
19{
20 return (long)key - ((branchen_code*)bc)->code;
21}
22
23static int qsort_cmp( const void *a, const void *b )
24{
25 return ((branchen_code*)a)->code - ((branchen_code*)b)->code;
26}
27
28int 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
46 if (input == end_p) break;
47 if (*end_p != ';') { fprintf( stderr, "Input error, line: %s\n", input); exit(1); }
48
49 r = strchr(end_p + 1, ';');
50 if (!r) { fprintf( stderr, "Input error, line: %s\n", input); exit(1); }
51 *r = 0;
52
53 asprintf(&g_codes[g_code_count].name, "%s", end_p + 1) ;
54 // printf( "%ld: %s\n", g_codes[g_code_count].code, g_codes[g_code_count].name);
55 g_code_count++;
56 }
57
58 qsort(g_codes, g_code_count, sizeof(branchen_code), qsort_cmp );
59
60 /* Now scan lines from 09_Verweise for semicolon separated branchen codes */
61 while ( (ll = getline( &input, &input_length, stdin ) ) >= 0 ) {
62 char *codes = input;
63 branchen_code *bc;
64 int multiple;
65 for (multiple = 0;; ++multiple) {
66 long code = strtoul(codes, &end_p, 10);
67 if (codes == end_p) break;
68 bc = (branchen_code*)bsearch((void *)(uintptr_t)code, g_codes, g_code_count, sizeof(branchen_code), find_code);
69 if (bc) {
70 if (multiple) putchar(';');
71 printf("%s", bc->name);
72 }
73 if (*end_p != ';') break;
74 codes = end_p + 1;
75 }
76 putchar(10);
77 }
78 return 0;
79}
diff --git a/src/export/map_branches.c b/src/export/map_branches_v4.c
index 160945d..160945d 100644
--- a/src/export/map_branches.c
+++ b/src/export/map_branches_v4.c