File: file.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (261 lines) | stat: -rw-r--r-- 5,546 bytes parent folder | download | duplicates (2)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "ags/lib/allegro/file.h"
#include "common/file.h"
#include "common/str.h"
#include "common/textconsole.h"

namespace AGS3 {

PACKFILE *PACKFILE::pack_fopen_chunk(int pack) {
	error("TODO: pack_fopen_chunk is not yet supported");
}

PACKFILE *PACKFILE::pack_fclose_chunk() {
	error("TODO: pack_fclose_chunk is not yet supported");
}

int PACKFILE::pack_igetw() {
	byte buf[2];
	return pack_fread(buf, 2) == 2 ? READ_LE_UINT16(buf) : 0;
}

int32_t PACKFILE::pack_igetl() {
	byte buf[4];
	return pack_fread(buf, 4) == 4 ? READ_LE_UINT32(buf) : 0;
}

int PACKFILE::pack_iputw(int w) {
	byte buf[2];
	WRITE_LE_UINT16(buf, w);
	pack_fwrite(buf, 2);
	return 0;
}

int32_t PACKFILE::pack_iputl(int32_t l) {
	byte buf[4];
	WRITE_LE_UINT32(buf, l);
	pack_fwrite(buf, 4);
	return 0;
}

int PACKFILE::pack_mgetw() {
	byte buf[2];
	return pack_fread(buf, 2) == 2 ? READ_BE_UINT16(buf) : 0;
}

int32_t PACKFILE::pack_mgetl() {
	byte buf[4];
	return pack_fread(buf, 4) == 4 ? READ_BE_UINT32(buf) : 0;
}

int PACKFILE::pack_mputw(int w) {
	byte buf[2];
	WRITE_BE_UINT16(buf, 2);
	pack_fwrite(buf, 2);
	return 0;
}

int32_t PACKFILE::pack_mputl(int32_t l) {
	byte buf[4];
	WRITE_BE_UINT16(buf, 4);
	pack_fwrite(buf, 4);
	return 0;
}

char *PACKFILE::pack_fgets(char *p, int max) {
	int c;
	char *dest = p;

	while ((c = pack_getc()) != 0 && !pack_feof() && max-- > 0) {
		*dest++ = c;
	}

	return p;
}

int PACKFILE::pack_fputs(AL_CONST char *p) {
	pack_fwrite(p, strlen(p));
	pack_putc(0);
	return 0;
}

/*------------------------------------------------------------------*/

/* Use strictly UTF-8 encoding for the file paths
 */
#define U_CURRENT U_UTF8
#define ugetc     utf8_getc
#define ugetx     utf8_getx
#define ugetxc    utf8_getx
#define usetc     utf8_setc
#define uwidth    utf8_width
#define ucwidth   utf8_cwidth
#define uisok     utf8_isok

void set_filename_encoding(int) {
	// No implementation
}

char *fix_filename_case(char *path) {
	return path;
}

char *fix_filename_slashes(char *path) {
	return path;
}

char *append_filename(char *dest, const char *path, const char *filename, int size) {
	strncpy(dest, path, size);
	strncat(dest, filename, size);
	return dest;
}

char *canonicalize_filename(char *dest, const char *filename, int size) {
	strncpy(dest, filename, size);
	return dest;
}

char *make_relative_filename(char *dest, const char *path, const char *filename, int size) {
	strncpy(dest, filename, size);
	return dest;
}

int is_relative_filename(const char *filename) {
	// ScummVM doesn't have absolute paths
	return true;
}

/*------------------------------------------------------------------*/

void packfile_password(AL_CONST char *password) {
	error("TODO: packfile_password");
}

PACKFILE *pack_fopen(AL_CONST char *filename, AL_CONST char *mode) {
	assert(!strcmp(mode, "r") || !strcmp(mode, "rb"));

	Common::File *f = new Common::File();
	if (f->open(filename)) {
		return new ScummVMPackFile(f);

	} else {
		delete f;
		return nullptr;
	}
}

PACKFILE *pack_fopen_vtable(AL_CONST PACKFILE_VTABLE *vtable, void *userdata) {
	return new VTablePackFile(vtable, userdata);
}

int pack_fclose(PACKFILE *f) {
	f->close();
	delete f;
	return 0;
}

int pack_fseek(PACKFILE *f, int offset) {
	return f->pack_fseek(offset);
}

PACKFILE *pack_fopen_chunk(PACKFILE *f, int pack) {
	return f->pack_fopen_chunk(pack);
}

PACKFILE *pack_fclose_chunk(PACKFILE *f) {
	return f->pack_fclose_chunk();
}

int pack_getc(PACKFILE *f) {
	return f->pack_getc();
}

int pack_putc(int c, PACKFILE *f) {
	return f->pack_putc(c);
}

int pack_feof(PACKFILE *f) {
	return f->pack_feof();
}

int pack_ferror(PACKFILE *f) {
	return f->pack_ferror();
}

int pack_igetw(PACKFILE *f) {
	error("TODO: xxx");
}

int32_t pack_igetl(PACKFILE *f) {
	return f->pack_igetl();
}

int pack_iputw(int w, PACKFILE *f) {
	return f->pack_iputw(w);
}

int32_t pack_iputl(int32_t l, PACKFILE *f) {
	return f->pack_iputl(l);
}

int pack_mgetw(PACKFILE *f) {
	return f->pack_mgetw();
}

int32_t pack_mgetl(PACKFILE *f) {
	return f->pack_mgetl();
}

int pack_mputw(int w, PACKFILE *f) {
	return f->pack_mputw(w);
}

int32_t pack_mputl(int32_t l, PACKFILE *f) {
	return f->pack_mputl(l);
}

long pack_fread(void *p, long n, PACKFILE *f) {
	return f->pack_fread(p, n);
}

long pack_fwrite(AL_CONST void *p, long n, PACKFILE *f) {
	return f->pack_fwrite(p, n);
}

int pack_ungetc(int c, PACKFILE *f) {
	return f->pack_ungetc(c);
}

char *pack_fgets(char *p, int max, PACKFILE *f) {
	return f->pack_fgets(p, max);
}

int pack_fputs(AL_CONST char *p, PACKFILE *f) {
	return f->pack_fputs(p);
}

void *pack_get_userdata(PACKFILE *f) {
	return f->pack_get_userdata();
}

} // namespace AGS3