Utf-8

From Base de connaissances eggdrops & TCL
Jump to: navigation, search

Ceci devrait activer le support de l'UTF-8 sur votre Eggdrop.

Attention.png A n'utiliser que sous votre propre responsabilité, et ça ne résoudra pas tous vos soucis d'encodage

Patch

Step 1

Ouvrir le fichier eggdrop1.6.21/src/main.h aux alentours de la ligne 46 et remplacer

#if (((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 1)) {{!}}{{!}} (TCL_MAJOR_VERSION > 8))
#  define USE_TCL_BYTE_ARRAYS
#  define USE_TCL_ENCODING
#endif

par

#if (((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 1)) {{!}}{{!}} (TCL_MAJOR_VERSION > 8))
#  undef USE_TCL_BYTE_ARRAYS
#  define USE_TCL_ENCODING
#endif

Step 2

Ouvrir le fichier eggdrop1.6.21/src/tcl.c aux alentours de la ligne 650 et insérer juste après

if (encoding == NULL) {
  encoding = "iso8859-1";
}

la ligne

encoding = "utf-8";

Step 3

Recompiler Eggdrop.

Canaux UTF-8

Si l'eggdrop n'arrive pas à rejoindre les canaux UTF-8, c'est probablement parce que le patch est incomplet.

diff -urN eggdrop1.6.19.original/src/chanprog.c eggdrop1.6.19.modified/src/chanprog.c
--- eggdrop1.6.19.original/src/chanprog.c       2008-02-16 22:41:03.000000000 +0100
+++ eggdrop1.6.19.modified/src/chanprog.c       2010-06-21 14:24:27.000000000 +0200
@@ -444,7 +444,7 @@
   protect_readonly = 0;
 
   /* Now read it */
-  if (!readtclprog(configfile))
+  if (!readtclprog(configfile, 0))
     fatal(MISC_NOCONFIGFILE, 0);
 
   for (i = 0; i < max_logs; i++) {
diff -urN eggdrop1.6.19.original/src/mod/channels.mod/channels.c eggdrop1.6.19.modified/src/mod/channels.mod/channels.c
--- eggdrop1.6.19.original/src/mod/channels.mod/channels.c      2008-02-16 22:41:06.000000000 +0100
+++ eggdrop1.6.19.modified/src/mod/channels.mod/channels.c      2010-06-21 14:24:27.000000000 +0200
@@ -498,7 +498,7 @@
     if (!channel_static(chan))
       chan->status |= CHAN_FLAGGED;
   chan_hack = 1;
-  if (!readtclprog(chanfile) && create) {
+  if (!readtclprog(chanfile, 1) && create) {
     FILE *f;
 
     /* Assume file isnt there & therfore make it */
diff -urN eggdrop1.6.19.original/src/mod/module.h eggdrop1.6.19.modified/src/mod/module.h
--- eggdrop1.6.19.original/src/mod/module.h     2008-02-16 22:41:06.000000000 +0100
+++ eggdrop1.6.19.modified/src/mod/module.h     2010-06-21 14:29:54.000000000 +0200
@@ -282,7 +282,7 @@
 #define copyfile ((int (*) (char *, char *))global[147])
 /* 148 - 151 */
 #define do_tcl ((void (*)(char *, char *))global[148])
-#define readtclprog ((int (*)(const char *))global[149])
+#define readtclprog ((int (*)(const char *, int))global[149])
 #define get_language ((char *(*)(int))global[150])
 #define def_get ((void *(*)(struct userrec *, struct user_entry *))global[151])
 /* 152 - 155 */
diff -urN eggdrop1.6.19.original/src/proto.h eggdrop1.6.19.modified/src/proto.h
--- eggdrop1.6.19.original/src/proto.h  2008-02-16 22:41:04.000000000 +0100
+++ eggdrop1.6.19.modified/src/proto.h  2010-06-21 14:30:06.000000000 +0200
@@ -270,7 +270,7 @@
 void protect_tcl();
 void unprotect_tcl();
 void do_tcl(char *, char *);
-int readtclprog(char *fname);
+int readtclprog(char *fname, int);
 
 /* userent.c */
 void list_type_kill(struct list_type *);
diff -urN eggdrop1.6.19.original/src/tcl.c eggdrop1.6.19.modified/src/tcl.c
--- eggdrop1.6.19.original/src/tcl.c    2008-02-16 22:41:04.000000000 +0100
+++ eggdrop1.6.19.modified/src/tcl.c    2010-06-21 14:26:57.000000000 +0200
@@ -725,21 +725,34 @@
  *
  * returns:   1 - if everything was okay
  */
-int readtclprog(char *fname)
+int readtclprog(char *fname, int noencoding)
 {
   int code;
   char *result;
 #ifdef USE_TCL_ENCODING
+  char *encoding = NULL;
   Tcl_DString dstr;
 #endif
 
   if (!file_readable(fname))
     return 0;
 
+#ifdef USE_TCL_ENCODING
+  if (noencoding && Tcl_Eval(interp, "encoding system") == TCL_OK) {
+    encoding = nmalloc(strlen(interp->result)+1);
+    strcpy(encoding, interp->result);
+    Tcl_SetSystemEncoding(interp, "identity");
+  }
+#endif
+
   code = Tcl_EvalFile(interp, fname);
   result = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY);
 
 #ifdef USE_TCL_ENCODING
+  if (noencoding && encoding) {
+    Tcl_SetSystemEncoding(interp, encoding);
+    nfree(encoding);
+  }
   /* properly convert string to system encoding. */
   Tcl_DStringInit(&dstr);
   Tcl_UtfToExternalDString(NULL, result, -1, &dstr);

Merci à Thommey : http://forum.egghelp.org/viewtopic.php?p=93395#93395