2001-05-16 00:21:17 +00:00
|
|
|
/* MDB Tools - A library for reading MS Access database file
|
|
|
|
|
* Copyright (C) 2000 Brian Bruns
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-04-20 21:06:46 +00:00
|
|
|
#include <stdio.h>
|
2003-01-20 16:04:24 +00:00
|
|
|
#include <string.h>
|
2001-04-20 21:06:46 +00:00
|
|
|
|
2003-01-28 23:51:06 +00:00
|
|
|
#ifdef DMALLOC
|
|
|
|
|
#include "dmalloc.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-01-21 23:43:31 +00:00
|
|
|
//#define MDB_DEBUG_LIKE 1
|
|
|
|
|
|
2003-01-20 16:04:24 +00:00
|
|
|
int mdb_like_cmp(char *s, char *r)
|
2001-04-20 21:06:46 +00:00
|
|
|
{
|
|
|
|
|
int i, ret;
|
|
|
|
|
|
2003-01-21 23:43:31 +00:00
|
|
|
#if MDB_DEBUG_LIKE
|
|
|
|
|
printf("comparing %s and %s\n", s, r);
|
|
|
|
|
#endif
|
2001-04-20 21:06:46 +00:00
|
|
|
switch (r[0]) {
|
|
|
|
|
case '\0':
|
|
|
|
|
if (s[0]=='\0') {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
case '_':
|
|
|
|
|
/* skip one character */
|
2003-01-20 16:04:24 +00:00
|
|
|
return mdb_like_cmp(&s[1],&r[1]);
|
2001-04-20 21:06:46 +00:00
|
|
|
case '%':
|
|
|
|
|
/* skip any number of characters */
|
|
|
|
|
/* the strlen(s)+1 is important so the next call can */
|
|
|
|
|
/* if there are trailing characters */
|
|
|
|
|
for(i=0;i<strlen(s)+1;i++) {
|
2003-01-20 16:04:24 +00:00
|
|
|
if (mdb_like_cmp(&s[i],&r[1])) {
|
2001-04-20 21:06:46 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
default:
|
|
|
|
|
for(i=0;i<strlen(r);i++) {
|
|
|
|
|
if (r[i]=='_' || r[i]=='%') break;
|
|
|
|
|
}
|
|
|
|
|
if (strncmp(s,r,i)) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
2003-01-21 23:43:31 +00:00
|
|
|
#if MDB_DEBUG_LIKE
|
|
|
|
|
printf("at pos %d comparing %s and %s\n", i, &s[i], &r[i]);
|
|
|
|
|
#endif
|
2003-01-20 16:04:24 +00:00
|
|
|
ret = mdb_like_cmp(&s[i],&r[i]);
|
2003-01-21 23:43:31 +00:00
|
|
|
#if MDB_DEBUG_LIKE
|
|
|
|
|
printf("returning %d (%s and %s)\n", ret, &s[i], &r[i]);
|
|
|
|
|
#endif
|
2001-04-20 21:06:46 +00:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|