]> git.sur5r.net Git - c128-kasse/commitdiff
alles wunderbar, credit_manager eigentlich feature-complete
authorsECuRE <sECuRE@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Sat, 28 Jul 2007 20:26:21 +0000 (20:26 +0000)
committersECuRE <sECuRE@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Sat, 28 Jul 2007 20:26:21 +0000 (20:26 +0000)
git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@23 af93e077-1a23-4f1e-9cbe-9382a9d578f5

credit_manager.c
general.c
kasse.c

index bce1f35c4e08fd403359b43c7d0fff25ff596153..12128a9cf9cac36c1e364001a04f88a625900c60 100644 (file)
@@ -1,28 +1,61 @@
 #include <conio.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #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;
        }
 }
index 345a6a9b861a044bfe1551c338c20cb76d2490b5..ab64528c5bee437e398c1af112596d070b7f4a09 100644 (file)
--- 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 1d0b30e8729faca315291e0d411ec8e8bfc52b5d..327aa88feec08367640cf25ed54353c03909e5c8 100644 (file)
--- 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 */