]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/name_match.c
ncurses 5.0
[ncurses.git] / ncurses / tinfo / name_match.c
similarity index 74%
rename from ncurses/name_match.c
rename to ncurses/tinfo/name_match.c
index 457f6376902af81bb431e744a43075d693763702..a9e8396959d119380c955e1858aa11713454a019 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc.                        *
+ * Copyright (c) 1999 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: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
- *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1999                        *
  ****************************************************************************/
 
 #include <curses.priv.h>
 #include <term.h>
 #include <tic.h>
 
-MODULE_ID("$Id: name_match.c,v 1.4 1998/02/11 12:13:55 tom Exp $")
+MODULE_ID("$Id: name_match.c,v 1.8 1999/03/07 01:58:36 tom Exp $")
 
 /*
  *     _nc_first_name(char *names)
@@ -46,16 +45,16 @@ MODULE_ID("$Id: name_match.c,v 1.4 1998/02/11 12:13:55 tom Exp $")
 char *_nc_first_name(const char *const sp)
 /* get the first name from the given name list */
 {
-    static char        buf[MAX_NAME_SIZE];
-    register char *cp;
+       static char     buf[MAX_NAME_SIZE+1];
+       register unsigned n;
 
-    (void) strcpy(buf, sp);
-
-    cp = strchr(buf, '|');
-    if (cp)
-       *cp = '\0';
-
-    return(buf);
+       for (n = 0; n < sizeof(buf)-1; n++) {
+               if ((buf[n] = sp[n]) == '\0'
+                || (buf[n] == '|'))
+                       break;
+       }
+       buf[n] = '\0';
+       return(buf);
 }
 
 /*
@@ -65,21 +64,33 @@ char *_nc_first_name(const char *const sp)
  */
 
 int _nc_name_match(const char *const namelst, const char *const name, const char *const delim)
-/* microtune this, it occurs in several critical loops */
 {
-char namecopy[MAX_ENTRY_SIZE]; /* this may get called on a TERMCAP value */
-register char *cp;
+       const char *s, *d, *t;
+       int code, found;
 
-       if (namelst == 0)
-               return(FALSE);
-       (void) strcpy(namecopy, namelst);
-       if ((cp = strtok(namecopy, delim)) != 0) {
-               do {
-                       /* avoid strcmp() function-call cost if possible */
-                       if (cp[0] == name[0] && strcmp(cp, name) == 0)
-                           return(TRUE);
-               } while
-                   ((cp = strtok((char *)0, delim)) != 0);
+       if ((s = namelst) != 0) {
+               while (*s != '\0') {
+                       for (d = name; *d != '\0'; d++) {
+                               if (*s != *d)
+                                       break;
+                               s++;
+                       }
+                       found = FALSE;
+                       for (code = TRUE; *s != '\0'; code = FALSE, s++) {
+                               for (t = delim; *t != '\0'; t++) {
+                                       if (*s == *t) {
+                                               found = TRUE;
+                                               break;
+                                       }
+                               }
+                               if (found)
+                                       break;
+                       }
+                       if (code && *d == '\0')
+                               return code;
+                       if (*s++ == 0)
+                               break;
+               }
        }
-       return(FALSE);
+       return FALSE;
 }