diff options
Diffstat (limited to 'src/backen.c')
-rw-r--r-- | src/backen.c | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/backen.c b/src/backen.c index 434f3d5..b93c721 100644 --- a/src/backen.c +++ b/src/backen.c | |||
@@ -12,12 +12,10 @@ int mystrcmp2( void *a, void *b ) { | |||
12 | int main( int argc, char **argv ) { | 12 | int main( int argc, char **argv ) { |
13 | char path[32]; /* files/file_XXXXX */ | 13 | char path[32]; /* files/file_XXXXX */ |
14 | int streetnum = 0, geomapnum = 0, geomahnum = 0, d = 0, i, j, k, run = 1; | 14 | int streetnum = 0, geomapnum = 0, geomahnum = 0, d = 0, i, j, k, run = 1; |
15 | char *geomaps[1000000]; | 15 | char *geomahs[15000000]; |
16 | char *geomahs[14000000]; | ||
17 | char *streets[400000]; | 16 | char *streets[400000]; |
18 | MAP maps[11]; int mapoffs[11]; | 17 | MAP maps[11]; int mapoffs[11]; |
19 | MAP streetf = map_file( "lists/streetlist", 1); | 18 | MAP streetf = map_file( "lists/streetlist", 1); |
20 | MAP geomapf = map_file( "lists/geolist", 1); | ||
21 | MAP geomahf = map_file( "lists/geohnrlist", 1); | 19 | MAP geomahf = map_file( "lists/geohnrlist", 1); |
22 | unsigned char lookup[1024], **geokord; /* PLZ, Streetname, Hnr */ | 20 | unsigned char lookup[1024], **geokord; /* PLZ, Streetname, Hnr */ |
23 | 21 | ||
@@ -25,15 +23,10 @@ int main( int argc, char **argv ) { | |||
25 | for( i=0; i<streetf->size; ++i ) | 23 | for( i=0; i<streetf->size; ++i ) |
26 | if( streetf->addr[i] == 0 ) streets[streetnum++] = streetf->addr+i+1; | 24 | if( streetf->addr[i] == 0 ) streets[streetnum++] = streetf->addr+i+1; |
27 | 25 | ||
28 | geomaps[geomapnum++] = geomapf->addr; | ||
29 | for( i=0; i<geomapf->size; ++i ) | ||
30 | if( geomapf->addr[i] == 0 ) geomaps[geomapnum++] = geomapf->addr+i+1; | ||
31 | |||
32 | geomahs[geomahnum++] = geomahf->addr; | 26 | geomahs[geomahnum++] = geomahf->addr; |
33 | for( i=0; i<geomahf->size; ++i ) | 27 | for( i=0; i<geomahf->size; ++i ) |
34 | if( geomahf->addr[i] == 0 ) geomahs[geomahnum++] = geomahf->addr+i+1; | 28 | if( geomahf->addr[i] == 0 ) geomahs[geomahnum++] = geomahf->addr+i+1; |
35 | 29 | ||
36 | qsort( geomaps, geomapnum, sizeof(char*), mystrcmp2 ); | ||
37 | qsort( geomahs, geomahnum, sizeof(char*), mystrcmp2 ); | 30 | qsort( geomahs, geomahnum, sizeof(char*), mystrcmp2 ); |
38 | 31 | ||
39 | i = 0; | 32 | i = 0; |
@@ -42,10 +35,15 @@ int main( int argc, char **argv ) { | |||
42 | sprintf( path, "files/file_%05X", i++); | 35 | sprintf( path, "files/file_%05X", i++); |
43 | maps[j] = map_file( path, 1 ); mapoffs[j] = 0; | 36 | maps[j] = map_file( path, 1 ); mapoffs[j] = 0; |
44 | } | 37 | } |
38 | |||
39 | if( !maps[0] ) goto out; | ||
40 | |||
45 | for(j=0;j<maps[0]->size;++j) { | 41 | for(j=0;j<maps[0]->size;++j) { |
42 | char ch; | ||
43 | |||
46 | for( k=0; k<11; ++k) { | 44 | for( k=0; k<11; ++k) { |
47 | unsigned char *end; | 45 | unsigned char *end; |
48 | int sid; | 46 | int sid,x ; |
49 | switch(k) { | 47 | switch(k) { |
50 | case 0: | 48 | case 0: |
51 | printf( "%02X\t", maps[k]->addr[mapoffs[k]++]); | 49 | printf( "%02X\t", maps[k]->addr[mapoffs[k]++]); |
@@ -53,6 +51,9 @@ int main( int argc, char **argv ) { | |||
53 | case 5: | 51 | case 5: |
54 | sid = strtol( maps[k]->addr+mapoffs[k], &end, 10); | 52 | sid = strtol( maps[k]->addr+mapoffs[k], &end, 10); |
55 | if( end > maps[k]->addr+mapoffs[k] ) { | 53 | if( end > maps[k]->addr+mapoffs[k] ) { |
54 | // no hnr, end+1 points to "" afterwards | ||
55 | if( !*end ) end--; | ||
56 | |||
56 | printf( "%s\t%s\t", streets[sid], end+1 ); | 57 | printf( "%s\t%s\t", streets[sid], end+1 ); |
57 | end = lookup + 6 + sprintf( lookup+6, "%s\t%s", streets[sid], end + 1 ); | 58 | end = lookup + 6 + sprintf( lookup+6, "%s\t%s", streets[sid], end + 1 ); |
58 | while( isalpha( (int)end[-1] )) *--end = 0; | 59 | while( isalpha( (int)end[-1] )) *--end = 0; |
@@ -66,26 +67,31 @@ int main( int argc, char **argv ) { | |||
66 | if( !maps[k]->addr[mapoffs[k]] ) | 67 | if( !maps[k]->addr[mapoffs[k]] ) |
67 | printf( "\t\t" ); | 68 | printf( "\t\t" ); |
68 | else if( !strchr(maps[k]->addr+mapoffs[k], 9)) | 69 | else if( !strchr(maps[k]->addr+mapoffs[k], 9)) |
69 | printf("%s\t\t", maps[k]->addr+mapoffs[k] ); | 70 | printf( "%s\t\t", maps[k]->addr+mapoffs[k] ); |
70 | else | 71 | else |
71 | printf("%s\t", maps[k]->addr+mapoffs[k] ); | 72 | printf( "%s\t", maps[k]->addr+mapoffs[k] ); |
72 | while( maps[k]->addr[mapoffs[k]++]); | 73 | while( maps[k]->addr[mapoffs[k]++]); |
73 | break; | 74 | break; |
74 | case 7: | 75 | case 7: |
75 | memcpy( lookup, ".....\t", 6 ); | 76 | for( x=0; (x<5) && (maps[k]->addr+mapoffs[k])[x]; ++x ) |
76 | snprintf( lookup, 5, "%s", maps[k]->addr+mapoffs[k] ); | 77 | lookup[x] = (maps[k]->addr+mapoffs[k])[x]; |
77 | lookup[5] = '\t'; | 78 | for( ; x<5; ++x ) |
79 | lookup[x] = '.'; | ||
80 | lookup[x] = '\t'; | ||
78 | default: | 81 | default: |
79 | printf( "%s\t", maps[k]->addr+mapoffs[k] ); | 82 | while( maps[k]->addr[mapoffs[k]] == '\t' ) mapoffs[k]++; |
80 | while( maps[k]->addr[mapoffs[k]++]); | 83 | while( (ch = maps[k]->addr[mapoffs[k]++] )) |
84 | if( ch < 32 ) | ||
85 | putchar( 32 ); | ||
86 | else | ||
87 | putchar( ch ); | ||
88 | putchar( '\t' ); | ||
81 | break; | 89 | break; |
82 | } | 90 | } |
83 | } | 91 | } |
84 | /* postprocessing */ | 92 | /* postprocessing */ |
85 | // printf( "\nLOOKUP: %s\n", lookup ); | ||
86 | 93 | ||
87 | if( (geokord = (char**)bsearch( lookup, geomahs, geomahnum, sizeof(char *), mystrcmp ) ) ) { | 94 | if( (geokord = (char**)bsearch( lookup, geomahs, geomahnum, sizeof(char *), mystrcmp ) ) ) { |
88 | // printf( "\nGEOKOORD: %s\n", *geokord ); | ||
89 | printf( "%s", *geokord+strlen(lookup)+1 ); | 95 | printf( "%s", *geokord+strlen(lookup)+1 ); |
90 | } else { | 96 | } else { |
91 | putchar('\t'); putchar('\t'); | 97 | putchar('\t'); putchar('\t'); |
@@ -94,8 +100,9 @@ int main( int argc, char **argv ) { | |||
94 | } | 100 | } |
95 | for(j=0; j<11; ++j) unmap_file( &maps[j] ); | 101 | for(j=0; j<11; ++j) unmap_file( &maps[j] ); |
96 | } | 102 | } |
103 | |||
104 | out: | ||
97 | unmap_file( &streetf ); | 105 | unmap_file( &streetf ); |
98 | unmap_file( &geomapf ); | ||
99 | unmap_file( &geomahf ); | 106 | unmap_file( &geomahf ); |
100 | return 0; | 107 | return 0; |
101 | } | 108 | } |