]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
A simple script, used to remove warnings from ORTE source codes.
authorTran Duy Khanh <trandk1@fel.cvut.cz>
Sat, 17 May 2008 20:32:48 +0000 (22:32 +0200)
committerTran Duy Khanh <trandk1@fel.cvut.cz>
Sat, 17 May 2008 20:32:48 +0000 (22:32 +0200)
src/roboorte/utils/ortewarnpatch.pl [new file with mode: 0755]

diff --git a/src/roboorte/utils/ortewarnpatch.pl b/src/roboorte/utils/ortewarnpatch.pl
new file mode 100755 (executable)
index 0000000..54b19aa
--- /dev/null
@@ -0,0 +1,101 @@
+#!/usr/bin/perl -w
+
+#
+# Call main function
+#
+&main();
+
+#
+# Usage
+#
+sub print_usage {
+
+print << "(END OF PRINT USAGE)";
+Patch ORTE to remove all compiling warnings.
+
+Usage: $0 <directory>
+Example:
+
+\t $0 ../../orte
+
+(END OF PRINT USAGE)
+
+       return 0;
+}
+
+#
+# Get files in the directory
+#
+sub get_files() {
+       my($path) = @_;
+       my(@fileList);
+
+       # append a trailing / if it's not there
+       $path .= '/' if($path !~ /\/$/);
+       
+       # loop through the files contained in the directory
+       for my $eachFile (glob($path.'*')) {
+               # if the file is a directory
+
+               if( -d $eachFile) {
+                       # pass the directory to the routine (recursion)
+                       push(@fileList, &get_files($eachFile));
+               } else {
+                       if ($eachFile =~ /\.[c]$/) {
+                               push(@fileList, $eachFile);
+                       }
+               }
+       }
+
+       return @fileList;
+}
+
+#
+# Script main loop
+#
+sub main {
+       my $content;
+       my $target;
+       
+       if (@ARGV < 1) {
+               &print_usage();
+               exit(1);
+       }
+       
+       $target = $ARGV[0];
+
+       unless (-d $target) {
+               die "Directory $target does not exist.\n";
+       }
+
+       @fileList = &get_files($target);
+
+       foreach $file (@fileList) {
+               open(FILE, "<$file");
+               undef $/;
+               $content = <FILE>;
+               close(FILE);
+
+               if ($file =~ /sock\.c$/) {
+                       next;
+               }
+
+               $content =~ s/(CDR_get_octet\([^,]+,)\s*(\(.*?\))*\s*([^\s]+)\s*(\))/$1 (CORBA_octet *)$3$4/g;
+               $content =~ s/(strcpy\()\s*(\(.*?\))*\s*([^\s]+)\s*(,.*\))/$1(char *)$3$4/g;
+               $content =~ s/(sock_get_local_interfaces\([^,]+,[^,]+,)\s*(\(.*?\))*\s*([^\s]+)/$1 (char *)$3/g;
+               $content =~ s/(sock_setsockopt\([^,]+,[^,]+,[^,]+,)\s*(\(.*?\))*\s*([^\s]+)/$1 (const char *)$3/g;
+               $content =~ s/(getsockopt\([^,]+,[^,]+,[^,]+,[^,]+,)\s*(\(.*?\))*\s*([^\s]+)\s*(\))/$1 (socklen_t *)$3$4/g;
+               $content =~ s/(CDR_get_ulong\([^,]+,)\s*(\(.*?\))*\s*([^\s]+)\s*(\))/$1 (CORBA_unsigned_long *)$3$4/g;
+               $content =~ s/(strcmp\()\s*(\(.*?\))*\s*([^\s]+)\s*,\s*(\(.*?\))*\s*([^\s]+)\s*(\))/$1(const char *)$3, (const char*)$5$6/g;
+               $content =~ s/(strncpy\()\s*(\(.*?\))*\s*([^,\s]+)\s*,\s*(\(.*?\))*\s*([^\s]+)/$1(char *)$3, (const char*)$5/g;
+               $content =~ s/(fnmatch\()\s*(\(.*?\))*\s*([^,\s]+)\s*,\s*(\(.*?\))*\s*([^\s]+)/$1(const char *)$3, (const char*)$5/g;
+               $content =~ s/(.*?\.topic\s*=\s*)/$1(char*)/g;
+               $content =~ s/(.*?\.type\s*=\s*)/$1(char*)/g;
+
+               open(FILE, ">$file");
+               print FILE $content;
+               close(FILE);
+       }
+}
+