summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Rodland <andrew@cleverdomain.org>2014-02-26 01:38:46 -0600
committerAndrew Rodland <andrew@cleverdomain.org>2014-02-26 01:42:29 -0600
commit36e495da1e91b8a841b65e066cc81f0215d99152 (patch)
tree762145ed1d1259ed2d52cff82311b27c27f90235
parent15faf9dc3b2b1f3556e442de2a093d355c2cec66 (diff)
Make jq --raw-output --unbuffered work
--unbuffered was only affecting the normal output case, not the --raw-output case. Make the two of them play together. This also makes sure that the output is flushed *after* printing the newline, so a consumer doesn't lag a line behind.
-rw-r--r--jv.h2
-rw-r--r--jv_print.c3
-rw-r--r--main.c3
3 files changed, 3 insertions, 5 deletions
diff --git a/jv.h b/jv.h
index 3fc966a3..6e82b4c1 100644
--- a/jv.h
+++ b/jv.h
@@ -124,7 +124,7 @@ jv jv_object_iter_value(jv, int);
int jv_get_refcnt(jv);
-enum { JV_PRINT_PRETTY = 1, JV_PRINT_ASCII = 2, JV_PRINT_COLOUR = 4, JV_PRINT_SORTED = 8, JV_PRINT_UNBUFFERED = 16 };
+enum { JV_PRINT_PRETTY = 1, JV_PRINT_ASCII = 2, JV_PRINT_COLOUR = 4, JV_PRINT_SORTED = 8 };
void jv_dumpf(jv, FILE *f, int flags);
void jv_dump(jv, int flags);
void jv_show(jv, int flags);
diff --git a/jv_print.c b/jv_print.c
index 4b7dd51e..7a20b3ed 100644
--- a/jv_print.c
+++ b/jv_print.c
@@ -265,9 +265,6 @@ void jv_dumpf(jv x, FILE *f, int flags) {
jvp_dtoa_context_init(&C);
jv_dump_term(&C, x, flags, 0, f, 0);
jvp_dtoa_context_free(&C);
- if (flags & JV_PRINT_UNBUFFERED) {
- fflush(f);
- }
}
void jv_dump(jv x, int flags) {
diff --git a/main.c b/main.c
index b2f2d9be..e128b2e7 100644
--- a/main.c
+++ b/main.c
@@ -89,7 +89,6 @@ static int process(jq_state *jq, jv value, int flags) {
if (options & ASCII_OUTPUT) dumpopts |= JV_PRINT_ASCII;
if (options & COLOUR_OUTPUT) dumpopts |= JV_PRINT_COLOUR;
if (options & NO_COLOUR_OUTPUT) dumpopts &= ~JV_PRINT_COLOUR;
- if (options & UNBUFFERED_OUTPUT) dumpopts |= JV_PRINT_UNBUFFERED;
if (jv_get_kind(result) == JV_KIND_FALSE || jv_get_kind(result) == JV_KIND_NULL)
ret = 11;
else
@@ -97,6 +96,8 @@ static int process(jq_state *jq, jv value, int flags) {
jv_dump(result, dumpopts);
}
printf("\n");
+ if (options & UNBUFFERED_OUTPUT)
+ fflush(stdout);
}
jv_free(result);
return ret;