]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/key_defined.c
ncurses 5.9 - patch 20120903
[ncurses.git] / ncurses / base / key_defined.c
index dac188748770e717fd40b6bd6fe91269415e39f8..ef987a5484d561bc87647b80852bfb710b1347de 100644 (file)
@@ -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            *
 
 #include <curses.priv.h>
 
-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