}
-# have three states, in which the program can be:
-# comment-mode, program-mode and skip-mode
-$comment_mode = 0;
-$program_mode = 1;
-$skip_mode = 2;
+# have four states, in which the program can be:
+# comment-mode, program-mode, skip-mode, and code-fragment-mode
+$comment_mode = 0;
+$program_mode = 1;
+$skip_mode = 2;
+$code_fragment_mode = 3;
$state = $comment_mode;
print " * \n";
s/\t/ /g;
+ # We are entering code fragments
+ if (($state != $code_fragment_mode) && m!^\s*//\s*\@code!)
+ {
+ # Cleanly close @code segments in program mode:
+ if ($state == $program_mode)
+ {
+ print " * \@endcode\n";
+ print " * \n";
+ }
+ $state = $code_fragment_mode;
+ }
# We shall skip something...
- if (($state != $skip_mode) && m!^\s*//\s*\@cond SKIP!)
+ elsif (($state != $skip_mode) && m!^\s*//\s*\@cond SKIP!)
{
# Cleanly close @code segments in program mode:
if ($state == $program_mode)
$state = $comment_mode;
}
}
-} while (<>);
+ elsif ($state == $code_fragment_mode)
+ {
+ # This is the end of a @code - @endcode block, so back to
+ # comment_mode:
+ if (m!^\s*//\s*\@endcode!)
+ {
+ $state = $comment_mode;
+ }
+ # in code fragment mode: only skip leading whitespace and
+ # comment // signs
+ s!\s*//\s(.*)\n!$1!;
+
+ # finally print this line
+ print " * $_\n";
+ }
+ } while (<>);
if ($state == $program_mode) {
print " * \@endcode\n";