1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

match in library style

This commit is contained in:
psyc://psyced.org/~lynX 2011-04-16 14:05:28 +02:00
parent a08c6f3f1d
commit 9f0bb8508e

View file

@ -1,18 +1,22 @@
#include <stdio.h>
#include <string.h> #include <string.h>
#include <stdint.h>
#ifdef TEST #ifdef TEST
# include <stdio.h>
# define PT(args) printf args; # define PT(args) printf args;
#else #else
# define PT(args) # define PT(args)
#endif #endif
int psycmatch(char* sho, char* lon) { int PSYC_matches(uint8_t* sho, unsigned int slen,
char *s, *l, *se, *le; uint8_t* lon, unsigned int llen) {
int slen, llen; uint8_t *s, *l, *se, *le;
if (!(slen = strlen(sho)) || *sho != '_' || if (!slen) slen = strlen(sho);
!(llen = strlen(lon)) || *lon != '_') { 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")) PT(("Please use long format keywords (compact ones would be faster, I know..)\n"))
return -2; return -2;
} }
@ -68,7 +72,7 @@ int main(int argc, char **argv) {
printf("Usage: %s <short> <long>\n\nExample: %s _failure_delivery _failure_unsuccessful_delivery_death\n", argv[0], argv[0]); printf("Usage: %s <short> <long>\n\nExample: %s _failure_delivery _failure_unsuccessful_delivery_death\n", argv[0], argv[0]);
return -1; 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"); printf("Yes, they match!\n");
} }
#endif #endif