#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);
if (filter[0] == '0') {
free(filter);
filter = NULL;
- }
- } else if (c == 'q')
+ } else filter_len = strlen(filter);
+ } else if (c == 'z')
break;
}
}
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 */
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) {
/* 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 */