transform.c (262629) | transform.c (262685) |
---|---|
1/**************************************************************************** | 1/**************************************************************************** |
2 * Copyright (c) 2009,2010 Free Software Foundation, Inc. * | 2 * Copyright (c) 2009-2010,2011 Free Software Foundation, Inc. * |
3 * * 4 * Permission is hereby granted, free of charge, to any person obtaining a * 5 * copy of this software and associated documentation files (the * 6 * "Software"), to deal in the Software without restriction, including * 7 * without limitation the rights to use, copy, modify, merge, publish, * 8 * distribute, distribute with modifications, sublicense, and/or sell * 9 * copies of the Software, and to permit persons to whom the Software is * 10 * furnished to do so, subject to the following conditions: * --- 18 unchanged lines hidden (view full) --- 29/**************************************************************************** 30 * Author: Thomas E. Dickey * 31 ****************************************************************************/ 32#include <progs.priv.h> 33#include <string.h> 34 35#include <transform.h> 36 | 3 * * 4 * Permission is hereby granted, free of charge, to any person obtaining a * 5 * copy of this software and associated documentation files (the * 6 * "Software"), to deal in the Software without restriction, including * 7 * without limitation the rights to use, copy, modify, merge, publish, * 8 * distribute, distribute with modifications, sublicense, and/or sell * 9 * copies of the Software, and to permit persons to whom the Software is * 10 * furnished to do so, subject to the following conditions: * --- 18 unchanged lines hidden (view full) --- 29/**************************************************************************** 30 * Author: Thomas E. Dickey * 31 ****************************************************************************/ 32#include <progs.priv.h> 33#include <string.h> 34 35#include <transform.h> 36 |
37MODULE_ID("$Id: transform.c,v 1.2 2010/09/04 21:16:17 tom Exp $") | 37MODULE_ID("$Id: transform.c,v 1.3 2011/05/14 22:41:17 tom Exp $") |
38 39#ifdef SUFFIX_IGNORED 40static void | 38 39#ifdef SUFFIX_IGNORED 40static void |
41trim_suffix(const char *a, unsigned *len) | 41trim_suffix(const char *a, size_t *len) |
42{ 43 const char ignore[] = SUFFIX_IGNORED; 44 45 if (sizeof(ignore) != 0) { 46 bool trim = FALSE; | 42{ 43 const char ignore[] = SUFFIX_IGNORED; 44 45 if (sizeof(ignore) != 0) { 46 bool trim = FALSE; |
47 unsigned need = (sizeof(ignore) - 1); | 47 size_t need = (sizeof(ignore) - 1); |
48 49 if (*len > need) { | 48 49 if (*len > need) { |
50 unsigned first = *len - need; 51 unsigned n; | 50 size_t first = *len - need; 51 size_t n; |
52 trim = TRUE; 53 for (n = first; n < *len; ++n) { 54 if (tolower(UChar(a[n])) != tolower(UChar(ignore[n - first]))) { 55 trim = FALSE; 56 break; 57 } 58 } 59 if (trim) { --- 4 unchanged lines hidden (view full) --- 64} 65#else 66#define trim_suffix(a, len) /* nothing */ 67#endif 68 69bool 70same_program(const char *a, const char *b) 71{ | 52 trim = TRUE; 53 for (n = first; n < *len; ++n) { 54 if (tolower(UChar(a[n])) != tolower(UChar(ignore[n - first]))) { 55 trim = FALSE; 56 break; 57 } 58 } 59 if (trim) { --- 4 unchanged lines hidden (view full) --- 64} 65#else 66#define trim_suffix(a, len) /* nothing */ 67#endif 68 69bool 70same_program(const char *a, const char *b) 71{ |
72 unsigned len_a = strlen(a); 73 unsigned len_b = strlen(b); | 72 size_t len_a = strlen(a); 73 size_t len_b = strlen(b); |
74 75 trim_suffix(a, &len_a); 76 trim_suffix(b, &len_b); 77 78 return (len_a == len_b) && (strncmp(a, b, len_a) == 0); 79} | 74 75 trim_suffix(a, &len_a); 76 trim_suffix(b, &len_b); 77 78 return (len_a == len_b) && (strncmp(a, b, len_a) == 0); 79} |