Fix logic for "slurp" option. Fixes #18
This commit is contained in:
1 parent
2620e21dcc
commit
f2601ab4f0
1 file changed
+8
-10
@@ -120,8 +120,13 @@ int main(int argc, char* argv[]) {
|
|||||||
process(jv_null());
|
process(jv_null());
|
||||||
} else {
|
} else {
|
||||||
jv slurped;
|
jv slurped;
|
||||||
if (options & SLURP) slurped = jv_invalid();
|
if (options & SLURP) {
|
||||||
int first = 1;
|
if (options & RAW_INPUT) {
|
||||||
|
slurped = jv_string("");
|
||||||
|
} else {
|
||||||
|
slurped = jv_array();
|
||||||
|
}
|
||||||
|
}
|
||||||
struct jv_parser parser;
|
struct jv_parser parser;
|
||||||
jv_parser_init(&parser);
|
jv_parser_init(&parser);
|
||||||
while (!feof(stdin)) {
|
while (!feof(stdin)) {
|
||||||
@@ -131,8 +136,7 @@ int main(int argc, char* argv[]) {
|
|||||||
int len = strlen(buf);
|
int len = strlen(buf);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
if (options & SLURP) {
|
if (options & SLURP) {
|
||||||
if (first) slurped = jv_string(buf);
|
slurped = jv_string_concat(slurped, jv_string(buf));
|
||||||
else slurped = jv_string_concat(slurped, jv_string(buf));
|
|
||||||
} else {
|
} else {
|
||||||
if (buf[len-1] == '\n') buf[len-1] = 0;
|
if (buf[len-1] == '\n') buf[len-1] = 0;
|
||||||
process(jv_string(buf));
|
process(jv_string(buf));
|
||||||
@@ -143,7 +147,6 @@ int main(int argc, char* argv[]) {
|
|||||||
jv value;
|
jv value;
|
||||||
while (jv_is_valid((value = jv_parser_next(&parser)))) {
|
while (jv_is_valid((value = jv_parser_next(&parser)))) {
|
||||||
if (options & SLURP) {
|
if (options & SLURP) {
|
||||||
if (first) slurped = jv_array();
|
|
||||||
slurped = jv_array_append(slurped, value);
|
slurped = jv_array_append(slurped, value);
|
||||||
} else {
|
} else {
|
||||||
process(value);
|
process(value);
|
||||||
@@ -158,15 +161,10 @@ int main(int argc, char* argv[]) {
|
|||||||
jv_free(value);
|
jv_free(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
first = 0;
|
|
||||||
}
|
}
|
||||||
jv_parser_free(&parser);
|
jv_parser_free(&parser);
|
||||||
if (options & SLURP) {
|
if (options & SLURP) {
|
||||||
if (jv_is_valid(slurped)) {
|
|
||||||
process(slurped);
|
process(slurped);
|
||||||
} else {
|
|
||||||
jv_free(slurped);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user