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