diff options
author | Manuel Bentele | 2020-09-08 15:07:31 +0200 |
---|---|---|
committer | Manuel Bentele | 2020-09-16 07:37:56 +0200 |
commit | efc492d327ea6a9658674eb9e971aff3742818cd (patch) | |
tree | 72a3e3e61ee3cbc7df4059ee24ae95487c265b60 /utils/libsmartcols/src/fput.c | |
parent | Added file format file format subsystem for loop devices (diff) | |
download | xloop-efc492d327ea6a9658674eb9e971aff3742818cd.tar.gz xloop-efc492d327ea6a9658674eb9e971aff3742818cd.tar.xz xloop-efc492d327ea6a9658674eb9e971aff3742818cd.zip |
Added patched losetup utility to configure xloop devices
Diffstat (limited to 'utils/libsmartcols/src/fput.c')
-rw-r--r-- | utils/libsmartcols/src/fput.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/utils/libsmartcols/src/fput.c b/utils/libsmartcols/src/fput.c new file mode 100644 index 0000000..b00c3d8 --- /dev/null +++ b/utils/libsmartcols/src/fput.c @@ -0,0 +1,97 @@ +#include "carefulputc.h" +#include "smartcolsP.h" + +void fput_indent(struct libscols_table *tb) +{ + int i; + + for (i = 0; i <= tb->indent; i++) + fputs(" ", tb->out); +} + +void fput_table_open(struct libscols_table *tb) +{ + tb->indent = 0; + + if (scols_table_is_json(tb)) { + fputc('{', tb->out); + fputs(linesep(tb), tb->out); + + fput_indent(tb); + fputs_quoted(tb->name, tb->out); + fputs(": [", tb->out); + fputs(linesep(tb), tb->out); + + tb->indent++; + tb->indent_last_sep = 1; + } +} + +void fput_table_close(struct libscols_table *tb) +{ + tb->indent--; + + if (scols_table_is_json(tb)) { + fput_indent(tb); + fputc(']', tb->out); + tb->indent--; + fputs(linesep(tb), tb->out); + fputc('}', tb->out); + tb->indent_last_sep = 1; + } +} + +void fput_children_open(struct libscols_table *tb) +{ + if (scols_table_is_json(tb)) { + fputc(',', tb->out); + fputs(linesep(tb), tb->out); + fput_indent(tb); + fputs("\"children\": [", tb->out); + } + /* between parent and child is separator */ + fputs(linesep(tb), tb->out); + tb->indent_last_sep = 1; + tb->indent++; + tb->termlines_used++; +} + +void fput_children_close(struct libscols_table *tb) +{ + tb->indent--; + + if (scols_table_is_json(tb)) { + fput_indent(tb); + fputc(']', tb->out); + fputs(linesep(tb), tb->out); + tb->indent_last_sep = 1; + } +} + +void fput_line_open(struct libscols_table *tb) +{ + if (scols_table_is_json(tb)) { + fput_indent(tb); + fputc('{', tb->out); + tb->indent_last_sep = 0; + } + tb->indent++; +} + +void fput_line_close(struct libscols_table *tb, int last, int last_in_table) +{ + tb->indent--; + if (scols_table_is_json(tb)) { + if (tb->indent_last_sep) + fput_indent(tb); + fputs(last ? "}" : "},", tb->out); + if (!tb->no_linesep) + fputs(linesep(tb), tb->out); + + } else if (tb->no_linesep == 0 && last_in_table == 0) { + fputs(linesep(tb), tb->out); + tb->termlines_used++; + } + + tb->indent_last_sep = 1; +} |