2 Cantaveria - action adventure platform game
3 Copyright (C) 2009 2010 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
44 //zzip_dir = zzip_dir_open(filename, 0);
46 // report_error("loader: unable to open game data in %s (%s)\n",
47 // filename, strerror( errno ) );
53 //zzip_dir_close(zzip_dir);
56 reader
* data_open(char* dir
, char* filename
){
59 strcat(buf
, filename
);
60 return loader_open(buf
);
63 reader
* loader_open(char* filename
){
64 char buf
[1024] = "data/";
66 strncpy(buf
+L
,filename
,1024-L
);
69 reader
* rd
= xmalloc(sizeof(reader
));
70 //printf("loader: %s\n",buf);
72 //rd->f = zzip_file_open(zzip_dir, buf, 0);
73 rd
->f
= zzip_open(buf
, 0);
75 //report_error("loader: unable to open %s (%s)\n",
76 // filename, zzip_strerror_of( zzip_dir ) );
77 report_error("loader: unable to open %s (%s)\n",
78 filename
, strerror( errno
) );
86 void loader_close(reader
* rd
){
87 //zzip_file_close(rd->f);
93 int loader_read(reader
* rd
, void* buf
, int count
){
94 return zzip_read(rd
->f
, buf
, count
);
97 unsigned char* loader_readall(char* filename
, int* size
){
99 reader
* rd
= loader_open(filename
);
101 if(zzip_fstat(rd
->f
, &zs
) < 0){
102 report_error("loader: stat error on %s\n",filename
);
106 unsigned char* buf
= xmalloc(N
);
107 loader_read(rd
,buf
,N
);
114 int loader_scanline(reader
* rd
, char* format
, ...){
121 /* get next character */
122 if(rd
->next_c
!= -1){
127 int n
= loader_read(rd
, &c
, 1);
133 /* see if it is a end of line sequence */
135 int n
= loader_read(rd
, &c
, 1);
153 va_start(ap
, format
);
155 int ret
= vsscanf(buf
,format
,ap
);
166 unsigned char read_byte(reader
* rd
){
168 loader_read(rd
, &c
, 1);
172 short read_short(reader
* rd
){
174 loader_read(rd
, c
+0, 1);
175 loader_read(rd
, c
+1, 1);
176 return (c
[0]<<8) | c
[1];
179 int read_int(reader
* rd
){
181 loader_read(rd
, c
+0, 1);
182 loader_read(rd
, c
+1, 1);
183 loader_read(rd
, c
+2, 1);
184 loader_read(rd
, c
+3, 1);
185 return (c
[0]<<24) | (c
[1]<<16) | (c
[2]<<8) | c
[3];
188 char* read_string(reader
* rd
){
189 unsigned int L
= read_int(rd
);
190 if(L
==0) return NULL
;
191 char* S
= xmalloc(L
+1);
193 loader_read(rd
, S
, L
);
200 char** loader_readdir(char* path
){
201 char buf
[1024] = "data/";
204 ZZIP_DIR
* dir
= zzip_opendir(buf
);
208 while( (ent
= zzip_readdir(dir
)) ) N
++;
210 char** res
= xmalloc((N
+1)*sizeof(char*));
213 dir
= zzip_opendir(buf
);
217 ent
= zzip_readdir(dir
);
222 else if(ent
->d_name
[0] == '.'){
225 res
[i
] = xmalloc(strlen(ent
->d_name
)+1);
226 strcpy(res
[i
], ent
->d_name
);
234 void loader_freedirlist(char** list
){
236 for(i
=0; list
[i
]; i
++){