2 * RGB2R-C128-Kassenprogramm
3 * © 2007-2009 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 static void itemz_print_screen() {
24 cprintf("itemz (phil_fry, sECuRE, sur5r) v:" GV "\r\n\r\n");
25 cprintf("Datei: ITEMS\r\n\r\n");
26 for (i = 0; i < max(status.num_items, 15); i++) {
27 if (format_euro(buffer, 10, status.status[i].price) != buffer) {
28 cprintf("Error: Could not format price %d\r\n", status.status[i].price);
31 cprintf("Eintrag %2d: %s (%s, %d mal verkauft)\r\n",
32 i, status.status[i].item_name, buffer, status.status[i].times_sold);
34 cprintf("\r\nn) Neu d) Loeschen s) Speichern m) Credit Modus q) Beenden\r\n");
37 static void new_item() {
41 if (status.num_items == MAX_ITEMS) {
42 cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n");
47 cprintf("\rName des Eintrags:\r\n");
48 if ((input = get_input()) == NULL || *input == '\0')
51 cprintf("\r\nPreis in Cents:\r\n");
52 if ((input = get_input()) == NULL || *input == '\0' || (price = atoi(input)) == 0)
54 cprintf("\r\nWie oft schon verkauft? [0] \r\n");
55 if ((input = get_input()) == NULL)
57 memset(status.status[status.num_items].item_name, '\0', MAX_ITEM_NAME_LENGTH+1);
58 strncpy(status.status[status.num_items].item_name, name, MAX_ITEM_NAME_LENGTH);
59 status.status[status.num_items].price = price;
60 status.status[status.num_items].times_sold = atoi(input);
65 static void _delete_item(BYTE num) {
66 memset(status.status[num].item_name, '\0', MAX_ITEM_NAME_LENGTH);
67 status.status[num].price = 0;
68 status.status[num].times_sold = 0;
71 static void delete_item() {
75 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
76 if ((input = get_input()) == NULL || *input == '\0')
79 if (status.num_items > 1) {
80 /* Swap last item with this one and delete the last one to avoid holes */
81 last = (status.num_items - 1);
82 strcpy(status.status[num].item_name, status.status[last].item_name);
83 status.status[num].price = status.status[last].price;
84 status.status[num].times_sold = status.status[last].times_sold;
93 static void itemz_manager(){
102 delete_item(); break;
106 return; // switch to credit mode
110 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");
119 credits.num_items = 0;
120 status.num_items = 0;
121 cprintf("itemz loading...\n");
123 cprintf("itemz: loading ITEMS...\n");
125 cprintf("itemz: loading CREDITS...\n");