X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Fkey_defined.c;h=ef987a5484d561bc87647b80852bfb710b1347de;hp=dac188748770e717fd40b6bd6fe91269415e39f8;hb=48c8a4fe456e83238533fb42b36fd5253db22f59;hpb=a8987e73ec254703634802b4f7ee30d3a485524d diff --git a/ncurses/base/key_defined.c b/ncurses/base/key_defined.c index dac18874..ef987a54 100644 --- a/ncurses/base/key_defined.c +++ b/ncurses/base/key_defined.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2003 Free Software Foundation, Inc. * + * Copyright (c) 2003-2006,2009 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 * @@ -32,26 +32,27 @@ #include -MODULE_ID("$Id: key_defined.c,v 1.3 2003/05/17 23:12:27 tom Exp $") +MODULE_ID("$Id: key_defined.c,v 1.9 2009/10/24 22:15:47 tom Exp $") static int -find_definition(struct tries *tree, const char *str) +find_definition(TRIES * tree, const char *str) { - struct tries *ptr; - int result = 0; + TRIES *ptr; + int result = OK; if (str != 0 && *str != '\0') { for (ptr = tree; ptr != 0; ptr = ptr->sibling) { if (UChar(*str) == UChar(ptr->ch)) { if (str[1] == '\0' && ptr->child != 0) { - result = -1; - } else if ((result = find_definition(ptr->child, str + 1)) == 0) { + result = ERR; + } else if ((result = find_definition(ptr->child, str + 1)) + == OK) { result = ptr->value; } else if (str[1] == '\0') { - result = -1; + result = ERR; } } - if (result != 0) + if (result != OK) break; } } @@ -60,17 +61,26 @@ find_definition(struct tries *tree, const char *str) /* * Returns the keycode associated with the given string. If none is found, - * return 0. If the string is only a prefix to other strings, return -1. + * return OK. If the string is only a prefix to other strings, return ERR. + * Otherwise, return the keycode's value (neither OK/ERR). */ NCURSES_EXPORT(int) -key_defined(const char *str) +NCURSES_SP_NAME(key_defined) (NCURSES_SP_DCLx const char *str) { int code = ERR; - T((T_CALLED("key_defined(%s)"), _nc_visbuf(str))); - if (SP != 0 && str != 0) { - code = find_definition(SP->_keytry, str); + T((T_CALLED("key_defined(%p, %s)"), (void *) SP_PARM, _nc_visbuf(str))); + if (SP_PARM != 0 && str != 0) { + code = find_definition(SP_PARM->_keytry, str); } returnCode(code); } + +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +key_defined(const char *str) +{ + return NCURSES_SP_NAME(key_defined) (CURRENT_SCREEN, str); +} +#endif