void texcache_openfiles(void) { Bstrcpy(ptempbuf,TEXCACHEFILE); Bstrcat(ptempbuf,".cache"); texcache.index = Bfopen(ptempbuf, "at+"); texcache.filehandle = Bopen(TEXCACHEFILE, BO_BINARY|BO_CREAT|BO_APPEND|BO_RDWR, BS_IREAD|BS_IWRITE); if (!texcache.index || texcache.filehandle < 0) { initprintf("Unable to open cache file \"%s\" or \"%s\": %s\n", TEXCACHEFILE, ptempbuf, strerror(errno)); texcache_closefiles(); glusetexcache = 0; return; } Bfseek(texcache.index, 0, BSEEK_END); if (!Bftell(texcache.index)) { Brewind(texcache.index); Bfprintf(texcache.index,"// automatically generated by EDuke32, DO NOT MODIFY!\n"); } else Brewind(texcache.index); initprintf("Opened \"%s\" as cache file\n", TEXCACHEFILE); }
static int32_t readconfig(BFILE *fp, const char *key, char *value, uint32_t len) { char buf[1000], *k, *v, *eq; int32_t x=0; if (len < 1) return 0; Brewind(fp); while (1) { if (!Bfgets(buf, 1000, fp)) return 0; if (buf[0] == ';') continue; eq = Bstrchr(buf, '='); if (!eq) continue; k = buf; v = eq+1; while (*k == ' ' || *k == '\t') k++; *(eq--) = 0; while ((*eq == ' ' || *eq == '\t') && eq>=k) *(eq--) = 0; if (Bstrcasecmp(k, key)) continue; while (*v == ' ' || *k == '\t') v++; eq = v + Bstrlen(v)-1; while ((*eq == ' ' || *eq == '\t' || *eq == '\r' || *eq == '\n') && eq>=v) *(eq--) = 0; value[--len] = 0; do value[x] = v[x]; while (v[x++] != 0 && len-- > 0); return x-1; } }