jshn: optimize the shell code some more
[project/libubox.git] / blobmsg_json.c
index 9835a885ee74583ad465d885860168022f0e9d0e..f1c47ce8128878300769eb4d2e29d15eff77175c 100644 (file)
@@ -129,14 +129,11 @@ static bool blobmsg_puts(struct strbuf *s, const char *c, int len)
 static void add_separator(struct strbuf *s)
 {
        static char indent_chars[17] = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
-       static const char indent_space = ' ';
        int indent;
        char *start;
 
-       if (!s->indent) {
-               blobmsg_puts(s, &indent_space, 1);
+       if (!s->indent)
                return;
-       }
 
        indent = s->indent_level;
        if (indent > 16)
@@ -219,7 +216,7 @@ static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, boo
 
        if (!array && blobmsg_name(attr)[0]) {
                blobmsg_format_string(s, blobmsg_name(attr));
-               blobmsg_puts(s, ": ", 2);
+               blobmsg_puts(s, ": ", s->indent ? 2 : 1);
        }
        if (head) {
                data = blob_data(attr);
@@ -247,7 +244,7 @@ static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, boo
                sprintf(buf, "%d", be16_to_cpu(*(uint16_t *)data));
                break;
        case BLOBMSG_TYPE_INT32:
-               sprintf(buf, "%d", be32_to_cpu(*(uint32_t *)data));
+               sprintf(buf, "%d", (int32_t) be32_to_cpu(*(uint32_t *)data));
                break;
        case BLOBMSG_TYPE_INT64:
                sprintf(buf, "%lld", (long long int) be64_to_cpu(*(uint64_t *)data));