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
|
/*
Copyright (C) 2000 Dancer A.L Vesperman
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 2
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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "Table.h"
#ifndef ALPHA_LINUX_CXX
# include <cstdio>
#endif
#include <iostream>
#include "exceptions.h"
#include "utils.h"
using std::string;
using std::vector;
using std::cout;
using std::cerr;
using std::endl;
using std::FILE;
using std::size_t;
Table::Table(const string &n) : U7file(n)
{
IndexTableFile();
}
void Table::IndexTableFile(void)
{
Table &ret=*this;
FILE *fp;
try {
fp=U7open(ret.filename.c_str(),"rb");
} catch (const file_open_exception &e)
{
cerr << e.what() << ". exiting." << endl;
std::exit(1);
}
fseek(fp,0,SEEK_END);
size_t file_size=ftell(fp);
fseek(fp,0,SEEK_SET);
unsigned int i=0;
while(1)
{
Table::Reference f;
f.size = Read2(fp);
// fread(&f.size,sizeof(uint16),1,fp);
if(f.size==65535)
break;
f.offset = Read4(fp);
// fread(&f.offset,sizeof(uint32),1,fp);
if(f.size>file_size||f.offset>file_size)
throw wrong_file_type_exception(filename,"Table");
#if 0
cout << "Item " << i << ": " << f.size << " @ " << f.offset << endl;
#endif
ret.object_list.push_back(f);
i++;
}
fclose(fp);
return;
}
char* Table::retrieve(uint32 objnum,size_t &len)
{ throw exult_exception("Illegal call to Table::retrieve()"); }
#if 0
char *Table::read_object(int objnum,uint32 &length)
{
if((unsigned)objnum>=object_list.size())
{
cerr << "objnum too large in read_object()" << endl;
return 0;
}
FILE *fp;
try {
fp=U7open(filename.c_str(),"rb");
} catch (const file_open_exception &e)
{
cerr << e.what() << ". exiting." << endl;
exit(1);
}
if(!fp)
{
cerr << "File open failed in read_object: " << filename << endl;
return 0;
}
fseek(fp,object_list[objnum].offset,SEEK_SET);
// length=object_list[objnum].size;
uint16 sz;
sz = Read2(fp);
// fread(&sz,sizeof(sz),1,fp);
length=sz-2;
char *ret=new char[length];
fread(ret,length,1,fp);
fclose(fp);
return ret;
}
#endif
|