#!/usr/bin/perl # # formattextpro.pl 2.0 # Copyright (C) 2003 by Fletcher T. Penney. # # # http://fletcher.freeshell.org/ # # 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. # # 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # Or visit http://gnu.org # # First, set defaults $VO = " (V.O.)"; $OS = " (O.S.)"; $NIGHT = " - NIGHT"; $DAY = " - DAY"; $CONT = " (CONT'D)"; $INT = "INT."; $EXT = "EXT."; $IE = "INT./EXT."; # Settings $MatchTransitions = "(((MATCH |JUMP )?CUT|DISSOLVE|BACK) TO:)|(FADE (IN:|OUT\.|TO BLACK\.))"; $keepcomments = 1; # Next, read headers and options and override defaults as appropriate $line = <>; if ($line =~ /#\s*BEGIN-HEADERS/i) { print $line; while (($line = <>) && ($line !~ /# END-HEADERS/i)) { if ($line =~ /^\s*CHARACTER\s*ALIAS\s*([\w\s]*)\=\s*([\w\|]*)/i) { push(@CharAliases,$2); $Char = $1; $Char =~ s/\s*$//; push(@CharName,$Char); } if ($line =~ /^\s*LOCATION\s*ALIAS\s*([\w\s]*)\=\s*([\w\|]*)/i) { push(@LocAliases,$2); $Char = $1; $Char =~ s/\s*$//; push(@LocName,$Char); } if ($line =~ /^\s*REMOVE\s*COMMENTS/i) { $keepcomments = 0; } if ($line =~ /^\s*DEFINE TRANS.*:(.*)/i) { $temp = $1; $temp =~ s/(\.|\(|\))/\\$1/g; $MatchTransitions.="|$temp"; } # Print Headers back out to new file print $line; } print "$line\n"; } # Now set variables $Scene = 0; $Act = 1; $blank = 0; $oldtype = "none"; $type = "none"; print $Header; # Main Loop while ($line = <>) { # Strip newlines. These will placed at beginning of lines when needed chomp $line; # Strip formfeeds. These appear when pdf is converted to text $line =~ s/\f//g; # Skip Comments if ($line =~ /^\s*#/) { if ($keepcomments eq 1) { if ($oldtype ne "comm") { $line = "\n\n$line"; } else { $line = "\n$line"; } $oldtype = "comm"; print $line; next; } else { next; } } # Handle Fade lines if ($line =~ /^F(A|AD|ADE)\s*(IN|OUT)/i) { $line = uc($line); $type = "trans"; } # Handle Transitions if ($line =~ /^$MatchTransitions$/i) { $line = uc($line); $type = "trans"; } # Skip empty lines if ($line =~ /^$/) { $blank = 1; $type="none"; next; } # Handle Sluglines if (($line =~ s/^I(NT)?\.?(\s+)/$INT /i)|| ($line =~ s/^E(X|XT)?\.?(\s+)/$EXT /i)|| ($line =~ s/^I(NT)?\.?\/E(X|XT)?\.?(\s+)/$IE /i)) { $line =~ s/[\s-]+D(AY)?$/$DAY/i; $line =~ s/[\s-]+N(IGHT)?$/$NIGHT/i; $line.=" "; for ($i=0;$i