keys.c: Convert most uses of unsigned char to char, clearing up warnings.

This also fixes the ability to bind to key sequences ending in ^.


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@476 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
Kevin Easton
2013-11-17 21:37:32 +00:00
parent de3d310678
commit ced7f9bcc9
2 changed files with 58 additions and 58 deletions

View File

@@ -1,5 +1,7 @@
[Changes 1.2c01] [Changes 1.2c01]
* Fix key bindings that terminate with ^. (caf)
* Fix the $timer() scripting function. (caf) * Fix the $timer() scripting function. (caf)
* Fix the /TKB (timed kickban) command. (caf) * Fix the /TKB (timed kickban) command. (caf)

View File

@@ -29,14 +29,13 @@ CVS_REVISION(keys_c)
#define MAIN_SOURCE #define MAIN_SOURCE
#include "modval.h" #include "modval.h"
#define KEY(meta, ch) (*keys[meta])[ch] #define KEY(meta, ch) (*keys[meta])[(unsigned char)(ch)]
typedef unsigned char uc; static void new_key(int, unsigned char, int, int, char *);
static void new_key (int, unsigned, int, int, char *);
static void snew_key(int meta, unsigned chr, char *what); static void snew_key(int meta, unsigned chr, char *what);
static uc * display_key (uc c); static char *display_key(char c);
static int lookup_function (const uc *name, int *lf_index); static int lookup_function(const char *name, int *lf_index);
static int parse_key (const uc *sequence, uc *term); static int parse_key(const char *sequence, char *term);
#ifdef GUI #ifdef GUI
char *mouse_actions[] = char *mouse_actions[] =
@@ -434,12 +433,12 @@ static void snew_key (int meta, unsigned chr, char *what)
#endif #endif
} }
static void snew_key_from_str (uc *string, char *what) static void snew_key_from_str(const char *string, char *what)
{ {
int i; int i;
int meta; int meta;
int old_display; int old_display;
uc chr; char chr;
old_display = window_display; old_display = window_display;
window_display = 0; window_display = 0;
@@ -454,7 +453,7 @@ static void snew_key_from_str (uc *string, char *what)
} }
static void new_key (int meta, unsigned chr, int type, int change, char *stuff) static void new_key(int meta, unsigned char chr, int type, int change, char *stuff)
{ {
/* /*
* Create a map first time we bind into it. We have to do this * Create a map first time we bind into it. We have to do this
@@ -494,7 +493,7 @@ static void new_key (int meta, unsigned chr, int type, int change, char *stuff)
* function will display to the screen the status of that bindings in a * function will display to the screen the status of that bindings in a
* human-readable way. * human-readable way.
*/ */
static void show_binding (int meta, uc c) static void show_binding(int meta, unsigned char c)
{ {
char meta_str[8]; char meta_str[8];
@@ -597,7 +596,7 @@ void save_bindings (FILE *fp, int do_all)
* a "meta" character. * a "meta" character.
* The value of 'func' will be NULL but you should not depend on that. * The value of 'func' will be NULL but you should not depend on that.
*/ */
int get_binding (int meta, uc c, KeyBinding *func, char **name) int get_binding(int meta, unsigned char c, KeyBinding *func, char **name)
{ {
*func = NULL; *func = NULL;
*name = NULL; *name = NULL;
@@ -741,10 +740,10 @@ BUILT_IN_COMMAND(rbindcmd)
/* * * * * * * * * * * * * * BIND * * * * * * * * * * * * * */ /* * * * * * * * * * * * * * BIND * * * * * * * * * * * * * */
static int grok_meta (const uc *ptr, const uc **end) static int grok_meta(const char *ptr, char **end)
{ {
int meta = -1; int meta = -1;
const uc * str; const char *str;
/* /*
* Well, if it is going to be anywhere, META has to be out front, * Well, if it is going to be anywhere, META has to be out front,
@@ -753,7 +752,7 @@ static int grok_meta (const uc *ptr, const uc **end)
if (!my_strnicmp(ptr, "META", 4)) if (!my_strnicmp(ptr, "META", 4))
{ {
str = ptr = ptr + 4; str = ptr = ptr + 4;
while (isdigit(*ptr)) while (isdigit((unsigned char)*ptr))
ptr++; ptr++;
if (*ptr == '_' && !my_strnicmp(ptr, "_CHARACTER", 10)) if (*ptr == '_' && !my_strnicmp(ptr, "_CHARACTER", 10))
ptr = ptr + 10; ptr = ptr + 10;
@@ -762,7 +761,8 @@ static int grok_meta (const uc *ptr, const uc **end)
meta = atol(str); meta = atol(str);
} }
*end = ptr; if (end)
*end = (char *)ptr;
return meta; return meta;
} }
@@ -772,13 +772,14 @@ static int grok_meta (const uc *ptr, const uc **end)
* work with, including the redux of ^X into X-64. * work with, including the redux of ^X into X-64.
* You can then work with the sequence after processing. * You can then work with the sequence after processing.
*/ */
void copy_redux (const uc *orig, uc *result) void copy_redux(const char *orig, char *result)
{ {
const uc *ptr; const char *ptr;
*result = 0;
for (ptr = orig; ptr && *ptr; ptr++, result++) for (ptr = orig; ptr && *ptr; ptr++, result++)
{ {
int c;
if (*ptr != '^') if (*ptr != '^')
{ {
*result = *ptr; *result = *ptr;
@@ -786,25 +787,27 @@ void copy_redux (const uc *orig, uc *result)
} }
ptr++; ptr++;
switch (toupper(*ptr)) c = toupper((unsigned char)*ptr);
switch (c)
{ {
case 0: /* ^<nul> is ^ */ case 0: /* ^<nul> is ^ */
*result = '^'; *result++ = '^';
return; goto out;
case '?': /* ^? is DEL */ case '?': /* ^? is DEL */
*result = 0177; *result = 0177;
break; break;
default: default:
if (toupper(*ptr) < 64) if (c < 64 || c > 127)
{ {
say("Illegal key sequence: ^%c", *ptr); say("Illegal key sequence: ^%c", *ptr);
*result = 0; goto out;
return;
} }
*result = toupper(*ptr) - 64; *result = c - 64;
break; break;
} }
} }
out:
*result = 0; *result = 0;
return; return;
} }
@@ -813,7 +816,7 @@ void copy_redux (const uc *orig, uc *result)
* find_meta_map: Finds a meta map that does not already contain a * find_meta_map: Finds a meta map that does not already contain a
* binding to the specified character. * binding to the specified character.
*/ */
int find_meta_map (uc key) int find_meta_map(char key)
{ {
int curr = MAX_META; int curr = MAX_META;
@@ -870,14 +873,13 @@ int find_meta_map (uc key)
* /BIND ^[[11~ BIND-ACTION (Force us to make suer ^[[11 is bound * /BIND ^[[11~ BIND-ACTION (Force us to make suer ^[[11 is bound
* to a meta map before returning.) * to a meta map before returning.)
*/ */
static int parse_key (const uc *sequence, uc *term) static int parse_key(const char *sequence, char *term)
{ {
uc *copy; char *copy, *end;
uc *end;
int return_meta = 0; int return_meta = 0;
int meta; int meta;
uc last_character; char last_character;
uc terminal_character; char terminal_character;
int last; int last;
int somethingN; int somethingN;
#ifdef GUI #ifdef GUI
@@ -908,7 +910,7 @@ static int parse_key (const uc *sequence, uc *term)
/* /*
* Remove any leading META description * Remove any leading META description
*/ */
if ((meta = grok_meta(copy, (const uc **)&copy)) == -1) if ((meta = grok_meta(copy, &copy)) == -1)
meta = 0; meta = 0;
if (x_debug & DEBUG_AUTOKEY) if (x_debug & DEBUG_AUTOKEY)
@@ -1070,11 +1072,11 @@ static int parse_key (const uc *sequence, uc *term)
*/ */
BUILT_IN_COMMAND(bindcmd) BUILT_IN_COMMAND(bindcmd)
{ {
uc *key, char *key;
*function; char *function;
uc *newkey; char *newkey;
int meta; int meta;
uc dakey; char dakey;
int bi_index; int bi_index;
int cnt, int cnt,
i; i;
@@ -1179,12 +1181,11 @@ BUILT_IN_COMMAND(bindcmd)
* set to the first item that matches the 'name'. For all other return * set to the first item that matches the 'name'. For all other return
* values, "lf_index" will have the value -1. * values, "lf_index" will have the value -1.
*/ */
static int lookup_function (const uc *orig_name, int *lf_index) static int lookup_function(const char *orig_name, int *lf_index)
{ {
int len, size_t len;
cnt, int cnt, i;
i; char *name;
uc *name, *breakage;
if (!orig_name) if (!orig_name)
{ {
@@ -1192,7 +1193,7 @@ static int lookup_function (const uc *orig_name, int *lf_index)
return 1; return 1;
} }
breakage = name = LOCAL_COPY(orig_name); name = LOCAL_COPY(orig_name);
upper(name); upper(name);
len = strlen(name); len = strlen(name);
@@ -1201,17 +1202,14 @@ static int lookup_function (const uc *orig_name, int *lf_index)
/* Handle "META" descriptions especially. */ /* Handle "META" descriptions especially. */
if (!strncmp(name, "META", 4)) if (!strncmp(name, "META", 4))
{ {
const uc * endp; int meta = grok_meta(name, NULL);
int meta;
if ((meta = grok_meta(name, &endp)) < 0) if (meta < 0)
return meta; return meta;
else
{
*lf_index = -meta; *lf_index = -meta;
return 1; return 1;
} }
}
for (cnt = 0, i = 0; i < NUMBER_OF_FUNCTIONS; i++) for (cnt = 0, i = 0; i < NUMBER_OF_FUNCTIONS; i++)
{ {
@@ -1239,12 +1237,12 @@ static int lookup_function (const uc *orig_name, int *lf_index)
* sequence by having a prepended caret ('^'). Other characters will be * sequence by having a prepended caret ('^'). Other characters will be
* left alone. The return value belongs to the function -- dont mangle it. * left alone. The return value belongs to the function -- dont mangle it.
*/ */
static uc * display_key (uc c) static char *display_key(char c)
{ {
static uc key[3]; static char key[3];
key[2] = (char) 0; key[2] = 0;
if (c < 32) if (c >= 0 && c < 32)
{ {
key[0] = '^'; key[0] = '^';
key[1] = c + 64; key[1] = c + 64;
@@ -1257,9 +1255,9 @@ static uc * display_key (uc c)
else else
{ {
key[0] = c; key[0] = c;
key[1] = (char) 0; key[1] = 0;
} }
return (key); return key;
} }
char *convert_to_keystr(char *key) char *convert_to_keystr(char *key)