|
| 1 | +/* |
| 2 | +Copyright (C) 2000 Dancer A.L Vesperman |
| 3 | +
|
| 4 | +This program is free software; you can redistribute it and/or |
| 5 | +modify it under the terms of the GNU General Public License |
| 6 | +as published by the Free Software Foundation; either version 2 |
| 7 | +of the License, or (at your option) any later version. |
| 8 | +
|
| 9 | +This program is distributed in the hope that it will be useful, |
| 10 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +GNU General Public License for more details. |
| 13 | +
|
| 14 | +You should have received a copy of the GNU General Public License |
| 15 | +along with this program; if not, write to the Free Software |
| 16 | +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | +*/ |
| 18 | + |
| 19 | + |
| 20 | +#if __GNUG__ >= 2 |
| 21 | +# pragma implementation |
| 22 | +#endif |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +#include "Flex.h" |
| 27 | + |
| 28 | +#include <cstdio> |
| 29 | +#include <iostream> |
| 30 | + |
| 31 | +void Flex::IndexFlexFile(void) |
| 32 | +{ |
| 33 | + Flex &ret=*this; |
| 34 | + FILE *fp; |
| 35 | + const char *name=ret.filename.c_str(); |
| 36 | + fp=fopen(name,"rb"); |
| 37 | + if(!fp) |
| 38 | + { |
| 39 | + throw 0; |
| 40 | + return; |
| 41 | + } |
| 42 | + fread(ret.title,sizeof(ret.title),1,fp); |
| 43 | + fread(&ret.magic1,sizeof(uint32),1,fp); |
| 44 | + fread(&ret.count,sizeof(uint32),1,fp); |
| 45 | + fread(&ret.magic2,sizeof(uint32),1,fp); |
| 46 | + if(magic1!=0xffff1a00UL) |
| 47 | + throw 0; // Not a flex file |
| 48 | + for(int i=0;i<9;i++) |
| 49 | + fread(&ret.padding[i],sizeof(uint32),1,fp); |
| 50 | +#if DEBUGFLEX |
| 51 | + cout << "Title: " << ret.title << endl; |
| 52 | + cout << "Count: " << ret.count << endl; |
| 53 | +#endif |
| 54 | + |
| 55 | + // We should already be there. |
| 56 | + fseek(fp,128,SEEK_SET); |
| 57 | + for(unsigned int i=0;i<ret.count;i++) |
| 58 | + { |
| 59 | + Flex::Reference f; |
| 60 | + fread(&f.offset,sizeof(uint32),1,fp); |
| 61 | + fread(&f.size,sizeof(uint32),1,fp); |
| 62 | +#if DEBUGFLEX |
| 63 | + cout << "Item " << i << ": " << f.size << " bytes @ " << f.offset << endl; |
| 64 | +#endif |
| 65 | + ret.object_list.push_back(f); |
| 66 | + } |
| 67 | + fclose(fp); |
| 68 | +} |
| 69 | + |
| 70 | +#if 0 |
| 71 | +char *Flex::read_object(int objnum,uint32 &length) |
| 72 | +{ |
| 73 | + if((unsigned)objnum>=object_list.size()) |
| 74 | + { |
| 75 | + cerr << "objnum too large in read_object()" << endl; |
| 76 | + return 0; |
| 77 | + } |
| 78 | + FILE *fp=fopen(filename.c_str(),"rb"); |
| 79 | + if(!fp) |
| 80 | + { |
| 81 | + cerr << "File open failed in read_object" << endl; |
| 82 | + return 0; |
| 83 | + } |
| 84 | + fseek(fp,object_list[objnum].offset,SEEK_SET); |
| 85 | + length=object_list[objnum].size; |
| 86 | + char *ret=new char[length]; |
| 87 | + fread(ret,length,1,fp); |
| 88 | + fclose(fp); |
| 89 | + return ret; |
| 90 | +} |
| 91 | +#endif |
0 commit comments