From da1423ee1c6f11aef0e98ade4fcecbe1a63f3772 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 22 Apr 2011 04:27:22 +0200 Subject: [PATCH 1/5] fix applogic --- Makefile | 2 +- brmbar.c | 74 ++++++++++++++++++++++++------------------------------ items.txt | 2 +- people.txt | 26 ++++++++++++++++++- 4 files changed, 60 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index e30beb3..9669154 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ all: brmbar.c bcc -Md -W brmbar.c -o brmbar.com clean: - rm -f brmbar.com + rm -f brmbar.com brmbar dos: dosbox brmbar.com diff --git a/brmbar.c b/brmbar.c index d2f0d87..9821fce 100644 --- a/brmbar.c +++ b/brmbar.c @@ -19,6 +19,7 @@ char people[PEOPLE_MAXCOUNT][PERSON_MAXLEN]; int items_count; int people_count; +int last_item = -1; char buf[BUFSIZE]; @@ -86,61 +87,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))) { + if (items[i].price) { + last_item = i; + printf("\n%s %d Kc\n\n", items[i].name, 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], strlen(people[i]) )) { + 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, 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/items.txt b/items.txt index 2dfaded..d92c0a3 100644 --- a/items.txt +++ b/items.txt @@ -3,6 +3,6 @@ cred100 Credit 100 cred200 Credit 200 cred500 Credit 500 cred1000 Credit 1000 -status Status 0 +RESET RESET 0 4029764001807 Club Mate 0.5L -35 4029764001821 Club Mate 0.33L -25 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 From 0ed434d9d215f5c02351da07b05192aba439a22f Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 22 Apr 2011 04:47:04 +0200 Subject: [PATCH 2/5] code done --- Makefile | 6 +++--- brmbar.c | 3 ++- dataio.c | 18 +++++++++++------- dataio.h | 1 - 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index c68511f..25213c1 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ 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 brmbar.c dataio.c -o brmbar + bcc -Md -W brmbar.c dataio.c -o brmbar.com clean: rm -f brmbar.com brmbar diff --git a/brmbar.c b/brmbar.c index 9821fce..d24bfbd 100644 --- a/brmbar.c +++ b/brmbar.c @@ -1,5 +1,6 @@ #include #include +#include "dataio.h" #define EAN_MAXLEN 32 #define NAME_MAXLEN 128 @@ -95,7 +96,7 @@ void read_input() // scan items for (i = 0; i < items_count; ++i) { - if (!strncmp(buf, items[i].ean, strlen(items[i].ean))) { + 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, items[i].price); 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 - From 4986b6c2882459c3362384ee8ce15d2cb0081b2c Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 22 Apr 2011 05:09:31 +0200 Subject: [PATCH 3/5] add barcode generator --- .gitignore | 1 + barcodes.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 barcodes.py 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/barcodes.py b/barcodes.py new file mode 100755 index 0000000..6eb30fb --- /dev/null +++ b/barcodes.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# +# requires zint binary from zint package +# + +from subprocess import Popen, PIPE +import sys + +svghead = """ + +""" + +svgfoot = """ + +""" + +cntx = 5 +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) +items += ['cred50','cred100','cred200','cred500','cred1000','RESET'] + +f = open('barcodes.svg','w') +f.write(svghead) + +i = 0 +j = 0 +for item in items: + elem = Popen(('zint','--directsvg','-d', item), 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, 42+i*200 , 14+j*90) ) + elem[23] = item + f.write('\n'.join(elem)) + i += 1 + if i >= cntx: + i = 0 + j += 1 + +f.write(svgfoot) +f.close() From 3cbb55a2be86ac1a16c2ac6f55cb54fe8d8c49d1 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 22 Apr 2011 05:31:21 +0200 Subject: [PATCH 4/5] barcodes --- Makefile | 2 +- barcodes.py | 14 ++++++++------ brmbar.c | 2 +- items.txt | 13 +++++++------ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 25213c1..6460a62 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ all: brmbar.c 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 index 6eb30fb..081ec2f 100755 --- a/barcodes.py +++ b/barcodes.py @@ -14,7 +14,7 @@ svgfoot = """ """ -cntx = 5 +cntx = 6 cnty = 10 scalex = 1.2 scaley = 1.2 @@ -24,18 +24,20 @@ items = f.readlines() f.close() items = map(lambda x: x.strip(), items) -items += ['cred50','cred100','cred200','cred500','cred1000','RESET'] +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 item in items: - elem = Popen(('zint','--directsvg','-d', item), stdout = PIPE).communicate()[0].split('\n') +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, 42+i*200 , 14+j*90) ) - elem[23] = item + 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: diff --git a/brmbar.c b/brmbar.c index d24bfbd..46ff12c 100644 --- a/brmbar.c +++ b/brmbar.c @@ -110,7 +110,7 @@ void read_input() // scan people for (i = 0; i < people_count; ++i) { - if (!strncmp( buf, people[i], strlen(people[i]) )) { + if (!strncmp( buf, people[i], 3 )) { printf("\nMember %s ", people[i]); if (last_item == -1) { balance = modify_credit(people[i], 0); diff --git a/items.txt b/items.txt index d92c0a3..9ecfa71 100644 --- a/items.txt +++ b/items.txt @@ -1,8 +1,9 @@ -cred50 Credit 50 -cred100 Credit 100 -cred200 Credit 200 -cred500 Credit 500 -cred1000 Credit 1000 -RESET RESET 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 From d86b9763c09a771a069845f705705bae3d48b5cf Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 22 Apr 2011 05:47:10 +0200 Subject: [PATCH 5/5] use abs for values --- Makefile | 2 +- brmbar.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6460a62..ac4be44 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CC=bcc CFLAGS=-Md -W all: brmbar.c -# gcc brmbar.c dataio.c -o brmbar +# gcc -Wall brmbar.c dataio.c -o brmbar bcc -Md -W brmbar.c dataio.c -o brmbar.com clean: diff --git a/brmbar.c b/brmbar.c index 46ff12c..aaf1c1e 100644 --- a/brmbar.c +++ b/brmbar.c @@ -1,5 +1,6 @@ #include #include +#include #include "dataio.h" #define EAN_MAXLEN 32 @@ -99,7 +100,7 @@ void read_input() 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, items[i].price); + 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); @@ -117,7 +118,7 @@ void read_input() 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, items[last_item].price, balance); + 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; } return;