cf8e7f1cbdcac91a5c197854c26f311f9013b32f
[tpg/opendispense2.git] / server / src / itemdb.c
1 /*
2  * OpenDispense 2 
3  * UCC (University [of WA] Computer Club) Electronic Accounting System
4  *
5  * itemdb.c - Dispense Item Databse
6  *
7  * This file is licenced under the 3-clause BSD Licence. See the file COPYING
8  * for full details.
9  */
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include "common.h"
13
14 // === GLOBALS ===
15  int    giNumItems = 0;
16 tItem   *gaItems = NULL;
17 tHandler        *gaHandlers = NULL;
18 char    *gsItemListFile = DEFAULT_ITEM_FILE;
19
20 // === CODE ===
21 /**
22  * \brief Read the item list from disk
23  */
24 void Load_Itemlist(void)
25 {
26         FILE    *fp = fopen(gsItemListFile, "r");
27         char    buffer[BUFSIZ];
28         char    *line;
29         
30         // Error check
31         if(!fp) {
32                 fprintf(stderr, "Unable to open item file '%s'\n", gsItemListFile);
33                 perror("Unable to open item file");
34         }
35         
36         while( fgets(buffer, BUFSIZ, fp) )
37         {
38                 char    *tmp;
39                 char    *type, *num, *price, *desc;
40                 // Remove comments
41                 tmp = strchr(buffer, '#');
42                 if(tmp) *tmp = '\0';
43                 tmp = strchr(buffer, ';');
44                 if(tmp) *tmp = '\0';
45                 
46                 // Trim whitespace
47                 line = trim(buffer);
48                 
49                 // Parse Line
50                 // - Type
51                 type = line;
52                 // - Number
53                 num = strchr(type, ' ');
54                 if(num)         while(*num == ' ' || *num == '\t');
55                 if(!num) {
56                         fprintf(stderr, "Syntax error on line %i of item file\n", lineNum);
57                         continue;
58                 }
59                 // - Price
60                 price = strchr(num, ' ');
61         }
62         
63 }

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