From: Maik Fischer Date: Sun, 29 Oct 2017 14:30:05 +0000 (+0100) Subject: use EUR_FORMAT_MINLEN to get rid of more magic numbers X-Git-Tag: rgb2rv17~9^2~5 X-Git-Url: https://git.sur5r.net/?p=c128-kasse;a=commitdiff_plain;h=7bfa846c797c312fd02a38f0264c109482540eb7 use EUR_FORMAT_MINLEN to get rid of more magic numbers --- diff --git a/include/general.h b/include/general.h index 413fa46..0133e30 100644 --- a/include/general.h +++ b/include/general.h @@ -2,6 +2,7 @@ #define GENERAL_H_ #include +#include "vdc_patch_charset.h" typedef unsigned char BYTE; typedef enum { @@ -63,6 +64,9 @@ extern BYTE _oserror; #define VIDEOMODE (((*(BYTE *)0xD7) == 0x80) ? 80 : 40) +#define EUR_FORMAT "%3d,%02d" EURSYM +#define EUR_FORMAT_MINLEN (sizeof("999,99" EURSYM) + 1) + /* because there is no macro expansion when stringifying, we need to use two * levels of macros to stringify the value of a macro (for example * MAX_ITEM_NAME_LENGTH) */ diff --git a/src/credit_manager.c b/src/credit_manager.c index 1f569f7..7aa4724 100644 --- a/src/credit_manager.c +++ b/src/credit_manager.c @@ -24,7 +24,7 @@ static BYTE current_credits_page = 0; static void credit_print_screen(void) { BYTE i, pages; - char buffer[10]; + char buffer[EUR_FORMAT_MINLEN]; clrscr(); cprintf("credit_manager (phil_fry, sECuRE, sur5r) v:" GV "\r\n\r\n"); diff --git a/src/general.c b/src/general.c index df0c2c6..d888a9a 100644 --- a/src/general.c +++ b/src/general.c @@ -141,7 +141,7 @@ char retry_or_quit(void) { } char *format_euro(char *s, int maxlen, int cent) { - if (snprintf(s, maxlen, "%3d,%02d" EURSYM, cent / 100, cent % 100) > maxlen) + if (snprintf(s, maxlen, EUR_FORMAT, cent / 100, cent % 100) > maxlen) return NULL; return s; } diff --git a/src/itemz.c b/src/itemz.c index 3f4d749..574705a 100644 --- a/src/itemz.c +++ b/src/itemz.c @@ -21,13 +21,13 @@ static void itemz_print_screen(void) { BYTE i; - char buffer[10]; + char buffer[EUR_FORMAT_MINLEN]; clrscr(); 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) { + if (format_euro(buffer, sizeof(buffer), status.status[i].price) != buffer) { cprintf("Error: Could not format price %d\r\n", status.status[i].price); exit(1); } diff --git a/src/kasse.c b/src/kasse.c index d6ffb48..eca3fce 100644 --- a/src/kasse.c +++ b/src/kasse.c @@ -25,7 +25,7 @@ // graphic 4,0,10 void print_item(BYTE i) { - char profit[10]; + char profit[EUR_FORMAT_MINLEN]; if (format_euro(profit, sizeof(profit), status.status[i].price) == NULL) { cprintf("Preis %ld konnte nicht umgerechnet werden\r\n", status.status[i].price); @@ -42,7 +42,7 @@ void print_item(BYTE i) { static void print_screen(void) { BYTE i = 0; char *time = get_time(); - char profit[10]; + char profit[EUR_FORMAT_MINLEN]; clrscr(); if (format_euro(profit, sizeof(profit), money) == NULL) { cprintf("Einnahme %ld konnte nicht umgerechnet werden\r\n", money); @@ -112,7 +112,7 @@ static void print_screen(void) { static void print_log(char *name, int item_price, int einheiten, char *nickname, char *rest) { char *time = get_time(); - char price[10]; + char price[EUR_FORMAT_MINLEN]; /* Format: Transaction-ID (Anzahl verkaufter Einträge, inklusive des zu druckenden!) -- 6-stellig @@ -145,7 +145,7 @@ static signed int buy(char *name, unsigned int price) { BYTE c, nickname_len; int einheiten; char nickname[NICKNAME_MAX_LEN + 1]; - char rest[10]; + char rest[EUR_FORMAT_MINLEN]; struct credits_t *credit; memset(nickname, '\0', sizeof(nickname)); @@ -159,7 +159,7 @@ static signed int buy(char *name, unsigned int price) { if (einheiten > 100 || einheiten < -100 || einheiten == 0) { cprintf("\r\nEinheit nicht in [-100, 100] oder 0, Abbruch, dr" uUML "cke " "RETURN...\r\n"); - cgetc(); + cget_return(); return 1; }