diff options
| author | kr.angelov <kr.angelov@gmail.com> | 2013-09-05 11:20:39 +0000 |
|---|---|---|
| committer | kr.angelov <kr.angelov@gmail.com> | 2013-09-05 11:20:39 +0000 |
| commit | 7c0bad50921365746ea362710015853a4879c0a7 (patch) | |
| tree | ead13c32a5b2d8ed2968bcdc5b58e5e7eed79720 /src/runtime/c/utils | |
| parent | 504341dfbafdcd858704350162bb7e233cf6daf2 (diff) | |
remove the read and write modules from libgu. this simplifies the i/o layer
Diffstat (limited to 'src/runtime/c/utils')
| -rw-r--r-- | src/runtime/c/utils/pgf-parse.c | 22 | ||||
| -rw-r--r-- | src/runtime/c/utils/pgf-print.c | 6 | ||||
| -rw-r--r-- | src/runtime/c/utils/pgf-service.c | 7 | ||||
| -rw-r--r-- | src/runtime/c/utils/pgf-translate.c | 40 |
4 files changed, 30 insertions, 45 deletions
diff --git a/src/runtime/c/utils/pgf-parse.c b/src/runtime/c/utils/pgf-parse.c index c64b07434..a990ee933 100644 --- a/src/runtime/c/utils/pgf-parse.c +++ b/src/runtime/c/utils/pgf-parse.c @@ -1,6 +1,5 @@ #include <gu/variant.h> #include <gu/map.h> -#include <gu/dump.h> #include <gu/log.h> #include <gu/enum.h> #include <gu/file.h> @@ -75,11 +74,6 @@ int main(int argc, char* argv[]) { // Create an output stream for stdout GuOut* out = gu_file_out(stdout, pool); - // Locale-encoding writers are currently unsupported - // GuWriter* wtr = gu_locale_writer(out, pool); - // Use a writer with hard-coded utf-8 encoding for now. - GuWriter* wtr = gu_new_utf8_writer(out, pool); - // We will keep the latest results in the 'ppool' and // we will iterate over them by using 'result'. GuPool* ppool = NULL; @@ -118,8 +112,8 @@ int main(int argc, char* argv[]) { clock_t start = clock(); - GuReader *rdr = gu_string_reader(gu_str_string(line, ppool), ppool); - PgfLexer *lexer = pgf_new_simple_lexer(rdr, ppool); + GuIn *in = gu_string_in(gu_str_string(line, ppool), ppool); + PgfLexer *lexer = pgf_new_simple_lexer(in, ppool); GuEnum* result = pgf_parse_with_heuristics(concr, cat, lexer, heuristics, ppool, ppool); PgfExprProb* ep = NULL; @@ -129,15 +123,15 @@ int main(int argc, char* argv[]) { clock_t end = clock(); double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; - gu_printf(wtr, err, "%d (%.0f ms): ", ctr, 1000.0 * cpu_time_used); + gu_printf(out, err, "%d (%.0f ms): ", ctr, 1000.0 * cpu_time_used); if (ep != NULL) { - gu_printf(wtr, err, "[%.4f] (", ep->prob); - pgf_print_expr(ep->expr, NULL, 0, wtr, err); - gu_printf(wtr, err, ")\n"); + gu_printf(out, err, "[%.4f] (", ep->prob); + pgf_print_expr(ep->expr, NULL, 0, out, err); + gu_printf(out, err, ")\n"); } else { - gu_printf(wtr, err, "---\n"); + gu_printf(out, err, "---\n"); } - gu_writer_flush(wtr, err); + gu_out_flush(out, err); } fail: diff --git a/src/runtime/c/utils/pgf-print.c b/src/runtime/c/utils/pgf-print.c index b93acb40e..b937ed46c 100644 --- a/src/runtime/c/utils/pgf-print.c +++ b/src/runtime/c/utils/pgf-print.c @@ -1,7 +1,6 @@ #include <pgf/pgf.h> #include <pgf/data.h> -#include <gu/dump.h> #include <gu/file.h> #include <gu/utf8.h> @@ -30,9 +29,8 @@ int main(int argc, char* argv[]) { 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); + pgf_print(pgf, out, err); + gu_out_flush(out, err); fail_read: gu_pool_free(pool); return status; diff --git a/src/runtime/c/utils/pgf-service.c b/src/runtime/c/utils/pgf-service.c index b18cfd603..36b781a3f 100644 --- a/src/runtime/c/utils/pgf-service.c +++ b/src/runtime/c/utils/pgf-service.c @@ -91,10 +91,9 @@ render(PgfPGF* pgf, PgfExpr expr, GuPool* pool) /* Parent. */ FILE* fstream = fdopen(pc[1], "w"); GuOut* out = gu_file_out(fstream, pool); - GuWriter* wtr = gu_new_utf8_writer(out, pool); GuExn* err = gu_new_exn(NULL, gu_kind(type), pool); - pgf_graphviz_abstract_tree(pgf, expr, wtr, err); + pgf_graphviz_abstract_tree(pgf, expr, out, err); fclose(fstream); close(cp[1]); @@ -138,11 +137,11 @@ static void linearize(PgfConcr* concr, PgfExpr expr, GuPool* pool) { GuStringBuf* sbuf = gu_string_buf(pool); - GuWriter* wtr = gu_string_buf_writer(sbuf); + GuOut* out = gu_string_buf_out(sbuf); GuExn* err = gu_new_exn(NULL, gu_kind(type), pool); - pgf_linearize(concr, expr, wtr, err); + pgf_linearize(concr, expr, out, err); GuString s = gu_string_buf_freeze(sbuf, pool); put_gu_string(s); diff --git a/src/runtime/c/utils/pgf-translate.c b/src/runtime/c/utils/pgf-translate.c index 9f12d49e1..b8eae9cb4 100644 --- a/src/runtime/c/utils/pgf-translate.c +++ b/src/runtime/c/utils/pgf-translate.c @@ -1,6 +1,5 @@ #include <gu/variant.h> #include <gu/map.h> -#include <gu/dump.h> #include <gu/log.h> #include <gu/enum.h> #include <gu/file.h> @@ -17,12 +16,12 @@ static void print_result(PgfExprProb* ep, PgfConcr* to_concr, - GuWriter* wtr, GuExn* err, GuPool* ppool) + GuOut* out, GuExn* err, GuPool* ppool) { // Write out the abstract syntax tree - gu_printf(wtr, err, " [%f] ", ep->prob); - pgf_print_expr(ep->expr, NULL, 0, wtr, err); - gu_putc('\n', wtr, err); + gu_printf(out, err, " [%f] ", ep->prob); + pgf_print_expr(ep->expr, NULL, 0, out, err); + gu_putc('\n', out, err); // Enumerate the concrete syntax trees corresponding // to the abstract tree. @@ -33,12 +32,12 @@ print_result(PgfExprProb* ep, PgfConcr* to_concr, if (gu_variant_is_null(ctree)) { break; } - gu_putc(' ', wtr, err); + gu_putc(' ', out, err); // Linearize the concrete tree as a simple // sequence of strings. - pgf_lzr_linearize_simple(to_concr , ctree, 0, wtr, err); - gu_putc('\n', wtr, err); - gu_writer_flush(wtr, err); + pgf_lzr_linearize_simple(to_concr , ctree, 0, out, err); + gu_putc('\n', out, err); + gu_out_flush(out, err); } } @@ -100,11 +99,6 @@ int main(int argc, char* argv[]) { // Create an output stream for stdout GuOut* out = gu_file_out(stdout, pool); - // Locale-encoding writers are currently unsupported - // GuWriter* wtr = gu_locale_writer(out, pool); - // Use a writer with hard-coded utf-8 encoding for now. - GuWriter* wtr = gu_new_utf8_writer(out, pool); - // We will keep the latest results in the 'ppool' and // we will iterate over them by using 'result'. GuPool* ppool = NULL; @@ -145,7 +139,7 @@ int main(int argc, char* argv[]) { goto fail_parse; } - print_result(ep, to_concr, wtr, err, ppool); + print_result(ep, to_concr, out, err, ppool); } continue; } @@ -161,10 +155,10 @@ int main(int argc, char* argv[]) { // sentence, so our memory usage doesn't increase over time. ppool = gu_new_pool(); - GuReader *rdr = - gu_string_reader(gu_str_string(line, ppool), ppool); + GuIn *in = + gu_string_in(gu_str_string(line, ppool), ppool); PgfLexer *lexer = - pgf_new_simple_lexer(rdr, ppool); + pgf_new_simple_lexer(in, ppool); clock_t start = clock(); @@ -175,11 +169,11 @@ int main(int argc, char* argv[]) { pgf_lexer_current_token(lexer); if (gu_string_eq(tok, gu_empty_string)) - gu_puts("Couldn't begin parsing", wtr, err); + gu_puts("Couldn't begin parsing", out, err); else { - gu_puts("Unexpected token: \"", wtr, err); - gu_string_write(tok, wtr, err); - gu_puts("\"\n", wtr, err); + gu_puts("Unexpected token: \"", out, err); + gu_string_write(tok, out, err); + gu_puts("\"\n", out, err); } goto fail_parse; @@ -196,7 +190,7 @@ int main(int argc, char* argv[]) { goto fail_parse; } - print_result(ep, to_concr, wtr, err, ppool); + print_result(ep, to_concr, out, err, ppool); continue; fail_parse: |
