From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/hdb/cvt.cc | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/hdb/cvt.cc (limited to 'src/hdb/cvt.cc') diff --git a/src/hdb/cvt.cc b/src/hdb/cvt.cc new file mode 100644 index 0000000..4788bf1 --- /dev/null +++ b/src/hdb/cvt.cc @@ -0,0 +1,83 @@ +/************************************************************************* + * + * 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