[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Eliot-dev] eliot configure.in dic/dic.h dic/dic_search.cpp... [cppdic]
From: |
eliot-dev |
Subject: |
[Eliot-dev] eliot configure.in dic/dic.h dic/dic_search.cpp... [cppdic] |
Date: |
Tue, 04 Dec 2007 11:10:00 +0000 |
CVSROOT: /cvsroot/eliot
Module name: eliot
Branch: cppdic
Changes by: Olivier Teulière <ipkiss> 07/12/04 11:10:00
Modified files:
. : configure.in
dic : dic.h dic_search.cpp encoding.cpp encoding.h
header.cpp header.h listdic.cpp
game : bag.cpp game_io.cpp
utils : game_io.cpp ncurses.cpp
Log message:
- Used the compression date and compilation information
(address@hidden) in the dictionary header
- Improved encapsulation of Dawg_edge (very slightly)
- New padAndConvert() utility function to handle display width of
multibyte characters
- Various fixes for multibyte characters handling
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/configure.in?cvsroot=eliot&only_with_tag=cppdic&r1=1.19.2.7&r2=1.19.2.8
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.13.2.6&r2=1.13.2.7
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic_search.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.1.2.4&r2=1.1.2.5
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/encoding.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.1.2.4&r2=1.1.2.5
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/encoding.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.1.2.2&r2=1.1.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/header.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.1.2.11&r2=1.1.2.12
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/header.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.1.2.7&r2=1.1.2.8
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/listdic.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.1.2.7&r2=1.1.2.8
http://cvs.savannah.gnu.org/viewcvs/eliot/game/bag.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.7.2.2&r2=1.7.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game_io.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.4.2.1&r2=1.4.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/utils/game_io.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.9.2.3&r2=1.9.2.4
http://cvs.savannah.gnu.org/viewcvs/eliot/utils/ncurses.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.22.2.2&r2=1.22.2.3
Patches:
Index: configure.in
===================================================================
RCS file: /cvsroot/eliot/eliot/configure.in,v
retrieving revision 1.19.2.7
retrieving revision 1.19.2.8
diff -u -b -r1.19.2.7 -r1.19.2.8
--- configure.in 3 Dec 2007 17:27:32 -0000 1.19.2.7
+++ configure.in 4 Dec 2007 11:09:58 -0000 1.19.2.8
@@ -161,7 +161,6 @@
dnl Information about who built eliot (useful for the dictionary)
AC_DEFINE_UNQUOTED(ELIOT_COMPILE_BY, "`whoami`", [user who ran configure])
AC_DEFINE_UNQUOTED(ELIOT_COMPILE_HOST, "`hostname`", [host which ran
configure])
-AC_DEFINE_UNQUOTED(ELIOT_COMPILE_DOMAIN, "`dnsdomainname 2>/dev/null ||
domainname 2>/dev/null || echo unknown`", [domain of the host which ran
configure])
dnl Check the operating system
case "${host_os}" in
Index: dic/dic.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/dic.h,v
retrieving revision 1.13.2.6
retrieving revision 1.13.2.7
diff -u -b -r1.13.2.6 -r1.13.2.7
--- dic/dic.h 3 Dec 2007 17:27:33 -0000 1.13.2.6
+++ dic/dic.h 4 Dec 2007 11:09:59 -0000 1.13.2.7
@@ -133,8 +133,8 @@
*/
unsigned int charLookup(const dic_elt_t &iRoot, const wchar_t *iPattern)
const;
- /// Getter for the dawg
- const uint32_t *getDawg() const { return m_dawg; }
+ /// Getter for the edge at the given position
+ const uint32_t *getEdgeAt(const dic_elt_t &iElt) const { return m_dawg +
iElt; }
private:
// Prevent from copying the dictionary!
Index: dic/dic_search.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Attic/dic_search.cpp,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -b -r1.1.2.4 -r1.1.2.5
--- dic/dic_search.cpp 3 Dec 2007 17:27:33 -0000 1.1.2.4
+++ dic/dic_search.cpp 4 Dec 2007 11:09:59 -0000 1.1.2.5
@@ -60,13 +60,13 @@
{
if (*s)
{
- const DAWG_EDGE *p = reinterpret_cast<const DAWG_EDGE*>(iDic.getDawg()
+ eptr->ptr);
+ const DAWG_EDGE *p = reinterpret_cast<const
DAWG_EDGE*>(iDic.getEdgeAt(eptr->ptr));
do
{
if (p->chr == iDic.getHeader().getCodeFromChar(*s))
return Dic_seek_edgeptr(iDic, s + 1, p);
} while (!(*p++).last);
- return reinterpret_cast<const DAWG_EDGE*>(iDic.getDawg());
+ return reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(0));
}
else
return eptr;
@@ -83,7 +83,7 @@
static int searchWordTempl(const Dictionary &iDic, const wstring &iWord)
{
const DAWG_EDGE *e =
- Dic_seek_edgeptr(iDic, iWord.c_str(), reinterpret_cast<const
DAWG_EDGE*>(iDic.getDawg() + iDic.getRoot()));
+ Dic_seek_edgeptr(iDic, iWord.c_str(), reinterpret_cast<const
DAWG_EDGE*>(iDic.getEdgeAt(iDic.getRoot())));
return e->term;
}
@@ -144,7 +144,7 @@
else
{
Dic_search_word_by_len(iDic, params, i + 1,
- reinterpret_cast<const
DAWG_EDGE*>(iDic.getDawg() + edgeptr->ptr));
+ reinterpret_cast<const
DAWG_EDGE*>(iDic.getEdgeAt(edgeptr->ptr)));
}
params->search_letters[edgeptr->chr] ++;
params->search_wordtst[i] = L'\0';
@@ -165,7 +165,7 @@
else
{
Dic_search_word_by_len(iDic, params, i + 1,
- reinterpret_cast<const
DAWG_EDGE*>(iDic.getDawg() + edgeptr->ptr));
+ reinterpret_cast<const
DAWG_EDGE*>(iDic.getEdgeAt(edgeptr->ptr)));
}
params->search_letters[0] ++;
params->search_wordtst[i] = L'\0';
@@ -219,8 +219,9 @@
return;
const DAWG_EDGE *root_edge =
- reinterpret_cast<const DAWG_EDGE*>(iDic.getDawg() +
- reinterpret_cast<const
DAWG_EDGE*>(iDic.getDawg() + iDic.getRoot())->ptr);
+ reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(iDic.getRoot()));
+ root_edge =
+ reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(root_edge->ptr));
params.results = &oWordList;
@@ -293,12 +294,12 @@
wordtst[i+1] = '\0';
const DAWG_EDGE *edge_seek = Dic_seek_edgeptr(iDic, iWord.c_str(),
- reinterpret_cast<const
DAWG_EDGE*>(iDic.getDawg() + iDic.getRoot()));
+ reinterpret_cast<const
DAWG_EDGE*>(iDic.getEdgeAt(iDic.getRoot())));
/* points to what the next letter can be */
- const DAWG_EDGE *edge = reinterpret_cast<const DAWG_EDGE*>(iDic.getDawg()
+ edge_seek->ptr);
+ const DAWG_EDGE *edge = reinterpret_cast<const
DAWG_EDGE*>(iDic.getEdgeAt(edge_seek->ptr));
- if (edge != reinterpret_cast<const DAWG_EDGE*>(iDic.getDawg()))
+ if (edge != reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(0)))
{
do
{
@@ -338,16 +339,16 @@
wchar_t wordtst[DIC_WORD_MAX];
wcscpy(wordtst + 3, iWord.c_str());
const DAWG_EDGE *edge0, *edge1, *edge2, *edgetst;
- edge0 = reinterpret_cast<const DAWG_EDGE*>(iDic.getDawg() +
- reinterpret_cast<const
DAWG_EDGE*>(iDic.getDawg() + iDic.getRoot())->ptr);
+ edge0 = reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(iDic.getRoot()));
+ edge0 = reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(edge0->ptr));
do
{
wordtst[0] = iDic.getHeader().getCharFromCode(edge0->chr);
- edge1 = reinterpret_cast<const DAWG_EDGE*>(iDic.getDawg() +
edge0->ptr);
+ edge1 = reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(edge0->ptr));
do
{
wordtst[1] = iDic.getHeader().getCharFromCode(edge1->chr);
- edge2 = reinterpret_cast<const DAWG_EDGE*>(iDic.getDawg() +
edge1->ptr);
+ edge2 = reinterpret_cast<const
DAWG_EDGE*>(iDic.getEdgeAt(edge1->ptr));
do
{
wordtst[2] = iDic.getHeader().getCharFromCode(edge2->chr);
@@ -389,7 +390,7 @@
list<wstring> &oWordList,
const DAWG_EDGE *edgeptr)
{
- const DAWG_EDGE *current = reinterpret_cast<const
DAWG_EDGE*>(iDic.getDawg() + edgeptr->ptr);
+ const DAWG_EDGE *current = reinterpret_cast<const
DAWG_EDGE*>(iDic.getEdgeAt(edgeptr->ptr));
if (params->mask[params->wordlen] == '\0' && edgeptr->term)
{
@@ -446,12 +447,12 @@
if (iDic.getHeader().getVersion() == 0)
{
Dic_search_cross_rec(iDic, ¶ms, oWordList,
- reinterpret_cast<const
Dawg_edge_old*>(iDic.getDawg() + iDic.getRoot()));
+ reinterpret_cast<const
Dawg_edge_old*>(iDic.getEdgeAt(iDic.getRoot())));
}
else
{
Dic_search_cross_rec(iDic, ¶ms, oWordList,
- reinterpret_cast<const Dawg_edge*>(iDic.getDawg()
+ iDic.getRoot()));
+ reinterpret_cast<const
Dawg_edge*>(iDic.getEdgeAt(iDic.getRoot())));
}
}
@@ -488,7 +489,7 @@
}
}
/* we now drive the search by exploring the dictionary */
- const DAWG_EDGE *current = reinterpret_cast<const
DAWG_EDGE*>(params->dic->getDawg() + edgeptr->ptr);
+ const DAWG_EDGE *current = reinterpret_cast<const
DAWG_EDGE*>(params->dic->getEdgeAt(edgeptr->ptr));
do
{
/* the current letter is current->chr */
@@ -568,12 +569,12 @@
if (iDic.getHeader().getVersion() == 0)
{
Dic_search_regexp_rec(¶ms, a->getInitId(),
- reinterpret_cast<const
Dawg_edge_old*>(iDic.getDawg() + iDic.getRoot()), oWordList);
+ reinterpret_cast<const
Dawg_edge_old*>(iDic.getEdgeAt(iDic.getRoot())), oWordList);
}
else
{
Dic_search_regexp_rec(¶ms, a->getInitId(),
- reinterpret_cast<const
Dawg_edge*>(iDic.getDawg() + iDic.getRoot()), oWordList);
+ reinterpret_cast<const
Dawg_edge*>(iDic.getEdgeAt(iDic.getRoot())), oWordList);
}
delete a;
Index: dic/encoding.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Attic/encoding.cpp,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -b -r1.1.2.4 -r1.1.2.5
--- dic/encoding.cpp 30 Nov 2007 17:53:46 -0000 1.1.2.4
+++ dic/encoding.cpp 4 Dec 2007 11:09:59 -0000 1.1.2.5
@@ -129,3 +129,22 @@
return res;
}
+
+
+string padAndConvert(const wstring &iWstr, unsigned int iLength,
+ bool iLeftPad, char c)
+{
+ int width = wcswidth(iWstr.c_str(), iWstr.size());
+ if (width == -1 || (unsigned int)width >= iLength)
+ return convertToMb(iWstr);
+ else
+ {
+ // Padding is needed
+ string s(iLength - width, c);
+ if (iLeftPad)
+ return s + convertToMb(iWstr);
+ else
+ return convertToMb(iWstr) + s;
+ }
+}
+
Index: dic/encoding.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Attic/encoding.h,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- dic/encoding.h 30 Nov 2007 17:53:46 -0000 1.1.2.2
+++ dic/encoding.h 4 Dec 2007 11:09:59 -0000 1.1.2.3
@@ -43,13 +43,21 @@
wchar_t *_wcstok(wchar_t *wcs, const wchar_t *delim, wchar_t **ptr);
/// Convert a multi-byte string into a wide-character string
-wstring convertToWc(const string& iStr);
+wstring convertToWc(const string &iStr);
/// Convert a wide-character string into a multi-byte string
-string convertToMb(const wstring& iWStr);
+string convertToMb(const wstring &iWStr);
/// Convert a wide character into a multi-byte string
string convertToMb(wchar_t iWChar);
+/**
+ * Convert the given string into a multi-byte one. If the number of columns
+ * needed to display the resulting string is less than iLength, pad it with
+ * the given character (defaulting to space)
+ */
+string padAndConvert(const wstring &iWstr, unsigned int iLength,
+ bool iLeftPad = true, char c = ' ');
+
#endif
Index: dic/header.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Attic/header.cpp,v
retrieving revision 1.1.2.11
retrieving revision 1.1.2.12
diff -u -b -r1.1.2.11 -r1.1.2.12
--- dic/header.cpp 30 Nov 2007 17:09:28 -0000 1.1.2.11
+++ dic/header.cpp 4 Dec 2007 11:09:59 -0000 1.1.2.12
@@ -42,10 +42,7 @@
#include <iconv.h>
-// FIXME: duplicated in dic.cpp
-// XXX: we can't use the htonl/ntohl functions, as the old format is little
-// endian and network format is big endian. But maybe we could use them for
-// the new dictionary format?
+// Note: swap4 is duplicated in dic.cpp
#if defined(WORDS_BIGENDIAN)
static uint32_t swap4(uint32_t v)
{
@@ -103,8 +100,8 @@
//@}
};
-// Do not change these values, as they impact the size of the structure
-#define _USER_HOST_MAX_ 24
+// Do not change these values, as they impact the size of the structure!
+#define _MAX_USER_HOST_ 32
#define _MAX_DIC_NAME_SIZE_ 32
#define _MAX_LETTERS_NB_ 63
#define _MAX_LETTERS_SIZE_ 80
@@ -112,10 +109,13 @@
/** Extension of the old format (used in version 1)*/
struct Dict_header_ext
{
- // Build information (XXX: currently only written, and not UTF-8 encoded)
- char compileUserHost[_USER_HOST_MAX_];
- // Number of seconds since the Epoch (XXX: currently unused)
- uint64_t compileDate;
+ // Time when the dictionary was compressed
+ // (number of seconds since the Epoch)
+ uint64_t compressDate;
+ // Build information
+ char userHost[_MAX_USER_HOST_];
+ // Size taken by the build information
+ uint32_t userHostSize;
// Compression algorithm (1 = DAWG, 2 = GADDAG)
uint8_t algorithm;
@@ -136,9 +136,11 @@
uint32_t nbLetters;
// Points of the letters (indexed by their code)
- uint8_t points[_MAX_LETTERS_NB_];
+ // The "+ 1" is there for struct alignment
+ uint8_t points[_MAX_LETTERS_NB_ + 1];
// Frequency of the letters (indexedy their code)
- uint8_t frequency[_MAX_LETTERS_NB_];
+ // The "+ 1" is there for struct alignment
+ uint8_t frequency[_MAX_LETTERS_NB_ + 1];
// Bitfield indicating whether letters are vowels
uint64_t vowels;
// Bitfield indicating whether letters are consonants
@@ -165,7 +167,7 @@
m_version = 1;
// Sanity checks
- if (iInfo.letters.size() >= _MAX_LETTERS_NB_)
+ if (iInfo.letters.size() > _MAX_LETTERS_NB_)
{
ostringstream ss;
ss << _MAX_LETTERS_NB_;
@@ -194,6 +196,8 @@
"iInfo.consonants and iInfo.letters");
}
+ m_compressDate = time(NULL);
+ m_userHost = convertToWc(ELIOT_COMPILE_BY + string("@") +
ELIOT_COMPILE_HOST);
m_root = iInfo.root;
m_nbWords = iInfo.nwords;
m_nodesUsed = iInfo.nodesused;
@@ -292,9 +296,12 @@
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_dicName = convertToWc("Unspecified (old format)");
m_letters = convertToWc("ABCDEFGHIJKLMNOPQRSTUVWXYZ?");
static const uint8_t Frenchpoints[] =
@@ -340,13 +347,16 @@
throw DicException("Header::read: expected to read more bytes");
// Handle endianness in the extension
- aHeaderExt.compileDate = ntohll(aHeaderExt.compileDate);
+ aHeaderExt.compressDate = ntohll(aHeaderExt.compressDate);
+ aHeaderExt.userHostSize = ntohl(aHeaderExt.userHostSize);
aHeaderExt.dicNameSize = ntohl(aHeaderExt.dicNameSize);
aHeaderExt.lettersSize = ntohl(aHeaderExt.lettersSize);
aHeaderExt.nbLetters = ntohl(aHeaderExt.nbLetters);
aHeaderExt.vowels = ntohll(aHeaderExt.vowels);
aHeaderExt.consonants = ntohll(aHeaderExt.consonants);
+ m_compressDate = aHeaderExt.compressDate;
+
if (aHeaderExt.algorithm == kDAWG)
m_type = kDAWG;
else if (aHeaderExt.algorithm == kGADDAG)
@@ -354,6 +364,9 @@
else
throw DicException("Header::read: unrecognized algorithm type");
+ readFromUTF8(m_userHost, aHeaderExt.userHost,
+ aHeaderExt.userHostSize, "user and host information");
+
// Convert the dictionary letters from UTF-8 to wchar_t*
readFromUTF8(m_dicName, aHeaderExt.dicName,
aHeaderExt.dicNameSize, "dictionary name");
@@ -405,9 +418,10 @@
if (m_version != 0)
{
Dict_header_ext aHeaderExt;
- string userHost = ELIOT_COMPILE_BY + string("@") + ELIOT_COMPILE_HOST;
- strncpy(aHeaderExt.compileUserHost, userHost.c_str(), _USER_HOST_MAX_);
- aHeaderExt.compileUserHost[_USER_HOST_MAX_ - 1] = '\0';
+ aHeaderExt.compressDate = m_compressDate;
+ aHeaderExt.userHostSize =
+ writeInUTF8(m_userHost, aHeaderExt.userHost,
+ _MAX_USER_HOST_, "user and host information");
aHeaderExt.algorithm = m_type;
// Convert the dictionary name to UTF-8
@@ -440,7 +454,8 @@
}
// Handle endianness in the extension
- aHeaderExt.compileDate = htonll(aHeaderExt.compileDate);
+ aHeaderExt.userHostSize = htonl(aHeaderExt.userHostSize);
+ aHeaderExt.compressDate = htonll(aHeaderExt.compressDate);
aHeaderExt.dicNameSize = htonl(aHeaderExt.dicNameSize);
aHeaderExt.lettersSize = htonl(aHeaderExt.lettersSize);
aHeaderExt.nbLetters = htonl(aHeaderExt.nbLetters);
@@ -515,7 +530,18 @@
{
printf("dictionary name: %s\n", convertToMb(m_dicName).c_str());
printf("dictionary type: %s\n", m_type == kDAWG ? "DAWG" : "GADDAG");
- printf("letters: %s\n", convertToMb(m_letters).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: %ls\n", m_userHost.c_str());
+ printf("letters: %ls\n", m_letters.c_str());
printf("number of letters: %d\n", m_letters.size());
printf("number of words: %d\n", m_nbWords);
printf("header size: %u bytes\n", sizeof(Dict_header_old) +
@@ -528,7 +554,8 @@
printf("-------+--------+-----------+-------+----------\n");
for (unsigned int i = 0; i < m_letters.size(); ++i)
{
- printf(" %lc | %2d | %2d | %d | %d\n",
m_letters[i],
+ printf(" %s | %2d | %2d | %d | %d\n",
+ padAndConvert(wstring(1, m_letters[i]), 2).c_str(),
m_points[i], m_frequency[i], m_vowels[i], m_consonants[i]);
}
printf("===============================================\n");
Index: dic/header.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Attic/header.h,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -b -r1.1.2.7 -r1.1.2.8
--- dic/header.h 3 Dec 2007 17:27:33 -0000 1.1.2.7
+++ dic/header.h 4 Dec 2007 11:09:59 -0000 1.1.2.8
@@ -23,6 +23,7 @@
#include <iosfwd>
#include <map>
#include <vector>
+#include <time.h>
using namespace std;
@@ -134,6 +135,9 @@
/// Version of the serialization
uint8_t m_version;
+ wstring m_userHost;
+ time_t m_compressDate;
+
uint32_t m_root;
uint32_t m_nbWords;
uint32_t m_nodesUsed;
Index: dic/listdic.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Attic/listdic.cpp,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -b -r1.1.2.7 -r1.1.2.8
--- dic/listdic.cpp 3 Dec 2007 17:27:33 -0000 1.1.2.7
+++ dic/listdic.cpp 4 Dec 2007 11:09:59 -0000 1.1.2.8
@@ -49,7 +49,7 @@
}
if (i.ptr)
{ /* Compute index: is it non-zero ? */
- const DAWG_EDGE *p = reinterpret_cast<const DAWG_EDGE*>(iDic.getDawg()
+ i.ptr);
+ const DAWG_EDGE *p = reinterpret_cast<const
DAWG_EDGE*>(iDic.getEdgeAt(i.ptr));
do
{ /* for each edge out of this node */
*s = iDic.getHeader().getCharFromCode(p->chr);
@@ -64,7 +64,7 @@
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.getDawg() + iDic.getRoot()));
+ print_dic_rec(cout, iDic, buf, buf, *reinterpret_cast<const
DAWG_EDGE*>(iDic.getEdgeAt(iDic.getRoot())));
}
@@ -77,7 +77,7 @@
uint32_t s;
} ee;
- ee.e = *reinterpret_cast<const DAWG_EDGE*>(dic.getDawg() + i);
+ ee.e = *reinterpret_cast<const DAWG_EDGE*>(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),
Index: game/bag.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/bag.cpp,v
retrieving revision 1.7.2.2
retrieving revision 1.7.2.3
diff -u -b -r1.7.2.2 -r1.7.2.3
--- game/bag.cpp 27 Nov 2007 18:01:05 -0000 1.7.2.2
+++ game/bag.cpp 4 Dec 2007 11:09:59 -0000 1.7.2.3
@@ -23,6 +23,7 @@
#include <dic.h>
#include "bag.h"
#include "debug.h"
+#include "encoding.h"
Bag::Bag(const Dictionary &iDic)
@@ -79,7 +80,7 @@
void Bag::takeTile(const Tile &iTile)
{
ASSERT(in(iTile),
- (wstring(L"The bag does not contain the letter ") +
iTile.toChar()).c_str());
+ "The bag does not contain the letter " +
convertToMb(iTile.toChar()));
m_tilesMap[iTile]--;
m_ntiles--;
@@ -89,7 +90,7 @@
void Bag::replaceTile(const Tile &iTile)
{
ASSERT(in(iTile) < iTile.maxNumber(),
- (wstring(L"Cannot replace tile: ") + iTile.toChar()).c_str());
+ "Cannot replace tile: " + convertToMb(iTile.toChar()));
m_tilesMap[iTile]++;
m_ntiles++;
Index: game/game_io.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game_io.cpp,v
retrieving revision 1.4.2.1
retrieving revision 1.4.2.2
diff -u -b -r1.4.2.1 -r1.4.2.2
--- game/game_io.cpp 23 Dec 2006 16:48:33 -0000 1.4.2.1
+++ game/game_io.cpp 4 Dec 2007 11:09:59 -0000 1.4.2.2
@@ -192,14 +192,7 @@
Game *pGame = NULL;
char buff[4096];
- int num;
- char rack[20];
- char word[20];
- char ref[4];
- int pts;
- int player;
char *pos;
- Tile tile;
/*************/
/* Game type */
@@ -322,9 +315,15 @@
}
+ int num;
+ char rack[20];
+ char tmpWord[20];
+ char ref[4];
+ int pts;
+ int player;
char bonus = 0;
int res = sscanf(buff, " %2d | %8s | %s | %3s | %3d | %1d | %c",
- &num, rack, word, ref, &pts, &player, &bonus);
+ &num, rack, tmpWord, ref, &pts, &player, &bonus);
debug(" -- line %s",buff);
@@ -335,7 +334,7 @@
}
debug(" %2d | %8s | %s | %3s | %3d | %1d | %c \n",
- num, rack, word, ref, pts, player, bonus);
+ num, rack, tmpWord, ref, pts, player, bonus);
// Integrity checks
// TODO: add more checks
@@ -369,6 +368,8 @@
if (bonus == '*')
round.setBonus(1);
+ wstring word = convertToWc(tmpWord);
+ Tile tile;
if (isalpha(ref[0]))
{
// Horizontal word
@@ -376,7 +377,7 @@
round.accessCoord().setRow(ref[0] - 'A' + 1);
round.accessCoord().setCol(atoi(ref + 1));
- for (unsigned int i = 0; i < strlen(word); i++)
+ for (unsigned int i = 0; i < word.size(); i++)
{
tile = Tile(word[i]);
@@ -386,8 +387,8 @@
}
else
{
- round.addRightFromRack(tile, islower(word[i]));
- pGame->m_bag.takeTile((islower(word[i])) ? Tile::Joker() :
tile);
+ round.addRightFromRack(tile, iswlower(word[i]));
+ pGame->m_bag.takeTile((iswlower(word[i])) ? Tile::Joker()
: tile);
}
}
}
@@ -398,7 +399,7 @@
round.accessCoord().setRow(ref[strlen(ref) - 1] - 'A' + 1);
round.accessCoord().setCol(atoi(ref));
- for (unsigned int i = 0; i < strlen(word); i++)
+ for (unsigned int i = 0; i < word.size(); i++)
{
tile = Tile(word[i]);
@@ -408,17 +409,17 @@
}
else
{
- round.addRightFromRack(tile, islower(word[i]));
- pGame->m_bag.takeTile((islower(word[i])) ? Tile::Joker() :
tile);
+ round.addRightFromRack(tile, iswlower(word[i]));
+ pGame->m_bag.takeTile((iswlower(word[i])) ? Tile::Joker()
: tile);
}
}
}
- // pGame->m_currPlayer = player;
- // // Update the rack for the player
- // pGame->m_players[player]->setCurrentRack(pldrack);
- // // End the turn for the current player (this creates a
new rack)
- // pGame->m_players[player]->endTurn(round,num - 1);
+// pGame->m_currPlayer = player;
+// // Update the rack for the player
+// pGame->m_players[player]->setCurrentRack(pldrack);
+// // End the turn for the current player (this creates a
new rack)
+// pGame->m_players[player]->endTurn(round,num - 1);
// Play the round
pGame->helperPlayRound(round);
@@ -545,14 +546,13 @@
for (int i = 0; i < m_history.getSize(); i++)
{
const Turn& turn = m_history.getTurn(i);
- string rack =
convertToMb(turn.getPlayedRack().toString(PlayedRack::RACK_EXTRA));
- string word = convertToMb(turn.getRound().getWord());
+ wstring rack = turn.getPlayedRack().toString(PlayedRack::RACK_EXTRA);
+ wstring word = turn.getRound().getWord();
string coord = convertToMb(turn.getRound().getCoord().toString());
- sprintf(line, "%2d | %8s | %s%s | %3s | %3d | %1d | %c",
+ sprintf(line, "%2d | %s | %s | %3s | %3d | %1d | %c",
i + 1,
- rack.c_str(), /* pldrack */
- word.c_str(), /* word */
- string(15 - word.size(), ' ').c_str(), /* fill spaces */
+ padAndConvert(rack, 8).c_str(), /* pldrack */
+ padAndConvert(word, 15, false).c_str(), /* word */
coord.c_str(), /* coord */
turn.getRound().getPoints(),
turn.getPlayer(),
Index: utils/game_io.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/utils/game_io.cpp,v
retrieving revision 1.9.2.3
retrieving revision 1.9.2.4
diff -u -b -r1.9.2.3 -r1.9.2.4
--- utils/game_io.cpp 27 Nov 2007 18:01:07 -0000 1.9.2.3
+++ utils/game_io.cpp 4 Dec 2007 11:10:00 -0000 1.9.2.4
@@ -46,8 +46,11 @@
out << " " << (char)(row - BOARD_MIN + 'A') << " ";
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
{
- char l = iGame.getBoard().getChar(row, col);
- out << setw(3) << (l ? l : '-');
+ wchar_t l = iGame.getBoard().getChar(row, col);
+ if (l == 0)
+ out << " -";
+ else
+ out << padAndConvert(wstring(1, l), 3);
}
out << endl;
}
@@ -94,11 +97,13 @@
out << " " << (char)(row - BOARD_MIN + 'A') << " ";
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
{
- char l = iGame.getBoard().getChar(row, col);
+ wchar_t l = iGame.getBoard().getChar(row, col);
bool j = (iGame.getBoard().getCharAttr(row, col) & ATTR_JOKER);
- out << " " << (j ? '.' : (l ? ' ' : '-'));
- out << (l ? l : '-');
+ if (l == 0)
+ out << " " << (j ? "." : "--");
+ else
+ out << " " << (j ? "." : " ") << convertToMb(l);
}
out << endl;
}
@@ -119,9 +124,9 @@
out << " " << (char)(row - BOARD_MIN + 'A') << " ";
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
{
- char l = iGame.getBoard().getChar(row, col);
+ wchar_t l = iGame.getBoard().getChar(row, col);
if (l != 0)
- out << " " << l;
+ out << padAndConvert(wstring(1, l), 3);
else
{
int wm = iGame.getBoard().getWordMultiplier(row, col);
Index: utils/ncurses.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/utils/ncurses.cpp,v
retrieving revision 1.22.2.2
retrieving revision 1.22.2.3
diff -u -b -r1.22.2.2 -r1.22.2.3
--- utils/ncurses.cpp 3 Dec 2007 17:27:33 -0000 1.22.2.2
+++ utils/ncurses.cpp 4 Dec 2007 11:10:00 -0000 1.22.2.3
@@ -236,7 +236,8 @@
Training *tr_game = static_cast<Training*>(m_game);
int h = 17;
- drawBox(win, y, x, h, 25, _(" Search results "));
+ int w = 25;
+ drawBox(win, y, x, h, w, _(" Search results "));
m_boxY = y + 1;
m_boxLines = h - 2;
m_boxLinesData = tr_game->getResults().size();
@@ -248,16 +249,15 @@
{
const Round &r = res.get(i);
wstring coord = r.getCoord().toString();
- boxPrint(win, i, x + 1, "%3d %s%s %3s",
+ boxPrint(win, i, x + 1, "%3d %s %3s",
r.getPoints(),
- convertToMb(r.getWord()).c_str(),
- string(h - 3 - r.getWordLen(), ' ').c_str(),
+ padAndConvert(r.getWord(), w - 11, false).c_str(),
convertToMb(coord).c_str());
}
// Complete the list with empty lines, to avoid trails
for (; i < m_boxStart + m_boxLines; i++)
{
- boxPrint(win, i, x + 1, string(23, ' ').c_str());
+ boxPrint(win, i, x + 1, string(w - 2, ' ').c_str());
}
}
@@ -283,12 +283,12 @@
{
const Turn& t = m_game->getHistory().getTurn(i);
const Round& r = t.getRound();
- string coord = convertToMb(r.getCoord().toString());
+ wstring coord = r.getCoord().toString();
boxPrint(win, i + 2, x + 2,
- "%2d %8ls %ls%s %3s %3d %1d %c",
- i + 1, t.getPlayedRack().toString().c_str(),
- r.getWord().c_str(), string(15 - r.getWordLen(), ' ').c_str(),
- coord.c_str(), r.getPoints(),
+ "%2d %s %s %s %3d %1d %c",
+ i + 1, padAndConvert(t.getPlayedRack().toString(), 8).c_str(),
+ padAndConvert(r.getWord(), 15, false).c_str(),
+ padAndConvert(coord, 3).c_str(), r.getPoints(),
t.getPlayer(), r.getBonus() ? '*' : ' ');
}
mvwvline(win, y + 1, x + 5, ACS_VLINE, min(i + 2 - m_boxStart,
m_boxLines));
@@ -564,7 +564,7 @@
// mvwprintw(win, 0, 0, "%3lc", c);
}
curs_set(0);
- return 0;
+ return false;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Eliot-dev] eliot configure.in dic/dic.h dic/dic_search.cpp... [cppdic],
eliot-dev <=