diff options
author | Karel Zak | 2015-06-05 11:58:42 +0200 |
---|---|---|
committer | Karel Zak | 2015-06-05 11:58:42 +0200 |
commit | 6a768b55165f8b09bf95fc018b771261ddf64084 (patch) | |
tree | a4b8006ab8c0077ac67881f3865bd597aed01bec | |
parent | lslocks: add --json (diff) | |
download | kernel-qcow2-util-linux-6a768b55165f8b09bf95fc018b771261ddf64084.tar.gz kernel-qcow2-util-linux-6a768b55165f8b09bf95fc018b771261ddf64084.tar.xz kernel-qcow2-util-linux-6a768b55165f8b09bf95fc018b771261ddf64084.zip |
libsmartcols: keep JSON field names lower-case
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | include/carefulputc.h | 10 | ||||
-rw-r--r-- | libsmartcols/src/table_print.c | 2 |
2 files changed, 9 insertions, 3 deletions
diff --git a/include/carefulputc.h b/include/carefulputc.h index 3a0ec5b66..681e66660 100644 --- a/include/carefulputc.h +++ b/include/carefulputc.h @@ -26,7 +26,7 @@ static inline int fputc_careful(int c, FILE *fp, const char fail) return (ret < 0) ? EOF : 0; } -static inline void fputs_quoted(const char *data, FILE *out) +static inline void fputs_quoted_case(const char *data, FILE *out, int dir) { const char *p; @@ -41,11 +41,17 @@ static inline void fputs_quoted(const char *data, FILE *out) fprintf(out, "\\x%02x", (unsigned char) *p); } else - fputc(*p, out); + fputc(dir == 1 ? toupper(*p) : + dir == -1 ? tolower(*p) : + *p, out); } fputc('"', out); } +#define fputs_quoted(_d, _o) fputs_quoted_case(_d, _o, 0) +#define fputs_quoted_upper(_d, _o) fputs_quoted_case(_d, _o, 1) +#define fputs_quoted_lower(_d, _o) fputs_quoted_case(_d, _o, -1) + static inline void fputs_nonblank(const char *data, FILE *out) { const char *p; diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index 731879cae..c743bf7bd 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -284,7 +284,7 @@ static int print_data(struct libscols_table *tb, return 0; case SCOLS_FMT_JSON: - fputs_quoted(scols_cell_get_data(&cl->header), tb->out); + fputs_quoted_lower(scols_cell_get_data(&cl->header), tb->out); fputs(": ", tb->out); if (!data || !*data) fputs("null", tb->out); |