summaryrefslogtreecommitdiff
path: root/docs/tutorials/combine
blob: c464f389e0030a465ee84f06d604c38aee01533a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

#
# This perl script will combine a set of files into one or more HTML pages.
#
# The file fooNN.html will be created by combining the files:
#    fooNN.hdr
#    fooNN.pre
#    fooNN.bdy
#    fooNN.pst
#
# Where NN is a 2-digit number.  If fooNN.hdr does not exist, the file 'hdr'
# will be used.  If any of the other file-parts don't exist, they will be
# ignored.
#
# Usage:
#    combine *.html
#    combine *.pre
#
# Input files:
#
#
#     hdr
#      If no *.hdr exists for the current page, this is used.  You will typically
#      use this to add <TITLE> and such to each page created.
#
#     *.hdr
#      You can override the generic hdr you create by creating one for
#      a specific page.
#
#    *.pre
#      Prefix files.  Their content is included after the hdr.
#
#    *.bdy
#      Body files follow prefix.  You generally use the links file to create
#      links between source-code and a bdy filename.  The bdy files are
#      examined and "fontified" (think emacs).
#
#     bodies
#      The list of files to use for the body of the HTML pages generated
#
#    *.pst
#      Post files.  This content follows the bdy content.
#
#    *.html    
#      These are the output.  If they exist before you run combine, they
#      will be overwritten.
#
use File::Copy;

%format = ();

$PAGE=0;

open(LINKS,"<bodies") || die("No 'bodies' file found!");
while( ($file = <LINKS>) ) {

	chomp($file);

        next if( $file =~ /^#/ || $file eq '' );

	if( $file =~ /^.*=/ ) {
		($var,$value) = split(/=/,$file);
		if( $var =~ /PAGE/ ) {
			$PAGE = $value + 0;
		}
		next;
	}

  $body{$PAGE++} = "$file";
}
close(LINKS);

foreach $file (@ARGV) {
  ($base = $file) =~ s/.html$//;
   $base =~ s/.pre$//;

  open(FILE,">$base.html") || die;
  select(FILE);
  $| = 1;

  # .hdr has the HTML header, title, etc...
  if( -f "$base.hdr" ) {
	copy("$base.hdr",\*FILE);
  }
  elsif( -f "hdr" ) {
	copy("hdr",\*FILE);
  }
  # .pre has the discussion of what you'll see on this page
  if( -f "$base.pre" ) {
	copy("$base.pre",\*FILE);
  }
  # .bdy is the body of the page
  if( -f "$base.bdy" ) {
	&addFile("$base.bdy");
  }

  ($num = $base) =~ s/[A-z]//g;
   $num += 0;

  if( -f "$body{$num}" || "$body{$num}" =~ /\s/ ) {
	&addFile("$body{$num}");
  }
  # .pst summarizes what was seen
  if( -f "$base.pst" ) {
	copy("$base.pst",\*FILE);
  }
  # .ftr follows the footer to show "continue to next page" stuff
  if( -f "$base.ftr" ) {
	copy("$base.ftr",\*FILE);
  }
  else {
	++$num;
	$base =~ s/[0-9]//g;
	$next = sprintf("$base%02.2d",$num);
	print FILE "<P><HR WIDTH=\"100%\">\n";
	print FILE "<CENTER>[<A HREF=\"../online-tutorials.html\">Tutorial Index</A>] ";
	if( $file ne $ARGV[$#ARGV] ) {
	  print FILE "[<A HREF=\"$next.html\">Continue This Tutorial</A>]";
	}
	print FILE "</CENTER>\n";
  }
  close(FILE);
}

sub addFile {
	local($file) = @_;

        local(@file) = split(/\s+/,$file);

        foreach $file (@file)
          {
               if( $#file > 0 )
                 {
                   print FILE "<HR width=50%><P><center>$file</center><HR width=50%>\n";
                 }
               print FILE "<PRE>\n" ;
               open(INPUT,"<$file") || die "Cannot open $file for read\n";
               # Do some substitutes on each line to try and get the output to
               # look like it does in fontified emacs.
               while( <INPUT> )
               {
                  s/</\&lt;/g;
                  if( m,include\s+"ace/.*\.h", ) {
                    s,(ace/.*\.h),<A HREF="../../../$1">$1</A>,;
                    s,\#\s*include,<font color=blue>$&</font>,;
                  }
                  else
                  {
                    s,\#(\s*)(e?l?if !?defined|pragma|ifn?def|define)(\W*)([\w\.]+),<font color=blue>\#$1$2</font>$3<font color=purple>$4</font>,;
                    s,\#\s*(include|endif),<font color=blue>$&</font>,;
                    s,"([^"]+)","<font color=green>$1</font>",g;
                    s,//.*$,<font color=red>$&</font>,;
                    s,/\*,<font color=red>$&,;
                    s,\*/,$&</font>,;
                    s,\w+::\~?\w+,<font color=\#008888>$&</font>,;
                  }
                  print FILE $_;
               }
               print FILE "</PRE>\n";
          }
}