]> git.sur5r.net Git - c128-kasse/blobdiff - src/config.c
Implement space completion when selling items.
[c128-kasse] / src / config.c
index 5b9a918c85fdcc4bd6ffd8f163e5e357dc45d2cf..05e06c877261a08c142539babf031410128d38e7 100644 (file)
@@ -1,6 +1,6 @@
 /* 
  * RGB2R-C128-Kassenprogramm
- * (c) 2007-2009 phil_fry, sECuRE, sur5r
+ * © 2007-2009 phil_fry, sECuRE, sur5r
  * See LICENSE for license information
  *
  */
@@ -15,6 +15,7 @@
 #include "kasse.h"
 #include "general.h"
 #include "config.h"
+#include "print.h"
 
 /* NOTE: undocumented function which scratches files
    We need to use this function because linking unistd.h
@@ -36,18 +37,10 @@ struct credits_array_t credits;
  * files directly)
  *
  */
-static void lookup_needed_files() {
+static void lookup_needed_files(void) {
        BYTE lfn = 8, c;
        struct cbm_dirent dirent;
-       char *buffer = malloc(sizeof(char) * 64 * 100);
-       char *walk;
        char filename[8];
-       int n;
-
-       if (buffer == NULL) {
-               cprintf("Not enough memory available\r\n");
-               exit(1);
-       }
 
        if (cbm_opendir(lfn, (BYTE)8) != 0) {
                cprintf("could not open directory\r\n");
@@ -70,28 +63,23 @@ static void lookup_needed_files() {
        if (log_num > 0) {
                log_num--;
 
-               sprintf(filename, "log-%d", log_num);
+               sprintf(filename, "log-%u", log_num);
                if ((c = cbm_open(lfn, (BYTE)8, (BYTE)CBM_READ, filename)) != 0) {
                        c128_perror(c, "cbm_open(log) for reading");
                        exit(1);
                }
-               n = cbm_read(lfn, buffer, sizeof(char) * 64 * 100);
-               if (n < 0) {
+               log_heap_offset = cbm_read(lfn, log_heap_buf, LOG_SIZE);
+               if (log_heap_offset < 0) {
                        cprintf("error while cbm_read()ing the logfile\r\n");
                        exit(1);
                }
-               buffer[n] = '\0';
-               for (walk = buffer; (walk - buffer) < n; walk++) {
-                       if (*walk == '\r' || *walk == '\n')
-                               log_lines_written++;
-               }
+               log_heap_flushed = log_heap_offset;
+               log_heap_buf[log_heap_offset] = '\0';
                cbm_close(lfn);
        }
-
-       free(buffer);
 }
 
-void load_items() {
+void load_items(void) {
        BYTE c;
 
        if (items_exists) {
@@ -100,33 +88,33 @@ void load_items() {
                cbm_load("items", (BYTE)8, &status);
                for (c = 0; c < status.num_items; c++) {
                        items_sold += status.status[c].times_sold;
-                       money += status.status[c].price * status.status[c].times_sold;
+                       money += (status.status[c].price * status.status[c].times_sold);
                }
        } else
                memset(&status, 0, sizeof(struct status_array_t));
 }
 
-void load_credits() {
+void load_credits(void) {
        if (credits_exists)
                cbm_load("credits", (BYTE)8, &credits);
        else
                memset(&credits, 0, sizeof(struct credits_array_t));
 }
 
-void save_items() {
+void save_items(void) {
        if (items_exists)
                _sysremove("items");
        cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t));
        items_exists = true;
 }
 
-void save_credits() {
+void save_credits(void) {
        if (credits_exists)
                _sysremove("credits");
        cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t));
        credits_exists = true;
 }
 
-void load_config() {
+void load_config(void) {
        lookup_needed_files();
 }