eliot-dev
[Top][All Lists]
Advanced

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

[Eliot-dev] eliot configure.in dic/encoding.cpp dic/encodin... [cppdic]


From: eliot-dev
Subject: [Eliot-dev] eliot configure.in dic/encoding.cpp dic/encodin... [cppdic]
Date: Fri, 30 Nov 2007 17:53:47 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Branch:         cppdic
Changes by:     Olivier Teulière <ipkiss>      07/11/30 17:53:47

Modified files:
        .              : configure.in 
        dic            : encoding.cpp encoding.h 
        utils          : Makefile.am eliottxt.cpp 

Log message:
         - dic/encoding.*: new portable _wcstok wrapper around wcstok
         - rest: if readline is missing, deal with it and do not complain. This 
allows building the text interface for windows again.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/configure.in?cvsroot=eliot&only_with_tag=cppdic&r1=1.19.2.5&r2=1.19.2.6
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/encoding.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.1.2.3&r2=1.1.2.4
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/encoding.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/utils/Makefile.am?cvsroot=eliot&only_with_tag=cppdic&r1=1.9.4.2&r2=1.9.4.3
http://cvs.savannah.gnu.org/viewcvs/eliot/utils/eliottxt.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.16.2.7&r2=1.16.2.8

Patches:
Index: configure.in
===================================================================
RCS file: /cvsroot/eliot/eliot/configure.in,v
retrieving revision 1.19.2.5
retrieving revision 1.19.2.6
diff -u -b -r1.19.2.5 -r1.19.2.6
--- configure.in        30 Nov 2007 17:09:28 -0000      1.19.2.5
+++ configure.in        30 Nov 2007 17:53:46 -0000      1.19.2.6
@@ -83,6 +83,8 @@
 AC_HEADER_STDC
 AC_CHECK_HEADERS(fcntl.h unistd.h sys/wait.h)
 AC_CHECK_HEADERS(arpa/inet.h netinet/in.h)
+AC_CHECK_HEADERS([readline/readline.h], [has_readline=1], [has_readline=0])
+AM_CONDITIONAL(HAS_READLINE, test "$has_readline" = "1")
 
 dnl --------------------------------------------------------------
 dnl Checks for typedefs, structures, and compiler characteristics.
@@ -144,11 +146,6 @@
 
 dnl Enable/disable text version
 AC_ARG_ENABLE([text],AC_HELP_STRING([--enable-text],[text interface support 
(default enabled)]))
-if test "${enable_text}" != "no"
-then
-  AC_CHECK_HEADERS(readline/readline.h, want_text=1,
-    [AC_MSG_ERROR([Could not find the readline library on your system])])
-fi
 AM_CONDITIONAL([BUILD_TEXT], [test "${enable_text}" != "no"])
 
 dnl Internationalization macros

Index: dic/encoding.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Attic/encoding.cpp,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -b -r1.1.2.3 -r1.1.2.4
--- dic/encoding.cpp    20 Nov 2007 12:54:03 -0000      1.1.2.3
+++ dic/encoding.cpp    30 Nov 2007 17:53:46 -0000      1.1.2.4
@@ -53,6 +53,17 @@
 }
 
 
+wchar_t *_wcstok(wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)
+{
+#ifdef WIN32
+    // Mingw32 does not take the third argument
+    return wcstok(wcs, delim);
+#else
+    return wcstok(wcs, delim, ptr);
+#endif
+}
+
+
 #define _MAX_SIZE_FOR_STACK_ 30
 wstring convertToWc(const string& iStr)
 {

Index: dic/encoding.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Attic/encoding.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- dic/encoding.h      15 Oct 2006 11:07:55 -0000      1.1.2.1
+++ dic/encoding.h      30 Nov 2007 17:53:46 -0000      1.1.2.2
@@ -39,6 +39,9 @@
 /// Equivalent of swprintf, but working also with mingw32
 int _swprintf(wchar_t *wcs, size_t maxlen, const wchar_t *format, ...);
 
+/// Equivalent of wcstok, but working also with mingw32
+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);
 

Index: utils/Makefile.am
===================================================================
RCS file: /cvsroot/eliot/eliot/utils/Makefile.am,v
retrieving revision 1.9.4.2
retrieving revision 1.9.4.3
diff -u -b -r1.9.4.2 -r1.9.4.3
--- utils/Makefile.am   30 Nov 2007 17:09:29 -0000      1.9.4.2
+++ utils/Makefile.am   30 Nov 2007 17:53:47 -0000      1.9.4.3
@@ -25,7 +25,10 @@
 if BUILD_TEXT
 noinst_PROGRAMS += eliottxt
 eliottxt_SOURCES = game_io.h game_io.cpp eliottxt.cpp
-eliottxt_LDADD = $(top_builddir)/game/libgame.a $(top_builddir)/dic/libdic.a 
-lreadline @LIBICONV@
+eliottxt_LDADD = $(top_builddir)/game/libgame.a $(top_builddir)/dic/libdic.a 
@LIBICONV@
+if HAS_READLINE
+eliottxt_LDADD += -lreadline
+endif
 endif
 
 if BUILD_NCURSES

Index: utils/eliottxt.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/utils/eliottxt.cpp,v
retrieving revision 1.16.2.7
retrieving revision 1.16.2.8
diff -u -b -r1.16.2.7 -r1.16.2.8
--- utils/eliottxt.cpp  27 Nov 2007 18:01:06 -0000      1.16.2.7
+++ utils/eliottxt.cpp  30 Nov 2007 17:53:47 -0000      1.16.2.8
@@ -18,16 +18,21 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *****************************************************************************/
 
+#include "config.h"
+
+#include <wchar.h>
+#include <fstream>
+#include <iostream>
 #include <stdlib.h>
-#include <stdio.h>
 #include <time.h>
 #include <string.h>
 #include <locale.h>
 #include <wctype.h>
-#include <wchar.h>
-#include <fstream>
-#include <readline/readline.h>
-#include <readline/history.h>
+#if HAVE_READLINE_READLINE_H
+#   include <stdio.h>
+#   include <readline/readline.h>
+#   include <readline/history.h>
+#endif
 
 #include "dic.h"
 #include "dic_search.h"
@@ -41,8 +46,6 @@
 
 
 /* A static variable for holding the line. */
-static char *line_read = NULL;
-/* Wide version of the line */
 static wchar_t *wline_read = NULL;
 
 /**
@@ -51,20 +54,16 @@
  */
 wchar_t *rl_gets()
 {
+#if HAVE_READLINE_READLINE_H
     // If the buffer has already been allocated, return the memory to the free
     // pool
-    if (line_read)
-    {
-        free(line_read);
-        line_read = NULL;
-    }
     if (wline_read)
     {
         delete[] wline_read;
-        wline_read = NULL;
     }
 
     // Get a line from the user
+    static char *line_read;
     line_read = readline("commande> ");
 
     // If the line has any text in it, save it on the history
@@ -78,7 +77,28 @@
         return NULL;
 
     wline_read = new wchar_t[len + 1];
-    len = mbstowcs(wline_read, line_read, len + 1);
+    mbstowcs(wline_read, line_read, len + 1);
+
+    if (line_read)
+    {
+        free(line_read);
+    }
+#else
+    if (!cin.good())
+        return NULL;
+
+    cout << "commande> ";
+    string line;
+    std::getline(cin, line);
+
+    // Get the needed length (we _can't_ use string::size())
+    size_t len = mbstowcs(NULL, line.c_str(), 0);
+    if (len == (size_t)-1)
+        return NULL;
+
+    wline_read = new wchar_t[len + 1];
+    mbstowcs(wline_read, line.c_str(), len + 1);
+#endif
 
     return wline_read;
 }
@@ -86,7 +106,7 @@
 
 wchar_t * next_token_alpha(wchar_t *cmd, const wchar_t *delim, wchar_t **state)
 {
-    wchar_t *token = wcstok(cmd, delim, state);
+    wchar_t *token = _wcstok(cmd, delim, state);
     if (token == NULL)
         return NULL;
     int i;
@@ -99,7 +119,7 @@
 
 wchar_t * next_token_alphanum(wchar_t *cmd, const wchar_t *delim, wchar_t 
**state)
 {
-    wchar_t *token = wcstok(cmd, delim, state);
+    wchar_t *token = _wcstok(cmd, delim, state);
     if (token == NULL)
         return NULL;
     int i;
@@ -112,7 +132,7 @@
 
 wchar_t * next_token_alphaplusjoker(wchar_t *cmd, const wchar_t *delim, 
wchar_t **state)
 {
-    wchar_t *token = wcstok(cmd, delim, state);
+    wchar_t *token = _wcstok(cmd, delim, state);
     if (token == NULL)
         return NULL;
     int i;
@@ -128,7 +148,7 @@
 
 wchar_t * next_token_digit(wchar_t *cmd, const wchar_t *delim, wchar_t **state)
 {
-    wchar_t *token = wcstok(cmd, delim, state);
+    wchar_t *token = _wcstok(cmd, delim, state);
     if (token == NULL)
         return NULL;
     int i;
@@ -141,7 +161,7 @@
 
 wchar_t * next_token_cross(wchar_t *cmd, const wchar_t *delim, wchar_t **state)
 {
-    wchar_t *token = wcstok(cmd, delim, state);
+    wchar_t *token = _wcstok(cmd, delim, state);
     if (token == NULL)
         return NULL;
     int i;
@@ -156,7 +176,7 @@
 
 wchar_t * next_token_filename(wchar_t *cmd, const wchar_t *delim, wchar_t 
**state)
 {
-    wchar_t *token = wcstok(cmd, delim, state);
+    wchar_t *token = _wcstok(cmd, delim, state);
     if (token == NULL)
         return NULL;
     int i;
@@ -378,7 +398,7 @@
     while (quit == 0)
     {
         commande = rl_gets();
-        token = wcstok(commande, delim, &state);
+        token = _wcstok(commande, delim, &state);
         if (token)
         {
             switch (token[0])
@@ -512,7 +532,7 @@
     while (quit == 0)
     {
         commande = rl_gets();
-        token = wcstok(commande, delim, &state);
+        token = _wcstok(commande, delim, &state);
         if (token)
         {
             switch (token[0])
@@ -613,7 +633,7 @@
     while (quit == 0)
     {
         commande = rl_gets();
-        token = wcstok(commande, delim, &state);
+        token = _wcstok(commande, delim, &state);
         if (token)
         {
             switch (token[0])
@@ -768,10 +788,10 @@
     struct search_RegE_list_t llist;
     eliot_regexp_build_default_llist(iDic, llist);
 
-    wchar_t *regexp = wcstok(NULL, delim, state);
-    wchar_t *cnres = wcstok(NULL, delim, state);
-    wchar_t *clmin = wcstok(NULL, delim, state);
-    wchar_t *clmax = wcstok(NULL, delim, state);
+    wchar_t *regexp = _wcstok(NULL, delim, state);
+    wchar_t *cnres = _wcstok(NULL, delim, state);
+    wchar_t *clmin = _wcstok(NULL, delim, state);
+    wchar_t *clmax = _wcstok(NULL, delim, state);
 
     if (regexp == NULL)
     {
@@ -821,7 +841,7 @@
     while (quit == 0)
     {
         commande = rl_gets();
-        token = wcstok(commande, delim, &state);
+        token = _wcstok(commande, delim, &state);
         if (token)
         {
             switch (token[0])
@@ -987,9 +1007,7 @@
         main_loop(dic);
         GameFactory::Destroy();
 
-        // Free the readline static variable and its wide equivalent
-        if (line_read)
-            free(line_read);
+        // Free the readline static variable
         if (wline_read)
             delete[] wline_read;
     }




reply via email to

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