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() {
58 char *time = get_time();
60 struct credits_t *credit;
63 cprintf("\r\nName:\r\n");
64 if ((input = get_input()) == NULL || *input == '\0')
65 return; // no name given
67 if ((credit = find_credit(input)) == NULL)
68 return; // cannot find named credit
70 cprintf("\r\nEinzahlung in Cent:\r\n");
71 if ((input = get_input()) == NULL || *input == '\0' || (deposit = atoi(input)) == 0)
74 credit->credit += deposit;
77 cprintf("%d Cent eingezahlt fuer %s.\r\nRestguthaben: %d\r\n", deposit, credit->nickname);
78 sprintf(print_buffer, "%c%s - %d Cent eingezahlt fuer %s. Restguthaben: %d Cent\r", 17, time, deposit, credit->nickname, credit->credit);
79 cprintf("%s", print_buffer);
82 cprintf("\r\nEinzahlung durchgefuehrt, druecke RETURN...\r\n");
89 static void new_credit() {
93 if (credits.num_items == 75) {
94 cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n");
100 cprintf("\rNickname:\r\n");
101 if ((input = get_input()) == NULL || *input == '\0')
103 name = strdup(input);
104 cprintf("\r\nGuthaben in Cents:\r\n");
105 if ((input = get_input()) == NULL || *input == '\0' || (credit = atoi(input)) == 0)
107 strcpy(credits.credits[credits.num_items].nickname, name);
108 credits.credits[credits.num_items].credit = credit;
110 sprintf(print_buffer, "%cGuthaben mit %d Cent fuer %s angelegt\r", 17, credit, name);
117 static void _delete_credit(BYTE num) {
118 memset(credits.credits[num].nickname, '\0', 11);
119 credits.credits[num].credit = 0;
122 static void delete_credit() {
126 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
127 if ((input = get_input()) == NULL || *input == '\0')
130 if (credits.num_items > 1) {
131 /* Swap last item with this one and delete the last one to avoid holes */
132 last = (credits.num_items - 1);
133 strcpy(credits.credits[num].nickname, credits.credits[last].nickname);
134 credits.credits[num].credit = credits.credits[last].credit;
135 _delete_credit(last);
143 void credit_manager(){
146 credit_print_screen();
152 delete_credit(); break;
154 save_credits(); break;
156 if (current_credits_page < (credits.num_items / CREDITS_PER_PAGE))
157 current_credits_page++;
160 if (current_credits_page > 0)
161 current_credits_page--;
164 deposit_credit(); break;
166 cprintf("Filter eingeben:\r\n");
167 filter = get_input();
168 if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0)
175 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");