Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 390215 | Differences between
and this patch

Collapse All | Expand All

(-)a/src/scroll.c (-3 / +40 lines)
Lines 34-45 Link Here
34
34
35
struct scroll_data {
35
struct scroll_data {
36
	char *text;
36
	char *text;
37
	unsigned int show_orig;
37
	unsigned int show;
38
	unsigned int show;
38
	unsigned int step;
39
	unsigned int step;
39
	unsigned int start;
40
	unsigned int start;
40
	long resetcolor;
41
	long resetcolor;
41
};
42
};
42
43
44
int utf8_charlen(char c) {
45
	unsigned char uc = (unsigned char) c;
46
	int len = 0;
47
48
	if ((uc & 0x80) == 0)
49
		return 1;
50
51
	while ((uc & 0x80) != 0) {
52
		++len;
53
		uc <<= 1;
54
	}
55
56
	return (len > 0 && len <= 4) ? len : -1;
57
}
58
59
int is_utf8_char_tail(char c) {
60
	unsigned char uc = (unsigned char) c;
61
	return (uc & 0xc0) == 0x80;
62
}
63
43
void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_crash)
64
void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_crash)
44
{
65
{
45
	struct scroll_data *sd;
66
	struct scroll_data *sd;
Lines 60-74 void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr Link Here
60
		sd->step = 1;
81
		sd->step = 1;
61
	}
82
	}
62
	sd->text = malloc(strlen(arg + n1) + sd->show + 1);
83
	sd->text = malloc(strlen(arg + n1) + sd->show + 1);
84
	sd->show_orig = sd->show;
63
85
64
	if (strlen(arg) > sd->show) {
86
	if (strlen(arg) > sd->show) {
65
		for(n2 = 0; (unsigned int) n2 < sd->show; n2++) {
87
		for(n2 = 0; (unsigned int) n2 < sd->show; n2++) {
66
		    sd->text[n2] = ' ';
88
			sd->text[n2] = ' ';
67
		}
89
		}
68
		sd->text[n2] = 0;
90
		sd->text[n2] = 0;
69
	}
91
	}
70
	else
92
	else
71
	    sd->text[0] = 0;
93
		sd->text[0] = 0;
72
94
73
	strcat(sd->text, arg + n1);
95
	strcat(sd->text, arg + n1);
74
	sd->start = 0;
96
	sd->start = 0;
Lines 82-87 void print_scroll(struct text_object *obj, char *p, int p_max_size, struct infor Link Here
82
{
104
{
83
	struct scroll_data *sd = obj->data.opaque;
105
	struct scroll_data *sd = obj->data.opaque;
84
	unsigned int j, colorchanges = 0, frontcolorchanges = 0, visibcolorchanges = 0, strend;
106
	unsigned int j, colorchanges = 0, frontcolorchanges = 0, visibcolorchanges = 0, strend;
107
	int charlen = 0;
108
	unsigned int utf8lenfix = 0;
85
	char *pwithcolors;
109
	char *pwithcolors;
86
	char buf[max_user_text];
110
	char buf[max_user_text];
87
111
Lines 109-114 void print_scroll(struct text_object *obj, char *p, int p_max_size, struct infor Link Here
109
	while(*(buf + sd->start) == SPECIAL_CHAR) {
133
	while(*(buf + sd->start) == SPECIAL_CHAR) {
110
		sd->start++;
134
		sd->start++;
111
	}
135
	}
136
	//skip parts of UTF-8 character which messes up display
137
	while(is_utf8_char_tail(*(buf + sd->start))) {
138
		sd->start++;
139
	}
112
	//place all chars that should be visible in p, including colorchanges
140
	//place all chars that should be visible in p, including colorchanges
113
	for(j=0; j < sd->show + visibcolorchanges; j++) {
141
	for(j=0; j < sd->show + visibcolorchanges; j++) {
114
		p[j] = *(buf + sd->start + j);
142
		p[j] = *(buf + sd->start + j);
Lines 117-123 void print_scroll(struct text_object *obj, char *p, int p_max_size, struct infor Link Here
117
		}
145
		}
118
		//if there is still room fill it with spaces
146
		//if there is still room fill it with spaces
119
		if( ! p[j]) break;
147
		if( ! p[j]) break;
148
149
		charlen = utf8_charlen(p[j]);
150
		if(charlen > 1 && charlen - 1 > sd->show + visibcolorchanges - j - 1) {
151
			//if the rest is a part of UTF-8 character fill that with spaces instead
152
			break;
153
		} else {
154
			//count visible length deficiency caused by UTF-8 chars
155
			utf8lenfix += (charlen > 1 ? charlen - 1 : 0);
156
		}
120
	}
157
	}
158
	sd->show = sd->show_orig + utf8lenfix;
121
	for(; j < sd->show + visibcolorchanges; j++) {
159
	for(; j < sd->show + visibcolorchanges; j++) {
122
		p[j] = ' ';
160
		p[j] = ' ';
123
	}
161
	}
124
- 

Return to bug 390215