virtual uint isProperty(const char *c, unsigned int index) const // Check if a property identified by the C string *c begins at index. // Return poition of '[' (always >0 assuming *c is not empty) if yes, zero if no. { if (index+strlen(c) >= strLength) return 0; while (*c != '\0') { if (*(c++) != Str.at(index++)) return 0; } uint tmppos = next_nonspace(index); if (at(tmppos) == '[') return tmppos; else return 0; }
static int palette_load_core(FILE *f, const char *file_name, palette_t *tmp_palette, palette_t *palette_return) { char buf[1024]; unsigned int line_num = 0; unsigned int entry_num = 0; while (1) { int i; BYTE values[4]; const char *p1; int line_len = util_get_line(buf, 1024, f); if (line_len < 0) { break; } line_num++; if (*buf == '#') { continue; } p1 = next_nonspace(buf); if (*p1 == '\0') { /* empty line */ continue; } for (i = 0; i < 4; i++) { long result; const char *p2; if (util_string_to_long(p1, &p2, 16, &result) < 0) { log_error(palette_log, "%s, %d: number expected.", file_name, line_num); return -1; } if (result < 0 || (i == 3 && result > 0xf) || result > 0xff || result < 0) { log_error(palette_log, "%s, %d: invalid value %lx.", file_name, line_num, result); return -1; } values[i] = (BYTE)result; p1 = p2; } p1 = next_nonspace(p1); if (*p1 != '\0') { log_error(palette_log, "%s, %d: garbage at end of line.", file_name, line_num); return -1; } if (entry_num >= palette_return->num_entries) { log_error(palette_log, "%s: too many entries, %d expected.", file_name, palette_return->num_entries); return -1; } if (palette_set_entry(tmp_palette, entry_num, values[0], values[1], values[2], values[3]) < 0) { log_error(palette_log, "Failed to set palette entry."); return -1; } entry_num++; } if (line_num == 0) { log_error(palette_log, "Could not read from palette file."); return -1; } if (entry_num < palette_return->num_entries) { log_error(palette_log, "%s: too few entries, %d found, %d expected.", file_name, entry_num, palette_return->num_entries); return -1; } if (palette_copy(palette_return, tmp_palette) < 0) { log_error(palette_log, "Failed to copy palette."); return -1; } return 0; }
void Reload_Sources(void) { int i; vfsfile_t *f; char ln[2048]; source_data *s; SB_ServerList_Lock(); for (i=0; i < sourcesn; i++) Delete_Source(sources[i]); sourcesn = 0; // create dummy unbound source sources[0] = Create_Source(); sources[0]->type = type_dummy; strlcpy (sources[0]->name, "Unbound", sizeof (sources[0]->name)); sources[0]->servers = (server_data **) Q_malloc(MAX_UNBOUND*sizeof(server_data *)); sources[0]->serversn = 0; sources[0]->servers_allocated = MAX_UNBOUND; sourcesn = 1; f = FS_OpenVFS(SOURCES_LIST_FILENAME, "rb", FS_ANY); if (!f) { //Com_Printf ("sources file not found: %s\n", SOURCES_PATH); SB_ServerList_Unlock(); return; } s = Create_Source(); while (VFS_GETS(f, ln, sizeof(ln))) { char line[2048]; char *p, *q; if (sscanf(ln, "%[ -~ ]s", line) != 1) { continue; } p = next_nonspace(line); if (*p == '/') continue; // comment q = next_space(p); if (!strncmp(p, "master", q-p)) { s->type = type_master; } else if (!strncmp(p, "file", q-p)) { s->type = type_file; } else if (!strncmp(p, "url", q-p)) { s->type = type_url; } else { continue; } p = next_nonspace(q); q = (*p == '\"') ? next_quote(++p) : next_space(p); if (q-p <= 0) continue; strlcpy (s->name, p, min(q-p+1, MAX_SOURCE_NAME+1)); p = next_nonspace(q+1); q = next_space(p); *q = 0; if (q-p <= 0) continue; if (s->type == type_file) strlcpy (s->address.filename, p, sizeof (s->address.filename)); else if (s->type == type_url) strlcpy (s->address.url, p, sizeof (s->address.url)); else if (!NET_StringToAdr(p, &(s->address.address))) continue; sources[sourcesn] = Create_Source(); i = sources[sourcesn]->unique; memcpy(sources[sourcesn], s, sizeof(source_data)); sources[sourcesn]->unique = i; sourcesn++; } Delete_Source(s); VFS_CLOSE(f); //Com_Printf("Read %d sources for Server Browser\n", sourcesn); // update all file sources for (i=0; i < sourcesn; i++) if (sources[i]->type == type_file) Update_Source(sources[i]); else if (sources[i]->type == type_master || sources[i]->type == type_url) Precache_Source(sources[i]); rebuild_servers_list = 1; resort_sources = 1; SB_ServerList_Unlock(); }
EXPORTED int dlist_parse(struct dlist **dlp, int parsekey, struct protstream *in, const char *alt_reserve_base) { struct dlist *dl = NULL; static struct buf kbuf; static struct buf vbuf; int c; /* handle the key if wanted */ if (parsekey) { c = getastring(in, NULL, &kbuf); c = next_nonspace(in, c); } else { buf_setcstr(&kbuf, ""); c = prot_getc(in); } /* connection dropped? */ if (c == EOF) goto fail; /* check what sort of value we have */ if (c == '(') { dl = dlist_newlist(NULL, kbuf.s); c = next_nonspace(in, ' '); while (c != ')') { struct dlist *di = NULL; prot_ungetc(c, in); c = dlist_parse(&di, 0, in, alt_reserve_base); if (di) dlist_stitch(dl, di); c = next_nonspace(in, c); if (c == EOF) goto fail; } c = prot_getc(in); } else if (c == '%') { /* no whitespace allowed here */ c = prot_getc(in); if (c == '(') { dl = dlist_newkvlist(NULL, kbuf.s); c = next_nonspace(in, ' '); while (c != ')') { struct dlist *di = NULL; prot_ungetc(c, in); c = dlist_parse(&di, 1, in, alt_reserve_base); if (di) dlist_stitch(dl, di); c = next_nonspace(in, c); if (c == EOF) goto fail; } } else if (c == '{') { struct message_guid tmp_guid; static struct buf pbuf, gbuf; unsigned size = 0; const char *fname; const char *part; c = getastring(in, NULL, &pbuf); if (c != ' ') goto fail; c = getastring(in, NULL, &gbuf); if (c != ' ') goto fail; c = getuint32(in, &size); if (c != '}') goto fail; c = prot_getc(in); if (c == '\r') c = prot_getc(in); if (c != '\n') goto fail; if (!message_guid_decode(&tmp_guid, gbuf.s)) goto fail; part = alt_reserve_base ? alt_reserve_base : pbuf.s; if (reservefile(in, part, &tmp_guid, size, &fname)) goto fail; dl = dlist_setfile(NULL, kbuf.s, pbuf.s, &tmp_guid, size, fname); /* file literal */ } else { /* unknown percent type */ goto fail; } c = prot_getc(in); } else if (c == '{') { prot_ungetc(c, in); /* could be binary in a literal */ c = getbastring(in, NULL, &vbuf); dl = dlist_setmap(NULL, kbuf.s, vbuf.s, vbuf.len); } else if (c == '\\') { /* special case for flags */ prot_ungetc(c, in); c = getastring(in, NULL, &vbuf); dl = dlist_setflag(NULL, kbuf.s, vbuf.s); } else { prot_ungetc(c, in); c = getnastring(in, NULL, &vbuf); dl = dlist_setatom(NULL, kbuf.s, vbuf.s); } /* success */ *dlp = dl; return c; fail: dlist_free(&dl); return EOF; }