00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022
00023 #include "Table.h"
00024
00025 #ifndef ALPHA_LINUX_CXX
00026 # include <cstdio>
00027 #endif
00028 #include <iostream>
00029 #include "exceptions.h"
00030 #include "utils.h"
00031
00032 using std::string;
00033 using std::vector;
00034
00035 using std::cout;
00036 using std::cerr;
00037 using std::endl;
00038 using std::FILE;
00039 using std::size_t;
00040
00041
00042 Table::Table(const string &n) : U7file(n)
00043 {
00044 IndexTableFile();
00045 }
00046
00047
00048 void Table::IndexTableFile(void)
00049 {
00050 Table &ret=*this;
00051 FILE *fp;
00052 try {
00053 fp=U7open(ret.filename.c_str(),"rb");
00054 } catch (const file_open_exception &e)
00055 {
00056 cerr << e.what() << ". exiting." << endl;
00057 std::exit(1);
00058 }
00059 fseek(fp,0,SEEK_END);
00060 size_t file_size=ftell(fp);
00061 fseek(fp,0,SEEK_SET);
00062 unsigned int i=0;
00063 while(1)
00064 {
00065 Table::Reference f;
00066 f.size = Read2(fp);
00067
00068 if(f.size==65535)
00069 break;
00070 f.offset = Read4(fp);
00071
00072 if(f.size>file_size||f.offset>file_size)
00073 throw wrong_file_type_exception(filename,"Table");
00074 #if 0
00075 cout << "Item " << i << ": " << f.size << " @ " << f.offset << endl;
00076 #endif
00077 ret.object_list.push_back(f);
00078 i++;
00079 }
00080 fclose(fp);
00081 return;
00082 }
00083
00084
00085 char* Table::retrieve(uint32 objnum,size_t &len)
00086 { throw exult_exception("Illegal call to Table::retrieve()"); }
00087
00088 #if 0
00089 char *Table::read_object(int objnum,uint32 &length)
00090 {
00091 if((unsigned)objnum>=object_list.size())
00092 {
00093 cerr << "objnum too large in read_object()" << endl;
00094 return 0;
00095 }
00096 FILE *fp;
00097 try {
00098 fp=U7open(filename.c_str(),"rb");
00099 } catch (const file_open_exception &e)
00100 {
00101 cerr << e.what() << ". exiting." << endl;
00102 exit(1);
00103 }
00104 if(!fp)
00105 {
00106 cerr << "File open failed in read_object: " << filename << endl;
00107 return 0;
00108 }
00109 fseek(fp,object_list[objnum].offset,SEEK_SET);
00110
00111 uint16 sz;
00112 sz = Read2(fp);
00113
00114 length=sz-2;
00115 char *ret=new char[length];
00116 fread(ret,length,1,fp);
00117 fclose(fp);
00118 return ret;
00119 }
00120 #endif