| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# creates a RPM compatible ChangeLog file from babelweb/changes.html |
| 4 |
# (published at https://www.gpsbabel.org) |
| 5 |
# |
| 6 |
# !!! input from stdin and output to stdout !!! |
| 7 |
# |
| 8 |
|
| 9 |
LANG='POSIX'; export LANG > /dev/null |
| 10 |
# Prefer GNU sed. |
| 11 |
PATH=/opt/local/libexec/gnubin:$PATH |
| 12 |
|
| 13 |
sed -e 's/^[ \t]*//;s/[ \t]*$//' | # trim leading and trailing spaces |
| 14 |
sed -e 's/ < / \< /g' -e 's/ > /\> /g' | # try replace some unhandled html operators |
| 15 |
sed -e :a -e 's/<[^<]*>/ /g;/</{N;s/\n/ /;ba;}' | # remove most html tags |
| 16 |
sed -e 's/ / /g' -e 's/&/\&/g' -e 's/>/\>/g' -e 's/</\</g'| # replace HTML special chars |
| 17 |
sed -e 's/^[ \t]*//;s/[ \t]*$//' | # trim leading and trailing spaces |
| 18 |
sed -e 's/ / /g' | # remove double (or more) spaces |
| 19 |
awk ' # create list with line format YYYY-MM-DD <comment> |
| 20 |
BEGIN { line=0; item=0; OUTP="" } |
| 21 |
/^20[0-9][0-9]-[0-9][0-9]-/ { # this will be work until 2099 |
| 22 |
line++ |
| 23 |
item=0 |
| 24 |
if (length(OUTP) > 0) |
| 25 |
{ |
| 26 |
printf("%s\n", OUTP) |
| 27 |
OUTP="" |
| 28 |
} |
| 29 |
printf("%s", substr($0, 1, 10)) |
| 30 |
next |
| 31 |
} |
| 32 |
{ if (line==0) next } # skip header stuff |
| 33 |
{ |
| 34 |
item++; |
| 35 |
if (item==1) |
| 36 |
{ |
| 37 |
if (length($0) > 0) OUTP=sprintf(" %s:", $0) |
| 38 |
next |
| 39 |
} |
| 40 |
else if (length($0) > 0) |
| 41 |
{ |
| 42 |
OUTP=sprintf("%s %s", OUTP, $0) |
| 43 |
next |
| 44 |
} |
| 45 |
} |
| 46 |
END { if (length(OUTP) > 0) printf("%s\n", OUTP) } |
| 47 |
' | |
| 48 |
sort -r | # keep sure, lines "YYYY-MM-DD ....." are sorted in descending order |
| 49 |
uniq | # and remove duplicates |
| 50 |
awk ' |
| 51 |
BEGIN { TMx=0 } |
| 52 |
{ |
| 53 |
DT=sprintf("%s %s %s 00 00 00", substr($0, 1, 4), substr($0, 6, 2), substr($0, 9, 2)) |
| 54 |
TM=mktime(DT) |
| 55 |
if (TM != TMx) |
| 56 |
{ |
| 57 |
TX=strftime("%a %b %d %Y", TM) |
| 58 |
printf("* %s https://www.gpsbabel.org\n", TX) |
| 59 |
TMx = TM |
| 60 |
} |
| 61 |
OUTP=substr($0, 11) |
| 62 |
while (substr(OUTP, 1, 1) <= " " ) { OUTP=substr(OUTP, 2) } |
| 63 |
printf("- %s \n", OUTP) |
| 64 |
next |
| 65 |
} |
| 66 |
' |