/*
* RGB2R-C128-Kassenprogramm
- * (c) 2007-2008 phil_fry, sECuRE, sur5r
+ * © 2007-2009 phil_fry, sECuRE, sur5r
* See LICENSE for license information
*
*/
#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;
static BYTE current_credits_page = 0;
-static void credit_print_screen() {
+static void credit_print_screen(void) {
BYTE i, pages;
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;
}
/*
- * 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() {
- char *input;
+void deposit_credit(char *input) {
+ char *time = get_time();
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
credit->credit += deposit;
toggle_videomode();
- cprintf("%d Cent eingezahlt fuer %s.\r\nRestguthaben: %d\r\n", deposit, credit->nickname);
- sprintf(print_buffer, "%c%d Cent eingezahlt fuer %s. Restguthaben: %d Cent\r", 17, deposit, credit->nickname, credit->credit);
+ 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();
print_the_buffer();
toggle_videomode();
}
-static void new_credit() {
+static void new_credit(void) {
char *input, *name;
+ char *time;
int credit;
if (credits.num_items == 75) {
}
clrscr();
- cprintf("\rNickname:\r\n");
+ cprintf("\rNickname (max. 10 Zeichen):\r\n");
if ((input = get_input()) == NULL || *input == '\0')
return;
name = strdup(input);
cprintf("\r\nGuthaben in Cents:\r\n");
if ((input = get_input()) == NULL || *input == '\0' || (credit = atoi(input)) == 0)
return;
- strcpy(credits.credits[credits.num_items].nickname, name);
+ strncpy(credits.credits[credits.num_items].nickname, name, NICKNAME_MAX_LEN);
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++;
credits.credits[num].credit = 0;
}
-static void delete_credit() {
+static void delete_credit(void) {
char *input;
BYTE num, last;
current_credits_page--;
break;
case 'p':
- deposit_credit(); break;
+ deposit_credit(NULL); break;
case 'g':
cprintf("Filter eingeben:\r\n");
filter = get_input();