Index: source/screen.c
===================================================================
RCS file: /home/cvs/repository/epic4/source/screen.c,v
retrieving revision 1.50
diff -u -3 -p -r1.50 screen.c
--- source/screen.c	9 May 2003 04:29:52 -0000	1.50
+++ source/screen.c	13 May 2003 20:50:20 -0000
@@ -33,6 +33,8 @@
  * SUCH DAMAGE.
  */
 
+#define FIXME_UTF8 1
+
 #define __need_putchar_x__
 #include "irc.h"
 #include "alias.h"
@@ -1562,14 +1564,16 @@ static 	int 	recursion = 0, 
 		firstwb = 0,	    /* Buffer position of second word */
 		line = 0,           /* Current pos in "output"      */
 		do_indent,          /* Use indent or continued line? */
-		newline = 0;        /* Number of newlines           */
+		newline = 0,        /* Number of newlines           */
+		utf8_bytes = 0;     /* # bytes making up a UTF-8 char */
 static	u_char 	**output = (unsigned char **)0;
 const 	u_char	*ptr;
 	u_char 	buffer[BIG_BUFFER_SIZE + 1],
 		*cont_ptr,
 		*cont = empty_string,
 		c,
-		*pos_copy;
+		*pos_copy,
+		utf8_char;
 	const char *words;
 	Attribute	a;
 	Attribute	saved_a;
@@ -1657,6 +1661,42 @@ const 	u_char	*ptr;
 
 			default:
 			{
+				/* Process UTF-8's multibyte chars - rain */
+				if (FIXME_UTF8) {
+					if ((*ptr & 0xc0) == 0xc0) {
+						/* UTF initial byte */
+						utf8_char = *ptr;
+
+						buffer[pos++] = utf8_char;
+
+						if (utf8_bytes) /* last sequence was invalid */
+							col++;
+						utf8_bytes = -1;
+						while ((utf8_char & 0x80) == 0x80) {
+							utf8_bytes++;
+							utf8_char <<= 1;
+						}
+//						fprintf(stderr, "u8 s 0x%02x + %d b\n", *ptr, utf8_bytes);
+						break; /* switch */
+					} else if (utf8_bytes && (*ptr & 0xc0) == 0x80) {
+						/* UTF following byte */
+						buffer[pos++] = *ptr;
+						utf8_bytes--;
+//						fprintf(stderr, "u8 c 0x%02x\n", *ptr);
+						if (!utf8_bytes) /* char complete */
+							col++;
+						break; /* switch */
+					} else if (utf8_bytes) {
+						/*
+						 * Incomplete UTF-8 sequence:
+						 * Abort!  Abort!
+						 */
+						utf8_bytes = 0;
+						col++; /* incomplete junk written */
+//						fprintf(stderr, "incomp u8\n");
+					}
+				}
+				/* FIXME: Disable this if inside a UTF8 char? */
 				if (!strchr(words, *ptr))
 				{
 					if (indent == -1)
@@ -1988,7 +2028,9 @@ static int 	rite (Window *window, const 
 int 	output_with_count (const unsigned char *str1, int clreol, int output)
 {
 	int 		beep = 0, 
-			out = 0;
+			out = 0,
+			utf8_bytes =0;
+	u_char		utf8_char;
 	Attribute	a;
 	const unsigned char *str;
 
@@ -2053,8 +2095,38 @@ int 	output_with_count (const unsigned c
 				 * that are nasty that get here, its probably
 				 * because the user specifically asked for it.
 				 */
+				
 				if (output)
 					putchar_x(*str);
+				if (FIXME_UTF8) {
+					if ((*str & 0xc0) == 0xc0) {
+						/* UTF initial byte */
+						utf8_char = *str;
+
+						if (utf8_bytes) /* last sequence was invalid */
+							out++;
+
+						utf8_bytes = -1;
+						while ((utf8_char & 0x80) == 0x80) {
+							utf8_bytes++;
+							utf8_char <<= 1;
+						}
+//						fprintf(stderr, "Xu8 s 0x%02x + %d b\n", *str, utf8_bytes);
+						break; /* switch */
+					} else if (utf8_bytes && (*str & 0xc0) == 0x80) {
+						/* UTF following byte */
+						utf8_bytes--;
+//						fprintf(stderr, "Xu8 c 0x%02x\n", *str);
+						if (!utf8_bytes) /* have a complete char */
+							out++;
+						break; /* switch */
+					} else if (utf8_bytes) {
+						/* Incomplete UTF-8 sequence */
+//						fprintf(stderr, "Xincomp u8\n");
+						out++; /* incomplete junk written */
+						utf8_bytes = 0;
+					}
+				}
 				out++;
 				break;
 			}
