#!/usr/bin/perl -w # Converts ApprovalPlugin entries in all pages of current directory to WorkFlowPlugin entries. # # History: # 1.0 (Thomas Weigert): # First release using STDIN and STDOUT. # 1.01 (Detlef Marxsen): # Changed to process a whole directory. # 1.02 (Detlef Marxsen): # Added syntax conversion "state=" to "name=". use English; use strict; $OUTPUT_AUTOFLUSH=1; my $direc; # Directory to process my $direntry; # One entry in directory my $line; # One line of file my @lines; # Buffer for the (modified) lines of file my $version="1.02"; # Enter program version here! print("Converter V. $version has been started ...\n"); chomp($direc=`pwd`); print("Directory: $direc\n"); opendir(DIRFILE,$direc)||die("Fail: Open directory: ",$!); rewinddir(DIRFILE); while (defined ($direntry=readdir(DIRFILE))) { next if $direntry eq '.'; next if $direntry eq '..'; next unless $direntry=~/\.txt$/i; print("$direntry\n"); (@lines)=(); # Clean restart open(DATAFILE,$direntry)||die("File access error."); # Open the source file while (defined($line=)) { chomp($line); $line=~s/APPROVALWORKFLOW/WORKFLOW/go; $line=~s/APPROVALNOTICE/WORKFLOWNOTICE/go; $line=~s/APPROVALBUTTON/WORKFLOWBUTTON/go; $line=~s/APPROVALHISTORYFORMAT/WORKFLOWHISTORYFORMAT/go; $line=~s/\%APPROVAL(.*?)\%/\%WORKFLOW$1\%/go; $line=~s/\%META:APPROVAL(.*?)\{/\%META:WORKFLOW$1\{/go; $line=~s/(\%META:WORKFLOW{.*?)state(=.*)/$1name$2/g; push(@lines,$line); # Buffer all (possibly modified) lines of file } close(DATAFILE); open(DATAFILE,">$direntry")||die("File access error."); # Open the source file for writing foreach $line (@lines) # Replace old content with buffered lines { print(DATAFILE "$line\n"); } close(DATAFILE); } close(DIRFILE);