@@ -36,7 +36,7 @@ cell_to_text(struct cell *cell, const struct table_style *style)
3636 if (cell -> json ) {
3737 if (style -> cell_format == CF_JSON || !cell -> type ) {
3838 cell -> text = json_to_string (cell -> json , JSSF_SORT );
39- } else if ( style -> cell_format == CF_STRING ) {
39+ } else {
4040 struct ovsdb_datum datum ;
4141 struct ovsdb_error * error ;
4242 struct ds s ;
@@ -45,14 +45,16 @@ cell_to_text(struct cell *cell, const struct table_style *style)
4545 NULL );
4646 if (!error ) {
4747 ds_init (& s );
48- ovsdb_datum_to_string (& datum , cell -> type , & s );
48+ if (style -> cell_format == CF_STRING ) {
49+ ovsdb_datum_to_string (& datum , cell -> type , & s );
50+ } else {
51+ ovsdb_datum_to_bare (& datum , cell -> type , & s );
52+ }
4953 ovsdb_datum_destroy (& datum , cell -> type );
5054 cell -> text = ds_steal_cstr (& s );
5155 } else {
5256 cell -> text = json_to_string (cell -> json , JSSF_SORT );
5357 }
54- } else {
55- NOT_REACHED ();
5658 }
5759 } else {
5860 cell -> text = xstrdup ("" );
@@ -272,6 +274,34 @@ table_print_table__(const struct table *table, const struct table_style *style)
272274 free (widths );
273275}
274276
277+ static void
278+ table_print_list__ (const struct table * table , const struct table_style * style )
279+ {
280+ static int n = 0 ;
281+ size_t x , y ;
282+
283+ if (n ++ > 0 ) {
284+ putchar ('\n' );
285+ }
286+
287+ if (table -> caption ) {
288+ puts (table -> caption );
289+ }
290+
291+ for (y = 0 ; y < table -> n_rows ; y ++ ) {
292+ if (y > 0 ) {
293+ putchar ('\n' );
294+ }
295+ for (x = 0 ; x < table -> n_columns ; x ++ ) {
296+ const char * text = cell_to_text (table_cell__ (table , y , x ), style );
297+ if (style -> headings ) {
298+ printf ("%-20s: " , table -> columns [x ].heading );
299+ }
300+ puts (text );
301+ }
302+ }
303+ }
304+
275305static void
276306table_escape_html_text__ (const char * s , size_t n )
277307{
@@ -469,6 +499,8 @@ table_parse_format(struct table_style *style, const char *format)
469499{
470500 if (!strcmp (format , "table" )) {
471501 style -> format = TF_TABLE ;
502+ } else if (!strcmp (format , "list" )) {
503+ style -> format = TF_LIST ;
472504 } else if (!strcmp (format , "html" )) {
473505 style -> format = TF_HTML ;
474506 } else if (!strcmp (format , "csv" )) {
@@ -487,6 +519,8 @@ table_parse_cell_format(struct table_style *style, const char *format)
487519{
488520 if (!strcmp (format , "string" )) {
489521 style -> cell_format = CF_STRING ;
522+ } else if (!strcmp (format , "bare" )) {
523+ style -> cell_format = CF_BARE ;
490524 } else if (!strcmp (format , "json" )) {
491525 style -> cell_format = CF_JSON ;
492526 } else {
@@ -503,6 +537,10 @@ table_print(const struct table *table, const struct table_style *style)
503537 table_print_table__ (table , style );
504538 break ;
505539
540+ case TF_LIST :
541+ table_print_list__ (table , style );
542+ break ;
543+
506544 case TF_HTML :
507545 table_print_html__ (table , style );
508546 break ;
0 commit comments