doxyfilter.pl
Go to the documentation of this file.
00001 #! /usr/bin/perl -w 00002 use Cwd qw(realpath); use File::Basename; use lib dirname(realpath(__FILE__)) . '/.'; use lib dirname(realpath(__FILE__)) . '/perl'; # <-- added by BASIS 00003 ############################################################################## 00004 # @file doxyfilter.pl 00005 # @brief Doxygen filter for CMake, Python, Perl, Bash, and MATLAB. 00006 # 00007 # Copyright (c) 2012 University of Pennsylvania. All rights reserved. 00008 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file. 00009 # 00010 # Contact: SBIA Group <sbia-software at uphs.upenn.edu> 00011 ############################################################################## 00012 00013 use File::Basename qw(fileparse); 00014 use BASIS::Basis qw(exename execute istarget); 00015 00016 use BASIS::DoxyFilter::Bash; 00017 use BASIS::DoxyFilter::CMake; 00018 00019 00020 if (@ARGV != 1) { 00021 print STDERR "Usage: " . exename() . " <file>\n"; 00022 exit 1; 00023 } 00024 00025 my $filename = $ARGV[0]; 00026 my $lang = undef; 00027 my $filter = undef; 00028 my $status = -1; 00029 00030 # get file name extension 00031 my ($dir, $base, $ext) = fileparse($filename, '\..*'); 00032 # select filter according to file extension 00033 if ($ext =~ /\.(pl|pm)/) { $lang = 'perl'; } 00034 elsif ($ext eq '.py') { $lang = 'python'; } 00035 elsif ($ext eq '.sh') { $lang = 'bash'; } 00036 elsif ($ext =~ /\.(cmake|ctest)/) { $lang = 'cmake'; } 00037 elsif ($ext eq '.m') { $lang = 'matlab'; } 00038 # otherwise, consider shebang directive if given 00039 if (not $lang) { 00040 open FILE, $filename or die "Failed to open file \"$filename\"!"; 00041 $lang = $2 if <FILE> =~ /^#!\s*(\/usr\/bin\/|\/bin\/|\/usr\/bin\/env\s+)(python|perl|bash)/; 00042 close FILE; 00043 } 00044 # create filter for source language 00045 if ($lang) { 00046 if ($lang eq 'bash') { $filter = new BASIS::DoxyFilter::Bash; } 00047 elsif ($lang eq 'cmake') { $filter = new BASIS::DoxyFilter::CMake; } 00048 } 00049 # execute filter 00050 if (defined $filter) { 00051 $filter->process($filename); 00052 print $filter->output(); 00053 $status = 0; 00054 } elsif ($lang and istarget("doxyfilter-$lang")) { 00055 my @cmd = ("doxyfilter-$lang"); 00056 push @cmd, '-f' if $lang eq 'python'; 00057 push @cmd, $filename; 00058 $status = execute(\@cmd, allow_fail=>1); 00059 } 00060 # otherwise, just pass input through unfiltered 00061 if ($status ne 0) { 00062 open FILE, $filename; 00063 print $_ while <FILE>; 00064 close FILE; 00065 }