jshn: add an option for printing the json data without a terminating newline
This commit is contained in:
parent
a8032be64c
commit
bdf6363777
2 changed files with 11 additions and 6 deletions
15
jshn.c
15
jshn.c
|
@ -210,33 +210,38 @@ out:
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int jshn_format(void)
|
static int jshn_format(bool no_newline)
|
||||||
{
|
{
|
||||||
json_object *obj;
|
json_object *obj;
|
||||||
|
|
||||||
obj = json_object_new_object();
|
obj = json_object_new_object();
|
||||||
jshn_add_objects(obj, "JSON_VAR", false);
|
jshn_add_objects(obj, "JSON_VAR", false);
|
||||||
fprintf(stdout, "%s\n", json_object_to_json_string(obj));
|
fprintf(stdout, "%s%s", json_object_to_json_string(obj),
|
||||||
|
no_newline ? "" : "\n");
|
||||||
json_object_put(obj);
|
json_object_put(obj);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage(const char *progname)
|
static int usage(const char *progname)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s -r <message>|-w\n", progname);
|
fprintf(stderr, "Usage: %s [-n] -r <message>|-w\n", progname);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
bool no_newline = false;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "r:w")) != -1) {
|
while ((ch = getopt(argc, argv, "nr:w")) != -1) {
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 'r':
|
case 'r':
|
||||||
return jshn_parse(optarg);
|
return jshn_parse(optarg);
|
||||||
case 'w':
|
case 'w':
|
||||||
return jshn_format();
|
return jshn_format(no_newline);
|
||||||
|
case 'n':
|
||||||
|
no_newline = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return usage(argv[0]);
|
return usage(argv[0]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ json_load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
json_dump() {
|
json_dump() {
|
||||||
jshn -w
|
jshn "$@" -w
|
||||||
}
|
}
|
||||||
|
|
||||||
json_get_type() {
|
json_get_type() {
|
||||||
|
|
Loading…
Reference in a new issue