#!/usr/bin/perl -w
#
# $Revision: 1.5 $ $Date: 2012-07-26 17:11:48-04 $
# $Source: /home/vogelke/bin/RCS/mktitle,v $
# $Host: sys7.com $
# $UUID: 3d738bff-5c9f-3eee-aae0-1c837a777168 $
#
#< mktitle: turn a document title into a decent filename

use strict;

# slurp stdin or join the arguments together
if (-f STDIN || -p STDIN) {
    while (<>) {
        chomp;
        title($_);
    }
} else {
    $_ = join(' ', @ARGV);
    title($_);
}

exit(0);

# -------------------------------------------------------------------------
# Kill quotes, level out the case, and kill spaces.

sub title {
    local($_);
    $_ = shift;

    if (length) {
        tr/'"//d;
        tr/A-Z/a-z/;
        s/\s+/-/g;
        tr!,/!-!;
        s/--*/-/g;
    }

    print "$_\n";
}
