From 7cc13dc5795559214950a934ec665a712db01632 Mon Sep 17 00:00:00 2001 From: matze Date: Sat, 28 Jul 2007 19:42:39 +0000 Subject: [PATCH] use #define REAL_DATA to read from disk git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@18 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- Makefile | 3 +++ config.c | 40 +++++++++++++++++++++++++++++++++------- config.h | 4 +++- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 688d5ec..ede4b6a 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,9 @@ all: config.o kasse.o credit_manager.o general.o cl65 -t c128 *.o -o kasse +test: config.o test.o + cl65 -t c128 config.o test.o -o test + clean: rm -rf *.o *.s diff --git a/config.c b/config.c index a142c18..fd8b2e3 100644 --- a/config.c +++ b/config.c @@ -1,4 +1,6 @@ #include +#include +#include #include "general.h" #include "config.h" @@ -9,21 +11,45 @@ unsigned long int items_sold = 0; struct status_t status[MAX_ITEMS+1]; struct credits_t credits[MAX_CREDIT_ITEMS+1]; +#ifdef REAL_DATA +void load_config(); + +void load_items(){ + FILE* f; + char line[80]; + char * sep; + f = fopen("items", "r"); + for (num_items=0; num_items < MAX_ITEMS && !feof(f); num_items++) { + fgets(line, 79, f); + sep = strchr(line, '='); + strncpy(status[num_items].item_name, line, sep-line); + status[num_items].price = atoi(sep+1); + status[num_items].times_sold = 0; + } + +} + +void load_state(){ + status[0].times_sold=23; + status[1].times_sold=42; +} +void save_state(){} + void load_config() { } +#else + void load_items() { uc c; num_items=2; - status[0].item_name = "cola"; + strcpy(status[0].item_name, "cola"); status[0].price = 230; status[0].times_sold = 0; - status[1].item_name = "mate"; + strcpy(status[1].item_name, "mate"); status[1].price = 150; status[1].times_sold = 0; - for (c = 2; c < MAX_ITEMS; ++c) - status[c].item_name = NULL; - + } void load_state() { @@ -37,5 +63,5 @@ void load_credits() { void save_state() { } -void save_credits() { -} +void save_credits() {} +#endif \ No newline at end of file diff --git a/config.h b/config.h index d7bea62..ec9ebe2 100644 --- a/config.h +++ b/config.h @@ -10,7 +10,8 @@ extern unsigned long int items_sold; /* Datenstruktur der verkauften Einträge */ struct status_t { - char *item_name; + char key; + char item_name[80]; /* Wieviel kostet der Eintrag (in Cent)? */ unsigned int price; /* Wie oft wurde er verkauft */ @@ -18,6 +19,7 @@ struct status_t { }; #define MAX_ITEMS 15 +extern struct status_t status[MAX_ITEMS+1]; extern struct status_t* status; /* Datenstruktur für die Guthaben */ -- 2.39.5