bool assemblegffexolocstr(XMLFile &xml, GFFFile &gff, uint32 n) { int pr, lang=0; std::string lbl; ExoLocString exo; uint64 tmp; while((pr = xml.parse()) >= 0) { switch(pr) { case 0: if(rsubstr(xml.section, 6) == ".label") lbl = xml.value; if(rsubstr(xml.section, 7) == ".strref") { sscanf(xml.value.c_str(), S_UINT64, &tmp); exo.stringref = (uint32) tmp; } if(rsubstr(xml.section, 16) == ".substr.language") { if((lang = getpos(langs, LANGS, xml.value)) == -1) return printxmlerr(xml, "Invalid language"); } if(rsubstr(xml.section, 7) == ".substr") exo.str[lang] = unquotestr(xml.value); break; case 1: if(rsubstr(xml.section, 7) != ".substr") return printxmlerr(xml, "Invalid tag"); break; case 2: if(rsubstr(xml.value, 10) == ".exolocstr") { if(gff.writeExoLocString(n, lbl, exo)) return printxmlerr(xml, gff.getStrError()); return true; } break; } } if(pr != -6) return printxmlerr(xml, xml.getStrError()); printxmlerr(xml, "Unexpected end of file"); return false; }
int tokenize(char *s, char ***ss) { int i, n; char *e, *p, **toks; *ss = NULL; while (*s==' ' || *s=='\t' || *s=='\n') s++; for(i=0, n=1, p=s; *p != '\0'; p++, i++) if (*p==' ' || *p=='\t' || *p=='\n') n++; toks = malloc((n+1)*sizeof(char *) + i + 1); if (!toks) return ENOMEM; p = (char *) toks + (n+1)*sizeof(char *); memmove(p, s, i + 1); for(i = 0; *p != '\0'; i++) { if (i >= n) { free(toks); return EIO; } toks[i] = unquotestr(p, &e); if (!toks[i]) { free(toks); return EIO; } p = e; while (*p==' ' || *p=='\t' || *p=='\n') p++; } toks[i] = NULL; *ss = toks; return i; }
bool assembleerfdesc(XMLFile &xml, ERFFile &erf) { int pr, lang=0; ExoLocString exo; uint64 tmp; while((pr = xml.parse()) >= 0) { switch(pr) { case 0: if(rsubstr(xml.section, 7) == ".strref") { sscanf(xml.value.c_str(), S_UINT64, &tmp); exo.stringref = (uint32) tmp; } if(rsubstr(xml.section, 16) == ".substr.language") { if((lang = getpos(langs, LANGS, xml.value)) == -1) return printxmlerr(xml, "Invalid language"); } if(rsubstr(xml.section, 7) == ".substr") exo.str[lang] = unquotestr(xml.value); break; case 1: if(rsubstr(xml.section, 7) != ".substr") return printxmlerr(xml, "Invalid tag"); break; case 2: if(rsubstr(xml.value, 12) == ".description") { erf.desc = exo; return true; } break; } } if(pr != -6) return printxmlerr(xml, xml.getStrError()); printxmlerr(xml, "Unexpected end of file"); return false; }
bool assembletlk(char *fname, uint8 **mem, uint32 *size) { int pr; uint32 flags=0; uint64 tmp; float32 sndlength=0; std::string sndresref, str; XMLFile xml; TLKFile tlk; if(xml.open(fname)) { std::cerr << "Error opening file \"" << fname << "\": "; std::cerr << xml.getStrError() << "\n"; return false; } while((pr = xml.parse()) >= 0) { switch(pr) { case 0: if(!mem && (xml.section == ".tlk.filename")) tlk.filename = xml.value; else if(xml.section == ".tlk.filetype") { if((tlk.type = tlk.getFileResTypeByExt(xml.value)) == -1) return printxmlerr(xml, "Unknown filetype"); if(!tlk.typeIsCorrect()) return printxmlerr(xml, "No TLK type"); } else if(xml.section == ".tlk.language") { if((tlk.language = (NWNLang) getpos(langs, LANGS, xml.value)) == -1) return printxmlerr(xml, "Invalid language"); } else if(xml.section == ".tlk.std::string.sndresref") sndresref = xml.value; else if(xml.section == ".tlk.std::string.flags") { sscanf(xml.value.c_str(), S_UINT64, &tmp); flags = (uint32) tmp; } else if(xml.section == ".tlk.std::string.sndlength") sscanf(xml.value.c_str(), S_FLOAT32, &sndlength); else if(xml.section == ".tlk.std::string") str = xml.value; break; case 1: if((xml.section != ".?xml") && (xml.section != ".tlk") && (getpos(validtlktags, TLKTAGS, xml.section) == -1)) return printxmlerr(xml, "Invalid tag"); break; case 2: if(xml.value == ".tlk.std::string") { if(tlk.add(flags, sndresref, sndlength, unquotestr(str))) return printxmlerr(xml, tlk.getStrError()); sndlength = flags = 0; str.clear(); sndresref.clear(); } break; } } if(pr != -6) return printxmlerr(xml, xml.getStrError()); xml.close(); if(!mem) { if(tlk.filename.empty()) return printxmlerr(xml, "Missing filename"); else if(tlk.write(tlk.filename)) return printnwnerr(tlk); } else if(tlk.write(mem, size)) return printnwnerr(tlk); return true; }
bool assemblegffstruct(XMLFile &xml, GFFFile &gff, uint32 n, std::string *slbl) { int pr, i; std::string sl, lbl, valstr; uint64 value=0, id=0; while((pr = xml.parse()) >= 0) { switch(pr) { case 0: if(rsubstr(xml.section, 13) == ".struct.label") { if(slbl) *slbl = xml.value; } else if(rsubstr(xml.section, 3) == ".id") { sscanf(xml.value.c_str(), S_UINT64, &id); if(gff.writeSetId(n, (uint32) id)) return printxmlerr(xml, gff.getStrError()); } else if(rsubstr(xml.section, 6) == ".label") lbl = xml.value; else if(rsubstr(xml.section, 12) == ".uint8.value") sscanf(xml.value.c_str(), S_UINT64, &value); else if(rsubstr(xml.section, 11) == ".int8.value") sscanf(xml.value.c_str(), S_INT64, &value); else if(rsubstr(xml.section, 13) == ".uint16.value") sscanf(xml.value.c_str(), S_UINT64, &value); else if(rsubstr(xml.section, 12) == ".int16.value") sscanf(xml.value.c_str(), S_INT64, &value); else if(rsubstr(xml.section, 13) == ".uint32.value") sscanf(xml.value.c_str(), S_UINT64, &value); else if(rsubstr(xml.section, 12) == ".int32.value") sscanf(xml.value.c_str(), S_INT64, &value); else if(rsubstr(xml.section, 13) == ".uint64.value") sscanf(xml.value.c_str(), S_UINT64, &value); else if(rsubstr(xml.section, 12) == ".int64.value") sscanf(xml.value.c_str(), S_INT64, &value); else if(rsubstr(xml.section, 12) == ".float.value") sscanf(xml.value.c_str(), S_FLOAT32, (float32*) &value); else if(rsubstr(xml.section, 13) == ".double.value") sscanf(xml.value.c_str(), S_FLOAT64, (float64*) &value); else if(rsubstr(xml.section, 13) == ".resref.value") valstr = xml.value; else if(rsubstr(xml.section, 10) == ".data.file") { if(gff.writeData(n, lbl, xml.value)) return printxmlerr(xml, gff.getStrError()); } else if(rsubstr(xml.section, 7) == ".exostr") valstr = unquotestr(xml.value); break; case 1: if(getpos(validgfftags, GFFTAGS, xml.section) == -1) return printxmlerr(xml, "Invalid tag"); if(rsubstr(xml.section, 7) == ".struct") { uint32 nsct; sl.clear(); if(gff.writeStruct(nsct, "", n)) return printxmlerr(xml, gff.getStrError()); if(!assemblegffstruct(xml, gff, nsct, &sl)) return false; if(gff.writeSetLabel(n, sl)) return printxmlerr(xml, gff.getStrError()); } else if(rsubstr(xml.section, 5) == ".list") { uint32 list; std::string lbl; if(gff.writeList(list, n, "")) return printxmlerr(xml, gff.getStrError()); if(!assemblegfflist(xml, gff, list, &lbl)) return false; if(gff.writeSetLabel(n, lbl)); } else if(rsubstr(xml.section, 10) == ".exolocstr") { if(!assemblegffexolocstr(xml, gff, n)) return false; } break; case 2: if((i = getpos(validgfftags, 10, xml.value)) != -1) { if(gff.writeVar(n, (NWNVarType) i, lbl, value)) return printxmlerr(xml, gff.getStrError()); lbl = valstr = ""; value = 0; } else if(rsubstr(xml.value, 7) == ".resref") { if(gff.writeResRef(n, lbl, valstr)) return printxmlerr(xml, gff.getStrError()); lbl = valstr = ""; value = 0; } else if(rsubstr(xml.value, 7) == ".exostr") { if(gff.writeExoString(n, lbl, valstr)) return printxmlerr(xml, gff.getStrError()); lbl = valstr = ""; value = 0; } else if(rsubstr(xml.value, 7) == ".struct") return true; break; } } if(pr != -6) return printxmlerr(xml, xml.getStrError()); printxmlerr(xml, "Unexpected end of file"); return false; }