comparison src/libmlk-rpg/rpg/map-file.c @ 428:26d23999a54b

core: get rid of zfile
author David Demelier <markand@malikania.fr>
date Sat, 15 Oct 2022 14:38:15 +0200
parents 7d2ebc334c8c
children 8f59201dc76b
comparison
equal deleted inserted replaced
427:b12e13e7a385 428:26d23999a54b
28 28
29 #include <core/alloc.h> 29 #include <core/alloc.h>
30 #include <core/error.h> 30 #include <core/error.h>
31 #include <core/image.h> 31 #include <core/image.h>
32 #include <core/trace.h> 32 #include <core/trace.h>
33 #include <core/zfile.h>
34 33
35 #include "map-file.h" 34 #include "map-file.h"
36 35
37 #define MAX_F(v) MAX_F_(v) 36 #define MAX_F(v) MAX_F_(v)
38 #define MAX_F_(v) "%" #v "[^\n|]" 37 #define MAX_F_(v) "%" #v "[^\n|]"
270 269
271 struct context ctx = { 270 struct context ctx = {
272 .mf = file, 271 .mf = file,
273 .map = map, 272 .map = map,
274 }; 273 };
275 struct zfile zf;
276 int ret = 0; 274 int ret = 0;
277 275
278 memset(map, 0, sizeof (*map)); 276 memset(map, 0, sizeof (*map));
279
280 alloc_pool_init(&file->blocks, sizeof (*map->blocks), NULL); 277 alloc_pool_init(&file->blocks, sizeof (*map->blocks), NULL);
281 278
282 if (zfile_open(&zf, path) < 0) 279 if (!(ctx.fp = fopen(path, "r")))
283 goto fail; 280 goto fail;
284
285 ctx.fp = zf.fp;
286
287 if ((ret = parse(&ctx, path)) < 0 || (ret = check(map)) < 0) 281 if ((ret = parse(&ctx, path)) < 0 || (ret = check(map)) < 0)
288 goto fail; 282 goto fail;
289 283
290 zfile_close(&zf); 284 fclose(ctx.fp);
291 285
292 return 0; 286 return 0;
293 287
294 fail: 288 fail:
295 errorf("%s: %s", path, strerror(errno));
296 map_finish(map); 289 map_finish(map);
297 map_file_finish(file); 290 map_file_finish(file);
298 zfile_close(&zf); 291
292 if (ctx.fp)
293 fclose(ctx.fp);
299 294
300 return -1; 295 return -1;
301 } 296 }
302 297
303 void 298 void