// ResolveAppends and ResolveIncludes must be called both // for each script. ResolveAppends has to be called first! BOOL C4AulScript::ResolveAppends(C4DefList *rDefs) { // resolve children appends for (C4AulScript *s = Child0; s; s = s->Next) s->ResolveAppends(rDefs); // resolve local appends if (State != ASS_PREPARSED) return FALSE; for (C4AListEntry *a = Appends; a; a = a->next()) { if ((long)a->Var != -1) { C4Def *Def = rDefs->ID2Def(C4ID(a->Var)); if (Def) AppendTo(Def->Script, true); else { // save id in buffer because AulWarn will use the buffer of C4IdText // to get the id of the object in which the error occurs... // (stupid static buffers...) char strID[5]; *strID = 0; strcpy(strID, C4IdText(C4ID(a->Var))); Warn("script to #appendto not found: ", strID); } } else { // append to all defs for (int i = 0; i < rDefs->GetDefCount(); i++) { C4Def *pDef = rDefs->GetDef(i); if (!pDef) break; if (pDef == Def) continue; // append AppendTo(pDef->Script, true); } } } return TRUE; }
C4AListEntry *C4AListEntry::nextVal() { // get entries beginning at next one C4AListEntry *e = this; while ((e = e->next())) { // return if Val != NULL if (e->Val) return e; } // nothing found return NULL; }
BOOL C4AulScript::ResolveIncludes(C4DefList *rDefs) { // resolve children includes for (C4AulScript *s = Child0; s; s = s->Next) s->ResolveIncludes(rDefs); // Had been preparsed? if (State != ASS_PREPARSED) return FALSE; // has already been resolved? if (IncludesResolved) return TRUE; // catch circular includes if (Resolving) { C4AulParseError(this, "Circular include chain detected - ignoring all includes!") .show(); IncludesResolved = true; State = ASS_LINKED; return FALSE; } Resolving = true; // append all includes to local script for (C4AListEntry *i = Includes; i; i = i->next()) { C4Def *Def = rDefs->ID2Def(C4ID(i->Var)); if (Def) { // resolve #includes in included script first (#include-chains :( ) if (!((C4AulScript &)Def->Script).IncludesResolved) if (!Def->Script.ResolveIncludes(rDefs)) continue; // skip this #include Def->Script.AppendTo(*this, false); } else { // save id in buffer because AulWarn will use the buffer of C4IdText // to get the id of the object in which the error occurs... // (stupid static buffers...) char strID[5]; *strID = 0; strcpy(strID, C4IdText(C4ID(i->Var))); Warn("script to #include not found: ", strID); } } IncludesResolved = true; // includes/appends are resolved now (for this script) Resolving = false; State = ASS_LINKED; return TRUE; }