]> git.sur5r.net Git - c128-kasse/blob - config.c
bugfix
[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
15 void load_config();
16
17 void load_items(){
18     FILE* f;
19     char line[80];
20     char * sep;
21     BYTE lfn = 219;
22 //  cbm_open(lfn, (BYTE)8, (BYTE)0, "items,r");
23     f = fopen("items","r");
24     for (num_items=0; num_items < MAX_ITEMS && !feof(f); num_items++) {
25         fgets(line, 79, f);
26         sep = strchr(line, '=');
27         strncpy(status[num_items].item_name, line, sep-line);
28         status[num_items].price = atoi(sep+1);
29         status[num_items].times_sold = 0; 
30     }
31     fclose(f);
32 }
33
34 /**
35  * must be called after load_items()
36  */
37 void load_state(){
38     FILE * f;
39     char line[80];
40     char * sep;
41     char i, j;
42     f = fopen("state", "r");
43     if (f==NULL){
44         cprintf("cannot open state\r\n");
45         return;
46     }
47     while (!feof(f)) {
48         fgets(line, 79, f);
49         sep = strchr(line, '=');
50         if (sep==NULL)
51                 continue;
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     fclose(f);
61 }
62
63 void save_state(){
64         FILE * f;
65         int i;
66         
67         f = fopen("state", "w");
68     if (f==NULL){
69         c128_perror(23, "cannot open state file");
70         return;
71     }
72     for (i=0;i<num_items;i++)
73         fprintf(f, "%s=%d\n",status[i].item_name, status[i].times_sold);
74     fclose(f);
75 }
76 /*
77 void dump_state(){
78         FILE * f;
79         char buf[128];
80         int i, len;
81         memset(buf, 0, 128);
82         f = fopen("state", "r");
83         len = fread(buf, 1, 128, f);
84         printf("read %d bytes from state\n", len);
85         fclose(f);
86         for (i=0;i<len;i++)
87                 printf("%x ", buf[i]);
88         printf("\n");
89         
90 }
91 */
92 void load_config() {
93 }