3 * UCC (University [of WA] Computer Club) Electronic Accounting System
5 * itemdb.c - Dispense Item Databse
7 * This file is licenced under the 3-clause BSD Licence. See the file COPYING
18 tItem *gaItems = NULL;
19 tHandler *gaHandlers = NULL;
20 char *gsItemListFile = DEFAULT_ITEM_FILE;
23 void Load_Itemlist(void);
24 char *trim(char *__str);
28 * \brief Read the item list from disk
30 void Load_Itemlist(void)
32 FILE *fp = fopen(gsItemListFile, "r");
39 fprintf(stderr, "Unable to open item file '%s'\n", gsItemListFile);
40 perror("Unable to open item file");
43 while( fgets(buffer, BUFSIZ, fp) )
46 char *type, *num, *price, *desc;
51 tmp = strchr(buffer, '#');
53 tmp = strchr(buffer, ';');
63 num = strchr(type, ' ');
65 while(*num == ' ' || *num == '\t') num ++;
68 fprintf(stderr, "Syntax error on line %i of item file\n", lineNum);
72 price = strchr(num, ' ');
74 while(*num == ' ' || *num == '\t') num ++;
77 fprintf(stderr, "Syntax error on line %i of item file\n", lineNum);
81 desc = strchr(price, ' ');
86 char *trim(char *__str)
91 while( isspace(*__str) )
96 while( i-- && isspace(__str[i]) ) {