: ########################################################################## # Title : fmtlinks - create HTML links # Version : 1.2 # Author : Heiner Steven # Date : 2001-08-26 # Category : WWW, HTML # SCCS-Id. : @(#) fmtlinks 1.2 02/03/12 ########################################################################## # Description # Reads ASCII text from standard input, and creates HTML anchors for # URLs, e.g. "http://www.shelldorado.com" is converted to # http://www.shelldorado.com # # Handles all URL schemes described in RFC 1738 ("Uniform Resource # Locators (URL)". Converts text resembling an e-mail address to a # "mailto:" HTML anchor. # # Bugs: # o user/password parts within URLs are not handled correctly, e.g. # http://user:passwd@ftp.download.com/pub # will create an invalid HTML anchor ########################################################################## PN=`basename "$0"` # Program name VER='1.2' Usage () { echo >&2 "$PN - fmtlinks - create HTML links, $VER usage: $PN [file ...]" exit 1 } Msg () { for MsgLine do echo "$PN: $MsgLine" >&2 done } Fatal () { Msg "$@"; exit 1; } set -- `getopt h "$@"` || Usage [ $# -lt 1 ] && Usage # "getopt" detected an error while [ $# -gt 0 ] do case "$1" in # your flags here --) shift; break;; -h) Usage;; -*) Usage;; *) break;; # First file name esac shift done exec sed -e 's|\(http:[^ <>()][^ <>()]*\)|\1|g' \ -e 's|\(ftp:\([^ <>()][^ <>()]*\)\)|\2|g' \ -e 's|\(telnet:\([^ <>()][^ <>()]*\)\)|\2|g' \ -e 's|\(gopher:\([^ <>()][^ <>()]*\)\)|\2|g' \ -e 's|\(news:\([^ <>()][^ <>()]*\)\)|\2|g' \ -e 's|\(nntp:\([^ <>()][^ <>()]*\)\)|\2|g' \ -e 's|\(wais:\([^ <>()][^ <>()]*\)\)|\2|g' \ -e 's|\(file:\([^ <>()][^ <>()]*\)\)|\2|g' \ -e 's|\(prospero:\([^ <>()][^ <>()]*\)\)|\2|g' \ -e 's|mailto:||g' \ -e 's|\([^ @:][^ @:]*@[^ @:][^ @:]*\)|\1|g' \ "$@"