BASIS  r3148
Bash.pm
Go to the documentation of this file.
00001 ##############################################################################
00002 # @file  DoxyFilter/Bash.pm
00003 # @brief Doxygen filter for Bash.
00004 #
00005 # Copyright (c) 2012 University of Pennsylvania. All rights reserved.
00006 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00007 #
00008 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00009 #
00010 # @ingroup BasisTools
00011 ##############################################################################
00012 
00013 package BASIS::DoxyFilter::Bash;
00014 use base BASIS::DoxyFilter;
00015 
00016 # ============================================================================
00017 # public
00018 # ============================================================================
00019 
00020 # ----------------------------------------------------------------------------
00021 ## @brief Constructs a CMake Doxygen filter.
00022 sub new
00023 {
00024     my $self = shift;
00025     $self->SUPER::new([
00026         # if elif fi
00027         ['start', qr/^\s*if\s*\[/, undef, 'start'], # discard if's such that
00028                                                     # Doxygen comment is
00029                                                     # associated with next
00030                                                     # block that is supposed
00031                                                     # to be in the then branch.
00032         # source
00033         ['start', qr/^\s*(\.|source)\s+(\"([^\"]|\\\")*[^\\]\"|'([^']|\\')*[^\\]'|[^\s&|]*)(\s*(\|\||&&|#).*)?$/, \&_source, 'start'],
00034         # constant
00035         ['start', qr/^\s*(\[\s+.*\s+\]\s*(\|\||&&)\s*|if\s+\[\s+.*\s+\]\s*;\s*then\s+)?readonly\s+(\w+)=(\"([^\"]|\\\")*[^\\]\"|'([^']|\\')*[^\\]'|[^#]*)(\s*;\s*fi\s*)?(\s*#.*)?$/, \&_constant, 'start'],
00036         # function
00037         ['start',  qr/^\s*(function\s*(\w+)|(\w+)\s*\(\s*\))\s*{\s*(#.*)?$/, \&_fndef, 'fnbody'],
00038         ['start',  qr/^\s*(function\s*(\w+)|(\w+)\s*\(\s*\))\s*(#.*)?$/,     \&_fndef, 'fndef'],
00039         ['fndef',  qr/^{\s*(#.*)?$/,                                         undef,    'fnbody'],
00040         ['fnbody', qr/^}\s*(#.*)?$/,                                         undef,    'start'],
00041     ]);
00042 }
00043 
00044 # ============================================================================
00045 # actions
00046 # ============================================================================
00047 
00048 # ----------------------------------------------------------------------------
00049 sub _source
00050 {
00051     my ($self, $unused, $module) = @_;
00052     $module =~ s/^\s*[\"']?//;
00053     $module =~ s/[\"']?\s*$//;
00054     $module =~ s/\/.\//\//g;
00055     $module =~ s/^\${_\w+_DIR}\///;
00056     $module =~ s/^\$\(exedir\)\///;
00057     $module =~ s/^\${?exec_dir}?\///;
00058     $self->_append("#include \"$module\"");
00059 }
00060 
00061 # ----------------------------------------------------------------------------
00062 sub _constant
00063 {
00064     my ($self, $unused1, $unused2, $name, $value) = @_;
00065     if (not $name =~ m/^_/) {
00066         $value =~ s/^\s*[\"']?//;
00067         $value =~ s/[\"']?\s*$//;
00068         if ($value =~ /^[+-]?[0-9]+$/) {
00069             $self->_append("int $name = $value;");
00070         } elsif ($value =~ /^[+-]?[0-9]+[.][0-9]+$/) {
00071             $self->_append("float $name = $value;");
00072         } else {
00073             $self->_append("string $name = \"$value\";");
00074         }
00075     }
00076 }
00077 
00078 # ----------------------------------------------------------------------------
00079 sub _fndef
00080 {
00081     my ($self, $unused, $name1, $name2) = @_;
00082     my $name = $name1 ? $name1 : $name2;
00083     if (not $name =~ m/^_/) {
00084         my @params = ();
00085         foreach my $paramdoc (@{$self->{'params'}}) {
00086             push @params, $paramdoc->{'dir'} . " " . $paramdoc->{'name'};
00087         }
00088         $self->_append("/// \@returns Nothing.") if not $self->{'returndoc'};
00089         $self->_append("function $name(" . join(', ', @params) . ");");
00090     }
00091 }
00092 
00093 
00094 1;