Skip to content

Commit d0fd670

Browse files
committed
adjusted program usage
1 parent 1a2c90e commit d0fd670

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

json.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <json-c/json.h>
88

99
#include "json.h"
10+
#include "util.h"
1011

1112
json_object *json_root;
1213

@@ -20,27 +21,24 @@ void json_init()
2021
void json_done()
2122
{
2223
if(json_root) json_object_put(json_root);
24+
2325
json_root = 0;
2426
}
2527

2628

27-
void json_print(char *file_name)
29+
void json_print()
2830
{
29-
if(!file_name) return;
31+
if(!opt.json) return;
3032

3133
json_object *json_obj = json_root;
3234

3335
if(json_object_array_length(json_obj) == 1) json_obj = json_object_array_get_idx(json_obj, 0);
3436

3537
int flags = JSON_C_TO_STRING_PRETTY + JSON_C_TO_STRING_NOSLASHESCAPE + JSON_C_TO_STRING_SPACED;
3638

37-
if(strcmp(file_name, "-")) {
38-
json_object_to_file_ext(file_name, json_obj, flags);
39-
}
40-
else {
41-
json_object_to_fd(STDOUT_FILENO, json_obj, flags);
42-
printf("\n");
43-
}
39+
json_object_to_fd(STDOUT_FILENO, json_obj, flags);
40+
41+
printf("\n");
4442
}
4543

4644

json.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
void json_init();
44
void json_done();
5-
void json_print(char *file_name);
5+
void json_print();
66
json_object *json_object_new_format(const char *format, ...) __attribute__ ((format (printf, 1, 2)));

parti.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct option options[] = {
2727
{ "version", 0, NULL, 1002 },
2828
{ "export-disk", 1, NULL, 1003 },
2929
{ "import-disk", 1, NULL, 1004 },
30-
{ "json", 1, NULL, 1005 },
30+
{ "json", 0, NULL, 1005 },
3131
{ }
3232
};
3333

@@ -66,7 +66,7 @@ int main(int argc, char **argv)
6666
break;
6767

6868
case 1005:
69-
opt.json_file = optarg;
69+
opt.json = 1;
7070
break;
7171

7272
default:
@@ -102,7 +102,7 @@ int main(int argc, char **argv)
102102
}
103103
}
104104

105-
json_print(opt.json_file);
105+
json_print();
106106

107107
json_done();
108108

@@ -120,7 +120,7 @@ void help()
120120
"\n"
121121
"Options:\n"
122122
"\n"
123-
" --json FILE Use JSON format for output.\n"
123+
" --json Use JSON format for output.\n"
124124
" --export-disk FILE Export all relevant disk data to FILE. FILE can then be used\n"
125125
" with --import-disk to reproduce the results.\n"
126126
" --import-disk FILE Import relevant disk data from FILE.\n"

util.c

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ uint64_t read_qword_be(void *buf)
9090

9191
void log_info(const char *format, ...)
9292
{
93+
if(opt.json) return;
94+
9395
va_list args;
9496
va_start(args, format);
9597
vfprintf(stdout, format, args);

util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ typedef struct {
1818
unsigned raw:1;
1919
} show;
2020
char *export_file;
21-
char *json_file;
21+
unsigned json:1;
2222
} opt_t;
2323

2424
extern opt_t opt;

0 commit comments

Comments
 (0)