150276Speter/**************************************************************************** 2184989Srafan * Copyright (c) 1999-2007,2008 Free Software Foundation, Inc. * 350276Speter * * 450276Speter * Permission is hereby granted, free of charge, to any person obtaining a * 550276Speter * copy of this software and associated documentation files (the * 650276Speter * "Software"), to deal in the Software without restriction, including * 750276Speter * without limitation the rights to use, copy, modify, merge, publish, * 850276Speter * distribute, distribute with modifications, sublicense, and/or sell * 950276Speter * copies of the Software, and to permit persons to whom the Software is * 1050276Speter * furnished to do so, subject to the following conditions: * 1150276Speter * * 1250276Speter * The above copyright notice and this permission notice shall be included * 1350276Speter * in all copies or substantial portions of the Software. * 1450276Speter * * 1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2250276Speter * * 2350276Speter * Except as contained in this notice, the name(s) of the above copyright * 2450276Speter * holders shall not be used in advertising or otherwise to promote the * 2550276Speter * sale, use or other dealings in this Software without prior written * 2650276Speter * authorization. * 2750276Speter ****************************************************************************/ 2850276Speter 2950276Speter/**************************************************************************** 30184989Srafan * Author: Thomas E. Dickey 1999-on * 3150276Speter ****************************************************************************/ 3250276Speter 3350276Speter#include <curses.priv.h> 3450276Speter#include <term.h> 3550276Speter#include <tic.h> 3650276Speter 37184989SrafanMODULE_ID("$Id: name_match.c,v 1.17 2008/08/03 19:49:33 tom Exp $") 3850276Speter 3950276Speter/* 4050276Speter * _nc_first_name(char *names) 4150276Speter * 4250276Speter * Extract the primary name from a compiled entry. 4350276Speter */ 44174993Srafan#define FirstName _nc_globals.first_name 4550276Speter 4676726SpeterNCURSES_EXPORT(char *) 4776726Speter_nc_first_name(const char *const sp) 4850276Speter/* get the first name from the given name list */ 4950276Speter{ 50174993Srafan unsigned n; 5150276Speter 52166124Srafan#if NO_LEAKS 53166124Srafan if (sp == 0) { 54174993Srafan if (FirstName != 0) 55174993Srafan FreeAndNull(FirstName); 56184989Srafan } else 57166124Srafan#endif 58184989Srafan { 59184989Srafan if (FirstName == 0) 60184989Srafan FirstName = typeMalloc(char, MAX_NAME_SIZE + 1); 61166124Srafan 62184989Srafan if (FirstName != 0) { 63184989Srafan for (n = 0; n < MAX_NAME_SIZE; n++) { 64184989Srafan if ((FirstName[n] = sp[n]) == '\0' 65184989Srafan || (FirstName[n] == '|')) 66184989Srafan break; 67184989Srafan } 68184989Srafan FirstName[n] = '\0'; 69184989Srafan } 7076726Speter } 71174993Srafan return (FirstName); 7250276Speter} 7350276Speter 7450276Speter/* 7550276Speter * int _nc_name_match(namelist, name, delim) 7650276Speter * 7750276Speter * Is the given name matched in namelist? 7850276Speter */ 7950276Speter 8076726SpeterNCURSES_EXPORT(int) 81166124Srafan_nc_name_match(const char *const namelst, const char *const name, const char *const delim) 8250276Speter{ 8376726Speter const char *s, *d, *t; 8476726Speter int code, found; 8550276Speter 8676726Speter if ((s = namelst) != 0) { 8776726Speter while (*s != '\0') { 8876726Speter for (d = name; *d != '\0'; d++) { 8976726Speter if (*s != *d) 9076726Speter break; 9176726Speter s++; 9276726Speter } 9376726Speter found = FALSE; 9476726Speter for (code = TRUE; *s != '\0'; code = FALSE, s++) { 9576726Speter for (t = delim; *t != '\0'; t++) { 9676726Speter if (*s == *t) { 9776726Speter found = TRUE; 9876726Speter break; 9976726Speter } 10050276Speter } 10176726Speter if (found) 10276726Speter break; 10376726Speter } 10476726Speter if (code && *d == '\0') 10576726Speter return code; 10676726Speter if (*s++ == 0) 10776726Speter break; 10850276Speter } 10976726Speter } 11076726Speter return FALSE; 11150276Speter} 112