From: Michael Stapelberg Date: Sun, 24 Sep 2017 14:11:33 +0000 (+0200) Subject: Format code using clang-format-3.9 (“make format”) X-Git-Tag: rgb2rv17~16 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2931ff1e7bc2a60e9e8e4a3d90763cfed6e11c87;p=c128-kasse Format code using clang-format-3.9 (“make format”) --- diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..aa19620 --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +# TODO: Sorting includes breaks compilation. Remove once fixed. +SortIncludes: false diff --git a/Makefile b/Makefile index 7c4a202..812283a 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ INCLUDES:=$(wildcard include/*.h) include/version.h GV:=$(shell git describe --tags --always) CFLAGS= -I include -t c128 -.PHONY: include/version.h clean dist-clean +.PHONY: include/version.h clean dist-clean format all: kasse itemz @@ -46,3 +46,6 @@ clean: dist-clean: clean rm -f kasse itemz kasse.d64 + +format: + clang-format-3.9 -i **/*.[ch] diff --git a/include/config.h b/include/config.h index b29f10d..5a19e80 100644 --- a/include/config.h +++ b/include/config.h @@ -13,33 +13,32 @@ extern unsigned long int money; extern unsigned long int items_sold; extern BYTE printer_port; - /* Datenstruktur der verkauften Einträge */ struct status_t { - char item_name[MAX_ITEM_NAME_LENGTH+1]; - /* Wieviel kostet der Eintrag (in Cent)? */ - unsigned int price; - /* Wie oft wurde er verkauft */ - unsigned int times_sold; + char item_name[MAX_ITEM_NAME_LENGTH + 1]; + /* Wieviel kostet der Eintrag (in Cent)? */ + unsigned int price; + /* Wie oft wurde er verkauft */ + unsigned int times_sold; }; struct status_array_t { - BYTE num_items; - unsigned int transaction_id; - struct status_t status[MAX_ITEMS]; + BYTE num_items; + unsigned int transaction_id; + struct status_t status[MAX_ITEMS]; }; /* Datenstruktur für die Guthaben */ #define NICKNAME_MAX_LEN 10 struct credits_t { - char nickname[NICKNAME_MAX_LEN + 1]; - /* Guthaben (in Cent) */ - unsigned int credit; + char nickname[NICKNAME_MAX_LEN + 1]; + /* Guthaben (in Cent) */ + unsigned int credit; }; struct credits_array_t { - BYTE num_items; - struct credits_t credits[MAX_CREDIT_ITEMS]; + BYTE num_items; + struct credits_t credits[MAX_CREDIT_ITEMS]; }; #ifndef _IS_CONFIG_C @@ -51,7 +50,7 @@ extern struct credits_array_t credits; void load_config(void); void load_items(void); void load_credits(void); -//void dump_state(void); +// void dump_state(void); void save_items(void); void save_credits(void); diff --git a/include/general.h b/include/general.h index a32ddeb..716ee39 100644 --- a/include/general.h +++ b/include/general.h @@ -5,56 +5,58 @@ typedef unsigned char BYTE; typedef enum { - INPUT_TERMINATOR_RETURN = (1 << 0), - INPUT_TERMINATOR_SPACE = (1 << 1), + INPUT_TERMINATOR_RETURN = (1 << 0), + INPUT_TERMINATOR_SPACE = (1 << 1), } input_terminator_t; typedef input_terminator_t input_terminator_mask_t; -input_terminator_t get_input_terminated_by(input_terminator_mask_t terminators, char *out, BYTE outlen); +input_terminator_t get_input_terminated_by(input_terminator_mask_t terminators, + char *out, BYTE outlen); char *get_input(void); char retry_or_quit(void); -char *format_euro(char * s, int maxlen, int cent); -void c128_perror(BYTE, char*); +char *format_euro(char *s, int maxlen, int cent); +void c128_perror(BYTE, char *); extern BYTE _oserror; /* C128 color codes, see PDF page 127 of - * http://www.pagetable.com/docs/Commodore%20128%20Programmer%27s%20Reference%20Guide.pdf */ -#define TC_BLACK 0 -#define TC_WHITE 1 -#define TC_RED 2 -#define TC_CYAN 3 -#define TC_PURPLE 4 -#define TC_GREEN 5 -#define TC_BLUE 6 -#define TC_YELLOW 7 -#define TC_ORANGE 8 -#define TC_BROWN 9 + * http://www.pagetable.com/docs/Commodore%20128%20Programmer%27s%20Reference%20Guide.pdf + */ +#define TC_BLACK 0 +#define TC_WHITE 1 +#define TC_RED 2 +#define TC_CYAN 3 +#define TC_PURPLE 4 +#define TC_GREEN 5 +#define TC_BLUE 6 +#define TC_YELLOW 7 +#define TC_ORANGE 8 +#define TC_BROWN 9 /* This is the good red */ -#define TC_LIGHT_RED 10 -#define TC_DARK_GRAY 11 +#define TC_LIGHT_RED 10 +#define TC_DARK_GRAY 11 #define TC_MEDIUM_GRAY 12 /* This is the good green */ #define TC_LIGHT_GREEN 13 -#define TC_LIGHT_BLUE 14 -#define TC_LIGHT_GRAY 15 +#define TC_LIGHT_BLUE 14 +#define TC_LIGHT_GRAY 15 /* Carriage return */ -#define PETSCII_CR 13 +#define PETSCII_CR 13 /* Delete */ #define PETSCII_DEL 20 /* Space */ -#define PETSCII_SP 32 -#define PETSCII_0 48 -#define PETSCII_1 49 -#define PETSCII_2 50 -#define PETSCII_3 51 -#define PETSCII_4 52 -#define PETSCII_5 53 -#define PETSCII_6 54 -#define PETSCII_7 55 -#define PETSCII_8 56 -#define PETSCII_9 57 +#define PETSCII_SP 32 +#define PETSCII_0 48 +#define PETSCII_1 49 +#define PETSCII_2 50 +#define PETSCII_3 51 +#define PETSCII_4 52 +#define PETSCII_5 53 +#define PETSCII_6 54 +#define PETSCII_7 55 +#define PETSCII_8 56 +#define PETSCII_9 57 -#define VIDEOMODE (((* (BYTE *)0xD7) == 0x80) ? 80 : 40) +#define VIDEOMODE (((*(BYTE *)0xD7) == 0x80) ? 80 : 40) /* 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 diff --git a/src/c128time.c b/src/c128time.c index 7bba5b8..9e5e458 100644 --- a/src/c128time.c +++ b/src/c128time.c @@ -1,4 +1,4 @@ -/* +/* * RGB2R-C128-Kassenprogramm * © 2007-2009 phil_fry, sECuRE, sur5r * See LICENSE for license information @@ -11,29 +11,29 @@ #include char *get_time(void) { - uint32_t h = PEEK(0x00A0) * 65536, - m = PEEK(0x00A1) * 256, - s = PEEK(0x00A2); - static char buffer[9]; - BYTE hrs, min; + uint32_t h = PEEK(0x00A0) * 65536, m = PEEK(0x00A1) * 256, s = PEEK(0x00A2); + static char buffer[9]; + BYTE hrs, min; - h = (h + m + s) / 60; - hrs = (h / 3600); - h -= ((uint32_t)hrs * (uint32_t)3600); - min = (h / 60); - h -= (min * 60); - - sprintf(buffer, "%02d:%02d:%02d", hrs, min, (BYTE)h); - return buffer; + h = (h + m + s) / 60; + hrs = (h / 3600); + h -= ((uint32_t)hrs * (uint32_t)3600); + min = (h / 60); + h -= (min * 60); + + sprintf(buffer, "%02d:%02d:%02d", hrs, min, (BYTE)h); + return buffer; } void set_time(BYTE hrs, BYTE min, BYTE sec) { - uint32_t added = ((uint32_t)sec + ((uint32_t)min * (uint32_t)60) + ((uint32_t)hrs * (uint32_t)3600)) * (uint32_t)60; - uint32_t lowbit = (added & 0xFF); - uint32_t middlebit = (added >> 8) & 0xFF; - uint32_t highbit = (added >> 16) & 0xFF; + uint32_t added = ((uint32_t)sec + ((uint32_t)min * (uint32_t)60) + + ((uint32_t)hrs * (uint32_t)3600)) * + (uint32_t)60; + uint32_t lowbit = (added & 0xFF); + uint32_t middlebit = (added >> 8) & 0xFF; + uint32_t highbit = (added >> 16) & 0xFF; - POKE(0x00A0, (BYTE)highbit); - POKE(0x00A1, (BYTE)middlebit); - POKE(0x00A2, (BYTE)lowbit); + POKE(0x00A0, (BYTE)highbit); + POKE(0x00A1, (BYTE)middlebit); + POKE(0x00A2, (BYTE)lowbit); } diff --git a/src/cat.c b/src/cat.c index ee93962..36ceacc 100644 --- a/src/cat.c +++ b/src/cat.c @@ -9,54 +9,53 @@ #define x2(x) (buffer[x] <= 0xF ? "0" : ""), buffer[x] int main(void) { - char *filename = NULL; - FILE *file; - unsigned int c; - unsigned char i; - char buffer[8]; - char readable[9]; + char *filename = NULL; + FILE *file; + unsigned int c; + unsigned char i; + char buffer[8]; + char readable[9]; - memset(readable, '\0', 9); + memset(readable, '\0', 9); - while (1) { - clrscr(); - while (filename == NULL || *filename == '\0') { - printf("Please enter filename (q to exit):\r\n"); - filename = get_input(); - } - if (*filename == 'q') - return 0; - c = 0; - if ((file = fopen(filename, "r")) == NULL) { - printf("Could not open file\r\n"); - continue; - } - clrscr(); - while (!feof(file)) { - if (fgets(buffer, 8, file) != buffer) { - printf("Could not read from file, bailing out\r\n"); - return 1; - } - for (i = 0; i < 8; i++) - if ( (buffer[i] >= 0x41 && buffer[i] <= 0x5A) || - (buffer[i] >= 0xC1 && buffer[i] <= 0xDA) || - (buffer[i] >= 0x30 && buffer[i] <= 0x39)) - readable[i] = buffer[i]; - else readable[i] = 0x2E; - printf("%s%x |%s%x %s%x %s%x %s%x %s%x %s%x %s%x %s%x| %s \n", - (c <= 0xF ? "0" : ""), c, - x2(0), x2(1), x2(2), x2(3), - x2(4), x2(5), x2(6), x2(7), - readable); - c++; - if ((c % 20) == 0) { - get_input(); - clrscr(); - } - } - fclose(file); - filename = NULL; - printf("File finished, press RETURN...\n"); - get_input(); - } + while (1) { + clrscr(); + while (filename == NULL || *filename == '\0') { + printf("Please enter filename (q to exit):\r\n"); + filename = get_input(); + } + if (*filename == 'q') + return 0; + c = 0; + if ((file = fopen(filename, "r")) == NULL) { + printf("Could not open file\r\n"); + continue; + } + clrscr(); + while (!feof(file)) { + if (fgets(buffer, 8, file) != buffer) { + printf("Could not read from file, bailing out\r\n"); + return 1; + } + for (i = 0; i < 8; i++) + if ((buffer[i] >= 0x41 && buffer[i] <= 0x5A) || + (buffer[i] >= 0xC1 && buffer[i] <= 0xDA) || + (buffer[i] >= 0x30 && buffer[i] <= 0x39)) + readable[i] = buffer[i]; + else + readable[i] = 0x2E; + printf("%s%x |%s%x %s%x %s%x %s%x %s%x %s%x %s%x %s%x| %s \n", + (c <= 0xF ? "0" : ""), c, x2(0), x2(1), x2(2), x2(3), x2(4), x2(5), + x2(6), x2(7), readable); + c++; + if ((c % 20) == 0) { + get_input(); + clrscr(); + } + } + fclose(file); + filename = NULL; + printf("File finished, press RETURN...\n"); + get_input(); + } } diff --git a/src/config.c b/src/config.c index 05e06c8..6f56124 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,4 @@ -/* +/* * RGB2R-C128-Kassenprogramm * © 2007-2009 phil_fry, sECuRE, sur5r * See LICENSE for license information @@ -31,90 +31,88 @@ static bool credits_exists = false; struct status_array_t status; struct credits_array_t credits; -/* +/* * Checks if items/credits-files are existing to avoid having to recover * the error state of the drive (we'd have to if we would just access the * files directly) * */ static void lookup_needed_files(void) { - BYTE lfn = 8, c; - struct cbm_dirent dirent; - char filename[8]; + BYTE lfn = 8, c; + struct cbm_dirent dirent; + char filename[8]; - if (cbm_opendir(lfn, (BYTE)8) != 0) { - cprintf("could not open directory\r\n"); - return; - } - while (cbm_readdir(lfn, &dirent) == 0) { - /* NOTE: You MUST NOT delete any logfiles. This does only work - * under the assumption that logfiles are named continuously */ - if (strncmp(dirent.name, "log", 3) == 0) - log_num++; - if (strcasecmp(dirent.name, "items") == 0) - items_exists = true; - if (strcasecmp(dirent.name, "credits") == 0) - credits_exists = true; - } - cbm_closedir(lfn); + if (cbm_opendir(lfn, (BYTE)8) != 0) { + cprintf("could not open directory\r\n"); + return; + } + while (cbm_readdir(lfn, &dirent) == 0) { + /* NOTE: You MUST NOT delete any logfiles. This does only work + * under the assumption that logfiles are named continuously */ + if (strncmp(dirent.name, "log", 3) == 0) + log_num++; + if (strcasecmp(dirent.name, "items") == 0) + items_exists = true; + if (strcasecmp(dirent.name, "credits") == 0) + credits_exists = true; + } + cbm_closedir(lfn); - /* Try to find out how many lines the last logfile got to seamlessly - * append to it, if we got more than one logfile. */ - if (log_num > 0) { - log_num--; + /* Try to find out how many lines the last logfile got to seamlessly + * append to it, if we got more than one logfile. */ + if (log_num > 0) { + log_num--; - sprintf(filename, "log-%u", log_num); - if ((c = cbm_open(lfn, (BYTE)8, (BYTE)CBM_READ, filename)) != 0) { - c128_perror(c, "cbm_open(log) for reading"); - exit(1); - } - log_heap_offset = cbm_read(lfn, log_heap_buf, LOG_SIZE); - if (log_heap_offset < 0) { - cprintf("error while cbm_read()ing the logfile\r\n"); - exit(1); - } - log_heap_flushed = log_heap_offset; - log_heap_buf[log_heap_offset] = '\0'; - cbm_close(lfn); - } + sprintf(filename, "log-%u", log_num); + if ((c = cbm_open(lfn, (BYTE)8, (BYTE)CBM_READ, filename)) != 0) { + c128_perror(c, "cbm_open(log) for reading"); + exit(1); + } + log_heap_offset = cbm_read(lfn, log_heap_buf, LOG_SIZE); + if (log_heap_offset < 0) { + cprintf("error while cbm_read()ing the logfile\r\n"); + exit(1); + } + log_heap_flushed = log_heap_offset; + log_heap_buf[log_heap_offset] = '\0'; + cbm_close(lfn); + } } void load_items(void) { - BYTE c; + BYTE c; - if (items_exists) { - items_sold = 0; - money = 0; - cbm_load("items", (BYTE)8, &status); - for (c = 0; c < status.num_items; c++) { - items_sold += status.status[c].times_sold; - money += (status.status[c].price * status.status[c].times_sold); - } - } else - memset(&status, 0, sizeof(struct status_array_t)); + if (items_exists) { + items_sold = 0; + money = 0; + cbm_load("items", (BYTE)8, &status); + for (c = 0; c < status.num_items; c++) { + items_sold += status.status[c].times_sold; + money += (status.status[c].price * status.status[c].times_sold); + } + } else + memset(&status, 0, sizeof(struct status_array_t)); } void load_credits(void) { - if (credits_exists) - cbm_load("credits", (BYTE)8, &credits); - else - memset(&credits, 0, sizeof(struct credits_array_t)); + if (credits_exists) + cbm_load("credits", (BYTE)8, &credits); + else + memset(&credits, 0, sizeof(struct credits_array_t)); } void save_items(void) { - if (items_exists) - _sysremove("items"); - cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t)); - items_exists = true; + if (items_exists) + _sysremove("items"); + cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t)); + items_exists = true; } void save_credits(void) { - if (credits_exists) - _sysremove("credits"); - cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t)); - credits_exists = true; + if (credits_exists) + _sysremove("credits"); + cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t)); + credits_exists = true; } -void load_config(void) { - lookup_needed_files(); -} +void load_config(void) { lookup_needed_files(); } diff --git a/src/credit_manager.c b/src/credit_manager.c index 8017524..a9ee0fe 100644 --- a/src/credit_manager.c +++ b/src/credit_manager.c @@ -1,4 +1,4 @@ -/* +/* * RGB2R-C128-Kassenprogramm * © 2007-2009 phil_fry, sECuRE, sur5r * See LICENSE for license information @@ -22,165 +22,183 @@ static BYTE filter_len; static BYTE current_credits_page = 0; static void credit_print_screen(void) { - BYTE i, pages; - char buffer[10]; - - clrscr(); - cprintf("credit_manager (phil_fry, sECuRE, sur5r) v:" GV "\r\n\r\n"); - pages = (credits.num_items / CREDITS_PER_PAGE); - if (current_credits_page > pages) - current_credits_page = pages; - cprintf("Datei: CREDITS (Seite %d von %d)\r\n\r\n", current_credits_page, pages); - for (i = (current_credits_page * CREDITS_PER_PAGE); i < credits.num_items && i < ((current_credits_page+1) * CREDITS_PER_PAGE); i++) { - if (filter == NULL || strncmp(credits.credits[i].nickname, filter, filter_len) == 0) { - if (format_euro(buffer, 10, credits.credits[i].credit) != buffer) { - cprintf("Error: Could not format credit %d\r\n", credits.credits[i].credit); - exit(1); - } - - cprintf("%d: %s: %s\r\n", i, credits.credits[i].nickname, buffer); - } - } - cprintf("\r\nn) Neu d) Loeschen p) Einzahlen b) Seite hoch f) Seite runter\r\ng) Filtern e) Aendern s) Speichern z) Zurueck\r\n"); + BYTE i, pages; + char buffer[10]; + + clrscr(); + cprintf("credit_manager (phil_fry, sECuRE, sur5r) v:" GV "\r\n\r\n"); + pages = (credits.num_items / CREDITS_PER_PAGE); + if (current_credits_page > pages) + current_credits_page = pages; + cprintf("Datei: CREDITS (Seite %d von %d)\r\n\r\n", current_credits_page, + pages); + for (i = (current_credits_page * CREDITS_PER_PAGE); + i < credits.num_items && + i < ((current_credits_page + 1) * CREDITS_PER_PAGE); + i++) { + if (filter == NULL || + strncmp(credits.credits[i].nickname, filter, filter_len) == 0) { + if (format_euro(buffer, 10, credits.credits[i].credit) != buffer) { + cprintf("Error: Could not format credit %d\r\n", + credits.credits[i].credit); + exit(1); + } + + cprintf("%d: %s: %s\r\n", i, credits.credits[i].nickname, buffer); + } + } + cprintf("\r\nn) Neu d) Loeschen p) Einzahlen b) Seite hoch f) Seite " + "runter\r\ng) Filtern e) Aendern s) Speichern z) Zurueck\r\n"); } -struct credits_t *find_credit(char *name){ - int i; - for (i = 0; i < credits.num_items; i++) - if (strncmp(name, credits.credits[i].nickname, NICKNAME_MAX_LEN + 1) == 0) - return &credits.credits[i]; - return NULL; +struct credits_t *find_credit(char *name) { + int i; + for (i = 0; i < credits.num_items; i++) + if (strncmp(name, credits.credits[i].nickname, NICKNAME_MAX_LEN + 1) == 0) + return &credits.credits[i]; + return NULL; } /* * Deposits credit for a user. Called in the credit manager (with input == * NULL) or interactively when the user does not have enough money for his * intended purchase (with input == nickname). - * + * */ void deposit_credit(char *input) { - char *time = get_time(); - struct credits_t *credit; - unsigned int deposit; - - if (input == NULL) { - cprintf("\r\nName:\r\n"); - if ((input = get_input()) == NULL || *input == '\0') - return; // no name given - } - - if ((credit = find_credit(input)) == NULL) - return; // cannot find named credit - - cprintf("\r\nEinzahlung in Cent:\r\n"); - if ((input = get_input()) == NULL || *input == '\0' || (deposit = atoi(input)) == 0) - return; - - credit->credit += deposit; - - toggle_videomode(); - cprintf("%d Cent eingezahlt fuer %s.\r\nRestguthaben: %d\r\n", deposit, credit->nickname, credit->credit); - sprintf(print_buffer, "%c%s - %d Cent eingezahlt fuer %s. Restguthaben: %d Cent\r", 17, time, deposit, credit->nickname, credit->credit); - cprintf("%s", print_buffer); - toggle_videomode(); - print_the_buffer(); - cprintf("\r\nEinzahlung durchgefuehrt, druecke RETURN...\r\n"); - input = get_input(); - toggle_videomode(); - clrscr(); - toggle_videomode(); + char *time = get_time(); + struct credits_t *credit; + unsigned int deposit; + + if (input == NULL) { + cprintf("\r\nName:\r\n"); + if ((input = get_input()) == NULL || *input == '\0') + return; // no name given + } + + if ((credit = find_credit(input)) == NULL) + return; // cannot find named credit + + cprintf("\r\nEinzahlung in Cent:\r\n"); + if ((input = get_input()) == NULL || *input == '\0' || + (deposit = atoi(input)) == 0) + return; + + credit->credit += deposit; + + toggle_videomode(); + cprintf("%d Cent eingezahlt fuer %s.\r\nRestguthaben: %d\r\n", deposit, + credit->nickname, credit->credit); + sprintf(print_buffer, + "%c%s - %d Cent eingezahlt fuer %s. Restguthaben: %d Cent\r", 17, + time, deposit, credit->nickname, credit->credit); + cprintf("%s", print_buffer); + toggle_videomode(); + print_the_buffer(); + cprintf("\r\nEinzahlung durchgefuehrt, druecke RETURN...\r\n"); + input = get_input(); + toggle_videomode(); + clrscr(); + toggle_videomode(); } static void new_credit(void) { - char *input, *name; - char *time; - int credit; - - if (credits.num_items == 75) { - cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n"); - input = get_input(); - return; - } - - clrscr(); - cprintf("\rNickname (max. 10 Zeichen):\r\n"); - if ((input = get_input()) == NULL || *input == '\0') - return; - name = strdup(input); - cprintf("\r\nGuthaben in Cents:\r\n"); - if ((input = get_input()) == NULL || *input == '\0' || (credit = atoi(input)) == 0) - return; - strncpy(credits.credits[credits.num_items].nickname, name, NICKNAME_MAX_LEN); - credits.credits[credits.num_items].credit = credit; - - time = get_time(); - sprintf(print_buffer, "%c%s - Guthaben mit %d Cent fuer %s angelegt\r", 17, time, credit, name); - print_the_buffer(); - - credits.num_items++; - free(name); + char *input, *name; + char *time; + int credit; + + if (credits.num_items == 75) { + cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, " + "druecke RETURN...\r\n"); + input = get_input(); + return; + } + + clrscr(); + cprintf("\rNickname (max. 10 Zeichen):\r\n"); + if ((input = get_input()) == NULL || *input == '\0') + return; + name = strdup(input); + cprintf("\r\nGuthaben in Cents:\r\n"); + if ((input = get_input()) == NULL || *input == '\0' || + (credit = atoi(input)) == 0) + return; + strncpy(credits.credits[credits.num_items].nickname, name, NICKNAME_MAX_LEN); + credits.credits[credits.num_items].credit = credit; + + time = get_time(); + sprintf(print_buffer, "%c%s - Guthaben mit %d Cent fuer %s angelegt\r", 17, + time, credit, name); + print_the_buffer(); + + credits.num_items++; + free(name); } static void _delete_credit(BYTE num) { - memset(credits.credits[num].nickname, '\0', 11); - credits.credits[num].credit = 0; + memset(credits.credits[num].nickname, '\0', 11); + credits.credits[num].credit = 0; } static void delete_credit(void) { - char *input; - BYTE num, last; - - cprintf("\r Welcher Eintrag soll geloescht werden?\r\n"); - if ((input = get_input()) == NULL || *input == '\0') - return; - num = atoi(input); - if (credits.num_items > 1) { - /* Swap last item with this one and delete the last one to avoid holes */ - last = (credits.num_items - 1); - strcpy(credits.credits[num].nickname, credits.credits[last].nickname); - credits.credits[num].credit = credits.credits[last].credit; - _delete_credit(last); - } else { - /* Just delete it */ - _delete_credit(num); - } - credits.num_items--; + char *input; + BYTE num, last; + + cprintf("\r Welcher Eintrag soll geloescht werden?\r\n"); + if ((input = get_input()) == NULL || *input == '\0') + return; + num = atoi(input); + if (credits.num_items > 1) { + /* Swap last item with this one and delete the last one to avoid holes */ + last = (credits.num_items - 1); + strcpy(credits.credits[num].nickname, credits.credits[last].nickname); + credits.credits[num].credit = credits.credits[last].credit; + _delete_credit(last); + } else { + /* Just delete it */ + _delete_credit(num); + } + credits.num_items--; } -void credit_manager(){ - char *c; - while(1){ - credit_print_screen(); - c = get_input(); - switch (*c) { - case 'n': - new_credit(); break; - case 'd': - delete_credit(); break; - case 's': - save_credits(); break; - case 'f': - if (current_credits_page < (credits.num_items / CREDITS_PER_PAGE)) - current_credits_page++; - break; - case 'b': - if (current_credits_page > 0) - current_credits_page--; - break; - case 'p': - deposit_credit(NULL); break; - case 'g': - cprintf("Filter eingeben:\r\n"); - filter = get_input(); - if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0) - filter = NULL; - break; - case 'z': - save_credits(); - return; - default: - cprintf("Unbekannter Befehl, druecke RETURN...\r\n"); - get_input(); - } - } +void credit_manager() { + char *c; + while (1) { + credit_print_screen(); + c = get_input(); + switch (*c) { + case 'n': + new_credit(); + break; + case 'd': + delete_credit(); + break; + case 's': + save_credits(); + break; + case 'f': + if (current_credits_page < (credits.num_items / CREDITS_PER_PAGE)) + current_credits_page++; + break; + case 'b': + if (current_credits_page > 0) + current_credits_page--; + break; + case 'p': + deposit_credit(NULL); + break; + case 'g': + cprintf("Filter eingeben:\r\n"); + filter = get_input(); + if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0) + filter = NULL; + break; + case 'z': + save_credits(); + return; + default: + cprintf("Unbekannter Befehl, druecke RETURN...\r\n"); + get_input(); + } + } } diff --git a/src/general.c b/src/general.c index 53d7804..668bdcf 100644 --- a/src/general.c +++ b/src/general.c @@ -1,4 +1,4 @@ -/* +/* * RGB2R-C128-Kassenprogramm * © 2007-2009 phil_fry, sECuRE, sur5r * See LICENSE for license information @@ -19,32 +19,36 @@ * get_input_terminated_by() returns the terminator it encountered. * */ -input_terminator_t get_input_terminated_by(input_terminator_mask_t terminators, char *out, BYTE outlen) { - BYTE i = strlen(out); - BYTE c, x, y; - x = wherex() - i; - y = wherey(); - while (1) { - c = cgetc(); - if (((terminators & INPUT_TERMINATOR_RETURN) == INPUT_TERMINATOR_RETURN) && (c == PETSCII_CR)) { - return INPUT_TERMINATOR_RETURN; - } else if (((terminators & INPUT_TERMINATOR_SPACE) == INPUT_TERMINATOR_SPACE) && (c == PETSCII_SP)) { - return INPUT_TERMINATOR_SPACE; - } else if (c == PETSCII_DEL) { - /* If you are at the left-most position, do nothing */ - if (i == 0) - continue; - out[--i] = '\0'; - cputcxy(x+i, y, ' '); - gotoxy(x+i, y); - continue; - } - if (i == (outlen-1)) { - continue; - } - cputc(c); - out[i++] = c; - } +input_terminator_t get_input_terminated_by(input_terminator_mask_t terminators, + char *out, BYTE outlen) { + BYTE i = strlen(out); + BYTE c, x, y; + x = wherex() - i; + y = wherey(); + while (1) { + c = cgetc(); + if (((terminators & INPUT_TERMINATOR_RETURN) == INPUT_TERMINATOR_RETURN) && + (c == PETSCII_CR)) { + return INPUT_TERMINATOR_RETURN; + } else if (((terminators & INPUT_TERMINATOR_SPACE) == + INPUT_TERMINATOR_SPACE) && + (c == PETSCII_SP)) { + return INPUT_TERMINATOR_SPACE; + } else if (c == PETSCII_DEL) { + /* If you are at the left-most position, do nothing */ + if (i == 0) + continue; + out[--i] = '\0'; + cputcxy(x + i, y, ' '); + gotoxy(x + i, y); + continue; + } + if (i == (outlen - 1)) { + continue; + } + cputc(c); + out[i++] = c; + } } /* @@ -55,33 +59,35 @@ input_terminator_t get_input_terminated_by(input_terminator_mask_t terminators, * */ char *get_input(void) { - static char output[32]; - memset(output, '\0', sizeof(output)); - get_input_terminated_by(INPUT_TERMINATOR_RETURN, output, sizeof(output)); - return output; + static char output[32]; + memset(output, '\0', sizeof(output)); + get_input_terminated_by(INPUT_TERMINATOR_RETURN, output, sizeof(output)); + return output; } char retry_or_quit(void) { - char *c; - do { - cprintf("\r\nr)etry or q)uit?\r\n"); - c = get_input(); - } while ((*c != 'r') && (*c != 'q')); - return *c; + char *c; + do { + cprintf("\r\nr)etry or q)uit?\r\n"); + c = get_input(); + } while ((*c != 'r') && (*c != 'q')); + return *c; } -char *format_euro(char *s, int maxlen, int cent){ - int tmp = cent; - int len = strlen(",EUR"); - while ((tmp /= 10) > 0) - ++len; - if (len >= maxlen) - return NULL; - // workaround to produce a leading zero for cents.. %0.2d won't work - sprintf(s, "%3d,%s%dEUR", cent / 100, ((cent%100)<10?"0":""), cent % 100); - return s; +char *format_euro(char *s, int maxlen, int cent) { + int tmp = cent; + int len = strlen(",EUR"); + while ((tmp /= 10) > 0) + ++len; + if (len >= maxlen) + return NULL; + // workaround to produce a leading zero for cents.. %0.2d won't work + sprintf(s, "%3d,%s%dEUR", cent / 100, ((cent % 100) < 10 ? "0" : ""), + cent % 100); + return s; } void c128_perror(BYTE c, char *msg) { - cprintf("\r\nError (Code %d) while: %s\r\nOS Error = %d\r\n", c, msg, _oserror); + cprintf("\r\nError (Code %d) while: %s\r\nOS Error = %d\r\n", c, msg, + _oserror); } diff --git a/src/itemz.c b/src/itemz.c index 0676c7a..e5e9f89 100644 --- a/src/itemz.c +++ b/src/itemz.c @@ -18,126 +18,135 @@ #include "version.h" static void itemz_print_screen(void) { - BYTE i; - char buffer[10]; + BYTE i; + char buffer[10]; - clrscr(); - cprintf("itemz (phil_fry, sECuRE, sur5r) 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) { - cprintf("Error: Could not format price %d\r\n", status.status[i].price); - exit(1); - } - 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"); + clrscr(); + cprintf("itemz (phil_fry, sECuRE, sur5r) 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) { + cprintf("Error: Could not format price %d\r\n", status.status[i].price); + exit(1); + } + 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"); } static void new_item(void) { - char *input, *name; - int price; + char *input, *name; + int price; - if (status.num_items == MAX_ITEMS) { - cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n"); - input = get_input(); - return; - } + if (status.num_items == MAX_ITEMS) { + cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, " + "druecke RETURN...\r\n"); + input = get_input(); + return; + } - cprintf("\rName des Eintrags:\r\n"); - if ((input = get_input()) == NULL || *input == '\0') - return; - name = strdup(input); - cprintf("\r\nPreis in Cents:\r\n"); - if ((input = get_input()) == NULL || *input == '\0' || (price = atoi(input)) == 0) - return; - cprintf("\r\nWie oft schon verkauft? [0] \r\n"); - if ((input = get_input()) == NULL) - 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.num_items++; - free(name); + cprintf("\rName des Eintrags:\r\n"); + if ((input = get_input()) == NULL || *input == '\0') + return; + name = strdup(input); + cprintf("\r\nPreis in Cents:\r\n"); + if ((input = get_input()) == NULL || *input == '\0' || + (price = atoi(input)) == 0) + return; + cprintf("\r\nWie oft schon verkauft? [0] \r\n"); + if ((input = get_input()) == NULL) + 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.num_items++; + free(name); } static void _delete_item(BYTE num) { - memset(status.status[num].item_name, '\0', MAX_ITEM_NAME_LENGTH); - status.status[num].price = 0; - status.status[num].times_sold = 0; + memset(status.status[num].item_name, '\0', MAX_ITEM_NAME_LENGTH); + status.status[num].price = 0; + status.status[num].times_sold = 0; } static void delete_item(void) { - char *input; - BYTE num, last; + char *input; + BYTE num, last; - cprintf("\r Welcher Eintrag soll geloescht werden?\r\n"); - if ((input = get_input()) == NULL || *input == '\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); - status.status[num].price = status.status[last].price; - status.status[num].times_sold = status.status[last].times_sold; - _delete_item(last); - } else { - /* Just delete it */ - _delete_item(num); - } - status.num_items--; + cprintf("\r Welcher Eintrag soll geloescht werden?\r\n"); + if ((input = get_input()) == NULL || *input == '\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); + status.status[num].price = status.status[last].price; + status.status[num].times_sold = status.status[last].times_sold; + _delete_item(last); + } else { + /* Just delete it */ + _delete_item(num); + } + status.num_items--; } static void reset_counters(void) { - BYTE i; + BYTE i; - for (i = 0; i < status.num_items; i++) { - status.status[i].times_sold = 0; - } + for (i = 0; i < status.num_items; i++) { + status.status[i].times_sold = 0; + } } -static void itemz_manager(){ - char *c; - while(1){ - itemz_print_screen(); - c = get_input(); - switch (*c) { - case 'n': - new_item(); break; - case 'd': - delete_item(); break; - case 's': - save_items(); break; - case 'r': - reset_counters(); break; - case 'm': - return; // switch to credit mode - case 'q': - exit(0); - default: - cprintf("Unbekannter Befehl, druecke RETURN...\r\n"); - get_input(); - } - } +static void itemz_manager() { + char *c; + while (1) { + itemz_print_screen(); + c = get_input(); + switch (*c) { + case 'n': + new_item(); + break; + case 'd': + delete_item(); + break; + case 's': + save_items(); + break; + case 'r': + reset_counters(); + break; + case 'm': + return; // switch to credit mode + case 'q': + exit(0); + default: + cprintf("Unbekannter Befehl, druecke RETURN...\r\n"); + get_input(); + } + } } int main(void) { - if (VIDEOMODE == 40) - toggle_videomode(); - credits.num_items = 0; - status.num_items = 0; - cprintf("itemz loading...\n"); - load_config(); - cprintf("itemz: loading ITEMS...\n"); - load_items(); - cprintf("itemz: loading CREDITS...\n"); - load_credits(); - while (1) { - itemz_manager(); - credit_manager(); - } - return 0; + if (VIDEOMODE == 40) + toggle_videomode(); + credits.num_items = 0; + status.num_items = 0; + cprintf("itemz loading...\n"); + load_config(); + cprintf("itemz: loading ITEMS...\n"); + load_items(); + cprintf("itemz: loading CREDITS...\n"); + load_credits(); + while (1) { + itemz_manager(); + credit_manager(); + } + return 0; } diff --git a/src/kasse.c b/src/kasse.c index ff244dc..f8a2f69 100644 --- a/src/kasse.c +++ b/src/kasse.c @@ -1,4 +1,4 @@ -/* +/* * RGB2R-C128-Kassenprogramm * © 2007-2009 phil_fry, sECuRE, sur5r * See LICENSE for license information @@ -22,450 +22,466 @@ // graphic 4,0,10 void print_item(BYTE i) { - char profit[10]; - if (format_euro(profit, sizeof(profit), status.status[i].price) == NULL) { - cprintf("Preis %ld konnte nicht umgerechnet werden\r\n", status.status[i].price); - exit(1); - } - textcolor(TC_YELLOW); - cprintf("%2d", i); - textcolor(TC_LIGHT_GRAY); - cprintf(": %-" xstr(MAX_ITEM_NAME_LENGTH) "s \xDD%s, %3dx ", - status.status[i].item_name, profit, status.status[i].times_sold); + char profit[10]; + if (format_euro(profit, sizeof(profit), status.status[i].price) == NULL) { + cprintf("Preis %ld konnte nicht umgerechnet werden\r\n", + status.status[i].price); + exit(1); + } + textcolor(TC_YELLOW); + cprintf("%2d", i); + textcolor(TC_LIGHT_GRAY); + cprintf(": %-" xstr(MAX_ITEM_NAME_LENGTH) "s \xDD%s, %3dx ", + status.status[i].item_name, profit, status.status[i].times_sold); } /* Hauptbildschirm ausgeben */ static void print_screen(void) { - BYTE i = 0; - char *time = get_time(); - char profit[10]; - clrscr(); - if (format_euro(profit, 10, money) == NULL) { - cprintf("Einnahme %ld konnte nicht umgerechnet werden\r\n", money); - exit(1); - } - textcolor(TC_CYAN); - cprintf("C128-Kassenprogramm (phil_fry, sECuRE, sur5r) " GV "\r\n"); - textcolor(TC_LIGHT_GRAY); - cprintf("\r\nUhrzeit: %s (wird nicht aktualisiert)\r\n" - "Eingenommen: %s, Verkauft: %ld Dinge, Drucken: %s\r\n", - time, profit, items_sold, (printing == 1 ? "ein" : "aus")); - textcolor(TC_LIGHT_GRAY); - cprintf(" \xB0" - "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB2" - "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB2" - "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB2" - "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xAE\r\n"); - for (; i < min(status.num_items, 15); ++i) { - - cprintf(" \xDD"); - print_item(i); - cprintf("\xDD"); - - /* if we have more than 15 items, use the second column */ - if ((i+15) < status.num_items) { - print_item(i+15); - cprintf("\xDD"); - } else { - cprintf(" \xDD \xDD"); - } + BYTE i = 0; + char *time = get_time(); + char profit[10]; + clrscr(); + if (format_euro(profit, 10, money) == NULL) { + cprintf("Einnahme %ld konnte nicht umgerechnet werden\r\n", money); + exit(1); + } + textcolor(TC_CYAN); + cprintf("C128-Kassenprogramm (phil_fry, sECuRE, sur5r) " GV "\r\n"); + textcolor(TC_LIGHT_GRAY); + cprintf("\r\nUhrzeit: %s (wird nicht aktualisiert)\r\n" + "Eingenommen: %s, Verkauft: %ld Dinge, Drucken: %s\r\n", + time, profit, items_sold, (printing == 1 ? "ein" : "aus")); + textcolor(TC_LIGHT_GRAY); + cprintf(" \xB0" + "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB2" + "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB2" + "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB2" + "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xAE" + "\r\n"); + for (; i < min(status.num_items, 15); ++i) { + + cprintf(" \xDD"); + print_item(i); + cprintf("\xDD"); + + /* if we have more than 15 items, use the second column */ + if ((i + 15) < status.num_items) { + print_item(i + 15); + cprintf("\xDD"); + } else { + cprintf(" \xDD \xDD"); + } - cprintf("\r\n"); - } - cprintf(" \xAD" - "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB1" - "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB1" - "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB1" - "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xBD\r\n"); - textcolor(TC_YELLOW); - cprintf(" s"); - textcolor(TC_LIGHT_GRAY); - cprintf(") Daten sichern "); - textcolor(TC_YELLOW); - cprintf("g"); - textcolor(TC_LIGHT_GRAY); - cprintf(") Guthabenverwaltung\r\n"); - textcolor(TC_YELLOW); - cprintf(" z"); - textcolor(TC_LIGHT_GRAY); - cprintf(") Zeit setzen "); - textcolor(TC_YELLOW); - cprintf("f"); - textcolor(TC_LIGHT_GRAY); - cprintf(") Freitext verkaufen "); - textcolor(TC_YELLOW); - cprintf("q"); - textcolor(TC_LIGHT_GRAY); - cprintf(") Beenden\r\n"); + cprintf("\r\n"); + } + cprintf(" \xAD" + "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB1" + "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB1" + "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xB1" + "\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xC0\xBD" + "\r\n"); + textcolor(TC_YELLOW); + cprintf(" s"); + textcolor(TC_LIGHT_GRAY); + cprintf(") Daten sichern "); + textcolor(TC_YELLOW); + cprintf("g"); + textcolor(TC_LIGHT_GRAY); + cprintf(") Guthabenverwaltung\r\n"); + textcolor(TC_YELLOW); + cprintf(" z"); + textcolor(TC_LIGHT_GRAY); + cprintf(") Zeit setzen "); + textcolor(TC_YELLOW); + cprintf("f"); + textcolor(TC_LIGHT_GRAY); + cprintf(") Freitext verkaufen "); + textcolor(TC_YELLOW); + cprintf("q"); + textcolor(TC_LIGHT_GRAY); + cprintf(") Beenden\r\n"); } /* * Prints a line and logs it to file. Every line can be at max 80 characters. * */ -static void print_log(char *name, int item_price, int einheiten, char *nickname, char *rest) { - char *time = get_time(); - char price[10]; - /* Format: - Transaction-ID (Anzahl verkaufter Einträge, inklusive des zu druckenden!) -- 6-stellig - Uhrzeit -- 8-stellig - Eintragname (= Getränk) -- 9-stellig - Preis (in Cents) -- 9-stellig - Anzahl -- 2-stellig - Nickname (falls es vom Guthaben abgezogen wird) -- 10-stellig - restguthaben (9-stellig) - - + 7 leerzeichen - --> 48 zeichen - */ - if (format_euro(price, 10, item_price) == NULL) { - cprintf("Preis %d konnte nicht umgerechnet werden\r\n", item_price); - exit(1); - } - - sprintf(print_buffer, "%c[%3u] %s - %-" xstr(MAX_ITEM_NAME_LENGTH) "s - %s - %s - %d - an %s\r", 17, - status.transaction_id, time, name, price, rest, - einheiten, (*nickname != '\0' ? nickname : "Unbekannt")); - status.transaction_id++; - print_the_buffer(); +static void print_log(char *name, int item_price, int einheiten, char *nickname, + char *rest) { + char *time = get_time(); + char price[10]; + /* Format: + Transaction-ID (Anzahl verkaufter Einträge, inklusive des zu druckenden!) + -- 6-stellig + Uhrzeit -- 8-stellig + Eintragname (= Getränk) -- 9-stellig + Preis (in Cents) -- 9-stellig + Anzahl -- 2-stellig + Nickname (falls es vom Guthaben abgezogen wird) -- 10-stellig + restguthaben (9-stellig) + + + 7 leerzeichen + --> 48 zeichen + */ + if (format_euro(price, 10, item_price) == NULL) { + cprintf("Preis %d konnte nicht umgerechnet werden\r\n", item_price); + exit(1); + } + + sprintf(print_buffer, "%c[%3u] %s - %-" xstr( + MAX_ITEM_NAME_LENGTH) "s - %s - %s - %d - an %s\r", + 17, status.transaction_id, time, name, price, rest, einheiten, + (*nickname != '\0' ? nickname : "Unbekannt")); + status.transaction_id++; + print_the_buffer(); } /* dialog which is called for each bought item */ static signed int buy(char *name, unsigned int price) { - int negative = 1; - char entered[5] = {'1', 0, 0, 0, 0}; - BYTE i = 0, matches = 0; - BYTE c, x, y, nickname_len; - int einheiten; - char nickname[NICKNAME_MAX_LEN+1]; - char rest[11]; - struct credits_t *credit; - - memset(nickname, '\0', sizeof(nickname)); - memset(rest, ' ', sizeof(rest)); - rest[8] = '\0'; - - clrscr(); - cprintf("Wieviel Einheiten \"%s\"? [1] \r\n", name); - x = wherex(); - y = wherey(); - while (1) { - /* Buffer-Ende erreicht? */ - if (i == 4) - break; - - c = cgetc(); - /* Enter */ - if (c == PETSCII_CR) - break; - /* Backspace */ - if (c == PETSCII_DEL) { - if (i == 0) - continue; - entered[--i] = '\0'; - cputcxy(x+i, y, ' '); - gotoxy(x+i, y); - continue; - } - if (c == 27) { - cprintf("Kauf abgebrochen, druecke RETURN...\r\n"); - get_input(); - return 1; - } - if (c == '-' && i == 0) { - negative = -1; - cputc(c); - } else if (c >= PETSCII_0 && c <= PETSCII_9) { - entered[i++] = c; - cputc(c); - } - - /* Ungültige Eingabe (keine Ziffer), einfach ignorieren */ - } - einheiten = atoi(entered) * negative; - - if (einheiten > 100 || einheiten < -100 || einheiten == 0) { - cprintf("\r\nEinheit nicht in [-100, 100] oder 0, Abbruch, druecke RETURN...\r\n"); - cgetc(); - return 1; - } - - toggle_videomode(); - cprintf("\r\n *** VERKAUF ***\r\n\r\n"); - cprintf("%dx %s", einheiten, name); - toggle_videomode(); - - cprintf("\r\nAuf ein Guthaben kaufen? Wenn ja, Nickname eingeben:\r\n"); - { - BYTE i; - BYTE x; - BYTE y; - BYTE matches; - char *uniquematch; - input_terminator_t terminator; - while (1) { - terminator = get_input_terminated_by( - INPUT_TERMINATOR_RETURN | - INPUT_TERMINATOR_SPACE, - nickname, - sizeof(nickname)); - - /* Clear the screen from any previous completions */ - x = wherex(); - y = wherey(); - for (i = 1; i < 7; i++) { - /* "Completion:" is longer than NICKNAME_MAX_LEN */ - cclearxy(0, y + i, strlen("Completion:")); - } - gotoxy(x, y); - - if (terminator != INPUT_TERMINATOR_SPACE) { - break; - } - - matches = 0; - uniquematch = NULL; - for (i = 0; i < credits.num_items; i++) { - if (strncmp(nickname, credits.credits[i].nickname, strlen(nickname)) != 0) { - continue; - } - matches++; - if (matches > 1) { - break; - } - uniquematch = credits.credits[i].nickname; - } - if (matches == 1) { - /* Display the rest of the nickname */ - textcolor(TC_LIGHT_GREEN); - cprintf("%s", uniquematch + strlen(nickname)); - textcolor(TC_LIGHT_GRAY); - strcat(nickname, uniquematch + strlen(nickname)); - } else { - /* Multiple nicknames match what was entered so far. Abort and - * display all matches, then prompt the user again. */ - char completion[NICKNAME_MAX_LEN+1]; - BYTE len = strlen(nickname); - x = wherex(); - y = wherey(); - cprintf("\r\nCompletion:\r\n"); - matches = 0; - for (i = 0; i < credits.num_items; i++) { - if (strncmp(nickname, credits.credits[i].nickname, len) != 0) { - continue; - } - if (++matches == 5) { - cprintf("...\r\n"); - break; - } - strcpy(completion, credits.credits[i].nickname); - *(completion + len) = '\0'; - cprintf("%s", completion); - textcolor(TC_LIGHT_GREEN); - cprintf("%c", *(credits.credits[i].nickname + len)); - textcolor(TC_LIGHT_GRAY); - cprintf("%s\r\n", completion + len + 1); - } - gotoxy(x, y); - } - } - } - if (*nickname != '\0') { - toggle_videomode(); - cprintf(" fuer %s\r\n", nickname); - toggle_videomode(); - } - - if (*nickname != '\0' && *nickname != 32) { - nickname_len = strlen(nickname); - /* go through credits and remove the amount of money or set nickname - * to NULL if no such credit could be found */ - credit = find_credit(nickname); - if (credit != NULL) { - while ((signed int)credit->credit < ((signed int)price * einheiten)) { - if (format_euro(rest, 10, credit->credit) == NULL) { - cprintf("Preis %d konnte nicht umgerechnet werden\r\n", credit->credit); - exit(1); - } - cprintf("\r\n%s hat nicht genug Geld (%s). e) einzahlen a) abbruch \r\n", nickname, rest); - c = cgetc(); - if (c == 'e') { - deposit_credit(nickname); - } else { - return 0; - } - } - /* substract money */ - credit->credit -= (price * einheiten); - - if (format_euro(rest, 10, credit->credit) == NULL) { - cprintf("Preis %d konnte nicht umgerechnet werden\r\n", credit->credit); - exit(1); - } - - textcolor(TC_LIGHT_GREEN); - cprintf("\r\nVerbleibendes Guthaben fuer %s: %s. Druecke RETURN...\r\n", - nickname, rest); - textcolor(TC_LIGHT_GRAY); - toggle_videomode(); - cprintf("\r\nDein Guthaben betraegt noch %s.\r\n", rest); - toggle_videomode(); - get_input(); - matches++; - } else { - textcolor(TC_LIGHT_RED); - cprintf("\r\nNickname nicht gefunden in der Guthabenverwaltung! Abbruch, druecke RETURN...\r\n"); - textcolor(TC_LIGHT_GRAY); - get_input(); - return 0; - } - } else { - /* Ensure that nickname is NULL if it's empty because it's used in print_log */ - *nickname = '\0'; - } - - money += price * einheiten; - items_sold += einheiten; - if (printing == 1) - print_log(name, price, einheiten, nickname, rest); - - return einheiten; + int negative = 1; + char entered[5] = {'1', 0, 0, 0, 0}; + BYTE i = 0, matches = 0; + BYTE c, x, y, nickname_len; + int einheiten; + char nickname[NICKNAME_MAX_LEN + 1]; + char rest[11]; + struct credits_t *credit; + + memset(nickname, '\0', sizeof(nickname)); + memset(rest, ' ', sizeof(rest)); + rest[8] = '\0'; + + clrscr(); + cprintf("Wieviel Einheiten \"%s\"? [1] \r\n", name); + x = wherex(); + y = wherey(); + while (1) { + /* Buffer-Ende erreicht? */ + if (i == 4) + break; + + c = cgetc(); + /* Enter */ + if (c == PETSCII_CR) + break; + /* Backspace */ + if (c == PETSCII_DEL) { + if (i == 0) + continue; + entered[--i] = '\0'; + cputcxy(x + i, y, ' '); + gotoxy(x + i, y); + continue; + } + if (c == 27) { + cprintf("Kauf abgebrochen, druecke RETURN...\r\n"); + get_input(); + return 1; + } + if (c == '-' && i == 0) { + negative = -1; + cputc(c); + } else if (c >= PETSCII_0 && c <= PETSCII_9) { + entered[i++] = c; + cputc(c); + } + + /* Ungültige Eingabe (keine Ziffer), einfach ignorieren */ + } + einheiten = atoi(entered) * negative; + + if (einheiten > 100 || einheiten < -100 || einheiten == 0) { + cprintf("\r\nEinheit nicht in [-100, 100] oder 0, Abbruch, druecke " + "RETURN...\r\n"); + cgetc(); + return 1; + } + + toggle_videomode(); + cprintf("\r\n *** VERKAUF ***\r\n\r\n"); + cprintf("%dx %s", einheiten, name); + toggle_videomode(); + + cprintf("\r\nAuf ein Guthaben kaufen? Wenn ja, Nickname eingeben:\r\n"); + { + BYTE i; + BYTE x; + BYTE y; + BYTE matches; + char *uniquematch; + input_terminator_t terminator; + while (1) { + terminator = get_input_terminated_by(INPUT_TERMINATOR_RETURN | + INPUT_TERMINATOR_SPACE, + nickname, sizeof(nickname)); + + /* Clear the screen from any previous completions */ + x = wherex(); + y = wherey(); + for (i = 1; i < 7; i++) { + /* "Completion:" is longer than NICKNAME_MAX_LEN */ + cclearxy(0, y + i, strlen("Completion:")); + } + gotoxy(x, y); + + if (terminator != INPUT_TERMINATOR_SPACE) { + break; + } + + matches = 0; + uniquematch = NULL; + for (i = 0; i < credits.num_items; i++) { + if (strncmp(nickname, credits.credits[i].nickname, strlen(nickname)) != + 0) { + continue; + } + matches++; + if (matches > 1) { + break; + } + uniquematch = credits.credits[i].nickname; + } + if (matches == 1) { + /* Display the rest of the nickname */ + textcolor(TC_LIGHT_GREEN); + cprintf("%s", uniquematch + strlen(nickname)); + textcolor(TC_LIGHT_GRAY); + strcat(nickname, uniquematch + strlen(nickname)); + } else { + /* Multiple nicknames match what was entered so far. Abort and + * display all matches, then prompt the user again. */ + char completion[NICKNAME_MAX_LEN + 1]; + BYTE len = strlen(nickname); + x = wherex(); + y = wherey(); + cprintf("\r\nCompletion:\r\n"); + matches = 0; + for (i = 0; i < credits.num_items; i++) { + if (strncmp(nickname, credits.credits[i].nickname, len) != 0) { + continue; + } + if (++matches == 5) { + cprintf("...\r\n"); + break; + } + strcpy(completion, credits.credits[i].nickname); + *(completion + len) = '\0'; + cprintf("%s", completion); + textcolor(TC_LIGHT_GREEN); + cprintf("%c", *(credits.credits[i].nickname + len)); + textcolor(TC_LIGHT_GRAY); + cprintf("%s\r\n", completion + len + 1); + } + gotoxy(x, y); + } + } + } + if (*nickname != '\0') { + toggle_videomode(); + cprintf(" fuer %s\r\n", nickname); + toggle_videomode(); + } + + if (*nickname != '\0' && *nickname != 32) { + nickname_len = strlen(nickname); + /* go through credits and remove the amount of money or set nickname + * to NULL if no such credit could be found */ + credit = find_credit(nickname); + if (credit != NULL) { + while ((signed int)credit->credit < ((signed int)price * einheiten)) { + if (format_euro(rest, 10, credit->credit) == NULL) { + cprintf("Preis %d konnte nicht umgerechnet werden\r\n", + credit->credit); + exit(1); + } + cprintf( + "\r\n%s hat nicht genug Geld (%s). e) einzahlen a) abbruch \r\n", + nickname, rest); + c = cgetc(); + if (c == 'e') { + deposit_credit(nickname); + } else { + return 0; + } + } + /* substract money */ + credit->credit -= (price * einheiten); + + if (format_euro(rest, 10, credit->credit) == NULL) { + cprintf("Preis %d konnte nicht umgerechnet werden\r\n", credit->credit); + exit(1); + } + + textcolor(TC_LIGHT_GREEN); + cprintf("\r\nVerbleibendes Guthaben fuer %s: %s. Druecke RETURN...\r\n", + nickname, rest); + textcolor(TC_LIGHT_GRAY); + toggle_videomode(); + cprintf("\r\nDein Guthaben betraegt noch %s.\r\n", rest); + toggle_videomode(); + get_input(); + matches++; + } else { + textcolor(TC_LIGHT_RED); + cprintf("\r\nNickname nicht gefunden in der Guthabenverwaltung! Abbruch, " + "druecke RETURN...\r\n"); + textcolor(TC_LIGHT_GRAY); + get_input(); + return 0; + } + } else { + /* Ensure that nickname is NULL if it's empty because it's used in print_log + */ + *nickname = '\0'; + } + + money += price * einheiten; + items_sold += einheiten; + if (printing == 1) + print_log(name, price, einheiten, nickname, rest); + + return einheiten; } void buy_stock(BYTE n) { - if (n >= status.num_items || status.status[n].item_name == NULL) { - cprintf("FEHLER: Diese Einheit existiert nicht.\r\n"); - get_input(); - return; - } - - status.status[n].times_sold += buy(status.status[n].item_name, status.status[n].price); + if (n >= status.num_items || status.status[n].item_name == NULL) { + cprintf("FEHLER: Diese Einheit existiert nicht.\r\n"); + get_input(); + return; + } + + status.status[n].times_sold += + buy(status.status[n].item_name, status.status[n].price); } void buy_custom(void) { - BYTE c = 0, i = 0; - int negative = 1; - char entered[5] = {'1', 0, 0, 0, 0}; - char *input, name[20]; - int price; - - clrscr(); - memset(name, '\0', 20); - cprintf("\r\nWas soll gekauft werden?\r\n"); - input = get_input(); - strncpy(name, input, 20); - if (*name == '\0') - return; - - cprintf("\r\nWie teuer ist \"%s\" (in cents)?\r\n", name); - while (1) { - c = cgetc(); - if (c == 13) - break; - cputc(c); - if (c == 27) { - cprintf("Kauf abgebrochen, druecke RETURN...\r\n"); - get_input(); - return; - } else if (c == '-' && i == 0) - negative = -1; - else if (c > 47 && c < 58) - entered[i++] = c; - } - price = atoi(entered) * negative; - - cprintf("\r\n"); - - buy(name, price); + BYTE c = 0, i = 0; + int negative = 1; + char entered[5] = {'1', 0, 0, 0, 0}; + char *input, name[20]; + int price; + + clrscr(); + memset(name, '\0', 20); + cprintf("\r\nWas soll gekauft werden?\r\n"); + input = get_input(); + strncpy(name, input, 20); + if (*name == '\0') + return; + + cprintf("\r\nWie teuer ist \"%s\" (in cents)?\r\n", name); + while (1) { + c = cgetc(); + if (c == 13) + break; + cputc(c); + if (c == 27) { + cprintf("Kauf abgebrochen, druecke RETURN...\r\n"); + get_input(); + return; + } else if (c == '-' && i == 0) + negative = -1; + else if (c > 47 && c < 58) + entered[i++] = c; + } + price = atoi(entered) * negative; + + cprintf("\r\n"); + + buy(name, price); } void set_time_interactive(void) { - BYTE part[3] = {'0', '0', '\0'}; - BYTE tp1, tp2, tp3; - char *time_input, *time; - cprintf("Gib die aktuelle Uhrzeit ein (Format HHMMSS):\r\n"); - time_input = get_input(); - part[0] = time_input[0]; - part[1] = time_input[1]; - tp1 = atoi(part); - part[0] = time_input[2]; - part[1] = time_input[3]; - tp2 = atoi(part); - part[0] = time_input[4]; - part[1] = time_input[5]; - tp3 = atoi(part); - set_time(tp1, tp2, tp3); - - time = get_time(); - cprintf("\r\nZeit gesetzt: %s\r\n", time); + BYTE part[3] = {'0', '0', '\0'}; + BYTE tp1, tp2, tp3; + char *time_input, *time; + cprintf("Gib die aktuelle Uhrzeit ein (Format HHMMSS):\r\n"); + time_input = get_input(); + part[0] = time_input[0]; + part[1] = time_input[1]; + tp1 = atoi(part); + part[0] = time_input[2]; + part[1] = time_input[3]; + tp2 = atoi(part); + part[0] = time_input[4]; + part[1] = time_input[5]; + tp3 = atoi(part); + set_time(tp1, tp2, tp3); + + time = get_time(); + cprintf("\r\nZeit gesetzt: %s\r\n", time); } int main(void) { - char *c; - char *time; - - if (VIDEOMODE == 40) - toggle_videomode(); - clrscr(); - - /* Allocate logging buffer memory */ - init_log(); - - /* Set time initially, c128 doesn't know it */ - set_time_interactive(); - - POKE(216, 255); - - /* Load configuration */ - load_config(); - - /* Load items (= drinks) */ - load_items(); - /* Load credits */ - load_credits(); - - time = get_time(); - sprintf(print_buffer, "%c--------------------------------------------------------------------------------\r", 17); - print_the_buffer(); - sprintf(print_buffer, "%cC128-Kasse Version " GV "\r", 17); - print_the_buffer(); - - sprintf(print_buffer, "%cKasse gestartet um %s. Nutze logfile log-%u, offset %d.\r", 17, time, log_num, log_heap_offset); - print_the_buffer(); - - print_header(); - - while (1) { - print_screen(); - c = get_input(); - /* ...display dialogs eventually */ - if (*c > 47 && *c < 58) { - /* if the input starts with a digit, we will interpret it as a number - * for the item to be sold */ - buy_stock(atoi(c)); - toggle_videomode(); - clrscr(); - toggle_videomode(); - } else if (*c == 'f') { - buy_custom(); - toggle_videomode(); - clrscr(); - toggle_videomode(); - } else if (*c == 's') { - save_items(); - save_credits(); - log_flush(); - cprintf("\r\nStatefile/Creditfile/Log gesichert, druecke RETURN...\r\n"); - get_input(); - } else if (*c == 'g') { - credit_manager(); - } else if (*c == 'z') { - set_time_interactive(); - } else if (*c == 'q') - break; - } - clrscr(); - cprintf("\r\nBYEBYE\r\n"); - - return 0; + char *c; + char *time; + + if (VIDEOMODE == 40) + toggle_videomode(); + clrscr(); + + /* Allocate logging buffer memory */ + init_log(); + + /* Set time initially, c128 doesn't know it */ + set_time_interactive(); + + POKE(216, 255); + + /* Load configuration */ + load_config(); + + /* Load items (= drinks) */ + load_items(); + /* Load credits */ + load_credits(); + + time = get_time(); + sprintf(print_buffer, "%c----------------------------------------------------" + "----------------------------\r", + 17); + print_the_buffer(); + sprintf(print_buffer, "%cC128-Kasse Version " GV "\r", 17); + print_the_buffer(); + + sprintf(print_buffer, + "%cKasse gestartet um %s. Nutze logfile log-%u, offset %d.\r", 17, + time, log_num, log_heap_offset); + print_the_buffer(); + + print_header(); + + while (1) { + print_screen(); + c = get_input(); + /* ...display dialogs eventually */ + if (*c > 47 && *c < 58) { + /* if the input starts with a digit, we will interpret it as a number + * for the item to be sold */ + buy_stock(atoi(c)); + toggle_videomode(); + clrscr(); + toggle_videomode(); + } else if (*c == 'f') { + buy_custom(); + toggle_videomode(); + clrscr(); + toggle_videomode(); + } else if (*c == 's') { + save_items(); + save_credits(); + log_flush(); + cprintf("\r\nStatefile/Creditfile/Log gesichert, druecke RETURN...\r\n"); + get_input(); + } else if (*c == 'g') { + credit_manager(); + } else if (*c == 'z') { + set_time_interactive(); + } else if (*c == 'q') + break; + } + clrscr(); + cprintf("\r\nBYEBYE\r\n"); + + return 0; } diff --git a/src/print.c b/src/print.c index 0ca1422..665f99f 100644 --- a/src/print.c +++ b/src/print.c @@ -28,45 +28,51 @@ int log_heap_flushed = 0; const int LOG_SIZE = 8192; void init_log(void) { - log_heap_buf = malloc(sizeof(char) * LOG_SIZE); - if (log_heap_buf == NULL) { - cprintf("malloc(log_heap_buf) failed"); - exit(1); - } + log_heap_buf = malloc(sizeof(char) * LOG_SIZE); + if (log_heap_buf == NULL) { + cprintf("malloc(log_heap_buf) failed"); + exit(1); + } } void print_the_buffer(void) { - BYTE c; + BYTE c; RETRY: - c = cbm_open((BYTE)4, (BYTE)4, (BYTE)0, NULL); - if (c != 0) { - c128_perror(c, "cbm_open(printer)"); - if (retry_or_quit() == 'q') - exit(1); - - goto RETRY; - } - c = cbm_write((BYTE)4, print_buffer, strlen(print_buffer)); - if (c != strlen(print_buffer)) { - c128_perror(c, "write(printer)"); - if (retry_or_quit() == 'q') - exit(1); - goto RETRY; - } - cbm_close((BYTE)4); - log_file(print_buffer); + c = cbm_open((BYTE)4, (BYTE)4, (BYTE)0, NULL); + if (c != 0) { + c128_perror(c, "cbm_open(printer)"); + if (retry_or_quit() == 'q') + exit(1); + + goto RETRY; + } + c = cbm_write((BYTE)4, print_buffer, strlen(print_buffer)); + if (c != strlen(print_buffer)) { + c128_perror(c, "write(printer)"); + if (retry_or_quit() == 'q') + exit(1); + goto RETRY; + } + cbm_close((BYTE)4); + log_file(print_buffer); } void print_header(void) { - sprintf(print_buffer, "%c--------------------------------------------------------------------------------\r", 17); - print_the_buffer(); - - sprintf(print_buffer, "%c#kauf Uhrzeit - Ding - Preis - Restguthbn - # - Nickname\r", 17); - print_the_buffer(); - - sprintf(print_buffer, "%c--------------------------------------------------------------------------------\r", 17); - print_the_buffer(); - + sprintf(print_buffer, "%c----------------------------------------------------" + "----------------------------\r", + 17); + print_the_buffer(); + + sprintf( + print_buffer, + "%c#kauf Uhrzeit - Ding - Preis - Restguthbn - # - Nickname\r", + 17); + print_the_buffer(); + + sprintf(print_buffer, "%c----------------------------------------------------" + "----------------------------\r", + 17); + print_the_buffer(); } /* @@ -75,28 +81,30 @@ void print_header(void) { * */ void log_flush(void) { - int c; - static char filename[8]; - sprintf(filename, "log-%d", log_num); - - /* If we have written to this logfile before, we need to remove it first */ - if (log_heap_flushed > 0) - _sysremove(filename); - - if ((c = cbm_open((BYTE)8, (BYTE)8, (BYTE)1, filename)) != 0) { - c128_perror(c, "cbm_open(log)"); - exit(1); - } - c = cbm_write((BYTE)8, log_heap_buf, log_heap_offset); - if (c != log_heap_offset) { - textcolor(TC_LIGHT_RED); - cprintf("\r\nCould not save logfile (wrote %d bytes, wanted %d bytes), please make sure the floppy is not full!\n", c, log_heap_offset); - c128_perror(c, "cbm_write"); - exit(1); - } - cbm_close((BYTE)8); - - log_heap_flushed = log_heap_offset; + int c; + static char filename[8]; + sprintf(filename, "log-%d", log_num); + + /* If we have written to this logfile before, we need to remove it first */ + if (log_heap_flushed > 0) + _sysremove(filename); + + if ((c = cbm_open((BYTE)8, (BYTE)8, (BYTE)1, filename)) != 0) { + c128_perror(c, "cbm_open(log)"); + exit(1); + } + c = cbm_write((BYTE)8, log_heap_buf, log_heap_offset); + if (c != log_heap_offset) { + textcolor(TC_LIGHT_RED); + cprintf("\r\nCould not save logfile (wrote %d bytes, wanted %d bytes), " + "please make sure the floppy is not full!\n", + c, log_heap_offset); + c128_perror(c, "cbm_write"); + exit(1); + } + cbm_close((BYTE)8); + + log_heap_flushed = log_heap_offset; } /* @@ -105,14 +113,14 @@ void log_flush(void) { * */ void log_file(const char *s) { - strcpy(log_heap_buf+log_heap_offset, s); - log_heap_offset += strlen(s); - - /* Force a flush when there are only five lines left */ - if (log_heap_offset > (LOG_SIZE - (5 * 80))) { - log_flush(); - log_num++; - log_heap_offset = 0; - log_heap_flushed = 0; - } + strcpy(log_heap_buf + log_heap_offset, s); + log_heap_offset += strlen(s); + + /* Force a flush when there are only five lines left */ + if (log_heap_offset > (LOG_SIZE - (5 * 80))) { + log_flush(); + log_num++; + log_heap_offset = 0; + log_heap_flushed = 0; + } } diff --git a/test/test.c b/test/test.c index 4873d87..9632181 100644 --- a/test/test.c +++ b/test/test.c @@ -8,27 +8,28 @@ #include "kasse.h" #include "credit_manager.h" -int main(){ - BYTE i=0; - char euro[10]; - load_items(); - load_state(); - for (i=0; i < status.num_items; ++i) { - cprintf("%x: %s (%s, %d mal)\n", - i, status.status[i].item_name, format_euro(euro, 9, status.status[i].price), - status.status[i].times_sold); - status.status[i].times_sold += 10; - } +int main() { + BYTE i = 0; + char euro[10]; + load_items(); + load_state(); + for (i = 0; i < status.num_items; ++i) { + cprintf("%x: %s (%s, %d mal)\n", i, status.status[i].item_name, + format_euro(euro, 9, status.status[i].price), + status.status[i].times_sold); + status.status[i].times_sold += 10; + } - save_state(); - load_items(); - load_state(); - for (i=0; i < status.num_items; ++i) { - cprintf("%x: %s (%s, %d mal)\n", - i, status.status[i].item_name, format_euro(euro, 9, status.status[i].price), - status.status[i].times_sold); - } - - cprintf("strlen(%s)==%d\n", status.status[1].item_name, strlen(status.status[1].item_name)); - cprintf("%d %d %d\n", status.status[1].item_name[0], '\r', '\n'); + save_state(); + load_items(); + load_state(); + for (i = 0; i < status.num_items; ++i) { + cprintf("%x: %s (%s, %d mal)\n", i, status.status[i].item_name, + format_euro(euro, 9, status.status[i].price), + status.status[i].times_sold); + } + + cprintf("strlen(%s)==%d\n", status.status[1].item_name, + strlen(status.status[1].item_name)); + cprintf("%d %d %d\n", status.status[1].item_name[0], '\r', '\n'); }