#!/usr/bin/perl -- # # Usage: # perl indentmk.pl < crud.mk > indented-crud.mk # perl indentmk.pl crud.mk crud.mk > indented-crud.mk # # use strict; use warnings; Main( @ARGV ); exit( 0 ); sub Main { local *ARGV; ## uncomment to edit files and make backups instead of printing to STDOUT #~ local $^I = ".orig"; local @ARGV = @_; my $dent = 0; my $oldent = 0; my $space = "\t"; LINE: while (defined($_ = )) { next if /^#/; my $w = /^\s*\.(\S+)/ ? $1 : ''; if( $w ) { $oldent = $dent; if( $w =~ /^END/i ){ $dent--; s/^/ $space x ( $dent )/e ; } else { $dent++ if $w =~ /^IF/i; s/^/ $space x ( $dent - 1 )/e ; } } else { s/^/ $space x ( $dent )/e; } } continue { die "-p destination: $!\n" unless print $_; } } __END__