From: Scott Worley Date: Wed, 4 Aug 2021 18:55:02 +0000 (-0700) Subject: The prototype X-Git-Tag: v0.2.0~25 X-Git-Url: http://git.scottworley.com/tablify/commitdiff_plain/ede6233355b70ac831aa79949e0b396ba6320b99?hp=606198161ee2305f65881c1b34f3eceab169436a The prototype --- diff --git a/log2table.awk b/log2table.awk new file mode 100644 index 0000000..5188c81 --- /dev/null +++ b/log2table.awk @@ -0,0 +1,75 @@ + +# TODO: Implement quoting properly +function quote_html(s) { return s; } +function quote_html_attribute(s) { return gensub("\"", """, "g", s) } + +BEGIN { + FS = ":" + num_rows = 0 + num_cols = 0 + read_header = 1 + # h/t https://wabain.github.io/2019/10/13/css-rotated-table-header.html + print "" +} + +END { + printf "" + for (i=0; i < num_cols; i++) { + printf "", quote_html_attribute(col_headers[i]), quote_html(col_headers[i]) + } + print ""; + for (i=1*skip_rows; i <= num_rows; i++) { + spacer_row = substr(row_headers[i], 1, 1) == "!" + row_header = spacer_row ? substr(row_headers[i], 2) : row_headers[i] + printf "", quote_html_attribute(row_header), quote_html(row_header) + for (j = 0;j < num_cols; j++) { + printf "" + } + print "" + } + print "
%s
%s" rows[i][j] "
" +} + +{ + if (/^$/) { + read_header = 1 + num_rows++ + } else { + if (read_header) { + read_header = 0 + row_headers[num_rows] = $0 + } else { + if (! ($1 in col_index)) { + col_headers[num_cols] = $1 + col_index[$1] = num_cols++ + } + rows[num_rows][col_index[$1]] = $2 ? $2 : " " + } + } +}