#!/usr/bin/perl # # Simple program to generate the examples.dox file from a simple text file, # with links to the next/previous examples. # # Copyright 2014-2021, John McNamara, jmcnamara@cpan.org # use strict; use warnings; my @examples; my @sections; my @links; my $buffer = ''; # Sample through the example sections and break the text into blocks. while ( my $line = <> ) { # Ignore comments in the input file. next if $line =~ /^#/; # Match the start of an example block. if ( $line =~ /^\@example/ ) { chomp $buffer; # Store the example name and the section body. push @examples, $line; push @sections, $buffer; $buffer = ''; next; } $buffer .= $line; } # Store the last example section and omit the first blank element. push @sections, $buffer; shift @sections; # Generate a set of @ref links targets from the example program names. for ( @examples ) { my $link = $_; chomp $link; $link =~ s/\@example //; push @links, [ $link, $link ]; } # Add the first and last links back to the examples. unshift @links, [ "examples", "Examples page" ]; push @links, [ "examples", "Examples page" ]; # Add the start of the Doxygen header. print "/**\n"; print "\@page examples Example Programs\n\n"; # Print out each section. for my $i ( 0 .. @examples - 1 ) { print $examples[$i]; # Add a simple header table with next/previous links. printf qq{\n\n}; printf qq{\n}; printf qq{ \n}, $links[$i]->[0], $links[$i]->[1]; printf qq{ \n}, $links[ $i + 2 ]->[0], $links[ $i + 2 ]->[1]; printf qq{\n}; printf qq{
\@ref %s "<< %s"\@ref %s "%s >>"
\n}; print $sections[$i], "\n\n\n\n"; } # Print the end of the doxygen comment. print "*/\n";