2 * RGB2R-C128-Kassenprogramm
3 * (c) 2007-2008 phil_fry, sECuRE, sur5r
4 * See LICENSE for license information
6 * itemz.c: Verwaltet die ITEMS- und CREDITS-datei
17 #include "credit_manager.h"
19 /* NOTE: dummy entry to fix linking */
22 static void itemz_print_screen() {
27 cprintf("itemz (phil_fry, sECuRE, sur5r)\r\n\r\n");
28 cprintf("Datei: ITEMS\r\n\r\n");
29 for (i = 0; i < status.num_items; i++) {
30 if (format_euro(buffer, 10, status.status[i].price) != buffer) {
31 cprintf("Error: Could not format price %d\r\n", status.status[i].price);
34 cprintf("Eintrag %x: %s (%s, %d mal verkauft)\r\n",
35 i, status.status[i].item_name, buffer, status.status[i].times_sold);
37 cprintf("\r\nn) Neu d) Loeschen s) Speichern m) Credit Modus q) Beenden\r\n");
40 static void new_item() {
44 if (status.num_items == MAX_ITEMS) {
45 cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n");
50 cprintf("\rName des Eintrags:\r\n");
51 if ((input = get_input()) == NULL || *input == '\0')
54 cprintf("\r\nPreis in Cents:\r\n");
55 if ((input = get_input()) == NULL || *input == '\0' || (price = atoi(input)) == 0)
57 cprintf("\r\nWie oft schon verkauft? [0] \r\n");
58 if ((input = get_input()) == NULL || *input == '\0')
60 memset(status.status[status.num_items].item_name, '\0', MAX_ITEM_NAME_LENGTH+1);
61 strncpy(status.status[status.num_items].item_name, name, MAX_ITEM_NAME_LENGTH);
62 status.status[status.num_items].price = price;
63 status.status[status.num_items].times_sold = atoi(input);
68 static void _delete_item(BYTE num) {
69 memset(status.status[num].item_name, '\0', MAX_ITEM_NAME_LENGTH);
70 status.status[num].price = 0;
71 status.status[num].times_sold = 0;
74 static void delete_item() {
78 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
79 if ((input = get_input()) == NULL || *input == '\0')
82 if (status.num_items > 1) {
83 /* Swap last item with this one and delete the last one to avoid holes */
84 last = (status.num_items - 1);
85 strcpy(status.status[num].item_name, status.status[last].item_name);
86 status.status[num].price = status.status[last].price;
87 status.status[num].times_sold = status.status[last].times_sold;
96 static void itemz_manager(){
105 delete_item(); break;
109 return; // switch to credit mode
113 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");
122 credits.num_items = 0;
123 status.num_items = 0;
124 cprintf("itemz loading...\n");
126 cprintf("itemz: loading ITEMS...\n");
128 cprintf("itemz: loading CREDITS...\n");