File: doc.zmm

package info (click to toggle)
zoem 08-248-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,752 kB
  • ctags: 2,074
  • sloc: ansic: 17,928; sh: 789; makefile: 228
file content (321 lines) | stat: -rw-r--r-- 8,211 bytes parent folder | download | duplicates (2)
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

\import{base.zmm}

\switch{\__device__}{
   {html}{}
   {roff}{
    \write{stderr}{txt}{Roff support must be fixed before use!\|\exit}
   }{
   \write{stderr}{txt}{No support for device "\__device__" (in \__fnin__)\|}\exit
   }
}

\:    _section_#3 is the main piece of work in here, together with all
\:    toc-related macros (note the dependencies). When hacking this
\:    stuff, pay attention that names do not shadow, (e.g. when using
\:    \_i_ in different macros), and note that some names are global.
\:    Toc-related macros are all hidden from user, except \"doc::maketoc".
\:    _section_#3 is not a user-level macro, thee should call one of
\:    sec1#2, sec1#3, sec2#2, sec2#3,  sec3#2, sec3#3 etc.

\:    first    argument is toc yes/no ('*' for no)
\:    second   is level,
\:    third    is anchor,
\:    fourth   is caption.

\formatted{

   \def{_section_#3}{\_section_{}{\1}{\2}{\3}}

   \def{_section_#4}{

      \setx{_toc_}{\1}
      \setx{_lev_}{\2}
      \setx{_ank_}{\3}     \: KDE or Dutch style anchor ('anker').
      \setx{_cap_}{\4}

      \ctrinc{doc::\_lev_} \: increment counter associated with this level.

                           \: \_num_ is possibly appended to below.
      \setx{_num_}{\ctrput{doc::1}}
      \setx{_hx_}{}        \: set below; size of header.

                           \:
                           \: reset section numbers if necessary.
                           \:
      \switch{\eqt{cp}{\_lev_}{\_doc_curlevel_}}{
         {-1}
            {  \ctrset{_i_}{\f{+}{\_lev_}{1}}
               \while{\eqt{lq}{\ctrput{_i_}}{\_doc_curlevel_}}{
                  \ctrset{doc::\ctrput{_i_}}{0}
                  \ctrinc{_i_}
               }
            }
         {0}
            {
            }
         {1}
            {  \ctrset{doc::\_lev_}{1}
                           \: ^^^^^^  that line redundant?
               \if{\eqt{ne}{\f{+}{\_doc_curlevel_}{1}}{\_lev_}}{
                  \write
                     {stderr}
                     {txt}
                     {\`{<}Section gap: from \_doc_curlevel_ to \_lev_\|\`{>}}
                  \exit
               }{}
            }
      }

                           \:
                           \: set the header size.
                           \:
      \switch{\_lev_}{
         {1} {\setx{_hx_}{h2}}
         {2} {\setx{_hx_}{h3}}
         {\setx{_hx_}{h4}}
      }

                           \:
                           \: create the section number, e.g. 2.5.4
                           \:
      \ctrset{_i_}{2}
      \while{\eqt{lq}{\ctrput{_i_}}{\_lev_}}{
         \setx{_num_}{\_num_.\ctrput{doc::\ctrput{_i_}}}
         \ctrinc{_i_}
      }

                           \:
                           \: create anchor if not given.
                           \:
      \if{\cmp{eq}{\_ank_}{}}{
         \setx{_ank_}{section_\tr{{from}{.}{to}{_}}{\_num_}}
      }{
      }

                           \:
                           \: write toc entry unless forbidden.
                           \: MQ need to cascade forbidden to nested sections.
                           \:
      \setx{_tocnum_}{
         \if{\eqt{eq}{\_lev_}{1}}{
            \_anch{toc\ctrput{doc::1}}{\_num_}
         }{
            \_num_
         }
      }
      \if{\cmp{eq}{\_toc_}{*}}{}{
         \write{\__fnbase__.zmt}{copy}{
            \!tocentry
               {\_ank_}
               {\_lev_}
               {Section}
               {\_tocnum_}
               {\_cap_}
               \`{n}      \: interpreted by \formatted.
         }
      }
      \write{\__fnbase__.zmr}{copy}{
         \!refload{\_ank_}{
            {level}{\_lev_}
            {type}{Section}
            {num}{\_num_}
            {cap}{\_cap_}
         }
         \`{n}           \: interpreted by \formatted.
      }

      \@{\C\P}\<a name="\_ank_">{}

      \<\_hx_>{
         \iref_quiet{toc\ctrput{doc::1}}{\_num_}
         \~\~\_cap_
      }

      \setx{_doc_curlevel_}{\_lev_}
   }
}

\def{"doc::html-style"}{
\@{
   div.box { border:solid; border-width:thin; width:100%; padding:1em}
   div.flushright { text-align: right }
}}

\set{{modes}{wv}}{}{
   {sec1#2}    {\sec1{}{\1}{\2}}
   {sec1#3}    {\_section_{\1}{1}{\2}{\3}}

   {sec2#2}    {\sec2{}{\1}{\2}}
   {sec2#3}    {\_section_{\1}{2}{\2}{\3}}

   {sec3#2}    {\sec3{}{\1}{\2}}
   {sec3#3}    {\_section_{\1}{3}{\2}{\3}}

   {sec4#2}    {\sec4{}{\1}{\2}}
   {sec4#3}    {\_section_{\1}{4}{\2}{\3}}

   {sec5#2}    {\sec5{}{\1}{\2}}
   {sec5#3}    {\_section_{\1}{5}{\2}{\3}}

   {sec6#2}    {\sec6{}{\1}{\2}}
   {sec6#3}    {\_section_{\1}{6}{\2}{\3}}


   {"doc::html-title"}     {t*i*t*l*e}
   {"doc::html-keywords"}  {}
   {"doc::title"}          {t*i*t*l*e}
   {"doc::year-title"}     {y*e*a*r}
   {"doc::year"}           {y*e*a*r}
   {"doc::day"}            {d*a*y}
   {"doc::month"}          {m*o*n*t*h}
   {"doc::author"}         {a*u*t*h*o*r}
}


\def{hrule}{\<hr noshade size="1"!>}
\def{prule}{\<div style="margin-top:1em">{\<hr noshade size="1"!>}}
\env{center}{\<div align=center>}{\</div>}

\def{"doc::preamble"}{\"doc::preamble"{{toc-and-date}{1}}}

\def{"doc::preamble"#1}{
   \set{%{"doc::preamble"}}{\1}
   \ctrset{doc::sec1}{0}
   \ctrset{doc::sec2}{0}
   \load{\__fnbase__.zmr}
   \setx{_doc_toclist}{\zinsert{\__fnbase__.zmt}}
   \'${roff}{
   }
   \'${html}{
\<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"!>
\<html>
\<!-- Copyright (c) \"doc::year" \"doc::author" --!>
\<head>{
   \<meta name="keywords" content="\"doc::html-keywords""!>
   \<style type="text/css">{
      \"gen::html-style-optional"
      \"gen::html-style-required"
      \"doc::html-style"
   }
   \<title>{\"doc::html-title"}
}

\<body>
\if{\%{"doc::preamble"}{toc-and-date}}{
\<table width="100%" summary="lay-out">{
   \<tr>{
      \<td>{\iref{toc}{TOC}}
      \<td valign=top>{
         \<div class=flushright>{
            \"doc::day" \"doc::month" \"doc::year"
         }
      }
   }
}}{}
\<h1 align=center>{\"doc::title"}
   }
}
\def{"doc::postamble"}{
   \'${html}{\</body>\@{\n}\</html>}
   \'${roff}{}
}

\env{quote}{\<blockquote>}{\</blockquote>}
\env{cite}{\<cite>}{\</cite>}

\def{secref#1}{
   \iref{\1}{\ref{\1}{cap}}
}

\constant{
   {'e}  {&eacute;}        \: 
   {`e}  {&egrave;}        \: 
   {(c)} {&copy;}          \: 
   {+-}  {&plusmn;}        \: 
}

\formatted{

   \ctrset{_toc_prevlevel_}{1}
   \ctrset{_toc_startlevel_}{1}
   \set{_doc_curlevel_}{1}

   \def{tocclose#3}{
      \if{\eqt{lt}{\ctrput{\1}}{\ctrput{\2}}
      }{ \3\ctrinc{\1}\tocclose{\1}{\2}{\3}
      }{
      }
   }

   \def{_doc_tocbegin}{
      \_anch{thetoc}{}
      \begin{itemize}{
         {compact}{1}
         {contiguous}{1}
         {margintop}{0}
         {w1}{1}
         {w2}{1}
      }
   }
   \def{_doc_tocend}{
      \tocclose
         {_toc_startlevel_}
         {_toc_prevlevel_}
         {\end{itemize}}
      \end{itemize}
   }
   \def{"doc::maketoc"}{
      \_doc_tocbegin
      \_doc_toclist
      \_doc_tocend
   }
}


\formatted{

\:
\:    tocentry arguments: anchor level type number caption
\:    MQ toc might need to close several entries at once.
\:
\:    arg 1:  anchor
\:    arg 2:  level
\:    arg 3:  type
\:    arg 4:  number arg.
\:    arg 5:  caption
\:
   \def{tocentry#5}{
      \ctrset{_toc_curlevel_}{\2}

      \switch{\eqt{cp}{\ctrput{_toc_curlevel_}}{\ctrput{_toc_prevlevel_}}}{
         {-1}
            {  \ctrset{_toc_tmplevel_}{\ctrput{_toc_curlevel_}}
               \tocclose
                  {_toc_tmplevel_}
                  {_toc_prevlevel_}
                  {\end{itemize}}
               \item{\4.}
                  \`{s}\_anch{toc_\1}{}\iref{\1}{\5}
            }
         {0}
            {  \item{\4.}
                  \`{s}\_anch{toc_\1}{}\iref{\1}{\5}
            }
         {1}
            {  \item{}
                  \begin{itemize}{
                     {compact}{1}
                     {contiguous}{1}
                     {margintop}{0}
                     {w1}{1}
                     {w2}{1}
                  }
                  \item{\4.}
                     \`{s}\_anch{toc_\1}{}\iref{\1}{\5}
            }
      }
      \ctrset{_toc_prevlevel_}{\ctrput{_toc_curlevel_}}
   }
}