]> git.sur5r.net Git - c128-kasse/commitdiff
put filter back in again.
authormatze <matze@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Thu, 25 Oct 2007 15:11:41 +0000 (15:11 +0000)
committermatze <matze@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Thu, 25 Oct 2007 15:11:41 +0000 (15:11 +0000)
implemented a deposit function which crashes the program...

git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@62 af93e077-1a23-4f1e-9cbe-9382a9d578f5

src/credit_manager.c

index 6fa39d5b5bb4b534217c36f683dafdd855430a8b..35ea3725b098131bf2969f56f02668e4bb8d9983 100644 (file)
@@ -29,16 +29,60 @@ static void credit_print_screen() {
                current_credits_page = pages;
        cprintf("Datei: CREDITS (Seite %d von %d)\r\n\r\n", current_credits_page, pages);
        for (i = (current_credits_page * 16); i < credits.num_items && i < ((current_credits_page+1) * 16); i++) {
-               if (format_euro(buffer, 10, credits.credits[i].credit) != buffer) {
-                       cprintf("Error: Could not format credit %d\r\n", credits.credits[i].credit);
-                       exit(1);
+               if (filter == NULL || strncmp(credits.credits[i].nickname, filter, filter_len) == 0) {
+                       if (format_euro(buffer, 10, credits.credits[i].credit) != buffer) {
+                               cprintf("Error: Could not format credit %d\r\n", credits.credits[i].credit);
+                               exit(1);
+                       }
+       
+                       cprintf("%d: %s: %s\r\n", i, credits.credits[i].nickname, buffer);
                }
-
-               cprintf("%d: %s: %s\r\n", i, credits.credits[i].nickname, buffer);
        }
-       cprintf("\r\nn) Neu d) Loeschen b) Seite hoch f) Seite runter\r\ne) Aendern s) Speichern z) Zurueck\r\n");
+       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){
+       int i;
+       for (i=0;i<credits.num_items;i++)
+               if (strncmp(name, credits.credits[i].nickname, 11) == 0) {
+                       return &credits.credits[i];
+               }
+       return NULL;
+}
+
+/* this is currently broken and should not be used
+ *
+ * when depositing money with this and returning to the main menu, the program
+ * will crash with a message like the following:
+ * 
+ * break
+ * pc    sr ac xr yr sp
+ * e180b 31 27 0a 00 e8 ....
+ */
+static void deposit_credit() {
+       char * input;
+       struct credits_t * credit;
+       int deposit;
+
+       cprintf("\r\nName:\r\n");
+       if ((input = get_input()) == NULL || *input == '\0')
+               return; // no name given
+               
+       if (!(credit = find_credit(input)))
+               return; // cannot find named credit
+       
+       cprintf("\r\nEinzahlung in Cent:\r\n");
+       if ((input = get_input()) == NULL || *input == '\0' || (deposit = atoi(input)) == 0)
+               return;
+
+       credit->credit += deposit;
+       
+       toggle_videomode();
+       cprintf("%d Cent eingezahlt fuer %s. Restguthaben: %d\r\n", deposit, credit->nickname, credit->credit);
+       sleep(1);
+       clrscr();
+       toggle_videomode();
+}
 
 static void new_credit() {
        char *input, *name;
@@ -109,6 +153,14 @@ void credit_manager(){
                                if (current_credits_page > 0)
                                        current_credits_page--;
                                break;
+                       case 'p':
+                               deposit_credit(); break;
+                       case 'g':
+                               cprintf("Filter eingeben:\r\n");
+                               filter = get_input();
+                               if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0)
+                                       filter = NULL;
+                               break;
                        case 'z':
                                return; 
                        default: