aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c4
-rw-r--r--src/print.c28
2 files changed, 16 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c
index 785a70d..8a47a44 100644
--- a/src/main.c
+++ b/src/main.c
@@ -134,7 +134,7 @@ static void from_blc(char *input, char *output_path)
debug("optimizing tree\n");
struct list *table = optimize_tree(tree, &all_trees);
- FILE *file = fopen(output_path, "wb");
+ FILE *file = output_path ? fopen(output_path, "wb") : stdout;
write_bloc(table, file);
fclose(file);
@@ -153,7 +153,7 @@ static void from_bloc(char *input, char *output_path, int dump)
if (dump)
print_bloc(bloc);
- FILE *file = fopen(output_path, "wb");
+ FILE *file = output_path ? fopen(output_path, "wb") : stdout;
write_blc(bloc, file);
fclose(file);
diff --git a/src/print.c b/src/print.c
index d73f9c5..2b094e2 100644
--- a/src/print.c
+++ b/src/print.c
@@ -10,22 +10,22 @@ void print_bruijn(struct term *term)
{
switch (term->type) {
case ABS:
- printf("[");
+ fprintf(stderr, "[");
print_bruijn(term->u.abs.term);
- printf("]");
+ fprintf(stderr, "]");
break;
case APP:
- printf("(");
+ fprintf(stderr, "(");
print_bruijn(term->u.app.lhs);
- printf(" ");
+ fprintf(stderr, " ");
print_bruijn(term->u.app.rhs);
- printf(")");
+ fprintf(stderr, ")");
break;
case VAR:
- printf("%d", term->u.var.index);
+ fprintf(stderr, "%d", term->u.var.index);
break;
case REF:
- printf("<%ld>", term->u.ref.index);
+ fprintf(stderr, "<%ld>", term->u.ref.index);
break;
default:
fatal("invalid type %d\n", term->type);
@@ -56,15 +56,15 @@ void print_blc(struct term *term)
void print_bloc(struct bloc_parsed *bloc)
{
- printf("\n=== START BLOC ===\n");
- printf("| entries:\t%ld\n", bloc->length);
+ fprintf(stderr, "\n=== START BLOC ===\n");
+ fprintf(stderr, "| entries:\t%ld\n", bloc->length);
for (size_t i = 0; i < bloc->length - 1; i++) {
- printf("| entry %ld:\t", bloc->length - i - 2);
+ fprintf(stderr, "| entry %ld:\t", bloc->length - i - 2);
print_bruijn(bloc->entries[i]);
- printf("\n");
+ fprintf(stderr, "\n");
}
- printf("| final:\t");
+ fprintf(stderr, "| final:\t");
print_bruijn(bloc->entries[bloc->length - 1]);
- printf("\n");
- printf("=== END BLOC ===\n\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "=== END BLOC ===\n\n");
}