summaryrefslogtreecommitdiff
path: root/src/runtime/c/utils/pgf-print.c
blob: 12d81a7c5662dc24d278e1def4e2bd22125d8fe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <pgf/pgf.h>
#include <pgf/data.h>

#include <gu/dump.h>
#include <gu/file.h>
#include <gu/utf8.h>

#include <locale.h>
#include <stdlib.h>

GU_DECLARE_TYPE(PgfAbstr, struct);

int main(int argc, char* argv[]) {
	// Set the character locale, so we can produce proper output.
	setlocale(LC_CTYPE, "");

	if (argc != 1) {
		fprintf(stderr, "usage: %s pgf\n", argv[0]);
		return EXIT_FAILURE;
	}
	char* filename = argv[1];

	GuPool* pool = gu_new_pool();
	GuExn* err = gu_exn(NULL, type, pool);
	PgfPGF* pgf = pgf_read(filename, pool, err);
	int status = 0;
	if (!gu_ok(err)) {
		fprintf(stderr, "Reading PGF failed\n");
		status = 1;
		goto fail_read;
	}
	GuOut* out = gu_file_out(stdout, pool);
	GuWriter* wtr = gu_new_utf8_writer(out, pool);
    pgf_print(pgf, wtr, err);
	gu_writer_flush(wtr, err);
fail_read:
	gu_pool_free(pool);
	return status;
}