X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fitemz.c;h=3f4d74972e6184330321674718ae295c893fbc9d;hb=750dbde18501efb6f9520d378475e3b58aea9ea4;hp=f04678c0753f1801a6b9a5d5470c18bf0db7f3c0;hpb=e3cfeb64e598ae12843ec7a1dd4a1feda6638bce;p=c128-kasse diff --git a/src/itemz.c b/src/itemz.c index f04678c..3f4d749 100644 --- a/src/itemz.c +++ b/src/itemz.c @@ -16,13 +16,15 @@ #include "config.h" #include "credit_manager.h" #include "version.h" +#include "vdc_patch_charset.h" +#include "globals.h" static void itemz_print_screen(void) { BYTE i; char buffer[10]; clrscr(); - cprintf("itemz (phil_fry, sECuRE, sur5r) v:" GV "\r\n\r\n"); + cprintf("itemz (phil_fry, sECuRE, sur5r, mxf) v:" GV "\r\n\r\n"); cprintf("Datei: ITEMS\r\n\r\n"); for (i = 0; i < max(status.num_items, 15); i++) { if (format_euro(buffer, 10, status.status[i].price) != buffer) { @@ -32,40 +34,37 @@ static void itemz_print_screen(void) { cprintf("Eintrag %2d: %s (%s, %d mal verkauft)\r\n", i, status.status[i].item_name, buffer, status.status[i].times_sold); } - cprintf("\r\nn) Neu d) Loeschen s) Speichern m) Credit Modus q) " - "Beenden\r\nr) Reset des Verkauft-Zaehlers\r\n"); + cprintf("\r\nn) Neu d) L" oUML "schen s) Speichern m) Credit Modus q) " + "Beenden\r\nr) Reset des Verkauft-Z" aUML "hlers\r\n"); } static void new_item(void) { - char *input, *name; - int price; + char name[MAX_ITEM_NAME_LENGTH + 1]; + int price, times_sold; if (status.num_items == MAX_ITEMS) { - cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, " - "druecke RETURN...\r\n"); - input = get_input(); + cprintf("\rEs ist bereits die maximale Anzahl an Eintr" aUML + "gen erreicht, dr" uUML "cke RETURN...\r\n"); + cget_return(); return; } cprintf("\rName des Eintrags:\r\n"); - if ((input = get_input()) == NULL || *input == '\0') + if (cgetn_input(name, sizeof(name)) == 0) return; - name = strdup(input); cprintf("\r\nPreis in Cents:\r\n"); - if ((input = get_input()) == NULL || *input == '\0' || - (price = atoi(input)) == 0) + if ((price = cget_number(0)) <= 0) return; cprintf("\r\nWie oft schon verkauft? [0] \r\n"); - if ((input = get_input()) == NULL) + if ((times_sold = cget_number(0)) < 0) return; memset(status.status[status.num_items].item_name, '\0', MAX_ITEM_NAME_LENGTH + 1); strncpy(status.status[status.num_items].item_name, name, MAX_ITEM_NAME_LENGTH); status.status[status.num_items].price = price; - status.status[status.num_items].times_sold = atoi(input); + status.status[status.num_items].times_sold = times_sold; status.num_items++; - free(name); } static void _delete_item(BYTE num) { @@ -75,17 +74,17 @@ static void _delete_item(BYTE num) { } static void delete_item(void) { - char *input; BYTE num, last; cprintf("\r Welcher Eintrag soll geloescht werden?\r\n"); - if ((input = get_input()) == NULL || *input == '\0') + if ((num = cget_number(-1)) < 0) return; - num = atoi(input); + if (status.num_items > 1) { /* Swap last item with this one and delete the last one to avoid holes */ last = (status.num_items - 1); - strcpy(status.status[num].item_name, status.status[last].item_name); + strncpy(status.status[num].item_name, status.status[last].item_name, + MAX_ITEM_NAME_LENGTH); status.status[num].price = status.status[last].price; status.status[num].times_sold = status.status[last].times_sold; _delete_item(last); @@ -128,7 +127,7 @@ static void itemz_manager() { exit(0); default: cprintf("Unbekannter Befehl, druecke RETURN...\r\n"); - get_input(); + cget_return(); } } }