From 6b6e83db8fb861c5725d36afe0f85ac955c0831e Mon Sep 17 00:00:00 2001 From: "psyc://psyced.org/~lynX" <@> Date: Sat, 16 Apr 2011 14:05:28 +0200 Subject: [PATCH] match in library style --- src/match.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/match.c b/src/match.c index c7dc6b2..6354012 100644 --- a/src/match.c +++ b/src/match.c @@ -1,18 +1,22 @@ -#include #include +#include #ifdef TEST +# include # define PT(args) printf args; #else # define PT(args) #endif -int psycmatch(char* sho, char* lon) { - char *s, *l, *se, *le; - int slen, llen; +int PSYC_matches(uint8_t* sho, unsigned int slen, + uint8_t* lon, unsigned int llen) { + uint8_t *s, *l, *se, *le; - if (!(slen = strlen(sho)) || *sho != '_' || - !(llen = strlen(lon)) || *lon != '_') { + if (!slen) slen = strlen(sho); + if (!llen) llen = strlen(lon); + + if (slen == 0 || *sho != '_' || + llen == 0 || *lon != '_') { PT(("Please use long format keywords (compact ones would be faster, I know..)\n")) return -2; } @@ -68,7 +72,7 @@ int main(int argc, char **argv) { printf("Usage: %s \n\nExample: %s _failure_delivery _failure_unsuccessful_delivery_death\n", argv[0], argv[0]); return -1; } - if (psycmatch(argv[1], argv[2]) == 0) + if (PSYC_matches((uint8_t*) argv[1], 0, (uint8_t*) argv[2], 0) == 0) printf("Yes, they match!\n"); } #endif