ip: Use single variable to represent -pretty

After commit a233caa0aa ("json: make pretty printing optional") I get
following build failure:

    LINK     rtmon
    ../lib/libutil.a(json_print.o): In function `new_json_obj':
    json_print.c:(.text+0x35): undefined reference to `show_pretty'
    collect2: error: ld returned 1 exit status
    make[1]: *** [rtmon] Error 1
    make: *** [all] Error 2

It is caused by missing show_pretty variable in rtmon.

On the other hand tc/tc.c there are two distinct variables and single
matches() call that handles -pretty option thus setting show_pretty
will never happen. Note that since commit 44dcfe8201 ("Change
formatting of u32 back to default") show_pretty is used in tc/f_u32.c
so this is first place where -pretty introduced.

Furthermore other utilities like misc/ifstat.c and misc/nstat.c define
pretty variable, however only for their own purposes. They both support
JSON output and thus depend show_pretty in new_json_obj().

Assuming above use common variable to represent -pretty option, define
it in utils.c and declare in utils.h that is commonly used. Replace
show_pretty with pretty.

Fixes: a233caa0aa ("json: make pretty printing optional")
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
Serhey Popovych 2018-02-15 20:31:33 +02:00 committed by David Ahern
parent 3ce21b2d84
commit 5433656705
8 changed files with 5 additions and 15 deletions

View File

@ -15,8 +15,6 @@
#include "json_writer.h" #include "json_writer.h"
#include "color.h" #include "color.h"
extern int show_pretty;
json_writer_t *get_json_writer(void); json_writer_t *get_json_writer(void);
/* /*

View File

@ -31,7 +31,6 @@ int show_stats;
int show_details; int show_details;
int oneline; int oneline;
int brief; int brief;
int show_pretty;
int json; int json;
int timestamp; int timestamp;
const char *_SL_; const char *_SL_;
@ -261,7 +260,7 @@ int main(int argc, char **argv)
} else if (matches(opt, "-json") == 0) { } else if (matches(opt, "-json") == 0) {
++json; ++json;
} else if (matches(opt, "-pretty") == 0) { } else if (matches(opt, "-pretty") == 0) {
++show_pretty; ++pretty;
} else if (matches(opt, "-rcvbuf") == 0) { } else if (matches(opt, "-rcvbuf") == 0) {
unsigned int size; unsigned int size;

View File

@ -28,7 +28,7 @@ void new_json_obj(int json)
perror("json object"); perror("json object");
exit(1); exit(1);
} }
if (show_pretty) if (pretty)
jsonw_pretty(_jw, true); jsonw_pretty(_jw, true);
jsonw_start_array(_jw); jsonw_start_array(_jw);
} }

View File

@ -37,6 +37,7 @@
int resolve_hosts; int resolve_hosts;
int timestamp_short; int timestamp_short;
int pretty;
int read_prop(const char *dev, char *prop, long *value) int read_prop(const char *dev, char *prop, long *value)
{ {

View File

@ -45,7 +45,6 @@ int no_update;
int scan_interval; int scan_interval;
int time_constant; int time_constant;
int show_errors; int show_errors;
int pretty;
double W; double W;
char **patterns; char **patterns;
int npatterns; int npatterns;

View File

@ -37,7 +37,6 @@ int reset_history;
int ignore_history; int ignore_history;
int no_output; int no_output;
int json_output; int json_output;
int pretty;
int no_update; int no_update;
int scan_interval; int scan_interval;
int time_constant; int time_constant;

View File

@ -25,8 +25,6 @@
#include "utils.h" #include "utils.h"
#include "tc_util.h" #include "tc_util.h"
extern int show_pretty;
static void explain(void) static void explain(void)
{ {
fprintf(stderr, fprintf(stderr,
@ -965,7 +963,7 @@ static void show_keys(FILE *f, const struct tc_u32_key *key)
{ {
int i = 0; int i = 0;
if (!show_pretty) if (!pretty)
goto show_k; goto show_k;
for (i = 0; i < ARRAY_SIZE(u32_pprinters); i++) { for (i = 0; i < ARRAY_SIZE(u32_pprinters); i++) {

View File

@ -33,7 +33,6 @@
int show_stats; int show_stats;
int show_details; int show_details;
int show_raw; int show_raw;
int show_pretty;
int show_graph; int show_graph;
int timestamp; int timestamp;
@ -42,7 +41,6 @@ int use_iec;
int force; int force;
bool use_names; bool use_names;
int json; int json;
int pretty;
static char *conf_file; static char *conf_file;
@ -449,7 +447,7 @@ int main(int argc, char **argv)
} else if (matches(argv[1], "-raw") == 0) { } else if (matches(argv[1], "-raw") == 0) {
++show_raw; ++show_raw;
} else if (matches(argv[1], "-pretty") == 0) { } else if (matches(argv[1], "-pretty") == 0) {
++show_pretty; ++pretty;
} else if (matches(argv[1], "-graph") == 0) { } else if (matches(argv[1], "-graph") == 0) {
show_graph = 1; show_graph = 1;
} else if (matches(argv[1], "-Version") == 0) { } else if (matches(argv[1], "-Version") == 0) {
@ -485,8 +483,6 @@ int main(int argc, char **argv)
++timestamp_short; ++timestamp_short;
} else if (matches(argv[1], "-json") == 0) { } else if (matches(argv[1], "-json") == 0) {
++json; ++json;
} else if (matches(argv[1], "-pretty") == 0) {
++pretty;
} else { } else {
fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]); fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
return -1; return -1;