/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
****************************************************************************/
/****************************************************************************
- * Author: Thomas E. Dickey <dickey@clark.net> 1997 *
+ * Author: Thomas E. Dickey 1997-on *
****************************************************************************/
#include <curses.priv.h>
-MODULE_ID("$Id: define_key.c,v 1.6 2000/12/10 02:43:26 tom Exp $")
+MODULE_ID("$Id: define_key.c,v 1.13 2006/12/30 23:23:31 tom Exp $")
NCURSES_EXPORT(int)
-define_key
-(char *str, int keycode)
+define_key(const char *str, int keycode)
{
int code = ERR;
T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode));
- if (keycode > 0) {
+ if (SP == 0) {
+ code = ERR;
+ } else if (keycode > 0) {
+ unsigned ukey = (unsigned) keycode;
+
if (str != 0) {
define_key(str, 0);
} else if (has_key(keycode)) {
- while (_nc_remove_key(&(SP->_keytry), keycode))
+ while (_nc_remove_key(&(SP->_keytry), ukey))
code = OK;
}
if (str != 0) {
- (void) _nc_add_to_try(&(SP->_keytry), str, keycode);
- code = OK;
+ if (key_defined(str) == 0) {
+ if (_nc_add_to_try(&(SP->_keytry), str, ukey) == OK) {
+ code = OK;
+ } else {
+ code = ERR;
+ }
+ } else {
+ code = ERR;
+ }
}
} else {
while (_nc_remove_string(&(SP->_keytry), str))