This commit is contained in:
Cestmir Houska 2011-04-22 05:52:07 +02:00
commit a251f6682c
8 changed files with 131 additions and 60 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
brmbar brmbar
brmbar.com brmbar.com
barcodes.svg

View file

@ -1,12 +1,12 @@
CC=bcc CC=bcc
CFLAGS=-Md -W CFLAGS=-Md -W
all: brmbar.c defines.h all: brmbar.c
gcc -Wall brmbar.c -o brmbar # gcc -Wall brmbar.c dataio.c -o brmbar
bcc -Md -W brmbar.c -o brmbar.com bcc -Md -W brmbar.c dataio.c -o brmbar.com
clean: clean:
rm -f brmbar.com brmbar rm -f brmbar.com brmbar barcodes.svg
dos: dos:
dosbox brmbar.com dosbox brmbar.com

48
barcodes.py Executable file
View file

@ -0,0 +1,48 @@
#!/usr/bin/python
#
# requires zint binary from zint package
#
from subprocess import Popen, PIPE
import sys
svghead = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="1052.3622" height="744.09448" version="1.1" id="svg2" inkscape:version="0.47 r22583" sodipodi:docname="barcodes.svg">
"""
svgfoot = """
</svg>
"""
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()

View file

@ -1,5 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "dataio.h"
#define EAN_MAXLEN 32 #define EAN_MAXLEN 32
#define NAME_MAXLEN 128 #define NAME_MAXLEN 128
@ -19,6 +21,7 @@ char people[PEOPLE_MAXCOUNT][PERSON_MAXLEN];
int items_count; int items_count;
int people_count; int people_count;
int last_item = -1;
char buf[BUFSIZE]; char buf[BUFSIZE];
@ -86,61 +89,52 @@ void fill_people()
fclose(f); fclose(f);
} }
int read_item() { void read_input()
int i; {
for (;;) { int i, balance;
printf("i> "); printf("> ");
if (fgets(buf, BUFSIZE, stdin)) { if (!fgets(buf, BUFSIZE, stdin)) return;
for (i = 0; i < items_count; ++i) {
if (!strncmp( buf, items[i].ean, strlen(items[i].ean) )) { // scan items
if (items[i].price) { for (i = 0; i < items_count; ++i) {
printf("Item: %s (%d Kc)\n\n", items[i].name, items[i].price); if (!strncmp(buf, items[i].ean, strlen(items[i].ean)) && strlen(items[i].ean)+1 == strlen(buf)) {
} else { if (items[i].price) {
printf("Item: %s\n\n", items[i].name); last_item = i;
} printf("\n%s %d Kc\n\n", items[i].name, abs(items[i].price));
return i; } else {
} last_item = -1;
printf("\n%s\n\n", items[i].name);
} }
printf("Unknown item: %s\n", buf); return;
} }
} }
}
int read_person() { // scan people
int i; for (i = 0; i < people_count; ++i) {
for (;;) { if (!strncmp( buf, people[i], 3 )) {
printf("p> "); printf("\nMember %s ", people[i]);
if (fgets(buf, BUFSIZE, stdin)) { if (last_item == -1) {
for (i = 0; i < people_count; ++i) { balance = modify_credit(people[i], 0);
if (!strncmp( buf, people[i], strlen(people[i]) )) { printf("has %d Kc.\n\n", balance);
printf("Person: %s\n\n", people[i]); } else {
return i; 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 main()
{ {
int i, p;
fill_items(); fill_items();
fill_people(); fill_people();
for (;;) { for (;;) {
i = read_item(); read_input();
p = read_person();
do_action(i, p);
} }
return 0; return 0;
} }

View file

@ -6,19 +6,24 @@ int modify_credit(name, price)
const char* name; const char* name;
int price; int price;
{ {
char filename[13]; char filename[20];
int i; int i;
int credit; int credit;
FILE* person_data; FILE* person_data;
strncpy(filename, name, 8); strcpy(filename, "DATA\\");
i = strlen(name); i = 5;
if (i > 8) i = 8; strncpy(&filename[i], name, 8);
if (strlen(name) > 8) {
i += 8;
} else {
i += strlen(name);
}
strcpy(&filename[i], ".txt"); strcpy(&filename[i], ".txt");
person_data = fopen(filename, "r"); person_data = fopen(filename, "r");
if (person_data == NULL) { if (person_data == NULL) {
printf("Warning: Filename %s does not exist!\n", filename); // printf("Warning: Filename %s does not exist!\n", filename);
credit = 0; credit = 0;
} else { } else {
fscanf(person_data, "%i", &credit); fscanf(person_data, "%i", &credit);
@ -30,7 +35,7 @@ int modify_credit(name, price)
credit += price; credit += price;
person_data = fopen(filename, "w"); person_data = fopen(filename, "w");
if (person_data == NULL) { 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 { } else {
fprintf(person_data, "%i", credit); fprintf(person_data, "%i", credit);
fclose(person_data); fclose(person_data);
@ -39,4 +44,3 @@ int modify_credit(name, price)
return credit; return credit;
} }

View file

@ -4,4 +4,3 @@
extern int modify_credit(name, price); extern int modify_credit(name, price);
#endif #endif

View file

@ -1,9 +1,10 @@
cred50 Credit 50 $02 Credit 20
cred100 Credit 100 $05 Credit 50
cred200 Credit 200 $10 Credit 100
cred500 Credit 500 $20 Credit 200
cred1000 Credit 1000 $50 Credit 500
status Status 0 $1k Credit 1000
RST RESET 0
4029764001807 Club Mate 0.5L -35 4029764001807 Club Mate 0.5L -35
4029764001821 Club Mate 0.33L -25 4029764001821 Club Mate 0.33L -25
5018374350930 Tesco Baked Beans in Tomato Sauce -20 5018374350930 Tesco Baked Beans in Tomato Sauce -20

View file

@ -1,6 +1,30 @@
abyssal
alexka
axtheb
b00lean
biiter biiter
blami
chido
czestmyr czestmyr
fissie
harvie
jenda
joe
johny
kubicekh
kxt
lui
nephirus
niekt0 niekt0
pasky
pborky
prusajr
rainbof
ruza
sargon
stick stick
swez
tma
tomsuch tomsuch
BACK tutchek
zombie