Fixed coke handler regex, added init for handlers
[tpg/opendispense2.git] / src / server / main.c
1 /*
2  * OpenDispense 2 
3  * UCC (University [of WA] Computer Club) Electronic Accounting System
4  *
5  * main.c - Initialisation Code
6  *
7  * This file is licenced under the 3-clause BSD Licence. See the file
8  * COPYING for full details.
9  */
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <signal.h>
14 #include "common.h"
15
16 // === IMPORTS ===
17 extern void     Init_Cokebank(const char *Argument);    // cokebank.c
18 extern void     Init_Handlers(void);
19 extern void     Load_Itemlist(void);
20 extern void     Server_Start(void);
21 extern int      giServer_Port;
22 extern char*    gsItemListFile;
23 extern char*    gsCoke_SerialPort;
24
25 // === GLOBALS ===
26  int    giDebugLevel = 0;
27 char    *gsCokebankPath = "cokebank.db";
28
29 // === CODE ===
30 void sigint_handler()
31 {
32         exit(0);
33 }
34
35 int main(int argc, char *argv[])
36 {
37          int    i;
38         
39         // Parse Arguments
40         for( i = 1; i < argc; i++ )
41         {
42                 char    *arg = argv[i];
43                 if( arg[0] == '-' && arg[1] != '-')
44                 {
45                         switch(arg[1])
46                         {
47                         case 'p':
48                                 giServer_Port = atoi(argv[++i]);
49                                 break;
50                         case 'd':
51                                 giDebugLevel = atoi(argv[++i]);
52                                 break;
53                         default:
54                                 // Usage Error?
55                                 break;
56                         }
57                 }
58                 else if( arg[0] == '-' && arg[1] == '-' ) {
59                         if( strcmp(arg, "--itemsfile") == 0 ) {
60                                 gsItemListFile = argv[++i];
61                         }
62                         if( strcmp(arg, "--cokeport") == 0 ) {
63                                 gsCoke_SerialPort = argv[++i];
64                         }
65                         else {
66                                 // Usage error?
67                         }
68                 }
69                 else {
70                         // Usage Error?
71                 }
72         }
73         
74         signal(SIGINT, sigint_handler);
75         
76         Init_Cokebank(gsCokebankPath);
77
78         Init_Handlers();
79
80         Load_Itemlist();
81         
82         Server_Start();
83         
84
85         return 0;
86 }
87

UCC git Repository :: git.ucc.asn.au