: ########################################################################## # Title : quote - quote text # Author : Heiner Steven # Date : 1994-02-11 # Requires : fmt, tab # Category : Text Utilities # SCCS-Id. : @(#) quote 1.6 04/02/18 ########################################################################## # Description ########################################################################## PN=`basename "$0"` # program name VER='1.6' : ${AWK:=nawk} : ${WORDWRAP:=fmt} : ${WORDWRAPFLAGS='-c -w "$width"'} Usage () { echo "$PN - quote text, $VER (stv '94) usage: $PN [file ...]" >&2 exit 1 } Msg () { for i do echo "$PN: $i" >&2 done } Fatal () { Msg "$@"; exit 1; } while [ $# -gt 0 ] do case "$1" in # Your flags here --) shift; break;; -h) Usage;; -*) Usage;; *) break;; # First file name esac shift done [ -x /usr/5bin/pr ] && DETAB="/usr/5bin/pr -e -t" : ${DETAB:='tab -e'} QuoteStr=" > " # string to prepend to every line Length=64 # number of characters per line Dequote=${TMPDIR:=/tmp}/q$$ trap "rm -f $Dequote > /dev/null 2>&1" 0 trap "exit 2" 1 2 3 15 Quote () { # "Unquoted" text is in $Dequote, Quotestring is in $OldQuote OldQuote="`dequote 2> $Dequote | $DETAB 2> /dev/null`" qlen=`expr "X$OldQuote" : '.*'` # length of quote string #echo >&2 "oldquote=<$OldQuote>, length=<$qlen>" qlen=`expr ${qlen:-1} - 1` # "X" did not belong to string #echo >&2 "oldquote=<$OldQuote>, length=<$qlen> Length=<$Length>" [ ${qlen:=0} -gt $Length ] && qlen=0 width=`expr $Length - $qlen` [ ${width:-0} -lt 5 ] && width=$Length : ${width:=$Length} eval "$WORDWRAP $WORDWRAPFLAGS" < $Dequote | sed "s:^:$QuoteStr$OldQuote:" } if [ $# -lt 1 ] then Quote # read from stdin else for i do Quote < "$i" done fi exit 0