swerc

anselm's simpler werc fork
git clone git://git.suckless.org/swerc
Log | Files | Refs | README

commit c9b8ff8441718dd00bcc9b2013ae65cc635e5de0
parent 90c3fe3f9d3d039784995ec9e038fa7ebe3dc1d7
Author: uriel@soma <unknown>
Date:   Fri, 13 Feb 2009 23:18:34 +0000

Fix bug in crop_text and make length argument optional (default is 512 chars).
Diffstat:
Mbin/cgilib.rc | 17+++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/bin/cgilib.rc b/bin/cgilib.rc @@ -160,16 +160,21 @@ fn ll_add { NEW_LINE=' ' +# crop_text [max_lenght [ellipsis]] +# TODO: Option to crop only at word-delimiters. fn crop_text { - ellipsis='...' - if(~ $#* 2) - ellipsis=$2 - - awk -v max'='^$"1^' ' -v 'ellipsis='$ellipsis ' + m=512 + e='...' + if(! ~ $#1 0) + m=$1 + if(! ~ $#2 0) + e=$2 + + awk -v 'max='^$"m -v 'ellipsis='$e ' { nc += 1 + length; if(nc > max) { - print substr($0, 1, nc - max) ellipsis + print substr($0, 1, nc - max) " " ellipsis exit } print