From da1423ee1c6f11aef0e98ade4fcecbe1a63f3772 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 22 Apr 2011 04:27:22 +0200 Subject: [PATCH] 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