3 * UCC (University [of WA] Computer Club) Electronic Accounting System
5 * main.c - Initialisation Code
7 * This file is licenced under the 3-clause BSD Licence. See the file
8 * COPYING for full details.
18 extern void Init_Cokebank(const char *Argument); // cokebank.c
19 extern void Init_Handlers(void);
20 extern void Load_Itemlist(void);
21 extern void Server_Start(void);
22 extern int giServer_Port;
23 extern char* gsItemListFile;
24 extern char* gsCoke_SerialPort;
25 extern char* gsSnack_SerialPort;
29 char *gsCokebankPath = "cokebank.db";
37 int main(int argc, char *argv[])
42 for( i = 1; i < argc; i++ )
45 if( arg[0] == '-' && arg[1] != '-')
50 giServer_Port = atoi(argv[++i]);
53 giDebugLevel = atoi(argv[++i]);
60 else if( arg[0] == '-' && arg[1] == '-' ) {
61 if( strcmp(arg, "--itemsfile") == 0 ) {
62 gsItemListFile = argv[++i];
64 else if( strcmp(arg, "--cokeport") == 0 ) {
65 gsCoke_SerialPort = argv[++i];
67 else if( strcmp(arg, "--snackport") == 0 ) {
68 gsSnack_SerialPort = argv[++i];
79 signal(SIGINT, sigint_handler);
81 Init_Cokebank(gsCokebankPath);
93 int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage)
97 ret = regexec(regex, string, nMatches, matches, 0);
99 size_t len = regerror(ret, regex, NULL, 0);
101 regerror(ret, regex, errorStr, len);
102 printf("string = '%s'\n", string);
103 fprintf(stderr, "%s\n%s", errorMessage, errorStr);
110 void CompileRegex(regex_t *regex, const char *pattern, int flags)
112 int ret = regcomp(regex, pattern, flags);
114 size_t len = regerror(ret, regex, NULL, 0);
116 regerror(ret, regex, errorStr, len);
117 fprintf(stderr, "Regex compilation failed - %s\n", errorStr);
123 void InitSerial(int FD, int BaudRate)
130 case 9600: baud = B9600; break;
134 cfmakeraw(&info); // Sets 8N1
135 cfsetspeed(&info, baud);
137 tcsetattr(FD, TCSANOW, &info);