mirror of
				https://github.com/stedolan/jq.git
				synced 2024-05-11 05:55:39 +00:00 
			
		
		
		
	Add a --unbuffered option. Closes #206
This commit is contained in:
		@@ -114,6 +114,12 @@ sections:
 | 
			
		||||
        ASCII output with every non-ASCII character replaced with the
 | 
			
		||||
        equivalent escape sequence.
 | 
			
		||||
 | 
			
		||||
      * `--unbuffered`
 | 
			
		||||
 | 
			
		||||
        Flush the output after each JSON object is printed (useful if
 | 
			
		||||
        you're piping a slow data source into jq and piping jq's
 | 
			
		||||
        output elsewhere).
 | 
			
		||||
 | 
			
		||||
      * `--sort-keys` / `-S`:
 | 
			
		||||
        
 | 
			
		||||
        Output the fields of each object with the keys in sorted order.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								jv.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								jv.h
									
									
									
									
									
								
							@@ -110,7 +110,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 };
 | 
			
		||||
enum { JV_PRINT_PRETTY = 1, JV_PRINT_ASCII = 2, JV_PRINT_COLOUR = 4, JV_PRINT_SORTED = 8, JV_PRINT_UNBUFFERED = 16 };
 | 
			
		||||
void jv_dump(jv, int flags);
 | 
			
		||||
jv jv_dump_string(jv, int flags);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -265,6 +265,9 @@ void jv_dump(jv x, int flags) {
 | 
			
		||||
  jvp_dtoa_context_init(&C);
 | 
			
		||||
  jv_dump_term(&C, x, flags, 0, stdout, 0);
 | 
			
		||||
  jvp_dtoa_context_free(&C);
 | 
			
		||||
  if (flags & JV_PRINT_UNBUFFERED) {
 | 
			
		||||
    fflush(stdout);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
jv jv_dump_string(jv x, int flags) {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.c
									
									
									
									
									
								
							@@ -55,6 +55,7 @@ enum {
 | 
			
		||||
  COLOUR_OUTPUT = 64,
 | 
			
		||||
  NO_COLOUR_OUTPUT = 128,
 | 
			
		||||
  SORTED_OUTPUT = 256,
 | 
			
		||||
  UNBUFFERED_OUTPUT = 4096,
 | 
			
		||||
 | 
			
		||||
  FROM_FILE = 512,
 | 
			
		||||
 | 
			
		||||
@@ -84,6 +85,7 @@ static void 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;
 | 
			
		||||
      jv_dump(result, dumpopts);
 | 
			
		||||
    }
 | 
			
		||||
    printf("\n");
 | 
			
		||||
@@ -166,6 +168,8 @@ int main(int argc, char* argv[]) {
 | 
			
		||||
      options |= NO_COLOUR_OUTPUT;
 | 
			
		||||
    } else if (isoption(argv[i], 'a', "ascii-output")) {
 | 
			
		||||
      options |= ASCII_OUTPUT;
 | 
			
		||||
    } else if (isoption(argv[i], 0, "unbuffered")) {
 | 
			
		||||
      options |= UNBUFFERED_OUTPUT;
 | 
			
		||||
    } else if (isoption(argv[i], 'S', "sort-keys")) {
 | 
			
		||||
      options |= SORTED_OUTPUT;
 | 
			
		||||
    } else if (isoption(argv[i], 'R', "raw-input")) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user