From: Mark Tearle Date: Sat, 27 Dec 2014 12:29:04 +0000 (+0800) Subject: Use common regex functions in client X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=26a80cc0cae35a63247b69a262aacd2a3932d924;p=tpg%2Fopendispense2.git Use common regex functions in client --- diff --git a/src/client/Makefile b/src/client/Makefile index 41c23cb..b70551e 100644 --- a/src/client/Makefile +++ b/src/client/Makefile @@ -8,6 +8,7 @@ LDFLAGS := -g -lncurses BIN := ../../dispense OBJ := main.o protocol.o menu.o +OBJ += doregex.o DEPFILES := $(OBJ:%.o=%.d) @@ -31,4 +32,8 @@ $(BIN): $(OBJ) $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS) $(CC) -M -MT $@ -o $*.d $< $(CPPFLAGS) +%.o: ../common/%.c + $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS) + $(CC) -M -MT $@ -o $*.d $< $(CPPFLAGS) + -include $(DEPFILES) diff --git a/src/client/main.c b/src/client/main.c index 2bd4312..ddf3779 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -16,6 +16,7 @@ #include // close/getuid #include // INT_MIN/INT_MAX #include "common.h" +#include "../common/doregex.h" #define USE_NCURSES_INTERFACE 0 #define DEBUG_TRACE_SERVER 0 @@ -982,32 +983,3 @@ char *trim(char *string) return string; } - -int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage) -{ - int ret; - - ret = regexec(regex, string, nMatches, matches, 0); - if( ret && errorMessage ) { - size_t len = regerror(ret, regex, NULL, 0); - char errorStr[len]; - regerror(ret, regex, errorStr, len); - printf("string = '%s'\n", string); - fprintf(stderr, "%s\n%s", errorMessage, errorStr); - exit(-1); - } - - return ret; -} - -void CompileRegex(regex_t *regex, const char *pattern, int flags) -{ - int ret = regcomp(regex, pattern, flags); - if( ret ) { - size_t len = regerror(ret, regex, NULL, 0); - char errorStr[len]; - regerror(ret, regex, errorStr, len); - fprintf(stderr, "Regex compilation failed - %s\n", errorStr); - exit(-1); - } -}