diff --git a/Utilities/Doxygen/CMakeLists.txt b/Utilities/Doxygen/CMakeLists.txt index 05d96781209..b766b9f64cd 100644 --- a/Utilities/Doxygen/CMakeLists.txt +++ b/Utilities/Doxygen/CMakeLists.txt @@ -5,7 +5,6 @@ if(ITK_BUILD_DOCUMENTATION) find_package(Doxygen) find_package(Gnuplot) find_package(HTMLHelp) - find_package(Perl) find_package(Wget) endif() @@ -109,12 +108,9 @@ mark_as_advanced( ITK_DOXYGEN_XML ITK_DOXYGEN_SERVER_BASED_SEARCH) -find_package(Perl) +if(Python3_EXECUTABLE) + set(ITK_DOXYGEN_INPUT_FILTER "${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/itkgroup.py") -if(PERL_FOUND) - set(ITK_DOXYGEN_INPUT_FILTER "${PERL_EXECUTABLE} ${ITK_BINARY_DIR}/Utilities/Doxygen/itkdoxygen.pl") - - configure_file(${ITK_SOURCE_DIR}/Utilities/Doxygen/itkdoxygen.pl.in ${ITK_BINARY_DIR}/Utilities/Doxygen/itkdoxygen.pl) else() set(ITK_DOXYGEN_INPUT_FILTER) endif() diff --git a/Utilities/Doxygen/itkdoxygen.pl.in b/Utilities/Doxygen/itkdoxygen.pl.in deleted file mode 100644 index f5c6f2a870a..00000000000 --- a/Utilities/Doxygen/itkdoxygen.pl.in +++ /dev/null @@ -1,9 +0,0 @@ -# for vxl files run the vxl_doxy.pl script, and use itkgroup.pl for all other files -if ( $ARGV[0] =~ /(vxl|vcl|vnl)/) -{ - system ("perl @ITK_SOURCE_DIR@/Utilities/Doxygen/vxl_doxy.pl $ARGV[0]"); -} -else -{ - system ("perl @ITK_SOURCE_DIR@/Utilities/Doxygen/itkgroup.pl $ARGV[0]"); -} diff --git a/Utilities/Doxygen/itkgroup.py b/Utilities/Doxygen/itkgroup.py new file mode 100755 index 00000000000..2ef1cd6aa66 --- /dev/null +++ b/Utilities/Doxygen/itkgroup.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +# +# Copyright NumFOCUS +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Usage: itkgroup.py " + +Processes the input filename and prints to stdout. + +The file has additional Doxygen grouping markers to doxygen comment blocks, where the block does not contain an empty + line. This groups multiple functions or variables not separated by a newline, into a single doxygen group allowing + the same doxyen comment to apply to all of them. + +""" + + +import re +import sys + +ingroup = False +semicount = 0 +endbracecount = 0 +endparencount = 0 +leading_space = " " +savebuffer = "" + + +def process_line(line: str): + global ingroup, semicount, endbracecount, endparencount, leading_space, savebuffer + + line = line.rstrip() + if re.search(r"\S+", line): + match = re.search(r"/\*\*(.*)", line) + if match: + if ingroup: + print(f"{leading_space}/**{savebuffer}") + if re.search(r"(\\class|\\brief)", line): + print(line) + else: + savebuffer = f"{match.group(1)}\n" + ingroup = True + semicount = 0 + endbracecount = 0 + endparencount = 0 + leading_space = re.match(r"(^\s*)", line).group(1) + else: + if ingroup: + savebuffer += f"{line}\n" + else: + print(line) + if re.search(r";", line): + semicount += 1 + if re.search(r"\}", line): + endbracecount += 1 + if re.search(r"\)", line): + endparencount += 1 + else: + if ingroup: + if endparencount > 1 and (semicount > 1 or endbracecount > 1): + print(f"{leading_space}/**@{{{savebuffer}{leading_space}/**@}}*/\n") + else: + print(f"{leading_space}/**{savebuffer}") + savebuffer = "" + ingroup = False + else: + print(line) + + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python itkgroup.py ") + sys.exit(1) + + filename = sys.argv[1] + with open(filename) as file: + for line in file: + process_line(line) diff --git a/Utilities/Doxygen/vxl_doxy.pl b/Utilities/Doxygen/vxl_doxy.pl deleted file mode 100755 index 87458fe6852..00000000000 --- a/Utilities/Doxygen/vxl_doxy.pl +++ /dev/null @@ -1,127 +0,0 @@ -#!/bin/sh -# -*- perl -*- -exec perl -w -x $0 ${1+"$@"} -#!perl -#line 6 -# If Windows barfs at line 3 here, you will need to run perl -x vxl_doxy.pl -# You can set up as a permanent file association using the following commands -# >assoc .pl-PerlScript -# >ftype PerlScript=Perl=C:\Perl\bin\Perl.exe -x "%1" %* - -# Script to change the perceps documentation format to Doxygen (JavaDoc) format -# Authors: -# Dave Cooper -# Maarten Vergauwen -# Date: -# 17/02/2000 -# Modified: -# 11 April 2001 Ian Scott. Remove support for old perceps commands -# 5 May 2001 Geoff Cross. Correctly handle end of verbatim blocks. Allow two contiguous comments -# 10 May 2001 Ian Scott. Merged Geoffs and my changes - - -# patterns to be matched -$verbpatt = '\\\\verbatim'; -$endverbpatt = '\\\\endverbatim'; -$slashslashpatt = '^\\s*//'; -$slashslashcolonpatt = '^\\s*//:'; -$slashstarstarpatt = '/**'; -$spacespacepatt = ' '; -$starpatt = '*'; -$starslashpatt = '*/'; - -# variables that keep state: - -# comment found -> first line should start with /**, next lines with *, last line with */ -$comment = 0; - -# verbatim found -> lines should not start with * (visible in Doxygen) -$verbatim = 0; -# finish verbatim mode at the end of this line. -$should_end_verbatim = 0; - -$debug = 0; - -# mainloop -while (<>) -{ - # preprocessing - s/\bVCL_SUNPRO_CLASS_SCOPE_HACK\s*\([^()]*\)//g; - s/\bVCL_SUNPRO_ALLOCATOR_HACK\s*\(([^()]*)\)/$1/g; - s/\bVCL_CAN_STATIC_CONST_INIT_(INT|FLOAT)\b/1/g; - s/\bVCL_STATIC_CONST_INIT_(INT|FLOAT)\s*\(([^()]*)\)/= $2/g; - s/\bVCL_DFL_TYPE_PARAM_STLDECL\s*\(([^,()]*),([^,()]*)\)/class $1 = $2 /g; - s/\bDECLARE_DYNCREATE\s*\([^()]*\)//g; # for MFC - - if ( $should_end_verbatim ) - { - $verbatim = 0; - $should_end_verbatim = 0; - } - - # found verbatim ? - if ( m/$verbpatt/ ) { $verbatim = 1; }; - - # found endverbatim ? - if ( m/$endverbpatt/ ) { $should_end_verbatim = 1; }; - - # found start of comment: "//:" ? - if ( s!$slashslashcolonpatt!$slashstarstarpatt! ) - { - chomp; s/\s*$//; - # escape a space following a dot, add a dot at the end, -# # and finish brief doc, unless the line is empty or only has '\file': - unless (m!^\s*\/\*\*\s*(\\file)?\s*$!) { -# s/\. /.\\ /g; s/(\.)?\s*$/. \*\/\n\/\*/; - s/\. /.\\ /g; s/(\.)?\s*$/.\n/; - } - else { s/$/\n/; } - - if ($comment) - { - # Previous comment hasn't ended--two contiguous comment blocks. - # (Should not happen.) - print STDERR "Two contiguous comment blocks -- this should not happen\n"; - print "*/\n"; - } - $comment = 1; - print; next; - } - - # Replace '$' with '\f$' (TeX math mode) - s/(\\f)?\$(.+?)(\\f)?\$/\\f\$$2\\f\$/g if ($comment); - - # found continuation of comment WITH verbatim -> no "*" - if ( m!$slashslashpatt! && $verbatim && $comment) - { - s!$slashslashpatt!$spacespacepatt!; -# # Make 'Modifications' a section title: -# s!\b(Modifications?)\b\:?!\$1\<\/H2\>!; - # remove lines of the form ========= or +-+-+-+-+ or ********* or longer: - print unless m/^\s*[*=+-]{9,}\s*$/; next; - } - - # found continuation of comment WITHOUT verbatim -> start line with "*" - if ( m!$slashslashpatt! && $comment ) - { - s!$slashslashpatt!$starpatt!; - # remove lines of the form ========= or +-+-+-+-+ or ********* or longer: - print unless m/^\s*[*=+-]{9,}\s*$/; next; - } - - # found end of comment -> start line with */ - # NOTE that *every* line within a comment (also empty lines) *must* start with // ! - # (In an earlier version of this script, empty lines were allowed inside comments.) - if ( $comment && ! m!$slashslashpatt! ) - { - print "$starslashpatt\n"; - $comment = 0; - print; next; - } - - # just print line if not in comment or in file - if ( !$comment ) { print; next; } - - # debug - print unprocessed lines (s.b. none) - if ($debug) { print "LNP:\t"; print; } -}