From: sECuRE Date: Sat, 20 Oct 2007 13:30:07 +0000 (+0000) Subject: fgets-replacement implemented X-Git-Tag: rgb2rv6~64 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ba0423cedebc6b580cbebdeb7bfb5a81d1d4df0a;p=c128-kasse fgets-replacement implemented git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@45 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- diff --git a/config.c b/config.c index f173947..de2f4f3 100644 --- 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); } /**