#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <signal.h>
#include "common.h"
// === IMPORTS ===
extern void Init_Cokebank(const char *Argument); // cokebank.c
+extern void Init_Handlers(void);
extern void Load_Itemlist(void);
extern void Server_Start(void);
extern int giServer_Port;
extern char* gsItemListFile;
extern char* gsCoke_SerialPort;
+extern char* gsSnack_SerialPort;
// === GLOBALS ===
int giDebugLevel = 0;
char *gsCokebankPath = "cokebank.db";
// === CODE ===
+void sigint_handler()
+{
+ exit(0);
+}
+
int main(int argc, char *argv[])
{
int i;
if( strcmp(arg, "--itemsfile") == 0 ) {
gsItemListFile = argv[++i];
}
- if( strcmp(arg, "--cokeport") == 0 ) {
+ else if( strcmp(arg, "--cokeport") == 0 ) {
gsCoke_SerialPort = argv[++i];
}
+ else if( strcmp(arg, "--snackport") == 0 ) {
+ gsSnack_SerialPort = argv[++i];
+ }
else {
// Usage error?
}
}
}
- Init_Cokebank(gsCokebankPath);
+ signal(SIGINT, sigint_handler);
+ Init_Cokebank(gsCokebankPath);
+
+ Init_Handlers();
+
Load_Itemlist();
Server_Start();
+
return 0;
}
+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 ) {
+ 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);
+ }
+}
+
+