/** * This gets called when all is well at the end. */ LOCAL void cleanup(tTemplate* pTF) { if (HAVE_OPT(USED_DEFINES)) print_used_defines(); if (pfDepends != NULL) wrap_up_depends(); optionFree(&autogenOptions); for (;;) { tTemplate* pT = pNamedTplList; if (pT == NULL) break; pNamedTplList = (tTemplate*)(void*)(pT->pNext); unloadTemplate(pT); } AGFREE(forInfo.fi_data); unloadTemplate(pTF); unloadDefs(); }
/*=macfunc INCLUDE * * what: Read in and emit a template block * handler_proc: * load_proc: * * desc: * * The entire contents of the named file is inserted at this point. * The contents of the file are processed for macro expansion. The * arguments are eval-ed, so you may compute the name of the file to * be included. The included file must not contain any incomplete * function blocks. Function blocks are template text beginning with * any of the macro functions @samp{CASE}, @samp{DEFINE}, @samp{FOR}, * @samp{IF} and @samp{WHILE}; extending through their respective * terminating macro functions. =*/ tMacro* mFunc_Include(tTemplate* pT, tMacro* pMac) { tTemplate * pNewTpl; ag_bool needFree; char const * pzFile = evalExpression(&needFree); tMacro* pM; if (*pzFile != NUL) { pNewTpl = loadTemplate(pzFile, pT->pzTplFile); /* * Strip off trailing white space from included templates */ pM = pNewTpl->aMacros + (pNewTpl->macroCt - 1); if (pM->funcCode == FTYP_TEXT) { char* pz = pNewTpl->pzTemplText + pM->ozText; char* pzE = pz + strlen(pz); while ((pzE > pz) && IS_WHITESPACE_CHAR(pzE[-1])) --pzE; /* * IF there is no text left, remove the macro entirely */ if (pz == pzE) pNewTpl->macroCt--; else *pzE = NUL; } if (OPT_VALUE_TRACE > TRACE_DEBUG_MESSAGE) { fprintf(pfTrace, TRACE_FN_INC_TPL, pNewTpl->pzTplFile); if (OPT_VALUE_TRACE == TRACE_EVERYTHING) fprintf(pfTrace, TRACE_FN_INC_LINE, pCurTemplate->pzTplFile, pMac->lineNo); } generateBlock(pNewTpl, pNewTpl->aMacros, pNewTpl->aMacros + pNewTpl->macroCt); unloadTemplate(pNewTpl); pCurTemplate = pT; } if (needFree) AGFREE((void*)pzFile); return pMac + 1; }