/*
* RGB2R-C128-Kassenprogramm
- * (c) 2007 phil_fry, sECuRE, sur5r
+ * (c) 2007-2008 phil_fry, sECuRE, sur5r
* See LICENSE for license information
*
*/
clrscr();
cprintf("itemz (phil_fry, sECuRE, sur5r)\r\n\r\n");
- /* 16 entries per page */
- pages = (credits.num_items / 16);
+ pages = (credits.num_items / CREDITS_PER_PAGE);
if (current_credits_page > pages)
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);
+ for (i = (current_credits_page * CREDITS_PER_PAGE); i < credits.num_items && i < ((current_credits_page+1) * CREDITS_PER_PAGE); i++) {
+ 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");
+}
+
+struct credits_t *find_credit(char *name){
+ int i;
+ for (i = 0; i < credits.num_items; i++)
+ if (strncmp(name, credits.credits[i].nickname, NICKNAME_MAX_LEN + 1) == 0)
+ return &credits.credits[i];
+ return NULL;
}
+/*
+ * when depositing money with this and returning to the main menu, the program
+ * will crash with a message like the following:
+ *
+ */
+static void deposit_credit() {
+ 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 ((credit = find_credit(input)) == NULL)
+ 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.\r\nRestguthaben: %d\r\n", deposit, credit->nickname, credit->credit);
+ toggle_videomode();
+ cprintf("\r\nEinzahlung durchgefuehrt, drucke RETURN...\r\n");
+ input = get_input();
+ toggle_videomode();
+ clrscr();
+ toggle_videomode();
+}
static void new_credit() {
char *input, *name;
case 's':
save_credits(); break;
case 'f':
- if (current_credits_page < (credits.num_items / 16))
+ if (current_credits_page < (credits.num_items / CREDITS_PER_PAGE))
current_credits_page++;
break;
case 'b':
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: