cutbuffer fix by Pyun YongHyeon <yongari@kt-is.co.kr> 

  http://www.kr.freebsd.org/ml/ports/2001-October/000373.html

diff -ur hanterm-xf-2.0.0.org/automata.c hanterm-xf-2.0.0.new/automata.c
--- hanterm-xf-2.0.0.org/automata.c	Wed Jun 27 20:30:40 2001
+++ hanterm-xf-2.0.0.new/automata.c	Wed Oct 31 13:28:34 2001
@@ -137,12 +137,12 @@
 	    break;
     }
     if (ret || process_ret == COMPOSER_NULL) {
-	int c = han_compose_buf[0];
+	int cc = han_compose_buf[0];
 	han_compose_buf[0] = 0;
 	ScrnRefresh(&term->screen, 
 	    term->screen.cursor_row, term->screen.cursor_col,
 	    1, 2, True);
-	han_compose_buf[0] = c;
+	han_compose_buf[0] = cc;
 	term->screen.cursor_state = OFF;
     } else {
 	ShowCursor();
diff -ur hanterm-xf-2.0.0.org/button.c hanterm-xf-2.0.0.new/button.c
--- hanterm-xf-2.0.0.org/button.c	Mon Jun 25 12:15:03 2001
+++ hanterm-xf-2.0.0.new/button.c	Wed Oct 31 18:52:09 2001
@@ -962,25 +962,29 @@
     Atom selection;
     int cutbuffer;
     Atom target;
+    Cardinal i;
 
     if (!IsXtermWidget(w))
 	return;
 
     XmuInternStrings(XtDisplay(w), params, (Cardinal)1, &selection);
     switch (selection) {
-      case XA_CUT_BUFFER0: cutbuffer = 0; break;
-      case XA_CUT_BUFFER1: cutbuffer = 1; break;
-      case XA_CUT_BUFFER2: cutbuffer = 2; break;
-      case XA_CUT_BUFFER3: cutbuffer = 3; break;
-      case XA_CUT_BUFFER4: cutbuffer = 4; break;
-      case XA_CUT_BUFFER5: cutbuffer = 5; break;
-
-      case XA_CUT_BUFFER6: cutbuffer = 6; break;
-      case XA_CUT_BUFFER7: cutbuffer = 7; break;
-      default:		   cutbuffer = -1;
-    }
+	case XA_CUT_BUFFER0: cutbuffer = 0; break;
+	case XA_CUT_BUFFER1: cutbuffer = 1; break;
+	case XA_CUT_BUFFER2: cutbuffer = 2; break;
+	case XA_CUT_BUFFER3: cutbuffer = 3; break;
+	case XA_CUT_BUFFER4: cutbuffer = 4; break;
+	case XA_CUT_BUFFER5: cutbuffer = 5; break;
+
+	case XA_CUT_BUFFER6: cutbuffer = 6; break;
+	case XA_CUT_BUFFER7: cutbuffer = 7; break;
+	default:		   cutbuffer = -1;
+	}
+    /*
+     * core dump!!!
     TRACE(("Cutbuffer: %d, target: %lu\n", cutbuffer,
 	   (unsigned long)targets[0]));
+     */
     if (cutbuffer >= 0) {
 	int inbytes;
 	unsigned long nbytes;
@@ -1000,10 +1004,15 @@
 	if (targets == NULL || targets[0] == None) {
 	    targets = _SelectionTargets(w);
 	}
-
 	target = targets[0];
-
-	if (targets[1] == None) { /* last target in list */
+	for(i = 0; i < num_params; i++) {
+		target = targets[i];
+		XtGetSelectionValue(w, selection, target,
+				    SelectionReceived,
+				    (XtPointer)NULL, ev_time);
+		}
+	/*if (targets[1] == None) {*/ /* last target in list */
+/*
 	    params++;
 	    num_params--;
 	    targets = _SelectionTargets(w);
@@ -1018,11 +1027,20 @@
 	    list->targets = targets;
 	    list->time = ev_time;
 	} else list = NULL;
-
+*/
+/*
 	XtGetSelectionValue(w, selection,
 			    target,
 			    SelectionReceived,
 			    (XtPointer)list, ev_time);
+*/
+/*
+	Got "hanterm in free(): warning: junk pointer, too high to make sense."
+	XtGetSelectionValues(w, selection,
+			    targets, num_params,
+			    SelectionReceived,
+			    (XtPointer)list, ev_time);
+*/
     }
 }
 
@@ -1199,6 +1217,7 @@
 		char *tmp = malloc(len+1);
 		johab_from_wansung_str(tmp, text_list[i], len);
 		memcpy(text_list[i], tmp, len);
+		free(tmp);
 	    }
 #endif /* OPT_HANGUL */
             _WriteSelectionData(((XtermWidget)w)->screen.respond,
@@ -2226,7 +2245,8 @@
     }
     *lp = '\0';			/* make sure we have end marked */
 
-    TRACE(("Salted TEXT:%.*s\n", (char *)lp - line, line));
+    /*TRACE(("Salted TEXT:%.*s\n", (char *)lp - line, line));*/
+    TRACE(("Salted TEXT:%d, %s\n", (char *)lp - line, line));
     screen->selection_length = ((char *)lp - line);
     _OwnSelection(term, params, num_params);
 }
diff -ur hanterm-xf-2.0.0.org/charproc.c hanterm-xf-2.0.0.new/charproc.c
--- hanterm-xf-2.0.0.org/charproc.c	Wed Jun 27 20:30:23 2001
+++ hanterm-xf-2.0.0.new/charproc.c	Wed Oct 31 13:07:05 2001
@@ -5339,7 +5339,6 @@
 #if OPT_HANGUL
 	Char	clo[2];
 	GC	currentHGC;
-	extern int han_new_typed_row;
 #else /* OPT_HANGUL */
 	Char	clo;
 #endif /* OPT_HANGUL */
@@ -5672,7 +5671,6 @@
 	int	start_x, end_x;
 	Char	*flags_buf, *chars_buf;
 	GC	currentHGC;
-	extern	int han_new_typed_row;
 #else /* OPT_HANGUL */
 	Char	clo;
 #endif /* OPT_HANGUL */
diff -ur hanterm-xf-2.0.0.org/chat.c hanterm-xf-2.0.0.new/chat.c
--- hanterm-xf-2.0.0.org/chat.c	Mon Jun 25 13:47:24 2001
+++ hanterm-xf-2.0.0.new/chat.c	Wed Oct 31 13:33:43 2001
@@ -23,6 +23,7 @@
 void history(Char *, int);
 Char *history_previous(void);
 Char *history_next(void);
+void history_add(Char *str, int len);	/* history.c */
 
 
 int (*chat_callback)(int fd, Char *str, int len);
diff -ur hanterm-xf-2.0.0.org/composer/comp.h hanterm-xf-2.0.0.new/composer/comp.h
--- hanterm-xf-2.0.0.org/composer/comp.h	Sun Jun  3 16:31:51 2001
+++ hanterm-xf-2.0.0.new/composer/comp.h	Wed Oct 31 13:51:50 2001
@@ -26,5 +26,6 @@
 int composer_has_temp_hangul(Composer *composer);
 Keymap * composer_get_keymap(Composer *composer);
 void composer_free(Composer *composer);
+Composer *composer_new_with_keyboard(char *keyboard);
 
 #endif
diff -ur hanterm-xf-2.0.0.org/composer/johabcode2.c hanterm-xf-2.0.0.new/composer/johabcode2.c
--- hanterm-xf-2.0.0.org/composer/johabcode2.c	Mon Jun 11 18:16:38 2001
+++ hanterm-xf-2.0.0.new/composer/johabcode2.c	Wed Oct 31 14:01:08 2001
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <iconv.h>
+#include "johabcode.h"
 
 #if defined(__sun__)
 #define CD_EUC_KR "ko_KR-euc"
diff -ur hanterm-xf-2.0.0.org/hangul.h hanterm-xf-2.0.0.new/hangul.h
--- hanterm-xf-2.0.0.org/hangul.h	Tue Jun 26 18:58:57 2001
+++ hanterm-xf-2.0.0.new/hangul.h	Wed Oct 31 13:36:12 2001
@@ -48,6 +48,8 @@
 extern int han_eng_descent;
 extern int han_no_status_line;
 extern int han_font_width_check;
+extern int han_new_typed_row;
+extern  int han_new_typed_row;
 
 #define XtNhangulFont  "hangulFont"
 #define XtNhangulBoldFont  "hangulBoldFont"
@@ -112,6 +114,7 @@
 extern void HandleChangeKeyboard PROTO_XT_ACTIONS_ARGS;
 extern void HandleCodeInput PROTO_XT_ACTIONS_ARGS;
 extern void HandleHanjaInput PROTO_XT_ACTIONS_ARGS;
+void han_set_code_to_font(char *charset_registry);
 extern void HDrawImageString(Display *, Window, GC, GC, int, int,
 			     Char *, int);
 extern void HDrawString(Display *, Window, GC, GC, int, int,
@@ -136,10 +139,15 @@
 extern void show_chat_buf(void);
 extern void chat_input(Char *str, int len);
 extern void chat_show_cursor(void);
+void chat_mode_toggle_hangul(void);
+void chat_mode_flush_hangul(void);
 #else
 #define chat_mode (0)
 #endif /* OPT_CHAT */
 
+#if OPT_NOW_CHAT_SCROLL_PATCH
+void ScrnMoveLine (register ScrnBuf sb, int src, int dest, int n, int size);
+#endif
 /* hanja.c */
 extern void hanja_mode_input(KeySym keysym, XKeyEvent *event,
 			     Char *str, int nbytes);
@@ -152,7 +160,7 @@
 void hangul_set_keyboard(int keyboard);
 void hangul_automata_clear(void);
 int hangul_automata(int c, Char *buf);
-void hangul_automata_init();
+void hangul_automata_init(void);
 int hangul_automata_flush(Char *buf);
 int hangul_automata_toggle(Char *buf);
 
diff -ur hanterm-xf-2.0.0.org/hanutil.c hanterm-xf-2.0.0.new/hanutil.c
--- hanterm-xf-2.0.0.org/hanutil.c	Thu Jun  7 19:09:51 2001
+++ hanterm-xf-2.0.0.new/hanutil.c	Wed Oct 31 13:46:09 2001
@@ -97,6 +97,7 @@
       charset_registry = hfont_fullname;
     }
     han_set_code_to_font(charset_registry);
+    return 1;
 }
 
 void
diff -ur hanterm-xf-2.0.0.org/hfont.c hanterm-xf-2.0.0.new/hfont.c
--- hanterm-xf-2.0.0.org/hfont.c	Wed Jun 27 22:09:09 2001
+++ hanterm-xf-2.0.0.new/hfont.c	Wed Oct 31 14:02:27 2001
@@ -2,6 +2,7 @@
 
 #if OPT_HANGUL
 #include "hfont.h"
+#include "johabcode.h"
 
 /* ¹ÞÄ§ÀÌ ¾øÀ» ¶§ (¸ðÀ½) ¿¡ µû¶ó ¾î¶² ¸ð¾çÀÇ ÃÊ¼ºÀ» ¾µ °ÇÁö °áÁ¤ */
 
diff -ur hanterm-xf-2.0.0.org/history.c hanterm-xf-2.0.0.new/history.c
--- hanterm-xf-2.0.0.org/history.c	Sat May 26 15:21:36 2001
+++ hanterm-xf-2.0.0.new/history.c	Wed Oct 31 13:48:16 2001
@@ -16,6 +16,12 @@
 static int history_offset;
 static int history_length;
 
+void history_init(void);	/* duplicated: chat.c */
+void history_reset(void);
+Char *history_previous(void);
+Char *history_next(void);
+void history_add(Char *str, int len);
+
 void 
 history_init(void)
 {
diff -ur hanterm-xf-2.0.0.org/menu.c hanterm-xf-2.0.0.new/menu.c
--- hanterm-xf-2.0.0.org/menu.c	Thu May 24 10:48:39 2001
+++ hanterm-xf-2.0.0.new/menu.c	Wed Oct 31 13:19:45 2001
@@ -143,6 +143,8 @@
 
 #if OPT_NOW_CHAT_SCROLL_PATCH
 static void do_nowchat         PROTO_XT_CALLBACK_ARGS;
+void HandleNowChat(Widget w, XEvent *event,
+		String *params, Cardinal *param_count);
 #endif /* OPT_NOW_CHAT_SCROLL_PATCH */
 
 #if OPT_SCO_FUNC_KEYS
diff -ur hanterm-xf-2.0.0.org/screen.c hanterm-xf-2.0.0.new/screen.c
--- hanterm-xf-2.0.0.org/screen.c	Wed Jun 27 20:24:42 2001
+++ hanterm-xf-2.0.0.new/screen.c	Wed Oct 31 13:25:36 2001
@@ -480,7 +480,7 @@
 }
 
 #if OPT_NOW_CHAT_SCROLL_PATCH
-int
+void
 ScrnMoveLine (register ScrnBuf sb, int src, int dest, int n, int size)
 {
     char *save;
@@ -488,7 +488,7 @@
     if ((save = alloca(n)) == NULL)
     {
 	fprintf(stderr, "ScrnMoveLine: alloca failed (size=%d)!\n", n);
-	return 0;
+	return;
     }
     memcpy(save, &sb[MAX_PTRS * src], n);
     memcpy(&sb[MAX_PTRS * src], &sb[MAX_PTRS * dest], n);
diff -ur hanterm-xf-2.0.0.org/util.c hanterm-xf-2.0.0.new/util.c
--- hanterm-xf-2.0.0.org/util.c	Wed Jun 27 20:26:08 2001
+++ hanterm-xf-2.0.0.new/util.c	Wed Oct 31 15:55:13 2001
@@ -1752,10 +1752,13 @@
 
 	/* If the font is complete, draw it as-is */
 	if (screen->fnt_boxes && !screen->force_box_chars) {
+		/*
+		 * core dump!!!
 		TRACE(("drawtext%c[%4d,%4d] (%d) %d:%s\n",
 			screen->cursor_state == OFF ? ' ' : '*',
 			y, x, chrset, len,
 			visibleChars(PAIRED_CHARS(text, text2), len)));
+		 */
 		y += FontAscent(screen);
 
 #if OPT_WIDE_CHARS
