eliot-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Eliot-dev] eliot dic/dic.cpp dic/dic.h dic/dic_internals.h...


From: eliot-dev
Subject: [Eliot-dev] eliot dic/dic.cpp dic/dic.h dic/dic_internals.h...
Date: Sat, 22 Nov 2008 13:11:49 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>      08/11/22 13:11:48

Modified files:
        dic            : dic.cpp dic.h dic_internals.h dic_search.cpp 
                         grammar.cpp header.cpp listdic.cpp 
        qt             : main_window.cpp 

Log message:
        Removed support for the old dictionary format. The code becomes simpler 
and (very slightly) faster.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic.cpp?cvsroot=eliot&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic.h?cvsroot=eliot&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic_internals.h?cvsroot=eliot&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic_search.cpp?cvsroot=eliot&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/grammar.cpp?cvsroot=eliot&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/header.cpp?cvsroot=eliot&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/listdic.cpp?cvsroot=eliot&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.cpp?cvsroot=eliot&r1=1.15&r2=1.16

Patches:
Index: dic/dic.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/dic.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- dic/dic.cpp 22 Nov 2008 13:09:28 -0000      1.4
+++ dic/dic.cpp 22 Nov 2008 13:11:48 -0000      1.5
@@ -50,24 +50,6 @@
 const Dictionary *Dictionary::m_dic = NULL;
 
 
-// Note: duplicated in header.cpp
-#if defined(WORDS_BIGENDIAN)
-static uint32_t swap4(uint32_t v)
-{
-    uint32_t r;
-    uint8_t *pv = (uint8_t*)&v;
-    uint8_t *pr = (uint8_t*)&r;
-
-    pr[0] = pv[3];
-    pr[1] = pv[2];
-    pr[2] = pv[1];
-    pr[3] = pv[0];
-
-    return r;
-}
-#endif
-
-
 Dictionary::Dictionary(const string &iPath)
     : m_dawg(NULL)
 {
@@ -112,22 +94,10 @@
 
 void Dictionary::convertDataToArch()
 {
-    if (m_header->getVersion() == 0)
-    {
-#if defined(WORDS_BIGENDIAN)
-        for (unsigned int i = 0; i < (m_header->getNbEdgesUsed() + 1); i++)
-        {
-            m_dawg[i] = swap4(m_dawg[i]);
-        }
-#endif
-    }
-    else
-    {
         for (unsigned int i = 0; i < (m_header->getNbEdgesUsed() + 1); i++)
         {
             m_dawg[i] = ntohl(m_dawg[i]);
         }
-    }
 }
 
 
@@ -164,9 +134,6 @@
 
 dic_elt_t Dictionary::getSucc(const dic_elt_t &e) const
 {
-    if (m_header->getVersion() == 0)
-        return reinterpret_cast<const DicEdgeOld*>(m_dawg + e)->ptr;
-    else
         return reinterpret_cast<const DicEdge*>(m_dawg + e)->ptr;
 }
 
@@ -179,9 +146,6 @@
 
 dic_code_t Dictionary::getCode(const dic_elt_t &e) const
 {
-    if (m_header->getVersion() == 0)
-        return reinterpret_cast<const DicEdgeOld*>(m_dawg + e)->chr;
-    else
         return reinterpret_cast<const DicEdge*>(m_dawg + e)->chr;
 }
 
@@ -194,18 +158,12 @@
 
 bool Dictionary::isLast(const dic_elt_t &e) const
 {
-    if (m_header->getVersion() == 0)
-        return reinterpret_cast<const DicEdgeOld*>(m_dawg + e)->last;
-    else
         return reinterpret_cast<const DicEdge*>(m_dawg + e)->last;
 }
 
 
 bool Dictionary::isEndOfWord(const dic_elt_t &e) const
 {
-    if (m_header->getVersion() == 0)
-        return reinterpret_cast<const DicEdgeOld*>(m_dawg + e)->term;
-    else
         return reinterpret_cast<const DicEdge*>(m_dawg + e)->term;
 }
 

Index: dic/dic.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/dic.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- dic/dic.h   22 Nov 2008 13:09:28 -0000      1.20
+++ dic/dic.h   22 Nov 2008 13:11:48 -0000      1.21
@@ -42,6 +42,7 @@
 struct params_cross_t;
 struct params_7plus1_t;
 struct params_regexp_t;
+class DicEdge;
 
 class Dictionary
 {
@@ -162,7 +163,11 @@
     unsigned int charLookup(const dic_elt_t &iRoot, const wchar_t *iPattern) 
const;
 
     /// Getter for the edge at the given position
-    const uint32_t *getEdgeAt(const dic_elt_t &iElt) const { return m_dawg + 
iElt; }
+    const DicEdge * getEdgeAt(const dic_elt_t &iElt) const
+    {
+        return reinterpret_cast<const DicEdge*>(m_dawg + iElt);
+    }
+
 
     /**
      * Search for a word in the dictionary
@@ -245,54 +250,27 @@
     void convertDataToArch();
     void initializeTiles();
 
-    /// Template getter for the edge at the given position
-    template <typename DAWG_EDGE>
-    const DAWG_EDGE * getEdgeAt(const dic_elt_t &iElt) const
-    {
-        return reinterpret_cast<const DAWG_EDGE*>(m_dawg + iElt);
-    }
-
     /**
      * Walk the dictionary until the end of the word
      * @param s: current pointer to letters
      * @param eptr: current edge in the dawg
      */
-    template <typename DAWG_EDGE>
-    const DAWG_EDGE * seekEdgePtr(const wchar_t *s, const DAWG_EDGE *eptr) 
const;
-
-    /// Helper for searchBenj()
-    template <typename DAWG_EDGE>
-    void searchBenjTempl(const wstring &iWord, vector<wstring> &oWordList,
-                         unsigned int iMaxResults) const;
-
-    /// Helper for searchRacc()
-    template <typename DAWG_EDGE>
-    void searchRaccTempl(const wstring &iWord, vector<wstring> &oWordList,
-                         unsigned int iMaxResults) const;
+    const DicEdge * seekEdgePtr(const wchar_t *s, const DicEdge *eptr) const;
 
     /// Helper for searchCross()
-    template <typename DAWG_EDGE>
-    void searchCrossRecTempl(struct params_cross_t *params,
+    void searchCrossRec(struct params_cross_t *params,
                              vector<wstring> &oWordList,
-                             const DAWG_EDGE *edgeptr,
+                        const DicEdge *edgeptr,
                              unsigned int iMaxResults) const;
 
     /// Helper for search7pl1()
-    template <typename DAWG_EDGE>
-    void search7pl1Templ(const wstring &iRack,
-                         map<wchar_t, vector<wstring> > &oWordList,
-                         bool joker) const;
-
-    /// Second helper for search7pl1()
-    template <typename DAWG_EDGE>
     void searchWordByLen(struct params_7plus1_t *params,
-                         int i, const DAWG_EDGE *edgeptr) const;
+                         int i, const DicEdge *edgeptr) const;
 
     /// Helper for searchRegExp()
-    template <typename DAWG_EDGE>
-    void searchRegexpRecTempl(struct params_regexp_t *params,
+    void searchRegexpRec(struct params_regexp_t *params,
                               int state,
-                              const DAWG_EDGE *edgeptr,
+                         const DicEdge *edgeptr,
                               vector<wstring> &oWordList,
                               unsigned int iMaxResults) const;
 };

Index: dic/dic_internals.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/dic_internals.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- dic/dic_internals.h 22 Nov 2008 13:09:28 -0000      1.10
+++ dic/dic_internals.h 22 Nov 2008 13:11:48 -0000      1.11
@@ -38,22 +38,6 @@
  *  ----------------
  */
 
-struct __attribute__ ((packed)) DicEdgeOld
-{
-    public:
-      uint32_t
-        ptr : 24,
-        term:  1,
-        last:  1,
-        fill:  1,
-        chr :  5;
-      bool operator==(const DicEdgeOld &iOther) const
-      {
-          return memcmp(this, &iOther, sizeof(*this)) == 0;
-      }
-};
-
-
 struct __attribute__ ((packed)) DicEdge
 {
     public:

Index: dic/dic_search.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/dic_search.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- dic/dic_search.cpp  30 Oct 2008 19:03:07 -0000      1.12
+++ dic/dic_search.cpp  22 Nov 2008 13:11:48 -0000      1.13
@@ -37,18 +37,17 @@
 static const unsigned int DEFAULT_VECT_ALLOC = 100;
 
 
-template <typename DAWG_EDGE>
-const DAWG_EDGE* Dictionary::seekEdgePtr(const wchar_t* s, const DAWG_EDGE 
*eptr) const
+const DicEdge* Dictionary::seekEdgePtr(const wchar_t* s, const DicEdge *eptr) 
const
 {
     if (*s)
     {
-        const DAWG_EDGE *p = getEdgeAt<DAWG_EDGE>(eptr->ptr);
+        const DicEdge *p = getEdgeAt(eptr->ptr);
         do
         {
             if (p->chr == getHeader().getCodeFromChar(*s))
                 return seekEdgePtr(s + 1, p);
         } while (!(*p++).last);
-        return getEdgeAt<DAWG_EDGE>(0);
+        return getEdgeAt(0);
     }
     else
         return eptr;
@@ -60,18 +59,8 @@
     if (!validateLetters(iWord))
         return false;
 
-    if (getHeader().getVersion() == 0)
-    {
-        const DicEdgeOld *e =
-            seekEdgePtr(iWord.c_str(), getEdgeAt<DicEdgeOld>(getRoot()));
-        return e->term;
-    }
-    else
-    {
-        const DicEdge *e =
-            seekEdgePtr(iWord.c_str(), getEdgeAt<DicEdge>(getRoot()));
+    const DicEdge *e = seekEdgePtr(iWord.c_str(), getEdgeAt(getRoot()));
         return e->term;
-    }
 }
 
 
@@ -93,9 +82,8 @@
     char search_letters[63];
 };
 
-template <typename DAWG_EDGE>
 void Dictionary::searchWordByLen(struct params_7plus1_t *params,
-                                 int i, const DAWG_EDGE *edgeptr) const
+                                 int i, const DicEdge *edgeptr) const
 {
     /* depth first search in the dictionary */
     do
@@ -120,7 +108,7 @@
                 }
                 else
                 {
-                    searchWordByLen(params, i + 1, 
getEdgeAt<DAWG_EDGE>(edgeptr->ptr));
+                    searchWordByLen(params, i + 1, getEdgeAt(edgeptr->ptr));
                 }
                 params->search_letters[edgeptr->chr] ++;
                 params->search_wordtst[i] = L'\0';
@@ -143,7 +131,7 @@
                 }
                 else
                 {
-                    searchWordByLen(params, i + 1, 
getEdgeAt<DAWG_EDGE>(edgeptr->ptr));
+                    searchWordByLen(params, i + 1, getEdgeAt(edgeptr->ptr));
                 }
                 params->search_letters[0] ++;
                 params->search_wordtst[i] = L'\0';
@@ -153,8 +141,7 @@
 }
 
 
-template <typename DAWG_EDGE>
-void Dictionary::search7pl1Templ(const wstring &iRack,
+void Dictionary::search7pl1(const wstring &iRack,
                                  map<wchar_t, vector<wstring> > &oWordList,
                                  bool joker) const
 {
@@ -196,8 +183,8 @@
     if (wordlen < 1)
         return;
 
-    const DAWG_EDGE *root_edge = getEdgeAt<DAWG_EDGE>(getRoot());
-    root_edge = getEdgeAt<DAWG_EDGE>(root_edge->ptr);
+    const DicEdge *root_edge = getEdgeAt(getRoot());
+    root_edge = getEdgeAt(root_edge->ptr);
 
     params.results = &oWordList;
 
@@ -223,22 +210,11 @@
     }
 }
 
-
-void Dictionary::search7pl1(const wstring &iRack,
-                            map<wchar_t, vector<wstring> > &oWordList,
-                            bool joker) const
-{
-    if (getHeader().getVersion() == 0)
-        search7pl1Templ<DicEdgeOld>(iRack, oWordList, joker);
-    else
-        search7pl1Templ<DicEdge>(iRack, oWordList, joker);
-}
-
 /****************************************/
 /****************************************/
 
-template <typename DAWG_EDGE>
-void Dictionary::searchRaccTempl(const wstring &iWord, vector<wstring> 
&oWordList,
+void Dictionary::searchRacc(const wstring &iWord,
+                            vector<wstring> &oWordList,
                                  unsigned int iMaxResults) const
 {
     if (iWord == L"")
@@ -271,13 +247,13 @@
     wordtst[i  ] = '\0';
     wordtst[i+1] = '\0';
 
-    const DAWG_EDGE *edge_seek =
-        seekEdgePtr(iWord.c_str(), getEdgeAt<DAWG_EDGE>(getRoot()));
+    const DicEdge *edge_seek =
+        seekEdgePtr(iWord.c_str(), getEdgeAt(getRoot()));
 
     /* points to what the next letter can be */
-    const DAWG_EDGE *edge = getEdgeAt<DAWG_EDGE>(edge_seek->ptr);
+    const DicEdge *edge = getEdgeAt(edge_seek->ptr);
 
-    if (edge != getEdgeAt<DAWG_EDGE>(0))
+    if (edge != getEdgeAt(0))
     {
         do
         {
@@ -292,20 +268,10 @@
     }
 }
 
-
-void Dictionary::searchRacc(const wstring &iWord, vector<wstring> &oWordList, 
unsigned int iMaxResults) const
-{
-    if (getHeader().getVersion() == 0)
-        searchRaccTempl<DicEdgeOld>(iWord, oWordList, iMaxResults);
-    else
-        searchRaccTempl<DicEdge>(iWord, oWordList, iMaxResults);
-}
-
 /****************************************/
 /****************************************/
 
-template <typename DAWG_EDGE>
-void Dictionary::searchBenjTempl(const wstring &iWord, vector<wstring> 
&oWordList,
+void Dictionary::searchBenj(const wstring &iWord, vector<wstring> &oWordList,
                                  unsigned int iMaxResults) const
 {
     if (iWord == L"")
@@ -319,17 +285,17 @@
 
     wchar_t wordtst[DIC_WORD_MAX];
     wcscpy(wordtst + 3, iWord.c_str());
-    const DAWG_EDGE *edge0, *edge1, *edge2, *edgetst;
-    edge0 = getEdgeAt<DAWG_EDGE>(getRoot());
-    edge0 = getEdgeAt<DAWG_EDGE>(edge0->ptr);
+    const DicEdge *edge0, *edge1, *edge2, *edgetst;
+    edge0 = getEdgeAt(getRoot());
+    edge0 = getEdgeAt(edge0->ptr);
     do
     {
         wordtst[0] = getHeader().getCharFromCode(edge0->chr);
-        edge1 = getEdgeAt<DAWG_EDGE>(edge0->ptr);
+        edge1 = getEdgeAt(edge0->ptr);
         do
         {
             wordtst[1] = getHeader().getCharFromCode(edge1->chr);
-            edge2 = getEdgeAt<DAWG_EDGE>(edge1->ptr);
+            edge2 = getEdgeAt(edge1->ptr);
             do
             {
                 edgetst = seekEdgePtr(iWord.c_str(), edge2);
@@ -345,16 +311,6 @@
     } while (!(*edge0++).last);
 }
 
-
-void Dictionary::searchBenj(const wstring &iWord, vector<wstring> &oWordList,
-                            unsigned int iMaxResults) const
-{
-    if (getHeader().getVersion() == 0)
-        searchBenjTempl<DicEdgeOld>(iWord, oWordList, iMaxResults);
-    else
-        searchBenjTempl<DicEdge>(iWord, oWordList, iMaxResults);
-}
-
 /****************************************/
 /****************************************/
 
@@ -365,16 +321,15 @@
 };
 
 
-template <typename DAWG_EDGE>
-void Dictionary::searchCrossRecTempl(struct params_cross_t *params,
+void Dictionary::searchCrossRec(struct params_cross_t *params,
                                      vector<wstring> &oWordList,
-                                     const DAWG_EDGE *edgeptr,
+                                const DicEdge *edgeptr,
                                      unsigned int iMaxResults) const
 {
     if (iMaxResults && oWordList.size() >= iMaxResults)
         return;
 
-    const DAWG_EDGE *current = getEdgeAt<DAWG_EDGE>(edgeptr->ptr);
+    const DicEdge *current = getEdgeAt(edgeptr->ptr);
 
     if (params->mask[params->wordlen] == '\0')
     {
@@ -392,7 +347,7 @@
         {
             params->mask[params->wordlen] = 
getHeader().getCharFromCode(current->chr);
             params->wordlen ++;
-            searchCrossRecTempl(params, oWordList, current, iMaxResults);
+            searchCrossRec(params, oWordList, current, iMaxResults);
             params->wordlen --;
             params->mask[params->wordlen] = '.';
         }
@@ -405,7 +360,7 @@
             if (current->chr == 
getHeader().getCodeFromChar(params->mask[params->wordlen]))
             {
                 params->wordlen ++;
-                searchCrossRecTempl(params, oWordList, current, iMaxResults);
+                searchCrossRec(params, oWordList, current, iMaxResults);
                 params->wordlen --;
                 break;
             }
@@ -440,16 +395,7 @@
     params.mask[i] = '\0';
 
     params.wordlen = 0;
-    if (getHeader().getVersion() == 0)
-    {
-        searchCrossRecTempl(&params, oWordList,
-                            getEdgeAt<DicEdgeOld>(getRoot()), iMaxResults);
-    }
-    else
-    {
-        searchCrossRecTempl(&params, oWordList,
-                            getEdgeAt<DicEdge>(getRoot()), iMaxResults);
-    }
+    searchCrossRec(&params, oWordList, getEdgeAt(getRoot()), iMaxResults);
 }
 
 /****************************************/
@@ -465,10 +411,9 @@
 };
 
 
-template <typename DAWG_EDGE>
-void Dictionary::searchRegexpRecTempl(struct params_regexp_t *params,
+void Dictionary::searchRegexpRec(struct params_regexp_t *params,
                                       int state,
-                                      const DAWG_EDGE *edgeptr,
+                                 const DicEdge *edgeptr,
                                       vector<wstring> &oWordList,
                                       unsigned int iMaxResults) const
 {
@@ -487,7 +432,7 @@
         }
     }
     /* we now drive the search by exploring the dictionary */
-    const DAWG_EDGE *current = getEdgeAt<DAWG_EDGE>(edgeptr->ptr);
+    const DicEdge *current = getEdgeAt(edgeptr->ptr);
     do
     {
         /* the current letter is current->chr */
@@ -498,7 +443,7 @@
             params->word[params->wordlen] =
                 getHeader().getCharFromCode(current->chr);
             params->wordlen ++;
-            searchRegexpRecTempl(params, next_state, current, oWordList, 
iMaxResults);
+            searchRegexpRec(params, next_state, current, oWordList, 
iMaxResults);
             params->wordlen --;
             params->word[params->wordlen] = L'\0';
         }
@@ -599,19 +544,9 @@
         params.automaton_field = a;
         memset(params.word, L'\0', sizeof(params.word));
         params.wordlen = 0;
-        if (getHeader().getVersion() == 0)
-        {
-            searchRegexpRecTempl(&params, a->getInitId(),
-                                 getEdgeAt<DicEdgeOld>(getRoot()), oWordList,
-                                 iMaxResults ? iMaxResults + 1 : 0);
-        }
-        else
-        {
-            searchRegexpRecTempl(&params, a->getInitId(),
-                                 getEdgeAt<DicEdge>(getRoot()), oWordList,
+        searchRegexpRec(&params, a->getInitId(),
+                        getEdgeAt(getRoot()), oWordList,
                                  iMaxResults ? iMaxResults + 1 : 0);
-        }
-
         delete a;
     }
     delete root;

Index: dic/grammar.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/grammar.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- dic/grammar.cpp     3 Sep 2008 17:28:27 -0000       1.5
+++ dic/grammar.cpp     22 Nov 2008 13:11:48 -0000      1.6
@@ -36,9 +36,6 @@
 using namespace boost::spirit;
 using namespace std;
 
-// TODO:
-// - error handling
-
 // A few typedefs to simplify things
 typedef const wchar_t *iterator_t;
 typedef tree_match<iterator_t> parse_tree_match_t;

Index: dic/header.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/header.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- dic/header.cpp      20 Jul 2008 12:15:52 -0000      1.3
+++ dic/header.cpp      22 Nov 2008 13:11:48 -0000      1.4
@@ -285,81 +285,27 @@
 
     m_version = aHeader.version;
 
-    // Handle endianness
+    // Version 0 corresponds to the dictionary format in the first Eliot
+    // versions, supported until Eliot 1.8 (excluded).
+    // The new version (version 1) was introduced in Eliot 1.6.
     if (m_version == 0)
     {
-#if defined(WORDS_BIGENDIAN)
-        aHeader.root       = swap4(aHeader.root);
-        aHeader.nwords     = swap4(aHeader.nwords);
-        aHeader.nodesused  = swap4(aHeader.nodesused);
-        aHeader.edgesused  = swap4(aHeader.edgesused);
-        aHeader.nodessaved = swap4(aHeader.nodessaved);
-        aHeader.edgessaved = swap4(aHeader.edgessaved);
-#endif
-        m_root = aHeader.root;
-        m_nbWords = aHeader.nwords;
-        m_nodesUsed = aHeader.nodesused;
-        m_edgesUsed = aHeader.edgesused;
-        m_nodesSaved = aHeader.nodessaved;
-        m_edgesSaved = aHeader.edgessaved;
+        throw DicException(_("Too old dictionary format. This format is not "
+                             "supported anymore since Eliot 1.8. You can "
+                             "create dictionaries in the new format with the "
+                             "'compdic' tool provided with Eliot (since "
+                             "version 1.6)."));
     }
-    else
-    {
+
+    // Handle endianness
         m_root = ntohl(aHeader.root);
         m_nbWords = ntohl(aHeader.nwords);
         m_nodesUsed = ntohl(aHeader.nodesused);
         m_edgesUsed = ntohl(aHeader.edgesused);
         m_nodesSaved = ntohl(aHeader.nodessaved);
         m_edgesSaved = ntohl(aHeader.edgessaved);
-    }
-
-    if (m_version == 0)
-    {
-        m_compressDate = 0;
-        m_userHost = convertToWc(_("Unknown (old format)"));
-        m_dicName = convertToWc(_("Unknown (old format)"));
 
-        // In version 0, the letters, points, frequency,
-        // vowels and consonants were hard-coded...
-        m_letters = convertToWc("ABCDEFGHIJKLMNOPQRSTUVWXYZ?");
-
-        static const uint8_t Frenchpoints[] =
-        {
-            // A B C D  E F G H I J  K L M N O P Q R S T U V  W  X  Y  Z ?
-               1,3,3,2, 1,4,2,4,1,8,10,1,2,1,1,3,8,1,1,1,1,4,10,10,10,10,0
-        };
-
-        static const uint8_t FrenchFrequency[] =
-        {
-            // A B C D  E F G H I J  K L M N O P Q R S T U V  W  X  Y  Z ?
-               9,2,2,3,15,2,2,2,8,1, 1,5,3,6,6,2,1,6,6,6,6,2, 1, 1, 1, 1,2
-        };
-
-        // The jokers and the 'Y' can be considered both as vowels or 
consonants
-        static const uint8_t FrenchVowels[] =
-        {
-            // A B C D  E F G H I J  K L M N O P Q R S T U V  W  X  Y  Z ?
-               1,0,0,0, 1,0,0,0,1,0, 0,0,0,0,1,0,0,0,0,0,1,0, 0, 0, 1, 0,1
-        };
-
-        static const uint8_t FrenchConsonants[] =
-        {
-            // A B C D  E F G H I J  K L M N O P Q R S T U V  W  X  Y  Z ?
-               0,1,1,1, 0,1,1,1,0,1, 1,1,1,1,0,1,1,1,1,1,0,1, 1, 1, 1, 1,1
-        };
-
-        for (unsigned int i = 0; i < m_letters.size(); ++i)
-        {
-            m_points.push_back(Frenchpoints[i]);
-            m_frequency.push_back(FrenchFrequency[i]);
-            m_vowels.push_back(FrenchVowels[i]);
-            m_consonants.push_back(FrenchConsonants[i]);
-        }
-    }
-    else
-    {
-        // This header doesn't use the old serialization format, so read the
-        // extension as well
+    // After reading the old header, we now read the extension
         Dict_header_ext aHeaderExt;
         iStream.read((char*)&aHeaderExt, sizeof(Dict_header_ext));
         if (iStream.gcount() != sizeof(Dict_header_ext))
@@ -412,8 +358,6 @@
             m_vowels.push_back(aHeaderExt.vowels & (1 << i));
             m_consonants.push_back(aHeaderExt.consonants & (1 << i));
         }
-
-    }
 }
 
 
@@ -434,8 +378,6 @@
     if (!oStream.good())
         throw DicException("Header::write: error when writing to file");
 
-    if (m_version != 0)
-    {
         Dict_header_ext aHeaderExt;
         aHeaderExt.compressDate = m_compressDate;
         aHeaderExt.userHostSize =
@@ -485,30 +427,21 @@
         oStream.write((char*)&aHeaderExt, sizeof(Dict_header_ext));
         if (!oStream.good())
             throw DicException("Header::write: error when writing to file");
-    }
 }
 
 
 void Header::print() const
 {
     printf(_("dictionary name: %s\n"), convertToMb(m_dicName).c_str());
-    if (m_version)
-    {
         char buf[50];
         strftime(buf, sizeof(buf), "%c", gmtime(&m_compressDate));
         printf(_("compressed on: %s\n"), buf);
-    }
-    else
-    {
-        printf(_("compressed on: Unknown date (old format)\n"));
-    }
     printf(_("compressed using a binary compiled by: %s\n"), 
convertToMb(m_userHost).c_str());
     printf(_("dictionary type: %s\n"), m_type == kDAWG ? "DAWG" : "GADDAG");
     printf(_("letters: %s\n"), convertToMb(m_letters).c_str());
     printf(_("number of letters: %lu\n"), (long unsigned int)m_letters.size());
     printf(_("number of words: %d\n"), m_nbWords);
-    long unsigned int size =
-        sizeof(Dict_header_old) + (m_version ? sizeof(Dict_header_ext) : 0);
+    long unsigned int size = sizeof(Dict_header_old) + sizeof(Dict_header_ext);
     printf(_("header size: %lu bytes\n"), size);
     printf(_("root: %d (edge)\n"), m_root);
     printf(_("nodes: %d used + %d saved\n"), m_nodesUsed, m_nodesSaved);

Index: dic/listdic.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/listdic.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- dic/listdic.cpp     22 Nov 2008 13:09:28 -0000      1.5
+++ dic/listdic.cpp     22 Nov 2008 13:11:48 -0000      1.6
@@ -46,8 +46,7 @@
 using namespace std;
 
 
-template <typename DAWG_EDGE>
-static void print_dic_rec(ostream &out, const Dictionary &iDic, wchar_t *buf, 
wchar_t *s, DAWG_EDGE i)
+static void print_dic_rec(ostream &out, const Dictionary &iDic, wchar_t *buf, 
wchar_t *s, DicEdge i)
 {
     if (i.term)  /* edge points at a complete word */
     {
@@ -56,7 +55,7 @@
     }
     if (i.ptr)
     {           /* Compute index: is it non-zero ? */
-        const DAWG_EDGE *p = reinterpret_cast<const 
DAWG_EDGE*>(iDic.getEdgeAt(i.ptr));
+        const DicEdge *p = iDic.getEdgeAt(i.ptr);
         do
         {                         /* for each edge out of this node */
             *s = iDic.getHeader().getCharFromCode(p->chr);
@@ -67,24 +66,22 @@
 }
 
 
-template <typename DAWG_EDGE>
 void print_dic_list(const Dictionary &iDic)
 {
     static wchar_t buf[80];
-    print_dic_rec(cout, iDic, buf, buf, *reinterpret_cast<const 
DAWG_EDGE*>(iDic.getEdgeAt(iDic.getRoot())));
+    print_dic_rec(cout, iDic, buf, buf, *iDic.getEdgeAt(iDic.getRoot()));
 }
 
 
-template <typename DAWG_EDGE>
 static void print_node_hex(const Dictionary &dic, int i)
 {
     union edge_t
     {
-        DAWG_EDGE e;
+        DicEdge e;
         uint32_t  s;
     } ee;
 
-    ee.e = *reinterpret_cast<const DAWG_EDGE*>(dic.getEdgeAt(i));
+    ee.e = *reinterpret_cast<const DicEdge*>(dic.getEdgeAt(i));
 
     printf("0x%04lx %08x |%4d ptr=%8d t=%d l=%d chr=%2d (%c)\n",
            (unsigned long)i*sizeof(ee), (unsigned int)(ee.s),
@@ -92,13 +89,12 @@
 }
 
 
-template <typename DAWG_EDGE>
 void print_dic_hex(const Dictionary &iDic)
 {
     printf(_("offset binary   | structure\n"));
     printf("------ -------- | --------------------\n");
     for (unsigned int i = 0; i < (iDic.getHeader().getNbEdgesUsed() + 1); i++)
-        print_node_hex<DAWG_EDGE>(iDic, i);
+        print_node_hex(iDic, i);
 }
 
 
@@ -172,17 +168,11 @@
         }
         if (option_print_dic_hex || option_print_all)
         {
-            if (dic.getHeader().getVersion() == 0)
-                print_dic_hex<DicEdgeOld>(dic);
-            else
-                print_dic_hex<DicEdge>(dic);
+            print_dic_hex(dic);
         }
         if (option_print_dic_list || option_print_all)
         {
-            if (dic.getHeader().getVersion() == 0)
-                print_dic_list<DicEdgeOld>(dic);
-            else
-                print_dic_list<DicEdge>(dic);
+            print_dic_list(dic);
         }
         return 0;
     }

Index: qt/main_window.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- qt/main_window.cpp  4 Nov 2008 21:31:14 -0000       1.15
+++ qt/main_window.cpp  22 Nov 2008 13:11:48 -0000      1.16
@@ -230,22 +230,10 @@
     if (iDic == NULL)
         m_dicNameLabel->setText("No dictionary");
     else {
-        if (iDic->getHeader().getVersion() != 0)
-        {
             QString dicName = qfw(m_dic->getHeader().getName());
             m_dicNameLabel->setText(_q("Dictionary: %1").arg(dicName));
             m_dicNameLabel->setToolTip("");
         }
-        else
-        {
-            m_dicNameLabel->setText(_q("Dictionary: Unknown (old format)"));
-            QString warning = _q("The dictionary name cannot be "
-                    "retrieved, because you are using an old dictionary 
format.\n"
-                    "You can probably download a newer version of the 
dictionary "
-                    "on http://www.nongnu.org/eliot/";);
-            m_dicNameLabel->setToolTip(warning);
-        }
-    }
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]