Cleanups of bugs and segfaults
[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     Load_Itemlist(void);
19 extern void     Server_Start(void);
20 extern int      giServer_Port;
21 extern char*    gsItemListFile;
22 extern char*    gsCoke_SerialPort;
23
24 // === GLOBALS ===
25  int    giDebugLevel = 0;
26 char    *gsCokebankPath = "cokebank.db";
27
28 // === CODE ===
29 void sigint_handler()
30 {
31         exit(0);
32 }
33
34 int main(int argc, char *argv[])
35 {
36          int    i;
37         
38         // Parse Arguments
39         for( i = 1; i < argc; i++ )
40         {
41                 char    *arg = argv[i];
42                 if( arg[0] == '-' && arg[1] != '-')
43                 {
44                         switch(arg[1])
45                         {
46                         case 'p':
47                                 giServer_Port = atoi(argv[++i]);
48                                 break;
49                         case 'd':
50                                 giDebugLevel = atoi(argv[++i]);
51                                 break;
52                         default:
53                                 // Usage Error?
54                                 break;
55                         }
56                 }
57                 else if( arg[0] == '-' && arg[1] == '-' ) {
58                         if( strcmp(arg, "--itemsfile") == 0 ) {
59                                 gsItemListFile = argv[++i];
60                         }
61                         if( strcmp(arg, "--cokeport") == 0 ) {
62                                 gsCoke_SerialPort = argv[++i];
63                         }
64                         else {
65                                 // Usage error?
66                         }
67                 }
68                 else {
69                         // Usage Error?
70                 }
71         }
72         
73         Init_Cokebank(gsCokebankPath);
74         
75         Load_Itemlist();
76         
77         Server_Start();
78         
79         signal(SIGINT, sigint_handler);
80
81         return 0;
82 }
83

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