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.com
barcodes.svg

View file

@ -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

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 <string.h>
#include <stdlib.h>
#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;
}

View file

@ -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;
}

View file

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

View file

@ -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

View file

@ -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