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.
21 extern void Init_Cokebank(const char *Argument); // cokebank.c
22 extern void Init_Handlers(void);
23 extern void Load_Itemlist(void);
24 extern void Server_Start(void);
25 extern int giServer_Port;
26 extern char* gsItemListFile;
27 extern char* gsCoke_SerialPort;
28 extern char* gsSnack_SerialPort;
32 char *gsCokebankPath = "cokebank.db";
40 int main(int argc, char *argv[])
45 for( i = 1; i < argc; i++ )
48 if( arg[0] == '-' && arg[1] != '-')
53 giServer_Port = atoi(argv[++i]);
56 giDebugLevel = atoi(argv[++i]);
63 else if( arg[0] == '-' && arg[1] == '-' ) {
64 if( strcmp(arg, "--itemsfile") == 0 ) {
65 gsItemListFile = argv[++i];
67 else if( strcmp(arg, "--cokeport") == 0 ) {
68 gsCoke_SerialPort = argv[++i];
70 else if( strcmp(arg, "--snackport") == 0 ) {
71 gsSnack_SerialPort = argv[++i];
82 signal(SIGINT, sigint_handler);
84 Init_Cokebank(gsCokebankPath);
96 int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage)
100 ret = regexec(regex, string, nMatches, matches, 0);
102 size_t len = regerror(ret, regex, NULL, 0);
104 regerror(ret, regex, errorStr, len);
105 printf("string = '%s'\n", string);
106 fprintf(stderr, "%s\n%s", errorMessage, errorStr);
113 void CompileRegex(regex_t *regex, const char *pattern, int flags)
115 int ret = regcomp(regex, pattern, flags);
117 size_t len = regerror(ret, regex, NULL, 0);
119 regerror(ret, regex, errorStr, len);
120 fprintf(stderr, "Regex compilation failed - %s\n", errorStr);
126 int InitSerial(const char *File, int BaudRate)
133 fd = open(File, O_RDWR | O_NOCTTY);
134 if( fd == -1 ) return -1;
138 case 9600: baud = B9600; break;
142 cfmakeraw(&info); // Sets 8N1
143 cfsetspeed(&info, baud);
145 tcsetattr(fd, TCSANOW, &info);