From: Ben Pfaff Date: Fri, 12 Feb 2010 19:34:10 +0000 (-0800) Subject: ovsdb-client: Improve HTML output. X-Git-Tag: v1.0.0~259^2~137 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=1f441586403f0fe315ff905775a3e055c088aeec;p=sliver-openvswitch.git ovsdb-client: Improve HTML output. This commit introduces links from UUIDs to rows that represent them and shortens UUIDs added to tables to their first 8 characters. This makes the output more readable. --- diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c index 45bb54c63..e7d601213 100644 --- a/ovsdb/ovsdb-client.c +++ b/ovsdb/ovsdb-client.c @@ -463,13 +463,14 @@ table_print_table__(const struct table *table) } static void -table_print_html_cell__(const char *element, const char *content) +table_escape_html_text__(const char *s, size_t n) { - const char *p; + size_t i; - printf(" <%s>", element); - for (p = content; *p != '\0'; p++) { - switch (*p) { + for (i = 0; i < n; i++) { + char c = s[i]; + + switch (c) { case '&': fputs("&", stdout); break; @@ -479,11 +480,33 @@ table_print_html_cell__(const char *element, const char *content) case '>': fputs(">", stdout); break; + case '"': + fputs(""", stdout); + break; default: - putchar(*p); + putchar(c); break; } } +} + +static void +table_print_html_cell__(const char *element, const char *content) +{ + const char *p; + + printf(" <%s>", element); + for (p = content; *p; ) { + struct uuid uuid; + + if (uuid_from_string_prefix(&uuid, p)) { + printf("%.*s", UUID_LEN, p, 8, p); + p += UUID_LEN; + } else { + table_escape_html_text__(p, 1); + p++; + } + } printf("\n", element); } @@ -492,7 +515,7 @@ table_print_html__(const struct table *table) { size_t x, y; - fputs("\n", stdout); + fputs("
\n", stdout); if (output_headings) { fputs(" \n", stdout); @@ -506,7 +529,17 @@ table_print_html__(const struct table *table) for (y = 0; y < table->n_rows; y++) { fputs(" \n", stdout); for (x = 0; x < table->n_columns; x++) { - table_print_html_cell__("td", *table_cell__(table, y, x)); + const char *content = *table_cell__(table, y, x); + + if (!strcmp(table->columns[x].heading, "_uuid")) { + fputs(" \n", stdout); + } else { + table_print_html_cell__("td", content); + } } fputs(" \n", stdout); }
", stdout); + table_escape_html_text__(content, 8); + fputs("