]> git.sur5r.net Git - c128-kasse/blob - config.c
items und state laden geht, demodaten in dateien state und items
[c128-kasse] / config.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include "general.h"
5 #include "config.h"
6
7 unsigned long int money = 0;
8 unsigned long int num_items = 0;
9 BYTE num_credit_items = 0;
10 unsigned long int items_sold = 0;
11 BYTE printer_port = 4;
12 struct status_t status[MAX_ITEMS+1];
13 struct credits_t credits[MAX_CREDIT_ITEMS+1];
14 #define REAL_DATA
15 #ifdef REAL_DATA
16 void load_config();
17
18
19 void load_items(){
20     FILE* f;
21     char line[80];
22     char * sep;
23     BYTE lfn = 219;
24 //  cbm_open(lfn, (BYTE)8, (BYTE)0, "items,r");
25     f = fopen("items","r");
26     for (num_items=0; num_items < MAX_ITEMS && !feof(f); num_items++) {
27         fgets(line, 79, f);
28         sep = strchr(line, '=');
29         strncpy(status[num_items].item_name, line, sep-line);
30         status[num_items].price = atoi(sep+1);
31         status[num_items].times_sold = 0; 
32     }
33     fclose(f);
34 }
35
36 /**
37  * must be called after load_items()
38  */
39 void load_state(){
40     FILE* f;
41     char line[80];
42     char * sep;
43     char i, j;
44     f = fopen("state", "r");
45     if (f==NULL){
46         printf("cannot open state\n");
47         return;
48     }
49     while (!feof(f)) {
50         fgets(line, 79, f);
51         sep = strchr(line, '=');
52         *(line + (sep-line)) = 0;
53         for (i=0; i< MAX_ITEMS; i++) {
54                 if (strcmp(line, status[i].item_name)==0) {
55                         status[i].times_sold = atoi(sep+1);
56                         break;
57                 }
58         }
59     }
60 }
61
62 void save_state(){}
63
64 void load_config() {
65 }
66
67 #else
68
69 void load_config() {
70 }
71
72 void load_items() {
73         BYTE c;
74         num_items=2;
75         strcpy(status[0].item_name, "cola");
76         status[0].price = 230;
77         status[0].times_sold = 0;
78         strcpy(status[1].item_name, "mate");
79         status[1].price = 150;
80         status[1].times_sold = 0;
81         for (c = 2; c < MAX_ITEMS; ++c)
82                 status[c].item_name[0] = 0;
83 }
84
85 void load_state() {
86         status[0].times_sold=23;        
87         status[1].times_sold=42;        
88 }
89
90 void load_credits() {
91 }
92
93 void save_state() {
94 }
95
96 void save_credits() {}
97 #endif