[BACK]Return to key-string.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/key-string.c between version 1.27 and 1.28

version 1.27, 2015/10/26 22:03:04 version 1.28, 2015/11/12 11:05:34
Line 22 
Line 22 
   
 #include "tmux.h"  #include "tmux.h"
   
 int     key_string_search_table(const char *);  key_code        key_string_search_table(const char *);
 int     key_string_get_modifiers(const char **);  key_code        key_string_get_modifiers(const char **);
   
 const struct {  const struct {
         const char     *string;          const char     *string;
         int             key;          key_code        key;
 } key_string_table[] = {  } key_string_table[] = {
         /* Function keys. */          /* Function keys. */
         { "F1",         KEYC_F1 },          { "F1",         KEYC_F1 },
Line 98 
Line 98 
 };  };
   
 /* Find key string in table. */  /* Find key string in table. */
 int  key_code
 key_string_search_table(const char *string)  key_string_search_table(const char *string)
 {  {
         u_int   i;          u_int   i;
Line 111 
Line 111 
 }  }
   
 /* Find modifiers. */  /* Find modifiers. */
 int  key_code
 key_string_get_modifiers(const char **string)  key_string_get_modifiers(const char **string)
 {  {
         int     modifiers;          key_code        modifiers;
   
         modifiers = 0;          modifiers = 0;
         while (((*string)[0] != '\0') && (*string)[1] == '-') {          while (((*string)[0] != '\0') && (*string)[1] == '-') {
Line 138 
Line 138 
 }  }
   
 /* Lookup a string and convert to a key value. */  /* Lookup a string and convert to a key value. */
 int  key_code
 key_string_lookup_string(const char *string)  key_string_lookup_string(const char *string)
 {  {
         static const char       *other = "!#()+,-.0123456789:;<=>?'\r\t";          static const char       *other = "!#()+,-.0123456789:;<=>?'\r\t";
         int                      key, modifiers;          key_code                 key;
         u_short                  u;          u_short                  u;
         int                      size;          int                      size;
           key_code                 modifiers;
           struct utf8_data         utf8data;
           u_int                    i;
   
         /* Is this a hexadecimal value? */          /* Is this a hexadecimal value? */
         if (string[0] == '0' && string[1] == 'x') {          if (string[0] == '0' && string[1] == 'x') {
Line 164 
Line 167 
                 return (KEYC_NONE);                  return (KEYC_NONE);
   
         /* Is this a standard ASCII key? */          /* Is this a standard ASCII key? */
         if (string[1] == '\0') {          if (string[1] == '\0' && (u_char)string[0] <= 127) {
                 key = (u_char) string[0];                  key = (u_char)string[0];
                 if (key < 32 || key == 127 || key > 255)                  if (key < 32 || key == 127)
                         return (KEYC_NONE);                          return (KEYC_NONE);
         } else {          } else {
                   /* Try as a UTF-8 key. */
                   if (utf8_open(&utf8data, (u_char)*string)) {
                           if (strlen(string) != utf8data.size)
                                   return (KEYC_NONE);
                           for (i = 1; i < utf8data.size; i++)
                                   utf8_append(&utf8data, (u_char)string[i]);
                           key = utf8_combine(&utf8data);
                           return (key | modifiers);
                   }
   
                 /* Otherwise look the key up in the table. */                  /* Otherwise look the key up in the table. */
                 key = key_string_search_table(string);                  key = key_string_search_table(string);
                 if (key == KEYC_NONE)                  if (key == KEYC_NONE)
Line 195 
Line 208 
   
 /* Convert a key code into string format, with prefix if necessary. */  /* Convert a key code into string format, with prefix if necessary. */
 const char *  const char *
 key_string_lookup_key(int key)  key_string_lookup_key(key_code key)
 {  {
         static char     out[24];          static char             out[24];
         char            tmp[8];          char                    tmp[8];
         u_int           i;          u_int                   i;
           struct utf8_data        utf8data;
   
         *out = '\0';          *out = '\0';
   
Line 237 
Line 251 
                 return (out);                  return (out);
         }          }
   
           /* Is this a UTF-8 key? */
           if (key > 127 && key < KEYC_BASE) {
                   if (utf8_split(key, &utf8data) == 0) {
                           memcpy(out, utf8data.data, utf8data.size);
                           out[utf8data.size] = '\0';
                           return (out);
                   }
           }
   
         /* Invalid keys are errors. */          /* Invalid keys are errors. */
         if (key == 127 || key > 255) {          if (key == 127 || key > 255) {
                 snprintf(out, sizeof out, "<INVALID#%04x>", key);                  snprintf(out, sizeof out, "<INVALID#%llx>", key);
                 return (out);                  return (out);
         }          }
   
         /* Check for standard or control key. */          /* Check for standard or control key. */
         if (key >= 0 && key <= 32) {          if (key <= 32) {
                 if (key == 0 || key > 26)                  if (key == 0 || key > 26)
                         xsnprintf(tmp, sizeof tmp, "C-%c", 64 + key);                          xsnprintf(tmp, sizeof tmp, "C-%c", (int)(64 + key));
                 else                  else
                         xsnprintf(tmp, sizeof tmp, "C-%c", 96 + key);                          xsnprintf(tmp, sizeof tmp, "C-%c", (int)(96 + key));
         } else if (key >= 32 && key <= 126) {          } else if (key >= 32 && key <= 126) {
                 tmp[0] = key;                  tmp[0] = key;
                 tmp[1] = '\0';                  tmp[1] = '\0';
         } else if (key >= 128)          } else if (key >= 128)
                 xsnprintf(tmp, sizeof tmp, "\\%o", key);                  xsnprintf(tmp, sizeof tmp, "\\%llo", key);
   
         strlcat(out, tmp, sizeof out);          strlcat(out, tmp, sizeof out);
         return (out);          return (out);

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28