Skip to content
Snippets Groups Projects
Commit 26a80cc0 authored by Mark Tearle's avatar Mark Tearle
Browse files

Use common regex functions in client

parent 0cad3846
No related merge requests found
...@@ -8,6 +8,7 @@ LDFLAGS := -g -lncurses ...@@ -8,6 +8,7 @@ LDFLAGS := -g -lncurses
BIN := ../../dispense BIN := ../../dispense
OBJ := main.o protocol.o menu.o OBJ := main.o protocol.o menu.o
OBJ += doregex.o
DEPFILES := $(OBJ:%.o=%.d) DEPFILES := $(OBJ:%.o=%.d)
...@@ -31,4 +32,8 @@ $(BIN): $(OBJ) ...@@ -31,4 +32,8 @@ $(BIN): $(OBJ)
$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS) $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
$(CC) -M -MT $@ -o $*.d $< $(CPPFLAGS) $(CC) -M -MT $@ -o $*.d $< $(CPPFLAGS)
%.o: ../common/%.c
$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
$(CC) -M -MT $@ -o $*.d $< $(CPPFLAGS)
-include $(DEPFILES) -include $(DEPFILES)
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <unistd.h> // close/getuid #include <unistd.h> // close/getuid
#include <limits.h> // INT_MIN/INT_MAX #include <limits.h> // INT_MIN/INT_MAX
#include "common.h" #include "common.h"
#include "../common/doregex.h"
#define USE_NCURSES_INTERFACE 0 #define USE_NCURSES_INTERFACE 0
#define DEBUG_TRACE_SERVER 0 #define DEBUG_TRACE_SERVER 0
...@@ -982,32 +983,3 @@ char *trim(char *string) ...@@ -982,32 +983,3 @@ char *trim(char *string)
return 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);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment