]> mj.ucw.cz Git - libucw.git/commitdiff
Xtypes: Documentation cleanup
authorMartin Mares <mj@ucw.cz>
Fri, 16 Jan 2015 15:23:47 +0000 (16:23 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 16 Jan 2015 15:23:47 +0000 (16:23 +0100)
Many missing bits have been added, many a wording has been polished.

The man page for table options has been moved to section 5, as it
describes a general convention, not a program.

ucw/doc/Makefile
ucw/doc/index.txt
ucw/doc/relnotes.txt
ucw/doc/table.txt
ucw/doc/ucw-tableprinter.1.txt [deleted file]
ucw/doc/ucw-tableprinter.5.txt [new file with mode: 0644]
ucw/table.h
ucw/xtypes-extra.h

index 9c09efe2fdc2c8ee6abd9ad6ccb9db604a383aab..26afcd6ed91bd0fc4e011feef97b3d956611a43a 100644 (file)
@@ -6,7 +6,7 @@ UCW_DOCS=basics log fastbuf index config configure install basecode hash docsys
 UCW_INDEX=$(o)/ucw/doc/def_index.html
 UCW_DOCS_HTML=$(addprefix $(o)/ucw/doc/,$(addsuffix .html,$(UCW_DOCS)))
 
-UCW_MANPAGES=ucw-tableprinter.1
+UCW_MANPAGES=ucw-tableprinter.5
 UCW_MANPAGES_HTML=$(patsubst %,$(o)/ucw/doc/%.html,$(UCW_MANPAGES))
 UCW_MANPAGES_NROFF=$(addprefix $(o)/ucw/doc/,$(UCW_MANPAGES))
 MANPAGES+=$(UCW_MANPAGES_NROFF)
index 9d439184d90914a0e5afb40891a63f72e1d206ba..5d20d5e609a358bdbe8a51c6026976e231176baf 100644 (file)
@@ -46,7 +46,8 @@ Modules
 - <<daemon:,Daemon helpers>>
 - <<signal:,Signal helpers>>
 - <<opt:,Command line parser>>
-- <<table:,Table printer>>
+- <<table:,Table printer>> and its <<ucw-tableprinter.5:,options>>
+- <<xtypes:,Extended data types>>
 
 Other features
 --------------
index 94d626d319cbec28d0b4de13b9392fd508fee047..85e64f37f291c62d5a6c457b866dc329eb806d10 100644 (file)
@@ -6,6 +6,7 @@ Release notes
 * Fixed race conditions in <<daemon:,daemon helpers>>.
 * The <<xtypes:,extended types>> have been documented and integrated
   in the table printer, command-line option parser, and configuration parser.
+* The <<ucw-tableprinter.5:,table printer options>> have been documented.
 
 6.1 (2014-08-09)
 ----------------
index 65cd291bc82b0c1e89ee15315dd9de7b9b5d86bf..94d910121586e2047c5620ad6e7b69a6149d23cc 100644 (file)
@@ -4,34 +4,23 @@ Table printer
 The table printer module provides formatting of 2-dimensional tables
 in various ways.
 
-Each table print-out consists of a number of rows, which are processed
-one after another. All rows have the same number of columns.
-Internally, the columns have a fixed order, each column has its name
-and a data type (e.g., int, uint, u64, etc.). The data type is
-realized using extended types (referred to as xtypes). The table
-printer checks that each cell is filled by a value of the appropriate
-type, except that a string value is allowed in any cell (for example,
-this allows a numeric cell to be set to "--" or "unknown"). Once a
-table is defined, it can be printed using a variety of formatters
-(human-readable, tab-separated values, etc.) and its cells can be
-formatted using at least three different formats: 1) pretty (or
-human-readable); 2) raw; 3) default.
-
-The table definition consists of various column types, each column
-type is a pair consisting of a name and a data type. Name of each
-column must be unique in the whole table definition.  Each column type
-can have multiple instances in the final table print-out. The columns
-are printed using xtypes.  For example: let have a column definition
-with name 'size' of type xt_size. The column can be printed on
-position 0 (in bytes) and position 5 (in kilobytes).  This allows easy
-filtering using standart cmd line filters. For example, we want to
-remove all rows that has size greater then 1572864 bytes (1.5MB) and
-print the size in human readable format. Human readable format means
-that if there is size of 1610612736 bytes it will be rather printed as
-1536MB.
-
-Also, columns can be printed in an arbitrary order and with repeated
-columns.
+Each table print-out consists of a number of 'rows', which are processed
+one after another. All rows have the same number of 'columns', each intersection
+of a row with a column is called a 'cell'. Each cell holds data, represented
+using the <<xtypes:,extended types>> (a.k.a. 'xtypes'). The table printer
+checks that the cells are filled by values of the appropriate types;
+additionally, a string value is allowed in any cell (for example,
+this allows a numeric cell to be set to "--" or "unknown").
+
+Once a table is defined, it can be printed using a variety of 'formatters'
+(human-readable, tab-separated values, etc.) and its cells can be formatted
+using at least three different formats: pretty (or human-readable), raw,
+default. Formatting of cells is handled by the xtype module.
+
+The order of columns can be modified, columns can be omitted, or even printed
+multiple times with different formatting options. We therefore distinguish
+between columns (according to the definition of the table) and 'column
+instances' (in the specific print-out).
 
 Example
 -------
diff --git a/ucw/doc/ucw-tableprinter.1.txt b/ucw/doc/ucw-tableprinter.1.txt
deleted file mode 100644 (file)
index fb42eb7..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-UCW-TABLEPRINTER(1)
-===================
-
-NAME
-----
-
-ucw-tableprinter - UCW table printer is a program module that allows user-customized printing of tables.
-
-DESCRIPTION
------------
-
-The table printer module provides formatting of 2-dimensional tables
-in various ways.
-
-Each table print-out consists of a number of rows, which are processed
-one after another. All rows have the same number of columns. Once a
-table is defined, it can be printed using a variety of formatters
-(block-line, human-readable, machine-readable, etc.).
-
-The table definition consists of various column definitions, each
-column definition is a pair consisting of a name and a type. Name of
-each column must be unique in the whole table. Each column definition
-can be instantiated(printed) in its own format, e.g., a size column
-can be printed three-times: 1) in bytes; 2) in gigabytes; 3)
-human-readable.
-
-The table can be controlled using various options:
-
-[options="header"]
-|===============================================================================================================
-| option      | argument                    | meaning
-| `header`    | 0 or 1                      | set whether a table header should be printed
-| `noheader`  | 'none'                      | equivalent to `header`=0
-| `cols`      | comma-separated column list | set order of columns
-| `fmt`              | `human`/`machine`/`block`   | set table formatter to one of the built-in formatters
-| `col-delim` | string                      | set column delimiter
-| `cells`     | string                      | set column cell format mode, possibilities are: default, raw, pretty
-| `raw`              | 'none'                      | set column cell format to raw data, equivalent to cells:raw
-| `pretty`    | 'none'                      | set column cell format to pretty-printing, equivalent to cells:pretty
-|===============================================================================================================
-
-Column order (`cols` option) has the following format:
-
-<col-order-string> := <col-def>[,<col-def>]*
-
-<col-def> := <col-name> [ '[' <col-opts> ']' ]
-
-<col-name> is a string that does not contain comma ',' or '[',']' brackets
-
-<col-opts> := <string> [ ',' <string> ]
-
-Where <col-opts> is a comma-separated list of options.
-
-Column delimiter option (`col-delim`) can be an arbitrary string. The
-cell format option `cells` can have one of the possible three values:
-1) `pretty`, 2) `default`, 3) `raw`. The `raw` and `pretty` value of
-`cells` option can be shortcutted as options `raw` and `pretty` with
-no value.
-
-Additionally to standard types (like integer, floating point) there
-are the two following types: 1) size; 2) timestamp. The 'size' type
-has the following case-sensitive column options: `KB`, `MB`, `GB`,
-`TB`, `auto`, e.g., a column of type size and name `file-size` can be
-specified as `file-size[MB]` or `file-size[auto]`.  The 'timestamp'
-has the following case-sensitive column options: 1) `datetime` which
-corresponds to date(1) format "%F %T", 2) `timestamp` which
-corresponds to a number of seconds relative to start of some epoch.
-
-Description of table formats
-----------------------------
-
-'human-readable': prints columns separated by single space, rows
-separated by newline '\n'.
-
-'block-line': prints each column on one line, i.e., the column
-separator is '\n', rows are separated by double newlines
-'\n\n'. Therefore, rows forms newline separated blocks of rows.
-
-'machine-readable': prints columns separated by a tabulator '\t', rows
-separated by '\n'.
diff --git a/ucw/doc/ucw-tableprinter.5.txt b/ucw/doc/ucw-tableprinter.5.txt
new file mode 100644 (file)
index 0000000..5928abc
--- /dev/null
@@ -0,0 +1,88 @@
+UCW-TABLEPRINTER(5)
+===================
+
+NAME
+----
+
+ucw-tableprinter - a program module for customizable printing of tables.
+
+DESCRIPTION
+-----------
+The table printer module is a part of the LibUCW library. It provides formatting
+of 2-dimensional tables in various ways. Users seldom interact with the table
+printer itself, but programs using it often provide means for customizing table
+output by passing options.
+
+This manual page describes the overall logic of the table printer and its
+options.
+
+Each table print-out consists of a number of rows, which are processed
+one after another. All rows have the same number of columns. Once a
+table is defined, it can be printed using a variety of formatters
+(block-line, human-readable, machine-readable, etc.).
+
+The table definition consists of various column definitions, each
+column definition is a pair consisting of a name and a type. Name of
+each column must be unique in the whole table. Each column definition
+can be instantiated (printed) in its own format, e.g., a size column
+can be printed three times: first in bytes, then in gigabytes, and
+finally in a human-readable form.
+
+The table can be controlled using various options:
+
+[options="header"]
+|===============================================================================================================
+| option      | argument                    | meaning
+| `header`    | 0 or 1                      | set whether a table header should be printed
+| `noheader`  | 'none'                      | equivalent to `header:0`
+| `cols`      | comma-separated column list | set order of columns and per-column options (see below)
+| `fmt`              | `human`/`machine`/`block`   | set table formatter to one of the built-in formatters (see below)
+| `col-delim` | string                      | set column delimiter
+| `cells`     | string                      | set column cell format mode, possibilities are: `default`, `raw`, `pretty`
+| `raw`              | 'none'                      | set column cell format to raw data, equivalent to `cells:raw`
+| `pretty`    | 'none'                      | set column cell format to pretty-printing, equivalent to `cells:pretty`
+|===============================================================================================================
+
+Table formats
+-------------
+The `fmt` option sets the overall format of the table. Currently,
+the following formats are available:
+
+* 'human-readable' (`human`): prints columns separated by a single space, rows
+separated by a newline character (ASCII 0x0a).
+
+* 'machine-readable' (`machine`): prints columns separated by a tab character (ASCII 0x09),
+rows separated by a newline character.
+
+* 'block-line' (`block`): prints each column on one line, rows separated by a single
+blank line. That is, the column separator is set to the newline character
+and an extra newline is printed at the end of each row.
+
+Column definitions
+------------------
+The `cols` option allows to specify a list of table columns and their options.
+For instance, you can use `name,size[raw],size[pretty]` to request a table with three columns:
+name, size as a raw value, and the same size pretty-printed.
+
+Formally, the argument of the `cols` option follows this grammar:
+
+  <col-order-string> := <col-def>[,<col-def>]*
+  <col-def> := <col-name> [ '[' <col-opts> ']' ]
+  <col-name> contains no commas nor square brackets
+  <col-opts> := <col-opt> [ ',' <col-opt> ]
+  <col-opt> contains no commas nor square brackets
+
+Column options
+--------------
+All column types accept these standard formatting modes:
+
+* `default`: human-readable, but not hostile to machine parsing
+* `raw`: raw data with no frills
+* `pretty`: tries to please humans (e.g., like `ls -h`)
+
+There are also formatting modes specific for particular column types:
+
+* Sizes can be given a unit (`KB`, `MB`, `GB`, `TB`, or `auto`; case-insensitive).
+* Timestamps can be formatted as `timestamp` or `epoch` (both are seconds since the
+  Unix epoch), or `datetime` (corresponds to date(1) format `"%F %T"`. Currently,
+  `raw` is an alias for `timestamp` and `pretty` is the same as `datetime`.
index 88f721c775e1e8352d7284eca45f9b524fc09875..494276bada5f4d14a95de042d5a468c01390961e 100644 (file)
@@ -151,7 +151,7 @@ struct table {
  *  * `TBL_COL_`'type'`_FMT(name, width, fmt)` defines a column with a custom format string
  *  * `TBL_COL_END` ends the column definitions
  *  * `TBL_COL_ORDER` specifies custom ordering of columns in the output
- *  * `TBL_COL_DELIMITER` and `TBL_APPEND_DELIMITER` override default delimiters
+ *  * `TBL_COL_DELIMITER` overrides the default delimiter
  *  * `TBL_FMT_HUMAN_READABLE` requests human-readable formatting (this is the default)
  *  * `TBL_FMT_MACHINE_READABLE` requests machine-readable TSV output
  *  * `TBL_FMT_BLOCKLINE` requests block formatting (each cell printed a pair of a key and value on its own line)
@@ -238,7 +238,6 @@ void table_end(struct table *tbl);
  *     to the `value`
  ***/
 
-
 #define TABLE_COL_PROTO(_name, _type) void table_col_##_name(struct table *tbl, int col, _type val);
 
 TABLE_COL_PROTO(int, int)
@@ -304,14 +303,16 @@ void table_reset_row(struct table *tbl);
 int table_get_col_idx(struct table *tbl, const char *col_name);
 
 /**
- * Sets a string option to an instance of a column type. This is the default version that checks
- * whether the xtype::parse_fmt can be called and calls it. However, there are situation in which
- * the xtype::parse_fmt is not sufficient, e.g., column decoration, post-processing, etc.
+ * Sets a string option on a column instance.
+ *
+ * By default, the option is parsed as a formatting mode of the corresponding <<xtypes:,xtype>>
+ * using <<xtypes:fun_xtype_parse_fmt,`xtype_parse_fmt()`>>.
  *
- * Each struct table_column has a pointer to a customized version of table_set_col_opt (called
- * set_col_opt). The hook set_call_opt should be always called through @table_set_col_opt. The hook
- * and @table_set_col_opt has the same prototype, but @table_set_col_opt should never be used as the
- * table_set_opt hook.
+ * As special cases might require special handling (e.g., column decoration, post-processing, etc.),
+ * a column can define a `set_col_opt` hook, which takes over option parsing. (Beware, the hook must
+ * not be called directly and it must not call this function.)
+ *
+ * See <<ucw-tableprinter.5:,the list of options>> for more.
  **/
 const char *table_set_col_opt(struct table *tbl, uint col_inst_idx, const char *col_opt);
 
@@ -337,15 +338,7 @@ void table_set_col_order(struct table *tbl, const struct table_col_instance *col
  * names. Returns NULL for success and an error message otherwise. The string is not referenced after
  * this function returns.
  *
- * The format of the col_order string is the following:
- * <col-order-string> := <col-def>[,<col-def>]*
- *
- * <col-def> := <col-name> [ '[' <col-opts> ']' ]
- *
- * <col-name> is a string that does not contain comma ',' or '[',']' brackets
- *
- * <col-opts> := <string> [ ',' <string> ]
- *  - <col-opts> is a comma-separated list of options
+ * See <<ucw-tableprinter.5:,the list of options>> for full syntax.
  **/
 const char *table_set_col_order_by_name(struct table *tbl, const char *col_order);
 
@@ -360,21 +353,8 @@ bool table_col_is_printed(struct table *tbl, uint col_def_idx);
 void table_set_formatter(struct table *tbl, const struct table_formatter *fmt);
 
 /**
- * Set a table option. All options have a key and a value. Currently,
- * the following keys are defined (other keys can be accepted by formatters):
- *
- * [options="header"]
- * |===================================================================================================
- * | key       | value                         | meaning
- * | `header`  | 0 or 1                        | set whether a table header should be printed
- * | `noheader`        | 'none'                        | equivalent to `header`=0
- * | `cols`    | comma-separated column list   | set order of columns
- * | `fmt`     | `human`/`machine`/`block`     | set table formatter to one of the built-in formatters
- * | `col-delim`| string                       | set column delimiter
- * | `cells`    | string                        | set column format mode
- * | `raw`     | 'none'                        | set column format to raw data
- * | `pretty`  | 'none'                        | set column format to pretty-printing
- * |===================================================================================================
+ * Set a table option. All options have a key and a value.
+ * See <<ucw-tableprinter.5:,the list of options>>.
  **/
 const char *table_set_option_value(struct table *tbl, const char *key, const char *value);
 
index fc94a96925f9ec021369aa10f4e601eea095aa75..e82a7c1bccbc3ff2075012b257ba39b3c0fdba7b 100644 (file)
@@ -37,7 +37,10 @@ enum size_units {
   XT_SIZE_UNIT_AUTO
 };
 
-/** Custom formatting mode: use a specified unit (`XT_SIZE_UNIT_`'xxx') **/
+/**
+ * Custom formatting mode: use a specified unit (`XT_SIZE_UNIT_`'xxx').
+ * Textual representation of the mode is the name of the unit (case-insensitive).
+ **/
 #define XT_SIZE_FMT_UNIT(_unit) (_unit | XT_SIZE_FMT_FIXED_UNIT)
 #define XT_SIZE_FMT_FIXED_UNIT XTYPE_FMT_CUSTOM
 
@@ -53,7 +56,16 @@ TABLE_COL_PROTO(size, u64)
  * `xt_timestamp` is a timestamp, internally represented as `time_t`.
  ***/
 
+/**
+ * Custom formatting mode: seconds since Unix epoch. Currently,
+ * this is the same as the raw format. Textual representation: `timestamp` or `epoch`.
+ **/
 #define XT_TIMESTAMP_FMT_EPOCH     XTYPE_FMT_RAW
+
+/**
+ * Custom formatting mode: date and time. Currently, this is the same
+ * as the human-readable format. Textual representation: `datetime`.
+ **/
 #define XT_TIMESTAMP_FMT_DATETIME  XTYPE_FMT_PRETTY
 
 extern const struct xtype xt_timestamp;