Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/jshn.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-05-31 17:41:19 +0400
committerFelix Fietkau <nbd@openwrt.org>2011-05-31 17:41:19 +0400
commitbdf636377785788f7463d915e0adfb1a77bfe8c5 (patch)
treeae24cea8c7907de66601ebd46ced8f9db8be24f4 /jshn.c
parenta8032be64c4d03a98af47e9f4d93ddc137d23733 (diff)
jshn: add an option for printing the json data without a terminating newline
Diffstat (limited to 'jshn.c')
-rw-r--r--jshn.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/jshn.c b/jshn.c
index a2d711f..e2f0b83 100644
--- a/jshn.c
+++ b/jshn.c
@@ -210,33 +210,38 @@ out:
return obj;
}
-static int jshn_format(void)
+static int jshn_format(bool no_newline)
{
json_object *obj;
obj = json_object_new_object();
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);
return 0;
}
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;
}
int main(int argc, char **argv)
{
+ bool no_newline = false;
int ch;
- while ((ch = getopt(argc, argv, "r:w")) != -1) {
+ while ((ch = getopt(argc, argv, "nr:w")) != -1) {
switch(ch) {
case 'r':
return jshn_parse(optarg);
case 'w':
- return jshn_format();
+ return jshn_format(no_newline);
+ case 'n':
+ no_newline = true;
+ break;
default:
return usage(argv[0]);
}