#!/bin/bash
# to convert ~/.curfloo/commands to cannon.html
curf_coms=~/.curfloo/commands
# format i use in curfloo/commands
# command:description -> url
# Format of file:
# 1. Lines beginning with "#" and having NF>1
# are section markers.
# 2. Lines that do not begin with "#" are either:
# A. comment without URL
# B. comment with URL
# fields:
# where NF > 1,
# $1 is either # or the command used in curfloo
# $2 is either the section head (if $1 was #) or ':'
# $n may be a url, where 2 < n <= NF or
# $n may be a description of a url or
# $n may be a comment
if [ ! -f ${curf_coms} ]
then
echo "${curf_coms} is not a file"
exit
fi
tstamp=$(date "+%B %d, %Y")
grep -e ^'#' -e 'http:' ${curf_coms} |\
grep -v ^#$ |\
awk 'BEGIN{FS=":"}
{
if (substr($0,1,1)=="#"){
print $0
} else {
print substr($0, index($0,$2))
}
}' |\
awk -v modtime="${tstamp}" 'BEGIN \
{
headcnt=1
linecnt=1
}
{
# check for section head
if (($1 == "#") && (NF > 1)) {
h_txt=substr($0, index($0,$2))
gsub(/ /,"_",h_txt)
header="" h_txt ""
hd[headcnt]=h_txt
headcnt++
line[linecnt]="
" header "
\n[ backto top ]
"
linecnt++
}
# check for comment
if (($1 != "#") && (NF > 1)) {
header=""
comstart=1
comend=index($0,"http") - 1
comlength=comend - comstart
comment=substr($0, comstart, comlength)
gsub(/->/,"",comment)
line[linecnt]="
" comment "
"
linecnt++
# check each field ($fieldcnt) in current line for URL(s)
fieldcnt=1
while (fieldcnt <= NF) {
if (substr($fieldcnt,1,4)=="http") {
url=$fieldcnt
tag=url
gsub(/\//, "/ ",tag)
gsub(/\/ \/ /,"//",tag)
line[linecnt]=" " tag "
"
linecnt++
}
fieldcnt++
}
}
}
END \
{
print ""
print ""
print " "
print " "
print " the_link_cannon"
print " "
print " "
orint "
"
print " This is the \"link cannon\". Some folks asked me to post this collection of links.
"
print " The collection began as my own, but it has since been greatly augmented by the efforts of the 'regulars' in Linux, FreeBSD, Solaris:1 on Yahoo! Chat.
"
print " Conversion of the chat client curfloo commands file into this html page is not perfect, obviously. The conversion script used is http://edge-op.org/files/curf-cannon.
"
print "
Last updated: "modtime"
"
for (cnt=1; cnt [ " hd[cnt] " ] "
}
for (cnt=1; cnt"
print ""
}' > cannon.html