File: scrollz-encoding.patch

package info (click to toggle)
scrollz 2.1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 6,992 kB
  • ctags: 4,728
  • sloc: ansic: 78,409; tcl: 2,866; makefile: 682; sh: 508
file content (104 lines) | stat: -rw-r--r-- 3,715 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
commit 7b34b964d0c2478a3c6dab9eabe69fe60b9ea97f
Author: Klaus Ethgen <Klaus@Ethgen.de>
Date:   Wed Jun 18 21:49:11 2008 +0100

    Fixing the encoding to stay in sync with the documentation.
    
    The INPUT_ENCODING was set wrong to UTF-8. But the documentation says that the
    default is ISO-8859-1.
    
    This has the effect that scrollz do stop working when the first ISO-8859-1
    character > 0x7f is typed! The changes switch to the documented default and will
    work also if the real input encoding is not right as ISO-8859-1 is a full 8bit
    encoding.
    
    Please note that the historical default on IRC is allways a 8bit encoding.
    
    Futermore this will use the locale variables to set the encoding.
    
    Closes: #398345

diff --git a/include/config.h b/include/config.h
index 95ed923..73209ab 100644
--- a/include/config.h
+++ b/include/config.h
@@ -132,7 +132,7 @@
 #define DEFAULT_CTCP_REPLY_IGNORE_SECONDS 10
 #define DEFAULT_DCC_BLOCK_SIZE 2048
 #define DEFAULT_DISPLAY 1
-#define DEFAULT_DISPLAY_ENCODING "UTF-8"
+#define DEFAULT_DISPLAY_ENCODING "ISO8859-1"
 #define DEFAULT_DISPLAY_ANSI 1
 #define DEFAULT_EIGHT_BIT_CHARACTERS 1
 #define DEFAULT_ENCRYPT_PROGRAM NULL
@@ -156,10 +156,10 @@
 #define DEFAULT_HYPER_DCC 0
 #define DEFAULT_INDENT 1
 #define DEFAULT_INPUT_ALIASES 0
-#define DEFAULT_INPUT_ENCODING "UTF-8"
+#define DEFAULT_INPUT_ENCODING "ISO-8859-1"
 #define DEFAULT_INPUT_PROMPT NULL
 #define DEFAULT_INPUT_PROTECTION 1
-#define DEFAULT_IRC_ENCODING "UTF-8"
+#define DEFAULT_IRC_ENCODING "ISO-8859-1"
 #define DEFAULT_INSERT_MODE 1
 #define DEFAULT_INVERSE_VIDEO 1
 #define DEFAULT_ISO2022_SUPPORT 0
diff --git a/include/irc.h b/include/irc.h
index 8610fd6..069faf1 100644
--- a/include/irc.h
+++ b/include/irc.h
@@ -131,6 +131,9 @@
 # endif
 #endif
 
+#include <langinfo.h>
+#include <locale.h>
+
 #ifdef HAVE_SYS_SELECT_H
 # include <sys/select.h>
 #endif
diff --git a/source/vars.c b/source/vars.c
index 00a88a7..ebe0e61 100644
--- a/source/vars.c
+++ b/source/vars.c
@@ -351,6 +351,13 @@ init_variables()
 /**************************** PATCHED by Flier ******************************/
         int old_disp;
 /****************************************************************************/
+	char *charset;
+
+	/* Switch the locale to the environment values to get the right charset */
+	setlocale(LC_ALL, "");
+	charset = nl_langinfo(CODESET);
+	/* Switch back to the locale used before (POSIX or C) to prevent side effects. */
+	setlocale(LC_ALL, "C");
 
 	check_variable_order();
 
@@ -359,12 +366,22 @@ init_variables()
 	set_string_var(SHELL_VAR, DEFAULT_SHELL);
 	set_string_var(SHELL_FLAGS_VAR, DEFAULT_SHELL_FLAGS);
 	set_string_var(DECRYPT_PROGRAM_VAR, UP(DEFAULT_DECRYPT_PROGRAM));
-	set_string_var(DISPLAY_ENCODING_VAR, DEFAULT_DISPLAY_ENCODING);
 	set_string_var(ENCRYPT_PROGRAM_VAR, DEFAULT_ENCRYPT_PROGRAM);
 	set_string_var(CONTINUED_LINE_VAR, DEFAULT_CONTINUED_LINE);
-	set_string_var(INPUT_ENCODING_VAR, DEFAULT_INPUT_ENCODING);
+	if (charset == NULL || charset[0] == '\0')
+	{
+	   set_string_var(DISPLAY_ENCODING_VAR, DEFAULT_DISPLAY_ENCODING);
+	   set_string_var(INPUT_ENCODING_VAR, DEFAULT_INPUT_ENCODING);
+	   set_string_var(IRC_ENCODING_VAR, DEFAULT_IRC_ENCODING);
+	}
+	else
+	{
+	   set_string_var(DISPLAY_ENCODING_VAR, charset);
+	   set_string_var(INPUT_ENCODING_VAR, charset);
+	   set_string_var(IRC_ENCODING_VAR, charset);
+	}
+
 	set_string_var(INPUT_PROMPT_VAR, DEFAULT_INPUT_PROMPT);
-	set_string_var(IRC_ENCODING_VAR, DEFAULT_IRC_ENCODING);
 	set_string_var(HIGHLIGHT_CHAR_VAR, DEFAULT_HIGHLIGHT_CHAR);
 	set_string_var(HISTORY_FILE_VAR, DEFAULT_HISTORY_FILE);
 	set_string_var(LASTLOG_LEVEL_VAR, DEFAULT_LASTLOG_LEVEL);