1#!/usr/bin/perl -s 2#---------------------------------------------------------------------------- 3# Project: TwlSDK - tools 4# File: conv2svnFormat.pl 5# 6# Copyright 2007 Nintendo. All rights reserved. 7# 8# These coded instructions, statements, and computer programs contain 9# proprietary information of Nintendo of America Inc. and/or Nintendo 10# Company Ltd., and are protected by Federal copyright law. They may 11# not be disclosed to third parties or copied or duplicated in any form, 12# in whole or in part, without the prior written consent of Nintendo. 13# 14# $Date:: 2007-09-19#$ 15# $Rev: 997 $ 16# $Author: ooshimay $ 17#---------------------------------------------------------------------------- 18 19#---------------------------------------------------------------------------- 20# Get the current year 21#---------------------------------------------------------------------------- 22sub GetThisYear 23{ 24 my @array = localtime(time); 25 26 return (@array[5] + 1900); 27} 28 29#---------------------------------------------------------------------------- 30# Main routine 31#---------------------------------------------------------------------------- 32{ 33 my $input_file; 34 my $output_file; 35 my $line; 36 37 # Copy input file to separately named file 38 $output_file = @ARGV[0]; 39 $input_file = $output_file . ".convbackup"; 40 system `cp -rf $output_file $input_file`; 41 42 open INPUTFILE, "$input_file" or die "ERROR: Cannot open file \'$input_file\'\n"; 43 open OUTPUTFILE, ">$output_file" or die "ERROR: Cannot create file \'$output_file\'\n"; 44 45 while ($line = <INPUTFILE>) 46 { 47 # Convert project character string 48 if ($line =~ m/.*Project: *NitroSDK.*$/) 49 { 50 $line =~ s/NitroSDK/TwlSDK/; 51 } 52 53 # Convery copyright year character string 54 if ($line =~ m/.*Copyright [0-9]+.*$/) 55 { 56 my $start = $line; 57 my $now = GetThisYear(); 58 59 $start =~ s/.*Copyright ([0-9]+).*\n/$1/; 60 if ($start >= $now) 61 { 62 $line =~ s/Copyright [0-9\-,]+/Copyright $now/; 63 } 64 else 65 { 66 $line =~ s/Copyright [0-9\-,]+/Copyright $start/; 67 } 68 } 69 70 # Replace log line with automatically converted string 71 if ($line =~ m/\${1}Log.*\$/) # Verbose expression so this won't mistakenly convert itself 72 { 73 my $prefix = $line; 74 my $suffix = $line; 75 76 $prefix =~ s/^(.*)\${1}Log.*\$.*\n/$1/; # Verbose expression so this won't mistakenly convert itself 77 #$suffix =~ s/.*(\r?\n)$/$1/; 78 if ($line =~ m/.*\r\n$/) 79 { 80 $suffix = "\r\n"; 81 } 82 else 83 { 84 $suffix = "\n"; 85 } 86 87 print OUTPUTFILE $prefix . "\$" . "Date:: \$" . $suffix; 88 print OUTPUTFILE $prefix . "\$" . "Rev:\$" . $suffix; 89 print OUTPUTFILE $prefix . "\$" . "Author:\$" . $suffix; 90 91 while ($line = <INPUTFILE>) 92 { 93 if ((index($line, $prefix, 0) == 0) && ($line =~ m/.*Revision [0-9\.]+.*/)) 94 { 95 while ($line = <INPUTFILE>) 96 { 97 $line =~ s/\r?\n$//; 98 if (length($line) <= length($prefix)) 99 { 100 last; 101 } 102 103 # Exit if gone all the way to NoKeywords 104 if ($line =~ m/\${1}NoKeywords.*\$/) 105 { 106 last; 107 } 108 } 109 } 110 else 111 { 112 last; 113 } 114 } 115 } 116 117 # Delete NoKeywords line 118 if ($line =~ m/\${1}NoKeywords.*\$/) # Redundant expression so this won't mistakenly convert itself 119 { 120 next; 121 } 122 123 # Output lines that do not match patterns as they are 124 print OUTPUTFILE $line; 125 } 126 127 close OUTPUTFILE; 128 close INPUTFILE; 129 130 # Add sub-version attribute to output file 131 system `svn propset -q --force "svn:keywords" "Id URL Author Date Rev" $output_file`; 132 if ($output_file =~ m/.*\.sh$/) 133 { 134 system `svn propset -q --force "svn:eol-style" "LF" $output_file`; 135 system `svn propset -q --force "svn:executable" "1" $output_file`; 136 } 137 elsif ($output_file =~ m/.*\.pl$/) 138 { 139 system `svn propset -q --force "svn:eol-style" "CRLF" $output_file`; 140 system `svn propset -q --force "svn:executable" "1" $output_file`; 141 } 142 else 143 { 144 system `svn propset -q --force "svn:eol-style" "CRLF" $output_file`; 145 } 146 147 # Delete temporarily copied files 148 system `rm -rf $input_file` 149} 150