~davbo/ubuntu/trusty/jq/merge-debian-changes

« back to all changes in this revision

Viewing changes to jv_print.c

  • Committer: David King
  • Date: 2017-04-12 15:47:07 UTC
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: dave@davbo.org-20170412154707-qq74qifqttlcqb3r
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <stdio.h>
3
3
#include <float.h>
4
4
#include <string.h>
 
5
#include <assert.h>
5
6
 
6
7
#include "jv_dtoa.h"
7
8
#include "jv_unicode.h"
194
195
      put_space(indent+INDENT, F, S);
195
196
    }
196
197
    int first = 1;
197
 
    jv_object_foreach(x, key, value) {
 
198
    int i = 0;
 
199
    jv keyset = jv_null();
 
200
    while (1) {
 
201
      jv key, value;
 
202
      if (flags & JV_PRINT_SORTED) {
 
203
        if (first) {
 
204
          keyset = jv_keys(jv_copy(x));
 
205
          i = 0;
 
206
        } else {
 
207
          i++;
 
208
        }
 
209
        if (i >= jv_array_length(jv_copy(keyset))) {
 
210
          jv_free(keyset);
 
211
          break;
 
212
        }
 
213
        key = jv_array_get(jv_copy(keyset), i);
 
214
        value = jv_object_get(jv_copy(x), jv_copy(key));
 
215
      } else {
 
216
        if (first) {
 
217
          i = jv_object_iter(x);
 
218
        } else {
 
219
          i = jv_object_iter_next(x, i);
 
220
        }
 
221
        if (!jv_object_iter_valid(x, i)) break;
 
222
        key = jv_object_iter_key(x, i);
 
223
        value = jv_object_iter_value(x, i);
 
224
      }
 
225
 
198
226
      if (!first) {
199
227
        if (flags & JV_PRINT_PRETTY){
200
228
          put_str(",\n", F, S);
232
260
  }
233
261
}
234
262
 
 
263
void jv_dumpf(jv x, FILE *f, int flags) {
 
264
  struct dtoa_context C;
 
265
  jvp_dtoa_context_init(&C);
 
266
  jv_dump_term(&C, x, flags, 0, f, 0);
 
267
  jvp_dtoa_context_free(&C);
 
268
}
 
269
 
235
270
void jv_dump(jv x, int flags) {
236
 
  struct dtoa_context C;
237
 
  jvp_dtoa_context_init(&C);
238
 
  jv_dump_term(&C, x, flags, 0, stdout, 0);
239
 
  jvp_dtoa_context_free(&C);
 
271
  jv_dumpf(x, stdout, flags);
 
272
}
 
273
 
 
274
void jv_show(jv x, int flags) {
 
275
  if (flags == -1)
 
276
    flags = JV_PRINT_PRETTY | JV_PRINT_COLOUR;
 
277
  jv_dumpf(jv_copy(x), stderr, flags);
 
278
  fflush(stderr);
240
279
}
241
280
 
242
281
jv jv_dump_string(jv x, int flags) {