2008-01-08 14:52:32 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Eliot
|
|
|
|
* Copyright (C) 2005-2007 Antoine Fraboulet
|
|
|
|
* Authors: Antoine Fraboulet <antoine.fraboulet @@ free.fr>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file regexpmain.c
|
|
|
|
* \brief Program used to test regexp
|
|
|
|
* \author Antoine Fraboulet
|
|
|
|
* \date 2005
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <exception>
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#if ENABLE_NLS
|
|
|
|
# include <libintl.h>
|
|
|
|
# define _(String) gettext(String)
|
|
|
|
#else
|
|
|
|
# define _(String) String
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "dic.h"
|
2008-07-07 19:29:59 +02:00
|
|
|
#include "header.h"
|
2008-01-08 14:52:32 +01:00
|
|
|
#include "regexp.h"
|
|
|
|
#include "encoding.h"
|
|
|
|
|
|
|
|
|
2008-07-07 19:29:59 +02:00
|
|
|
void init_letter_lists(const Dictionary &iDic, struct search_RegE_list_t *iList)
|
2008-01-08 14:52:32 +01:00
|
|
|
{
|
2008-07-07 19:29:59 +02:00
|
|
|
memset(iList, 0, sizeof(*iList));
|
2008-01-08 14:52:32 +01:00
|
|
|
iList->minlength = 1;
|
|
|
|
iList->maxlength = 15;
|
2008-07-07 19:29:59 +02:00
|
|
|
iList->valid[0] = true; // all letters
|
2008-01-08 14:52:32 +01:00
|
|
|
iList->symbl[0] = RE_ALL_MATCH;
|
2008-07-07 19:29:59 +02:00
|
|
|
iList->valid[1] = true; // vowels
|
2008-01-08 14:52:32 +01:00
|
|
|
iList->symbl[1] = RE_VOWL_MATCH;
|
2008-07-07 19:29:59 +02:00
|
|
|
iList->valid[2] = true; // consonants
|
2008-01-08 14:52:32 +01:00
|
|
|
iList->symbl[2] = RE_CONS_MATCH;
|
2008-07-07 19:29:59 +02:00
|
|
|
iList->letters[0][0] = false;
|
|
|
|
iList->letters[1][0] = false;
|
|
|
|
iList->letters[2][0] = false;
|
|
|
|
const wstring &allLetters = iDic.getHeader().getLetters();
|
|
|
|
for (size_t i = 1; i <= allLetters.size(); ++i)
|
2008-01-08 14:52:32 +01:00
|
|
|
{
|
2008-07-07 19:29:59 +02:00
|
|
|
iList->letters[0][i] = true;
|
|
|
|
iList->letters[1][i] = iDic.getHeader().isVowel(i);
|
|
|
|
iList->letters[2][i] = iDic.getHeader().isConsonant(i);
|
2008-01-08 14:52:32 +01:00
|
|
|
}
|
2008-07-07 19:29:59 +02:00
|
|
|
|
|
|
|
iList->valid[3] = false; // user defined list 1
|
2008-01-08 14:52:32 +01:00
|
|
|
iList->symbl[3] = RE_USR1_MATCH;
|
2008-07-07 19:29:59 +02:00
|
|
|
iList->valid[4] = false; // user defined list 2
|
2008-01-08 14:52:32 +01:00
|
|
|
iList->symbl[4] = RE_USR2_MATCH;
|
|
|
|
}
|
|
|
|
|
2008-07-07 19:29:59 +02:00
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
void usage(const char *iBinaryName)
|
|
|
|
{
|
|
|
|
cerr << _("usage: %s dictionary") << iBinaryName << endl;
|
|
|
|
cerr << _(" dictionary: path to eliot dawg dictionary") << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Dictionary dic(argv[1]);
|
|
|
|
|
|
|
|
char er[200];
|
|
|
|
strcpy(er, ".");
|
|
|
|
|
|
|
|
struct search_RegE_list_t regList;
|
|
|
|
while (strcmp(er, ""))
|
|
|
|
{
|
|
|
|
cout << "**************************************************************" << endl;
|
|
|
|
cout << "**************************************************************" << endl;
|
|
|
|
cout << _("enter a regular expression:") << endl;
|
|
|
|
fgets(er, sizeof(er), stdin);
|
|
|
|
/* strip \n */
|
|
|
|
er[strlen(er) - 1] = '\0';
|
|
|
|
if (strcmp(er, "") == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* automaton */
|
2008-07-07 19:29:59 +02:00
|
|
|
init_letter_lists(dic, ®List);
|
2008-03-02 19:45:10 +01:00
|
|
|
vector<wstring> wordList;
|
2008-01-08 14:52:32 +01:00
|
|
|
dic.searchRegExp(convertToWc(er), wordList, ®List);
|
|
|
|
|
|
|
|
cout << _("result:") << endl;
|
2008-03-02 19:45:10 +01:00
|
|
|
vector<wstring>::const_iterator it;
|
2008-01-08 14:52:32 +01:00
|
|
|
for (it = wordList.begin(); it != wordList.end(); it++)
|
|
|
|
{
|
|
|
|
cerr << convertToMb(*it) << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
catch (std::exception &e)
|
|
|
|
{
|
|
|
|
std::cerr << e.what() << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2008-07-07 19:29:59 +02:00
|
|
|
std::cerr << "Unknown exception taken" << endl;
|
2008-01-08 14:52:32 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|