1#!/usr/bin/tclsh
2# good enough pile of Tcl used to assemble the e93 documents "stubs" into HTML documentation
3# This all works, but still needs some work
4
5set auto_path "scripts $auto_path"
6auto_mkindex scripts
7
8proc wrap {srcFile templateFile prev next destfile} \
9{
10	# load the template file
11	set templateChan [open $templateFile]
12	set template [read $templateChan]
13	close $templateChan
14
15	# load the source file
16	set inChan [open $srcFile]
17	set body [read $inChan]
18	close $inChan
19
20	# set the Tcl vars our template needs
21	set date [clock format [clock seconds] -format "%B %Y"]
22
23	# get the page Title out of the HTML
24	set name [getTaggedText "TITLE" $body]
25	regsub -all "&" $body "%amp%" body
26	regsub -all "%name%" $template $name template
27	regsub -all "%date%" $template [clock format [clock seconds] -format "%B %Y"] template
28	regsub -all "%prev%" $template $prev template
29	regsub -all "%next%" $template $next template
30	regsub -all "%body%" $template $body template
31	regsub -all "%amp%" $template {\&} template
32
33	# open a destination file
34	set outfile [open $destfile w+]
35	fconfigure $outfile -translation lf
36	puts $outfile $template
37	close $outfile
38}
39
40proc makeCommandIndex {} {
41	global stubsDir
42
43	# open a destination file
44	set outfile [open $stubsDir/commands.html w+]
45	fconfigure $outfile -translation lf
46
47	puts $outfile "<!-- THIS FILE IS GENERATED: DON'T EDIT -->"
48	puts $outfile "<TITLE>\nCommand Reference\n</TITLE>"
49	puts $outfile "<LINK REL=\"STYLESHEET\" HREF=\"cmdref.css\" CHARSET=\"ISO-8859-1\" TYPE=\"text/css\">"
50	puts $outfile "<CENTER>\n<H1>\nCommand Reference\n</H1>\n</CENTER>"
51	puts $outfile "<CENTER>"
52	puts $outfile "<P>"
53	puts $outfile "<!-- <OBJECT type=\"text/summary\">\nA dictionary of e93 commands\n</OBJECT> -->"
54
55	set letter 65
56	while {$letter<90} \
57	{
58		set theChar [format "%c" $letter]
59		incr letter
60		puts -nonewline $outfile "<A HREF=\"#$theChar\">$theChar</A> <CODE>|</CODE>"
61	}
62	puts $outfile "<A HREF=\"#$theChar\">$theChar</A>"
63	puts $outfile "</P>"
64	puts $outfile "<HR WIDTH=\"750\">"
65	puts $outfile "<!-- Table Start -->\n<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">"
66
67	set letter 65
68	while {$letter<91} \
69	{
70		set theChar [format "%c" $letter]
71		incr letter
72		# UNIX will need both cases globed, for now keep the source files lowercase
73		set commands [lsort [glob -nocomplain $stubsDir/commands/$theChar*.html]]
74
75		if {[llength $commands]>0} \
76		{
77			puts $outfile "<A NAME=\"$theChar\"></$theChar>"
78
79			foreach theFile $commands \
80			{
81				# load the source file
82				set inChan [open $theFile]
83				set body [read $inChan]
84				close $inChan
85
86				# get the page Title out of the HTML
87				set name [getTaggedText "TITLE" $body]
88				# set summary [getTaggedText "SUMMARY" $body]
89				set summary [getTaggedText "OBJECT" $body " type=\"text/summary\""]
90
91				puts $outfile "\t<TR><TD WIDTH=250><A HREF=\"commands/[file tail $theFile]\"><CODE>$name</CODE></A></TD><TD>$summary</TD></TR>"
92			}
93		}
94	}
95	puts $outfile "</TABLE>\n<!-- Table End -->\n</CENTER>"
96
97	close $outfile
98}
99
100proc wrapCommands {} \
101{
102	global stubsDir destDir
103
104	# all commands in alphabetical order
105	set commands [lsort [glob -nocomplain $stubsDir/commands/*.html]]
106	# they all point back to the command index
107	set root {../commands.html}
108	set count 1
109	set prev $root
110	foreach theFile $commands \
111	{
112		set next [file tail [lindex $commands $count]]
113		if {$next == ""} \
114		{
115			set next $root
116		}
117
118		regsub -all "$stubsDir/" $theFile $destDir/ outFileName
119		wrap $theFile templates/commands.html $prev $next $outFileName
120
121		set prev [file tail $theFile]
122		incr count
123	}
124}
125
126proc wrapChapters {} \
127{
128	global stubsDir destDir chapters
129
130	# they all point back to the main index
131	set root index.html
132	set count 1
133	set prev $root
134	foreach theFile $chapters \
135	{
136		set next [file tail [lindex $chapters $count]]
137		if {$next == ""} \
138		{
139			set next $root
140		}
141		regsub -all "$stubsDir/" $theFile $destDir/ outFileName
142		wrap $theFile templates/sections.html $prev $next $outFileName
143		set prev [file tail $theFile]
144		incr count
145	}
146}
147
148proc makeHTMLTOCEntry {theFile} \
149{
150	# load the source file
151	set inChan [open $theFile]
152	# get the page Title out of the HTML
153	set body [read $inChan]
154	set name [getTaggedText "TITLE" $body]
155	# set summary [getTaggedText "SUMMARY" $body]
156	set summary [getTaggedText "OBJECT" $body " type=\"text/summary\""]
157	set theFile [file tail $theFile]
158	close $inChan
159
160	return "<TR>\n<TD WIDTH=300>\n<H3>\n<A HREF=\"$theFile\">$name</A>\n</H3>\n</TD>\n<TD>\n$summary\n</TD>\n</TR>"
161}
162
163proc makeHTMLTOC {TOCFileName} \
164{
165	global stubsDir chapters
166
167	# open a destination file
168	set outfile [open $TOCFileName w+]
169	fconfigure $outfile -translation lf
170
171	puts $outfile "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n<HTML>\n<HEAD>\n<!-- Sitemap 1.0 -->\n</HEAD><BODY>\n<OBJECT type=\"text/site properties\">\n	<param name=\"ImageType\" value=\"Folder\">\n</OBJECT>"
172	puts $outfile "<UL>"
173
174	foreach theFile $chapters \
175	{
176		puts $outfile [makeHTMLTOCEntry $theFile]
177	}
178
179	puts $outfile "</UL>"
180
181	close $outfile
182}
183
184# relative path from this file to the directory that contains the .html stub files
185set stubsDir html
186
187# relative path from this file to the directory to generate the final html into
188set destDir ../docs
189
190file delete -force $destDir
191
192# make the dest dir if its not already there
193file mkdir $destDir/commands
194
195# convert the .xml commands to .html
196source scripts/xml2html.tcl
197
198# wrap the command stubs in their navigation header and footer and link them together
199wrapCommands
200
201# make the "Command Index" chapter
202makeCommandIndex
203
204# the main chapters
205# set chapters [lsort -dictionary [glob $stubsDir/*.html]]
206set chapters "html/about.html html/starting.html html/environment.html html/windows_buffers.html html/cursors.html html/selections.html html/marks.html html/cutcopypaste.html html/scripting.html html/keyboardinput.html html/menuskeybindings.html html/findreplace.html html/undoredo.html html/keynames.html html/StandardKeyboardLayout.html html/crlf.html html/commandconventions.html html/commands.html html/startup.html html/copyright.html"
207
208# wrap the main chapter stubs in their navigation header and footer and link them together
209wrapChapters
210
211# make the TOC, which lists the main chapters
212makeHTMLTOC $destDir/index.html
213# wrap it in the header and footer found in templates/index.html
214wrap $destDir/index.html templates/index.html {} {} $destDir/index.html
215
216# copy any cascading style sheets
217catch {file copy -force [glob $stubsDir/*.css] $destDir/}
218
219# copy images, if any
220catch {file copy -force [glob $stubsDir/*.jpg]  $destDir}
221catch {file copy -force [glob $stubsDir/*.gif]  $destDir}
222catch {file copy -force [glob $stubsDir/commands/*.jpg]  $destDir/commands/}
223catch {file copy -force [glob $stubsDir/commands/*.gif]  $destDir/commands/}
224
225# make a Windows html help project for our files
226source scripts/makeWindowsHelpProject.tcl
227
228exit
229