mirror of
https://github.com/json-c/json-c.git
synced 2026-04-09 23:39:06 +08:00
Fix printf format issues in apps/json_parse, and actually call the usage() function.
This commit is contained in:
@@ -31,7 +31,7 @@ static const char *fname = NULL;
|
|||||||
#define json_tokener_get_parse_end(tok) ((tok)->char_offset)
|
#define json_tokener_get_parse_end(tok) ((tok)->char_offset)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void usage(int exitval, const char *errmsg);
|
static void usage(const char *argv0, int exitval, const char *errmsg);
|
||||||
static void showmem(void);
|
static void showmem(void);
|
||||||
static int parseit(int fd, int (*callback)(struct json_object *));
|
static int parseit(int fd, int (*callback)(struct json_object *));
|
||||||
static int showobj(struct json_object *new_obj);
|
static int showobj(struct json_object *new_obj);
|
||||||
@@ -42,7 +42,7 @@ static void showmem(void)
|
|||||||
struct rusage rusage;
|
struct rusage rusage;
|
||||||
memset(&rusage, 0, sizeof(rusage));
|
memset(&rusage, 0, sizeof(rusage));
|
||||||
getrusage(RUSAGE_SELF, &rusage);
|
getrusage(RUSAGE_SELF, &rusage);
|
||||||
printf("maxrss: %d KB\n", rusage.ru_maxrss);
|
printf("maxrss: %ld KB\n", rusage.ru_maxrss);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,14 +137,14 @@ static int showobj(struct json_object *new_obj)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(int exitval, const char *errmsg)
|
static void usage(const char *argv0, int exitval, const char *errmsg)
|
||||||
{
|
{
|
||||||
FILE *fp = stdout;
|
FILE *fp = stdout;
|
||||||
if (exitval != 0)
|
if (exitval != 0)
|
||||||
fp = stderr;
|
fp = stderr;
|
||||||
if (errmsg != NULL)
|
if (errmsg != NULL)
|
||||||
fprintf(fp, "ERROR: %s\n\n", errmsg);
|
fprintf(fp, "ERROR: %s\n\n", errmsg);
|
||||||
fprintf(fp, "Usage: %s [-f] [-n] [-s]\n");
|
fprintf(fp, "Usage: %s [-f] [-n] [-s]\n", argv0);
|
||||||
fprintf(fp, " -f - Format the output with JSON_C_TO_STRING_PRETTY\n");
|
fprintf(fp, " -f - Format the output with JSON_C_TO_STRING_PRETTY\n");
|
||||||
fprintf(fp, " -n - No output\n");
|
fprintf(fp, " -n - No output\n");
|
||||||
fprintf(fp, " -s - Parse in strict mode, flags:\n");
|
fprintf(fp, " -s - Parse in strict mode, flags:\n");
|
||||||
@@ -160,14 +160,15 @@ int main(int argc, char **argv)
|
|||||||
json_object *new_obj;
|
json_object *new_obj;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "fns")) != -1)
|
while ((opt = getopt(argc, argv, "fhns")) != -1)
|
||||||
{
|
{
|
||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
case 'f': formatted_output = 1; break;
|
case 'f': formatted_output = 1; break;
|
||||||
case 'n': show_output = 0; break;
|
case 'n': show_output = 0; break;
|
||||||
case 's': strict_mode = 1; break;
|
case 's': strict_mode = 1; break;
|
||||||
default: /* '?' */ fprintf(stderr, "Usage: %s [-f]\n", argv[0]); exit(EXIT_FAILURE);
|
case 'h': usage(argv[0], 0, NULL);
|
||||||
|
default: /* '?' */ usage(argv[0], 1, "Unknown arguments");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user