Commit Graph

7 Commits

Author SHA1 Message Date
Thomas Weißschuh f48554d48b libsmartcols: add support for optional boolean values
These default to `null` instead of `false`.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2021-05-30 23:17:23 +02:00
Karel Zak 64a89adaa1 lib/jsonwrt: don't use ctype.h for ASCII chars
tolower() does not work "as expected" for tr_TR.UTF-8 (Turkish).
Fortunately, we need to convert only objects and variables names in
JSON output, and this is always old good ASCII.

Anyway, for more details:

	$ cat a.c
	#include <ctype.h>
	#include <stdio.h>
	#include <locale.h>

	int main(void)
	{
		int in, out;

		setlocale(LC_ALL, "");

		in ='I';
		out = tolower(in);

		printf("%1$c [%1$d] --> %2$c [%2$d]\n", in, out);
		return 0;
	}

	$ make a
	cc     a.c   -o a

	$ LANG=en_US.utf8 ./a
	I [73] --> i [105]

	$ LANG=tr_TR.UTF-8 ./a
	I [73] --> I [73]

Fixes: https://github.com/karelzak/util-linux/issues/1302
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 16:35:50 +02:00
Karel Zak 3a07505a39 lib/jsonwrt: remove fputs_quoted_json_* functions from include/carefulputc.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 16:05:56 +02:00
Karel Zak d124a78034 lib/jsonwrt: remove 'islast' from API
The code should be able to keep track about previous content and print
JSON objects separator automatically.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 15:58:02 +02:00
Karel Zak 3c7355dd63 libsmartcols: support arrays for JSON output
This patch add support to format multi-line cells (columns with
SCOLS_FL_WRAP) to arrays in JSON output.

For example mountpoints[] in lsblk output:

Normal output:
	 $ lsblk -oNAME,FSTYPE,TYPE,MOUNTPOINTS /dev/sdc1
	 NAME FSTYPE TYPE MOUNTPOINTS
	 sdc1 btrfs  part /mnt/A
			  /mnt/test
			  /mnt/B

JSON output:
	$ lsblk -J -oNAME,FSTYPE,TYPE,MOUNTPOINTS /dev/sdc1
	{
	   "blockdevices": [
	      {
		 "name": "sdc1",
		 "fstype": "btrfs",
		 "type": "part",
		 "mountpoints": [
		     "/mnt/A",
		     "/mnt/test",
		     "/mnt/B"
		 ]
	      }
	   ]
	}

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-08 13:12:57 +01:00
Karel Zak e434cf2cdb lib/jsonwrt: use proper output function
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-12 11:38:55 +01:00
Karel Zak 37bcd05602 lib/jsonwrt: add new functions to write in JSON
We need JSON formatting stuff also outside libsmartcols.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-12 11:19:13 +01:00