]> git.sur5r.net Git - c128-kasse/commitdiff
fgets-replacement implemented
authorsECuRE <sECuRE@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Sat, 20 Oct 2007 13:30:07 +0000 (13:30 +0000)
committersECuRE <sECuRE@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Sat, 20 Oct 2007 13:30:07 +0000 (13:30 +0000)
git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@45 af93e077-1a23-4f1e-9cbe-9382a9d578f5

config.c

index f173947d2ac233751844ba425d7e3f73c2b1f981..de2f4f302547faf1b964c8df15b44472b5863f79 100644 (file)
--- a/config.c
+++ b/config.c
@@ -15,28 +15,40 @@ struct credits_t credits[MAX_CREDIT_ITEMS+1];
 
 void load_config();
 
-void load_items(){
-    char line[80];
-    char *sep;
-    BYTE lfn = 8;
+void load_items() {
+       char line[80];
+       char *sep, *newl = NULL, *lp;
+       BYTE lfn = 8;
        BYTE rc;
-       int count=1;
+       int count = 1;
 
-    rc=cbm_open(lfn, (BYTE)8, (BYTE)0, "items,r");
-       if(rc!=0)
-       {
+       if ((rc = cbm_open(lfn, (BYTE)8, (BYTE)0, "items,r")) != 0) {
                cprintf("cannot open items\r\n");
                return;
        }
-    for (num_items=0; num_items < MAX_ITEMS && count>0; num_items++) {
-               count=cbm_read(lfn, line, 79);
-        //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; 
-    }
-    cbm_close(lfn);
+       for (num_items = 0; num_items < MAX_ITEMS && count > 0;) {
+               count = cbm_read(lfn, line, 79);
+               if (count < 0) {
+                       cprintf("read error\r\n");
+                       return;
+               }
+               line[count] = '\0';
+               lp = line;
+               do {
+                       if (newl)
+                               if (newl < ((line+count)-1))
+                                       lp = newl+1;
+                               else break;
+                       sep = strchr(lp, '=');
+                       strncpy(status[num_items].item_name, lp, sep-lp);
+                       if (newl)
+                               *newl = '\0';
+                       status[num_items].price = atoi(sep+1);
+                       status[num_items].times_sold = 0; 
+                       num_items++;
+               } while (newl = strchr(lp, '\n'));
+       }
+       cbm_close(lfn);
 }
 
 /**