15f4613f2SJohn Marino /**************************************************************************** 2*3468e90cSJohn Marino * Copyright (c) 2009-2010,2011 Free Software Foundation, Inc. * 35f4613f2SJohn Marino * * 45f4613f2SJohn Marino * Permission is hereby granted, free of charge, to any person obtaining a * 55f4613f2SJohn Marino * copy of this software and associated documentation files (the * 65f4613f2SJohn Marino * "Software"), to deal in the Software without restriction, including * 75f4613f2SJohn Marino * without limitation the rights to use, copy, modify, merge, publish, * 85f4613f2SJohn Marino * distribute, distribute with modifications, sublicense, and/or sell * 95f4613f2SJohn Marino * copies of the Software, and to permit persons to whom the Software is * 105f4613f2SJohn Marino * furnished to do so, subject to the following conditions: * 115f4613f2SJohn Marino * * 125f4613f2SJohn Marino * The above copyright notice and this permission notice shall be included * 135f4613f2SJohn Marino * in all copies or substantial portions of the Software. * 145f4613f2SJohn Marino * * 155f4613f2SJohn Marino * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 165f4613f2SJohn Marino * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 175f4613f2SJohn Marino * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 185f4613f2SJohn Marino * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 195f4613f2SJohn Marino * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 205f4613f2SJohn Marino * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 215f4613f2SJohn Marino * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 225f4613f2SJohn Marino * * 235f4613f2SJohn Marino * Except as contained in this notice, the name(s) of the above copyright * 245f4613f2SJohn Marino * holders shall not be used in advertising or otherwise to promote the * 255f4613f2SJohn Marino * sale, use or other dealings in this Software without prior written * 265f4613f2SJohn Marino * authorization. * 275f4613f2SJohn Marino ****************************************************************************/ 285f4613f2SJohn Marino 295f4613f2SJohn Marino /**************************************************************************** 305f4613f2SJohn Marino * Author: Thomas E. Dickey * 315f4613f2SJohn Marino ****************************************************************************/ 325f4613f2SJohn Marino #include <progs.priv.h> 335f4613f2SJohn Marino #include <string.h> 345f4613f2SJohn Marino 355f4613f2SJohn Marino #include <transform.h> 365f4613f2SJohn Marino 37*3468e90cSJohn Marino MODULE_ID("$Id: transform.c,v 1.3 2011/05/14 22:41:17 tom Exp $") 385f4613f2SJohn Marino 395f4613f2SJohn Marino #ifdef SUFFIX_IGNORED 405f4613f2SJohn Marino static void 41*3468e90cSJohn Marino trim_suffix(const char *a, size_t *len) 425f4613f2SJohn Marino { 435f4613f2SJohn Marino const char ignore[] = SUFFIX_IGNORED; 445f4613f2SJohn Marino 455f4613f2SJohn Marino if (sizeof(ignore) != 0) { 465f4613f2SJohn Marino bool trim = FALSE; 47*3468e90cSJohn Marino size_t need = (sizeof(ignore) - 1); 485f4613f2SJohn Marino 495f4613f2SJohn Marino if (*len > need) { 50*3468e90cSJohn Marino size_t first = *len - need; 51*3468e90cSJohn Marino size_t n; 525f4613f2SJohn Marino trim = TRUE; 535f4613f2SJohn Marino for (n = first; n < *len; ++n) { 545f4613f2SJohn Marino if (tolower(UChar(a[n])) != tolower(UChar(ignore[n - first]))) { 555f4613f2SJohn Marino trim = FALSE; 565f4613f2SJohn Marino break; 575f4613f2SJohn Marino } 585f4613f2SJohn Marino } 595f4613f2SJohn Marino if (trim) { 605f4613f2SJohn Marino *len -= need; 615f4613f2SJohn Marino } 625f4613f2SJohn Marino } 635f4613f2SJohn Marino } 645f4613f2SJohn Marino } 655f4613f2SJohn Marino #else 665f4613f2SJohn Marino #define trim_suffix(a, len) /* nothing */ 675f4613f2SJohn Marino #endif 685f4613f2SJohn Marino 695f4613f2SJohn Marino bool 705f4613f2SJohn Marino same_program(const char *a, const char *b) 715f4613f2SJohn Marino { 72*3468e90cSJohn Marino size_t len_a = strlen(a); 73*3468e90cSJohn Marino size_t len_b = strlen(b); 745f4613f2SJohn Marino 755f4613f2SJohn Marino trim_suffix(a, &len_a); 765f4613f2SJohn Marino trim_suffix(b, &len_b); 775f4613f2SJohn Marino 785f4613f2SJohn Marino return (len_a == len_b) && (strncmp(a, b, len_a) == 0); 795f4613f2SJohn Marino } 80