]> git.sur5r.net Git - c128-kasse/commitdiff
* buy() now uses find_credit
authormatze <matze@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Fri, 26 Oct 2007 01:39:35 +0000 (01:39 +0000)
committermatze <matze@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Fri, 26 Oct 2007 01:39:35 +0000 (01:39 +0000)
* 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
src/credit_manager.c
src/kasse.c

index 0e718e4a43e23f795afa2b95c71f4608ae65145c..60eea81968c2b49bee2a7f24196aa66b47a7241f 100644 (file)
@@ -1,4 +1,5 @@
 #ifndef CREDIT_MANAGER_H_
 #define CREDIT_MANAGER_H_
+struct credits_t *find_credit(char *name);
 void credit_manager();
 #endif
index 870ca6330596ad1ba342ad7301ea96d87b0d9fb2..c6e56160b0cc2608288dd2f0000b81bde77efef5 100644 (file)
@@ -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;
 }
index 0064df8d7271ffba850d71f228237b68a563ff22..ed701c5ee0bff28617943cdb2c34ac258ead1de0 100644 (file)
@@ -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;