diff options
author | erdgeist <> | 2005-01-18 05:07:17 +0000 |
---|---|---|
committer | erdgeist <> | 2005-01-18 05:07:17 +0000 |
commit | b1d066634b4ad459a58ea8cdf05aee42680ba2b2 (patch) | |
tree | fa33fbeebb97ab61feabfd962826225d11e55918 | |
parent | 73827ba1f4a50107272d6e465b92f356fb9e0abe (diff) |
herbst 2004
-rw-r--r-- | src/backen.c | 101 | ||||
-rw-r--r-- | src/decompress.c | 52 |
2 files changed, 153 insertions, 0 deletions
diff --git a/src/backen.c b/src/backen.c new file mode 100644 index 0000000..d97f743 --- /dev/null +++ b/src/backen.c | |||
@@ -0,0 +1,101 @@ | |||
1 | #include <string.h> | ||
2 | #include "mystdlib.h" | ||
3 | |||
4 | int mystrcmp( void *a, void *b ) { | ||
5 | return strncmp( a, *(char**)b, strlen( a )); | ||
6 | } | ||
7 | |||
8 | int mystrcmp2( void *a, void *b ) { | ||
9 | return strcmp( *(char**)a, *(char**)b); | ||
10 | } | ||
11 | |||
12 | int main( int argc, char **argv ) { | ||
13 | char path[32]; /* files/file_XXXXX */ | ||
14 | int streetnum = 0, geomapnum = 0, geomahnum = 0, d = 0, i, j, k, run = 1; | ||
15 | char *geomaps[1000000]; | ||
16 | char *geomahs[14000000]; | ||
17 | char *streets[400000]; | ||
18 | MAP maps[11]; int mapoffs[11]; | ||
19 | MAP streetf = map_file( "lists/streetlist", 1); | ||
20 | MAP geomapf = map_file( "lists/geolist", 1); | ||
21 | MAP geomahf = map_file( "lists/geohnrlist", 1); | ||
22 | unsigned char lookup[1024], **geokord; /* PLZ, Streetname, Hnr */ | ||
23 | |||
24 | streets[streetnum++] = streetf->addr; | ||
25 | for( i=0; i<streetf->size; ++i ) | ||
26 | if( streetf->addr[i] == 0 ) streets[streetnum++] = streetf->addr+i+1; | ||
27 | |||
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; | ||
33 | for( i=0; i<geomahf->size; ++i ) | ||
34 | if( geomahf->addr[i] == 0 ) geomahs[geomahnum++] = geomahf->addr+i+1; | ||
35 | |||
36 | qsort( geomaps, geomapnum, sizeof(char*), mystrcmp2 ); | ||
37 | qsort( geomahs, geomahnum, sizeof(char*), mystrcmp2 ); | ||
38 | |||
39 | i = 0; | ||
40 | while( run ) { | ||
41 | for(j=0; j<11; ++j) { | ||
42 | sprintf( path, "files/file_%05X", i++); | ||
43 | maps[j] = map_file( path, 1 ); mapoffs[j] = 0; | ||
44 | } | ||
45 | for(j=0;j<maps[0]->size;++j) { | ||
46 | for( k=0; k<11; ++k) { | ||
47 | unsigned char *end; | ||
48 | int sid; | ||
49 | switch(k) { | ||
50 | case 0: | ||
51 | printf( "%02X\t", maps[k]->addr[mapoffs[k]++]); | ||
52 | break; | ||
53 | case 5: | ||
54 | sid = strtol( maps[k]->addr+mapoffs[k], &end, 10); | ||
55 | if( end > maps[k]->addr+mapoffs[k] ) { | ||
56 | printf( "%s\t%s\t", streets[sid], end+1 ); | ||
57 | end = lookup + 6 + sprintf( lookup+6, "%s\t%s", streets[sid], end + 1 ); | ||
58 | while( isalpha( (int)end[-1] )) *--end = 0; | ||
59 | *++end = '\t'; *++end = 0; | ||
60 | } else { | ||
61 | printf( "\t\t" ); lookup[6] = lookup[7] = '\t'; lookup[8] = 0; | ||
62 | } | ||
63 | while( maps[k]->addr[mapoffs[k]++]); | ||
64 | break; | ||
65 | case 10: | ||
66 | if( !maps[k]->addr[mapoffs[k]] ) | ||
67 | printf( "\t\t" ); | ||
68 | else if( !strchr(maps[k]->addr+mapoffs[k], 9)) | ||
69 | printf("%s\t\t", maps[k]->addr+mapoffs[k] ); | ||
70 | else | ||
71 | printf("%s\t", maps[k]->addr+mapoffs[k] ); | ||
72 | while( maps[k]->addr[mapoffs[k]++]); | ||
73 | break; | ||
74 | case 7: | ||
75 | memcpy( lookup, ".....\t", 6 ); | ||
76 | sprintf( lookup, "%s", maps[k]->addr+mapoffs[k] ); | ||
77 | lookup[5] = '\t'; | ||
78 | default: | ||
79 | printf( "%s\t", maps[k]->addr+mapoffs[k] ); | ||
80 | while( maps[k]->addr[mapoffs[k]++]); | ||
81 | break; | ||
82 | } | ||
83 | } | ||
84 | /* postprocessing */ | ||
85 | // printf( "\nLOOKUP: %s\n", lookup ); | ||
86 | |||
87 | if( (geokord = (char**)bsearch( lookup, geomahs, geomahnum, sizeof(char *), mystrcmp ) ) ) { | ||
88 | // printf( "\nGEOKOORD: %s\n", *geokord ); | ||
89 | printf( "%s", *geokord+strlen(lookup)+1 ); | ||
90 | } else { | ||
91 | putchar('\t'); putchar('\t'); | ||
92 | } | ||
93 | putchar( 10 ); | ||
94 | } | ||
95 | for(j=0; j<11; ++j) unmap_file( &maps[j] ); | ||
96 | } | ||
97 | unmap_file( &streetf ); | ||
98 | unmap_file( &geomapf ); | ||
99 | unmap_file( &geomahf ); | ||
100 | return 0; | ||
101 | } | ||
diff --git a/src/decompress.c b/src/decompress.c new file mode 100644 index 0000000..dea2bca --- /dev/null +++ b/src/decompress.c | |||
@@ -0,0 +1,52 @@ | |||
1 | #include <zlib.h> | ||
2 | #include <stdio.h> | ||
3 | #include <unistd.h> | ||
4 | #include <fcntl.h> | ||
5 | |||
6 | #define XORLEN (29) | ||
7 | #define HUGEBLOCK (1024*1024) | ||
8 | |||
9 | int main(int argc, char **argv) { | ||
10 | // int infile = open("/Volumes/DasTelefonbuch/atb/phonebook.db", O_RDONLY); | ||
11 | |||
12 | int infile = open( argv[1], O_RDONLY); | ||
13 | printf( "%i\n", infile ); | ||
14 | |||
15 | unsigned const char xorkey [XORLEN] = "Just for Fun. Linus Torvalds."; | ||
16 | unsigned char input [HUGEBLOCK]; | ||
17 | unsigned char output [HUGEBLOCK]; | ||
18 | unsigned char respath[32]; /* file_XXXXX\0 */ | ||
19 | int i, offs = 0, zres = 0, filenum = 0, resfile, avail=1; | ||
20 | z_stream z; memset( &z, 0, sizeof(z)); | ||
21 | |||
22 | while( avail ) { | ||
23 | do { | ||
24 | lseek( infile, offs, SEEK_SET ); | ||
25 | avail = read( infile, input, HUGEBLOCK ); | ||
26 | if( !avail) break; | ||
27 | for( i=0; i<XORLEN; ++i ) input[i] ^= xorkey[i]; | ||
28 | |||
29 | z.next_in = input; z.avail_in = avail; | ||
30 | z.next_out = output; z.avail_out = HUGEBLOCK; | ||
31 | inflateInit( &z ); zres = inflate( &z, Z_NO_FLUSH ); | ||
32 | |||
33 | if( (zres != Z_OK) && (zres != Z_STREAM_END) ) { | ||
34 | inflateEnd(&z); memset( &z, 0, sizeof(z)); | ||
35 | offs++; | ||
36 | } | ||
37 | } while((zres != Z_OK) && (zres != Z_STREAM_END)); | ||
38 | |||
39 | if( !avail ) break; | ||
40 | if( zres == Z_OK) while( inflate( &z, Z_NO_FLUSH ) == Z_OK ); | ||
41 | |||
42 | sprintf( respath, "file_%05X", filenum++ ); | ||
43 | resfile = open( respath, O_RDWR | O_CREAT, 0644 ); | ||
44 | /* I know, I know, error checking */ | ||
45 | write( resfile, output, z.total_out ); | ||
46 | close( resfile ); | ||
47 | offs += z.total_in; | ||
48 | |||
49 | inflateEnd(&z); memset( &z, 0, sizeof(z)); | ||
50 | } | ||
51 | close( infile ); | ||
52 | } | ||