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 /* 16 entries per page */
27 pages = (credits.num_items / 10);
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 * 10); i < credits.num_items && i < ((current_credits_page+1) * 10); 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, credit->credit);
78 cprintf("\r\nEinzahlung durchgefuehrt, drucke RETURN...\r\n");
85 static void new_credit() {
89 if (credits.num_items == 75) {
90 cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n");
95 cprintf("\rNickname:\r\n");
96 if ((input = get_input()) == NULL || *input == '\0')
99 cprintf("\r\nGuthaben in Cents:\r\n");
100 if ((input = get_input()) == NULL || *input == '\0' || (credit = atoi(input)) == 0)
102 strcpy(credits.credits[credits.num_items].nickname, name);
103 credits.credits[credits.num_items].credit = credit;
108 static void _delete_credit(BYTE num) {
109 memset(credits.credits[num].nickname, '\0', 11);
110 credits.credits[num].credit = 0;
113 static void delete_credit() {
117 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
118 if ((input = get_input()) == NULL || *input == '\0')
121 if (credits.num_items > 1) {
122 /* Swap last item with this one and delete the last one to avoid holes */
123 last = (credits.num_items - 1);
124 strcpy(credits.credits[num].nickname, credits.credits[last].nickname);
125 credits.credits[num].credit = credits.credits[last].credit;
126 _delete_credit(last);
134 void credit_manager(){
137 credit_print_screen();
143 delete_credit(); break;
145 save_credits(); break;
147 if (current_credits_page < (credits.num_items / 16))
148 current_credits_page++;
151 if (current_credits_page > 0)
152 current_credits_page--;
155 deposit_credit(); break;
157 cprintf("Filter eingeben:\r\n");
158 filter = get_input();
159 if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0)
165 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");