#! /bin/perl ############################################################################# # # $Source: /share/local/bin/RCS/hang,v $ # $Revision: 1.2 $ # $Date: 1999/09/08 02:01:55 $ # $Author: mhansen $ # $Locker: $ # $State: Exp $ # # Purpose: set hanging indent # # Directions: expects data on stdin and outputs to stdout # sets indent to same as first line # # Default Location: /share/local/bin # # Invoked by: mapped in .exrc # # Copyright (C) 1996 Marc Hansen # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General Public # License as published by the Free Software Foundation available at: # http://http://www.gnu.org/copyleft/gpl.html # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # ############################################################################# # # # REVISION HISTORY: # # $Log: hang,v $ # Revision 1.2 1999/09/08 02:01:55 mhansen # Revision 1.1 1997/11/14 02:01:55 mhansen # Initial revision # # # # # Process option args # use Getopt::Std; getopts ('wbn'); # # Get first line # $_=; # seperate white space at begining of first line if ($opt_b) { s/(^\s*\S+\s+)//; $toplead = $1; $lead = $1; $lead =~ s/\S/ /g; } else { s/(^\s*)//; $toplead = $1; $lead = $1; } if (! $opt_w && ! $opt_n ) { print $toplead,$_; while (<>) { s/^\s*//; print $lead,$_; } } else { #calculate number of positions after white space @chars = split //, $lead; $cnt=0; foreach (@chars) { if (/ /) {$cnt++} if (/\t/) {$cnt=$cnt+(8-($cnt%8))} } if ($opt_n) {$len=int(79-($cnt*1.5))} else {$len=79-$cnt} open TMP, "|fmt -$len > /tmp/hang.$$"; print TMP $_; # # Collect rest of data, removing any leading whitespace # while (<>) { s/(^\s*)//; print TMP $_; } close TMP; open TMP,"; print $toplead,$_; while () { print $lead,$_ } close TMP; unlink "/tmp/hang.$$"; }