-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_html.awk
70 lines (63 loc) · 2.15 KB
/
output_html.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/awk -f
#
# DATEX - Textual database library for Shell Script
#
# Copyright (c) 2021 Flavio Augusto (@facmachado)
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE file for details.
#
function trim(x) {
sub(/^ */, "", x)
sub(/ *$/, "", x)
return x
}
BEGIN {
title = "DATEX - output_html"
"date" | getline date
}
$0 == "" {
next
}
!h[$1]++ {
if ($1 == "id") {
head = " <tr>\n"
}
head = head " <th>" $1 "</th>\n"
if ($1 == "del") {
head = head " </tr>\n"
}
}
{
value = ""
for (i = 3; i <= NF; i++) {
value = value " " $i
}
if ($1 == "id") {
line = line " <tr>\n"
}
line = line " <td>" trim(value) "</td>\n"
if ($1 == "del") {
line = line " </tr>\n"
}
}
END {
printf "<!doctype html>\n" \
"<html>\n" \
"<head>\n" \
" <title>" title "</title>\n" \
"</head>\n" \
"<body>\n" \
" <h1>" title "</h1>\n" \
" <hr>\n" \
" <table border=\"1\" cellpadding=\"4\" cellspacing=\"1\">\n" \
" <thead>\n" head " </thead>\n" \
" <tbody>\n" line " </tbody>\n" \
" </table>\n" \
" <hr>\n" \
" <i>Generated on " date ".<br>Get DATEX on <a href=\"https://github.c" \
"om/facmachado/datex\" target=\"_blank\">https://github.com/facmachado/" \
"datex</a></i>\n" \
"</body>\n" \
"</html>\n"
}