Commit Graph
121 Commits
Author SHA1 Message Date
Jason Hood 88e1f59ec1 Allow globbing on Windows
The mingw-w64 runtime expands wildcards, which causes a discrepancy
between `main`'s `argv` (multiple file names) and Windows' `wargv` (a
single wildcard).  Use `wmain` to retrieve the wide character args.
2019-02-17 23:58:23 -06:00
Jason Hood 80b064f97b Make UTC time on Windows
Windows has `_mkgmtime` for the UTC equivalent of `mktime`.
2019-02-16 20:42:25 -06:00
Jason Hood 0fc8200ab4 Add ISO 8601-specific strptime
Implement `strptime` for systems lacking it, but only supporting the
ISO 8601 format string.
2019-02-16 20:41:41 -06:00
Jason Hood 87594f81d6 Prevent redirecting to NUL crash
Windows regards the `NUL` device as tty, which causes `WriteFile` to
fail (the bytes written pointer cannot be `NULL` in this case).  Tweak
the color test to ensure tty is accurate.
2019-02-16 20:40:41 -06:00
Jason Hood def42a31ca Possibly enable color output on Windows (#1494)
Windows 10 supports color output, but it must be explicitly enabled;
ANSICON provides support for other versions.  Enable color if either of
those are available.  Resolves #1494.
2019-02-16 20:40:41 -06:00
Muh Muhten 605bfb3577 Reimplement block_drop_unreferenced in linear time 2019-02-16 20:30:20 -06:00
Muh Muhten 3f59bee3e0 Make sure to free in jv_string_indexes 2019-02-09 17:17:59 -05:00
Muh Muhten 88613f5469 Improve linking time by marking subtrees with unbound symbols 2019-02-08 22:41:31 -06:00
Nicolas Williams 2660b04a73 Fix infinite loop in index("") (fix #1815) 2019-02-08 20:40:55 -06:00
Muh Muhten 956d40d9dd Define error/1 in terms of error/0
The parser generates a call to error/0 on break. Having that exported
from C directly removes a language dependency on builtin.jq.

In any case, error/0 seems to be the more fundamental operation, seeing
as the old C impementation of error/1 did nothing useful with its input.
2019-02-07 11:05:06 -06:00
Muh Muhten 2fd725209e Export input/0 directly from C, removing _input/0
The distinction between input/0 and _input/0 has been unnecessary since
a9c613..7dc34b, which moved end-of-input handling into C and replaced
the jq definition of input with `def input: _input;`
2019-02-06 12:06:03 -06:00
Derrick Pallas 21be3857b5 builtin/f_match: prevent overruns of input_string
If these values do not match exactly, it is because the UTF-8 is invalid
anyway and we counted codepoints differently than oniguruma did.  Perhaps it
would be better to error out here, but at least one similar loop already
uses < vs != and since we're off the rails anyway this might be OK.  It is
certainly better than overruning the buffer.

Resolves https://github.com/stedolan/jq/issues/1804
2019-02-04 14:12:03 -06:00
Derrick Pallas d29bf5b4fc builtin/f_match: call onig_error_code_to_str with einfo correctly 2019-02-02 16:17:12 -08:00
Muh Muhten 3c5b1419a2 Unify timegm fallbacks into my_mktime
my_timegm was introduced in 1900c7 to add a mktime fallback used in
4a6241, the subsequently removed in c53823. As a result of this code
shuffling, the jq mktime function (f_mktime) wound up using a fallback
even on systems where timegm is available, with incorrect results in
some time zones with DST, e.g.

% TZ=America/New_York jq -n '"2018-08-31T00:00:00Z"|fromdate|todate'
"2018-08-31T01:00:00Z"

This undoes 1900c7 and moves the workaround it added into the #else of
my_mktime.
2019-01-30 22:05:51 -06:00
Muh Muhten 12a628abdc Fix include/import namespace confusion 2019-01-30 09:47:24 -06:00
Nicolas Williams 61cd6dbb3b contains should handle embedded NULs (fix #1732) 2019-01-18 22:33:46 -06:00
Ricardo Constantino b10878fea7 builtin: add missing windows.h include
Follow-up fix to b436156f5 because BOOL and DWORD
are not built-in to mingw64.
2018-12-26 12:53:48 -06:00
HE, Tao b436156f5b Mingw-w64 on windows doesn't have setenv, fix that.
Signed-off-by: HE, Tao <sighingnow@gmail.com>
2018-12-19 09:07:14 -06:00
Eugen fb1c635af6 Make fromstream/1 more efficient 2018-12-18 14:20:35 -06:00
Ryoichi KATO 6d3d2750ec fix --exit-code issues #1142 and #1139
* Set default error code to -4 in main(), Fixes #1142
* fix --exit-code with more than one object in input, Fixes #1139
    - Return code 1 or 4 based on last output, not last input.
2018-12-18 14:17:47 -06:00
Nicolas Williams 8ea4a5584e Allow variable refs as object keys {$key:value}
Users are often surprised by the requirement to parenthesize any
non-trivial object key expressions in object constructors.  E.g.,
{"a"+"b":1}.  This commit adds one more kind of key expression besides
literals and idents: variable references.

A common use case for this is jq programs as JSON templates to fill in
with variables computed from inputs or passed in on the command-line.
E.g., {some_key:$value}.  Now users can also use, e.g., {$key:$value}.

This and the restrictions on key and value expressions in object
constructors are now clarified a bit in the documentation.
2018-12-10 21:54:59 -06:00
William Langford a1f1231a73 Add missing jv_copy when printing with -ar 2018-11-20 09:58:25 -05:00
William Langford dd4cec664c fix memory leak 2018-08-30 21:09:04 -04:00
William Langford 46d1ce2667 Restore JV_PRINT_COLOUR as an alias
JV_PRINT_COLOUR was part of the public libjq headers and was removed as
part of 2d05b54. While JV_PRINT_COLOR is definitely the preferred
spelling this side of the pond, we shouldn't just remove otherwise
exposed enum values.
2018-08-17 23:23:10 -04:00
William Langford 0673dee1b3 Fix destructuring alternation
Attempting to use the existing FORK_OPT opcode resulted in difficulty
knowing when to pop an error message off the stack and when not to. This
commit makes DESTRUCTURE_ALT a real opcode that is identical to
FORK_OPT, except for never pushing the error message onto the stack when
continuing from an error backtrack.

Some small changes were necessary to the DUP/POP behavior surrounding
destructuring to accomodate this.
2018-08-17 23:15:48 -04:00
Roland C. Dowdeswell 90bc29c1b5 jv_file.c: check to see if the file is a directory and fail
Not all stdio implementations disallow one to open a directory with
fopen(3) and so we specifically check for directories as it is also
in the standard search path.
2018-05-11 19:32:25 -05:00
Nicolas Williams 7fd9e86ea6 Make limit/2 more efficient
Contributed by @pkoppstein.
2018-03-06 16:35:33 -06:00
Nicolas Williams e113c67d51 limit/2 evals exp one time too many 2018-03-06 11:29:13 -06:00
rain1 bf88c73c20 src/main.c: fix issue #1587 by using jv_dumpf in the raw-output and ascii-output case. retain fwrite in the raw-output case. 2018-03-01 14:33:47 -06:00
David Fetter b4742c1257 Added rawfile
In passing, clean remnants of argfile from slurpfile docs.
2017-12-11 12:17:17 -06:00
Nicolas Williams 9a4576e756 Revert "reduce: handle empty updates (fix #1313)"
This reverts commit e24af3c78e.

While the semantics are desirable, there is no way to implement them
efficiently.  The reason is that in order to handle backtracking (empty)
from the state update expression, we have to retain a reference to the
reduction state value in order to restore it upon backtracking.
Retaining a reference to the reduction state kills performance by
causing lots of additional memory allocations and garbage because the
input to the update expression will always have at least two references,
thus no changes to it can be done in-place, and all changes end up being
CoW changes.

Avoiding this is the very reason for the LOADVN instruction (leaving
`null` in the variable loaded from).
2017-12-11 11:20:16 -06:00
Nicolas Williams b5560d8420 Fix import as $data linking 2017-12-10 23:09:35 -06:00
William Langford 79ece35981 Fix hang for slurped inputs with trailing newline 2017-12-04 20:10:56 -05:00
William Langford f06deb828a Fix #1534 2017-12-04 19:20:58 -05:00
William Langford 0c9eacedaa Actually fix the strptime tests
This has been a complicated issue to fix for a number of reasons.
The core of it is that the behavior is different between different
versions of macOS, some of which set possible-but-incorrect values.

This commit addresses the issue by always using our computation for
tm_wday and tm_yday on macOS. As a side-effect, strptime format
strings that specify %u and %j will no longer work on macOS.
2017-11-29 20:47:56 -05:00
Eric Bréchemier 476b36770d Keep object keys in parsing order in tostream output
As noted by @nicowilliams, `tostream` used `keys`,
which sorts the keys in alphabetical order, instead
of `keys_unsorted`, which preserves the parsing order.

Fixes #1541.
2017-11-29 11:46:08 -06:00
William Langford c3cbbdd8a2 Fix memory leaks in various c-coded builtins 2017-11-27 20:37:14 -05:00
Nicolas Williams 18879fb993 Fix leak on error in strptime 2017-11-23 01:51:22 -06:00
William Langford 7b81a836c3 Merge pull request #1403 from Argoday/master
Use unsorted keys in walk
2017-06-19 10:55:26 -04:00
Nicolas Williams c538237f4e Deal with strptime() on OS X and *BSD (fix #1415)
strptime() on OS X and *BSDs (reputedly) does not set tm_wday and
tm_yday unless corresponding %U and %j format specifiers were used.
That can be... surprising when one parsed year, month, and day anyways.
Glibc's strptime() conveniently sets tm_wday and tm_yday in those cases,
but OS X's does not, ignoring them completely.

This commit makes jq compute those where possible, though the day of
week computation may be wrong for dates before 1900-03-01 or after
2099-12-31.
2017-05-21 16:24:48 -05:00
Nicolas Williams 4a6241be06 Attempt to fix #1415
OS X (and *BSD) strptime() does not set tm_wday nor tm_yday unless
corresponding format options are used.  That means we must call timegm()
to set them.
2017-05-21 01:58:18 -05:00
Nicolas Williams 1900c7bcac Add private my_timegm() 2017-05-21 01:57:55 -05:00
Nicolas Williams 578d536233 Fix HAVE_TM_TM_GMT_OFF usage 2017-05-21 01:53:00 -05:00
Nicolas Williams 10d66051ef Fix jv_load_file() assertion (fix #1410) 2017-05-20 18:53:48 -05:00
Jonathan Word ca12bd9b5d Use unsorted keys in walk
Preserve key sorting order when executing in walk, if sorted keys is desired `--sort-keys` should be used to explicitly obtain sorted keys.
2017-05-03 15:49:21 -04:00
Nico Williams 6d89e297fe Add JQ_COLORS env var for color config (fix #1252) 2017-04-29 14:00:52 -04:00
Nicolas Williams 32d8f2000a Fix build 2017-04-26 20:55:50 -05:00
Nicolas Williams 0bd7614bd5 Always use jv_mem_*alloc() 2017-04-21 18:41:06 -05:00
pkoppstein 4b4cf789e0 def isempty(g) # Testing 'isempty(empty)' at line number 1364 2017-04-15 16:45:00 -05:00
Nicolas Williams 18753cb7a7 Also fix jn/2 and yn/2 2017-03-30 11:46:03 -05:00