Skip to content

Commit 39a385e

Browse files
committed
4.3.3 -- Docs, refactor, delete old manpages on install
1 parent e85361d commit 39a385e

File tree

8 files changed

+146
-27
lines changed

8 files changed

+146
-27
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ install: jt jt.1
5151
mkdir -p $(BINDIR) $(MANDIR)
5252
cp jt $(BINDIR)
5353
cp jt.1 $(MANDIR)
54+
cat $(PREFIX)/man/man1/jt.1 2>&1 |grep -q 'micha\\\.niskin@gmail\\\.com' \
55+
&& rm -f $(PREFIX)/man/man1/jt.1 || true
5456

5557
jt.tar: jt jt.1
5658
tar cf $@ --transform 's@^@bin/@' jt

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,13 @@ See the [man page][man] or `man jt` in your terminal.
182182

183183
The [man page][man] has many examples.
184184

185+
## SEE ALSO
186+
187+
**Jt** is based on ideas from the excellent [jshon][jshon] tool.
188+
185189
## COPYRIGHT
186190

187191
Copyright © 2017 Micha Niskin. Distributed under the Eclipse Public License.
188192

189193
[man]: http://htmlpreview.github.io/?https://raw.githubusercontent.com/micha/json-table/master/jt.1.html
194+
[jshon]: http://kmkeen.com/jshon/

jt.1

+54-4
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,51 @@ Otherwise, \fB@\fR prints the type of the item, or \fI[none]\fR if there is no v
275275
.
276276
.nf
277277

278-
$ echo \'"hello world"\' | jt @
278+
$ echo \'["hello", "world"]\' | jt @
279279
[string]
280+
.
281+
.fi
282+
.
283+
.IP "" 0
284+
.
285+
.IP "" 4
286+
.
287+
.nf
288+
289+
$ echo \'[1, 2]\' | jt @
290+
[number]
291+
.
292+
.fi
293+
.
294+
.IP "" 0
295+
.
296+
.IP "" 4
297+
.
298+
.nf
280299

281-
$ echo {} | jt foo @
300+
$ echo \'[true, false]\' | jt @
301+
[boolean]
302+
.
303+
.fi
304+
.
305+
.IP "" 0
306+
.
307+
.IP "" 4
308+
.
309+
.nf
310+
311+
$ echo \'[null, null]\' | jt @
312+
[null]
313+
.
314+
.fi
315+
.
316+
.IP "" 0
317+
.
318+
.IP "" 4
319+
.
320+
.nf
321+
322+
$ echo \'[]\' | jt @
282323
[none]
283324
.
284325
.fi
@@ -391,7 +432,7 @@ $ jt foo bar % <<EOT
391432
.IP "" 0
392433
.
393434
.P
394-
The \fB%\fR command can be used multiple times\. The printed values will be delimited by tabs:
435+
The \fB%\fR command can be used multiple times\. The printed values will be separated by tabs:
395436
.
396437
.IP "" 4
397438
.
@@ -411,7 +452,10 @@ $ jt % foo % bar % <<EOT
411452
.IP "" 0
412453
.
413454
.SS "Save / Restore"
414-
The \fB[\fR and \fB]\fR commands provide a sort of \fBGOSUB\fR facility\. Use \fB[\fR to save the data stack\'s state on the gosub stack\. Then drill down and print a value\. The \fB]\fR command pops the gosub stack and restores the data stack to that state\. Now it is possible to drill down into a different path to print another value:
455+
The \fB[\fR and \fB]\fR commands provide a way to save the data stack\'s state before performing some operations and restore it afterwards\. This makes it possible to drill down into one part of an object and then "rewind" to drill down into another part of the same object\.
456+
.
457+
.P
458+
The \fB[\fR command saves the state of the data stack and the \fB]\fR command restores the data stack to the corresponding saved state\. It is an error to use the \fB]\fR command without a corresponding \fB[\fR command\.
415459
.
416460
.IP "" 4
417461
.
@@ -877,5 +921,11 @@ foo 1 bar 200
877921
.
878922
.IP "" 0
879923
.
924+
.SH "SEE ALSO"
925+
\fBJt\fR is based on ideas from the excellent \fBjshon\fR tool, which can be found at \fIhttp://kmkeen\.com/jshon/\fR\. Source code for \fBjt\fR is available at \fIhttps://github\.com/micha/json\-table\fR\.
926+
.
927+
.SH "BUGS"
928+
Please open an issue here: \fIhttps://github\.com/micha/json\-table/issues\fR\.
929+
.
880930
.SH "COPYRIGHT"
881931
Copyright © 2017 Micha Niskin \fB<micha\.niskin@gmail\.com>\fR, distributed under the Eclipse Public License, version 1\.0\. This is free software: you are free to change and redistribute it\. There is NO WARRANTY, to the extent permitted by law\.

jt.1.html

+36-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jt.1.ronn

+38-7
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,27 @@ bar
237237
Otherwise, `@` prints the type of the item, or <[none]> if there is no value:
238238
239239
```bash
240-
$ echo '"hello world"' | jt @
240+
$ echo '["hello", "world"]' | jt @
241241
[string]
242+
```
243+
244+
```bash
245+
$ echo '[1, 2]' | jt @
246+
[number]
247+
```
248+
249+
```bash
250+
$ echo '[true, false]' | jt @
251+
[boolean]
252+
```
253+
254+
```bash
255+
$ echo '[null, null]' | jt @
256+
[null]
257+
```
242258
243-
$ echo {} | jt foo @
259+
```bash
260+
$ echo '[]' | jt @
244261
[none]
245262
```
246263
@@ -324,7 +341,7 @@ $ jt foo bar % <<EOT
324341
100
325342
```
326343
327-
The `%` command can be used multiple times. The printed values will be delimited
344+
The `%` command can be used multiple times. The printed values will be separated
328345
by tabs:
329346
330347
```bash
@@ -340,10 +357,14 @@ $ jt % foo % bar % <<EOT
340357
341358
### Save / Restore
342359
343-
The `[` and `]` commands provide a sort of `GOSUB` facility. Use `[` to save
344-
the data stack's state on the gosub stack. Then drill down and print a value.
345-
The `]` command pops the gosub stack and restores the data stack to that state.
346-
Now it is possible to drill down into a different path to print another value:
360+
The `[` and `]` commands provide a way to save the data stack's state before
361+
performing some operations and restore it afterwards. This makes it possible
362+
to drill down into one part of an object and then "rewind" to drill down into
363+
another part of the same object.
364+
365+
The `[` command saves the state of the data stack and the `]` command restores
366+
the data stack to the corresponding saved state. It is an error to use the `]`
367+
command without a corresponding `[` command.
347368
348369
```bash
349370
$ jt [ foo % ] bar % <<EOT
@@ -687,6 +708,16 @@ foo 0 bar 100
687708
foo 1 bar 200
688709
```
689710
711+
## SEE ALSO
712+
713+
**Jt** is based on ideas from the excellent **jshon** tool, which can be found
714+
at <http://kmkeen.com/jshon/>. Source code for **jt** is available at
715+
<https://github.com/micha/json-table>.
716+
717+
## BUGS
718+
719+
Please open an issue here: <https://github.com/micha/json-table/issues>.
720+
690721
## COPYRIGHT
691722
692723
Copyright © 2017 Micha Niskin `<[email protected]>`, distributed under

jt.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define JT_STACKSIZE 256
1212
#endif
1313

14-
#define JT_VERSION "4.3.2"
14+
#define JT_VERSION "4.3.3"
1515

1616
int opt_join = 0;
1717
int opt_iter = 0;
@@ -42,8 +42,11 @@ int run(int wordc, word_t *wordv) {
4242

4343
if (wordc <= 0) return 0;
4444

45-
if (d && ((js_is_array(js_tok(p, d)) && !opt_iter) || (e = (wordv[0].cmd == '.')))) {
46-
if (!js_is_collection(js_tok(p, d)) || js_is_empty(js_tok(p, d))) {
45+
if ((e = (wordv[0].cmd == '.')) || (d && js_is_array(js_tok(p, d)) && !opt_iter)) {
46+
if (!d) {
47+
stack_push(DAT, 0);
48+
if (opt_join) cols = -JT_STACKSIZE;
49+
} else if (!js_is_collection(js_tok(p, d)) || js_is_empty(js_tok(p, d))) {
4750
stack_push(DAT, 0);
4851
run(wordc - e, wordv + e);
4952
if (opt_join) cols = -JT_STACKSIZE;
@@ -67,11 +70,6 @@ int run(int wordc, word_t *wordv) {
6770
return cols;
6871
} else {
6972
switch (wordv[0].cmd) {
70-
case '.':
71-
// can only get here if top of stack is null
72-
if (opt_join) return -JT_STACKSIZE;
73-
stack_push(DAT, 0);
74-
break;
7573
case '^':
7674
cols = 1;
7775
stack_push(OUT, stack_head(IDX));
@@ -213,7 +211,7 @@ void version() {
213211
printf("jt %s\n", JT_VERSION);
214212
#endif
215213
printf("\n");
216-
printf("Copyright © 2017 Micha Niskin <[email protected]>, distributed under\n");
214+
printf("Copyright © 2017 by Micha Niskin <[email protected]>, distributed under\n");
217215
printf("the Eclipse Public License, version 1.0. This is free software: you are free\n");
218216
printf("to change and redistribute it. There is NO WARRANTY, to the extent permitted\n");
219217
printf("by law.\n");

jt.tar.gz

264 Bytes
Binary file not shown.

test/test-jt.sh

+4
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,8 @@ assert $LINENO \
211211
EOT
212212
)"
213213

214+
assert $LINENO \
215+
"$(echo '{}' |$jt . % && echo OK)" \
216+
OK
217+
214218
[[ $fails == 0 ]] || exit 1

0 commit comments

Comments
 (0)