summaryrefslogtreecommitdiff
path: root/VP/decomp-slz.cpp
blob: fa094115e9d8cac4d420a8528f95a898c00432b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>

#include "lzss.h"
#include "fileutils.h"
#include "generic.h"

int main(int argc, char ** argv) {
    int sig, l, d, v;
    FILE * fin = stdin, * fout = stdout;
    
    switch (argc) {
    case 3:
	if (!(fout = fopen(argv[2], "w"))) {
	    printm(M_ERROR, "Error opening file %s.\n", argv[3]);
	    exit(-1);
	}
    case 2:
	if (!(fin = fopen(argv[1], "r"))) {
	    printm(M_ERROR, "Error opening file %s.\n", argv[2]);
	    exit(-1);
	}
	break;
    case 1:
	break;
    default:
	printm(M_BARE, "Usage: %s [filein] [fileout]\n", argv[0]);
	exit(-1);
    }
    
    verbosity = M_STATUS;
    
    fread(&sig, 1, 4, fin);
    fread(&d, 1, 4, fin);
    fread(&l, 1, 4, fin);
    switch (sig) {
    case 0x05a4c53:
	printm(M_STATUS, "Detected a SLZ-type 0 file.\n");
	fread(&v, 1, 4, fin);
	copy(fin, fout, d);
	exit(0);
    case 0x15a4c53:
	scheme = schemes[VP_1];
	printm(M_STATUS, "Detected a SLZ-type 1 file.\n");
	break;
    case 0x25a4c53:
	scheme = schemes[VP_2];
	printm(M_STATUS, "Detected a SLZ-type 2 file.\n");
	break;
    default:
	printm(M_ERROR, "Not a SLZ file.\n");
	exit(-1);
    }
    
    lzss_decomp(fin, fout, l);
    exit(0);
}