#!/usr/bin/perl -w
#
# $Revision: 1.3 $ $Date: 2012-07-26 17:11:47-04 $
# $Source: /home/vogelke/bin/RCS/cssalign,v $
# $Host: sys7.com $
# $UUID: c4fafed8-edd0-3efe-9909-1be628179a68 $
#
#<cssalign: fix alignment in CSS files.

use strict;

while (<>) {
    chomp;

    # handle opening and closing brackets
    s/{ */{/g;
    s/ *{/ {\n  /g;
    s/ *}/}/g;

    # handle colons and semicolons;
    # try to avoid turning "a:hover" into "a: hover" by
    # looking for two characters before a colon.
    s/; */;/g;
    s/ *;/;\n  /g;
    s/;\n  $//g;
    s/(\S\S\S*):/$1: /g;

    # cleanup
    s/ *}/}\n/g;
    s/:  */: /g;

    print "$_\n";
}

exit(0);
