diff --git a/.gitignore b/.gitignore
index c351c70..2b56fa8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
brmbar
brmbar.com
+barcodes.svg
diff --git a/Makefile b/Makefile
index c68511f..ac4be44 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,12 @@
CC=bcc
CFLAGS=-Md -W
-all: brmbar.c defines.h
- gcc -Wall brmbar.c -o brmbar
- bcc -Md -W brmbar.c -o brmbar.com
+all: brmbar.c
+# gcc -Wall brmbar.c dataio.c -o brmbar
+ bcc -Md -W brmbar.c dataio.c -o brmbar.com
clean:
- rm -f brmbar.com brmbar
+ rm -f brmbar.com brmbar barcodes.svg
dos:
dosbox brmbar.com
diff --git a/barcodes.py b/barcodes.py
new file mode 100755
index 0000000..081ec2f
--- /dev/null
+++ b/barcodes.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+#
+# requires zint binary from zint package
+#
+
+from subprocess import Popen, PIPE
+import sys
+
+svghead = """
+
+"""
+
+cntx = 6
+cnty = 10
+scalex = 1.2
+scaley = 1.2
+
+f = open('people.txt','r')
+items = f.readlines()
+f.close()
+
+items = map(lambda x: x.strip(), items)
+itemss = map(lambda x: x[0:3], items)
+items += ['credit 20', 'credit 50', 'credit 100', 'credit 200', 'credit 500', 'credit 1000', 'RESET']
+itemss += ['$02','$05','$10','$20','$50','$1k','RST']
+
+f = open('barcodes.svg','w')
+f.write(svghead)
+
+i = 0
+j = 0
+for idx in xrange(len(items)):
+ elem = Popen(('zint','--directsvg','-d', itemss[idx]), stdout = PIPE).communicate()[0].split('\n')
+ elem = elem[8:-2]
+ elem[0] = elem[0].replace('id="barcode"', 'transform="matrix(%f,0,0,%f,%f,%f)"' % (scalex, scaley, 52+i*160 , 14+j*100) )
+ elem[23] = items[idx]
+ f.write('\n'.join(elem))
+ i += 1
+ if i >= cntx:
+ i = 0
+ j += 1
+
+f.write(svgfoot)
+f.close()
diff --git a/brmbar.c b/brmbar.c
index d2f0d87..aaf1c1e 100644
--- a/brmbar.c
+++ b/brmbar.c
@@ -1,5 +1,7 @@
#include
#include
+#include
+#include "dataio.h"
#define EAN_MAXLEN 32
#define NAME_MAXLEN 128
@@ -19,6 +21,7 @@ char people[PEOPLE_MAXCOUNT][PERSON_MAXLEN];
int items_count;
int people_count;
+int last_item = -1;
char buf[BUFSIZE];
@@ -86,61 +89,52 @@ void fill_people()
fclose(f);
}
-int read_item() {
- int i;
- for (;;) {
- printf("i> ");
- if (fgets(buf, BUFSIZE, stdin)) {
- for (i = 0; i < items_count; ++i) {
- if (!strncmp( buf, items[i].ean, strlen(items[i].ean) )) {
- if (items[i].price) {
- printf("Item: %s (%d Kc)\n\n", items[i].name, items[i].price);
- } else {
- printf("Item: %s\n\n", items[i].name);
- }
- return i;
- }
+void read_input()
+{
+ int i, balance;
+ printf("> ");
+ if (!fgets(buf, BUFSIZE, stdin)) return;
+
+ // scan items
+ for (i = 0; i < items_count; ++i) {
+ if (!strncmp(buf, items[i].ean, strlen(items[i].ean)) && strlen(items[i].ean)+1 == strlen(buf)) {
+ if (items[i].price) {
+ last_item = i;
+ printf("\n%s %d Kc\n\n", items[i].name, abs(items[i].price));
+ } else {
+ last_item = -1;
+ printf("\n%s\n\n", items[i].name);
}
- printf("Unknown item: %s\n", buf);
+ return;
}
}
-}
-int read_person() {
- int i;
- for (;;) {
- printf("p> ");
- if (fgets(buf, BUFSIZE, stdin)) {
- for (i = 0; i < people_count; ++i) {
- if (!strncmp( buf, people[i], strlen(people[i]) )) {
- printf("Person: %s\n\n", people[i]);
- return i;
- }
+ // scan people
+ for (i = 0; i < people_count; ++i) {
+ if (!strncmp( buf, people[i], 3 )) {
+ printf("\nMember %s ", people[i]);
+ if (last_item == -1) {
+ balance = modify_credit(people[i], 0);
+ printf("has %d Kc.\n\n", balance);
+ } else {
+ balance = modify_credit(people[i], items[last_item].price);
+ printf("has ordered %s for %d Kc and now has %d Kc.\n\n", items[last_item].name, abs(items[last_item].price), balance);
+ last_item = -1;
}
- printf("Unknown person %s\n", buf);
+ return;
}
}
+
+ // error
+ printf("\nUnknown code %s\n", buf);
}
-
-void do_action(i, p) int i; int p; {
-// TODO: perform action - person P selected item I
- if (!strcmp("BACK", people[p])) {
- printf("Going back ...\n\n");
- return;
- }
-}
-
-
int main()
{
- int i, p;
fill_items();
fill_people();
for (;;) {
- i = read_item();
- p = read_person();
- do_action(i, p);
+ read_input();
}
return 0;
}
diff --git a/dataio.c b/dataio.c
index ff28cf4..7b50394 100644
--- a/dataio.c
+++ b/dataio.c
@@ -6,19 +6,24 @@ int modify_credit(name, price)
const char* name;
int price;
{
- char filename[13];
+ char filename[20];
int i;
int credit;
FILE* person_data;
- strncpy(filename, name, 8);
- i = strlen(name);
- if (i > 8) i = 8;
+ strcpy(filename, "DATA\\");
+ i = 5;
+ strncpy(&filename[i], name, 8);
+ if (strlen(name) > 8) {
+ i += 8;
+ } else {
+ i += strlen(name);
+ }
strcpy(&filename[i], ".txt");
person_data = fopen(filename, "r");
if (person_data == NULL) {
- printf("Warning: Filename %s does not exist!\n", filename);
+// printf("Warning: Filename %s does not exist!\n", filename);
credit = 0;
} else {
fscanf(person_data, "%i", &credit);
@@ -30,7 +35,7 @@ int modify_credit(name, price)
credit += price;
person_data = fopen(filename, "w");
if (person_data == NULL) {
- printf("ERROR: Filename %s could not be created or overwritten!\nCheck system integrity!\n", filename);
+// printf("ERROR: Filename %s could not be created or overwritten!\nCheck system integrity!\n", filename);
} else {
fprintf(person_data, "%i", credit);
fclose(person_data);
@@ -39,4 +44,3 @@ int modify_credit(name, price)
return credit;
}
-
diff --git a/dataio.h b/dataio.h
index 3e7d340..61a243d 100644
--- a/dataio.h
+++ b/dataio.h
@@ -4,4 +4,3 @@
extern int modify_credit(name, price);
#endif
-
diff --git a/items.txt b/items.txt
index 088faed..ed793fc 100644
--- a/items.txt
+++ b/items.txt
@@ -1,9 +1,10 @@
-cred50 Credit 50
-cred100 Credit 100
-cred200 Credit 200
-cred500 Credit 500
-cred1000 Credit 1000
-status Status 0
+$02 Credit 20
+$05 Credit 50
+$10 Credit 100
+$20 Credit 200
+$50 Credit 500
+$1k Credit 1000
+RST RESET 0
4029764001807 Club Mate 0.5L -35
4029764001821 Club Mate 0.33L -25
5018374350930 Tesco Baked Beans in Tomato Sauce -20
diff --git a/people.txt b/people.txt
index a096c83..a685f94 100644
--- a/people.txt
+++ b/people.txt
@@ -1,6 +1,30 @@
+abyssal
+alexka
+axtheb
+b00lean
biiter
+blami
+chido
czestmyr
+fissie
+harvie
+jenda
+joe
+johny
+kubicekh
+kxt
+lui
+nephirus
niekt0
+pasky
+pborky
+prusajr
+rainbof
+ruza
+sargon
stick
+swez
+tma
tomsuch
-BACK
+tutchek
+zombie