2 * RGB2R-C128-Kassenprogramm
3 * (c) 2007-2008 phil_fry, sECuRE, sur5r
4 * See LICENSE for license information
16 static char *filter = NULL;
17 static BYTE filter_len;
19 static BYTE current_credits_page = 0;
21 static void credit_print_screen() {
26 cprintf("itemz (phil_fry, sECuRE, sur5r)\r\n\r\n");
27 pages = (credits.num_items / CREDITS_PER_PAGE);
28 if (current_credits_page > pages)
29 current_credits_page = pages;
30 cprintf("Datei: CREDITS (Seite %d von %d)\r\n\r\n", current_credits_page, pages);
31 for (i = (current_credits_page * CREDITS_PER_PAGE); i < credits.num_items && i < ((current_credits_page+1) * CREDITS_PER_PAGE); i++) {
32 if (filter == NULL || strncmp(credits.credits[i].nickname, filter, filter_len) == 0) {
33 if (format_euro(buffer, 10, credits.credits[i].credit) != buffer) {
34 cprintf("Error: Could not format credit %d\r\n", credits.credits[i].credit);
38 cprintf("%d: %s: %s\r\n", i, credits.credits[i].nickname, buffer);
41 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");
44 struct credits_t *find_credit(char *name){
46 for (i = 0; i < credits.num_items; i++)
47 if (strncmp(name, credits.credits[i].nickname, NICKNAME_MAX_LEN + 1) == 0)
48 return &credits.credits[i];
53 * when depositing money with this and returning to the main menu, the program
54 * will crash with a message like the following:
57 static void deposit_credit() {
59 struct credits_t *credit;
62 cprintf("\r\nName:\r\n");
63 if ((input = get_input()) == NULL || *input == '\0')
64 return; // no name given
66 if ((credit = find_credit(input)) == NULL)
67 return; // cannot find named credit
69 cprintf("\r\nEinzahlung in Cent:\r\n");
70 if ((input = get_input()) == NULL || *input == '\0' || (deposit = atoi(input)) == 0)
73 credit->credit += deposit;
76 cprintf("%d Cent eingezahlt fuer %s.\r\nRestguthaben: %d\r\n", deposit, credit->nickname);
77 sprintf(print_buffer, "%c%d Cent eingezahlt fuer %s. Restguthaben: %d Cent\r", 17, deposit, credit->nickname, credit->credit);
78 cprintf("%s", print_buffer);
81 cprintf("\r\nEinzahlung durchgefuehrt, druecke RETURN...\r\n");
88 static void new_credit() {
92 if (credits.num_items == 75) {
93 cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n");
99 cprintf("\rNickname:\r\n");
100 if ((input = get_input()) == NULL || *input == '\0')
102 name = strdup(input);
103 cprintf("\r\nGuthaben in Cents:\r\n");
104 if ((input = get_input()) == NULL || *input == '\0' || (credit = atoi(input)) == 0)
106 strcpy(credits.credits[credits.num_items].nickname, name);
107 credits.credits[credits.num_items].credit = credit;
109 sprintf(print_buffer, "%cGuthaben mit %d Cent fuer %s angelegt\r", 17, credit, name);
116 static void _delete_credit(BYTE num) {
117 memset(credits.credits[num].nickname, '\0', 11);
118 credits.credits[num].credit = 0;
121 static void delete_credit() {
125 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
126 if ((input = get_input()) == NULL || *input == '\0')
129 if (credits.num_items > 1) {
130 /* Swap last item with this one and delete the last one to avoid holes */
131 last = (credits.num_items - 1);
132 strcpy(credits.credits[num].nickname, credits.credits[last].nickname);
133 credits.credits[num].credit = credits.credits[last].credit;
134 _delete_credit(last);
142 void credit_manager(){
145 credit_print_screen();
151 delete_credit(); break;
153 save_credits(); break;
155 if (current_credits_page < (credits.num_items / CREDITS_PER_PAGE))
156 current_credits_page++;
159 if (current_credits_page > 0)
160 current_credits_page--;
163 deposit_credit(); break;
165 cprintf("Filter eingeben:\r\n");
166 filter = get_input();
167 if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0)
174 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");