#include <stdio.h>
#include <stdlib.h>
#include "config.h"
+#include "doregex.h"
#include <regex.h>
#include <string.h>
#include <ctype.h>
#ifndef _CONFIG_H_
#define _CONFIG_H_
-#include <regex.h>
-extern void CompileRegex(regex_t *Regex, const char *Pattern, int Flags);
-extern int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage);
-
// === HELPER MACROS ===
#define _EXPSTR(x) #x
#define EXPSTR(x) _EXPSTR(x)
--- /dev/null
+/*
+ * OpenDispense 2
+ * UCC (University [of WA] Computer Club) Electronic Accounting System
+ *
+ * doregex.c - Initialisation Code
+ *
+ * This file is licenced under the 3-clause BSD Licence. See the file
+ * COPYING for full details.
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include "doregex.h"
+
+// === CODE ===
+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 == REG_NOMATCH ) {
+ return -1;
+ }
+ if( ret ) {
+ 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%s\n", errorStr, pattern);
+ exit(-1);
+ }
+}
+
--- /dev/null
+/*
+ * OpenDispense2
+ *
+ * This code is published under the terms of the Acess licence.
+ * See the file COPYING for details.
+ *
+ * doregex.h - Regex Header
+ */
+#ifndef _DOREGEX_H_
+#define _DOREGEX_H_
+
+#include <regex.h>
+extern void CompileRegex(regex_t *Regex, const char *Pattern, int Flags);
+extern int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage);
+
+#endif
INSTALLDIR := /usr/local/opendispense2
-OBJ := main.o server.o logging.o config.o
+OBJ := main.o server.o logging.o
OBJ += dispense.o itemdb.o
OBJ += handler_coke.o handler_snack.o handler_door.o
+OBJ += config.o doregex.o
BIN := ../../dispsrv
OBJ := $(OBJ:%=obj/%)
fprintf(stderr, "Error: No space for %p in periodic list\n", Fcn);
}
-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 == REG_NOMATCH ) {
- return -1;
- }
- if( ret ) {
- 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%s\n", errorStr, pattern);
- exit(-1);
- }
-}
-
// Serial helper
int InitSerial(const char *File, int BaudRate)
{