Permalink
Browse files

working dfsch_put_object

  • Loading branch information...
1 parent c5f7311 commit 44590b894e050865a685c24ba2992c4465c00546 @adh committed Apr 9, 2012
Showing with 26 additions and 3 deletions.
  1. +4 −0 dfsch/writer.h
  2. +2 −1 lib/console.c
  3. +20 −2 src/writer.c
View
@@ -2,6 +2,7 @@
#define H__dfsch__writer__
#include <dfsch/dfsch.h>
+#include <stdio.h>
#ifdef __cplusplus
extern "C" {
@@ -51,6 +52,9 @@ extern "C" {
void dfsch_write_unreadable_with_slots_method(dfsch_object_t* obj,
dfsch_writer_state_t* state);
+ void dfsch_put_object(FILE* f, dfsch_object_t* obj,
+ int max_depth, int mode);
+
#ifdef __cplusplus
}
#endif
View
@@ -487,7 +487,8 @@ static int repl_callback(dfsch_object_t *obj, repl_context_t* ctx){
dfsch_object_t** ret;
ret = dfsch_get_values(ctx->last_result = ctx->evalfun(obj, ctx->baton));
while (*ret != DFSCH_INVALID_OBJECT){
- puts(dfsch_object_2_string(*ret,ctx->print_depth,1));
+ dfsch_put_object(stdout, *ret, ctx->print_depth, 1);
+ printf("\n");
ret++;
}
return 1;
View
@@ -82,10 +82,28 @@ void dfsch_write_object_circular(dfsch_object_t* obj,
dfsch_invalidate_writer_state(state);
}
+static void stdio_output_proc(FILE* stream, char* buf, size_t len){
+ if (fwrite(buf, len, 1, stream) != 1){
+ dfsch_operating_system_error("fwrite");
+ }
+}
void dfsch_put_object(FILE* f, dfsch_object_t* obj,
- int max_depth){
-
+ int max_depth, int mode){
+ if (max_depth >= 0){
+ dfsch_writer_state_t* state =
+ dfsch_make_writer_state(max_depth,
+ mode,
+ (dfsch_output_proc_t)stdio_output_proc,
+ f);
+ dfsch_write_object(state, obj);
+ dfsch_invalidate_writer_state(state);
+ } else {
+ dfsch_write_object_circular(obj,
+ mode,
+ (dfsch_output_proc_t)stdio_output_proc,
+ f);
+ }
}

0 comments on commit 44590b8

Please sign in to comment.