diff options
author | Tor Andersson <tor@ghostscript.com> | 2004-10-05 04:50:44 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2004-10-05 04:50:44 +0200 |
commit | 00905a4e2b959ccc3b79381acbf1d3b8e5319e8e (patch) | |
tree | e880b845138781aa72473a7be579152a5d20e4eb /object | |
parent | 970ce563601547adcaa131229bf296f5c3e2db3c (diff) | |
download | mupdf-00905a4e2b959ccc3b79381acbf1d3b8e5319e8e.tar.xz |
refactor file code. fix file writing.
Diffstat (limited to 'object')
-rw-r--r-- | object/print.c | 83 |
1 files changed, 27 insertions, 56 deletions
diff --git a/object/print.c b/object/print.c index af6941f9..520e53b9 100644 --- a/object/print.c +++ b/object/print.c @@ -2,10 +2,9 @@ struct fmt { - FILE *file; char *buf; + int cap; int len; - int indent; int tight; int col; @@ -33,9 +32,7 @@ static inline void fmtputc(struct fmt *fmt, int c) } fmt->sep = 0; - if (fmt->file) - putc(c, fmt->file); - if (fmt->buf) + if (fmt->buf && fmt->len < fmt->cap) fmt->buf[fmt->len] = c; if (c == '\n') @@ -259,74 +256,48 @@ static void fmtobj(struct fmt *fmt, fz_obj *obj) } int -fz_sprintobj(char *s, fz_obj *obj) +fz_sprintobj(char *s, int n, fz_obj *obj, int tight) { struct fmt fmt; fmt.indent = 0; - fmt.tight = 0; fmt.col = 0; fmt.sep = 0; fmt.last = 0; - fmt.file = nil; + fmt.tight = tight; fmt.buf = s; + fmt.cap = n; fmt.len = 0; fmtobj(&fmt, obj); - return fmt.len; -} -int -fz_sprintcobj(char *s, fz_obj *obj) -{ - struct fmt fmt; - - fmt.indent = 0; - fmt.tight = 1; - fmt.col = 0; - fmt.sep = 0; - fmt.last = 0; + if (fmt.buf && fmt.len < fmt.cap) + fmt.buf[fmt.len] = '\0'; - fmt.file = nil; - fmt.buf = s; - fmt.len = 0; - fmtobj(&fmt, obj); return fmt.len; } -int -fz_fprintobj(FILE *file, fz_obj *obj) +void +fz_debugobj(fz_obj *obj) { - struct fmt fmt; + char buf[1024]; + char *ptr; + int n; - fmt.indent = 0; - fmt.tight = 0; - fmt.col = 0; - fmt.sep = 0; - fmt.last = 0; - - fmt.file = file; - fmt.buf = nil; - fmt.len = 0; - fmtobj(&fmt, obj); - return fmt.len; -} - -int -fz_fprintcobj(FILE *file, fz_obj *obj) -{ - struct fmt fmt; - - fmt.indent = 0; - fmt.tight = 1; - fmt.col = 0; - fmt.sep = 0; - fmt.last = 0; - - fmt.file = file; - fmt.buf = nil; - fmt.len = 0; - fmtobj(&fmt, obj); - return fmt.len; + n = fz_sprintobj(nil, 0, obj, 0); + if (n < sizeof buf) + { + fz_sprintobj(buf, sizeof buf, obj, 0); + fwrite(buf, 1, n, stdout); + } + else + { + ptr = fz_malloc(n); + if (!ptr) + return; + fz_sprintobj(ptr, n, obj, 0); + fwrite(ptr, 1, n, stdout); + fz_free(ptr); + } } |