2 * Copyright 2010-2012 Chris Spiegel.
4 * This file is part of Bocfel.
6 * Bocfel is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version
8 * 2 or 3, as published by the Free Software Foundation.
10 * Bocfel 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 Bocfel. If not, see <http://www.gnu.org/licenses/>.
33 struct zterp_iff *next;
36 void zterp_iff_free(zterp_iff *iff)
40 zterp_iff *tmp = iff->next;
46 zterp_iff *zterp_iff_parse(zterp_io *io, const char type[4])
50 zterp_iff *iff = NULL, *tail = NULL;
52 if(zterp_io_seek(io, 0, SEEK_SET) == -1) goto err;
54 if(!zterp_io_read32(io, &tag) || tag != STRID("FORM")) goto err;
56 if(zterp_io_seek(io, 4, SEEK_CUR) == -1) goto err;
58 if(!zterp_io_read32(io, &tag) || tag != STRID(type)) goto err;
60 while(zterp_io_read32(io, &tag))
65 if(!zterp_io_read32(io, &size)) goto err;
67 new = malloc(sizeof *new);
68 if(new == NULL) goto err;
72 new->offset = zterp_io_tell(io);
76 if(iff == NULL) iff = new;
77 else tail->next = new;
81 if(new->offset == -1) goto err;
85 if(zterp_io_seek(io, size, SEEK_CUR) == -1) goto err;
96 int zterp_iff_find(zterp_iff *iff, const char tag[4], uint32_t *size)
100 if(iff->tag == STRID(tag))
102 if(zterp_io_seek(iff->io, iff->offset, SEEK_SET) == -1) return 0;