Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Mar 2002 02:44:59 +0800 (CST)
From:      Chou Yeh-Jyi <yjchou@cis.nctu.edu.tw>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   ports/35485: [PATCH] Upgrade chinese/irssi to 0.8.1
Message-ID:  <200203021844.g22Iixk89221@dcspc2.cis.nctu.edu.tw>

next in thread | raw e-mail | index | archive | help

>Number:         35485
>Category:       ports
>Synopsis:       [PATCH] Upgrade chinese/irssi to 0.8.1
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 02 10:50:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Chou Yeh-Jyi
>Release:        FreeBSD 4.5-STABLE i386
>Organization:
>Environment:
System: FreeBSD dcspc2.cis.nctu.edu.tw 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Jan 30 16:53:33 CST 2002 root@dcspc2.cis.nctu.edu.tw:/usr/obj/usr/src/sys/Age i386


>Description:
	Upgrade chinese/irssi to 0.8.1 , fix the BROKEN problem.

	* Add line-wrap support with big5 charset.
	* Add multibytes cursor movement support with big5 charset. 

>How-To-Repeat:
	N/A
>Fix:

diff -urN irssi-0.8.1.orig/src/fe-text/gui-entry.c irssi-0.8.1/src/fe-text/gui-entry.c
--- irssi-0.8.1.orig/src/fe-text/gui-entry.c	Sat Feb 16 19:10:11 2002
+++ irssi-0.8.1/src/fe-text/gui-entry.c	Sun Mar  3 02:17:07 2002
@@ -67,6 +67,27 @@
         g_free(entry);
 }
 
+/* Fixes the cursor position if it at big5_lo .
+   Direct: -1    ,  left shift 1 byte.
+   Direct: 0, +1 ,  right shift 1 byte.
+*/
+static int _fix_big5_pos(unichar *p, int pos, int direct)
+{
+	int newpos;
+
+	for (newpos=0; newpos<pos && p[newpos] != 0; ) {
+		if (is_big5(p[newpos], p[newpos+1]))
+			newpos += 2;
+		else
+			newpos ++;
+	}
+
+	if (newpos != pos)
+		pos += direct > 0 ? 1 : -1;
+
+	return pos;
+}
+
 /* Fixes the cursor position in screen */
 static void gui_entry_fix_cursor(GUI_ENTRY_REC *entry)
 {
@@ -84,6 +105,8 @@
 		entry->scrstart = entry->pos - entry->scrpos;
 	}
 
+	entry->scrstart = _fix_big5_pos(entry->text, entry->scrstart, -1);
+
 	if (old_scrstart != entry->scrstart)
                 entry->redraw_needed_from = 0;
 }
@@ -335,11 +358,18 @@
 
 void gui_entry_erase(GUI_ENTRY_REC *entry, int size)
 {
+	int newpos;
+
         g_return_if_fail(entry != NULL);
 
 	if (entry->pos < size)
 		return;
 
+	/* recount the erase size with big5 charsets */
+	for (newpos = entry->pos; newpos >= 0 && size > 0; size--)
+		newpos = _fix_big5_pos(entry->text, newpos-1, -1);
+	size = entry->pos - newpos;
+
         /* put erased text to cutbuffer */
 	if (entry->cutbuffer == NULL || entry->cutbuffer_len < size) {
 		g_free(entry->cutbuffer);
@@ -461,10 +491,24 @@
 
 void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos)
 {
+	int newpos;
+
         g_return_if_fail(entry != NULL);
 
-	if (entry->pos+pos >= 0 && entry->pos+pos <= entry->text_len)
-		entry->pos += pos;
+	/* move cursor with big5 charset */
+	newpos = _fix_big5_pos(entry->text, entry->pos, -1);
+	if (pos > 0) {
+		while (pos > 0 && newpos < entry->text_len) {
+			newpos = _fix_big5_pos(entry->text, newpos+1, 1);
+			pos --;
+		}
+	} else {
+		while (pos < 0 && newpos > 0) {
+			newpos = _fix_big5_pos(entry->text, newpos-1, -1);
+			pos ++;
+		}
+	}
+	entry->pos = newpos;
 
 	gui_entry_fix_cursor(entry);
 	gui_entry_draw(entry);
diff -urN irssi-0.8.1.orig/src/fe-text/term-terminfo.c irssi-0.8.1/src/fe-text/term-terminfo.c
--- irssi-0.8.1.orig/src/fe-text/term-terminfo.c	Sun Feb 17 23:48:32 2002
+++ irssi-0.8.1/src/fe-text/term-terminfo.c	Sun Mar  3 02:38:03 2002
@@ -549,12 +549,6 @@
 	}
 }
 
-/* XXX I didn't check the encoding range of big5+. This is standard big5. */
-#define is_big5_los(lo) (0x40 <= (lo) && (lo) <= 0x7E) /* standard */
-#define is_big5_lox(lo) (0x80 <= (lo) && (lo) <= 0xFE) /* extended */
-#define is_big5_hi(hi)  (0x81 <= (hi) && (hi) <= 0xFE)
-#define is_big5(hi,lo) (is_big5_hi(hi) && (is_big5_los(lo) || is_big5_lox(lo)))
-
 static int input_big5(const unsigned char *buffer, int size, unichar *result)
 {
 	if (is_big5_hi(*buffer)) {
diff -urN irssi-0.8.1.orig/src/fe-text/textbuffer-view.c irssi-0.8.1/src/fe-text/textbuffer-view.c
--- irssi-0.8.1.orig/src/fe-text/textbuffer-view.c	Fri Feb 15 22:10:10 2002
+++ irssi-0.8.1/src/fe-text/textbuffer-view.c	Sun Mar  3 02:17:07 2002
@@ -194,7 +194,7 @@
 			continue;
 		}
 
-		if (xpos == view->width && sub != NULL &&
+		if (xpos >= view->width && sub != NULL &&
 		    (last_space <= indent_pos || last_space <= 10) &&
 		    view->longword_noindent) {
                         /* long word, remove the indentation from this line */
@@ -202,7 +202,7 @@
                         sub->indent = 0;
 		}
 
-		if (xpos == view->width) {
+		if (xpos >= view->width) {
 			xpos = indent_func == NULL ? indent_pos :
 				indent_func(view, line, -1);
 
@@ -233,12 +233,21 @@
 		if (view->utf8)
 			get_utf8_char(&ptr, 6);
 
-		xpos++;
-		if (*ptr++ == ' ') {
+		/* set line-wrap data with big5 charset */
+		xpos ++;
+		if (ptr[1] != '\0' && is_big5(ptr[0], ptr[1])) {
 			last_space = xpos-1;
+			xpos ++;
+			if (xpos < view->width)
+				ptr += 2;
 			last_space_ptr = ptr;
 			last_color = color;
-		}
+		} else if (*ptr == ' ') {
+			last_space = xpos-1;
+			last_space_ptr = ++ptr;
+			last_color = color;
+		} else
+			ptr++;
 	}
 
 	rec = g_malloc(sizeof(LINE_CACHE_REC)-sizeof(LINE_CACHE_SUB_REC) +
diff -urN irssi-0.8.1.orig/src/fe-text/utf8.h irssi-0.8.1/src/fe-text/utf8.h
--- irssi-0.8.1.orig/src/fe-text/utf8.h	Sun Feb 17 23:10:09 2002
+++ irssi-0.8.1/src/fe-text/utf8.h	Sun Mar  3 02:38:07 2002
@@ -18,4 +18,11 @@
    Make sure out is at least 6 x length of str. */
 void utf16_to_utf8(const unichar *str, char *out);
 
+/* XXX I didn't check the encoding range of big5+. This is standard big5. */
+#define is_big5_los(lo) (0x40 <= (lo) && (lo) <= 0x7E) /* standard */
+#define is_big5_lox(lo) (0x80 <= (lo) && (lo) <= 0xFE) /* extended */
+#define is_big5_lo(lo)	((is_big5_los(lo) || is_big5_lox(lo)))
+#define is_big5_hi(hi)  (0x81 <= (hi) && (hi) <= 0xFE)
+#define is_big5(hi,lo) (is_big5_hi(hi) && is_big5_lo(lo))
+
 #endif
>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203021844.g22Iixk89221>