summaryrefslogtreecommitdiff
path: root/dumb/dumb-0.9.3/src/allegro/packfile.c
blob: 525baebd4eccad5091d11519aabb36097026e231 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*  _______         ____    __         ___    ___
 * \    _  \       \    /  \  /       \   \  /   /       '   '  '
 *  |  | \  \       |  |    ||         |   \/   |         .      .
 *  |  |  |  |      |  |    ||         ||\  /|  |
 *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
 *  |  |  |  |      |  |    ||         ||    |  |         .      .
 *  |  |_/  /        \  \__//          ||    |  |
 * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
 *                                                      /  \
 *                                                     / .  \
 * packfile.c - Packfile input module.                / / \  \
 *                                                   | <  /   \_
 * By entheh.                                        |  \/ /\   /
 *                                                    \_  /  > /
 * Note that this does not use file compression;        | \ / /
 * for that you must open the file yourself and         |  ' /
 * then use dumbfile_open_packfile().                    \__/
 */

#include <allegro.h>

#include "aldumb.h"



static void *dumb_packfile_open(const char *filename)
{
	return pack_fopen(filename, F_READ);
}



static int dumb_packfile_skip(void *f, long n)
{
	return pack_fseek(f, n);
}



static int dumb_packfile_getc(void *f)
{
	return pack_getc(f);
}



static long dumb_packfile_getnc(char *ptr, long n, void *f)
{
	return pack_fread(ptr, n, f);
}



static void dumb_packfile_close(void *f)
{
	pack_fclose(f);
}



static DUMBFILE_SYSTEM packfile_dfs = {
	&dumb_packfile_open,
	&dumb_packfile_skip,
	&dumb_packfile_getc,
	&dumb_packfile_getnc,
	&dumb_packfile_close
};



void dumb_register_packfiles(void)
{
	register_dumbfile_system(&packfile_dfs);
}



static DUMBFILE_SYSTEM packfile_dfs_leave_open = {
	NULL,
	&dumb_packfile_skip,
	&dumb_packfile_getc,
	&dumb_packfile_getnc,
	NULL
};



DUMBFILE *dumbfile_open_packfile(PACKFILE *p)
{
	return dumbfile_open_ex(p, &packfile_dfs_leave_open);
}



DUMBFILE *dumbfile_from_packfile(PACKFILE *p)
{
	return p ? dumbfile_open_ex(p, &packfile_dfs) : NULL;
}