From: sECuRE Date: Sat, 28 Jul 2007 20:26:21 +0000 (+0000) Subject: alles wunderbar, credit_manager eigentlich feature-complete X-Git-Tag: rgb2rv6~86 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=01b8d4b9103074ff497eece1fdfc4b67f5bea68e;p=c128-kasse alles wunderbar, credit_manager eigentlich feature-complete git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@23 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- diff --git a/credit_manager.c b/credit_manager.c index bce1f35..12128a9 100644 --- a/credit_manager.c +++ b/credit_manager.c @@ -1,28 +1,61 @@ #include #include #include +#include #include "config.h" #include "general.h" char *filter = NULL; +uc filter_len; void print_credit_screen() { uc i = 0; clrscr(); - printf("C128-Kassenprogramm: Guthabenverwaltung\n\n"); + printf("C128-Kassenprogramm: Credit Manager\n\n"); for (; i < num_credit_items; ++i) - printf("Guthaben für %s: %d Cents\n", credits[i].nickname, credits[i].credit); - printf("\nBefehle: f) Filtern q) Back to main screen\n"); + if (filter == NULL || strncmp(credits[i].nickname, filter, filter_len) == 0) + printf("Guthaben %s: %d Cents\n", credits[i].nickname, credits[i].credit); + printf("\nBefehle: n) Neues Guthaben f) Filtern z) Zurueck\n"); } /* Guthabenverwalter */ void credit_manager() { + int negative = 1; uc c; + char *nickname, *credits_input; + /* credits_int is a stupid name, but overlaps with struct credits_t credits; else */ + int credits_int; while (1) { print_credit_screen(); c = getchar(); - if (c == 'f') { + if (c == 'n') { + printf("Nickname eingeben:\n"); + nickname = get_input(); + if (nickname[0] == '\0') { + free(nickname); + continue; + } + printf("\nGuthaben eingeben:\n"); + credits_input = get_input(); + if (credits_input[0] == '\0') { + free(credits_input); + continue; + } + if (credits_input[0] == '-') { + negative = -1; + ++credits_input; + } + credits_int = atoi(credits_input) * negative; + if (credits_int > 0) { + credits[num_credit_items].nickname = nickname; + credits[num_credit_items].credit = credits_int; + ++num_credit_items; + } + if (negative == -1) + --credits_input; + free(credits_input); + } else if (c == 'f') { printf("Filter eingeben:\n"); if (filter != NULL) free(filter); @@ -30,8 +63,8 @@ void credit_manager() { if (filter[0] == '0') { free(filter); filter = NULL; - } - } else if (c == 'q') + } else filter_len = strlen(filter); + } else if (c == 'z') break; } } diff --git a/general.c b/general.c index 345a6a9..ab64528 100644 --- a/general.c +++ b/general.c @@ -4,6 +4,11 @@ #include "general.h" +/* + * Liest (maximal 31) Zeichen ein, bis Enter gedrückt wird. Der zurückgegebene + * char-pointer muss anschließend ge-free()d werden! + * + */ char *get_input() { uc i = 0; char *output = malloc(32 * sizeof(char)); diff --git a/kasse.c b/kasse.c index 1d0b30e..327aa88 100644 --- a/kasse.c +++ b/kasse.c @@ -16,10 +16,10 @@ void print_screen() { uc i = 0; clrscr(); printf("C128-Kassenprogramm\n\n"); - printf("Eingenommen: %d Euro, Verkauft: %d Flaschen\n\n", money * 100, items_sold); + printf("Eingenommen: %ld Euro, Verkauft: %ld Flaschen, Drucken: %s\n\n", money * 100, items_sold, (printing == 1 ? "ein" : "aus")); for (; i < num_items; ++i) - printf("Item %x: %s (%d Cents, %d mal verkauft)\n", i, status[i].item_name, status[i].price, status[i].times_sold); - printf("\nBefehle: s) Save Data p) Toggle Printing\n"); + printf("Eintrag %x: %s (%d Cents, %d mal verkauft)\n", i, status[i].item_name, status[i].price, status[i].times_sold); + printf("\nBefehle: s) Daten sichern d) Drucken umschalten g) Guthabenverwaltung\n"); } /* Druckt eine entsprechende Zeile aus */ @@ -43,7 +43,7 @@ void buy(uc n) { uc c; int einheiten; if (status[n].item_name == NULL) - printf("ERROR: No such item\n"); + printf("FEHLER: Diese Einheit existiert nicht.\n"); else { printf("Wieviel Einheiten \"%s\"?\n", status[n].item_name); while (1) { @@ -87,12 +87,12 @@ int main() { /* Zustandsdatei schreiben */ save_state(); save_credits(); - printf("Statefile/Creditfile saved, press ANYKEY to continue...\n"); + printf("Statefile/Creditfile gesichert, druecke ANYKEY...\n"); getchar(); - } else if (c == 'p') { + } else if (c == 'd') { /* Drucken an- oder ausschalten */ printing = (printing == 1 ? 0 : 1); - printf("Printing is now %s, press ANYKEY to continue...\n", (printing == 1 ? "on" : "off")); + printf("Drucken ist nun %s, druecke ANYKEY...\n", (printing == 1 ? "eingeschaltet" : "ausgeschaltet")); getchar(); } else if (c == 'g') { /* Guthabenverwalter aufrufen */