#!/usr/bin/perl
#
#NAME
#  msort - sort makefile entries
#
#SYNOPSIS
#  For vi users:
#    :'a,'b!msort
#
#  This will sort the entries from marks 'a to 'b.
#
#DESCRIPTION
#  Sort makefile entries.  We split the input apart on blank lines, sort  the
#  resulting chunks, and output them with blank lines in between.
#
#  Duplicates are removed.
#
#  This can be used to sort other things that are organized into "paragraphs"
#  that are separated by blank lines. What we do is chop the text up into its
#  paragraphs, and sort them lexically.  Thus, if the first line of each is a
#  function declaration, this will sort the functions lexically.
#
#  Note that we use the (<>) gimmick, so you can use this as  a  normal  unix
#  filter.   You  can  put  file  names on the command line, and they will be
#  merged and then sorted.  Or you can feed it the input via standard input.
# 
#  The sorted result is always written to standard output.
#
#RETURNS
#  As far as I know, this should always return an exit status of  zero.   The
#  worst  thing  that can go wrong is that there's no input to sort, and that
#  works just like you'd expect.
#
#BUGS
#  The description is longer than the code.  That's perl for you.
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>
#  Use this however you like, as long as you don't claim you wrote it.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

$/ = $y = '';
chomp(@out = sort(<>));
for $x (@out) {print "\n$x\n" if lc($x) ne lc($y); $y = $x}
print "\n";
