00001 #! /usr/bin/perl -w 00002 ############################################################################## 00003 # @file doxyfilter.pl 00004 # @brief Doxygen input filter. 00005 # 00006 # This Perl script is used as pre-processor for input files to Doxygen. 00007 # Depending on the file extension, it invokes the corresponding Doxygen 00008 # filters which transform the input file into something that Doxygen 00009 # understands. 00010 # 00011 # Based on the Doxygen Filter from Bart Schuller and Aeby Thomas. 00012 # @sa http://www.bigsister.ch/doxygenfilter/ 00013 # 00014 # Copyright (c) 2011 University of Pennsylvania. All rights reserved. 00015 # See https://www.rad.upenn.edu/sbia/software/license.html or COPYING file. 00016 # 00017 # Contact: SBIA Group <sbia-software at uphs.upenn.edu> 00018 # 00019 # @ingroup Tools 00020 ############################################################################## 00021 00022 # ======================================================================= 00023 # Doxygen Pre-Processor for Perl 00024 # Copyright (C) 2002 Bart Schuller 00025 # Copyright (C) 2006 Phinex Informatik AG 00026 # Copyright (C) 2011 University of Pennsylvania 00027 # All Rights Reserved 00028 # 00029 # Doxygen Filter is free software; you can redistribute it and/or modify 00030 # it under the same terms as Perl itself. 00031 # 00032 # Larry Wall's 'Artistic License' for perl can be found in 00033 # http://www.perl.com/pub/a/language/misc/Artistic.html 00034 # 00035 # ======================================================================= 00036 # 00037 # Author: Aeby Thomas, Phinex Informatik AG, 00038 # Based on DoxygenFilter from Bart Schuller 00039 # E-Mail: tom.aeby@phinex.ch 00040 # 00041 # Phinex Informatik AG 00042 # Thomas Aeby 00043 # Kirchweg 52 00044 # 1735 Giffers 00045 # 00046 # ======================================================================= 00047 00048 00049 use Cwd qw(realpath); 00050 use File::Basename; 00051 use lib realpath(dirname(realpath(__FILE__)) . '/perl5'); 00052 use lib realpath(dirname(realpath(__FILE__)) . '/perl5'); 00053 use lib dirname(realpath(__FILE__)); 00054 00055 package Basis; 00056 use SBIA::BASIS::Basis qw(:everything); 00057 package main; 00058 00059 00060 use Cwd qw(realpath); 00061 use SBIA::BASIS::DoxyGen::PerlFilter; 00062 use Getopt::Long; 00063 00064 $Getopt::Long::ignorecase = 0; 00065 my $verbose; 00066 my $help; 00067 00068 unless (GetOptions( "verbose" => \$verbose, "v" => \$verbose, 00069 "help" => \$help, "h" => \$help ) && $ARGV[0]) { 00070 $help = 1; 00071 } 00072 00073 if ($help) { 00074 my $prog = $0; 00075 $prog =~ s#.*/##; 00076 print STDERR <<END; 00077 Usage: $prog [-v] filename 00078 00079 Pre-processes Perl code in file <filename> and outputs 00080 something doxygen does understand. 00081 00082 END 00083 exit 1; 00084 } 00085 00086 open (FILE, "<$ARGV[0]") or die "Failed to open file $ARGV[0]\n"; 00087 my $filehead = ""; 00088 for (my $line = 0; ($line < 3) && ($_ = <FILE>); $line++) { 00089 $filehead .= $_; 00090 } 00091 close FILE; 00092 00093 my $ext = ''; 00094 if ($ARGV[0] =~ /\.([a-z]+)$/i) { 00095 $ext = lc ($1); 00096 } 00097 00098 my $filter = undef; 00099 00100 # Perl 00101 if (grep ($_ eq $ext, "pl", "pm", "perl") || $filehead =~ /^#!\s*(\/usr\/bin\/perl|\/bin\/perl|\/usr\/bin\/env\s+perl)/) { 00102 print STDERR "treating file as Perl\n" if ($verbose); 00103 $filter = SBIA::BASIS::DoxyGen::PerlFilter->new (\*STDOUT); 00104 # Python 00105 } elsif ($ext eq "py" || $filehead =~ /^#!\s*(\/usr\/bin\/python|\/bin\/python|\/usr\/bin\/env\s+python)/) { 00106 print STDERR "Treating file as Python\n" if ($verbose); 00107 unshift (@ARGV, 'doxyfilter-python'); 00108 push (@ARGV, '-f'); 00109 # BASH 00110 } elsif ($ext eq "sh" || $filehead =~ /^#!\s*(\/usr\/bin\/bash|\/bin\/bash|\/usr\/bin\/env\s+bash)/) { 00111 print STDERR "Treating file as BASH\n" if ($verbose); 00112 unshift (@ARGV, 'doxyfilter-bash'); 00113 # CMake 00114 } elsif ($ext eq "cmake" or $ext eq "ctest") { 00115 print STDERR "Treating file as CMake\n" if ($verbose); 00116 unshift (@ARGV, 'doxyfilter-cmake'); 00117 # otherwise 00118 } else { 00119 print STDERR "passing file through\n" if ($verbose); 00120 print <>; 00121 exit 0; 00122 } 00123 00124 # execute filter instance or external command 00125 if ($filter) { 00126 $filter->filter ($ARGV [0]); 00127 } else { 00128 Basis::execute_process (\@ARGV); 00129 }