Gentoo Archives: gentoo-commits

From: "Daniel Pielmeier (billie)" <billie@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in app-admin/conky/files: conky-1.8.1-utf8-scroll.patch
Date: Wed, 16 Nov 2011 19:50:44
Message-Id: 20111116195034.624422004C@flycatcher.gentoo.org
1 billie 11/11/16 19:50:34
2
3 Added: conky-1.8.1-utf8-scroll.patch
4 Log:
5 Fix scroll variable for utf8. This fixes bug #390215. Thanks to Amadeusz Żołnowski for the report and the patch.
6
7 (Portage version: 2.1.10.34/cvs/Linux i686)
8
9 Revision Changes Path
10 1.1 app-admin/conky/files/conky-1.8.1-utf8-scroll.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-admin/conky/files/conky-1.8.1-utf8-scroll.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-admin/conky/files/conky-1.8.1-utf8-scroll.patch?rev=1.1&content-type=text/plain
14
15 Index: conky-1.8.1-utf8-scroll.patch
16 ===================================================================
17 From b1f6a30bcce020b3c377434137de9856a09b899a Mon Sep 17 00:00:00 2001
18 From: =?UTF-8?q?Amadeusz=20=C5=BBo=C5=82nowski?= <aidecoe@×××××××.name>
19 Date: Fri, 11 Nov 2011 11:27:43 +0100
20 Subject: [PATCH] Make scroll UTF-8 aware. Fixes bug #3134941.
21
22 ---
23 src/scroll.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
24 1 files changed, 42 insertions(+), 2 deletions(-)
25
26 diff --git a/src/scroll.c b/src/scroll.c
27 index f78f807..738db0d 100644
28 --- a/src/scroll.c
29 +++ b/src/scroll.c
30 @@ -34,12 +34,33 @@
31
32 struct scroll_data {
33 char *text;
34 + unsigned int show_orig;
35 unsigned int show;
36 unsigned int step;
37 unsigned int start;
38 long resetcolor;
39 };
40
41 +int utf8_charlen(char c) {
42 + unsigned char uc = (unsigned char) c;
43 + int len = 0;
44 +
45 + if ((uc & 0x80) == 0)
46 + return 1;
47 +
48 + while ((uc & 0x80) != 0) {
49 + ++len;
50 + uc <<= 1;
51 + }
52 +
53 + return (len > 0 && len <= 4) ? len : -1;
54 +}
55 +
56 +int is_utf8_char_tail(char c) {
57 + unsigned char uc = (unsigned char) c;
58 + return (uc & 0xc0) == 0x80;
59 +}
60 +
61 void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_crash)
62 {
63 struct scroll_data *sd;
64 @@ -60,15 +81,18 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr
65 sd->step = 1;
66 }
67 sd->text = malloc(strlen(arg + n1) + sd->show + 1);
68 + // sd->show value may change when there are UTF-8 chars to be shown, so
69 + // save its origin value
70 + sd->show_orig = sd->show;
71
72 if (strlen(arg) > sd->show) {
73 for(n2 = 0; (unsigned int) n2 < sd->show; n2++) {
74 - sd->text[n2] = ' ';
75 + sd->text[n2] = ' ';
76 }
77 sd->text[n2] = 0;
78 }
79 else
80 - sd->text[0] = 0;
81 + sd->text[0] = 0;
82
83 strcat(sd->text, arg + n1);
84 sd->start = 0;
85 @@ -82,9 +106,13 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size, struct infor
86 {
87 struct scroll_data *sd = obj->data.opaque;
88 unsigned int j, colorchanges = 0, frontcolorchanges = 0, visibcolorchanges = 0, strend;
89 + int charlen = 0;
90 + unsigned int utf8lenfix = 0;
91 char *pwithcolors;
92 char buf[max_user_text];
93
94 + sd->show = sd->show_orig;
95 +
96 if (!sd)
97 return;
98
99 @@ -109,6 +137,18 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size, struct infor
100 while(*(buf + sd->start) == SPECIAL_CHAR) {
101 sd->start++;
102 }
103 + //skip parts of UTF-8 character which messes up display
104 + while(is_utf8_char_tail(*(buf + sd->start))) {
105 + sd->start++;
106 + }
107 + //extend length to be shown for wide characters
108 + j = 0;
109 + while(j < sd->show + visibcolorchanges + utf8lenfix) {
110 + charlen = utf8_charlen(*(buf + sd->start + j));
111 + utf8lenfix += (charlen > 1 ? charlen - 1 : 0);
112 + j += charlen;
113 + }
114 + sd->show = sd->show_orig + utf8lenfix;
115 //place all chars that should be visible in p, including colorchanges
116 for(j=0; j < sd->show + visibcolorchanges; j++) {
117 p[j] = *(buf + sd->start + j);
118 --
119 1.7.8.rc1