EditContext *NewEditContext(EvalContext *ctx, char *filename, Attributes a, const Promise *pp) { EditContext *ec; if (!IsAbsoluteFileName(filename)) { CfOut(OUTPUT_LEVEL_ERROR, "", "Relative file name %s was marked for editing but has no invariant meaning\n", filename); return NULL; } ec = xcalloc(1, sizeof(EditContext)); ec->filename = filename; ec->empty_first = a.edits.empty_before_use; if (a.haveeditline) { if (!LoadFileAsItemList(ctx, &(ec->file_start), filename, a, pp)) { free(ec); return NULL; } } if (a.haveeditxml) { #ifdef HAVE_LIBXML2 if (!LoadFileAsXmlDoc(ctx, &(ec->xmldoc), filename, a, pp)) { free(ec); return NULL; } #else cfPS(ctx, OUTPUT_LEVEL_ERROR, CF_FAIL, "", pp, a, " !! Cannot edit XML files without LIBXML2\n"); free(ec); return NULL; #endif } if (a.edits.empty_before_use) { CfOut(OUTPUT_LEVEL_VERBOSE, "", " -> Build file model from a blank slate (emptying)\n"); DeleteItemList(ec->file_start); ec->file_start = NULL; } EDIT_MODEL = true; return ec; }
EditContext *NewEditContext(char *filename, Attributes a) { EditContext *ec; if (!IsAbsoluteFileName(filename)) { Log(LOG_LEVEL_ERR, "Relative file name '%s' was marked for editing but has no invariant meaning", filename); return NULL; } ec = xcalloc(1, sizeof(EditContext)); ec->filename = filename; if (a.haveeditline) { if (!LoadFileAsItemList(&(ec->file_start), filename, a.edits)) { free(ec); return NULL; } } if (a.haveeditxml) { #ifdef HAVE_LIBXML2 if (!LoadFileAsXmlDoc(&(ec->xmldoc), filename, a.edits)) { free(ec); return NULL; } #else Log(LOG_LEVEL_ERR, "Cannot edit XML files without LIBXML2"); free(ec); return NULL; #endif } if (a.edits.empty_before_use) { Log(LOG_LEVEL_VERBOSE, "Build file model from a blank slate (emptying)"); DeleteItemList(ec->file_start); ec->file_start = NULL; } return ec; }