ScriptSectionType * SCRIPT_AddSection(int32_t scripthandle, char * sectionname) { ScriptSectionType *s,*s2; if (scripthandle < 0 || scripthandle >= MAXSCRIPTFILES) return NULL; if (!sectionname) return NULL; if (!SC(scripthandle)) return NULL; s = SCRIPT_SectionExists(scripthandle, sectionname); if (s) return s; AllocSection(s); s->name = Bstrdup(sectionname); if (!SCRIPT(scripthandle,script)) { SCRIPT(scripthandle,script) = s; } else { s2 = SCRIPT(scripthandle,script); while (s2->nextsection != s2) s2=s2->nextsection; s2->nextsection = s; s->prevsection = s2; } return s; }
struct sSection * obj_ReadRGB1Section(FILE * f) { struct sSection *pSection; pSection = AllocSection(); pSection->nByteSize = readlong(f); pSection->Type = (enum eSectionType) fgetc(f); /* * And because of THIS new feature I'll have to rewrite loads and * loads of stuff... oh well it needed to be done anyway * */ pSection->nOrg = readlong(f); pSection->nBank = readlong(f); /* does the user want the -s mode? */ if ((options & OPT_SMALL) && (pSection->Type == SECT_ROMX)) { pSection->Type = SECT_ROM0; } if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) { /* * These sectiontypes contain data... * */ if (pSection->nByteSize) { pSection->pData = malloc(pSection->nByteSize); if (!pSection->pData) { err(1, NULL); } SLONG nNumberOfPatches; struct sPatch **ppPatch, *pPatch; char s[256]; fread(pSection->pData, sizeof(UBYTE), pSection->nByteSize, f); nNumberOfPatches = readlong(f); ppPatch = &pSection->pPatches; /* * And patches... * */ while (nNumberOfPatches--) { pPatch = malloc(sizeof *pPatch); if (!pPatch) { err(1, NULL); } *ppPatch = pPatch; readasciiz(s, f); pPatch->pzFilename = malloc(strlen(s) + 1); if (!pPatch->pzFilename) { err(1, NULL); } strcpy(pPatch->pzFilename, s); pPatch->nLineNo = readlong(f); pPatch->nOffset = readlong(f); pPatch->Type = (enum ePatchType) fgetc(f); if ((pPatch->nRPNSize = readlong(f)) > 0) { pPatch->pRPN = malloc(pPatch->nRPNSize); if (!pPatch->pRPN) { err(1, NULL); } fread(pPatch->pRPN, sizeof(UBYTE), pPatch->nRPNSize, f); } else pPatch->pRPN = NULL; pPatch->pNext = NULL; ppPatch = &(pPatch->pNext); } } else { /* Skip number of patches */ readlong(f); pSection->pData = &dummymem; } } return pSection; }