]> diplodocus.org Git - nmh/blobdiff - sbr/context_find.c
folder_realloc.c: Move interface to own file.
[nmh] / sbr / context_find.c
index 4d89fbc5fe5013b46db3bdca5f71d93b56da5810..05e368ba8b256fe206b90e547e79d93c321789f6 100644 (file)
@@ -5,7 +5,8 @@
  * complete copyright information.
  */
 
-#include <h/mh.h>
+#include "h/mh.h"
+#include "context_find.h"
 
 
 char *
@@ -13,9 +14,10 @@ context_find (const char *str)
 {
     struct node *np;
 
+    str = FENDNULL(str);
     for (np = m_defs; np; np = np->n_next)
-       if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(str)))
-           return (np->n_field);
+       if (!strcasecmp(FENDNULL(np->n_name), str))
+           return np->n_field;
 
     return NULL;
 }
@@ -29,7 +31,8 @@ context_find (const char *str)
  */
 char *
 context_find_by_type (const char *string, const char *type,
-                      const char *subtype) {
+                      const char *subtype)
+{
     char *value = NULL;
 
     if (subtype) {
@@ -57,11 +60,14 @@ context_find_by_type (const char *string, const char *type,
  * The search is case insensitive.
  */
 int
-context_find_prefix (const char *prefix) {
+context_find_prefix (const char *prefix)
+{
     struct node *np;
+    size_t len;
 
+    len = strlen(prefix);
     for (np = m_defs; np; np = np->n_next) {
-       if (np->n_name  &&  ! strncasecmp (np->n_name, prefix, strlen(prefix))) {
+       if (np->n_name  &&  ! strncasecmp (np->n_name, prefix, len)) {
            return 1;
         }
     }