@port-labs/jq-node-bindings 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/deps/jq/COPYING +1 -9
  2. package/deps/jq/Makefile.am +13 -18
  3. package/deps/jq/NEWS.md +2 -2
  4. package/deps/jq/README.md +3 -18
  5. package/deps/jq/configure.ac +1 -0
  6. package/deps/jq/docs/Pipfile.lock +59 -72
  7. package/deps/jq/docs/README.md +1 -1
  8. package/deps/jq/docs/build_manpage.py +1 -1
  9. package/deps/jq/docs/build_mantests.py +1 -1
  10. package/deps/jq/docs/content/download/default.yml +1 -23
  11. package/deps/jq/docs/content/index.yml +0 -5
  12. package/deps/jq/docs/content/manual/{dev/manual.yml → manual.yml} +36 -162
  13. package/deps/jq/docs/content/manual/v1.3/manual.yml +5 -0
  14. package/deps/jq/docs/content/manual/v1.4/manual.yml +5 -0
  15. package/deps/jq/docs/content/manual/v1.5/manual.yml +8 -3
  16. package/deps/jq/docs/content/manual/v1.6/manual.yml +8 -3
  17. package/deps/jq/docs/content/manual/v1.7/manual.yml +11 -6
  18. package/deps/jq/docs/content/tutorial/default.yml +3 -3
  19. package/deps/jq/docs/manual_schema.yml +3 -0
  20. package/deps/jq/docs/templates/index.html.j2 +6 -6
  21. package/deps/jq/docs/templates/manual.html.j2 +1 -11
  22. package/deps/jq/jq.1.prebuilt +26 -162
  23. package/deps/jq/jq.spec +1 -1
  24. package/deps/jq/src/builtin.c +211 -298
  25. package/deps/jq/src/builtin.jq +7 -13
  26. package/deps/jq/src/bytecode.h +3 -8
  27. package/deps/jq/src/compile.c +2 -2
  28. package/deps/jq/src/decNumber/decBasic.c +1 -1
  29. package/deps/jq/src/decNumber/decCommon.c +1 -1
  30. package/deps/jq/src/decNumber/decNumber.c +4 -4
  31. package/deps/jq/src/execute.c +42 -22
  32. package/deps/jq/src/jq.h +1 -1
  33. package/deps/jq/src/jq_test.c +7 -69
  34. package/deps/jq/src/jv.c +12 -17
  35. package/deps/jq/src/jv.h +0 -3
  36. package/deps/jq/src/jv_aux.c +4 -3
  37. package/deps/jq/src/jv_dtoa.c +1 -1
  38. package/deps/jq/src/jv_parse.c +0 -2
  39. package/deps/jq/src/jv_print.c +27 -21
  40. package/deps/jq/src/jv_unicode.c +0 -18
  41. package/deps/jq/src/jv_unicode.h +0 -2
  42. package/deps/jq/src/lexer.c +262 -283
  43. package/deps/jq/src/lexer.h +2 -3
  44. package/deps/jq/src/lexer.l +1 -7
  45. package/deps/jq/src/libm.h +5 -15
  46. package/deps/jq/src/linker.c +4 -6
  47. package/deps/jq/src/main.c +252 -179
  48. package/deps/jq/src/util.c +35 -41
  49. package/deps/jq/src/util.h +1 -1
  50. package/deps/jq/tests/jq.test +10 -148
  51. package/deps/jq/tests/jq_fuzz_load_file.c +0 -1
  52. package/deps/jq/tests/man.test +8 -26
  53. package/deps/jq/tests/setup +0 -4
  54. package/deps/jq/tests/shtest +39 -150
  55. package/index.d.ts +3 -2
  56. package/lib/jq.js +2 -2
  57. package/lib/templateAsync.js +8 -15
  58. package/package.json +2 -2
  59. package/src/binding.cc +46 -27
  60. package/test/santiy-async.test.js +4 -0
  61. package/deps/jq/sig/v1.7.1/jq-1.7.1.tar.gz.asc +0 -16
  62. package/deps/jq/sig/v1.7.1/jq-1.7.1.zip.asc +0 -16
  63. package/deps/jq/sig/v1.7.1/jq-linux-amd64.asc +0 -16
  64. package/deps/jq/sig/v1.7.1/jq-linux-arm64.asc +0 -16
  65. package/deps/jq/sig/v1.7.1/jq-linux-armel.asc +0 -16
  66. package/deps/jq/sig/v1.7.1/jq-linux-armhf.asc +0 -16
  67. package/deps/jq/sig/v1.7.1/jq-linux-i386.asc +0 -16
  68. package/deps/jq/sig/v1.7.1/jq-linux-mips.asc +0 -16
  69. package/deps/jq/sig/v1.7.1/jq-linux-mips64.asc +0 -16
  70. package/deps/jq/sig/v1.7.1/jq-linux-mips64el.asc +0 -16
  71. package/deps/jq/sig/v1.7.1/jq-linux-mips64r6.asc +0 -16
  72. package/deps/jq/sig/v1.7.1/jq-linux-mips64r6el.asc +0 -16
  73. package/deps/jq/sig/v1.7.1/jq-linux-mipsel.asc +0 -16
  74. package/deps/jq/sig/v1.7.1/jq-linux-mipsr6.asc +0 -16
  75. package/deps/jq/sig/v1.7.1/jq-linux-mipsr6el.asc +0 -16
  76. package/deps/jq/sig/v1.7.1/jq-linux-powerpc.asc +0 -16
  77. package/deps/jq/sig/v1.7.1/jq-linux-ppc64el.asc +0 -16
  78. package/deps/jq/sig/v1.7.1/jq-linux-riscv64.asc +0 -16
  79. package/deps/jq/sig/v1.7.1/jq-linux-s390x.asc +0 -16
  80. package/deps/jq/sig/v1.7.1/jq-linux64.asc +0 -16
  81. package/deps/jq/sig/v1.7.1/jq-macos-amd64.asc +0 -16
  82. package/deps/jq/sig/v1.7.1/jq-macos-arm64.asc +0 -16
  83. package/deps/jq/sig/v1.7.1/jq-osx-amd64.asc +0 -16
  84. package/deps/jq/sig/v1.7.1/jq-win64.exe.asc +0 -16
  85. package/deps/jq/sig/v1.7.1/jq-windows-amd64.exe.asc +0 -16
  86. package/deps/jq/sig/v1.7.1/jq-windows-i386.exe.asc +0 -16
  87. package/deps/jq/sig/v1.7.1/sha256sum.txt +0 -26
  88. package/deps/jq/tests/uri.test +0 -38
  89. package/deps/jq/tests/uritest +0 -5
@@ -462,7 +462,6 @@ void yyfree ( void * , yyscan_t yyscanner );
462
462
  #define IN_BRACE 3
463
463
  #define IN_QQINTERP 4
464
464
  #define IN_QQSTRING 5
465
- #define IN_COMMENT 6
466
465
 
467
466
  #endif
468
467
 
@@ -732,9 +731,9 @@ extern int yylex \
732
731
  #undef yyTABLES_NAME
733
732
  #endif
734
733
 
735
- #line 137 "src/lexer.l"
734
+ #line 131 "src/lexer.l"
736
735
 
737
736
 
738
- #line 738 "src/lexer.h"
737
+ #line 737 "src/lexer.h"
739
738
  #undef jq_yyIN_HEADER
740
739
  #endif /* jq_yyHEADER_H */
@@ -21,7 +21,6 @@ struct lexer_param;
21
21
  %s IN_BRACE
22
22
  %s IN_QQINTERP
23
23
  %x IN_QQSTRING
24
- %x IN_COMMENT
25
24
  %{
26
25
  static int enter(int opening, int state, yyscan_t yyscanner);
27
26
  static int try_exit(int closing, int state, yyscan_t yyscanner);
@@ -38,12 +37,7 @@ struct lexer_param;
38
37
 
39
38
  %%
40
39
 
41
- "#" { yy_push_state(IN_COMMENT, yyscanner); }
42
- <IN_COMMENT>{
43
- \\[\\\n]|. { }
44
- \n { yy_pop_state(yyscanner); }
45
- }
46
- <IN_COMMENT><<EOF>> { yy_pop_state(yyscanner); }
40
+ "#"[^\n]* { /* comments */ }
47
41
 
48
42
  "!=" { return NEQ; }
49
43
  "==" { return EQ; }
@@ -249,6 +249,11 @@ LIBM_DDD(nexttoward)
249
249
  #else
250
250
  LIBM_DDD_NO(nexttoward)
251
251
  #endif
252
+ #if defined(HAVE_POW10) && !defined(WIN32)
253
+ LIBM_DD(pow10)
254
+ #else
255
+ LIBM_DD_NO(pow10)
256
+ #endif
252
257
  #ifdef HAVE_RINT
253
258
  LIBM_DD(rint)
254
259
  #else
@@ -284,18 +289,3 @@ LIBM_DDD(ldexp)
284
289
  #else
285
290
  LIBM_DDD_NO(ldexp)
286
291
  #endif
287
- #ifdef HAVE_MODF
288
- LIBM_DA(modf, double)
289
- #else
290
- LIBM_DA_NO(modf, double)
291
- #endif
292
- #ifdef HAVE_FREXP
293
- LIBM_DA(frexp, int)
294
- #else
295
- LIBM_DA_NO(frexp, int)
296
- #endif
297
- #ifdef HAVE_LGAMMA_R
298
- LIBM_DA(lgamma_r, int)
299
- #else
300
- LIBM_DA_NO(lgamma_r, int)
301
- #endif
@@ -420,16 +420,14 @@ int load_program(jq_state *jq, struct locfile* src, block *out_block) {
420
420
  return 1;
421
421
  }
422
422
 
423
- jv home = get_home();
424
- if (jv_is_valid(home)) {
425
- /* Import ~/.jq as a library named "" found in $HOME or %USERPROFILE% */
423
+ char* home = getenv("HOME");
424
+ if (home) { // silently ignore no $HOME
425
+ /* Import ~/.jq as a library named "" found in $HOME */
426
426
  block import = gen_import_meta(gen_import("", NULL, 0),
427
427
  gen_const(JV_OBJECT(
428
428
  jv_string("optional"), jv_true(),
429
- jv_string("search"), home)));
429
+ jv_string("search"), jv_string(home))));
430
430
  program = BLOCK(import, program);
431
- } else { // silently ignore if home dir not determined
432
- jv_free(home);
433
431
  }
434
432
 
435
433
  nerrors = process_dependencies(jq, jq_get_jq_origin(jq), jq_get_prog_origin(jq), &program, &lib_state);
@@ -94,8 +94,8 @@ static void usage(int code, int keep_it_short) {
94
94
  " --stream-errors implies --stream and report parse error as\n"
95
95
  " an array;\n"
96
96
  " --seq parse input/output as application/json-seq;\n"
97
- " -f, --from-file load the filter from a file;\n"
98
- " -L, --library-path dir search modules from the directory;\n"
97
+ " -f, --from-file file load filter from the file;\n"
98
+ " -L directory search modules from the directory;\n"
99
99
  " --arg name value set $name to the string value;\n"
100
100
  " --argjson name value set $name to the JSON value;\n"
101
101
  " --slurpfile name file set $name to an array of JSON values read\n"
@@ -126,21 +126,23 @@ static void die() {
126
126
  }
127
127
 
128
128
  static int isoptish(const char* text) {
129
- return text[0] == '-' && (text[1] == '-' || isalpha((unsigned char)text[1]));
129
+ return text[0] == '-' && (text[1] == '-' || isalpha(text[1]));
130
130
  }
131
131
 
132
- static int isoption(const char** text, char shortopt, const char* longopt, int is_short) {
133
- if (is_short) {
134
- if (shortopt && **text == shortopt) {
135
- (*text)++;
136
- if (!**text) *text = NULL;
137
- return 1;
138
- }
139
- } else {
140
- if (!strcmp(*text, longopt)) {
141
- *text = NULL;
142
- return 1;
143
- }
132
+ static int isoption(const char* text, char shortopt, const char* longopt, size_t *short_opts) {
133
+ if (text[0] != '-' || text[1] == '-')
134
+ *short_opts = 0;
135
+ if (text[0] != '-') return 0;
136
+
137
+ // check long option
138
+ if (text[1] == '-' && !strcmp(text+2, longopt)) return 1;
139
+ else if (text[1] == '-') return 0;
140
+
141
+ // must be short option; check it and...
142
+ if (!shortopt) return 0;
143
+ if (strchr(text, shortopt) != NULL) {
144
+ (*short_opts)++; // ...count it (for option stacking)
145
+ return 1;
144
146
  }
145
147
  return 0;
146
148
  }
@@ -160,8 +162,9 @@ enum {
160
162
  UNBUFFERED_OUTPUT = 2048,
161
163
  EXIT_STATUS = 4096,
162
164
  SEQ = 16384,
165
+ RUN_TESTS = 32768,
163
166
  /* debugging only */
164
- DUMP_DISASM = 32768,
167
+ DUMP_DISASM = 65536,
165
168
  };
166
169
 
167
170
  enum {
@@ -175,11 +178,28 @@ enum {
175
178
  #define jq_exit_with_status(r) exit(abs(r))
176
179
  #define jq_exit(r) exit( r > 0 ? r : 0 )
177
180
 
181
+ #define TIMEOUT_SEC 5
182
+
183
+ static const char *skip_shebang(const char *p) {
184
+ if (strncmp(p, "#!", sizeof("#!") - 1) != 0)
185
+ return p;
186
+ const char *n = strchr(p, '\n');
187
+ if (n == NULL || n[1] != '#')
188
+ return p;
189
+ n = strchr(n + 1, '\n');
190
+ if (n == NULL || n[1] == '#' || n[1] == '\0' || n[-1] != '\\' || n[-2] == '\\')
191
+ return p;
192
+ n = strchr(n + 1, '\n');
193
+ if (n == NULL)
194
+ return p;
195
+ return n+1;
196
+ }
197
+
178
198
  static int process(jq_state *jq, jv value, int flags, int dumpopts, int options) {
179
199
  int ret = JQ_OK_NO_OUTPUT; // No valid results && -e -> exit(4)
180
200
  jq_start(jq, value, flags);
181
201
  jv result;
182
- while (jv_is_valid(result = jq_next(jq))) {
202
+ while (jv_is_valid(result = jq_next(jq, TIMEOUT_SEC))) {
183
203
  if ((options & RAW_OUTPUT) && jv_get_kind(result) == JV_KIND_STRING) {
184
204
  if (options & ASCII_OUTPUT) {
185
205
  jv_dumpf(jv_copy(result), stdout, JV_PRINT_ASCII);
@@ -341,8 +361,9 @@ int main(int argc, char* argv[]) {
341
361
  int further_args_are_json = 0;
342
362
  int args_done = 0;
343
363
  int jq_flags = 0;
364
+ size_t short_opts = 0;
344
365
  jv lib_search_paths = jv_null();
345
- for (int i=1; i<argc; i++) {
366
+ for (int i=1; i<argc; i++, short_opts = 0) {
346
367
  if (args_done || !isoptish(argv[i])) {
347
368
  if (!program) {
348
369
  program = argv[i];
@@ -362,171 +383,223 @@ int main(int argc, char* argv[]) {
362
383
  } else if (!strcmp(argv[i], "--")) {
363
384
  args_done = 1;
364
385
  } else {
365
- const char* text = argv[i];
366
- int is_short;
367
- // First '-' already checked by isoptish
368
- if (text[1] == '-') {
369
- text += 2;
370
- is_short = 0;
371
- } else {
372
- text++;
373
- is_short = 1;
374
- }
375
- int raw; // Temporary for --rawfile
376
-
377
- // Parse a long option in one iteration or iterate over short options
378
- while (text != NULL) {
379
- if (isoption(&text, 's', "slurp", is_short)) {
380
- options |= SLURP;
381
- } else if (isoption(&text, 'r', "raw-output", is_short)) {
382
- options |= RAW_OUTPUT;
383
- } else if (isoption(&text, 0, "raw-output0", is_short)) {
384
- options |= RAW_OUTPUT | RAW_NO_LF | RAW_OUTPUT0;
385
- } else if (isoption(&text, 'j', "join-output", is_short)) {
386
- options |= RAW_OUTPUT | RAW_NO_LF;
387
- } else if (isoption(&text, 'c', "compact-output", is_short)) {
388
- dumpopts &= ~(JV_PRINT_TAB | JV_PRINT_INDENT_FLAGS(7));
389
- } else if (isoption(&text, 'C', "color-output", is_short)) {
390
- options |= COLOR_OUTPUT;
391
- } else if (isoption(&text, 'M', "monochrome-output", is_short)) {
392
- options |= NO_COLOR_OUTPUT;
393
- } else if (isoption(&text, 'a', "ascii-output", is_short)) {
394
- options |= ASCII_OUTPUT;
395
- } else if (isoption(&text, 0, "unbuffered", is_short)) {
396
- options |= UNBUFFERED_OUTPUT;
397
- } else if (isoption(&text, 'S', "sort-keys", is_short)) {
398
- options |= SORTED_OUTPUT;
399
- } else if (isoption(&text, 'R', "raw-input", is_short)) {
400
- options |= RAW_INPUT;
401
- } else if (isoption(&text, 'n', "null-input", is_short)) {
402
- options |= PROVIDE_NULL;
403
- } else if (isoption(&text, 'f', "from-file", is_short)) {
404
- options |= FROM_FILE;
405
- } else if (isoption(&text, 'L', "library-path", is_short)) {
406
- if (jv_get_kind(lib_search_paths) == JV_KIND_NULL)
407
- lib_search_paths = jv_array();
408
- if (text != NULL) { // -Lname
409
- lib_search_paths = jv_array_append(lib_search_paths, jq_realpath(jv_string(text)));
410
- text = NULL;
411
- } else if (i >= argc - 1) {
412
- fprintf(stderr, "-L takes a parameter: (e.g. -L /search/path or -L/search/path)\n");
413
- die();
414
- } else {
415
- lib_search_paths = jv_array_append(lib_search_paths, jq_realpath(jv_string(argv[i+1])));
416
- i++;
417
- }
418
- } else if (isoption(&text, 'b', "binary", is_short)) {
386
+ if (argv[i][1] == 'L') {
387
+ if (jv_get_kind(lib_search_paths) == JV_KIND_NULL)
388
+ lib_search_paths = jv_array();
389
+ if (argv[i][2] != 0) { // -Lname (faster check than strlen)
390
+ lib_search_paths = jv_array_append(lib_search_paths, jq_realpath(jv_string(argv[i]+2)));
391
+ } else if (i >= argc - 1) {
392
+ fprintf(stderr, "-L takes a parameter: (e.g. -L /search/path or -L/search/path)\n");
393
+ die();
394
+ } else {
395
+ lib_search_paths = jv_array_append(lib_search_paths, jq_realpath(jv_string(argv[i+1])));
396
+ i++;
397
+ }
398
+ continue;
399
+ }
400
+
401
+ if (isoption(argv[i], 's', "slurp", &short_opts)) {
402
+ options |= SLURP;
403
+ if (!short_opts) continue;
404
+ }
405
+ if (isoption(argv[i], 'r', "raw-output", &short_opts)) {
406
+ options |= RAW_OUTPUT;
407
+ if (!short_opts) continue;
408
+ }
409
+ if (isoption(argv[i], 0, "raw-output0", &short_opts)) {
410
+ options |= RAW_OUTPUT | RAW_NO_LF | RAW_OUTPUT0;
411
+ if (!short_opts) continue;
412
+ }
413
+ if (isoption(argv[i], 'j', "join-output", &short_opts)) {
414
+ options |= RAW_OUTPUT | RAW_NO_LF;
415
+ if (!short_opts) continue;
416
+ }
417
+ if (isoption(argv[i], 'c', "compact-output", &short_opts)) {
418
+ dumpopts &= ~(JV_PRINT_TAB | JV_PRINT_INDENT_FLAGS(7));
419
+ if (!short_opts) continue;
420
+ }
421
+ if (isoption(argv[i], 'C', "color-output", &short_opts)) {
422
+ options |= COLOR_OUTPUT;
423
+ if (!short_opts) continue;
424
+ }
425
+ if (isoption(argv[i], 'M', "monochrome-output", &short_opts)) {
426
+ options |= NO_COLOR_OUTPUT;
427
+ if (!short_opts) continue;
428
+ }
429
+ if (isoption(argv[i], 'a', "ascii-output", &short_opts)) {
430
+ options |= ASCII_OUTPUT;
431
+ if (!short_opts) continue;
432
+ }
433
+ if (isoption(argv[i], 0, "unbuffered", &short_opts)) {
434
+ options |= UNBUFFERED_OUTPUT;
435
+ continue;
436
+ }
437
+ if (isoption(argv[i], 'S', "sort-keys", &short_opts)) {
438
+ options |= SORTED_OUTPUT;
439
+ if (!short_opts) continue;
440
+ }
441
+ if (isoption(argv[i], 'R', "raw-input", &short_opts)) {
442
+ options |= RAW_INPUT;
443
+ if (!short_opts) continue;
444
+ }
445
+ if (isoption(argv[i], 'n', "null-input", &short_opts)) {
446
+ options |= PROVIDE_NULL;
447
+ if (!short_opts) continue;
448
+ }
449
+ if (isoption(argv[i], 'f', "from-file", &short_opts)) {
450
+ options |= FROM_FILE;
451
+ if (!short_opts) continue;
452
+ }
453
+ if (isoption(argv[i], 'b', "binary", &short_opts)) {
419
454
  #ifdef WIN32
420
- fflush(stdout);
421
- fflush(stderr);
422
- _setmode(fileno(stdin), _O_BINARY);
423
- _setmode(fileno(stdout), _O_BINARY);
424
- _setmode(fileno(stderr), _O_BINARY);
455
+ fflush(stdout);
456
+ fflush(stderr);
457
+ _setmode(fileno(stdin), _O_BINARY);
458
+ _setmode(fileno(stdout), _O_BINARY);
459
+ _setmode(fileno(stderr), _O_BINARY);
460
+ if (!short_opts) continue;
425
461
  #endif
426
- } else if (isoption(&text, 0, "tab", is_short)) {
427
- dumpopts &= ~JV_PRINT_INDENT_FLAGS(7);
428
- dumpopts |= JV_PRINT_TAB | JV_PRINT_PRETTY;
429
- } else if (isoption(&text, 0, "indent", is_short)) {
430
- if (i >= argc - 1) {
431
- fprintf(stderr, "%s: --indent takes one parameter\n", progname);
432
- die();
433
- }
434
- dumpopts &= ~(JV_PRINT_TAB | JV_PRINT_INDENT_FLAGS(7));
435
- int indent = atoi(argv[i+1]);
436
- if (indent < -1 || indent > 7) {
437
- fprintf(stderr, "%s: --indent takes a number between -1 and 7\n", progname);
438
- die();
439
- }
440
- dumpopts |= JV_PRINT_INDENT_FLAGS(indent);
441
- i++;
442
- } else if (isoption(&text, 0, "seq", is_short)) {
443
- options |= SEQ;
444
- } else if (isoption(&text, 0, "stream", is_short)) {
445
- parser_flags |= JV_PARSE_STREAMING;
446
- } else if (isoption(&text, 0, "stream-errors", is_short)) {
447
- parser_flags |= JV_PARSE_STREAMING | JV_PARSE_STREAM_ERRORS;
448
- } else if (isoption(&text, 'e', "exit-status", is_short)) {
449
- options |= EXIT_STATUS;
450
- } else if (isoption(&text, 0, "args", is_short)) {
451
- further_args_are_strings = 1;
452
- further_args_are_json = 0;
453
- } else if (isoption(&text, 0, "jsonargs", is_short)) {
454
- further_args_are_strings = 0;
455
- further_args_are_json = 1;
456
- } else if (isoption(&text, 0, "arg", is_short)) {
457
- if (i >= argc - 2) {
458
- fprintf(stderr, "%s: --arg takes two parameters (e.g. --arg varname value)\n", progname);
459
- die();
460
- }
461
- if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1])))
462
- program_arguments = jv_object_set(program_arguments, jv_string(argv[i+1]), jv_string(argv[i+2]));
463
- i += 2; // skip the next two arguments
464
- } else if (isoption(&text, 0, "argjson", is_short)) {
465
- if (i >= argc - 2) {
466
- fprintf(stderr, "%s: --argjson takes two parameters (e.g. --argjson varname text)\n", progname);
467
- die();
468
- }
469
- if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1]))) {
470
- jv v = jv_parse(argv[i+2]);
471
- if (!jv_is_valid(v)) {
472
- fprintf(stderr, "%s: invalid JSON text passed to --argjson\n", progname);
473
- die();
474
- }
475
- program_arguments = jv_object_set(program_arguments, jv_string(argv[i+1]), v);
476
- }
477
- i += 2; // skip the next two arguments
478
- } else if ((raw = isoption(&text, 0, "rawfile", is_short)) ||
479
- isoption(&text, 0, "slurpfile", is_short)) {
480
- const char *which = raw ? "rawfile" : "slurpfile";
481
- if (i >= argc - 2) {
482
- fprintf(stderr, "%s: --%s takes two parameters (e.g. --%s varname filename)\n", progname, which, which);
462
+ }
463
+ if (isoption(argv[i], 0, "tab", &short_opts)) {
464
+ dumpopts &= ~JV_PRINT_INDENT_FLAGS(7);
465
+ dumpopts |= JV_PRINT_TAB | JV_PRINT_PRETTY;
466
+ continue;
467
+ }
468
+ if (isoption(argv[i], 0, "indent", &short_opts)) {
469
+ if (i >= argc - 1) {
470
+ fprintf(stderr, "%s: --indent takes one parameter\n", progname);
471
+ die();
472
+ }
473
+ dumpopts &= ~(JV_PRINT_TAB | JV_PRINT_INDENT_FLAGS(7));
474
+ int indent = atoi(argv[i+1]);
475
+ if (indent < -1 || indent > 7) {
476
+ fprintf(stderr, "%s: --indent takes a number between -1 and 7\n", progname);
477
+ die();
478
+ }
479
+ dumpopts |= JV_PRINT_INDENT_FLAGS(indent);
480
+ i++;
481
+ continue;
482
+ }
483
+ if (isoption(argv[i], 0, "seq", &short_opts)) {
484
+ options |= SEQ;
485
+ continue;
486
+ }
487
+ if (isoption(argv[i], 0, "stream", &short_opts)) {
488
+ parser_flags |= JV_PARSE_STREAMING;
489
+ continue;
490
+ }
491
+ if (isoption(argv[i], 0, "stream-errors", &short_opts)) {
492
+ parser_flags |= JV_PARSE_STREAMING | JV_PARSE_STREAM_ERRORS;
493
+ continue;
494
+ }
495
+ if (isoption(argv[i], 'e', "exit-status", &short_opts)) {
496
+ options |= EXIT_STATUS;
497
+ if (!short_opts) continue;
498
+ }
499
+ // FIXME: For --arg* we should check that the varname is acceptable
500
+ if (isoption(argv[i], 0, "args", &short_opts)) {
501
+ further_args_are_strings = 1;
502
+ further_args_are_json = 0;
503
+ continue;
504
+ }
505
+ if (isoption(argv[i], 0, "jsonargs", &short_opts)) {
506
+ further_args_are_strings = 0;
507
+ further_args_are_json = 1;
508
+ continue;
509
+ }
510
+ if (isoption(argv[i], 0, "arg", &short_opts)) {
511
+ if (i >= argc - 2) {
512
+ fprintf(stderr, "%s: --arg takes two parameters (e.g. --arg varname value)\n", progname);
513
+ die();
514
+ }
515
+ if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1])))
516
+ program_arguments = jv_object_set(program_arguments, jv_string(argv[i+1]), jv_string(argv[i+2]));
517
+ i += 2; // skip the next two arguments
518
+ continue;
519
+ }
520
+ if (isoption(argv[i], 0, "argjson", &short_opts)) {
521
+ if (i >= argc - 2) {
522
+ fprintf(stderr, "%s: --argjson takes two parameters (e.g. --argjson varname text)\n", progname);
523
+ die();
524
+ }
525
+ if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1]))) {
526
+ jv v = jv_parse(argv[i+2]);
527
+ if (!jv_is_valid(v)) {
528
+ fprintf(stderr, "%s: invalid JSON text passed to --argjson\n", progname);
483
529
  die();
484
530
  }
485
- if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1]))) {
486
- jv data = jv_load_file(argv[i+2], raw);
487
- if (!jv_is_valid(data)) {
488
- data = jv_invalid_get_msg(data);
489
- fprintf(stderr, "%s: Bad JSON in --%s %s %s: %s\n", progname, which,
490
- argv[i+1], argv[i+2], jv_string_value(data));
491
- jv_free(data);
492
- ret = JQ_ERROR_SYSTEM;
493
- goto out;
494
- }
495
- program_arguments = jv_object_set(program_arguments, jv_string(argv[i+1]), data);
496
- }
497
- i += 2; // skip the next two arguments
498
- } else if (isoption(&text, 0, "debug-dump-disasm", is_short)) {
499
- options |= DUMP_DISASM;
500
- } else if (isoption(&text, 0, "debug-trace=all", is_short)) {
501
- jq_flags |= JQ_DEBUG_TRACE_ALL;
502
- } else if (isoption(&text, 0, "debug-trace", is_short)) {
503
- jq_flags |= JQ_DEBUG_TRACE;
504
- } else if (isoption(&text, 'h', "help", is_short)) {
505
- usage(0, 0);
506
- } else if (isoption(&text, 'V', "version", is_short)) {
507
- printf("jq-%s\n", JQ_VERSION);
508
- ret = JQ_OK;
509
- goto out;
510
- } else if (isoption(&text, 0, "build-configuration", is_short)) {
511
- printf("%s\n", JQ_CONFIG);
512
- ret = JQ_OK;
513
- goto out;
514
- } else if (isoption(&text, 0, "run-tests", is_short)) {
515
- i++;
516
- // XXX Pass program_arguments, even a whole jq_state *, through;
517
- // could be useful for testing
518
- ret = jq_testsuite(lib_search_paths,
519
- (options & DUMP_DISASM) || (jq_flags & JQ_DEBUG_TRACE),
520
- argc - i, argv + i);
521
- goto out;
522
- } else {
523
- if (is_short) {
524
- fprintf(stderr, "%s: Unknown option -%c\n", progname, text[0]);
525
- } else {
526
- fprintf(stderr, "%s: Unknown option --%s\n", progname, text);
527
- }
531
+ program_arguments = jv_object_set(program_arguments, jv_string(argv[i+1]), v);
532
+ }
533
+ i += 2; // skip the next two arguments
534
+ continue;
535
+ }
536
+ if (isoption(argv[i], 0, "rawfile", &short_opts) ||
537
+ isoption(argv[i], 0, "slurpfile", &short_opts)) {
538
+ int raw = isoption(argv[i], 0, "rawfile", &short_opts);
539
+ const char *which;
540
+ if (raw)
541
+ which = "rawfile";
542
+ else
543
+ which = "slurpfile";
544
+ if (i >= argc - 2) {
545
+ fprintf(stderr, "%s: --%s takes two parameters (e.g. --%s varname filename)\n", progname, which, which);
528
546
  die();
529
547
  }
548
+ if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1]))) {
549
+ jv data = jv_load_file(argv[i+2], raw);
550
+ if (!jv_is_valid(data)) {
551
+ data = jv_invalid_get_msg(data);
552
+ fprintf(stderr, "%s: Bad JSON in --%s %s %s: %s\n", progname, which,
553
+ argv[i+1], argv[i+2], jv_string_value(data));
554
+ jv_free(data);
555
+ ret = JQ_ERROR_SYSTEM;
556
+ goto out;
557
+ }
558
+ program_arguments = jv_object_set(program_arguments, jv_string(argv[i+1]), data);
559
+ }
560
+ i += 2; // skip the next two arguments
561
+ continue;
562
+ }
563
+ if (isoption(argv[i], 0, "debug-dump-disasm", &short_opts)) {
564
+ options |= DUMP_DISASM;
565
+ continue;
566
+ }
567
+ if (isoption(argv[i], 0, "debug-trace=all", &short_opts)) {
568
+ jq_flags |= JQ_DEBUG_TRACE_ALL;
569
+ if (!short_opts) continue;
570
+ }
571
+ if (isoption(argv[i], 0, "debug-trace", &short_opts)) {
572
+ jq_flags |= JQ_DEBUG_TRACE;
573
+ continue;
574
+ }
575
+ if (isoption(argv[i], 'h', "help", &short_opts)) {
576
+ usage(0, 0);
577
+ if (!short_opts) continue;
578
+ }
579
+ if (isoption(argv[i], 'V', "version", &short_opts)) {
580
+ printf("jq-%s\n", JQ_VERSION);
581
+ ret = JQ_OK;
582
+ goto out;
583
+ }
584
+ if (isoption(argv[i], 0, "build-configuration", &short_opts)) {
585
+ printf("%s\n", JQ_CONFIG);
586
+ ret = JQ_OK;
587
+ goto out;
588
+ }
589
+ if (isoption(argv[i], 0, "run-tests", &short_opts)) {
590
+ i++;
591
+ // XXX Pass program_arguments, even a whole jq_state *, through;
592
+ // could be useful for testing
593
+ ret = jq_testsuite(lib_search_paths,
594
+ (options & DUMP_DISASM) || (jq_flags & JQ_DEBUG_TRACE),
595
+ argc - i, argv + i);
596
+ goto out;
597
+ }
598
+
599
+ // check for unknown options... if this argument was a short option
600
+ if (strlen(argv[i]) != short_opts + 1) {
601
+ fprintf(stderr, "%s: Unknown option %s\n", progname, argv[i]);
602
+ die();
530
603
  }
531
604
  }
532
605
  }
@@ -585,7 +658,7 @@ int main(int argc, char* argv[]) {
585
658
  jq_set_attr(jq, jv_string("VERSION_DIR"), jv_string_fmt("%.*s-master", (int)(strchr(JQ_VERSION, '-') - JQ_VERSION), JQ_VERSION));
586
659
 
587
660
  #ifdef USE_ISATTY
588
- if (!program && !(options & FROM_FILE) && (!isatty(STDOUT_FILENO) || !isatty(STDIN_FILENO)))
661
+ if (!program && (!isatty(STDOUT_FILENO) || !isatty(STDIN_FILENO)))
589
662
  program = ".";
590
663
  #endif
591
664
 
@@ -614,7 +687,7 @@ int main(int argc, char* argv[]) {
614
687
  program_arguments = jv_object_set(program_arguments,
615
688
  jv_string("JQ_BUILD_CONFIGURATION"),
616
689
  jv_string(JQ_CONFIG)); /* named arguments */
617
- compiled = jq_compile_args(jq, jv_string_value(data), jv_copy(program_arguments));
690
+ compiled = jq_compile_args(jq, skip_shebang(jv_string_value(data)), jv_copy(program_arguments));
618
691
  free(program_origin);
619
692
  jv_free(data);
620
693
  } else {