1#! /usr/bin/env perl
2#
3# This script extracts the text blocks from a source file and creates a
4# simple text block out of them.
5#
6# Initially, we will use this to create LaTeX blocks so that the ADI reference
7# manual can contain the comments from the example source files adi3.c and
8# adi3.h.
9#
10
11use warnings;
12
13$debug = 0;
14while (<>) {
15    if (/\/\*T([^ ]*)[ ]*\n/) {
16	$filename = $1;
17	print "Filename = |$filename|\n" if $debug;
18	$filename =~ s/\s*//;
19	if ($filename ne "") {
20	    open( OUTFILE, ">$filename" ) || die "Could not open $filename\n";
21	    $OUTFILE = OUTFILE;
22	}
23	else {
24	    $OUTFILE = STDOUT;
25	}
26	# Process until we find the matching T*/
27        $_=<>;
28	if (/Section[ ]*[0-9:]*[ ]*(.*)/) {
29	    print $OUTFILE "\\section{$1}\n";
30	}
31	else {
32	    s/^ \*//;
33	    if (/[A-Za-z]:[ ]*$/) {
34		s/[ ]*(.*):/\\subsection{$1}/g;
35	    }
36	    s/^.vb/\\begin{verbatim}/g;
37	    s/^.ve/\\end{verbatim}/g;
38	    s/\'([^\']*)\'/]\texttt{$1}/g;
39	    s/\\:/:/g;
40	    print $OUTFILE $_;
41	}
42	while (<>) {
43	    if (/T\*\//) { last ; }
44	    s/^ \*//;
45	    if (/[A-Za-z]:[ ]*$/) {
46		s/[ ]*(.*):/\\subsection{$1}/g;
47	    }
48	    s/^.vb/\\begin{verbatim}/g;
49	    s/^.ve/\\end{verbatim}/g;
50	    s/\'([^\']*)\'/\\texttt{$1}/g;
51	    s/\`([^\`]*)\`/\\emph{$1}/g;
52	    s/\\:/:/g;
53	    print $OUTFILE $_;
54	}
55	if ($filename ne "") { close(OUTFILE); }
56    }
57}
58