2 * RGB2R-C128-Kassenprogramm
3 * (c) 2007-2008 phil_fry, sECuRE, sur5r
4 * See LICENSE for license information
15 static char *filter = NULL;
16 static BYTE filter_len;
18 static BYTE current_credits_page = 0;
20 static void credit_print_screen() {
25 cprintf("itemz (phil_fry, sECuRE, sur5r)\r\n\r\n");
26 pages = (credits.num_items / CREDITS_PER_PAGE);
27 if (current_credits_page > pages)
28 current_credits_page = pages;
29 cprintf("Datei: CREDITS (Seite %d von %d)\r\n\r\n", current_credits_page, pages);
30 for (i = (current_credits_page * CREDITS_PER_PAGE); i < credits.num_items && i < ((current_credits_page+1) * CREDITS_PER_PAGE); i++) {
31 if (filter == NULL || strncmp(credits.credits[i].nickname, filter, filter_len) == 0) {
32 if (format_euro(buffer, 10, credits.credits[i].credit) != buffer) {
33 cprintf("Error: Could not format credit %d\r\n", credits.credits[i].credit);
37 cprintf("%d: %s: %s\r\n", i, credits.credits[i].nickname, buffer);
40 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");
43 struct credits_t *find_credit(char *name){
45 for (i = 0; i < credits.num_items; i++)
46 if (strncmp(name, credits.credits[i].nickname, NICKNAME_MAX_LEN + 1) == 0)
47 return &credits.credits[i];
52 * when depositing money with this and returning to the main menu, the program
53 * will crash with a message like the following:
56 static void deposit_credit() {
58 struct credits_t *credit;
61 cprintf("\r\nName:\r\n");
62 if ((input = get_input()) == NULL || *input == '\0')
63 return; // no name given
65 if ((credit = find_credit(input)) == NULL)
66 return; // cannot find named credit
68 cprintf("\r\nEinzahlung in Cent:\r\n");
69 if ((input = get_input()) == NULL || *input == '\0' || (deposit = atoi(input)) == 0)
72 credit->credit += deposit;
75 cprintf("%d Cent eingezahlt fuer %s.\r\nRestguthaben: %d\r\n", deposit, credit->nickname, credit->credit);
77 cprintf("\r\nEinzahlung durchgefuehrt, drucke RETURN...\r\n");
84 static void new_credit() {
88 if (credits.num_items == 75) {
89 cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n");
94 cprintf("\rNickname:\r\n");
95 if ((input = get_input()) == NULL || *input == '\0')
98 cprintf("\r\nGuthaben in Cents:\r\n");
99 if ((input = get_input()) == NULL || *input == '\0' || (credit = atoi(input)) == 0)
101 strcpy(credits.credits[credits.num_items].nickname, name);
102 credits.credits[credits.num_items].credit = credit;
107 static void _delete_credit(BYTE num) {
108 memset(credits.credits[num].nickname, '\0', 11);
109 credits.credits[num].credit = 0;
112 static void delete_credit() {
116 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
117 if ((input = get_input()) == NULL || *input == '\0')
120 if (credits.num_items > 1) {
121 /* Swap last item with this one and delete the last one to avoid holes */
122 last = (credits.num_items - 1);
123 strcpy(credits.credits[num].nickname, credits.credits[last].nickname);
124 credits.credits[num].credit = credits.credits[last].credit;
125 _delete_credit(last);
133 void credit_manager(){
136 credit_print_screen();
142 delete_credit(); break;
144 save_credits(); break;
146 if (current_credits_page < (credits.num_items / CREDITS_PER_PAGE))
147 current_credits_page++;
150 if (current_credits_page > 0)
151 current_credits_page--;
154 deposit_credit(); break;
156 cprintf("Filter eingeben:\r\n");
157 filter = get_input();
158 if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0)
164 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");