2 * RGB2R-C128-Kassenprogramm
3 * © 2007-2009 phil_fry, sECuRE, sur5r
4 * See LICENSE for license information
19 static char *filter = NULL;
20 static BYTE filter_len;
22 static BYTE current_credits_page = 0;
24 static void credit_print_screen(void) {
29 cprintf("credit_manager (phil_fry, sECuRE, sur5r) v:" GV "\r\n\r\n");
30 pages = (credits.num_items / CREDITS_PER_PAGE);
31 if (current_credits_page > pages)
32 current_credits_page = pages;
33 cprintf("Datei: CREDITS (Seite %d von %d)\r\n\r\n", current_credits_page,
35 for (i = (current_credits_page * CREDITS_PER_PAGE);
36 i < credits.num_items &&
37 i < ((current_credits_page + 1) * CREDITS_PER_PAGE);
40 strncmp(credits.credits[i].nickname, filter, filter_len) == 0) {
41 if (format_euro(buffer, 10, credits.credits[i].credit) != buffer) {
42 cprintf("Error: Could not format credit %d\r\n",
43 credits.credits[i].credit);
47 cprintf("%d: %s: %s\r\n", i, credits.credits[i].nickname, buffer);
50 cprintf("\r\nn) Neu d) Loeschen p) Einzahlen b) Seite hoch f) Seite "
51 "runter\r\ng) Filtern e) Aendern s) Speichern z) Zurueck\r\n");
54 struct credits_t *find_credit(char *name) {
56 for (i = 0; i < credits.num_items; i++)
57 if (strncmp(name, credits.credits[i].nickname, NICKNAME_MAX_LEN + 1) == 0)
58 return &credits.credits[i];
63 * Deposits credit for a user. Called in the credit manager (with input ==
64 * NULL) or interactively when the user does not have enough money for his
65 * intended purchase (with input == nickname).
68 void deposit_credit(char *input) {
69 char *time = get_time();
70 struct credits_t *credit;
74 cprintf("\r\nName:\r\n");
75 if ((input = get_input()) == NULL || *input == '\0')
76 return; // no name given
79 if ((credit = find_credit(input)) == NULL)
80 return; // cannot find named credit
82 cprintf("\r\nEinzahlung in Cent:\r\n");
83 if ((input = get_input()) == NULL || *input == '\0' ||
84 (deposit = atoi(input)) == 0)
87 credit->credit += deposit;
90 cprintf("\r\nEinzahlung durchgefuehrt, druecke RETURN...\r\n");
94 static void new_credit(void) {
99 if (credits.num_items == 75) {
100 cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, "
101 "druecke RETURN...\r\n");
107 cprintf("\rNickname (max. 10 Zeichen):\r\n");
108 if ((input = get_input()) == NULL || *input == '\0')
110 name = strdup(input);
111 cprintf("\r\nGuthaben in Cents:\r\n");
112 if ((input = get_input()) == NULL || *input == '\0' ||
113 (credit = atoi(input)) == 0)
115 strncpy(credits.credits[credits.num_items].nickname, name, NICKNAME_MAX_LEN);
116 credits.credits[credits.num_items].credit = credit;
119 sprintf(print_buffer, "%c%s - Guthaben mit %d Cent fuer %s angelegt\r", 17,
127 static void _delete_credit(BYTE num) {
128 memset(credits.credits[num].nickname, '\0', 11);
129 credits.credits[num].credit = 0;
132 static void delete_credit(void) {
136 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
137 if ((input = get_input()) == NULL || *input == '\0')
140 if (credits.num_items > 1) {
141 /* Swap last item with this one and delete the last one to avoid holes */
142 last = (credits.num_items - 1);
143 strcpy(credits.credits[num].nickname, credits.credits[last].nickname);
144 credits.credits[num].credit = credits.credits[last].credit;
145 _delete_credit(last);
153 void credit_manager() {
156 credit_print_screen();
169 if (current_credits_page < (credits.num_items / CREDITS_PER_PAGE))
170 current_credits_page++;
173 if (current_credits_page > 0)
174 current_credits_page--;
177 deposit_credit(NULL);
180 cprintf("Filter eingeben:\r\n");
181 filter = get_input();
182 if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0)
189 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");