diff options
Diffstat (limited to 'src/extractstreets.c')
-rw-r--r-- | src/extractstreets.c | 66 |
1 files changed, 0 insertions, 66 deletions
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 | |||
8 | int 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 | } | ||