summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2014-02-20 02:46:41 +0100
committerDirk Engling <erdgeist@erdgeist.org>2014-02-20 02:46:41 +0100
commit64c85dfc1d3b546dd4b5f84168e9256817f3a741 (patch)
treee3de2e7a99362bfa1dfcde3d4bad3e76af179c61 /src
parent632c350fcf2021620afd032994e6e32c34c6dbfb (diff)
clean up source directory
Diffstat (limited to 'src')
-rw-r--r--src/backen.c108
-rw-r--r--src/extractblocks.c69
-rw-r--r--src/extractstreets.c66
-rw-r--r--src/hexout.c13
-rw-r--r--src/postprocess/cleanindex.c (renamed from src/cleanindex.c)0
-rw-r--r--src/postprocess/cutfile.c (renamed from src/cutfile.c)0
-rw-r--r--src/postprocess/dumpindex2.c (renamed from src/dumpindex2.c)0
-rw-r--r--src/postprocess/dumppointers.c (renamed from src/dumppointers.c)0
-rw-r--r--src/postprocess/dumppointers2.c (renamed from src/dumppointers2.c)0
-rw-r--r--src/postprocess/joinfields.c (renamed from src/joinfields.c)0
-rw-r--r--src/postprocess/makepic.c (renamed from src/makepic.c)0
-rw-r--r--src/postprocess/sortindex.c (renamed from src/sortindex.c)0
-rw-r--r--src/postprocess/testmap.c (renamed from src/testmap.c)0
-rw-r--r--src/splitfiles.c126
14 files changed, 0 insertions, 382 deletions
diff --git a/src/backen.c b/src/backen.c
deleted file mode 100644
index b93c721..0000000
--- a/src/backen.c
+++ /dev/null
@@ -1,108 +0,0 @@
1#include <string.h>
2#include "mystdlib.h"
3
4int mystrcmp( void *a, void *b ) {
5 return strncmp( a, *(char**)b, strlen( a ));
6}
7
8int mystrcmp2( void *a, void *b ) {
9 return strcmp( *(char**)a, *(char**)b);
10}
11
12int 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 *geomahs[15000000];
16 char *streets[400000];
17 MAP maps[11]; int mapoffs[11];
18 MAP streetf = map_file( "lists/streetlist", 1);
19 MAP geomahf = map_file( "lists/geohnrlist", 1);
20 unsigned char lookup[1024], **geokord; /* PLZ, Streetname, Hnr */
21
22 streets[streetnum++] = streetf->addr;
23 for( i=0; i<streetf->size; ++i )
24 if( streetf->addr[i] == 0 ) streets[streetnum++] = streetf->addr+i+1;
25
26 geomahs[geomahnum++] = geomahf->addr;
27 for( i=0; i<geomahf->size; ++i )
28 if( geomahf->addr[i] == 0 ) geomahs[geomahnum++] = geomahf->addr+i+1;
29
30 qsort( geomahs, geomahnum, sizeof(char*), mystrcmp2 );
31
32 i = 0;
33 while( run ) {
34 for(j=0; j<11; ++j) {
35 sprintf( path, "files/file_%05X", i++);
36 maps[j] = map_file( path, 1 ); mapoffs[j] = 0;
37 }
38
39 if( !maps[0] ) goto out;
40
41 for(j=0;j<maps[0]->size;++j) {
42 char ch;
43
44 for( k=0; k<11; ++k) {
45 unsigned char *end;
46 int sid,x ;
47 switch(k) {
48 case 0:
49 printf( "%02X\t", maps[k]->addr[mapoffs[k]++]);
50 break;
51 case 5:
52 sid = strtol( maps[k]->addr+mapoffs[k], &end, 10);
53 if( end > maps[k]->addr+mapoffs[k] ) {
54 // no hnr, end+1 points to "" afterwards
55 if( !*end ) end--;
56
57 printf( "%s\t%s\t", streets[sid], end+1 );
58 end = lookup + 6 + sprintf( lookup+6, "%s\t%s", streets[sid], end + 1 );
59 while( isalpha( (int)end[-1] )) *--end = 0;
60 *end++ = '\t'; *end = 0;
61 } else {
62 printf( "\t\t" ); lookup[6] = lookup[7] = '\t'; lookup[8] = 0;
63 }
64 while( maps[k]->addr[mapoffs[k]++]);
65 break;
66 case 10:
67 if( !maps[k]->addr[mapoffs[k]] )
68 printf( "\t\t" );
69 else if( !strchr(maps[k]->addr+mapoffs[k], 9))
70 printf( "%s\t\t", maps[k]->addr+mapoffs[k] );
71 else
72 printf( "%s\t", maps[k]->addr+mapoffs[k] );
73 while( maps[k]->addr[mapoffs[k]++]);
74 break;
75 case 7:
76 for( x=0; (x<5) && (maps[k]->addr+mapoffs[k])[x]; ++x )
77 lookup[x] = (maps[k]->addr+mapoffs[k])[x];
78 for( ; x<5; ++x )
79 lookup[x] = '.';
80 lookup[x] = '\t';
81 default:
82 while( maps[k]->addr[mapoffs[k]] == '\t' ) 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' );
89 break;
90 }
91 }
92 /* postprocessing */
93
94 if( (geokord = (char**)bsearch( lookup, geomahs, geomahnum, sizeof(char *), mystrcmp ) ) ) {
95 printf( "%s", *geokord+strlen(lookup)+1 );
96 } else {
97 putchar('\t'); putchar('\t');
98 }
99 putchar( 10 );
100 }
101 for(j=0; j<11; ++j) unmap_file( &maps[j] );
102 }
103
104out:
105 unmap_file( &streetf );
106 unmap_file( &geomahf );
107 return 0;
108}
diff --git a/src/extractblocks.c b/src/extractblocks.c
deleted file mode 100644
index 51505ef..0000000
--- a/src/extractblocks.c
+++ /dev/null
@@ -1,69 +0,0 @@
1#include <sys/types.h>
2#include <sys/stat.h>
3#include <sys/mman.h>
4#include <strings.h>
5#include <stdio.h>
6#include <fcntl.h>
7
8int main( int args, char **argv )
9{
10 int toindex;
11 int i, run = 1, filenum = 0, offset = 0, oldoffset = -1;
12 struct stat fstatus;
13 unsigned char *mappedfile;
14
15 if( args != 2 )
16 { fputs( "Missing filenames.", stderr ); exit( 1 ); }
17
18 if( ( toindex = open( argv[1], O_RDONLY ) ) < 0 )
19 { fprintf( stderr, "Can't open file: %s.\n", argv[1] ); exit( toindex ); }
20
21 fstat( toindex, &fstatus );
22
23 printf( "Size of file: %d\n", fstatus.st_size );
24
25 if( ( mappedfile = mmap( NULL, (size_t)fstatus.st_size, PROT_READ | PROT_WRITE, MAP_NOCORE | MAP_PRIVATE, toindex, 0) ) == MAP_FAILED )
26 { fprintf( stderr, "Can't mmap file: %s.", argv[1] ); exit( 1 ); }
27
28 while( run )
29 {
30 while( ( offset < fstatus.st_size ) && (
31 ( mappedfile[ offset + 0 ] != 0xd9 ) ||
32 ( mappedfile[ offset + 2 ] != 0x6f ) ||
33 ( mappedfile[ offset + 3 ] != 0x6d ) ||
34 ( mappedfile[ offset + 4 ] != 0xaa ) ||
35 ( mappedfile[ offset + 5 ] != 0x11 ) ||
36 ( mappedfile[ offset + 6 ] != 0x6f )
37 ) ) offset++;
38
39 printf( "Found an appropriate offset at: %d\n", oldoffset );
40
41 if( offset == fstatus.st_size )
42 run = 0;
43
44 if( oldoffset != -1 )
45 {
46 unsigned long *mf = (unsigned long*)(mappedfile + oldoffset);
47 unsigned char filename[20], cs = 0;
48
49 for( i=0; i<8; ++i)
50 mf[i]^=0x014224c2;
51
52 snprintf( filename, sizeof( filename ), "%05d.lha", filenum++ );
53
54 memcpy( ((unsigned char*)mf) + 22, filename, 5);
55
56 for( i=2; i<29; ++i)
57 cs += ((unsigned char*)mf)[i];
58 ((unsigned char*)mf)[1] = cs;
59
60 i = open( filename, O_CREAT | O_TRUNC | O_WRONLY, 0644 );
61 write( i, mf, offset - oldoffset );
62 close( i );
63 }
64 oldoffset = offset;
65 offset++;
66 }
67
68 return 0;
69}
diff --git a/src/extractstreets.c b/src/extractstreets.c
deleted file mode 100644
index 097a736..0000000
--- a/src/extractstreets.c
+++ /dev/null
@@ -1,66 +0,0 @@
1#include <sys/types.h>
2#include <sys/stat.h>
3#include <sys/mman.h>
4#include <strings.h>
5#include <stdio.h>
6#include <fcntl.h>
7
8int main( int args, char **argv )
9{
10 int toindex;
11 int i, run = 1, filenum = 0, offset = 0, oldoffset = -1;
12 struct stat fstatus;
13 unsigned char *mappedfile;
14
15 if( args != 2 )
16 { fputs( "Missing filenames.", stderr ); exit( 1 ); }
17
18 if( ( toindex = open( argv[1], O_RDONLY ) ) < 0 )
19 { fprintf( stderr, "Can't open file: %s.\n", argv[1] ); exit( toindex ); }
20
21 fstat( toindex, &fstatus );
22
23 printf( "Size of file: %d\n", fstatus.st_size );
24
25 if( ( mappedfile = mmap( NULL, (size_t)fstatus.st_size, PROT_READ | PROT_WRITE, MAP_NOCORE | MAP_PRIVATE, toindex, 0) ) == MAP_FAILED )
26 { fprintf( stderr, "Can't mmap file: %s.", argv[1] ); exit( 1 ); }
27
28 while( run )
29 {
30 while( ( offset < fstatus.st_size ) && (
31 ( mappedfile[ offset + 0 ] != 0x22 ) ||
32 ( mappedfile[ offset + 2 ] != 0x2d ) ||
33 ( mappedfile[ offset + 3 ] != 0x6c ) ||
34 ( mappedfile[ offset + 4 ] != 0x68 ) ||
35 ( ( mappedfile[ offset + 5 ] != 0x35 ) && ( mappedfile[ offset + 5 ] != 0x30 )) ||
36 ( mappedfile[ offset + 6 ] != 0x2d )
37 ) ) offset++;
38
39 printf( "Found an appropriate offset at: %d\n", oldoffset );
40
41 if( offset == fstatus.st_size )
42 run = 0;
43
44 if( oldoffset != -1 )
45 {
46 unsigned long *mf = (unsigned long*)(mappedfile + oldoffset);
47 unsigned char filename[20], cs = 0;
48
49 snprintf( filename, sizeof( filename ), "%012d.lha", filenum++ );
50
51 memcpy( ((unsigned char*)mf) + 22, filename, 12);
52
53 for( i=2; i<36; ++i)
54 cs += ((unsigned char*)mf)[i];
55 ((unsigned char*)mf)[1] = cs;
56
57 i = open( filename, O_CREAT | O_TRUNC | O_WRONLY, 0644 );
58 write( i, mf, offset - oldoffset );
59 close( i );
60 }
61 oldoffset = offset;
62 offset++;
63 }
64
65 return 0;
66}
diff --git a/src/hexout.c b/src/hexout.c
deleted file mode 100644
index 1af6805..0000000
--- a/src/hexout.c
+++ /dev/null
@@ -1,13 +0,0 @@
1#include <stdio.h>
2
3int main() {
4 char tbl[] = "0123456789ABCDEF";
5 int in;
6
7 while( ( in = getchar() ) != EOF ) {
8 putchar( tbl[in>>4]);
9 putchar( tbl[in&15]);
10 putchar( '\n' );
11 }
12 return 0;
13}
diff --git a/src/cleanindex.c b/src/postprocess/cleanindex.c
index fb15bed..fb15bed 100644
--- a/src/cleanindex.c
+++ b/src/postprocess/cleanindex.c
diff --git a/src/cutfile.c b/src/postprocess/cutfile.c
index a2c87dc..a2c87dc 100644
--- a/src/cutfile.c
+++ b/src/postprocess/cutfile.c
diff --git a/src/dumpindex2.c b/src/postprocess/dumpindex2.c
index f49a329..f49a329 100644
--- a/src/dumpindex2.c
+++ b/src/postprocess/dumpindex2.c
diff --git a/src/dumppointers.c b/src/postprocess/dumppointers.c
index c677d71..c677d71 100644
--- a/src/dumppointers.c
+++ b/src/postprocess/dumppointers.c
diff --git a/src/dumppointers2.c b/src/postprocess/dumppointers2.c
index 80a4b61..80a4b61 100644
--- a/src/dumppointers2.c
+++ b/src/postprocess/dumppointers2.c
diff --git a/src/joinfields.c b/src/postprocess/joinfields.c
index 2415842..2415842 100644
--- a/src/joinfields.c
+++ b/src/postprocess/joinfields.c
diff --git a/src/makepic.c b/src/postprocess/makepic.c
index 5c54cbd..5c54cbd 100644
--- a/src/makepic.c
+++ b/src/postprocess/makepic.c
diff --git a/src/sortindex.c b/src/postprocess/sortindex.c
index b3b3bfe..b3b3bfe 100644
--- a/src/sortindex.c
+++ b/src/postprocess/sortindex.c
diff --git a/src/testmap.c b/src/postprocess/testmap.c
index d57ac80..d57ac80 100644
--- a/src/testmap.c
+++ b/src/postprocess/testmap.c
diff --git a/src/splitfiles.c b/src/splitfiles.c
deleted file mode 100644
index d49971b..0000000
--- a/src/splitfiles.c
+++ /dev/null
@@ -1,126 +0,0 @@
1#include "mystdlib.h"
2
3#define NUMFIELDS 12
4#define PREFIX "teiln/"
5
6#define STREETFIELD 3
7#define HOUSENUMFIELD 4
8#define ZIPCODEFIELD 6
9#define TOWNFIELD 7
10
11char **generate_index( MAP toindex )
12{
13 off_t fileidx = 0, idxidx = 0;
14 char **index;
15
16 while( fileidx < toindex->size )
17 if( !toindex->addr[ fileidx++ ] ) idxidx++;
18 index = (char**)malloc( sizeof( char *) * idxidx );
19
20 fileidx = idxidx = 0;
21 if( index )
22 {
23 while( fileidx < toindex->size )
24 {
25 index[ idxidx++ ] = toindex->addr + fileidx;
26 while( (fileidx < toindex->size) && (toindex->addr[ fileidx++]));
27 }
28 }
29 return index;
30}
31
32static int g_coordidxsize;
33
34int coordcmp( const void *s1, const void *s2 )
35{
36 return strncmp( s1, s2, g_coordidxsize );
37}
38
39int main( )
40{
41 int i = 0, j, k, leave = 0;
42 off_t in1, in2, in3;
43 char fname[32], **streetnames = NULL;
44 MAP streets = NULL, vnames, nnames, tables, coords = NULL;
45
46 if( !(coords = map_file( "coords/list", true ))) goto cleanup_main;
47 if( !(streets = map_file( "streets/list",true ))) goto cleanup_main;
48 if( !(streetnames = generate_index( streets ))) goto cleanup_main;
49
50 for( i=0; !leave; i+=3 )
51 {
52 int fof[ NUMFIELDS ];
53 char coordidx[160], *coordline;
54 vnames = nnames = tables = NULL;
55
56 snprintf( fname, sizeof( fname ), PREFIX "%05d", i );
57 if( !( tables = map_file( fname, true ) ) ) goto cleanup_loop;
58 snprintf( fname, sizeof( fname ), PREFIX "%05d", i+1 );
59 if( !( nnames = map_file( fname, true ) ) ) goto cleanup_loop;
60 snprintf( fname, sizeof( fname ), PREFIX "%05d", i+2 );
61 if( !( vnames = map_file( fname, true ) ) ) goto cleanup_loop;
62
63 in1 = 0x34; in2 = 0x34; in3 = 0;
64
65 for( j = 0; j < NUMFIELDS; ++j)
66 {
67 fof[ j ] = in1;
68 for( k = 0; k < 3000; ++k )
69 while( tables->addr[ in1++ ]);
70 }
71
72 for( j = 0; j < 3000; ++j )
73 {
74 char *stringend;
75 int v = strtoul( tables->addr + fof[ STREETFIELD ], &stringend, 16 );
76 char *currentstreet = ( stringend == (char*)(tables->addr + fof[ STREETFIELD ])) ? "" : streetnames[ v ];
77 int xco= 0, yco= 0;
78
79 printf( "%s\t%s", nnames->addr+in2, vnames->addr+in3 );
80 while( nnames->addr[ in2++ ] );
81 while( vnames->addr[ in3++ ] );
82
83 g_coordidxsize = snprintf( coordidx, sizeof( coordidx ), "%s;%s;%s;%s;",
84 tables->addr + fof [ ZIPCODEFIELD ],
85 tables->addr + fof [ TOWNFIELD ],
86 currentstreet,
87 tables->addr + fof [ HOUSENUMFIELD ] );
88
89 if( !(coordline = (char*)bsearch( coordidx, coords->addr, coords->size / 90, 90, coordcmp ))) coordline = ";;;;;;";
90 v = 5; while( v--) { while( *coordline && *coordline++ != ';'); }
91 sscanf( coordline, "%d;%d", &xco, &yco );
92
93 for( k = 0; k < NUMFIELDS; ++k )
94 {
95 if( k == STREETFIELD )
96 {
97 printf( "\t%s", currentstreet);
98 }
99 else
100 printf( "\t%s", tables->addr + fof[ k ] );
101 {
102 }
103 while( tables->addr [ fof[ k ]++] );
104 }
105
106 printf( "\t%d\t%d", xco, yco );
107 putchar( 10 );
108 }
109
110 leave ^= 1;
111
112 cleanup_loop:
113 leave ^= 1;
114
115 unmap_file( &vnames );
116 unmap_file( &nnames );
117 unmap_file( &tables );
118 }
119
120 cleanup_main:
121 if( streetnames ) free( streetnames );
122 unmap_file( &streets );
123 unmap_file( &coords );
124
125 return 0;
126}