Policy *ParserParseFile(AgentType agent_type, const char *path, unsigned int warnings, unsigned int warnings_error) { ParserStateReset(&P, false); P.agent_type = agent_type; P.policy = PolicyNew(); P.warnings = warnings; P.warnings_error = warnings_error; strncpy(P.filename, path, CF_MAXVARSIZE); yyin = safe_fopen(path, "rt"); if (yyin == NULL) { Log(LOG_LEVEL_ERR, "While opening file '%s' for parsing. (fopen: %s)", path, GetErrorStr()); exit(EXIT_FAILURE); } while (!feof(yyin)) { yyparse(); if (ferror(yyin)) { perror("cfengine"); exit(EXIT_FAILURE); } } fclose(yyin); if (P.error_count > 0) { PolicyDestroy(P.policy); ParserStateReset(&P, true); ParserStateClean(&P); return NULL; } Policy *policy = P.policy; ParserStateReset(&P, false); ParserStateClean(&P); return policy; }
Policy *ParserParseFile(const char *path) { ParserStateReset(); P.policy = PolicyNew(); strncpy(P.filename, path, CF_MAXVARSIZE); yyin = fopen(path, "r"); while (!feof(yyin)) { yyparse(); if (ferror(yyin)) { perror("cfengine"); exit(1); } } fclose(yyin); return P.policy; }