2 * RGB2R-C128-Kassenprogramm
3 * (c) 2007 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 / 16);
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 * 16); i < credits.num_items && i < ((current_credits_page+1) * 16); 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 static struct credits_t * find_credit(char * name){
46 for (i=0;i<credits.num_items;i++)
47 if (strncmp(name, credits.credits[i].nickname, 11) == 0) {
48 return &credits.credits[i];
53 /* this is currently broken and should not be used
55 * when depositing money with this and returning to the main menu, the program
56 * will crash with a message like the following:
60 * e180b 31 27 0a 00 e8 ....
62 static void deposit_credit() {
64 struct credits_t * credit;
67 cprintf("\r\nName:\r\n");
68 if ((input = get_input()) == NULL || *input == '\0')
69 return; // no name given
71 if (!(credit = find_credit(input)))
72 return; // cannot find named credit
74 cprintf("\r\nEinzahlung in Cent:\r\n");
75 if ((input = get_input()) == NULL || *input == '\0' || (deposit = atoi(input)) == 0)
78 credit->credit += deposit;
81 cprintf("%d Cent eingezahlt fuer %s. Restguthaben: %d\r\n", deposit, credit->nickname, credit->credit);
87 static void new_credit() {
91 if (credits.num_items == 75) {
92 cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n");
97 cprintf("\rNickname:\r\n");
98 if ((input = get_input()) == NULL || *input == '\0')
100 name = strdup(input);
101 cprintf("\r\nGuthaben in Cents:\r\n");
102 if ((input = get_input()) == NULL || *input == '\0' || (credit = atoi(input)) == 0)
104 strcpy(credits.credits[credits.num_items].nickname, name);
105 credits.credits[credits.num_items].credit = credit;
110 static void _delete_credit(BYTE num) {
111 memset(credits.credits[num].nickname, '\0', 11);
112 credits.credits[num].credit = 0;
115 static void delete_credit() {
119 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
120 if ((input = get_input()) == NULL || *input == '\0')
123 if (credits.num_items > 1) {
124 /* Swap last item with this one and delete the last one to avoid holes */
125 last = (credits.num_items - 1);
126 strcpy(credits.credits[num].nickname, credits.credits[last].nickname);
127 credits.credits[num].credit = credits.credits[last].credit;
128 _delete_credit(last);
136 void credit_manager(){
139 credit_print_screen();
145 delete_credit(); break;
147 save_credits(); break;
149 if (current_credits_page < (credits.num_items / 16))
150 current_credits_page++;
153 if (current_credits_page > 0)
154 current_credits_page--;
157 deposit_credit(); break;
159 cprintf("Filter eingeben:\r\n");
160 filter = get_input();
161 if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0)
167 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");