summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/export/extract_version_1.c20
-rw-r--r--src/export/extract_version_2.c65
-rw-r--r--src/export/extract_version_3.c7
-rw-r--r--src/export/map_coords.c4
-rw-r--r--src/export/mystdlib.c4
-rw-r--r--src/export/mystdlib.h5
-rw-r--r--src/export/split_version_2.c16
7 files changed, 60 insertions, 61 deletions
diff --git a/src/export/extract_version_1.c b/src/export/extract_version_1.c
index 987c38f..bbe900a 100644
--- a/src/export/extract_version_1.c
+++ b/src/export/extract_version_1.c
@@ -7,7 +7,7 @@
7 7
8#include "mystdlib.h" 8#include "mystdlib.h"
9 9
10static char xlat_table[] = { 10static uint8_t xlat_table[] = {
11 0x00, 0x09, 0x02, 0x03, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 11 0x00, 0x09, 0x02, 0x03, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
12 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 12 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
13 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 13 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
@@ -18,7 +18,7 @@ static char xlat_table[] = {
18 0xfb, 0xf9, 0xff, 0xd6, 0xdc, 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xdf, 0x5b, 0x5c, 0x5d, 0x60 18 0xfb, 0xf9, 0xff, 0xd6, 0xdc, 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xdf, 0x5b, 0x5c, 0x5d, 0x60
19}; 19};
20 20
21static char cp437_to_iso8859_1_table[] = { 21static uint8_t cp437_to_iso8859_1_table[] = {
22 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 22 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
23 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 23 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
24 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 24 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
@@ -42,7 +42,7 @@ static struct {
42 char * zip; 42 char * zip;
43} g_state; 43} g_state;
44 44
45void decode_7bit_string( uint8_t const *source, uint8_t *dest ) 45static void decode_7bit_string( uint8_t const *source, uint8_t *dest )
46{ 46{
47 uint16_t acc = 0, acc_bits = 0; 47 uint16_t acc = 0, acc_bits = 0;
48 while( 1 ) 48 while( 1 )
@@ -55,7 +55,7 @@ again:
55 } 55 }
56} 56}
57 57
58void split_to_files( uint8_t *entries, int num_entries ) 58static void split_to_files( uint8_t *entries, int num_entries )
59{ 59{
60 int entry = 0, column; 60 int entry = 0, column;
61 char *e = (char*)entries; 61 char *e = (char*)entries;
@@ -74,7 +74,7 @@ void split_to_files( uint8_t *entries, int num_entries )
74 if( end ) { 74 if( end ) {
75 *end = '\n'; 75 *end = '\n';
76 if( column == 9 && *e >= '0' && *e <= '9' ) write( g_state.outfiles[column+1], "0", 1 ); /* Augment Vorwahl */ 76 if( column == 9 && *e >= '0' && *e <= '9' ) write( g_state.outfiles[column+1], "0", 1 ); /* Augment Vorwahl */
77 write( g_state.outfiles[column+1], e, end - e + 1); 77 write( g_state.outfiles[column+1], e, (size_t)(end - e + 1) );
78 e = end + 1; 78 e = end + 1;
79 } else 79 } else
80 dprintf( g_state.outfiles[column+1], "%s\n", e); 80 dprintf( g_state.outfiles[column+1], "%s\n", e);
@@ -82,7 +82,7 @@ void split_to_files( uint8_t *entries, int num_entries )
82 } 82 }
83} 83}
84 84
85void act_on_record( uint8_t *file, int flag, uint8_t *page, uint16_t record_off ) 85static void act_on_record( uint8_t *file, int flag, uint8_t *page, uint16_t record_off )
86{ 86{
87 uint8_t outbuf[8192], *out_dest = outbuf, *record; 87 uint8_t outbuf[8192], *out_dest = outbuf, *record;
88 int num_entries; 88 int num_entries;
@@ -116,7 +116,7 @@ void act_on_record( uint8_t *file, int flag, uint8_t *page, uint16_t record_off
116} 116}
117 117
118/* Page is always 0x2000 */ 118/* Page is always 0x2000 */
119void act_on_page( uint8_t *file, uint8_t *page, int page_nr ) 119static void act_on_page( uint8_t *file, uint8_t *page, int page_nr )
120{ 120{
121 int record, flag = page[0]; 121 int record, flag = page[0];
122 int blob_len = *(uint16_t*)(page + 0x2); 122 int blob_len = *(uint16_t*)(page + 0x2);
@@ -131,17 +131,17 @@ void act_on_page( uint8_t *file, uint8_t *page, int page_nr )
131 act_on_record( file, flag, page + 0xe, recs[record] ); 131 act_on_record( file, flag, page + 0xe, recs[record] );
132} 132}
133 133
134void act_on_file( uint8_t *file ) 134static void act_on_file( uint8_t *file )
135{ 135{
136 int page, num_pages = *(uint16_t*)(file+0x40); 136 int page, num_pages = *(uint16_t*)(file+0x40);
137 int num_records = *(uint32_t*)(file+0x42); 137 uint32_t num_records= *(uint32_t*)(file+0x42);
138 char *gasse = (char *)file + 0x8e; 138 char *gasse = (char *)file + 0x8e;
139 char *ort = gasse + 1 + strlen(gasse); 139 char *ort = gasse + 1 + strlen(gasse);
140 char *zip = ort + 1 + strlen(ort); 140 char *zip = ort + 1 + strlen(ort);
141 char *vorwahl = zip + 1 + strlen(zip); 141 char *vorwahl = zip + 1 + strlen(zip);
142 char ort_conv[1024]; int i; 142 char ort_conv[1024]; int i;
143 143
144 for(i=0; ort[i]; ++i ) ort_conv[i] = cp437_to_iso8859_1_table[((uint8_t*)ort)[i]]; ort_conv[i] = 0; 144 for(i=0; ort[i]; ++i ) ort_conv[i] = (char)cp437_to_iso8859_1_table[((uint8_t*)ort)[i]]; ort_conv[i] = 0;
145 /* printf( "Working on a %04d page and %06d records file, city: %4s %-32s with prefix %s\n", num_pages, num_records, zip, ort_conv, vorwahl ); */ 145 /* printf( "Working on a %04d page and %06d records file, city: %4s %-32s with prefix %s\n", num_pages, num_records, zip, ort_conv, vorwahl ); */
146 (void)num_records; /* silence warning about unused variable */ 146 (void)num_records; /* silence warning about unused variable */
147 147
diff --git a/src/export/extract_version_2.c b/src/export/extract_version_2.c
index 6686dca..c4914a7 100644
--- a/src/export/extract_version_2.c
+++ b/src/export/extract_version_2.c
@@ -28,10 +28,9 @@ static uint8_t mantra_in[] = { 0x68, 0x35, 0x2d, 0x6c };
28 28
29int main( int args, char **argv ) 29int main( int args, char **argv )
30{ 30{
31 int filenum = 0, run = 1; 31 int filenum = 0, run = 1, first_run = 1;
32 size_t offset = 0, reported = 0, enc_len = 32; 32 size_t offset = 0, old_offset = 0, reported = 0, enc_len = 32;
33 ssize_t oldoffset = -1; 33 uint8_t mantra[4], id0, id5, *mapped_file;
34 uint8_t mantra[4], id0, id5, *mappedfile;
35 MAP map; 34 MAP map;
36 35
37 /* For streets we do have a enc_len of 34 */ 36 /* For streets we do have a enc_len of 34 */
@@ -39,11 +38,11 @@ int main( int args, char **argv )
39 switch( getopt( args, argv, ":e:" ) ) { 38 switch( getopt( args, argv, ":e:" ) ) {
40 case -1 : run = 0; break; 39 case -1 : run = 0; break;
41 case 'e': 40 case 'e':
42 enc_len = atol( optarg ); 41 enc_len = strtoul( optarg, 0, 0 );
43 break; 42 break;
44 default: 43 default:
45 fputs( "Syntax: %s [-e encrypted_length (default: 32, for streets 34 or 0)] path-to-teiln.dat", stderr ); exit( 1 ); 44 fputs( "Syntax: %s [-e encrypted_length (default: 32, for streets 34 or 0)] path-to-teiln.dat", stderr );
46 break; 45 exit( 1 );
47 } 46 }
48 } 47 }
49 run = 1; 48 run = 1;
@@ -52,25 +51,25 @@ int main( int args, char **argv )
52 { fputs( "Missing filename.", stderr ); exit( 1 ); } 51 { fputs( "Missing filename.", stderr ); exit( 1 ); }
53 52
54 map = map_file( argv[optind], 1 ); 53 map = map_file( argv[optind], 1 );
55 mappedfile = map->addr; 54 mapped_file = map->addr;
56 55
57 mantra[0] = mantra_in[0] ^ mappedfile[4]; 56 mantra[0] = mantra_in[0] ^ mapped_file[4];
58 mantra[1] = mantra_in[1] ^ mappedfile[5]; 57 mantra[1] = mantra_in[1] ^ mapped_file[5];
59 mantra[2] = mantra_in[2] ^ mappedfile[2]; 58 mantra[2] = mantra_in[2] ^ mapped_file[2];
60 mantra[3] = mantra_in[3] ^ mappedfile[3]; 59 mantra[3] = mantra_in[3] ^ mapped_file[3];
61 60
62 id0 = mappedfile[0]; 61 id0 = mapped_file[0];
63 id5 = mappedfile[5]; 62 id5 = mapped_file[5];
64 63
65 while( run ) 64 while( run )
66 { 65 {
67 while( ( offset < map->size ) && ( 66 while( ( offset < map->size ) && (
68 ( mappedfile[ offset + 0 ] != id0 ) || 67 ( mapped_file[ offset + 0 ] != id0 ) ||
69 ( mappedfile[ offset + 2 ] != ( '-' ^ mantra[2] )) || 68 ( mapped_file[ offset + 2 ] != ( '-' ^ mantra[2] )) ||
70 ( mappedfile[ offset + 3 ] != ( 'l' ^ mantra[3] )) || 69 ( mapped_file[ offset + 3 ] != ( 'l' ^ mantra[3] )) ||
71 ( mappedfile[ offset + 4 ] != ( 'h' ^ mantra[0] )) || 70 ( mapped_file[ offset + 4 ] != ( 'h' ^ mantra[0] )) ||
72 ( mappedfile[ offset + 5 ] != id5 ) || 71 ( mapped_file[ offset + 5 ] != id5 ) ||
73 ( mappedfile[ offset + 6 ] != ( '-' ^ mantra[2] )) 72 ( mapped_file[ offset + 6 ] != ( '-' ^ mantra[2] ))
74 ) ) offset++; 73 ) ) offset++;
75 74
76 // printf( "Found an appropriate offset at: %zd\n", offset ); 75 // printf( "Found an appropriate offset at: %zd\n", offset );
@@ -85,11 +84,12 @@ int main( int args, char **argv )
85 if( offset == map->size ) 84 if( offset == map->size )
86 run = 0; 85 run = 0;
87 86
88 if( oldoffset != -1 ) 87 if( !first_run )
89 { 88 {
90 uint8_t *mf = mappedfile + oldoffset, df[128]; 89 uint8_t *mf = mapped_file + old_offset, df[128];
91 size_t filename_len, header_len, i; 90 size_t filename_len, header_len, i;
92 char filename_template[32], filename[32]; 91 int fh;
92 char filename[32];
93 93
94 /* De-"crypt" obfuscation to our header copy */ 94 /* De-"crypt" obfuscation to our header copy */
95 for( i=0; i<enc_len; ++i) 95 for( i=0; i<enc_len; ++i)
@@ -104,26 +104,25 @@ int main( int args, char **argv )
104 df[i] = mf[i]; 104 df[i] = mf[i];
105 105
106 /* Make up new sequental file name */ 106 /* Make up new sequental file name */
107 snprintf( filename_template, sizeof(filename_template), "%%0%dd.lha", (int)filename_len ); 107 snprintf( filename, sizeof(filename), "%0*d.lha", (int)filename_len, filenum++ );
108 snprintf( filename, sizeof( filename ), filename_template, filenum++ );
109 memcpy( ((uint8_t*)df) + 22, filename, filename_len); 108 memcpy( ((uint8_t*)df) + 22, filename, filename_len);
110 109
111 /* Recalculate checksum with new file name */ 110 /* Recalculate checksum with new file name */
112 df[1] = 0; for( i=2; i<header_len; ++i) df[1] += df[i]; 111 df[1] = 0; for( i=2; i<header_len; ++i) df[1] += df[i];
113 112
114 /* Open file and dump our de-"crypted" header and then rest of file */ 113 /* Open file and dump our de-"crypted" header and then rest of file */
115 i = open( filename, O_CREAT | O_TRUNC | O_WRONLY, 0644 ); 114 fh = open( filename, O_CREAT | O_TRUNC | O_WRONLY, 0644 );
116 if( enc_len > header_len ) { 115 if( enc_len > header_len ) {
117 write( i, df, enc_len ); 116 write( fh, df, enc_len );
118 write( i, mf + enc_len, offset - oldoffset - enc_len ); 117 write( fh, mf + enc_len, offset - old_offset - enc_len );
119 } else { 118 } else {
120 write( i, df, header_len ); 119 write( fh, df, header_len );
121 write( i, mf + header_len, offset - oldoffset - header_len ); 120 write( fh, mf + header_len, offset - old_offset - header_len );
122 } 121 }
123 close( i ); 122 close( fh );
124 } 123 }
125 oldoffset = offset; 124 first_run = 0;
126 offset++; 125 old_offset = offset++;
127 } 126 }
128 127
129 unmap_file( &map ); 128 unmap_file( &map );
diff --git a/src/export/extract_version_3.c b/src/export/extract_version_3.c
index 19df167..cbe0c7e 100644
--- a/src/export/extract_version_3.c
+++ b/src/export/extract_version_3.c
@@ -19,8 +19,8 @@ int main(int argc, char **argv) {
19 unsigned char input [XORLEN]; 19 unsigned char input [XORLEN];
20 unsigned char output [HUGEBLOCK]; 20 unsigned char output [HUGEBLOCK];
21 char respath[32]; /* file_XXXXX\0 */ 21 char respath[32]; /* file_XXXXX\0 */
22 int i, zres = 0, filenum = 0, resfile; 22 int zres = 0, filenum = 0, resfile;
23 size_t offs = 0, reported = 0; 23 size_t i, offs = 0, reported = 0;
24 24
25 z_stream z; memset( &z, 0, sizeof(z)); 25 z_stream z; memset( &z, 0, sizeof(z));
26 26
@@ -32,7 +32,8 @@ int main(int argc, char **argv) {
32 if( (zres != Z_OK) && (zres != Z_STREAM_END) ) 32 if( (zres != Z_OK) && (zres != Z_STREAM_END) )
33 goto error_continue; 33 goto error_continue;
34 34
35 z.next_in = in->addr + offs + XORLEN; z.avail_in = in->size - offs - XORLEN; 35 z.next_in = in->addr + offs + XORLEN;
36 z.avail_in = (unsigned int)(in->size - offs - XORLEN);
36 while( zres == Z_OK ) zres = inflate( &z, Z_NO_FLUSH ); 37 while( zres == Z_OK ) zres = inflate( &z, Z_NO_FLUSH );
37 38
38 if( zres != Z_STREAM_END ) { 39 if( zres != Z_STREAM_END ) {
diff --git a/src/export/map_coords.c b/src/export/map_coords.c
index 93c858f..ed5376a 100644
--- a/src/export/map_coords.c
+++ b/src/export/map_coords.c
@@ -5,13 +5,13 @@
5#include <string.h> 5#include <string.h>
6#include <ctype.h> 6#include <ctype.h>
7 7
8int find_offset( const void *key, const void *line ) 8static int find_offset( const void *key, const void *line )
9{ 9{
10 size_t l = strlen( (char*)key ); 10 size_t l = strlen( (char*)key );
11 return strncmp( (char*)key, *(char**)line, l ); 11 return strncmp( (char*)key, *(char**)line, l );
12} 12}
13 13
14int qsort_cmp( const void *a, const void *b ) 14static int qsort_cmp( const void *a, const void *b )
15{ 15{
16 return strcmp( *(char**)a, *(char**)b ); 16 return strcmp( *(char**)a, *(char**)b );
17} 17}
diff --git a/src/export/mystdlib.c b/src/export/mystdlib.c
index ffc0cd9..b65f63d 100644
--- a/src/export/mystdlib.c
+++ b/src/export/mystdlib.c
@@ -46,10 +46,10 @@ void unmap_file ( MAP *pMap )
46 free( *pMap ); *pMap = NULL; 46 free( *pMap ); *pMap = NULL;
47} 47}
48 48
49int getfilesize( int fd, unsigned long *size) 49int getfilesize( int fd, size_t *size)
50{ 50{
51 struct stat sb; 51 struct stat sb;
52 if( fstat( fd, &sb )) return -1; 52 if( fstat( fd, &sb )) return -1;
53 *size = sb.st_size; 53 *size = (size_t)sb.st_size;
54 return 0; 54 return 0;
55} 55}
diff --git a/src/export/mystdlib.h b/src/export/mystdlib.h
index 2e9499f..dd08137 100644
--- a/src/export/mystdlib.h
+++ b/src/export/mystdlib.h
@@ -1,7 +1,8 @@
1#include <sys/types.h> 1#include <sys/types.h>
2#include <stdint.h>
2#include <stdio.h> 3#include <stdio.h>
3 4
4typedef struct { int fh; unsigned char *addr; size_t size; } *MAP; 5typedef struct { int fh; uint8_t *addr; size_t size; } *MAP;
5 6
6/* Mapps a file into memory 7/* Mapps a file into memory
7 returns pointer to the mapping struct, 8 returns pointer to the mapping struct,
@@ -28,5 +29,5 @@ void unmap_file ( MAP *pMap );
28 29
29/* Gets file size of open file 30/* Gets file size of open file
30 returns != 0 in case of error */ 31 returns != 0 in case of error */
31inline int getfilesize( int fd, unsigned long *size ); 32inline int getfilesize( int fd, size_t *size );
32 33
diff --git a/src/export/split_version_2.c b/src/export/split_version_2.c
index ab6c8cf..2019762 100644
--- a/src/export/split_version_2.c
+++ b/src/export/split_version_2.c
@@ -7,19 +7,17 @@
7 7
8int main( int argc, char **args ) { 8int main( int argc, char **args ) {
9 char table[64], f[1024*1024]; 9 char table[64], f[1024*1024];
10 int outfiles[64], i, base = 0; 10 int outfiles[64], i, base = 0, fixed_columns = 0;
11 uint32_t fixed_columns = 0;
12 uint32_t *p = (uint32_t*)f; 11 uint32_t *p = (uint32_t*)f;
13 12
14 if( argc > 1 ) base = atol( args[1] ); 13 if( argc > 1 ) base = atoi( args[1] );
15 if( argc > 2 ) fixed_columns = atol( args[2] ); 14 if( argc > 2 ) fixed_columns = atoi( args[2] );
16 15
17 /* No output file yet valid */ 16 /* No output file yet valid */
18 for( i=0; i<64; ++i ) outfiles[i] = -1; 17 for( i=0; i<64; ++i ) outfiles[i] = -1;
19 18
20 while( fgets( table, sizeof(table), stdin ) ) { 19 while( fgets( table, sizeof(table), stdin ) ) {
21 unsigned int file, strnr; 20 int file, strnr, columns, count;
22 uint32_t count, columns;
23 21
24 table[strlen(table)-1] = 0; 22 table[strlen(table)-1] = 0;
25 23
@@ -32,15 +30,15 @@ int main( int argc, char **args ) {
32 close(f_in); 30 close(f_in);
33 } 31 }
34 32
35 count = p[0], 33 count = (int)*p,
36 columns = fixed_columns ? fixed_columns : p[1] / 4 - 1; 34 columns = fixed_columns ? fixed_columns : (int)p[1] / 4 - 1;
37 35
38 for( file=0; file<columns; ++file ) { 36 for( file=0; file<columns; ++file ) {
39 uint32_t off; 37 uint32_t off;
40 38
41 /* Create outfile, if it is not yet there */ 39 /* Create outfile, if it is not yet there */
42 if( outfiles[file] == -1 ) { 40 if( outfiles[file] == -1 ) {
43 sprintf( table, "%02d_unknown", file+base ); 41 sprintf( table, "%02d_unknown", file + base );
44 outfiles[file] = open( table, O_WRONLY | O_APPEND | O_CREAT, 0644 ); 42 outfiles[file] = open( table, O_WRONLY | O_APPEND | O_CREAT, 0644 );
45 if ( outfiles[file] == -1 ) { 43 if ( outfiles[file] == -1 ) {
46 fprintf( stderr, "Can not create output file %s\n", table ); 44 fprintf( stderr, "Can not create output file %s\n", table );