[817] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r811 - branches/barnowl_unicode/owl

daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:10:01 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Wed,  9 Jan 2008 14:17:58 -0500 (EST)

Author: asedeno
Date: 2008-01-09 14:17:57 -0500 (Wed, 09 Jan 2008)
New Revision: 811

Modified:
   branches/barnowl_unicode/owl/keymap.c
   branches/barnowl_unicode/owl/keypress.c
   branches/barnowl_unicode/owl/keys.c
   branches/barnowl_unicode/owl/owl.c
   branches/barnowl_unicode/owl/owl.h
Log:
take two for input processing

Modified: branches/barnowl_unicode/owl/keymap.c
===================================================================
--- branches/barnowl_unicode/owl/keymap.c	2008-01-09 07:23:31 UTC (rev 810)
+++ branches/barnowl_unicode/owl/keymap.c	2008-01-09 19:17:57 UTC (rev 811)
@@ -4,7 +4,7 @@
 static const char fileIdent[] = "$Id$";
 
 /* returns 0 on success */
-int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)(int), void (*prealways_fn)(int), void (*postalways_fn)(int))
+int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)(owl_input), void (*prealways_fn)(owl_input), void (*postalways_fn)(owl_input))
 {
   if (!name || !desc) return(-1);
   if ((km->name = owl_strdup(name)) == NULL) return(-1);
@@ -150,7 +150,7 @@
   owl_dict_insert_element(&kh->keymaps, km->name, km, NULL);
 }
 
-owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)(int), void (*prealways_fn)(int), void (*postalways_fn)(int))
+owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)(owl_input), void (*prealways_fn)(owl_input), void (*postalways_fn)(owl_input))
 {
   owl_keymap *km;
   km = (owl_keymap*)owl_malloc(sizeof(owl_keymap));
@@ -201,7 +201,7 @@
 
 /* processes a keypress.  returns 0 if the keypress was handled,
  * 1 if not handled, -1 on error, and -2 if j==ERR. */
-int owl_keyhandler_process(owl_keyhandler *kh, gunichar j)
+int owl_keyhandler_process(owl_keyhandler *kh, owl_input j)
 {
   owl_keymap     *km;
   owl_keybinding *kb;
@@ -213,7 +213,7 @@
   }
 
   /* temporarily disallow C-`/C-SPACE until we fix associated bugs */
-  if (j==ERR || j==0) {
+  if (j.ch == ERR || j.ch == 0) {
 	return(-1);
   }
 
@@ -223,16 +223,16 @@
   */
 
   /* deal with ESC prefixing */
-  if (!kh->in_esc && j==27) {
+  if (!kh->in_esc && j.ch == 27) {
     kh->in_esc = 1;
     return(0);
   }
   if (kh->in_esc) {
-    j = OWL_META(j);
+    j.ch = OWL_META(j.ch);
     kh->in_esc = 0;
   }
   
-  kh->kpstack[++(kh->kpstackpos)] = j;
+  kh->kpstack[++(kh->kpstackpos)] = j.ch;
   if (kh->kpstackpos >= OWL_KEYMAP_MAXSTACK) {
     owl_keyhandler_reset(kh);
     owl_function_makemsg("Too many prefix keys pressed...");
@@ -259,7 +259,7 @@
 	return(0);
       } else if (match == 2) {	/* exact match */
 	/* owl_function_debugmsg("processkey: found exact match in %s", km->name); */
-	owl_keybinding_execute(kb, j);
+	owl_keybinding_execute(kb, j.ch);
 	owl_keyhandler_reset(kh);
 	if (km->postalways_fn) {
 	  km->postalways_fn(j);

Modified: branches/barnowl_unicode/owl/keypress.c
===================================================================
--- branches/barnowl_unicode/owl/keypress.c	2008-01-09 07:23:31 UTC (rev 810)
+++ branches/barnowl_unicode/owl/keypress.c	2008-01-09 19:17:57 UTC (rev 811)
@@ -147,7 +147,7 @@
     }
   }
   if (!*kb) {
-    if (j&OWL_META(0)) {
+    if (j & OWL_META(0)) {
       strcat(kb, "M-");
       j &= ~OWL_META(0);
     }
@@ -162,6 +162,7 @@
       kb2[1] = 0;
       strcat(kb, kb2);    
     }
+    
   }  
   if (!*kb) {
     /* not a valid key */

Modified: branches/barnowl_unicode/owl/keys.c
===================================================================
--- branches/barnowl_unicode/owl/keys.c	2008-01-09 07:23:31 UTC (rev 810)
+++ branches/barnowl_unicode/owl/keys.c	2008-01-09 19:17:57 UTC (rev 811)
@@ -293,27 +293,29 @@
 /********************* Support Functions ************************/
 /****************************************************************/
 
-void owl_keys_recwin_prealways(int j) {
+void owl_keys_recwin_prealways(owl_input j) {
   /* Clear the message line on subsequent key presses */
   owl_function_makemsg("");
 }
 
-void owl_keys_editwin_default(int j) {
+void owl_keys_editwin_default(owl_input j) {
   owl_editwin *e;
-  if (NULL != (e=owl_global_get_typwin(&g))) {
-    owl_editwin_process_char(e, j);
+  if (NULL != (e=owl_global_get_typwin(&g))
+      && j.ch < 0x100) {
+       owl_editwin_process_char(e, j.uch);
   }
 }
 
-void owl_keys_editwin_postalways(int j) {
+void owl_keys_editwin_postalways(owl_input j) {
   owl_editwin *e;
-  if (NULL != (e=owl_global_get_typwin(&g))) {
-    owl_editwin_post_process_char(e, j);
+  if (NULL != (e=owl_global_get_typwin(&g))
+      && j.ch < 0x100) {
+    owl_editwin_post_process_char(e, j.uch);
   }  
   owl_global_set_needrefresh(&g);
 }
 
-void owl_keys_popless_postalways(int j) {
+void owl_keys_popless_postalways(owl_input j) {
   owl_viewwin *v = owl_global_get_viewwin(&g);
   owl_popwin *pw = owl_global_get_popwin(&g);
 
@@ -322,9 +324,9 @@
   }  
 }
 
-void owl_keys_default_invalid(int j) {
-  if (j==ERR) return;
-  if (j==410) return;
+void owl_keys_default_invalid(owl_input j) {
+  if (j.ch==ERR) return;
+  if (j.ch==410) return;
   owl_keyhandler_invalidkey(owl_global_get_keyhandler(&g));
 }
 

Modified: branches/barnowl_unicode/owl/owl.c
===================================================================
--- branches/barnowl_unicode/owl/owl.c	2008-01-09 07:23:31 UTC (rev 810)
+++ branches/barnowl_unicode/owl/owl.c	2008-01-09 19:17:57 UTC (rev 811)
@@ -70,7 +70,7 @@
   owl_editwin *tw;
   owl_popwin *pw;
   int ret, initialsubs, debug, argcsave, followlast;
-  gunichar j;
+  owl_input j;
   int newmsgs, nexttimediff;
   struct sigaction sigact;
   char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE];
@@ -545,38 +545,43 @@
     /* Handle all keypresses.  If no key has been pressed, sleep for a
      * little bit, but otherwise do not.  This lets input be grabbed
      * as quickly as possbile */
-    j=wgetch(typwin);
-    if (j == ERR
-#ifdef KEY_RESIZE
-	|| j == KEY_RESIZE
-#endif
-	 ) {
+    j.ch = wgetch(typwin);
+    if (j.ch == ERR) {
       usleep(10000);
     } else {
-      /* Pull in a full utf-8 character. */
-      if (j & 0x80) {
-	char utf8buf[7];
+      j.uch = '\0';
+      if (j.ch >= KEY_MIN && j.ch <= KEY_MAX) {
+	/* This is a curses control character. */
+      }
+      else if (j.ch > 0x7f && j.ch < 0xfe) {
+	/* Pull in a full utf-8 character. */
 	int bytes, i;
-	memset(utf8buf,'\0',7);
-	utf8buf[0] = j;
+	char *utf8buf[7];
+	memset(utf8buf, '\0', 7);
 
-	if ((j & 0xc0) && (~j & 0x20)) bytes = 2;
-	else if ((j & 0xe0) && (~j & 0x10)) bytes = 3;
-	else if ((j & 0xf0) && (~j & 0x08)) bytes = 4;
-	else if ((j & 0xf8) && (~j & 0x04)) bytes = 5;
-	else if ((j & 0xfc) && (~j & 0x02)) bytes = 6;
+	utf8buf[0] = j.ch;
+
+	if ((j.ch & 0xc0) && (~j.ch & 0x20)) bytes = 2;
+	else if ((j.ch & 0xe0) && (~j.ch & 0x10)) bytes = 3;
+	else if ((j.ch & 0xf0) && (~j.ch & 0x08)) bytes = 4;
+	else if ((j.ch & 0xf8) && (~j.ch & 0x04)) bytes = 5;
+	else if ((j.ch & 0xfc) && (~j.ch & 0x02)) bytes = 6;
 	else bytes = 1;
 	
 	for (i = 1; i < bytes; i++) {
 	  utf8buf[i] = wgetch(typwin);
 	}
 	if (g_utf8_validate(utf8buf, -1, NULL)) {
-	  j = g_utf8_get_char(utf8buf);
+	  j.uch = g_utf8_get_char(utf8buf);
 	}
 	else {
-	  j = ERR;
+	  j.ch = ERR;
 	}
       }
+      else if (j.ch <= 0x7f) {
+	j.uch = j.ch;
+      }
+      
       owl_global_update_lastinputtime(&g);
       /* find and activate the current keymap.
        * TODO: this should really get fixed by activating

Modified: branches/barnowl_unicode/owl/owl.h
===================================================================
--- branches/barnowl_unicode/owl/owl.h	2008-01-09 07:23:31 UTC (rev 810)
+++ branches/barnowl_unicode/owl/owl.h	2008-01-09 19:17:57 UTC (rev 811)
@@ -271,6 +271,12 @@
 				/* frees val as needed */
 } owl_variable;
 
+typedef struct _owl_input {
+  int ch;
+  char utf8buf[8];
+  gunichar uch;
+} owl_input;
+
 typedef struct _owl_fmtext {
   int textlen;
   int bufflen;
@@ -510,9 +516,9 @@
   char     *desc;		/* description */
   owl_list  bindings;		/* key bindings */
   struct _owl_keymap *submap;	/* submap */
-  void (*default_fn)(int j);	/* default action (takes a keypress) */
-  void (*prealways_fn)(int j);	/* always called before a keypress is received */
-  void (*postalways_fn)(int j);	/* always called after keypress is processed */
+  void (*default_fn)(owl_input j);	/* default action (takes a keypress) */
+  void (*prealways_fn)(owl_input  j);	/* always called before a keypress is received */
+  void (*postalways_fn)(owl_input  j);	/* always called after keypress is processed */
 } owl_keymap;
 
 typedef struct _owl_keyhandler {


home help back first fref pref prev next nref lref last post