Back to index

tetex-bin  3.0
name_match.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1999-2002,2004 Free Software Foundation, Inc.              *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *  Author: Thomas E. Dickey <dickey@clark.net> 1999                        *
00031  ****************************************************************************/
00032 
00033 #include <curses.priv.h>
00034 #include <term.h>
00035 #include <tic.h>
00036 
00037 MODULE_ID("$Id: name_match.c,v 1.13 2004/04/17 22:11:21 tom Exp $")
00038 
00039 /*
00040  *     _nc_first_name(char *names)
00041  *
00042  *     Extract the primary name from a compiled entry.
00043  */
00044 
00045 NCURSES_EXPORT(char *)
00046 _nc_first_name(const char *const sp)
00047 /* get the first name from the given name list */
00048 {
00049     static char *buf;
00050     register unsigned n;
00051 
00052 #if NO_LEAKS
00053     if (sp == 0) {
00054        FreeAndNull(buf);    /* for leak-testing */
00055        return 0;
00056     }
00057 #endif
00058 
00059     if (buf == 0)
00060        buf = typeMalloc(char, MAX_NAME_SIZE + 1);
00061     for (n = 0; n < MAX_NAME_SIZE; n++) {
00062        if ((buf[n] = sp[n]) == '\0'
00063            || (buf[n] == '|'))
00064            break;
00065     }
00066     buf[n] = '\0';
00067     return (buf);
00068 }
00069 
00070 /*
00071  *     int _nc_name_match(namelist, name, delim)
00072  *
00073  *     Is the given name matched in namelist?
00074  */
00075 
00076 NCURSES_EXPORT(int)
00077 _nc_name_match(const char *const namelst, const char *const name, const char *const delim)
00078 {
00079     const char *s, *d, *t;
00080     int code, found;
00081 
00082     if ((s = namelst) != 0) {
00083        while (*s != '\0') {
00084            for (d = name; *d != '\0'; d++) {
00085               if (*s != *d)
00086                   break;
00087               s++;
00088            }
00089            found = FALSE;
00090            for (code = TRUE; *s != '\0'; code = FALSE, s++) {
00091               for (t = delim; *t != '\0'; t++) {
00092                   if (*s == *t) {
00093                      found = TRUE;
00094                      break;
00095                   }
00096               }
00097               if (found)
00098                   break;
00099            }
00100            if (code && *d == '\0')
00101               return code;
00102            if (*s++ == 0)
00103               break;
00104        }
00105     }
00106     return FALSE;
00107 }