summaryrefslogtreecommitdiff
path: root/src/runtime/c/pgf/pgf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/c/pgf/pgf.c')
-rw-r--r--src/runtime/c/pgf/pgf.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/runtime/c/pgf/pgf.c b/src/runtime/c/pgf/pgf.c
index a1649b9ff..af046d63c 100644
--- a/src/runtime/c/pgf/pgf.c
+++ b/src/runtime/c/pgf/pgf.c
@@ -2,6 +2,7 @@
#include <pgf/data.h>
#include <pgf/expr.h>
#include <pgf/reader.h>
+#include <pgf/writer.h>
#include <pgf/linearizer.h>
#include <gu/file.h>
#include <gu/string.h>
@@ -44,6 +45,28 @@ pgf_read_in(GuIn* in,
return pgf;
}
+PGF_API_DECL void
+pgf_write(PgfPGF* pgf, const char* fpath, GuExn* err)
+{
+ FILE* outfile = fopen(fpath, "wb");
+ if (outfile == NULL) {
+ gu_raise_errno(err);
+ return;
+ }
+
+ GuPool* tmp_pool = gu_local_pool();
+
+ // Create an input stream from the input file
+ GuOut* out = gu_file_out(outfile, tmp_pool);
+
+ PgfWriter* wtr = pgf_new_writer(out, tmp_pool, err);
+ pgf_write_pgf(pgf, wtr);
+
+ gu_pool_free(tmp_pool);
+
+ fclose(outfile);
+}
+
PGF_API GuString
pgf_abstract_name(PgfPGF* pgf)
{