/************************************************************************* * * HTCd - Copyright (C) 1998-2006 Henrik Rydberg * * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include using namespace std; const mstring HEAD10="HTC DB File Format version 1.0\n"; const mstring HEAD11="HDB/1.1"; static fp_stream merr(stderr); static void Read(FILE* fp,mstring& s,int version) { int n; fread(&n,4,1,fp); switch(version) { case 10: s.resize(n); fread(s.data(),1,n,fp); break; case 11: s.resize(n-1); fread(s.data(),1,n,fp); s.resize(strlen(s.data())); if(s.size()>=n) THROW("dbmap: assertion failed on dimension"); break; default: THROW("read: bad HDB version"); break; } } void Convert(dbmap& db,const char* path) { FILE* fp=fopen(path,"rb"); char line[1024]; fgets(line,1000,fp); int version=0; if(sref(line)==HEAD10) { fgetc(fp); version=10; } else if(First(sref(line))==HEAD11) { version=11; } if(version==0) THROW("hdbcvt: unknown HDB format"); int tables; mstring s; fread(&tables,4,1,fp); for(int i=0;i