git.ucc.asn.au
/
tpg
/
opendispense2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Working on item database
[tpg/opendispense2.git]
/
server
/
src
/
itemdb.c
diff --git
a/server/src/itemdb.c
b/server/src/itemdb.c
index
cf8e7f1
..
01f801e
100644
(file)
--- a/
server/src/itemdb.c
+++ b/
server/src/itemdb.c
@@
-9,6
+9,8
@@
*/
#include <stdlib.h>
#include <stdio.h>
*/
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
#include "common.h"
// === GLOBALS ===
#include "common.h"
// === GLOBALS ===
@@
-17,6
+19,10
@@
tItem *gaItems = NULL;
tHandler *gaHandlers = NULL;
char *gsItemListFile = DEFAULT_ITEM_FILE;
tHandler *gaHandlers = NULL;
char *gsItemListFile = DEFAULT_ITEM_FILE;
+// === PROTOTYPES ===
+void Load_Itemlist(void);
+char *trim(char *__str);
+
// === CODE ===
/**
* \brief Read the item list from disk
// === CODE ===
/**
* \brief Read the item list from disk
@@
-26,6
+32,7
@@
void Load_Itemlist(void)
FILE *fp = fopen(gsItemListFile, "r");
char buffer[BUFSIZ];
char *line;
FILE *fp = fopen(gsItemListFile, "r");
char buffer[BUFSIZ];
char *line;
+ int lineNum = 0;
// Error check
if(!fp) {
// Error check
if(!fp) {
@@
-37,6
+44,9
@@
void Load_Itemlist(void)
{
char *tmp;
char *type, *num, *price, *desc;
{
char *tmp;
char *type, *num, *price, *desc;
+
+ lineNum ++;
+
// Remove comments
tmp = strchr(buffer, '#');
if(tmp) *tmp = '\0';
// Remove comments
tmp = strchr(buffer, '#');
if(tmp) *tmp = '\0';
@@
-51,13
+61,41
@@
void Load_Itemlist(void)
type = line;
// - Number
num = strchr(type, ' ');
type = line;
// - Number
num = strchr(type, ' ');
- if(num) while(*num == ' ' || *num == '\t');
- if(!num) {
+ if(num) {
+ while(*num == ' ' || *num == '\t') num ++;
+ }
+ else {
fprintf(stderr, "Syntax error on line %i of item file\n", lineNum);
continue;
}
// - Price
price = strchr(num, ' ');
fprintf(stderr, "Syntax error on line %i of item file\n", lineNum);
continue;
}
// - Price
price = strchr(num, ' ');
+ if( price ) {
+ while(*num == ' ' || *num == '\t') num ++;
+ }
+ else {
+ fprintf(stderr, "Syntax error on line %i of item file\n", lineNum);
+ continue;
+ }
+ // - Name/Description
+ desc = strchr(price, ' ');
}
}
}
}
+
+char *trim(char *__str)
+{
+ char *ret;
+ int i;
+
+ while( isspace(*__str) )
+ __str++;
+ ret = __str;
+
+ i = strlen(ret);
+ while( i-- && isspace(__str[i]) ) {
+ __str[i] = '\0';
+ }
+
+ return ret;
+}
UCC
git Repository :: git.ucc.asn.au