imgtools/buildrom/tools/checkincludeslash.pl
author kelvzhu
Thu, 11 Nov 2010 17:31:39 +0800
changeset 680 e4701f5f5159
parent 600 6d08f4a05d93
permissions -rw-r--r--
update feature database
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
#!/usr/bin/perl
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
use Getopt::Long;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
use constant TOOL_VERSION=>"0.1";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
my $help;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
my $dir;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
my $convert;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
my $logfile;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
&processcmdline();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
open (LOG, ">$logfile") or die "cannot open log file $logfile\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
&checkdir($dir);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
close LOG;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
sub processcmdline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
	GetOptions("h" => \$help, "l=s" => \$logfile, "c" => \$convert);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
	if ($help)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
		print_usage();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
		exit 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
	$logfile = "checkincludeslash.log" if (!defined $logfile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
	$dir = shift @ARGV;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
	if (!defined $dir || !-d $dir)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
		print_usage();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
		die "\nERROR: directory missing!!\n" if (!defined $dir);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
		die "\nERROR: directory $dir does not exist!!\n" if (!-d $dir);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
sub checkdir 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
  my $path = shift;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
  return if (!-d $path);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
  opendir(DIR,$path);   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
  my @entries = readdir(DIR);   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
  closedir(DIR);   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
  my $entry;   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
  foreach $entry (@entries) {   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
	  next if (($entry eq ".") || ($entry eq ".."));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
	  my $item = "$path/$entry";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
  	if (-d $item) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
 	 		&checkdir($item);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
	  }else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
	  	next if ($entry !~ /.*\.[a-z]by$/i);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
	  	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
		  &convobyfile($item, "$item.bak");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
  	}   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
  } 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
}   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
sub convobyfile
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
	my $src = shift;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
	my $dst = shift;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
	open (SRC, "<$src");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
	open (DST, ">$dst") if($convert);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
	my $line;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
	while($line = <SRC>)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
		if ($line =~ /#\s*include\s*(<|\")(.*\\.*)(>|\")/)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
	  	print "Found content in file $src\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
	  	print LOG "Found content in file $src\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
	  	print "current line is $line";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
	  	print LOG "current line is $line";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
	  	if($convert)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
	  	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
		  	my $path = $2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
		  	my $pathorg = $path;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
		  	$pathorg =~ s-\\-\\\\-g;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
		  	$path =~ s-\\-\/-g;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
		  	$line =~ s-$pathorg-$path-g;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
		  	print "converted line is $line";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
		  	print LOG "converted line is  $line";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
		  }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
	  	print "\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
	  	print LOG "\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
		print DST $line  if($convert);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
	close SRC;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
	if($convert)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
		close DST;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
	  unlink "$src";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
  	rename ("$dst", "$src");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
  }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
sub print_usage
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
	print "\nCheckincludeslash - Check back slash tool V".TOOL_VERSION."\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
	print "Copyright (c) 2010 Nokia Corporation.\n\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
	print <<USAGE_EOF;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
Usage:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
  checkincludeslash.pl [-h] [-c] [-l <logfile>] <directory>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
Check oby/iby files cursively in the <directory>. 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
When it find back slash in include line in the files like \"\#include <dir\\file>\", 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
it will report the line in log file. If with -c option it will convert the back slash
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
to forward slash like \"\#include <dir/file>\".
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
The <directory> is the directory contain all the oby/iby files.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
Usually it should be /epoc32/rom/ and it will be checked cursively.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
Options:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
   -l <logfile>       - the log file to record the log, 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
                        if not specfied it is \"checkincludeslash.log\"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
   -h                 - displays this help
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
   -c                 - convert the back slash to forward slash.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
USAGE_EOF
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
}