1# This file takes the place of a proper XML parser and a XSL sytlesheet
2# the input XML must contain TITLE and DESCRIPTION
3
4# tagTable assosiates the tag name with the section name that will appear in the html
5# TODO: put all the tag names into TclVars and replace all the literals in this file
6
7# required
8	set	tagTable(TITLE)				"TITLE"
9	set	tagTable(DESCRIPTION)		"DESCRIPTION"
10
11# the SYNOPSIS section is generated
12
13#defaults
14	# defaults to "Built-in" if not specified
15	set	tagTable(TYPE)				"TYPE"
16
17	# defaults to fist sentance of DESCRIPTION if not specified
18	set	tagTable(SUMMARY)			"SUMMARY"
19
20	# default to "None" if not specified
21	set	tagTable(INPUT)				"INPUT"
22	set	tagTable(OUTPUT)			"OUTPUT"
23
24	# defaults to "TITLE always returns a status code of 0." if not specified
25	set	tagTable(STATUS)			"STATUS"
26
27	# 0-N
28	set	tagTable(PARAMETERS)		"PARAMETER"
29	set	tagTable(OPTION)			"OPTION"
30
31	# 0-N PARAMETER tags (it should contain a PARAMDESCRIPTION for each one it includes)
32	set	tagTable(PARAMDESCRIPTION)	"PARAMDESCRIPTION"
33
34	# 0-N OPTION tags (it should contain an OPTDESCRIPTION for each one it includes)
35	set	tagTable(OPTDESCRIPTION)	"OPTDESCRIPTION"
36
37#optional
38	# these sections will not appear unless explcitly included
39	set	tagTable(EXAMPLES)			"EXAMPLES"
40	set	tagTable(LIMITATIONS)		"LIMITATIONS"
41	set	tagTable(SEEALSO)			"SEE ALSO"
42	set	tagTable(LOCATION)			"LOCATION"
43
44proc makeSection {heading contents} \
45{
46	return "<H3>\n$heading\n</H3>\n<BLOCKQUOTE>\n<P>$contents</P>\n</BLOCKQUOTE>"
47}
48
49proc makeHTMLCommands {srcFile destfile} \
50{
51	global tagTable
52
53	# load the source file
54	set inChan [open $srcFile]
55	set body [read $inChan]
56	close $inChan
57
58	set title [getTaggedText "TITLE" $body]
59	set summary [getTaggedText "SUMMARY" $body]
60	if {$summary == ""} \
61	{
62		set summary [getTaggedText "DESCRIPTION" $body]
63		set exp \[^\.<]*
64		regexp -nocase $exp $summary summary
65	}
66
67	set type [getTaggedText "TYPE" $body]
68	if {$type == ""} \
69	{
70		set type "Built-in"
71	}
72
73	# open a destination file
74	set outfile [open $destfile w+]
75	fconfigure $outfile -translation lf
76
77	puts $outfile "<TITLE>$title</TITLE>"
78	puts $outfile "<LINK REL=\"STYLESHEET\" HREF=\"../cmdref.css\" CHARSET=\"ISO-8859-1\" TYPE=\"text/css\">"
79	puts $outfile "<!-- <OBJECT type=\"text/summary\">\n$summary\n</OBJECT> -->"
80	puts $outfile "<TABLE WIDTH=\"750\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">\n<TR>\n<TD WIDTH=\"500\" ALIGN=\"LEFT\"><H1>$title</H1></TD>\n<TD WIDTH=\"250\" ALIGN=\"RIGHT\"><H1>$type</H1></TD>\n</TR>\n</TABLE>"
81
82	# manditory sections
83
84	# build SYNOPSIS section
85	set section SYNOPSIS
86	set contents "<CODE>$title<VAR>"
87	set options [getAllTaggedText OPTION $body]
88	foreach option $options \
89	{
90		append contents " [string trim  $option]"
91	}
92	set parameters [getAllTaggedText PARAMETER $body]
93	foreach parameter $parameters \
94	{
95		append contents " [string trim  $parameter]"
96	}
97	append contents "</VAR></CODE>"
98	puts $outfile [makeSection "$section" $contents]
99
100	# get manditory sections, use default if they are not part of the XML
101	foreach section {DESCRIPTION INPUT OUTPUT} \
102	{
103		set contents [getTaggedText "$section" $body]
104		if {$contents == ""} \
105		{
106			set contents "None"
107		}
108
109		puts $outfile [makeSection "$section" $contents]
110	}
111
112	# build STATUS section
113	set section "STATUS"
114	set contents [getTaggedText $section $body]
115	if {$contents == ""} \
116	{
117		set contents "$title always returns a status code of 0."
118	}
119	puts $outfile [makeSection "$section" $contents]
120
121	# build PARAMETERS section
122	set section PARAMETERS
123	set contents ""
124	if {[llength $parameters]==0} \
125	{
126		set contents "None"
127	}
128	foreach parameter $parameters \
129	{
130		set parameter [string trim $parameter]
131		append contents "<VAR>$parameter</VAR>\n<BLOCKQUOTE>\n<P>[getTaggedText "PARAMDESCRIPTION" $body " name=\"$parameter\""]</P>\n</BLOCKQUOTE>"
132	}
133	puts $outfile [makeSection "$section" $contents]
134
135
136	# build OPTIONS section
137	set section OPTIONS
138	set contents ""
139	if {[llength $options]==0} \
140	{
141		set contents "None"
142	}
143	foreach option $options \
144	{
145		set option [string trim $option]
146		append contents "<VAR>$option</VAR>\n<BLOCKQUOTE>\n<P>[getTaggedText "OPTDESCRIPTION" $body " name=\"$option\""]</P>\n</BLOCKQUOTE>"
147	}
148	puts $outfile [makeSection "$section" $contents]
149
150
151	# optional sections
152	foreach section {EXAMPLES LIMITATIONS SEEALSO LOCATION} \
153	{
154		set contents [getTaggedText "$section" $body]
155		if {$contents != ""} \
156		{
157			puts $outfile [makeSection $tagTable($section) $contents]
158		}
159	}
160
161	close $outfile
162}
163
164proc makeHTMLChapters {srcFile destfile} \
165{
166	# load the source file
167	set inChan [open $srcFile]
168	set body [read $inChan]
169	close $inChan
170
171	set title [getTaggedText "TITLE" $body]
172
173	set summary [getTaggedText "SUMMARY" $body]
174	if {$summary == ""} \
175	{
176		set summary [getTaggedText "BODY" $body]
177		set exp \[^\.<]*
178		regexp -nocase $exp $summary summary
179	}
180
181	# open a destination file
182	set outfile [open $destfile w+]
183	fconfigure $outfile -translation lf
184
185	puts $outfile "<TITLE>$title</TITLE>"
186	puts $outfile "<LINK REL=\"STYLESHEET\" HREF=\"cmdref.css\" CHARSET=\"ISO-8859-1\" TYPE=\"text/css\">"
187	puts $outfile "<!-- <OBJECT type=\"text/summary\">\n$summary\n</OBJECT> -->"
188	puts $outfile "<CENTER>\n<H1>\n$title\n</H1>\n</CENTER>"
189	# if we wanted sections we would do it here
190	puts $outfile "<P>[getTaggedText "BODY" $body]</P>"
191
192	close $outfile
193}
194
195set xmlDir xml
196set htmlDir html
197
198# remove the old html dir
199file delete -force $htmlDir
200
201# make the html dir
202file mkdir $htmlDir/commands
203
204# make the commands
205set sourceFiles [lsort [glob -nocomplain $xmlDir/commands/*.xml]]
206foreach srcFile $sourceFiles \
207{
208	set destfile $htmlDir/commands/[file tail [file rootname $srcFile]].html
209	makeHTMLCommands $srcFile $destfile
210}
211
212# make the chapters
213set sourceFiles [lsort [glob -nocomplain $xmlDir/*.xml]]
214foreach srcFile $sourceFiles \
215{
216	set destfile $htmlDir/[file tail [file rootname $srcFile]].html
217	makeHTMLChapters $srcFile $destfile
218}
219
220# copy any cascading style sheets
221catch {file copy -force [glob $xmlDir/*.css] $htmlDir/}
222
223# copy images, if any
224catch {file copy -force [glob $xmlDir/*.jpg]  $htmlDir}
225catch {file copy -force [glob $xmlDir/*.gif]  $htmlDir}
226catch {file copy -force [glob $xmlDir/commands/*.jpg]  $htmlDir/commands/}
227catch {file copy -force [glob $xmlDir/commands/*.gif]  $htmlDir/commands/}
228
229