| 1 |
#!/bin/sh |
| 2 |
# -*- perl -*- |
| 3 |
exec perl -w -x $0 ${1+"$@"} |
| 4 |
#!perl |
| 5 |
#line 6 |
| 6 |
# If Windows barfs at line 3 here, you will need to run perl -x this_file.pl |
| 7 |
# You can set up as a permanent file association using the following commands |
| 8 |
# >assoc .pl-PerlScript |
| 9 |
# >ftype PerlScript=Perl=C:\Perl\bin\Perl.exe -x "%1" %* |
| 10 |
|
| 11 |
# Script to change the perceps documentation format to Doxygen (JavaDoc) format |
| 12 |
# Authors: |
| 13 |
# Dave Cooper |
| 14 |
# Maarten Vergauwen |
| 15 |
# Date: |
| 16 |
# 17/02/2000 |
| 17 |
# Modified: |
| 18 |
# 11 April 2001 Ian Scott. Remove support for old perceps commands |
| 19 |
# 5 May 2001 Geoff Cross. Correctly handle end of verbatim blocks. Allow two contiguous comments |
| 20 |
# 10 May 2001 Ian Scott. Merged Geoffs and my changes |
| 21 |
|
| 22 |
|
| 23 |
# patterns to be matched |
| 24 |
$verbpatt = '\\\\verbatim'; |
| 25 |
$endverbpatt = '\\\\endverbatim'; |
| 26 |
$slashslashpatt = '^\\s*//'; |
| 27 |
$slashslashcolonpatt = '^\\s*//:'; |
| 28 |
$slashstarstarpatt = '/**'; |
| 29 |
$spacespacepatt = ' '; |
| 30 |
$starpatt = '*'; |
| 31 |
$starslashpatt = '*/'; |
| 32 |
|
| 33 |
# variables that keep state: |
| 34 |
|
| 35 |
# comment found -> first line should start with /**, next lines with *, last line with */ |
| 36 |
$comment = 0; |
| 37 |
|
| 38 |
# verbatim found -> lines should not start with * (visible in Doxygen) |
| 39 |
$verbatim = 0; |
| 40 |
# finish verbatim mode at the end of this line. |
| 41 |
$should_end_verbatim = 0; |
| 42 |
|
| 43 |
$debug = 0; |
| 44 |
|
| 45 |
# mainloop |
| 46 |
while (<>) |
| 47 |
{ |
| 48 |
# preprocessing |
| 49 |
s/\bDECLARE_DYNCREATE\s*\([^()]*\)//g; # for MFC |
| 50 |
s/\bTODO\b/\\todo/g; |
| 51 |
|
| 52 |
if ( $should_end_verbatim ) |
| 53 |
{ |
| 54 |
$verbatim = 0; |
| 55 |
$should_end_verbatim = 0; |
| 56 |
} |
| 57 |
|
| 58 |
# found verbatim ? |
| 59 |
if ( m/$verbpatt/ ) { $verbatim = 1; }; |
| 60 |
|
| 61 |
# found endverbatim ? |
| 62 |
if ( m/$endverbpatt/ ) { $should_end_verbatim = 1; }; |
| 63 |
|
| 64 |
# found start of comment: "//:" ? |
| 65 |
if ( s!$slashslashcolonpatt!$slashstarstarpatt! ) |
| 66 |
{ |
| 67 |
chomp; s/\s*$//; |
| 68 |
# escape a space following a dot, add a dot at the end, |
| 69 |
# # and finish brief doc, unless the line is empty or only has '\file': |
| 70 |
unless (m!^\s*\/\*\*\s*(\\file)?\s*$!) { |
| 71 |
# s/\. /.\\ /g; s/(\.)?\s*$/. \*\/\n\/\*/; |
| 72 |
s/\. /.\\ /g; s/(\.)?\s*$/.\n/; |
| 73 |
} |
| 74 |
else { s/$/\n/; } |
| 75 |
|
| 76 |
if ($comment) |
| 77 |
{ |
| 78 |
# Previous comment hasn't ended--two contiguous comment blocks. |
| 79 |
# (Should not happen.) |
| 80 |
print STDERR "Two contiguous comment blocks -- this should not happen\n"; |
| 81 |
print "*/\n"; |
| 82 |
} |
| 83 |
$comment = 1; |
| 84 |
print; next; |
| 85 |
} |
| 86 |
|
| 87 |
# Replace '$' with '\f$' (TeX math mode) |
| 88 |
s/(\\f)?\$(.+?)(\\f)?\$/\\f\$$2\\f\$/g if ($comment); |
| 89 |
|
| 90 |
# found continuation of comment WITH verbatim -> no "*" |
| 91 |
if ( m!$slashslashpatt! && $verbatim && $comment) |
| 92 |
{ |
| 93 |
s!$slashslashpatt!$spacespacepatt!; |
| 94 |
# # Make 'Modifications' a section title: |
| 95 |
# s!\b(Modifications?)\b\:?!\<H2\>$1\<\/H2\>!; |
| 96 |
# remove lines of the form ========= or +-+-+-+-+ or ********* or longer: |
| 97 |
print unless m/^\s*[*=+-]{9,}\s*$/; next; |
| 98 |
} |
| 99 |
|
| 100 |
# found continuation of comment WITHOUT verbatim -> start line with "*" |
| 101 |
if ( m!$slashslashpatt! && $comment ) |
| 102 |
{ |
| 103 |
s!$slashslashpatt!$starpatt!; |
| 104 |
# remove lines of the form ========= or +-+-+-+-+ or ********* or longer: |
| 105 |
print unless m/^\s*[*=+-]{9,}\s*$/; |
| 106 |
# found \brief: finish it after single line: |
| 107 |
# print "\n" if ( m!\\brief\b!); |
| 108 |
next; |
| 109 |
} |
| 110 |
|
| 111 |
# found end of comment -> start line with */ |
| 112 |
# NOTE that *every* line within a comment (also empty lines) *must* start with // ! |
| 113 |
# (In an earlier version of this script, empty lines were allowed inside comments.) |
| 114 |
if ( $comment && ! m!$slashslashpatt! ) |
| 115 |
{ |
| 116 |
print "$starslashpatt"; |
| 117 |
$comment = 0; |
| 118 |
print; next; |
| 119 |
} |
| 120 |
|
| 121 |
# just print line if not in comment or in file |
| 122 |
if ( !$comment ) { print; next; } |
| 123 |
|
| 124 |
# debug - print unprocessed lines (s.b. none) |
| 125 |
if ($debug) { print "LNP:\t"; print; } |
| 126 |
} |