[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Eliot-dev] eliot dic/Makefile.am dic/listdic.cpp qt/dic_to...
From: |
Olivier Teulière |
Subject: |
[Eliot-dev] eliot dic/Makefile.am dic/listdic.cpp qt/dic_to... |
Date: |
Sat, 18 Sep 2010 13:07:39 +0000 |
CVSROOT: /cvsroot/eliot
Module name: eliot
Changes by: Olivier Teulière <ipkiss> 10/09/18 13:07:39
Modified files:
dic : Makefile.am listdic.cpp
qt : dic_tools_widget.cpp dic_tools_widget.h
qt/ui : dic_tools_widget.ui
Added files:
dic : listdic.h listdicmain.cpp
Log message:
New button on the "Dic. info" tab, to save the dictionary words list to
a file
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/Makefile.am?cvsroot=eliot&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/listdic.cpp?cvsroot=eliot&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/listdic.h?cvsroot=eliot&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/listdicmain.cpp?cvsroot=eliot&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/dic_tools_widget.cpp?cvsroot=eliot&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/dic_tools_widget.h?cvsroot=eliot&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/ui/dic_tools_widget.ui?cvsroot=eliot&r1=1.6&r2=1.7
Patches:
Index: dic/Makefile.am
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Makefile.am,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- dic/Makefile.am 15 May 2010 12:14:53 -0000 1.22
+++ dic/Makefile.am 18 Sep 2010 13:07:39 -0000 1.23
@@ -33,7 +33,8 @@
automaton.cpp automaton.h \
regexp.cpp regexp.h \
grammar.cpp grammar.h \
- compdic.cpp compdic.h
+ compdic.cpp compdic.h \
+ listdic.cpp listdic.h
#####################################
if BUILD_DICTOOLS
@@ -47,7 +48,7 @@
compdic_CPPFLAGS=$(AM_CPPFLAGS) @BOOST_CPPFLAGS@
compdic_LDADD=libdic.a @LIBINTL@
-listdic_SOURCES=listdic.cpp
+listdic_SOURCES=listdicmain.cpp
listdic_LDADD=libdic.a @LIBINTL@
#regexp_CFLAGS=-DDEBUG_RE
Index: dic/listdic.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/listdic.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- dic/listdic.cpp 22 Nov 2008 13:11:48 -0000 1.6
+++ dic/listdic.cpp 18 Sep 2010 13:07:39 -0000 1.7
@@ -21,165 +21,43 @@
#include "config.h"
-#include <fstream>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cstddef>
-#if ENABLE_NLS
-# include <libintl.h>
-# define _(String) gettext(String)
-#else
-# define _(String) String
-#endif
-#ifdef WIN32
-# include <windows.h>
-#endif
-
-#include "header.h"
#include "encoding.h"
+#include "header.h"
#include "dic_internals.h"
#include "dic.h"
+#include "listdic.h"
using namespace std;
-
-static void print_dic_rec(ostream &out, const Dictionary &iDic, wchar_t *buf,
wchar_t *s, DicEdge i)
+static void printDicRec(ostream &out, const Dictionary &iDic, const wchar_t *
const buf, wchar_t *s, DicEdge edge)
{
- if (i.term) /* edge points at a complete word */
+ if (edge.term) /* edge points at a complete word */
{
*s = '\0';
out << convertToMb(buf) << endl;
}
- if (i.ptr)
+ if (edge.ptr)
{ /* Compute index: is it non-zero ? */
- const DicEdge *p = iDic.getEdgeAt(i.ptr);
+ const DicEdge *p = iDic.getEdgeAt(edge.ptr);
do
{ /* for each edge out of this node */
*s = iDic.getHeader().getCharFromCode(p->chr);
- print_dic_rec(out, iDic, buf, s + 1, *p);
+ printDicRec(out, iDic, buf, s + 1, *p);
}
while (!(*p++).last);
}
}
-void print_dic_list(const Dictionary &iDic)
-{
- static wchar_t buf[80];
- print_dic_rec(cout, iDic, buf, buf, *iDic.getEdgeAt(iDic.getRoot()));
-}
-
-
-static void print_node_hex(const Dictionary &dic, int i)
-{
- union edge_t
- {
- DicEdge e;
- uint32_t s;
- } ee;
-
- 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),
- i, ee.e.ptr, ee.e.term, ee.e.last, ee.e.chr, ee.e.chr +'a' -1);
-}
-
-
-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(iDic, i);
-}
-
-
-void usage(const string &iName)
-{
- printf(_("usage: %s [-a|-h|-l|-x] dictionary\n"), iName.c_str());
- printf(_(" -a: print all\n"));
- printf(_(" -h: print header\n"));
- printf(_(" -l: print dictionary word list\n"));
- printf(_(" -x: print dictionary in hex\n"));
-}
-
-
-int main(int argc, char *argv[])
+void ListDic::printWords(ostream &out, const Dictionary &iDic)
{
-#if HAVE_SETLOCALE
- // Set locale via LC_ALL
- setlocale(LC_ALL, "");
-#endif
-
-#if ENABLE_NLS
- // Set the message domain
-#ifdef WIN32
- // Get the absolute path, as returned by GetFullPathName()
- char baseDir[MAX_PATH];
- GetFullPathName(argv[0], MAX_PATH, baseDir, NULL);
- char *pos = strrchr(baseDir, L'\\');
- if (pos)
- *pos = '\0';
- const string localeDir = baseDir + string("\\locale");
-#else
- static const string localeDir = LOCALEDIR;
-#endif
- bindtextdomain(PACKAGE, localeDir.c_str());
- textdomain(PACKAGE);
-#endif
-
- int arg_count;
- int option_print_all = 0;
- int option_print_header = 0;
- int option_print_dic_hex = 0;
- int option_print_dic_list = 0;
-
- if (argc < 3)
- {
- usage(argv[0]);
- exit(1);
- }
-
- arg_count = 1;
- while (argv[arg_count][0] == '-')
- {
- switch (argv[arg_count][1])
- {
- case 'a': option_print_all = 1; break;
- case 'h': option_print_header = 1; break;
- case 'l': option_print_dic_list = 1; break;
- case 'x': option_print_dic_hex = 1; break;
- default: usage(argv[0]); exit(2); break;
- }
- arg_count++;
- }
-
- try
- {
- Dictionary dic(argv[arg_count]);
-
- if (option_print_header || option_print_all)
- {
- dic.getHeader().print();
- }
- if (option_print_dic_hex || option_print_all)
- {
- print_dic_hex(dic);
- }
- if (option_print_dic_list || option_print_all)
- {
- print_dic_list(dic);
- }
- return 0;
- }
- catch (std::exception &e)
- {
- cerr << e.what() << endl;
- return 1;
- }
+ wchar_t buf[100];
+ printDicRec(out, iDic, buf, buf, *iDic.getEdgeAt(iDic.getRoot()));
}
Index: qt/dic_tools_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/dic_tools_widget.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- qt/dic_tools_widget.cpp 15 May 2010 12:20:20 -0000 1.14
+++ qt/dic_tools_widget.cpp 18 Sep 2010 13:07:39 -0000 1.15
@@ -23,17 +23,21 @@
#include <map>
#include <vector>
#include <algorithm>
+#include <fstream>
#include <QtGui/QTreeView>
#include <QtGui/QStandardItemModel>
#include <QtGui/QVBoxLayout>
#include <QtGui/QLineEdit>
#include <QtGui/QToolTip>
+#include <QtGui/QFileDialog>
+#include <QtGui/QMessageBox>
#include <QtCore/QString>
#include "dic_tools_widget.h"
#include "qtcommon.h"
#include "dic.h"
#include "header.h"
+#include "listdic.h"
#include "dic_exception.h"
using namespace std;
@@ -85,6 +89,7 @@
QObject::connect(lineEditCheck, SIGNAL(textChanged(const QString&)), this,
SLOT(refreshCheck()));
QObject::connect(lineEditPlus1, SIGNAL(returnPressed()), this,
SLOT(refreshPlus1()));
QObject::connect(lineEditRegexp, SIGNAL(returnPressed()), this,
SLOT(refreshRegexp()));
+ QObject::connect(buttonSaveWords, SIGNAL(clicked()), this,
SLOT(exportWordsList()));
// Create models
m_plus1Model = new QStandardItemModel(this);
@@ -345,6 +350,29 @@
}
+void DicToolsWidget::exportWordsList()
+{
+ if (m_dic == NULL)
+ return;
+ QString fileName = QFileDialog::getSaveFileName(this, _q("Export words
list"));
+ if (fileName != "")
+ {
+ try
+ {
+ ofstream file(qtl(fileName).c_str());
+ ListDic::printWords(file, *m_dic);
+ QMessageBox::information(this, _q("Export words list"),
+ _q("File '%1' successfully
saved").arg(fileName));
+ }
+ catch (std::exception &e)
+ {
+ QMessageBox::warning(this, _q("Eliot - Error"),
+ _q("Cannot save the words list:
%1").arg(e.what()));
+ }
+ }
+}
+
+
DicRackValidator::DicRackValidator(QObject *parent,
const Dictionary *iDic,
Index: qt/dic_tools_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/dic_tools_widget.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- qt/dic_tools_widget.h 27 Jun 2009 18:09:44 -0000 1.4
+++ qt/dic_tools_widget.h 18 Sep 2010 13:07:39 -0000 1.5
@@ -68,6 +68,8 @@
void refreshRegexp();
/// Force synchronizing the model with the dictionary letters
void refreshDicInfo();
+ /// Save the words of the dictionary to a file
+ void exportWordsList();
};
#endif
Index: qt/ui/dic_tools_widget.ui
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/ui/dic_tools_widget.ui,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- qt/ui/dic_tools_widget.ui 15 May 2010 12:20:32 -0000 1.6
+++ qt/ui/dic_tools_widget.ui 18 Sep 2010 13:07:39 -0000 1.7
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>435</width>
- <height>354</height>
+ <height>386</height>
</rect>
</property>
<property name="windowTitle">
@@ -180,7 +180,22 @@
</property>
</widget>
</item>
+ <item row="3" column="0" colspan="2">
+ <widget class="QTreeView" name="treeViewDicLetters">
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <property name="rootIsDecorated">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
<item row="2" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
<widget class="QSpinBox" name="spinBoxWords">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@@ -202,25 +217,49 @@
</property>
</widget>
</item>
- <item row="3" column="0" colspan="2">
- <widget class="QTreeView" name="treeViewDicLetters">
- <property name="editTriggers">
- <set>QAbstractItemView::NoEditTriggers</set>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
</property>
- <property name="alternatingRowColors">
- <bool>true</bool>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
</property>
- <property name="rootIsDecorated">
- <bool>false</bool>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="buttonSaveWords">
+ <property name="text">
+ <string>_("Save words list...")</string>
</property>
</widget>
</item>
</layout>
+ </item>
+ </layout>
</widget>
</widget>
</item>
</layout>
</widget>
+ <tabstops>
+ <tabstop>tabWidget</tabstop>
+ <tabstop>lineEditCheck</tabstop>
+ <tabstop>lineEditPlus1</tabstop>
+ <tabstop>treeViewPlus1</tabstop>
+ <tabstop>lineEditRegexp</tabstop>
+ <tabstop>spinBoxMinLength</tabstop>
+ <tabstop>spinBoxMaxLength</tabstop>
+ <tabstop>treeViewRegexp</tabstop>
+ <tabstop>lineEditName</tabstop>
+ <tabstop>lineEditLetters</tabstop>
+ <tabstop>spinBoxWords</tabstop>
+ <tabstop>buttonSaveWords</tabstop>
+ <tabstop>treeViewDicLetters</tabstop>
+ </tabstops>
<resources/>
<connections/>
</ui>
Index: dic/listdic.h
===================================================================
RCS file: dic/listdic.h
diff -N dic/listdic.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dic/listdic.h 18 Sep 2010 13:07:39 -0000 1.1
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Eliot
+ * Copyright (C) 2010 Olivier Teulière
+ * Authors: Olivier Teulière <ipkiss @@ gmail.com>
+ *
+ * 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
+ *****************************************************************************/
+
+#ifndef DIC_LISTDIC_H_
+#define DIC_LISTDIC_H_
+
+#include <iosfwd>
+
+
+class Dictionary;
+
+using namespace std;
+
+
+class ListDic
+{
+
+public:
+ ListDic();
+
+ static void printWords(ostream &out, const Dictionary &iDic);
+
+private:
+
+};
+
+#endif /* DIC_LISTDIC_H_ */
Index: dic/listdicmain.cpp
===================================================================
RCS file: dic/listdicmain.cpp
diff -N dic/listdicmain.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dic/listdicmain.cpp 18 Sep 2010 13:07:39 -0000 1.1
@@ -0,0 +1,159 @@
+/*****************************************************************************
+ * Eliot
+ * Copyright (C) 1999-2007 Antoine Fraboulet & Olivier Teulière
+ * Authors: Antoine Fraboulet <antoine.fraboulet @@ free.fr>
+ * Olivier Teulière <ipkiss @@ gmail.com>
+ *
+ * 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 "config.h"
+
+#include <fstream>
+#include <iostream>
+#include <cstring>
+#include <cstdlib>
+#include <cstdio>
+#include <cstddef>
+
+#if ENABLE_NLS
+# include <libintl.h>
+# define _(String) gettext(String)
+#else
+# define _(String) String
+#endif
+#ifdef WIN32
+# include <windows.h>
+#endif
+
+#include "header.h"
+#include "encoding.h"
+#include "dic_internals.h"
+#include "listdic.h"
+#include "dic.h"
+
+using namespace std;
+
+
+static void print_node_hex(const Dictionary &dic, int i)
+{
+ union edge_t
+ {
+ DicEdge e;
+ uint32_t s;
+ } ee;
+
+ 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),
+ i, ee.e.ptr, ee.e.term, ee.e.last, ee.e.chr, ee.e.chr +'a' -1);
+}
+
+
+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(iDic, i);
+}
+
+
+void usage(const string &iName)
+{
+ printf(_("usage: %s [-a|-h|-l|-x] dictionary\n"), iName.c_str());
+ printf(_(" -a: print all\n"));
+ printf(_(" -h: print header\n"));
+ printf(_(" -l: print dictionary word list\n"));
+ printf(_(" -x: print dictionary in hex\n"));
+}
+
+
+int main(int argc, char *argv[])
+{
+#if HAVE_SETLOCALE
+ // Set locale via LC_ALL
+ setlocale(LC_ALL, "");
+#endif
+
+#if ENABLE_NLS
+ // Set the message domain
+#ifdef WIN32
+ // Get the absolute path, as returned by GetFullPathName()
+ char baseDir[MAX_PATH];
+ GetFullPathName(argv[0], MAX_PATH, baseDir, NULL);
+ char *pos = strrchr(baseDir, L'\\');
+ if (pos)
+ *pos = '\0';
+ const string localeDir = baseDir + string("\\locale");
+#else
+ static const string localeDir = LOCALEDIR;
+#endif
+ bindtextdomain(PACKAGE, localeDir.c_str());
+ textdomain(PACKAGE);
+#endif
+
+ int arg_count;
+ int option_print_all = 0;
+ int option_print_header = 0;
+ int option_print_dic_hex = 0;
+ int option_print_dic_list = 0;
+
+ if (argc < 3)
+ {
+ usage(argv[0]);
+ exit(1);
+ }
+
+ arg_count = 1;
+ while (argv[arg_count][0] == '-')
+ {
+ switch (argv[arg_count][1])
+ {
+ case 'a': option_print_all = 1; break;
+ case 'h': option_print_header = 1; break;
+ case 'l': option_print_dic_list = 1; break;
+ case 'x': option_print_dic_hex = 1; break;
+ default: usage(argv[0]); exit(2); break;
+ }
+ arg_count++;
+ }
+
+ try
+ {
+ Dictionary dic(argv[arg_count]);
+
+ if (option_print_header || option_print_all)
+ {
+ dic.getHeader().print();
+ }
+ if (option_print_dic_hex || option_print_all)
+ {
+ print_dic_hex(dic);
+ }
+ if (option_print_dic_list || option_print_all)
+ {
+ ListDic::printWords(cout, dic);
+ }
+ return 0;
+ }
+ catch (std::exception &e)
+ {
+ cerr << e.what() << endl;
+ return 1;
+ }
+}
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Eliot-dev] eliot dic/Makefile.am dic/listdic.cpp qt/dic_to...,
Olivier Teulière <=