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 */
21 int log_lines_written = 0;
23 static void itemz_print_screen() {
28 cprintf("itemz (phil_fry, sECuRE, sur5r)\r\n\r\n");
29 cprintf("Datei: ITEMS\r\n\r\n");
30 for (i = 0; i < status.num_items; i++) {
31 if (format_euro(buffer, 10, status.status[i].price) != buffer) {
32 cprintf("Error: Could not format price %d\r\n", status.status[i].price);
35 cprintf("Eintrag %x: %s (%s, %d mal verkauft)\r\n",
36 i, status.status[i].item_name, buffer, status.status[i].times_sold);
38 cprintf("\r\nn) Neu d) Loeschen s) Speichern m) Credit Modus q) Beenden\r\n");
41 static void new_item() {
45 if (status.num_items == MAX_ITEMS) {
46 cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n");
51 cprintf("\rName des Eintrags:\r\n");
52 if ((input = get_input()) == NULL || *input == '\0')
55 cprintf("\r\nPreis in Cents:\r\n");
56 if ((input = get_input()) == NULL || *input == '\0' || (price = atoi(input)) == 0)
58 cprintf("\r\nWie oft schon verkauft? [0] \r\n");
59 if ((input = get_input()) == NULL || *input == '\0')
61 memset(status.status[status.num_items].item_name, '\0', MAX_ITEM_NAME_LENGTH+1);
62 strncpy(status.status[status.num_items].item_name, name, MAX_ITEM_NAME_LENGTH);
63 status.status[status.num_items].price = price;
64 status.status[status.num_items].times_sold = atoi(input);
69 static void _delete_item(BYTE num) {
70 memset(status.status[num].item_name, '\0', MAX_ITEM_NAME_LENGTH);
71 status.status[num].price = 0;
72 status.status[num].times_sold = 0;
75 static void delete_item() {
79 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
80 if ((input = get_input()) == NULL || *input == '\0')
83 if (status.num_items > 1) {
84 /* Swap last item with this one and delete the last one to avoid holes */
85 last = (status.num_items - 1);
86 strcpy(status.status[num].item_name, status.status[last].item_name);
87 status.status[num].price = status.status[last].price;
88 status.status[num].times_sold = status.status[last].times_sold;
97 static void itemz_manager(){
100 itemz_print_screen();
106 delete_item(); break;
110 return; // switch to credit mode
114 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");
123 credits.num_items = 0;
124 status.num_items = 0;
125 cprintf("itemz loading...\n");
127 cprintf("itemz: loading ITEMS...\n");
129 cprintf("itemz: loading CREDITS...\n");