From 5b5804e1799212ccbb104af947cfe9ac8a4452cb Mon Sep 17 00:00:00 2001 From: matze Date: Fri, 26 Oct 2007 01:39:35 +0000 Subject: [PATCH] * buy() now uses find_credit * there is no strncasecmp git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@64 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- include/credit_manager.h | 1 + src/credit_manager.c | 4 ++-- src/kasse.c | 33 ++++++++++++++++----------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/credit_manager.h b/include/credit_manager.h index 0e718e4..60eea81 100644 --- a/include/credit_manager.h +++ b/include/credit_manager.h @@ -1,4 +1,5 @@ #ifndef CREDIT_MANAGER_H_ #define CREDIT_MANAGER_H_ +struct credits_t *find_credit(char *name); void credit_manager(); #endif diff --git a/src/credit_manager.c b/src/credit_manager.c index 870ca63..c6e5616 100644 --- a/src/credit_manager.c +++ b/src/credit_manager.c @@ -41,10 +41,10 @@ static void credit_print_screen() { cprintf("\r\nn) Neu d) Loeschen p) Einzahlen b) Seite hoch f) Seite runter\r\ng) Filtern e) Aendern s) Speichern z) Zurueck\r\n"); } -static struct credits_t *find_credit(char *name){ +struct credits_t *find_credit(char *name){ int i; for (i = 0; i < credits.num_items; i++) - if (strncasecmp(name, credits.credits[i].nickname, 11) == 0) + if (strncmp(name, credits.credits[i].nickname, 11) == 0) return &credits.credits[i]; return NULL; } diff --git a/src/kasse.c b/src/kasse.c index 0064df8..ed701c5 100644 --- a/src/kasse.c +++ b/src/kasse.c @@ -107,6 +107,7 @@ void buy(BYTE n) { BYTE c, nickname_len; int einheiten; char *nickname; + struct credits_t *credit; if (status.status[n].item_name == NULL) { cprintf("FEHLER: Diese Einheit existiert nicht.\r\n"); @@ -142,24 +143,22 @@ void buy(BYTE n) { nickname_len = strlen(nickname); /* go through credits and remove the amount of money or set nickname * to NULL if no such credit could be found */ - for (c = 0; c < credits.num_items; ++c) - if (strncmp(nickname, credits.credits[c].nickname, nickname_len) == 0) { - if ((signed int)credits.credits[c].credit < ((signed int)status.status[n].price * einheiten)) { - cprintf("Sorry, %s hat nicht genug Geld :-(\r\n", nickname); - return; - } - /* Geld abziehen */ - credits.credits[c].credit -= (status.status[n].price * einheiten); - cprintf("\r\nVerbleibendes Guthaben fuer %s: %d Cents. Druecke RETURN...\r\n", - nickname, credits.credits[c].credit); - toggle_videomode(); - cprintf("\r\nDein verbleibendes Guthaben betraegt %d Cents.\r\n", credits.credits[c].credit); - toggle_videomode(); - get_input(); - matches++; - break; + credit = find_credit(nickname); + if (credit != NULL) { + if ((signed int)credit->credit < ((signed int)status.status[n].price * einheiten)) { + cprintf("Sorry, %s hat nicht genug Geld :-(\r\n", nickname); + return; } - if (matches == 0) { + /* Geld abziehen */ + credit->credit -= (status.status[n].price * einheiten); + cprintf("\r\nVerbleibendes Guthaben fuer %s: %d Cents. Druecke RETURN...\r\n", + nickname, credit->credit); + toggle_videomode(); + cprintf("\r\nDein verbleibendes Guthaben betraegt %d Cents.\r\n", credit->credit); + toggle_videomode(); + get_input(); + matches++; + } else { cprintf("\r\nNickname nicht gefunden in der Guthabenverwaltung! Abbruch, druecke RETURN...\r\n"); get_input(); return; -- 2.39.5