>>>>> On 2005-10-18 19:05 PDT, Kevin Atkinson writes: Karl> Would it be possible to output the personal dictionary Karl> sorted, if so specified by a configuration option? Also Karl> I would like to be able write "0" as the size hint, to Karl> be able to merge the dictionary from multiple places Karl> without conflicts.
Kevin> I will consider a patch but only if it is made optional Kevin> at run-time via a configure option. Attached is a patch. Would you please consider it? Thanks.
Index: common/config.cpp =================================================================== RCS file: /cvsroot/aspell/aspell/common/config.cpp,v retrieving revision 1.77 diff -u -b -w -r1.77 config.cpp --- common/config.cpp 3 May 2005 05:08:19 -0000 1.77 +++ common/config.cpp 20 Oct 2005 01:33:05 -0000 @@ -1477,6 +1477,10 @@ , {"personal", KeyInfoString, PERSONAL, N_("personal dictionary file name")} , {"personal-path", KeyInfoString, "<home-dir/personal>", 0} + , {"personal-no-hint", KeyInfoBool, "false", + N_("don't write size hint to personal dictionary when saving")} + , {"personal-sort", KeyInfoBool, "false", + N_("sort personal dictionary when saving")} , {"prefix", KeyInfoString, PREFIX, N_("prefix directory")} , {"repl", KeyInfoString, REPL, Index: common/hash.hpp =================================================================== RCS file: /cvsroot/aspell/aspell/common/hash.hpp,v retrieving revision 1.8 diff -u -b -w -r1.8 hash.hpp --- common/hash.hpp 3 May 2005 05:08:19 -0000 1.8 +++ common/hash.hpp 20 Oct 2005 01:33:05 -0000 @@ -47,6 +47,11 @@ template <class Value> class HT_Iterator { public: // but don't use + typedef std::input_iterator_tag iterator_category; + typedef Value value_type; + typedef ptrdiff_t difference_type; + typedef Value* pointer; + typedef Value& reference; typedef typename BlockSList<Value>::Node Node; Node * * t; Node * * n; Index: modules/speller/default/writable.cpp =================================================================== RCS file: /cvsroot/aspell/aspell/modules/speller/default/writable.cpp,v retrieving revision 1.30 diff -u -b -w -r1.30 writable.cpp --- modules/speller/default/writable.cpp 3 May 2005 05:08:19 -0000 1.30 +++ modules/speller/default/writable.cpp 20 Oct 2005 01:33:05 -0000 @@ -99,6 +99,7 @@ WritableBase(BasicType t, const char * n, const char * s, const char * cs) : Dictionary(t,n), suffix(s), compatibility_suffix(cs), + personal_no_hint(false), personal_sort(false), use_soundslike(true) {fast_lookup = true;} virtual ~WritableBase() {} @@ -121,6 +122,12 @@ PosibErr<void> synchronize() {return save(true);} PosibErr<void> save_noupdate() {return save(false);} + template <typename InputIterator> + void save_words(FStream&, InputIterator, InputIterator); + + bool personal_no_hint; + bool personal_sort; + bool use_soundslike; ObjStack buffer; @@ -139,6 +146,9 @@ const String f = file_name(); FStream in; + personal_no_hint = config.retrieve_bool("personal-no-hint"); + personal_sort = config.retrieve_bool("personal-sort"); + if (file_exists(f)) { RET_ON_ERR(open_file_readlock(in, f)); @@ -607,19 +617,40 @@ return no_err; } -PosibErr<void> WritableDict::save(FStream & out, ParmString file_name) +template <typename InputIterator> +inline void WritableBase::save_words(FStream& out, InputIterator i, InputIterator e) { - out.printf("personal_ws-1.1 %s %i %s\n", - lang_name(), word_lookup->size(), file_encoding.c_str()); - - WordLookup::const_iterator i = word_lookup->begin(); - WordLookup::const_iterator e = word_lookup->end(); - ConvP conv(oconv); for (;i != e; ++i) { const char *w = (*i)->word_; out.printf("%s\n", conv(w)); } +} + +// return true if r1 < r2 +inline bool compare_WordRec(WordRec const* r1, WordRec const* r2) +{ + return strcmp(r1->key(), r2->key()) < 0; +} + +PosibErr<void> WritableDict::save(FStream & out, ParmString file_name) +{ + int size = personal_no_hint ? 0 : word_lookup->size(); + + out.printf("personal_ws-1.1 %s %i %s\n", + lang_name(), size, file_encoding.c_str()); + + if (personal_sort) { + // WordVec sorted_words(word_lookup->begin(), word_lookup->end()); + // WordVec doesn't support the iterator copy constructor + WordVec sorted_words; + sorted_words.assign(word_lookup->begin(), word_lookup->end()); + std::sort(sorted_words.begin(), sorted_words.end(), compare_WordRec); + save_words(out, sorted_words.begin(), sorted_words.end()); + } else { + save_words(out, word_lookup->begin(), word_lookup->end()); + } + return no_err; }
-- Karl 2005-10-19 18:33
_______________________________________________ Aspell-devel mailing list Aspell-devel@gnu.org http://lists.gnu.org/mailman/listinfo/aspell-devel