#!/usr/athena/bin/perl
# $Id: fmt.pl,v 1.1 1999/04/27 19:21:34 danw Exp $

# This is basically like the fmt utility, but customized to cope with
# the output of rtf2text and lhalw. Every line is one paragraph, so
# output blank lines between them and don't indent the whole paragraph
# to the indentation of the first line.

# Doesn't cope well with code, patches and other things that shouldn't
# be line-wrapped and shouldn't have blank lines between every
# "paragraph". But if you send those as RTF/Word, you deserve to lose.

while (<>) {
    if (length() < 72) { print; }
    else {
	$len = 0;
	# We want to preserve multiple spaces and tabbing, so split on
	# / / instead of the default of /\s+/.
	foreach $word (split(/ /,$_)) {
	    if (!$len) {
		print $word;
	    } elsif ($len + length($word) < 71) {
		print " $word";
	    } else {
		print "\n$word";
		$len = 0;
	    }
	    $len += length($word) + 1;
	}
    }
    print "\n";
}
