]> git.sur5r.net Git - c128-kasse/blobdiff - src/credit_manager.c
Restructure Makefile and create include/version.h
[c128-kasse] / src / credit_manager.c
index 5839f7834812e6b1c6388746c22eaa63eec5e929..670926dad7f713fd148264f0cf28d652f9009d8b 100644 (file)
@@ -1,6 +1,6 @@
 /* 
  * RGB2R-C128-Kassenprogramm
- * (c) 2007-2008 phil_fry, sECuRE, sur5r
+ * © 2007-2009 phil_fry, sECuRE, sur5r
  * See LICENSE for license information
  *
  */
@@ -12,6 +12,9 @@
 #include "config.h"
 #include "general.h"
 #include "kasse.h"
+#include "c128time.h"
+#include "print.h"
+#include "version.h"
 
 static char *filter = NULL;
 static BYTE filter_len;
@@ -23,7 +26,7 @@ static void credit_print_screen() {
        char buffer[10];
 
        clrscr();
-       cprintf("itemz (phil_fry, sECuRE, sur5r)\r\n\r\n");
+       cprintf("credit_manager (phil_fry, sECuRE, sur5r) v:" GV "\r\n\r\n");
        pages = (credits.num_items / CREDITS_PER_PAGE);
        if (current_credits_page > pages)
                current_credits_page = pages;
@@ -50,20 +53,22 @@ struct credits_t *find_credit(char *name){
 }
 
 /*
- * when depositing money with this and returning to the main menu, the program
- * will crash with a message like the following:
+ * Deposits credit for a user. Called in the credit manager (with input ==
+ * NULL) or interactively when the user does not have enough money for his
+ * intended purchase (with input == nickname).
  * 
  */
-static void deposit_credit() {
+void deposit_credit(char *input) {
        char *time = get_time();
-       char *input;
        struct credits_t *credit;
        unsigned int deposit;
 
-       cprintf("\r\nName:\r\n");
-       if ((input = get_input()) == NULL || *input == '\0')
-               return; // no name given
-               
+       if (input == NULL) {
+               cprintf("\r\nName:\r\n");
+               if ((input = get_input()) == NULL || *input == '\0')
+                       return; // no name given
+       }
+
        if ((credit = find_credit(input)) == NULL)
                return; // cannot find named credit
        
@@ -74,7 +79,7 @@ static void deposit_credit() {
        credit->credit += deposit;
        
        toggle_videomode();
-       cprintf("%d Cent eingezahlt fuer %s.\r\nRestguthaben: %d\r\n", deposit, credit->nickname);
+       cprintf("%d Cent eingezahlt fuer %s.\r\nRestguthaben: %d\r\n", deposit, credit->nickname, credit->credit);
        sprintf(print_buffer, "%c%s - %d Cent eingezahlt fuer %s. Restguthaben: %d Cent\r", 17, time, deposit, credit->nickname, credit->credit);
        cprintf("%s", print_buffer);
        toggle_videomode();
@@ -88,6 +93,7 @@ static void deposit_credit() {
 
 static void new_credit() {
        char *input, *name;
+       char *time;
        int credit;
 
        if (credits.num_items == 75) {
@@ -107,7 +113,8 @@ static void new_credit() {
        strcpy(credits.credits[credits.num_items].nickname, name);
        credits.credits[credits.num_items].credit = credit;
 
-       sprintf(print_buffer, "%cGuthaben mit %d Cent fuer %s angelegt\r", 17, credit, name);
+       time = get_time();
+       sprintf(print_buffer, "%c%s - Guthaben mit %d Cent fuer %s angelegt\r", 17, time, credit, name);
        print_the_buffer();
 
        credits.num_items++;
@@ -161,7 +168,7 @@ void credit_manager(){
                                        current_credits_page--;
                                break;
                        case 'p':
-                               deposit_credit(); break;
+                               deposit_credit(NULL); break;
                        case 'g':
                                cprintf("Filter eingeben:\r\n");
                                filter = get_input();