/** * @brief Generates the curTile->entdata string from all the entities * @sa ParseEntities */ const char* UnparseEntities (void) { char key[1024]; char value[1024]; curTile->entdata[0] = '\0'; for (int i = 0; i < num_entities; i++) { const epair_t* ep = entities[i].epairs; if (!ep) continue; /* ent got removed */ Q_strcat(curTile->entdata, sizeof(curTile->entdata), "{\n"); for (ep = entities[i].epairs; ep; ep = ep->next) { Q_strncpyz(key, ep->key, sizeof(key)); StripTrailingWhitespaces(key); Q_strncpyz(value, ep->value, sizeof(value)); StripTrailingWhitespaces(value); if (IsInvalidEntityToken(value) || IsInvalidEntityToken(key)) Sys_Error("Invalid entity %i found with key '%s' and value '%s'", i, key, value); Q_strcat(curTile->entdata, sizeof(curTile->entdata), "\"%s\" \"%s\"\n", key, value); } Q_strcat(curTile->entdata, sizeof(curTile->entdata), "}\n"); } curTile->entdatasize = strlen(curTile->entdata); return curTile->entdata; }
epair_t* AddEpair (const char* key, const char* value, int entNum) { epair_t* e = Mem_AllocType(epair_t); if (IsInvalidEntityToken(value) || IsInvalidEntityToken(key)) Sys_Error("Invalid entity %i found with key '%s' and value '%s'", entNum, key, value); if (strlen(key) >= MAX_KEY - 1) Sys_Error("ParseEpar: token too long"); e->key = key; if (strlen(value) >= MAX_VALUE - 1) Sys_Error("ParseEpar: token too long"); e->value = value; return e; }