2 * RGB2R-C128-Kassenprogramm
3 * (c) 2007-2008 phil_fry, sECuRE, sur5r
4 * See LICENSE for license information
17 static char *filter = NULL;
18 static BYTE filter_len;
20 static BYTE current_credits_page = 0;
22 static void credit_print_screen() {
27 cprintf("itemz (phil_fry, sECuRE, sur5r)\r\n\r\n");
28 pages = (credits.num_items / CREDITS_PER_PAGE);
29 if (current_credits_page > pages)
30 current_credits_page = pages;
31 cprintf("Datei: CREDITS (Seite %d von %d)\r\n\r\n", current_credits_page, pages);
32 for (i = (current_credits_page * CREDITS_PER_PAGE); i < credits.num_items && i < ((current_credits_page+1) * CREDITS_PER_PAGE); i++) {
33 if (filter == NULL || strncmp(credits.credits[i].nickname, filter, filter_len) == 0) {
34 if (format_euro(buffer, 10, credits.credits[i].credit) != buffer) {
35 cprintf("Error: Could not format credit %d\r\n", credits.credits[i].credit);
39 cprintf("%d: %s: %s\r\n", i, credits.credits[i].nickname, buffer);
42 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");
45 struct credits_t *find_credit(char *name){
47 for (i = 0; i < credits.num_items; i++)
48 if (strncmp(name, credits.credits[i].nickname, NICKNAME_MAX_LEN + 1) == 0)
49 return &credits.credits[i];
54 * when depositing money with this and returning to the main menu, the program
55 * will crash with a message like the following:
58 static void deposit_credit() {
59 char *time = get_time();
61 struct credits_t *credit;
64 cprintf("\r\nName:\r\n");
65 if ((input = get_input()) == NULL || *input == '\0')
66 return; // no name given
68 if ((credit = find_credit(input)) == NULL)
69 return; // cannot find named credit
71 cprintf("\r\nEinzahlung in Cent:\r\n");
72 if ((input = get_input()) == NULL || *input == '\0' || (deposit = atoi(input)) == 0)
75 credit->credit += deposit;
78 cprintf("%d Cent eingezahlt fuer %s.\r\nRestguthaben: %d\r\n", deposit, credit->nickname);
79 sprintf(print_buffer, "%c%s - %d Cent eingezahlt fuer %s. Restguthaben: %d Cent\r", 17, time, deposit, credit->nickname, credit->credit);
80 cprintf("%s", print_buffer);
83 cprintf("\r\nEinzahlung durchgefuehrt, druecke RETURN...\r\n");
90 static void new_credit() {
94 if (credits.num_items == 75) {
95 cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n");
101 cprintf("\rNickname:\r\n");
102 if ((input = get_input()) == NULL || *input == '\0')
104 name = strdup(input);
105 cprintf("\r\nGuthaben in Cents:\r\n");
106 if ((input = get_input()) == NULL || *input == '\0' || (credit = atoi(input)) == 0)
108 strcpy(credits.credits[credits.num_items].nickname, name);
109 credits.credits[credits.num_items].credit = credit;
111 sprintf(print_buffer, "%cGuthaben mit %d Cent fuer %s angelegt\r", 17, credit, name);
118 static void _delete_credit(BYTE num) {
119 memset(credits.credits[num].nickname, '\0', 11);
120 credits.credits[num].credit = 0;
123 static void delete_credit() {
127 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
128 if ((input = get_input()) == NULL || *input == '\0')
131 if (credits.num_items > 1) {
132 /* Swap last item with this one and delete the last one to avoid holes */
133 last = (credits.num_items - 1);
134 strcpy(credits.credits[num].nickname, credits.credits[last].nickname);
135 credits.credits[num].credit = credits.credits[last].credit;
136 _delete_credit(last);
144 void credit_manager(){
147 credit_print_screen();
153 delete_credit(); break;
155 save_credits(); break;
157 if (current_credits_page < (credits.num_items / CREDITS_PER_PAGE))
158 current_credits_page++;
161 if (current_credits_page > 0)
162 current_credits_page--;
165 deposit_credit(); break;
167 cprintf("Filter eingeben:\r\n");
168 filter = get_input();
169 if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0)
176 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");