/* * This file part of makedict - convertor from any * dictionary format to any http://xdxf.sourceforge.net * Copyright (C) 2006 Evgeniy * * 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 Library 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 #include #include #include #include #include #include using std::cerr; using std::endl; using std::string; using std::vector; #include "generator.hpp" class dictd_generator : public makedict_generator { public: dictd_generator() { set_format("dictd"); set_version("dictd_generator, version 0.1"); } ~dictd_generator() { for (vector::const_iterator p=keys_list.begin(); p!=keys_list.end(); ++p) delete [] p->val; for (vector::const_iterator p=coord_list.begin(); p!=coord_list.end(); ++p) delete [] *p; } protected: struct dictd_key { char *val; char *coord; dictd_key(char *v, char *c) : val(v), coord(c) {} }; struct dictd_less { bool operator()(const dictd_key& lh, const dictd_key& rh) { return strcmp(lh.val, rh.val)<0; } }; vector keys_list; vector coord_list; string dict_file_name; std::ofstream dict_file; int generate(const string& basename, const string& workdir); void on_have_data(); void add_headword(const string& name, const string& val) { keys=std::list(1, name); data=val; on_have_data(); } }; int dictd_generator::generate(const string& basename, const string& workdir) { string dirname=workdir+G_DIR_SEPARATOR+basename; if (!make_directory(dirname)) return EXIT_FAILURE; string realbasename = dirname+G_DIR_SEPARATOR+basename; string file_name=realbasename+".index"; std::ofstream idx_file(file_name.c_str(), std::ios::binary|std::ios::out|std::ios::trunc); if (!idx_file) { cerr<<_("Can not open/create: ")<::const_iterator p=keys_list.begin(); p!=keys_list.end(); ++p) idx_file<val<coord<<'\n'; return EXIT_SUCCESS; } static inline char *new_string(const string& str) { char *ptr=new char [str.length()+1]; memcpy(ptr, str.c_str(), str.length()+1); return ptr; } void dictd_generator::on_have_data() { gulong off=dict_file.tellp(); gulong size=data.size(); if (!dict_file.write(&data[0], data.size())) { cerr<<_("Can not write to: ")<::iterator p=keys.begin(); p!=keys.end(); ++p) keys_list.push_back(dictd_key(new_string(*p), coord)); } int main(int argc, char *argv[]) { return dictd_generator().run(argc, argv); }