Revert^2 "Use cil_write_build_ast"

bde09de39feec91cf8220f0f798a6e52154d69e9

Change-Id: I1c94eb98d1b37216096dfba297434377f805eed9
diff --git a/tools/version_policy.c b/tools/version_policy.c
index 8bb422a..3f97268 100644
--- a/tools/version_policy.c
+++ b/tools/version_policy.c
@@ -9,7 +9,6 @@
 #include <sys/stat.h>
 #include <cil/android.h>
 #include <cil/cil.h>
-#include <cil/cil_write_ast.h>
 
 void __attribute__ ((noreturn)) static usage(char *prog) {
 	printf("Usage: %s [OPTION]...\n", prog);
@@ -90,6 +89,7 @@
 	char *num = NULL;
 	char *dot;
 	char *output = NULL;
+	FILE *output_file = NULL;
 	struct cil_db *base_db = NULL;
 	struct cil_db *out_db = NULL;
 
@@ -177,11 +177,21 @@
 			goto exit;
 		}
 	}
-	rc = cil_write_ast(out_db, output);
-	if (rc != SEPOL_OK) {
+
+	output_file = fopen(output, "we");
+	if (!output_file) {
+		fprintf(stderr, "Could not open file: %s\n", output);
 		goto exit;
 	}
 
+	rc = cil_write_build_ast(output_file, out_db);
+	if (rc != SEPOL_OK) {
+		fprintf(stderr, "Failed to write AST\n");
+		goto build_err;
+	}
+
+build_err:
+	fclose(output_file);
 exit:
 	free(base);
 	free(tgt_policy);