aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/lzp/qlp.c
blob: 3be8356c052100e4425587205b36397a7e4c0734 (plain) (blame)
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
58
59
60
61
62
63
64
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "lzqlp.h"

static char* lcase(char* str) {

    while(*str != 0x00) {
		*str = tolower(*str);
		str++;
    }

    return(str);

}

int qlpFileCount(void* qlpfile) {

    if (strncmp(((QLP_HEAD*)qlpfile)->id, "QLP", 3) != 0)
		return(PACK_ERR_INVALID);

    return(((QLP_HEAD*)qlpfile)->numfiles);

}

QLP_FILE* qlpFileEntry(int index, void* qlpfile) {

	if (strncmp(((QLP_HEAD*)qlpfile)->id, "QLP", 3) != 0)
		return(NULL);

	if (index > ((QLP_HEAD*)qlpfile)->numfiles)
		return(NULL);

	return(&((QLP_FILE*)(qlpfile+4))[index]);

}

void* qlpFileAddr(int index, void* qlpfile) {

	return( qlpfile+((QLP_FILE*)(qlpfile+4))[index].offs );

}

int qlpFindFile(char* fileName, void* qlpfile) {

	int i;
	char nameBuff[2][16];

    strcpy(nameBuff[0], fileName);
    lcase(nameBuff[0]);

	for(i=0; i<((QLP_HEAD*)qlpfile)->numfiles; i++) {

		strcpy(nameBuff[1], ((QLP_FILE*)(qlpfile+4))[i].name);
        lcase(nameBuff[1]);

        if (strcmp(nameBuff[0], nameBuff[1]) == 0)
			return(i);

	}

	return(PACK_ERR_NOTFOUND);

}