Debian Codegraph @

tutorial/0fw_tut.fw

raw ◀ ▶
1 Debian patch touch this file
1 @!345678901234567890123456789012345678901234567890123456789012345678901234567890
2 @!******************************************************************************
3
4 @t vskip 50 mm
5 @t title titlefont centre "FunnelWeb Tutorial Manual Web"
6 @t vskip 10 mm
7 @t title smalltitlefont centre "by Ross N. Williams"
8 @t title smalltitlefont centre "18 April 1999"
9 @t vskip 10 mm
10 @t title smalltitlefont centre "Copyright (c) Ross N. Williams, 1992."
11 @t new_page
12 @t vskip 20 mm
13 @t title titlefont centre "Contents"
14 @t vskip 10 mm
15 @t table_of_contents
16 @t new_page
17
18 @!******************************************************************************
19 @!******************************************************************************
20
21 @A@<FunnelWeb Tutorial Manual Web@>
22
23 This document contains the FunnelWeb source for the
24 FunnelWeb tutorial manual web. When processed by the
25 FunnelWeb macro preprocessor, this file will generate all
26 the text files in the web.
27
28 @!******************************************************************************
29
30 @B@<Copyright Notice@>
31
32 This FunnelWeb source file and all works derived from it
33 (including, but not limited to, the output files and printed
34 documentation that can be extracted using the FunnelWeb
35 preprocessor) are copyright as shown below, and the
36 copyright message in the copyright macro applies to all of
37 these works. The enclosing macro is called at the start of
38 each FunnelWeb output file so that the copyright message
39 appears in each output file as well as in this FunnelWeb
40 source file.
41
42 @$@<Copyright notice/HTML@>@M@{@-
43 Copyright @<(C)@> Ross N. Williams 1992,1999. All rights reserved.@}
44
45 Permission is granted to redistribute and use this manual in
46 any medium, with or without modification, provided that all
47 notices (including, without limitation, the copyright
48 notice, this permission notice, any record of modification,
49 and all legal notices) are preserved on all copies, that all
50 modifications are clearly marked, and that modified versions
51 are not represented as the original version unless all the
52 modifications since the manual's original release by Ross N.
53 Williams (www.ross.net) consist of translations or other
54 transformations that alter only the manual's form, not its
55 content. THIS MANUAL IS PROVIDED "AS IS" AND WITHOUT ANY
56 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
57 LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
58 FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT PERMITTED BY
59 LAW THERE IS ABSOLUTELY NO WARRANTY.
60
61 @!******************************************************************************
62
63 @p maximum_input_line_length = 500
64 @p maximum_output_line_length = 500
65
66 @!******************************************************************************
67
68 @B@<Change Log@>
69
70 @$@<Change log@>@Z@{
71 18-Apr-1999 RNW Converted original 1992 FunnelWeb manual to this web (+ref web).
72 08-May-1999 RNW Documented new HTML +u option.
73 12-May-1999 RNW Documented @@L library feature.
74 13-May-1999 RNW Added the chapter on webmaking.
75 29-Dec-1999 RNW Added sidebar image strut to stop it collapsing.
76 30-Dec-1999 RNW Added the HTML style page.
77 30-Dec-1999 RNW Added the emacs mode page.
78 30-Dec-1999 RNW Changed manual version number scheme.
79 31-Dec-1999 RNW Tweaked the wholistic debugging page.
80 03-Jan-2000 RNW Changed copyright permission notice.
81 06-Jan-2000 RNW Added black background table to sidebar to cope with no-images.
82 09-Jan-2000 RNW Moved main version notice into a macro in the fw include file.
83 @}
84
85 @!******************************************************************************
86
87 @B@<General Notes@>
88
89 @$@<General Information@>@Z@{
90 Checking Procedure
91 ------------------
92 * Spelling check.
93 * WebLint check.
94
95 Shipping Procedure
96 ------------------
97 * Use FunnelWeb to ENEO *.html
98 * Run FunnelWeb. Eliminate all warnings.
99 * Nuke the old web.
100 * Upload the new web.
101 * Briefly surf to check.
102 @}
103
104 FORMATTING NOTE: Experimentation has shown that any page containing a
105 VERBATIM wider than 55 characters must be set to /wide.
106
107 @!******************************************************************************
108
109 @B@<Things To Do@>
110
111 @$@<Things to do@>@Z@{
112 TTDList
113 -------
114
115 @}
116
117 @!******************************************************************************
118
119 @B@<Conversion Of Printed Manual@>
120
121 The FunnelWeb documentation used to be embodied in a single printed manual
122 called The FunnelWeb User's Manual. Here's a record of how the material
123 in the manual ended up in the FunnelWeb documentation webs:
124
125 @$@<Printed Manual Conversion@>@Z@{
126 Printed User Manual Section Where It Ended Up
127 --------------------------- -----------------
128 Preface DELETED
129 Acknowledgements Copyright page of all FunnelWeb webs.
130 Presentation Notes DELETED
131 1. A Tutorial Introduction Tut: Chapters 1..4.
132 2. FunnelWeb Hints. Tut: Chapter 5..6.
133 3. FunnelWeb Definition. Ref: Most of the reference manual.
134 4. FunnelWeb Installation. Mainweb,Dev
135 5. FunnelWeb Administration. DELETED, but 5.2 => Main: stability
136 Glossary Ref: Glossary.
137 References Ref: References.
138
139 Printed Hacker Manual Section Where It Ended Up
140 ----------------------------- -----------------
141 Preface Dev: Home page intro.
142 Acknowledgements Copyright page of all FunnelWeb webs.
143 Presentation Notes DELETED
144 1. FunnelWeb Design Dev: Chapter 2.
145 2. FunnelWeb Implementation Dev: Chapter 3.
146 3. FunnelWeb Modification Dev: Chapter 4.
147 4. FunnelWeb Future Dev: Chapter 5.
148 A. GNU Licence V2 Dev: Chapter 6.
149 References Ref: References.
150 @}
151
152 @!******************************************************************************
153
154 @B@<Graphic Design Notes@>
155
156 These notes record the details of how the graphics in this web were created.
157 This will enable the graphics to be easily recreated, duplicated, or modified
158 if necessary.
159
160 @$@<Graphic Design Notes@>@Z@{
161 Sidebar is 50x1200 colour=(0,0,0).
162
163 Title
164 Bookman Black SSi, 20pt, Antialias
165
166
167 @}
168
169 @!******************************************************************************
170 @!******************************************************************************
171
172 @B@<Parameter Macros@>
173
174 @$@<Body@>@M@{@-
175 <BODY BACKGROUND="@<Bin@>background.gif"
176 BGCOLOR=@<White@>
177 TEXT="#000000"
178 VLINK="#660000"
179 LINK="#FF0000"
180 ALINK="#CC0000">@}
181
182 @$@<FunnelWeb WWW@>@Z@M@{../@}
183 @$@<FunnelWeb Tutorial WWW@>@Z@M@{@}
184 @$@<FunnelWeb Reference WWW@>@Z@M@{../reference/@}
185 @$@<FunnelWeb Developer WWW@>@Z@M@{../developer/@}
186
187 @!******************************************************************************
188
189 @B@<Page Macros@>
190
191 The following macros provide macros to set up the top and bottom of pages.
192
193 @!------------------------------------------------------------------------------
194
195 @$@<SideLink@>@(@2@)@Z@M@{<A HREF="@1"><FONT COLOR="#FFFFFF">@2</FONT></A>@<BR@>@}
196 @$@<SideLink/bold/target@>@(@3@)@M@{@<WindowLink@>@(@1@,@2@,<FONT COLOR="#FFFFFF"><B>@3</B></FONT>@)@<BR@>@}
197 @$@<SideLink/bold@>@(@2@)@M@{<A HREF="@1"><FONT COLOR="#FFFFFF"><B>@2</B></FONT></A>@<BR@>@}
198
199 @$@<Begin FWTutMan margin@>@M@{
200 <TABLE WIDTH="490">
201 <TR>
202 <TD WIDTH="130" VALIGN="top">
203 @<HStrut@>@(130@)@<BR@>
204
205 @<Sidebar menu@>
206
207 </TD>
208 <TD WIDTH="360" VALIGN="top">
209 @<Begin size3@>
210 @}
211
212 @$@<Begin FWTutMan margin/wide@>@M@{
213 <TABLE WIDTH="590">
214 <TR>
215 <TD WIDTH="130" VALIGN="top">
216 @<HStrut@>@(130@)@<BR@>
217
218 @<Sidebar menu@>
219
220 </TD>
221 <TD WIDTH="460" VALIGN="top">
222 @<Begin size3@>
223 @}
224
225 @$@<End FWTutMan margin@>@M@{
226 @<End size3@>
227 </TD>
228 </TR>
229 @<End table@>
230 @}
231
232 @$@<Sidebar menu@>@M@{@-
233 @<Begin size2@>
234 @<BR@>
235 @<RossNet linklogo IMAGE@>@<BR@>
236 @<BR@>
237 @<FunnelWeb linklogo IMAGE@>@<BR@>
238 @<BR@>
239 @<Begin tablecolour@>@(#000000@)
240 @<SideLink/bold/target@>@(@<FunnelWeb Reference WWW@>index.html@,@<FunnelWeb Reference WINDOWNAME@>@,Reference@)
241 @<BR@>
242 @<SideLink/bold/target@>@(@<FunnelWeb Developer WWW@>index.html@,@<FunnelWeb Developer WINDOWNAME@>@,Developer@)
243 @<BR@>
244 @<SideLink/bold@>@(@<FunnelWeb Tutorial WWW@>index.html@,Tutorial@)
245 @<SideLink@>@(@<Intro FILE@>@,@<Intro HEADING/short@>@)
246 @<SideLink@>@(@<Macro FILE@>@,@<Macro HEADING/short@>@)
247 @<SideLink@>@(@<Type FILE@>@,@<Type HEADING/short@>@)
248 @<SideLink@>@(@<Example FILE@>@,@<Example HEADING/short@>@)
249 @<SideLink@>@(@<Hints FILE@>@,@<Hints HEADING/short@>@)
250 @<SideLink@>@(@<Examples FILE@>@,@<Examples HEADING/short@>@)
251 @<SideLink@>@(@<Web FILE@>@,@<Web HEADING/short@>@)
252
253 @<BR@>
254 @<SideLink/bold@>@(@<FunnelWeb_search FILE@>@,SEARCH@)
255 @<End size2@>
256 @<End tablecolour@>
257 @}
258
259 @!------------------------------------------------------------------------------
260
261 @$@<Begin FWTutMan page/H1@>@(@1@)@Z@M@{
262 <HTML>
263 @<Header comment@>
264 <HEAD>
265 <TITLE>@1</TITLE>
266 @<Suppress hyperlink underlining@>
267 </HEAD>
268 @<Body@>
269 @<Begin FWTutMan margin@>
270 @<RunningHeader IMAGE@>
271 @<FWTutMan heading@>@(@1@)
272 @}
273
274 @$@<Begin FWTutMan page/wide/H1@>@(@1@)@Z@M@{
275 <HTML>
276 @<Header comment@>
277 <HEAD>
278 <TITLE>@1</TITLE>
279 @<Suppress hyperlink underlining@>
280 </HEAD>
281 @<Body@>
282 @<Begin FWTutMan margin/wide@>
283 @<RunningHeader IMAGE@>
284 @<FWTutMan heading@>@(@1@)
285 @}
286
287 @!------------------------------------------------------------------------------
288
289 @$@<End FWTutMan page@>@Z@M@{
290 @<HR@>
291 @<Begin size2@>
292 @<Link@>@(mailto:@<Ross webmaster EMAIL@>@,Webmaster@)@<_@>@<_@>@<_@>
293 <A HREF="@<Copyright FILE@>">@<Copyright notice/HTML@></A><BR>
294 @<End size2@>
295 @<End FWTutMan margin@>
296
297 </BODY>
298
299 @<Trailer comment@>
300 </HTML>@}
301
302 @$@<Page title prefix@>@Z@M@{@}
303
304 @!******************************************************************************
305
306 @B@<Images@>
307
308 @$@<RunningHeader IMAGE@>@M@{
309 <A HREF="@<FunnelWeb Reference WWW@>index.html"><IMG SRC="@<Bin@>title.gif"
310 WIDTH="302" HEIGHT="24"
311 BORDER="0" ALT="FunnelWeb Tutorial Manual"
312 HSPACE="0" VSPACE="0"></A>@}
313
314 @!******************************************************************************
315
316 @B@<General Macros@>
317
318 @$@<FWTutMan heading@>@(@1@)@M@{@-
319 @<P@>@<Size5@>@(@1@)@<BR@>@}
320
321 @$@<FWTutMan subheading@>@(@1@)@M@{@-
322 @<P@>@<BR@>@<Size4@>@(@<B@>@(@1@)@)@<BR@>@}
323
324 @$@<FWTutMan subsubheading@>@(@1@)@Z@M@{@-
325 @<P@>@<BR@>@<Size3@>@(@<B@>@(@1@)@)@<BR@>@}
326
327 @$@<FWTutMan subsubsubheading@>@(@1@)@Z@M@{@-
328 @<P@>@<BR@>@<Size3@>@(@<U@>@(@1@)@)@<BR@>@}
329
330 @$@<FWTutMan heading/nospace@>@(@1@)@Z@M@{@-
331 @<Size4@>@(@<B@>@(@1@)@)@<BR@>@}
332
333 @$@<FWTutMan heading/center@>@(@1@)@Z@M@{@-
334 @<P@>@<BR@>
335 @<Begin center@>
336 @<Size5@>@(@<B@>@(@1@)@)@<BR@>
337 @<End center@>@}
338
339
340 @!******************************************************************************
341
342 @$@<FWTutMan keywords and decription@>@{
343 <META NAME="description"
344 CONTENT="The FunnelWeb Tutorial Manual. FunnelWeb is a portable
345 free literate programming tool.">
346
347 <META NAME="keywords"
348 CONTENT="funnelweb,FunnelWeb,funnel,web,
349 tutorial,manual,tutorial manual,
350 literate programming,literate,programming,literate-programming,
351 documentation,
352 macro,macros,preprocessor,macro preprocessor,
353 software,free,freeware,
354 open source,open,source,gnu,gpl,copyleft,
355 web,development,tool,web tool">
356 @}
357
358 @!******************************************************************************
359 @!******************************************************************************
360
361 @A@<HTML Pages@>
362
363 This section contains the HTML pages of the web.
364
365 @!******************************************************************************
366
367 @$@<Index HEADING@>@M@{FunnelWeb Tutorial Manual@}
368 @$@<Index FILE@>@M@{index.html@}
369 @O@<index.html@>@{@-
370 <HTML>
371
372 <HEAD>
373 @<FWTutMan keywords and decription@>
374 @<Suppress hyperlink underlining@>
375 <TITLE>@<Index HEADING@></TITLE>
376 </HEAD>
377
378 @<Body@>
379
380 @<Begin FWTutMan margin@>
381
382 @<RunningHeader IMAGE@>
383
384 @<FunnelWeb manual version notice@>
385
386 @<P@>@<Bigger@>@(T@)HIS TUTORIAL MANUAL provides a friendly
387 introduction to the FunnelWeb literate programming
388 preprocessor
389
390 @<P@>This Tutorial Manual does not provide a definitive
391 description of FunnelWeb, so if you have a specific technical
392 question, you should refer to the @<FunnelWeb Reference Manual@>,
393 which is definitive. To perform a keyword search
394 of the Reference Manual and/or this Tutorial manual, click
395 on SEARCH in the margin.
396
397 @<P@>
398 @<Begin size4@>
399 @<Begin indent@>
400
401 @<HeadStyle@>@(@<Intro FILE@>@,@<Intro HEADING@>@)
402 @<Intro index@>
403
404 @<HeadStyle@>@(@<Macro FILE@>@,@<Macro HEADING@>@)
405 @<Macro index@>
406
407 @<HeadStyle@>@(@<Type FILE@>@,@<Type HEADING@>@)
408 @<Type index@>
409
410 @<HeadStyle@>@(@<Example FILE@>@,@<Example HEADING@>@)
411
412 @<HeadStyle@>@(@<Hints FILE@>@,@<Hints HEADING@>@)
413 @<Hints index@>
414
415 @<HeadStyle@>@(@<Examples FILE@>@,@<Examples HEADING@>@)
416 @<Examples index@>
417
418 @<HeadStyle@>@(@<Web FILE@>@,@<Web HEADING@>@)
419 @<Web index@>
420
421 @<End indent@>
422 @<End size4@>
423
424 @<End FWTutMan page@>
425 @}
426
427 @$@<HeadStyle@>@(@2@)@M@{@<P@><A HREF="@1"><B>@2</B></A><BR>@}
428
429 @!******************************************************************************
430
431 @$@<Intro HEADING@>@M@{@<SH@>@(1@)Introduction@}
432 @$@<Intro HEADING/short@>@M@{@<SH@>@(1@)Introduction@}
433 @$@<Intro FILE@>@M@{intro.html@}
434 @O@<intro.html@>@{@-
435 @<Begin FWTutMan page/H1@>@(@<Intro HEADING@>@)
436
437 @<P@>
438
439 @<Intro index@>
440
441 @<Nav/first@>@(@<Index FILE@>@,@<Index FILE@>@,@<Macro FILE@>@)
442
443 @<End FWTutMan page@>
444 @}
445
446 @$@<Intro index@>@M@{
447 @<Begin size3@>
448 @<Begin indent/narrow@>
449 @<Link@>@(@<Intro_what FILE@>@,@<Intro_what HEADING@>@)@<BR@>
450 @<Link@>@(@<Intro_whatfw FILE@>@,@<Intro_whatfw HEADING@>@)@<BR@>
451 @<Link@>@(@<Intro_name FILE@>@,@<Intro_name HEADING@>@)@<BR@>
452 @<Link@>@(@<Intro_tutorial FILE@>@,@<Intro_tutorial HEADING@>@)@<BR@>
453 @<Link@>@(@<Intro_hello FILE@>@,@<Intro_hello HEADING@>@)@<BR@>
454 @<End indent/narrow@>
455 @<End size3@>
456 @}
457
458 @!==============================================================================
459
460 @$@<Intro_what HEADING@>@M@{@<SH@>@(1.1@)What Is Literate Programming?@}
461 @$@<Intro_what FILE@>@M@{intro_what.html@}
462 @O@<intro_what.html@>@{@-
463 @<Begin FWTutMan page/H1@>@(@<Intro_what HEADING@>@)
464 @<X@>@(literate programming@)
465
466 @<P@>A traditional computer program consists of a text file
467 containing program code. Scattered in amongst the program
468 code are comments which describe the various parts of the
469 code.
470
471 @<P@>In @<NewTerm@>@(literate programming@) the emphasis is
472 reversed. Instead of writing code containing documentation,
473 the literate programmer writes documentation containing
474 code. No longer does the English commentary injected into a
475 program have to be hidden in comment delimiters at the top
476 of the file, or under procedure headings, or at the end of
477 lines. Instead, it is wrenched into the daylight and made
478 the main focus. The @<DQ@>@(program@) then becomes primarily
479 a document directed at humans, with the code being herded
480 between @<DQ@>@(code delimiters@) from where it can be
481 extracted and shuffled out sideways to the language system
482 by literate programming tools.
483
484 @<P@>The effect of this simple shift of emphasis can be so
485 profound as to change one's whole approach to programming.
486 Under the literate programming paradigm, the central
487 activity of programming becomes that of conveying meaning to
488 other intelligent beings rather than merely convincing the
489 computer to behave in a particular way. It is the difference
490 between performing and exposing a magic trick.@<X@>@(magic
491 trick@)
492
493 @<P@>In order to program in a literate style, particular
494 tools are required.@<XX@>@(tools@,literate programming@) The
495 traditional approach (used in the FunnelWeb system) is to
496 have some sort of text-file-in/text-file-out utility that
497 reads a literate program (containing a program commentary
498 peppered with scraps of program text) and writes out a file
499 containing all the program code and a file containing
500 typesetter commands representing the entire input document,
501 documentation, code, and all. See the diagram below.
502
503 @<P@>
504 @<Begin verbatim@>
505 +-----------------------------------------+
506 | File containing the program description |
507 | peppered with scraps of program code. |
508 | This is what the programmer works on. |
509 | (e.g. sloth.web) |
510 +-----------------------------------------+
511 |
512 v
513 o---------------------------o
514 | Literate Programming Tool |
515 o---------------------------o
516 |
517 +------------+-------------+
518 | |
519 v v
520 +------------------+ +--------------------------+
521 | Traditional | | Documentation file |
522 | Computer Program | | (e.g. sloth.tex) |
523 | (e.g. sloth.c) | | (e.g. sloth.html) |
524 +------------------+ +--------------------------+
525
526 @<End verbatim@>
527 @<CaptionTitle@>@(Traditional architecture of literate programming tools.@)
528 @<Begin blockquote@>
529 @<Begin size2@>
530 Literate programming tools could be organized in a number of
531 ways. However, to fit in with current file and command line
532 based environments, most tools conform to the traditional
533 architecture shown here in which the user feeds in a file
534 containing a literate program, and the literate programming
535 utility generates program files and a documentation file.
536 @<End size2@>
537 @<End blockquote@>
538
539 @<P@>Given the coming age of hypertext@<X@>@(hypertext@)
540 systems, this is probably not the best approach. However, it
541 does mesh beautifully with current text files and command
542 line interfaces, the expectation of linear presentations in
543 the documents we read, and the particular requirements of
544 current programming languages and typesetting systems. It is
545 certainly not a bad approach.
546
547 @<P@>With this structure in place, the literate programming
548 system can provide far more than just a reversal of the
549 priority of comments and code. In its full blown form, a
550 good literate programming facility can provide total support
551 for the essential thrust of literate programming, which is
552 that computer programs should be written more for the human
553 reader than for the compiler. In particular, a literate
554 programming system can provide:@<XS@>@(literate
555 programming@,facilities@)
556
557 @<Narrowthing@>@(Re-ordering of code:@,Programming languages
558 often force the programmer to give the various parts of a
559 computer program in a particular
560 order.@<XX@>@(program@,ordering@) For example, the
561 Pascal@<X@>@(Pascal@) programming language@<Paper@>@(BSI82@)
562 imposes the ordering: constants, types, variables,
563 procedures, code. Pascal also requires that procedures
564 appear in an order consistent with the partial ordering
565 imposed by the static call graph (but forward declarations
566 allow this to be bypassed). In contrast, the literate style
567 requires that the programmer be free to present the computer
568 program in any order whatsoever. The facility to do this is
569 implemented in literate programming tools by providing text
570 @<I@>@(macros@) that can be defined and used in any order.@)
571
572 @<Narrowthing@>@(Typeset code and
573 documentation:@,Traditionally program listings are dull
574 affairs consisting of pages of fan-form paper imprinted with
575 meandering coastlines of structured text in a boring font.
576 In contrast, literate programming systems are capable of
577 producing documentation that is superior in two ways. First,
578 because most of the documentation text is fed straight to
579 the typesetter, the programmer can make use of all the power
580 of the underlying typesetter, resulting in documentation
581 that has the same presentation as an ordinary typeset
582 document. Second, because the literate programming utility
583 sees all the code, it can use its knowledge of the
584 programming language and the features of the typesetting
585 language to typeset the program code as if it were appearing
586 in a technical journal. It is the difference between:@)
587
588 @<P@>
589 @<Begin verbatim@>
590 while sloth@<<@>walrus loop
591 sloth:=sloth+1;
592 end loop
593 @<End verbatim@>
594
595 and
596
597 @<Begin indent@>
598 @<B@>@(while@) @<I@>@(sloth@)@<<@>@<I@>@(walrus@) @<B@>@(loop@)@<BR@>
599 @<_@>@<_@>@<_@>@<_@>@<_@>@<_@>@<I@>@(sloth@)=@<I@>@(sloth@)+1;@<BR@>
600 @<B@>@(end@) @<B@>@(loop@)
601 @<End indent@>
602
603 @<P@>Unfortunately, while FunnelWeb provides full
604 typesetting of the documentation, it typesets all of its
605 code in the style of the first of these two examples. To
606 typeset in the style of the second requires knowledge of the
607 programming language, and the current version of FunnelWeb
608 is programming language independent. At a later stage, it is
609 possible that FunnelWeb will be modified to read in a file
610 containing information about the target programming language
611 to be used to assist in typesetting the code properly.
612
613 @<Narrowthing@>@(Cross referencing:@,Because@<X@>@(cross
614 referencing@) the literate tool sees all the code and
615 documentation, it is able to generate extensive cross
616 referencing information in the typeset documentation. This
617 makes the printed program document more easy to navigate and
618 partially compensates for the lack of an automatic searching
619 facility when reading printed documentation.@)
620
621 @<P@>In the end, the details don't matter. The most
622 significant benefit that literate programming offers is
623 @<I@>@(its capacity to transform the state of mind of the
624 programmer@).@<XS@>@(literate programming@,most significant
625 benefit@) It is well known that the act of explaining
626 something can transform one's understanding of it. This is
627 one of the justifications behind the powerful combination of
628 research and teaching in
629 universities @<Paper@>@(Rosovsky90@).@<X@>@(universities@)
630 Similarly, by constantly explaining the unfolding program
631 code in English to an imaginary reader, the programmer
632 transforms his perception of the code, laying it open,
633 prone, to the critical eye.@<XX@>@(explaining@,code@)
634
635 @<P@>The result of this exposure is a higher quality of
636 programming. When exposed to the harsh light of the literate
637 eye, bugs crawl out, special cases vanish, and sloppy code
638 evaporates. As a rule, literate programs take longer to write
639 than ordinary programs, but the total development
640 time@<XX@>@(development@,time@) is the same or less because
641 the time taken to write and document the program carefully
642 is compensated for by a reduced debugging and maintenance
643 time. Thus literate programming does not merely assist in
644 the preparation of documentation, but also makes significant
645 contributes to the process of programming itself. In
646 practice this has turned out to be a contribution far more
647 important than the mere capacity to produce typeset
648 documentation.
649
650 @<P@>For more information on literate programming, the
651 reader is directed to Knuth's early founding work
652 @<Paper@>@(Knuth83@) and @<Paper@>@(Knuth84@). For more
653 recent information refer to @<Paper@>@(Smith91@), which
654 provides a comprehensive bibliography up to 1990.
655
656
657 @<Nav/first@>@(@<Intro FILE@>@,@<Intro FILE@>@,@<Intro_whatfw FILE@>@)
658
659 @<End FWTutMan page@>
660 @}
661
662 @!==============================================================================
663
664 @$@<Intro_whatfw HEADING@>@M@{@<SH@>@(1.2@)What Is FunnelWeb?@}
665 @$@<Intro_whatfw FILE@>@M@{intro_whatfw.html@}
666 @O@<intro_whatfw.html@>@{@-
667 @<Begin FWTutMan page/H1@>@(@<Intro_whatfw HEADING@>@)
668 @<XX@>@(FunnelWeb@,overview@)
669
670 @<P@>FunnelWeb is a particular literate programming system
671 that is implemented by a single C program. FunnelWeb takes
672 as input a single @<TT@>@(.fw@) @<NewTerm@>@(input file@)
673 and writes one or more @<NewTerm@>@(product files@) and a
674 @<NewTerm@>@(documentation file@) (see below).
675
676 @<P@>
677 @<Begin verbatim@>
678 +-----------+
679 | sloth.fw |
680 +-----------+
681 |
682 v
683 o-------------------o
684 | FUNNELWEB Program |
685 o-------------------o
686 |
687 +-----------+-----------+
688 | |
689 v v
690 +----------------+ +--------------------+
691 | Product File | | Documentation File |
692 | (e.g. sloth.c) | | (e.g. sloth.html) |
693 | | | (e.g. sloth.tex) |
694 +----------------+ +--------------------+
695
696 @<End verbatim@>
697 @<CaptionTitle@>@(Architecture of FunnelWeb.@)
698
699 @<P@>In literate programming systems, it is usual to refer
700 to the product file as a @<DQ@>@(program file@). However, as
701 FunnelWeb is a general tool that can be used to prepare all
702 sorts of text files that are not computer programs, the more
703 generic term @<DQ@>@(product file@) was chosen. Product
704 files should be carefully distinguished from the term
705 @<NewTerm@>@(output files@) which refers to all of the
706 output files produced by FunnelWeb.
707
708 @<P@>FunnelWeb is distinguished by the following
709 characteristics:
710
711 @<Narrowthing@>@(Simplicity:@,A@<X@>@(simplicity@) governing
712 design goal of FunnelWeb is to provide a @<I@>@(simple@)
713 tool that could be easily learnt and completely mastered.
714 This manual is thick because it is comprehensive and lingers
715 on the ways in which FunnelWeb can be used. The tool itself
716 is quite simple.@)
717
718 @<Narrowthing@>@(Reliability:@,Another@<X@>@(reliability@)
719 design goal is to provide a tool that will protect the user
720 as much as possible from silly errors. Macro preprocessors
721 are notorious for causing obscure errors. Every attempt has
722 been made in FunnelWeb to keep the syntax robust. For
723 example, in FunnelWeb the syntax of macro calls has been
724 purposely designed to be highly visible so that the reader
725 is always aware when the macro facility is being invoked.@)
726
727 @<Narrowthing@>@(Language and Typesetter
728 Independence:@,Unlike Knuth's
729 original@<XX@>@(language@,independence@)@<XX@>@(typesetter@,independence@)
730 Web system which was specific to the Pascal programming
731 language@<Paper@>@(BSI82@) and the TeX typesetting
732 language@<Paper@>@(Knuth84@), FunnelWeb strives to be
733 language and typesetter independent.
734 FunnelWeb is completely language independent. FunnelWeb
735 input files can be typesetter independent too, and
736 FunnelWeb can generate documentation in TeX and HTML formats.@)
737
738 @<Narrowthing@>@(Portability:@,FunnelWeb@<X@>@(portability@)
739 has been written in the C programming language with great
740 emphasis on portability. FunnelWeb currently runs on the
741 Sun, OpenVMS, IBM PC, and Mac.@)
742
743 @<Narrowthing@>@(Controllable:@,FunnelWeb@<X@>@(controllability@)
744 is an extremely controllable tool. To protect users'
745 investment in source files constructed in the FunnelWeb
746 macro language, the C source code to FunnelWeb has been
747 released under a GNU General Public License
748 (GPL).@<XX@>@(GNU@,license@) This means
749 that it will always be available to everyone. Furthermore,
750 license has been granted for the FunnelWeb User's Manual to
751 be copied freely so long as they are not modified. All this
752 means that FunnelWeb is not going to disappear suddenly.@)
753
754 @<Narrowthing@>@(A Production Tool:@,Above@<X@>@(production
755 tool@) all, FunnelWeb has been designed to be a production
756 tool and every effort has been made to ensure that it will
757 operate effectively in a professional environment. FunnelWeb
758 is @<DQ@>@(open@) and portable. There is a comprehensive
759 user manual. Its error messages are comprehensive. It is
760 fast. Finally, it has been designed with the experience of
761 three years of using FunnelWeb@<_@>V1.@)
762
763 @<Nav@>@(@<Intro_what FILE@>@,@<Intro FILE@>@,@<Intro_name FILE@>@)
764
765 @<End FWTutMan page@>
766 @}
767
768 @!==============================================================================
769
770 @$@<Intro_name HEADING@>@M@{@<SH@>@(1.3@)The Name FunnelWeb@}
771 @$@<Intro_name FILE@>@M@{intro_name.html@}
772 @O@<intro_name.html@>@{@-
773 @<Begin FWTutMan page/H1@>@(@<Intro_name HEADING@>@)
774 @<XX@>@(FunnelWeb@,name@)
775
776 @<P@>The name @<DQ@>@(FunnelWeb@) was chosen because it
777 contains the name @<DQ@>@(WEB@), which is the name of
778 Knuth's system. It was also chosen because it has a
779 distinctly Australian flavour.
780
781 @<P@>Funnel-web spiders@<XX@>@(Funnel-web@,spider@) are
782 found in Northern and Eastern Australia. They are about
783 three to four centimetres long and are very poisonous. The
784 Sydney@<X@>@(Sydney@) Funnel-web spider (@<I@>@(Atrax
785 robustus@)@<X@>@(Atrax robustus@)), common in Sydney, has
786 caused the most trouble and has been responsible for several
787 deaths. Funnel-web spiders love to crawl into temporarily
788 discarded shoes where they later react in a hostile manner
789 to an unsuspecting foot. They are known to hang on once they
790 sink their fangs in. Funnel-web spiders derive their name
791 from the shape of their webs which are horizontally-aligned
792 narrowing tubes, open at one end@<Paper@>@(ANZE@).
793
794 @<P@>The Funnel-web spider, like the tiger
795 snake@<XX@>@(tiger@,snake@) and the white pointer
796 shark,@<XX@>@(white pointer@,shark@) is secretly regarded by
797 Australians as a kind of national
798 treasure.@<XN@>@(Edna@,Everage@)@<XN@>@(Barry@,Humphries@)
799
800 @<P@>
801 @<Begin indent@>
802 @<B@>@(F@) is for Funnel-web@<BR@>
803 Our furry-legged foe.@<BR@>
804 He sleeps in your slipper@<BR@>
805 And breakfasts on toe.@<BR@>
806 --- One verse from @<I@>@(A Megastar's Mantras: Things that Mean a Lot to Me@),@<BR@>
807 @<_@>@<_@>@<_@>@<_@>@<_@>@<_@>@<_@>by Dame Edna Everage@<Paper@>@(Humphries91@).@<BR@>
808 @<End indent@>
809
810 @<Nav@>@(@<Intro_whatfw FILE@>@,@<Intro FILE@>@,@<Intro_tutorial FILE@>@)
811
812 @<End FWTutMan page@>
813 @}
814
815 @!==============================================================================
816
817 @$@<Intro_tutorial HEADING@>@M@{@<SH@>@(1.4@)Using These Tutorials@}
818 @$@<Intro_tutorial FILE@>@M@{intro_tutorial.html@}
819 @O@<intro_tutorial.html@>@{@-
820 @<Begin FWTutMan page/H1@>@(@<Intro_tutorial HEADING@>@)
821 @<X@>@(tutorial@)@<XX@>@(tutorial@,introduction@)
822
823 @<P@>Much of the rest of this manual consists of
824 introductory tutorials on FunnelWeb. Ideally you should have
825 a working version of FunnelWeb in front of you so that you
826 can try out the examples yourself. There is no need to try
827 all the examples, so long as you type in enough to feel
828 comfortable with what you are reading.
829
830 @<P@>For best effect, you should create a new, temporary,
831 empty directory in which to experiment with FunnelWeb. That
832 way, it will be more obvious when FunnelWeb creates an
833 output file. You can either type in the examples in this
834 chapter directly, or copy and paste them directly from
835 this manual or the FunnelWeb test suite. The test files called
836 @<TT@>@(ex01.fw@) through @<TT@>@(ex16.fw@) and
837 @<TT@>@(hi01.fw@) through @<TT@>@(hi10.fw@) contain the
838 examples in the manual.
839
840 @<P@>If you do not yet have an installed copy of FunnelWeb,
841 refer to the main @<FunnelWeb@> web for full details on how
842 to obtain and install a copy of FunnelWeb. If you are not
843 sure if you have an installed copy, try invoking FunnelWeb
844 by giving the command @<DQP@>@(fw@). If this yields an error
845 such as @<DQ@>@(command not found@) then you do not have a
846 properly installed version of FunnelWeb.
847
848 @<Nav@>@(@<Intro_name FILE@>@,@<Intro FILE@>@,@<Intro_hello FILE@>@)
849
850 @<End FWTutMan page@>
851 @}
852
853 @!==============================================================================
854
855 @$@<Intro_hello HEADING@>@M@{@<SH@>@(1.5@)A Hello World Document@}
856 @$@<Intro_hello FILE@>@M@{intro_hello.html@}
857 @O@<intro_hello.html@>@{@-
858 @<Begin FWTutMan page/H1@>@(@<Intro_hello HEADING@>@)
859 @<X@>@(hello world document@)
860
861 @<P@>Just as one starts the process of learning a new
862 programming language with a @<DQ@>@(Hello World@) program,
863 when learning FunnelWeb, you can start with a @<DQ@>@(Hello
864 World@) document. And here it is! Edit a text file called
865 @<TT@>@(hello.fw@) and put the following text in it. (Note:
866 The second character is the letter @<DQ@>@(Oh@), not the
867 digit @<DQ@>@(Zero@)).
868
869 @<P@>
870 @<Begin verbatim@>
871 @@O@@@<<@>hello.txt@@@<>@>@@{Hello World@@+@@}
872 @<End verbatim@>
873
874 @<P@>To @<DQ@>@(run@) this @<DQ@>@(program@), invoke
875 FunnelWeb using the @<DQP@>@(fw@) command as
876 follows.@<X@>@(invoking FunnelWeb@)
877
878 @<P@>
879 @<Begin verbatim@>
880 fw hello
881 @<End verbatim@>
882
883 @<P@>@<I@>@(If this command doesn't work, then chances are
884 that FunnelWeb has not been installed on your machine. Refer
885 to the main @<FunnelWeb@> web for full details on how to
886 obtain and install a copy of FunnelWeb.@)
887
888 @<P@>There should be no errors. If there are, have a look at
889 the listing file @<TT@>@(hello.lis@), which should contain
890 an explanation of the error, and compare the area in the
891 file where the error occurred with the text above. If there
892 are no errors, you will find that the following two files
893 have been created.
894
895 @<P@>
896 @<Begin verbatim@>
897 hello.lis - The LISTING file.
898 hello.txt - The PRODUCT file.
899 @<End verbatim@>
900
901 @<P@>Take a look at @<TT@>@(hello.txt@). It should contain a
902 single line with the text @<TT@>@(Hello World@). Let's take
903 another look at the input file.
904
905 @<P@>
906 @<Begin verbatim@>
907 @@O@@@<<@>hello.txt@@@<>@>@@{Hello World@@+@@}
908 @<End verbatim@>
909
910 @<P@>The whole structure of the input file is controlled by
911 @<DQP@>@(@@@), called the @<NewTerm@>@(special character@),
912 which introduces @<NewTerm@>@(special sequence@)s. A
913 scanner's-eye view of the command line looks like this:
914
915 @<P@>
916 @<Begin verbatim@>
917 @@O @@@<<@> "hello.txt" @@@<>@>
918 @@{ "Hello World" @@+ @@}
919 @<End verbatim@>
920
921 @<P@>The @<TT@>@(@@@) character controls everything. In this
922 file we have six different special sequences that together
923 form a single macro definition. The
924 @<TT@>@(@@@<<@>@)@<X@>@(@@@<<@>@) and
925 @<TT@>@(@@@<>@>@)@<X@>@(@@@<>@>@) delimit the name of the
926 macro. The @<TT@>@(@@O@)@<X@>@(@@O@) signals the start of
927 the macro definition and indicates that the macro is to be
928 connected to a product file with the same name as the macro
929 (This is is why we got a product file when we ran
930 FunnelWeb). The @<TT@>@(@@{@) and
931 @<TT@>@(@@}@)@<X@>@(@@braces@) delimit the body of the
932 macro. Finally, the @<TT@>@(@@+@)@<X@>@(@@+@) instructs that
933 an end of line sequence should be inserted at that point in
934 the product file.
935
936 @<P@>If you think this syntax looks messy, then you're
937 right. It @<I@>@(is@) messy. FunnelWeb @<I@>@(could@) have
938 employed a @<DQ@>@(simpler@) notation in which more of the
939 @<TT@>@(@@@) sequences were eliminated. For example:
940
941 @<P@>
942 @<Begin verbatim@>
943 Warning: This example is NOT legal FunnelWeb.
944
945 #hello.txt{Hello World+}
946 @<End verbatim@>
947
948 @<P@>However, if such a syntax were used, the user (you!)
949 would have to remember that @<TT@>@(#@) starts a new macro.
950 You would also have to remember that the characters
951 @<TT@>@(}@) and @<TT@>@(+@) cannot be used in a macro body
952 without a fuss. And so on. FunnelWeb is messier, but
953 provides one simple rule:@<XX@>@(simple@,rule@)
954 @<I@>@(Nothing special happens unless the special character
955 @<TT@>@(@@@) appears.@)
956
957 @<P@>This means that in FunnelWeb, you can look at large
958 blocks of text in the confidence that (unlike for the C
959 pre-processor@<XX@>@(C@,preprocessor@)) there are no macro
960 calls hidden in there. If there were, there would be an
961 @<TT@>@(@@@) character! (The only exception to this
962 rule occurs where the user has explicitly changed the
963 special character using the @<TT@>@(@@=@)@<X@>@(@@=@)
964 special sequence).
965
966 @<P@>Let's take another look at the hello world program.
967
968 @<P@>
969 @<Begin verbatim@>
970 @@O@@@<<@>hello.txt@@@<>@>@@{Hello World@@+@@}
971 @<End verbatim@>
972
973 @<P@>In its current form, it consists of a single macro
974 definition. This definition, while completely valid on its
975 own, only represents half the power of FunnelWeb. In fact
976 you could say that it is a @<DQ@>@(Hello Northern Hemisphere
977 Program@).@<X@>@(Hello Northern Hemisphere Program@) To turn
978 it into a proper FunnelWeb @<DQ@>@(Hello World@) program, we
979 need to add some documentation.
980
981 @<P@>A FunnelWeb input file consists of a sequence of macro
982 definitions surrounded by a sea of documentation which is
983 just ordinary text. Modify your hello world document so that
984 it looks like this:
985
986 @<P@>
987 @<Begin verbatim@>
988 This hello world document was
989 created by -insert your name here-.
990
991 @@O@@@<<@>hello.txt@@@<>@>@@{Hello World@@+@@}
992
993 It writes out a file called hello.txt
994 containing the string ``Hello World''.
995 @<End verbatim@>
996
997 @<P@>Now run it through FunnelWeb, but this time, add a
998 @<TT@>@(+t@) to the command line.
999
1000 @<P@>
1001 @<Begin verbatim@>
1002 fw hello +t
1003 @<End verbatim@>
1004
1005 @<P@>If all goes well, you should find that you now have
1006
1007 @<P@>
1008 @<Begin verbatim@>
1009 hello.lis - A LISTING file.
1010 hello.tex - A DOCUMENTATION file (in TeX format).
1011 hello.txt - A PRODUCT file.
1012 @<End verbatim@>
1013
1014 @<P@>Take a look at @<TT@>@(hello.txt@). You will find that
1015 it is identical to the @<TT@>@(hello.txt@) of the previous
1016 run. Only macro definitions affect the product files that
1017 FunnelWeb produces (as a result of @<TT@>@(@@O@) macro
1018 definitions). The surrounding documentation has @<I@>@(no@)
1019 effect. In contrast, the new file, @<TT@>@(hello.tex@) (have
1020 a look at it now) which was created as a result of your
1021 adding the @<TT@>@(+t@) option contains a fairly full
1022 representation of the input file. Whereas
1023 @<TT@>@(hello.txt@) is the @<I@>@(product file@) of
1024 FunnelWeb, @<TT@>@(hello.tex@) is the @<I@>@(documentation
1025 file@).
1026
1027 @<P@>Try typesetting the documentation file now using the
1028 TeX typesetting program. Then print it. The following
1029 commands are an example of the sort of commands you will
1030 have to give to do this.
1031
1032 @<P@>
1033 @<Begin verbatim@>
1034 tex hello ! Typeset the doc.
1035 lpr -Pcslw -d hello.dvi ! Print the typeset doc.
1036 @<End verbatim@>
1037
1038 @<P@>If you don't have TeX, you can generate an
1039 HTML documentation file instead. Here's how:
1040
1041 @<P@>
1042 @<Begin verbatim@>
1043 fw hello +u
1044 @<End verbatim@>
1045
1046 @<P@>The documentation should consist of single page containing
1047 the two lines of documentation along with a typeset representation
1048 of the macro. At this point, you have exercised the two main
1049 aspects of FunnelWeb.@<XX@>@(FunnelWeb@,two main aspects@)
1050 Starting with an input file containing macros (or in this
1051 case macro) and documentation, you have successfully
1052 generated a product file based on the macros, and a
1053 documentation file, based on the entire document.
1054
1055 @<P@>The next two sections focus on FunnelWeb's macro
1056 facilities and its typesetting facilities. By tradition, the
1057 generation of program files from a literate text is called
1058 @<NewTerm@>@(Tangling@), and the generation of typeset
1059 documentation is called @<NewTerm@>@(Weaving@). In
1060 FunnelWeb, these two functions are aspects of a single
1061 computer program. However, in Knuth's WEB@<X@>@(WEB@)
1062 system, the two functions are embodied in two separate
1063 computer programs called Tangle and Weave, presumably
1064 because, as everyone knows, @<DQ@>@(it takes two to
1065 Tangle@).
1066
1067 @<Nav/last@>@(@<Intro_tutorial FILE@>@,@<Intro FILE@>@,@<Intro FILE@>@)
1068
1069 @<End FWTutMan page@>
1070 @}
1071
1072 @!******************************************************************************
1073
1074 @$@<Macro HEADING@>@M@{@<SH@>@(2@)Macro Facilities Tutorial@}
1075 @$@<Macro HEADING/short@>@M@{@<SH@>@(2@)Macros@}
1076 @$@<Macro FILE@>@M@{macro.html@}
1077 @O@<macro.html@>@{@-
1078 @<Begin FWTutMan page/H1@>@(@<Macro HEADING@>@)
1079 @<XX@>@(tutorial@,macro facilities@)
1080
1081 @<P@>
1082 @<Macro index@>
1083
1084 @<Nav@>@(@<Intro FILE@>@,@<Index FILE@>@,@<Type FILE@>@)
1085
1086 @<End FWTutMan page@>
1087 @}
1088
1089 @$@<Macro index@>@M@{
1090 @<Begin size3@>
1091 @<Begin indent/narrow@>
1092 @<Link@>@(@<Macro_simple FILE@>@,@<Macro_simple HEADING@>@)@<BR@>
1093 @<Link@>@(@<Macro_times FILE@>@,@<Macro_times HEADING@>@)@<BR@>
1094 @<Link@>@(@<Macro_indent FILE@>@,@<Macro_indent HEADING@>@)@<BR@>
1095 @<Link@>@(@<Macro_additive FILE@>@,@<Macro_additive HEADING@>@)@<BR@>
1096 @<Link@>@(@<Macro_param FILE@>@,@<Macro_param HEADING@>@)@<BR@>
1097 @<Link@>@(@<Macro_library FILE@>@,@<Macro_library HEADING@>@)@<BR@>
1098 @<Link@>@(@<Macro_expansion FILE@>@,@<Macro_expansion HEADING@>@)@<BR@>
1099 @<Link@>@(@<Macro_include FILE@>@,@<Macro_include HEADING@>@)@<BR@>
1100 @<End indent/narrow@>
1101 @<End size3@>
1102 @}
1103
1104 @!==============================================================================
1105
1106 @$@<Macro_simple HEADING@>@M@{@<SH@>@(2.1@)Simple Macros@}
1107 @$@<Macro_simple FILE@>@M@{macro_simple.html@}
1108 @O@<macro_simple.html@>@{@-
1109 @<Begin FWTutMan page/H1@>@(@<Macro_simple HEADING@>@)
1110 @<XX@>@(tutorial@,simple macros@)@<XX@>@(tutorial@,macros simple@)
1111
1112 @<P@>The original @<DQ@>@(Hello World@) program consisted of
1113 a single macro definition.
1114
1115 @<P@>
1116 @<Begin verbatim@>
1117 @@O@@@<<@>hello.txt@@@<>@>@@{Hello World@@+@@}
1118 @<End verbatim@>
1119
1120 @<P@>In fact, this is a rather exceptional macro, as it
1121 causes its expansion to be written to a product file. The
1122 @<TT@>@(@@O@)@<X@>@(@@O@) (for @<B@>@(O@)utput) signals this. In
1123 FunnelWeb, most macros are defined using
1124 @<TT@>@(@@$@).@<X@>@(@@dollar@) This results in a macro
1125 that does not generate a product file, but which can be
1126 called in other macros (including @<TT@>@(@@O@) macros). Let
1127 us expand the hello world program to include some other
1128 macros.
1129
1130 @<P@>
1131 @<Begin verbatim@>
1132 @@O@@@<<@>hello.txt@@@<>@>@@{@@@<<@>Greetings@@@<>@>@@+@@}
1133
1134 @@$@@@<<@>H@@@<>@>==@@{Hello@@}
1135 @@$@@@<<@>W@@@<>@>==@@{World@@}
1136
1137 @@$@@@<<@>Greetings@@@<>@>==@@{@@@<<@>H@@@<>@> @@@<<@>W@@@<>@>@@}
1138 @<End verbatim@>
1139
1140 @<P@>Type in the file and run it through FunnelWeb using the command:
1141
1142 @<P@>
1143 @<Begin verbatim@>
1144 fw hello
1145 @<End verbatim@>
1146
1147 @<P@>The product file (result.out) should look like this:
1148
1149 @<P@>
1150 @<Begin verbatim@>
1151 Hello World
1152 @<End verbatim@>
1153
1154 @<P@>This short program illustrates some of the features of
1155 ordinary macros in FunnelWeb. Consider the @<TT@>@(@@O@)
1156 macro. Instead of containing straight text (@<DQ@>@(Hello
1157 World@)), it now contains the macro call
1158 @<TT@>@(@@@<<@>Greetings@@@<>@>@). A FunnelWeb macro can
1159 be called from within the body of another macro just by
1160 giving the macro name delimited in @<TT@>@(@@@<<@>@) and
1161 @<TT@>@(@@@<>@>@).
1162
1163 @<P@>At the bottom of the file is the definition of the
1164 @<TT@>@(@@@<<@>Greetings@@@<>@>@) macro. The definition
1165 is similar to the definition of @<TT@>@(hello.txt@) except
1166 that it starts with @<TT@>@(@@$@) to indicate that no
1167 product file is desired from this macro (directly). It also
1168 employs the optional @<TT@>@(==@) syntax which has no
1169 semantic impact, but can be used to make definitions
1170 clearer. The body of the
1171 @<TT@>@(@@@<<@>Greetings@@@<>@>@) macro consists of
1172 calls to the @<TT@>@(H@) and @<TT@>@(W@) macros which are
1173 defined immediately above.
1174
1175 @<P@>Note that the macros are not constrained to be defined
1176 in any particular order. One of the main features of
1177 literate programming tools is that they allow the different
1178 parts of the text document being developed (usually a
1179 computer program) to be layed out in any
1180 order.@<XX@>@(order@,program@)@<XX@>@(program@,layout@) So
1181 long as there is a definition somewhere in the input file
1182 for every macro call, FunnelWeb will sort it all out.
1183
1184 @<P@>In fact, FunnelWeb's macro facility is very
1185 simple.@<XX@>@(macro@,bindings@) Unlike many macro
1186 preprocessors which allow macros to define other macros,
1187 FunnelWeb completely finishes parsing and analysing the
1188 macros in the input file before it starts expanding them
1189 into product files. Other preprocessors allow macros to be
1190 redefined like variables (as in, say, TeX@<X@>@(TeX@))
1191 taking on many different values as the macro pre-processor
1192 travels through the input file. In contrast, FunnelWeb has
1193 no concept of @<DQ@>@(different times@) and treats the input
1194 as one huge static orderless, timeless, collection of
1195 definitions. In FunnelWeb, there is only ever one time, and
1196 so there can only ever be one value/definition for each
1197 macro.
1198
1199 @<Nav@>@(@<Macro FILE@>@,@<Macro FILE@>@,@<Macro_times FILE@>@)
1200
1201 @<End FWTutMan page@>
1202 @}
1203
1204 @!==============================================================================
1205
1206 @$@<Macro_times HEADING@>@M@{@<SH@>@(2.2@)Number of Times Called@}
1207 @$@<Macro_times FILE@>@M@{macro_times.html@}
1208 @O@<macro_times.html@>@{@-
1209 @<Begin FWTutMan page/H1@>@(@<Macro_times HEADING@>@)
1210 @<X@>@(number of times called@)@<XX@>@(calls@,number@)@<XX@>@(invocation@,number@)
1211
1212 @<P@>So far we have seen only tiny, degenerate input files.
1213 The next example moves up to the level of @<DQ@>@(trivial@),
1214 but starts to convey the flavour of the way FunnelWeb can be
1215 used in practice. Normally, there would be documentation
1216 text appearing between the macros, but this has been omitted
1217 so as to keep the focus on the macros themselves. Although
1218 the next example is much longer than the previous example,
1219 the only new construct is @<TT@>@(@@-@) which can appear
1220 only at the end of a line, and suppresses
1221 it,@<XX@>@(EOL@,suppression@) preventing it from appearing
1222 in the text. The @<TT@>@(@@-@)@<X@>@(@@-@) construct allows
1223 the text of a macro to be aligned at the left margin, rather
1224 than having the first line hanging at the end of the
1225 @<TT@>@(@@{@). FunnelWeb could have been set up so that
1226 this end of line marker was suppressed. However, it would
1227 have been a special case that would have broken the very
1228 memorable rule @<DQ@>@(the text of a macro is the text
1229 appearing between the @<TT@>@(@@{@) and @<TT@>@(@@}@)@).
1230
1231 @<P@>Type the following text into the file
1232 @<TT@>@(hello.fw@) and run it through FunnelWeb. The file
1233 contains some intentional errors so be sure to type it in
1234 exactly and worry only if FunnelWeb @<I@>@(doesn't@)
1235 generate some errors.
1236
1237 @<P@>
1238 @<Begin verbatim@>
1239 @@O@@@<<@>hello.c@@@<>@>==@@{@@-
1240 @@@<<@>Include Files@@@<>@>
1241 @@@<<@>Include Files@@@<>@>
1242 @@@<<@>Main Program@@@<>@>
1243 @@}
1244
1245 @@$@@@<<@>Main Program@@@<>@>==@@{@@-
1246 main()
1247 {
1248 doit();
1249 }
1250 @@}
1251
1252 @@$@@@<<@>Subroutine@@@<>@>==@@{@@-
1253 void doit()
1254 {
1255 int i;
1256 for (i=0;i@<<@>10;i++)
1257 {
1258 @@@<<@>Print@@@<>@>
1259 @@@<<@>Print@@@<>@>
1260 }
1261 }@@}
1262
1263 @@$@@@<<@>Print@@@<>@>==@@{@@-
1264 printf("Hello World!");
1265 printf("\n");@@}
1266
1267 @@$@@@<<@>Scan@@@<>@>==@@{scanf@@}
1268
1269 @@$@@@<<@>Include Files@@@<>@>==@@{@@-
1270 #include @<<@>stdio.h@<>@>
1271 #include @<<@>stdlib.h@<>@>@@}
1272 @<End verbatim@>
1273
1274 @<P@>What happened? Well, if you haven't typed the file in
1275 properly, you may get some miscellaneous syntax errors. Fix
1276 these before continuing. If the file has been correctly
1277 typed, you should be faced with some error messages to do
1278 with the number of times some of the macros are called.
1279
1280 @<P@>By default, FunnelWeb insists that each macro defined
1281 is invoked exactly once. However, the file above defines
1282 macros that are used more than once and a macro that is not
1283 used at all. Let us examine the errors.
1284
1285 @<P@>First, we see that FunnelWeb has alerted us to the fact
1286 that the @<TT@>@(Include Files@) macro has been called
1287 twice. Once alerted to this, a quick look at the program
1288 convinces us that calling the macro twice is a mistake, and
1289 that one of the calls should be deleted.
1290
1291 @<P@>Second, we note that FunnelWeb has alerted us to the
1292 fact that the @<TT@>@(@@@<<@>subroutine@@@<>@>@) macro
1293 is never called. Again, a quick look at the program tells us
1294 that this is a mistake (and a very common one in the use of
1295 FunnelWeb), and that a call to the
1296 @<TT@>@(@@@<<@>subroutine@@@<>@>@) macro should be
1297 inserted just above the call to the @<TT@>@(@@@<<@>Main
1298 Program@@@<>@>@) macro in the definition of
1299 @<TT@>@(@@@<<@>hello.c@@@<>@>@).
1300
1301 @<P@>These two cases demonstrate why these checks have been
1302 placed in FunnelWeb. It is nearly always acceptable for a
1303 macro to be called once. However, if a macro is not called
1304 at all, or called more than once, this is often a sign that
1305 the user has made a mistake.
1306
1307 @<P@>These checks have a dark side too. In addition to the
1308 errors mentioned above, FunnelWeb has generated two similar
1309 errors that do not help us.
1310
1311 @<P@>First, we are alerted to the fact that the
1312 @<TT@>@(@@@<<@>print@@@<>@>@) macro has been called
1313 twice. Clearly, in this case, this is not a problem, and so
1314 here FunnelWeb's fussiness is a nuisance.
1315
1316 @<P@>Second, we are alerted to the fact that the
1317 @<TT@>@(@@@<<@>scan@@@<>@>@) macro has never been
1318 called. Like the @<TT@>@(@@@<<@>print@@@<>@>@) macro,
1319 this macro was defined as a notational convenience, and
1320 clearly it does not matter here if it is not used. Again,
1321 FunnelWeb is being a nuisance.
1322
1323 @<P@>The four cases above demonstrate the light and dark
1324 side of FunnelWeb's insistence that each macro be called
1325 exactly once. To resolve the conflict without reducing the
1326 strength of the checking, FunnelWeb provides two special
1327 sequences @<TT@>@(@@Z@) (for @<B@>@(Z@)ero) and @<TT@>@(@@M@)
1328 (for @<B@>@(M@)any) that can be attached to macro definitions.
1329 Presence of the @<TT@>@(@@Z@)@<XX@>@(@@Z@,tutorial@) tag
1330 allows the designated macro to be called zero times.
1331 Presence of the @<TT@>@(@@M@)@<XX@>@(@@M@,tutorial@) tag
1332 allows the designated macro to be called more than once. A
1333 single macro may carry both tags. It is always true that all
1334 macros are allowed to be called exactly once.
1335
1336 @<P@>Here is the revised program with the errors fixed, by
1337 eliminating or adding macro calls, or by adding tags. Try
1338 processing the file now. There should be no errors.
1339
1340 @<P@>
1341 @<Begin verbatim@>
1342 @@O@@@<<@>hello.c@@@<>@>==@@{@@-
1343 @@@<<@>Include Files@@@<>@>
1344 @@@<<@>Function@@@<>@>
1345 @@@<<@>Main Program@@@<>@>
1346 @@}
1347
1348 @@$@@@<<@>Main Program@@@<>@>==@@{@@-
1349 main()
1350 {
1351 doit();
1352 }
1353 @@}
1354
1355 @@$@@@<<@>Function@@@<>@>==@@{@@-
1356 void doit()
1357 {
1358 int i;
1359 for (i=0;i@<<@>10;i++)
1360 {
1361 @@@<<@>Print@@@<>@>
1362 @@@<<@>Print@@@<>@>
1363 }
1364 }@@}
1365
1366 @@$@@@<<@>Print@@@<>@>@@M==@@{@@-
1367 printf("Hello World!");
1368 printf("\n");@@}
1369
1370 @@$@@@<<@>Scan@@@<>@>@@Z==@@{scanf@@}
1371
1372 @@$@@@<<@>Include Files@@@<>@>==@@{@@-
1373 #include @<<@>stdio.h@<>@>
1374 #include @<<@>stdlib.h@<>@>@@}
1375 @<End verbatim@>
1376
1377 @<Nav@>@(@<Macro_simple FILE@>@,@<Macro FILE@>@,@<Macro_indent FILE@>@)
1378
1379 @<End FWTutMan page@>
1380 @}
1381
1382 @!==============================================================================
1383
1384 @$@<Macro_indent HEADING@>@M@{@<SH@>@(2.3@)Indentation@}
1385 @$@<Macro_indent FILE@>@M@{macro_indent.html@}
1386 @O@<macro_indent.html@>@{@-
1387 @<Begin FWTutMan page/H1@>@(@<Macro_indent HEADING@>@)
1388 @<XX@>@(indentation@,macro calls@)
1389
1390 @<P@>The body of the @<TT@>@(print@) macro of the previous
1391 example contains two lines of text. A literal substitution
1392 of this macro's body in its context would result in:
1393
1394 @<P@>
1395 @<Begin verbatim@>
1396 {
1397 printf("Hello World!");
1398 printf("\n");
1399 printf("Hello World!");
1400 printf("\n");
1401 }
1402 @<End verbatim@>
1403
1404 @<P@>But instead, it comes out as (have a look at this part
1405 of @<TT@>@(hello.c@) now):
1406
1407 @<P@>
1408 @<Begin verbatim@>
1409 {
1410 printf("Hello World!");
1411 printf("\n");
1412 printf("Hello World!");
1413 printf("\n");
1414 }
1415 @<End verbatim@>
1416
1417 @<P@>The explanation is that FunnelWeb indents each line of
1418 multiline macros by the level of indentation at the point of
1419 call. This means that, as in the case above, program texts,
1420 which are usually highly indented, come out looking
1421 @<DQ@>@(right@).
1422
1423 @<P@>In other circumstances, where the model of the text is
1424 one dimensional, FunnelWeb's indentation could become an
1425 impediment or even a danger. In these cases, it can be
1426 switched off by including the FunnelWeb
1427 @<NewTerm@>@(pragma@) line
1428
1429 @<P@>
1430 @<Begin verbatim@>
1431 @@p indentation = none
1432 @<End verbatim@>
1433
1434 @<P@>anywhere in the input file.
1435
1436 @<P@>One of the design goals of FunnelWeb is to allow the
1437 user total control over the product files. This contrasts
1438 with the approach of Knuth's WEB@<X@>@(WEB@) system
1439 @<Paper@>@(Knuth83@) (upon which FunnelWeb is based), which
1440 mangles the input text at the Pascal@<X@>@(Pascal@) program
1441 syntax level, truncating identifiers, converting the text to
1442 upper case, and paragraphing text. Here is an example of
1443 part of a Pascal program produced by
1444 WEB@<XX@>@(output@,WEB@) (from page@<_@>14 of
1445 @<Paper@>@(Knuth83@)):
1446
1447 @<P@>
1448 @<Begin verbatim@>
1449 IF R=0 THEN XREF[P]:=XREFPTR ELSE
1450 XMEM[R].XLINKFIELD:=XREFPTR;END;{:51}
1451 {58:}FUNCTION IDLOOKUP(T:EIGHTBITS):NAMEPOINTER;
1452 LABEL 31;
1453 VAR I:0..LONGBUFSIZE;H:0..HASHSIZE;K:0..MAXBYTES;
1454 W:0..1;
1455 L:0..LONGBUFSIZE;P:NAMEPOINTER;BEGIN
1456 L:=IDLOC-IDFIRST;{59:}
1457 H:=BUFFER[IDFIRST];I=IDFIRST+1;
1458 WHILE I@<<@>IDLOC DO BEGIN H:=(H+H+BUFFER[I])MOD
1459 HASHSIZE;I=I+1;END{:59};
1460 @<End verbatim@>
1461 @! CHECKED: I can't believe I actually typed this mess in.
1462 @! Had to add in some line breaks to make it fit in web page.
1463
1464 @<P@>Knuth's theory is that the program generated by a
1465 literate programming system should be treated as object code
1466 and hence should look like object code too.@<X@>@(object
1467 code@) While this may be an admirable approach in the long
1468 run, the present programming environment is one of faulty
1469 compilers and buggy tools. The FunnelWeb view is that, in
1470 this environment, the programmer needs all the help he can
1471 get and that therefore he should be allowed total control
1472 over the product file. Another reason for FunnelWeb's
1473 providing total control over the product file, is that
1474 FunnelWeb is intended to be target language independent, and
1475 so even if Knuth's view were adopted, it would not be clear
1476 what a legitimate transformation of the text could be.
1477
1478 @<Nav@>@(@<Macro_times FILE@>@,@<Macro FILE@>@,@<Macro_additive FILE@>@)
1479
1480 @<End FWTutMan page@>
1481 @}
1482
1483 @!==============================================================================
1484
1485 @$@<Macro_additive HEADING@>@M@{@<SH@>@(2.4@)Additive Macros@}
1486 @$@<Macro_additive FILE@>@M@{macro_additive.html@}
1487 @O@<macro_additive.html@>@{@-
1488 @<Begin FWTutMan page/H1@>@(@<Macro_additive HEADING@>@)
1489 @<XX@>@(additive@,macros@)
1490
1491 @<P@>Sometimes it is convenient to build up the definition
1492 of a macro in stages throughout the input file. In
1493 FunnelWeb, this can be done using an @<NewTerm@>@(additive
1494 macro@). An additive macro is identical to an ordinary macro
1495 except that@<XX@>@(tutorial@,==@)@<XX@>@(tutorial@,+=@)
1496
1497 @<P@>
1498 @<Begin list/ordered@>
1499 @<Item@> It has @<TT@>@(+=@) instead of @<TT@>@(==@).
1500 @<Item@> It can be defined in one or more parts throughout the input file.
1501 The definition of the macro is the concatenation of all the parts in the
1502 order in which they appear.
1503 @<End list/ordered@>
1504
1505 @<P@>The following example shows how additive macros can be
1506 used to scatter and regroup information, in this case
1507 assisting in the lucid construction of a data
1508 abstraction@<XX@>@(data@,abstraction@) in a language
1509 (Pascal@<X@>@(Pascal@)) that does not support them
1510 explicitly.
1511
1512 @<P@>
1513 @<Begin verbatim@>
1514 @@!******************************
1515
1516 @@O@@@<<@>prog.pas@@@<>@>==@@{@@-
1517 program adt(input,output);
1518 @@@<<@>Types@@@<>@>
1519 @@@<<@>Variables@@@<>@>
1520 @@@<<@>Procedures@@@<>@>
1521 begin startproc; end.
1522 @@}
1523
1524 @@!******************************
1525
1526 @@$@@@<<@>Types@@@<>@>+=@@{@@-
1527 type buffer_type =
1528 record
1529 length : integer;
1530 buf : array[1..100] of char;
1531 end;
1532 @@}
1533
1534 @@$@@@<<@>Variables@@@<>@>+=@@{@@-
1535 bigbuf : buffer_type;
1536 @@}
1537
1538 @@$@@@<<@>Procedures@@@<>@>+=@@{@@-
1539 procedure buf_init (var b : buffer_type )
1540 {Body of buf_init}
1541 procedure buf_add (var b : buffer_type; ch : char)
1542 {Body of buf_add}
1543 procedure buf_get (var b : buffer_type; var ch : char)
1544 {Body of buf_get}
1545 @@}
1546
1547 @@!******************************
1548
1549 @@$@@@<<@>Types@@@<>@>+=@@{@@-
1550 type complex_type = record r,i : real; end;
1551 @@}
1552
1553 @@$@@@<<@>Procedures@@@<>@>+=@@{@@-
1554 procedure cm_set (var c: complex_type; a,b: real)
1555 {Body of cm_set}
1556 procedure cm_add (a,b: complex_type; var c: complex_type)
1557 {Body of cm_add}
1558 {Other procedures and functions}
1559 @@}
1560
1561 @@!******************************
1562
1563 {...more pieces of program...}
1564
1565 @@!******************************
1566 @<End verbatim@>
1567
1568 @<P@>It is important to remember that the definition of each
1569 macro does not change throughout the input file. FunnelWeb
1570 parses the entire input file and assembles all the macro
1571 definitions before it even starts to expand macros. As a
1572 result, each additive macro can only have one definition,
1573 and that definition is the concatenation of all its parts.
1574
1575 @<P@>The example above shows how additive macros can be used
1576 to rearrange the presentation of a computer program in the
1577 order in which the user wishes to discuss it rather than the
1578 order in which the compiler requires that it be consumed. It
1579 is easy, however, to abuse the feature of additive macros.
1580 In many cases, the same effect can be obtained more clearly
1581 by replacing each part of an additive macro in-situ using
1582 uniquely named non-additive macros, and then collect them
1583 together as a group at the point where the additive macro is
1584 called. Doing this is more work, and is more error prone,
1585 but can result in a clearer exposition. The following
1586 program illustrates this alternative approach.
1587
1588 @<P@>
1589 @<Begin verbatim@>
1590 @@!******************************
1591
1592 @@O@@@<<@>prog.pas@@@<>@>==@@{@@-
1593 program adt(input,output);
1594 @@@<<@>Types@@@<>@>
1595 @@@<<@>Variables@@@<>@>
1596 @@@<<@>Procedures@@@<>@>
1597 begin startproc; end.
1598 @@}
1599
1600 @@$@@@<<@>Types@@@<>@>==@@{@@-
1601 @@@<<@>Buffer type@@@<>@>
1602 @@@<<@>Complex type@@@<>@>
1603 @@}
1604
1605 @@$@@@<<@>Variables@@@<>@>==@@{@@-
1606 @@@<<@>Buffer variable@@@<>@>
1607 @@}
1608
1609 @@$@@@<<@>Procedures@@@<>@>==@@{@@-
1610 @@@<<@>Buffer procedures@@@<>@>
1611 @@@<<@>Complex procedures@@@<>@>
1612 @@}
1613
1614 @@!******************************
1615
1616 @@$@@@<<@>Buffer type@@@<>@>==@@{@@-
1617 type buffer_type = record
1618 length : integer;
1619 buf : array[1..100] of char;
1620 end;
1621 @@}
1622
1623 @@$@@@<<@>Buffer variable@@@<>@>==@@{@@-
1624 bigbuf : buffer_type;
1625 @@}
1626
1627 @@$@@@<<@>Buffer procedures@@@<>@>==@@{@@-
1628 procedure buf_init(var b : buffer_type)
1629 {Body of buf_init}
1630 procedure buf_add(var b : buffer_type; ch : char)
1631 {Body of buf_add}
1632 procedure buf_get(var b : buffer_type; var ch : char)
1633 {Body of buf_get}
1634 @@}
1635
1636 @@!******************************
1637
1638 @@$@@@<<@>Complex type@@@<>@>==@@{@@-
1639 type complex_type = record r,i : real; end;
1640 @@}
1641
1642 @@$@@@<<@>Complex procedures@@@<>@>+=@@{@@-
1643 procedure cm_set(var c: complex_type; a,b : real)
1644 {Body of cm_set}
1645 procedure cm_add(a,b : complex_type; var c: complex_type)
1646 {Body of cm_add}
1647 {Other procedures and functions}
1648 @@}
1649
1650 @@!******************************
1651
1652 {...more pieces of program...}
1653
1654 @@!******************************
1655 @<End verbatim@>
1656
1657 @<P@>One of advantages of FunnelWeb (and literate
1658 programming in general) is that (as shown above) it allows
1659 the user to lay out the program in whatever order is
1660 desired@<XX@>@(program@,layout@) with near total
1661 independence from the ordering requirements of the target
1662 programming language.
1663
1664 @<P@>Additive macros are allowed to be tagged with
1665 @<TT@>@(@@Z@) and @<TT@>@(@@M@) just as other macros can,
1666 but the tags must appear only on the first definition of the
1667 macro. Additive macros cannot be connected directly to
1668 product files.
1669
1670 @<Nav@>@(@<Macro_indent FILE@>@,@<Macro FILE@>@,@<Macro_param FILE@>@)
1671
1672 @<End FWTutMan page@>
1673 @}
1674
1675 @!==============================================================================
1676
1677 @$@<Macro_param HEADING@>@M@{@<SH@>@(2.5@)Parameterized Macros@}
1678 @$@<Macro_param FILE@>@M@{macro_param.html@}
1679 @O@<macro_param.html@>@{@-
1680 @<Begin FWTutMan page/H1@>@(@<Macro_param HEADING@>@)
1681 @<XX@>@(parameterized@,macros@)
1682
1683 @<P@>No self-respecting macro preprocessor would be complete
1684 without some form of macro parameterization, and FunnelWeb
1685 is no exception. FunnelWeb allows each macro to have from
1686 zero to nine formal parameters@<XX@>@(formal@,parameters@)
1687 named @<TT@>@(@@1@)@<X@>@(@@1...@), @<TT@>@(@@2@),
1688 @<TT@>@(@@3@), @<TT@>@(@@4@), @<TT@>@(@@5@), @<TT@>@(@@6@),
1689 @<TT@>@(@@7@), @<TT@>@(@@8@), and @<TT@>@(@@9@).
1690
1691 @<P@>To define a macro with one or more parameters, insert a
1692 formal parameter list@<XX@>@(formal@,parameters@) just after
1693 the macro name in the macro definition. Because macro
1694 parameters have fixed names
1695 (@<TT@>@(@@1@)@<LDots@>@<TT@>@(@@9@)), there is no need to
1696 specify the names of formal parameters in the formal
1697 parameter list. All that need be conveyed is how many
1698 parameters the macro has. Here is an example of the
1699 definition of a macro having three parameters:
1700
1701 @<P@>
1702 @<Begin verbatim@>
1703 @@$@@@<<@>While loop@@@<>@>@@(@@3@@)@@M==@@{@@-
1704 @@1
1705 while (@@2)
1706 {
1707 @@3
1708 }
1709 @@}
1710 @<End verbatim@>
1711
1712 @<P@>To call a parameterized macro, an actual
1713 parameter@<XX@>@(actual@,parameters@) list must be supplied
1714 that contains exactly the same number of actual parameters
1715 as there are formal parameters in the definition of the
1716 macro being called. An actual parameter list is delimited by
1717 @<TT@>@(@@(@)@<X@>@(@@(@) and @<TT@>@(@@)@),@<X@>@(@@}@) and
1718 parameters are @<I@>@(separated@) by
1719 @<TT@>@(@@,@).@<X@>@(@@,@) The actual parameters themselves
1720 are general FunnelWeb expressions (see the
1721 @<FunnelWeb Reference Manual@> for the exact syntax) and can
1722 be inserted into the list directly or can be delimited by
1723 @<TT@>@(@@"@)@<X@>@(@@"@) so as to allow some white space to
1724 assist in formatting the actual parameters. Here are some
1725 examples of calls of the @<TT@>@(While loop@) macro defined
1726 above.
1727
1728 @<P@>
1729 @<Begin verbatim@>
1730 @@! First form of actual parameters
1731 @@! without whitespace and double quotes.
1732 @@@<<@>While loop@@@<>@>@@(@@-
1733 x=1;@@,x@<<@>=10@@,printf("X=%u\n",x);@@)
1734
1735 @@! Second form of actual parameters. The double
1736 @@! quotes allow non-active whitespace that helps
1737 @@! to lay out the actual parameters neatly. This
1738 @@! call is functionally identical to the one above.
1739 @@@<<@>While loop@@@<>@>@@(
1740 @@"x:=1;@@" @@,
1741 @@"x@<<@>=10@@" @@,
1742 @@"printf("X=%u\n",x);@@" @@)
1743
1744 @@! The two forms can be mixed in a single call.
1745 @@@<<@>While loop@@@<>@>@@(x=1;@@,x@<<@>=10@@,
1746 @@"printf("X=%u\n",x);@@" @@)
1747 @<End verbatim@>
1748
1749 @<P@>A few rules about parameterized macros are worth
1750 mentioning. Macros that do not have any parameters must have
1751 no formal or actual parameter lists.@<XS@>@(parameter
1752 list@,absent@) Additive macros can have parameters, but the
1753 formal parameter list must appear in the first definition
1754 part only.
1755
1756 @<P@>Here is another example of the use of parameterized
1757 macros. This time, parameters and macro calls are used in a
1758 FunnelWeb input file that constructs an O(n)
1759 representation of a song@<X@>@(song@)@<X@>@(twelve bugs of
1760 christmas@) whose full size is O(n^2) in the number n of
1761 unique lines.@<X@>@(rec.humor.funny@)@<XN@>@(Pat@,Scannel@)
1762
1763 @<P@>
1764 @<Begin verbatim@>
1765 @@O@@@<<@>Twelve_bugs.txt@@@<>@>==@@{@@-
1766 The Twelve Bugs of Christmas
1767 ----------------------------
1768 @@@<<@>Verse@@@<>@>@@(@@"first@@" @@,@@@<<@>1@@@<>@>@@)
1769 @@@<<@>Verse@@@<>@>@@(@@"second@@" @@,@@@<<@>2@@@<>@>@@)
1770 @@@<<@>Verse@@@<>@>@@(@@"third@@" @@,@@@<<@>3@@@<>@>@@)
1771 @@@<<@>Verse@@@<>@>@@(@@"fourth@@" @@,@@@<<@>4@@@<>@>@@)
1772 @@@<<@>Verse@@@<>@>@@(@@"fifth@@" @@,@@@<<@>5@@@<>@>@@)
1773 @@@<<@>Verse@@@<>@>@@(@@"sixth@@" @@,@@@<<@>6@@@<>@>@@)
1774 @@@<<@>Verse@@@<>@>@@(@@"seventh@@" @@,@@@<<@>7@@@<>@>@@)
1775 @@@<<@>Verse@@@<>@>@@(@@"eighth@@" @@,@@@<<@>8@@@<>@>@@)
1776 @@@<<@>Verse@@@<>@>@@(@@"ninth@@" @@,@@@<<@>9@@@<>@>@@)
1777 @@@<<@>Verse@@@<>@>@@(@@"tenth@@" @@,@@@<<@>A@@@<>@>@@)
1778 @@@<<@>Verse@@@<>@>@@(@@"eleventh@@" @@,@@@<<@>B@@@<>@>@@)
1779 @@@<<@>Verse@@@<>@>@@(@@"twelfth@@" @@,@@@<<@>C@@@<>@>@@)
1780
1781 This song appeared in the internet newsgroup
1782 rec.humor.funny on 24-Dec-1991. It was contributed
1783 by Pat Scannell (scannell@@@@darkstar.ma30.bull.com).
1784 @@}
1785
1786 @@$@@@<<@>Verse@@@<>@>@@(@@2@@)@@M==@@{@@-
1787 For the @@1 bug of Christmas, my manager said to me
1788 @@2
1789 @@}
1790
1791 @@$@@@<<@>1@@@<>@>@@M==@@{@@-
1792 See if they can do it again.@@}
1793 @@$@@@<<@>2@@@<>@>@@M==@@{@@-
1794 Ask them how they did it and@@+@@@<<@>1@@@<>@>@@}
1795 @@$@@@<<@>3@@@<>@>@@M==@@{@@-
1796 Try to reproduce it@@+@@@<<@>2@@@<>@>@@}
1797 @@$@@@<<@>4@@@<>@>@@M==@@{@@-
1798 Run with the debugger@@+@@@<<@>3@@@<>@>@@}
1799 @@$@@@<<@>5@@@<>@>@@M==@@{@@-
1800 Ask for a dump@@+@@@<<@>4@@@<>@>@@}
1801 @@$@@@<<@>6@@@<>@>@@M==@@{@@-
1802 Reinstall the software@@+@@@<<@>5@@@<>@>@@}
1803 @@$@@@<<@>7@@@<>@>@@M==@@{@@-
1804 Say they need an upgrade@@+@@@<<@>6@@@<>@>@@}
1805 @@$@@@<<@>8@@@<>@>@@M==@@{@@-
1806 Find a way around it@@+@@@<<@>7@@@<>@>@@}
1807 @@$@@@<<@>9@@@<>@>@@M==@@{@@-
1808 Blame it on the hardware@@+@@@<<@>8@@@<>@>@@}
1809 @@$@@@<<@>A@@@<>@>@@M==@@{@@-
1810 Change the documentation@@+@@@<<@>9@@@<>@>@@}
1811 @@$@@@<<@>B@@@<>@>@@M==@@{@@-
1812 Say it's not supported@@+@@@<<@>A@@@<>@>@@}
1813 @@$@@@<<@>C@@@<>@>@@M==@@{@@-
1814 Tell them it's a feature@@+@@@<<@>B@@@<>@>@@}
1815 @<End verbatim@>
1816
1817 @<Nav@>@(@<Macro_additive FILE@>@,@<Macro FILE@>@,@<Macro_library FILE@>@)
1818
1819 @<End FWTutMan page@>
1820 @}
1821
1822 @!==============================================================================
1823
1824 @$@<Macro_library HEADING@>@M@{@<SH@>@(2.6@)Library Macros@}
1825 @$@<Macro_library FILE@>@M@{macro_library.html@}
1826 @O@<macro_library.html@>@{@-
1827 @<Begin FWTutMan page/H1@>@(@<Macro_library HEADING@>@)
1828 @<XX@>@(library@,macros@)
1829
1830 @<P@>FunnelWeb provides a library macro feature that allows
1831 you to redefine macros. Normally, FunnelWeb will generate an
1832 error if you attempt to define a macro of a particular name
1833 more than once. However, if you attach a different number of
1834 @<TT@>@(@@L@) markers (up to five) to each definition,
1835 FunnelWeb accepts the multiple definitions, and at tangle time
1836 uses the definition with the least number of @<TT@>@(@@L@)s.
1837 For example:
1838
1839 @<P@>
1840 @<Begin verbatim@>
1841 @@$@@@<<@>ugly duckling@@@<>@>@@L@@L@@{egg@@}
1842 @@$@@@<<@>ugly duckling@@@<>@>@@{swan@@}
1843 @@$@@@<<@>ugly duckling@@@<>@>@@L@@{signet@@}
1844 @<End verbatim@>
1845
1846 @<P@>In this example, the ugly duckling macro will expand
1847 to @<TT@>@(swan@) because the swan definition has the least
1848 number of @<TT@>@(@@L@) markers (@<ie@>the lowest library level).
1849
1850 @<P@>No two definitions may have the same name and level, but
1851 definitions having the same name, but differing levels, are
1852 independent of each other and can have different call number
1853 constraints. They can even be defined additively,
1854 with their multipart definitions interlaced. For example:
1855
1856 @<P@>
1857 @<Begin verbatim@>
1858 @@$@@@<<@>ugly duckling@@@<>@>@@L@@L+=@@{eg@@}
1859 @@$@@@<<@>ugly duckling@@@<>@>@@L+=@@{sig@@}
1860 @@$@@@<<@>ugly duckling@@@<>@>@@L@@L+=@@{g@@}
1861 @@$@@@<<@>ugly duckling@@@<>@>@@L+=@@{net@@}
1862 @<End verbatim@>
1863
1864 @<P@>Here, two macros having the same
1865 name (@<TT@>@(ugly duckling@)) are defined at library
1866 levels one and two. Each of these macros is defined in
1867 two additive parts. The first macro is at level two
1868 and has the value @<TT@>@(egg@). The second macro is
1869 at level one and has the value @<TT@>@(signet@).
1870 If this macro name were referenced by another macro, it
1871 would be expanded to @<TT@>@(signet@), as this is the
1872 value of the definition with the lowest library level.
1873
1874 @<FWTutMan subheading@>@(Uses Of Library Macros@)
1875
1876 @<P@>When using FunnelWeb as a macro preprocessor (@<eg@>for
1877 the generation of HTML webs), it's convenient to be able to
1878 define include files that contain large numbers of commonly
1879 used macro definitions. However, sometimes, some macros must
1880 be redefined. By tagging such macros in the include file
1881 using @<TT@>@(@@L@), such redefinition is made possible.
1882
1883 @<Nav@>@(@<Macro_param FILE@>@,@<Macro FILE@>@,@<Macro_expansion FILE@>@)
1884
1885 @<End FWTutMan page@>
1886 @}
1887
1888 @!==============================================================================
1889
1890 @$@<Macro_expansion HEADING@>@M@{@<SH@>@(2.7@)Macro Expansion@}
1891 @$@<Macro_expansion FILE@>@M@{macro_expansion.html@}
1892 @O@<macro_expansion.html@>@{@-
1893 @<Begin FWTutMan page/H1@>@(@<Macro_expansion HEADING@>@)
1894 @<XX@>@(macro@,expansion@)
1895
1896 @<P@>One of the strengths of FunnelWeb is that, when writing
1897 product files, it does not attempt to evaluate any text
1898 expression (@<eg@>text block, parameter, macro call) in
1899 memory@<XX@>@(memory@,use of@) and then write the result
1900 out. Instead, it always writes out what it is expanding
1901 dynamically and directly. This means that you need not
1902 fear defining macros that expand to huge amounts of text and
1903 then calling those macros in other macros, or passing those
1904 huge macros as parameters to other macros. In all cases,
1905 FunnelWeb expands directly to the product file, and there
1906 can be no danger in running out of memory during expansion
1907 (except for running out of stack space and other marginally
1908 used resources in pathological cases).
1909
1910 @<P@>The only thing to remember in this regard is that
1911 FunnelWeb always stores the entire @<I@>@(input@) file and
1912 all included files, in their entirety in memory, for the
1913 duration of the run.
1914
1915 @<P@>Here is an example, that illustrates how robust
1916 FunnelWeb is:
1917
1918 @<P@>
1919 @<Begin verbatim@>
1920 @@! FunnelWeb copes well with the following
1921 @@! macro definitions. (Providing that it has
1922 @@! a little over ten megabytes of memory).
1923
1924 @@O@@@<<@>woppa.txt@@@<>@>==@@{@@-
1925 @@@<<@>Quote@@@<>@>@@(@@@<<@>Humungeous@@@<>@>@@)@@+@@}
1926
1927 @@$@@@<<@>Quote@@@<>@>@@(@@1@@)==@@{"@@1"@@}
1928
1929 @@$@@@<<@>Humungeous@@@<>@>==@@{@@-
1930 ...Ten Megabytes of Text...
1931 @@}
1932 @<End verbatim@>
1933
1934 @<Nav@>@(@<Macro_library FILE@>@,@<Macro FILE@>@,@<Macro_include FILE@>@)
1935
1936 @<End FWTutMan page@>
1937 @}
1938
1939 @!==============================================================================
1940
1941 @$@<Macro_include HEADING@>@M@{@<SH@>@(2.8@)Include Files@}
1942 @$@<Macro_include FILE@>@M@{macro_include.html@}
1943 @O@<macro_include.html@>@{@-
1944 @<Begin FWTutMan page/H1@>@(@<Macro_include HEADING@>@)
1945 @<XX@>@(include@,files@)
1946
1947 @<P@>FunnelWeb provides a nested include file facility that
1948 can be used for a number of purposes. When FunnelWeb runs
1949 into a single line containing the special sequence
1950 @<TT@>@(@@i@)@<X@>@(@@i@) followed by a blank, followed by a
1951 file name, it reads in the designated file and replaces the
1952 line containing the command (including the end of line
1953 marker at the end of the line) with the entire contents of
1954 the designated file. For example, if there was a file called
1955 @<TT@>@(camera.txt@) containing the two
1956 lines:@<XX@>@(poem@,camera@)@<XX@>@(animal@,poem@)
1957
1958 @<P@>
1959 @<Begin verbatim@>
1960 'Cos I shoot with a camera instead of a gun.
1961 The animals flock to be petted and fed,
1962 @<End verbatim@>
1963
1964 @<P@>and another file called @<TT@>@(poem.fw@)
1965 containing the following four lines@<X@>@(shooting@)
1966
1967 @<P@>
1968 @<Begin verbatim@>
1969 I like to go shooting, it's a whole lot of fun,
1970 @@i camera.txt
1971 Cos they know my camera isn't loaded with lead.
1972 - RNW, 04-Jan-1991.
1973 @<End verbatim@>
1974
1975 @<P@>Then, if FunnelWeb were to process @<TT@>@(poem.fw@),
1976 the result would be as if FunnelWeb had read in:
1977
1978 @<P@>
1979 @<Begin verbatim@>
1980 I like to go shooting, it's a whole lot of fun,
1981 'Cos I shoot with a camera instead of a gun.
1982 The animals flock to be petted and fed,
1983 'Cos they know my camera isn't loaded with lead.
1984 - RNW, 04-Jan-1991.
1985 @<End verbatim@>
1986
1987 @<P@>FunnelWeb expands include files before it starts
1988 scanning and parsing the included text. The result is that
1989 include files can contain anything that can be found in a
1990 FunnelWeb file. The following example illustrates the level
1991 at which the include mechanism operates. If
1992 @<TT@>@(main.fw@) contains
1993
1994 @<P@>
1995 @<Begin verbatim@>
1996 @@O@@@<<@>output.dat@@@<>@>==@@{@@-
1997 @@i inc.fw
1998 This is the text of the sloth macro.
1999 @@}
2000 @<End verbatim@>
2001
2002 @<P@>and inc.fw contains
2003
2004 @<P@>
2005 @<Begin verbatim@>
2006 @@@<<@>Sloth@@@<>@>
2007 @@}
2008
2009 @@$@@@<<@>Sloth@@@<>@>==@@{@@-
2010 @<End verbatim@>
2011
2012 @<P@>Then if FunnelWeb were applied to @<TT@>@(main.fw@), it would see:
2013
2014 @<P@>
2015 @<Begin verbatim@>
2016 @@O@@@<<@>output.dat@@@<>@>==@@{@@-
2017 @@@<<@>Sloth@@@<>@>
2018 @@}
2019
2020 @@$@@@<<@>Sloth@@@<>@>==@@{@@-
2021 This is the text of the sloth macro.
2022 @@}
2023 @<End verbatim@>
2024
2025 @<P@>which it would process in the normal manner. The only
2026 special sequence processing that takes place at a level
2027 lower than include files is the processing of the
2028 @<TT@>@(@<<@>special@<>@>=@<<@>newspecial@<>@>@)
2029 sequence which changes the special character.@<XX@>@(special
2030 character@,changing@)
2031
2032 @<P@>A few other facts about include files are worth
2033 mentioning here. Include files inherit the directory
2034 specification supplied using the @<TT@>@(+I@) command line
2035 option. The special character is saved at the start of each
2036 include file and restored to its previous value at the end
2037 of each include file. Include files can be nested up to ten
2038 levels. Recursive included files@<XX@>@(include
2039 files@,recursive@) will always cause an infinite recursion
2040 as there is no bottoming out mechanism available. Include
2041 files must contain an integer number of lines (@<ie@>the
2042 last line must be terminated with an end of line marker).
2043 Once FunnelWeb has seen @<DQP@>@(@@i@<_@>@) at the start of a
2044 line, it will grab the rest of the line raw and treat it as
2045 a file name. There is no place on the line for things like
2046 FunnelWeb comments (see later) or extraneous text.
2047
2048 @<P@>Include files can be used for many purposes, but are
2049 particularly useful for hauling in macro
2050 libraries.@<XX@>@(macro@,libraries@)
2051
2052 @<Nav/last@>@(@<Macro_expansion FILE@>@,@<Macro FILE@>@,@<Macro FILE@>@)
2053
2054 @<End FWTutMan page@>
2055 @}
2056
2057 @!******************************************************************************
2058
2059 @$@<Type HEADING@>@M@{@<SH@>@(3@)Typesetting Facilities Tutorial@}
2060 @$@<Type HEADING/short@>@M@{@<SH@>@(3@)Typesetting@}
2061 @$@<Type FILE@>@M@{type.html@}
2062 @O@<type.html@>@{@-
2063 @<Begin FWTutMan page/H1@>@(@<Type HEADING@>@)
2064
2065 @<P@>
2066 @<Type index@>
2067
2068 @<Nav@>@(@<Macro FILE@>@,@<Index FILE@>@,@<Example FILE@>@)
2069
2070 @<End FWTutMan page@>
2071 @}
2072
2073 @$@<Type index@>@M@{
2074 @<Begin size3@>
2075 @<Begin indent/narrow@>
2076 @<Link@>@(@<Type_overview FILE@>@,@<Type_overview HEADING@>@)@<BR@>
2077 @<Link@>@(@<Type_independence FILE@>@,@<Type_independence HEADING@>@)@<BR@>
2078 @<Link@>@(@<Type_hierarchy FILE@>@,@<Type_hierarchy HEADING@>@)@<BR@>
2079 @<Link@>@(@<Type_printed FILE@>@,@<Type_printed HEADING@>@)@<BR@>
2080 @<Link@>@(@<Type_literals FILE@>@,@<Type_literals HEADING@>@)@<BR@>
2081 @<Link@>@(@<Type_header FILE@>@,@<Type_header HEADING@>@)@<BR@>
2082 @<Link@>@(@<Type_comments FILE@>@,@<Type_comments HEADING@>@)@<BR@>
2083 @<End indent/narrow@>
2084 @<End size3@>
2085 @}
2086
2087 @!==============================================================================
2088
2089 @$@<Type_overview HEADING@>@M@{@<SH@>@(3.1@)Overview@}
2090 @$@<Type_overview FILE@>@M@{type_overview.html@}
2091 @O@<type_overview.html@>@{@-
2092 @<Begin FWTutMan page/H1@>@(@<Type_overview HEADING@>@)
2093 @<XX@>@(overview@,typesetting@)
2094
2095 @<P@>The previous sections of this manual have focused solely on the
2096 macro facilities of FunnelWeb (which are more or less covered
2097 completely). As a result, the example documents you have
2098 seen so far have been gross distortions of @<DQ@>@(normal@)
2099 FunnelWeb documents. Normal FunnelWeb documents
2100 often contain as much
2101 documentation as code.@<X@>@(documentation vs
2102 code@)@<X@>@(code vs documentation@) While there
2103 are applications where FunnelWeb can be used solely as a
2104 macro preprocessor, many applications will use its
2105 typesetting facilities as well.
2106
2107 @<P@>The macro definitions discussed in the macro tutorial
2108 completely define the contents of the product files that
2109 FunnelWeb will generate. These macro definitions can be
2110 arranged in any order, and nothing external to them can
2111 affect the contents of the product files. The macros can be
2112 thought of as a group of self-contained islands.
2113
2114 @<P@>Although FunnelWeb will can process the macros all on
2115 their own, the full power of FunnelWeb is realized only when
2116 the macros are surrounded by a sea of documentation. This
2117 sea can take two forms: directives and free text. Some of
2118 the directives control things such as the maximum input line
2119 length. However, most of them are typesetting directives
2120 that affect the printed documentation. Thus a FunnelWeb
2121 document can be viewed as a sequence of @<NewTerm@>@(macro
2122 definitions@), @<NewTerm@>@(directives@), and
2123 @<NewTerm@>@(free text@).
2124
2125 @<P@>Unlike the product files which consist of unscrambled
2126 macro calls, the documentation file is more or less a direct
2127 representation of the input file. Each part of the input
2128 file appears in the documentation file in the order in which
2129 it appears in the input file. However, each different kind
2130 of part is typeset [Note: Here the term @<DQ@>@(typeset@)
2131 is used loosely to refer to FunnelWeb's generation of
2132 typesetter commands for each construct in the input file.
2133 Strictly, the term should be used only to describe the
2134 actions of a typesetter program (@<eg@>TeX).] in a
2135 different manner. Macros are typeset in a particular style,
2136 with the macro body appearing in @<TT@>@(tt font@) (see some
2137 FunnelWeb printed documentation for an example). Typesetter
2138 directives have specific defined effects (more later). Free
2139 text is typeset exactly as it is, except that each block of
2140 text between blank lines is filled and justified as a
2141 paragraph.
2142
2143 @<P@>The following example demonstrates how all this works.
2144 Type in the following as @<TT@>@(example.fw@) and run it
2145 through FunnelWeb with the command @<DQP@>@(fw@<_@>example@<_@>+t@).
2146 The @<DQP@>@(+t@) instructs FunnelWeb to generate a
2147 documentation file called @<TT@>@(example.tex@). Run the
2148 file through TeX and print it. Examine the files
2149 @<TT@>@(example.out@) and @<TT@>@(example.tex@).
2150
2151 @<P@>
2152 @<Begin verbatim@>
2153 You are reading some free text before the
2154 macro. Free text can consist of any text
2155 (not containing the FunnelWeb special
2156 character) including typesetter commands
2157 such as $, %, #, and TeX which
2158 will be typeset to appear exactly as
2159 they do in the input file!
2160 Look out! Here comes a macro!
2161
2162 @@O@@@<<@>example.out@@@<>@>==@@{@@-
2163 This text is part of
2164 a macro definition.
2165 @@}
2166
2167 This is free text following the macro. This
2168 sentence contains two @@{inline@@} typesetter
2169 @@/directives@@/. Now here is a non-inline
2170 typesetting directive.
2171
2172 @@t new_page
2173
2174 This sentence will appear on the next page.
2175 @<End verbatim@>
2176
2177 @<P@>At the top of the @<TT@>@(example.tex@) documentation
2178 file will be a set of TeX macro definitions. The TeX code
2179 corresponding to the input above appears at the end of the
2180 file. It should look something like this.
2181
2182 @<P@>
2183 @<Begin verbatim@>
2184 You are reading some free text before the
2185 macro. Free text can consist of any text
2186 (not containing the FunnelWeb special
2187 character) including typesetter commands
2188 such as \$, \%, \#, and \TeX{} which
2189 will be typeset to appear exactly as
2190 they do in the input file!
2191 Look out! Here comes a macro!
2192
2193 \fwbeginmacro
2194 \fwfilename{example.out,1}\fwequals
2195 \fwodef \fwbtx[This text is part of
2196 a macro definition.
2197 ]fwetx=%
2198 \fwcdef
2199 \fwbeginmacronotes
2200 \fwisafile{This macro is attached to an output file.}
2201 \fwendmacronotes
2202 \fwendmacro
2203
2204 This is free text following the macro. This sentence contains
2205 two \fwlit{inline} typesetter \fwemp{directives}.
2206 Now here is a non-inline typesetting directive.
2207
2208 \fwnewpage
2209
2210 This sentence will appear on the next page.
2211 @<End verbatim@>
2212
2213 @<P@>The following points explain the @<TT@>@(example.tex@)
2214 file.
2215
2216 @<Narrowthing@>@(You don't have to know TeX:@,If you don't
2217 know TeX, don't pay too much attention to this section. You
2218 don't need to know TeX to use FunnelWeb.@)
2219
2220 @<Narrowthing@>@(In order:@,FunnelWeb has merely transformed
2221 the input. It hasn't rearranged it.@)
2222
2223 @<Narrowthing@>@(Free text:@,Most of the free text has been
2224 simply copied over. The TeX typesetter justifies and fills
2225 all paragraphs fed to it by default, so most of the text has
2226 just been copied verbatim.@)
2227
2228 @<Narrowthing@>@(TeX codes:@,The characters and sequences
2229 which TeX treats as special have been neutralized in the
2230 documentation file. For example, @<DQP@>@($@) has become
2231 @<DQP@>@(\$@). By default, FunnelWeb allows the user to
2232 write any text as free text and not have to worry about
2233 accidentally invoking typesetter features.@)
2234
2235 @<Narrowthing@>@(fw sequences:@,The @<TT@>@(fw@) sequences
2236 (@<eg@>@<TT@>@(\fwbeginmacro@)) invoke TeX macros
2237 defined earlier in the documentation file (and not shown
2238 here).@)
2239
2240 @<Narrowthing@>@(The macro:@,The macro is typeset using a
2241 set of predefined TeX macros. See the printed documentation
2242 to see what this looks like on paper.@)
2243
2244 @<Narrowthing@>@(Typesetter directives:@,Unlike the TeX
2245 command sequences (which were neutralized), the FunnelWeb
2246 typesetter directives turn into TeX macro calls. For
2247 example, @<DQP@>@(@@{inline@@}@) became
2248 @<DQP@>@(\fwlit{inline}@).@)
2249
2250 @<P@>FunnelWeb can also generate documentation in HTML form.
2251 Just replace the @<TT@>@(+t@) option with the @<TT@>@(+u@) option.
2252
2253 @<P@>In summary, FunnelWeb produces typeset documentation
2254 that transforms, but does not reorder, the input file.
2255 Macros are typeset in a specific style. FunnelWeb typesetter
2256 directives have particular well-defined effects. Free text
2257 is filled and justified, but will otherwise appear in the
2258 printed documentation exactly as it appears in the input
2259 file.
2260
2261 @<Nav/first@>@(@<Type FILE@>@,@<Type FILE@>@,@<Type_independence FILE@>@)
2262
2263 @<End FWTutMan page@>
2264 @}
2265
2266 @!==============================================================================
2267
2268 @$@<Type_independence HEADING@>@M@{@<SH@>@(3.2@)Typesetter Independence@}
2269 @$@<Type_independence FILE@>@M@{type_independence.html@}
2270 @O@<type_independence.html@>@{@-
2271 @<Begin FWTutMan page/H1@>@(@<Type_independence HEADING@>@)
2272 @<XX@>@(typesetter@,independence@)
2273
2274 @<P@>FunnelWeb encourages
2275 typesetter independence by neutralizing all TeX (or HTML) control
2276 sequences before writing them out. The result is that you
2277 don't have worry about upsetting or depending on TeX by
2278 accidentally including some special character or sequence.
2279 By default your input file is @<NewTerm@>@(typesetter
2280 independent@).
2281
2282 @<P@>This scheme differs from other literate programming
2283 tools (including very early versions of FunnelWeb) which
2284 copy their free text directly to the documentation file,
2285 the justification being that the programmer can use the full
2286 power of the typesetter language to describe the program.
2287 The disadvantages of doing this are first that the
2288 programmer is required to know the typesetting language and
2289 second that the input file becomes typesetter dependent.
2290 FunnelWeb avoids these problems by nobbling the free text
2291 be default.
2292
2293 @<P@>However, FunnelWeb does provide a trapdoor for those
2294 who want their free text to be fed directly to TeX. To open
2295 the trapdoor, simply include one of the following pragmas
2296 somewhere in your input file.
2297
2298 @<P@>
2299 @<Begin verbatim@>
2300 @@p typesetter = tex
2301 @@p typesetter = html
2302 @<End verbatim@>
2303
2304 @<P@>See the @<FunnelWeb Reference Manual@> for more information.
2305
2306 @<P@>FunnelWeb leaves the degree to which the user wishes to
2307 bind a particular document to a particular typesetter up to
2308 the user. In some cases, the extra typesetting power may
2309 compensate for the lack of portability. However, as a rule,
2310 it is best to avoid typesetter-specific commands, so as to
2311 allow your input files to be formatted at a later date for
2312 different typesetters. FunnelWeb includes a number of its
2313 own typesetter commands so as to support
2314 typesetter-independent input files. The following sections
2315 describe some of these commands. In particular, the next
2316 section describes the most powerful FunnelWeb typesetting
2317 directives which allow the user to structure the document
2318 hierarchically.
2319
2320 @<Nav@>@(@<Type_overview FILE@>@,@<Type FILE@>@,@<Type_hierarchy FILE@>@)
2321
2322 @<End FWTutMan page@>
2323 @}
2324
2325 @!==============================================================================
2326
2327 @$@<Type_hierarchy HEADING@>@M@{@<SH@>@(3.3@)Hierarchical Structure@}
2328 @$@<Type_hierarchy FILE@>@M@{type_hierarchy.html@}
2329 @O@<type_hierarchy.html@>@{@-
2330 @<Begin FWTutMan page/H1@>@(@<Type_hierarchy HEADING@>@)
2331 @<XX@>@(hierarchical@,structure@)
2332
2333 @<P@>The tree structure is one of the most effective
2334 structuring tools that exists, deriving its power from the
2335 principal of divide and conquor. So effective is it that the
2336 internal organization of most technical books are tree
2337 structures which are concisely summarized in the table of
2338 contents. In contrast, computer programs are usually
2339 presented as flat sequences of text to be consumed by an
2340 anonymous compiler.
2341
2342 @<P@>In order to bring program documentation up to the
2343 structural sophistication commonplace in technical books,
2344 FunnelWeb provides five levels of section
2345 headings@<XX@>@(section@,headings@) implemented by the five
2346 special sequences @<TT@>@(@@A@),@<X@>@(@@A...@)
2347 @<TT@>@(@@B@), @<TT@>@(@@C@), @<TT@>@(@@D@), and
2348 @<TT@>@(@@E@). These must always appear at the start of a
2349 line. @<TT@>@(@@A@) is the highest level section (@<eg@>like
2350 LaTeX's @<TT@>@(\chapter@)) and @<TT@>@(@@E@) is the
2351 lowest level section (@<eg@>like LaTeX's
2352 @<TT@>@(\subsubsubsection@)). Section headings can
2353 appear anywhere in the free text of a FunnelWeb input file
2354 (@<ie@>anywhere except inside a macro definition).
2355
2356 @<P@>Each section heading@<XX@>@(name@,section@) in a
2357 FunnelWeb document has an associated name. The name of a
2358 section can be provided explicitly by supplying it delimited
2359 by @<TT@>@(@@@<<@>@) and @<TT@>@(@@@<>@>@) immediately
2360 after the section sequence (@<eg@>@<TT@>@(@@A@)), or
2361 implicitly by not providing an explicit name, in which case
2362 the section takes the name of the first macro defined
2363 between the section header in question and the following
2364 section header. An error is generated if a section has not
2365 been given an explicit name and does not contain any macro
2366 definitions. Here are some example headings:
2367
2368 @<P@>
2369 @<Begin verbatim@>
2370 @@A@@@<<@>Feed the Penguins and Save the World@@@<>@>
2371 @@B@@@<<@>Feed the Penguins@@@<>@>
2372 @@C@@@<<@>Feed the little penguins@@@<>@>
2373 @@C@@@<<@>Feed the big penguins@@@<>@>
2374 @@B@@@<<@>Save the World@@@<>@>
2375 @@C@@@<<@>Save Europe@@@<>@>
2376 @@C@@@<<@>Save Africa@@@<>@>
2377
2378 @@C This heading hasn't been given an
2379 explicit name, but will inherit the name
2380 @<TT@>@(Save the rest of the world@)
2381 from the macro definition below.
2382
2383 @@$@@@<<@>Save the rest of the world@@@<>@>@@Z==@@{...@@}
2384 @<End verbatim@>
2385
2386 @<P@>The feature of having unnamed sections inherit the name
2387 of the first macro defined within their scope is present
2388 because a common style of writing in FunnelWeb is to have
2389 one section per macro definition. Because, under this style,
2390 each section describes a single macro, it usually turns out
2391 that the macro name makes a good name for the section too.
2392 The inheritance mechanism prevents duplication of the
2393 name.@<XX@>@(section name@,inheritance@)
2394
2395 @<P@>Apart from the requirement that each section have an
2396 explicit or implicit name and that its special sequence
2397 appear at the start of a line, the only other restriction on
2398 section headings is that a section heading at level n
2399 cannot appear immediately after a section heading at level
2400 n-1 or less. In other words, the hierarchy cannot be
2401 broken. For example, an @<TT@>@(@@C@) cannot appear after an
2402 @<TT@>@(@@A@) heading unless there is an intervening
2403 @<TT@>@(@@B@) heading.
2404
2405 @<P@>
2406 @<Begin verbatim@>
2407 @@A@@@<<@>The Top Heading@@@<>@>
2408 @@C@@@<<@>Level C here is not allowed after an A@@@<>@>
2409 @<End verbatim@>
2410
2411 @<P@>This rule extends to the start of the file; if there
2412 are any headings at all, the first one must be an
2413 @<TT@>@(@@A@) heading. The following file, while short, is
2414 in error.
2415
2416 @<P@>
2417 @<Begin verbatim@>
2418 This FunnelWeb input file is in error
2419 because its first section heading
2420 is at level C rather than level A.
2421 @@C@@@<<@>2@@@<>@>
2422 @<End verbatim@>
2423
2424 @<Nav@>@(@<Type_independence FILE@>@,@<Type FILE@>@,@<Type_printed FILE@>@)
2425
2426 @<End FWTutMan page@>
2427 @}
2428
2429 @!==============================================================================
2430
2431 @$@<Type_printed HEADING@>@M@{@<SH@>@(3.4@)Understanding the Printed Documentation@}
2432 @$@<Type_printed FILE@>@M@{type_printed.html@}
2433 @O@<type_printed.html@>@{@-
2434 @<Begin FWTutMan page/H1@>@(@<Type_printed HEADING@>@)
2435
2436 @<P@>Type in the following file, and use FunnelWeb and TeX
2437 to generate the corresponding printed
2438 documentation.@<XX@>@(programmer's@,cheer@)@<XX@>@(hacker's@,cheer@)
2439 @<XX@>@(hacker's@,dictionary@)
2440
2441 @<P@>
2442 @<Begin verbatim@>
2443 @@A@@@<<@>Table of Contents@@@<>@>
2444
2445 @@t table_of_contents
2446
2447 @@A@@@<<@>Macros for Moral Support@@@<>@>
2448
2449 The following macro contain comments that provide moral
2450 support.
2451
2452 @@$@@@<<@>Programmer's Cheer@@@<>@>@@M==@@{
2453 -- Shift to the left!
2454 -- Shift to the right!
2455 -- Pop up, push down!
2456 -- Byte! Byte! Byte!
2457 -- (From "The New Hacker's Dictionary").
2458 @@}
2459
2460 The next macro is similar but is
2461 distributed throughout the program.
2462
2463 @@$@@@<<@>Hacker's Cheer@@@<>@>+=@@{
2464 -- Pointer to the left@@+@@}
2465
2466 @@A@@@<<@>An Extremely Imperative Stack Abstraction@@@<>@>
2467
2468 @@B@@@<<@>Define the Stack@@@<>@>
2469
2470 @@$@@@<<@>Hacker's Cheer@@@<>@>+=@@{@@-
2471 -- Pointer to the right@@+@@}
2472
2473 @@$@@@<<@>Stack Type@@@<>@>@@Z==@@{@@-
2474 type stack = record ... end;@@}
2475
2476 @@B@@@<<@>Push the Stack@@@<>@>
2477
2478 @@$@@@<<@>Hacker's Cheer@@@<>@>+=@@{@@-
2479 -- Hack that code@@+@@}
2480
2481 @@$@@@<<@>Push Procedure@@@<>@>@@Z==@@{@@-
2482 procedure push(var b:stack; v:value);
2483 @@@<<@>Programmer's Cheer@@@<>@> {...}@@}
2484
2485 @@B@@@<<@>Pop the Stack@@@<>@>
2486
2487 @@$@@@<<@>Hacker's Cheer@@@<>@>+=@@{@@-
2488 -- Tight! Tight! Tight!@@+@@}
2489
2490 @@$@@@<<@>Pop Procedure@@@<>@>@@Z==@@{@@-
2491 procedure pop(var b:stack);
2492
2493 @@@<<@>Programmer's Cheer@@@<>@> {...}@@}
2494
2495 @@B@@@<<@>Rough the Stack Up a Bit@@@<>@>
2496
2497 @@$@@@<<@>Hacker's Cheer@@@<>@>+=@@{@@-
2498 -- (RNW, 04-Jan-1991).@@+@@}
2499
2500 @@$@@@<<@>Rough Procedure@@@<>@>@@Z==@@{@@-
2501 procedure rough(var b:stack);
2502 @@@<<@>Hacker's Cheer@@@<>@> {...}@@}
2503
2504 @@O@@@<<@>dummy.txt@@@<>@>==@@{dummy@@+@@}
2505 @<End verbatim@>
2506
2507 @<P@>An examination of the printed documentation reveals a
2508 lot about how FunnelWeb's presentation works.
2509
2510 @<P@>First, notice how the @<TT@>@(@@t@) typesetter
2511 directive at the top of the file has caused a table of
2512 contents to appear. This is one of FunnelWeb's typesetting
2513 features and is discussed in a later section. The table of
2514 contents shows that the sections have been numbered
2515 hierarchically.
2516
2517 @<P@>Now take a look at the typeset macro definitions. Most
2518 important are the numbers in square brackets that follow
2519 each macro name. As well as numbering the headings
2520 @<I@>@(hierarchically@), FunnelWeb @<I@>@(independently@)
2521 numbers the macro definitions @<I@>@(sequentially@). The
2522 first macro definition (for @<DQ@>@(Programmer's Cheer@)) is
2523 numbered 1. The second (for @<DQ@>@(Hacker's Cheer@)) is
2524 numbered 2 and so on. Note that it is not macros that are
2525 numbered, but macro definitions. The distinction is
2526 necessary because some macros (such as the @<DQ@>@(Hacker's
2527 Cheer@) macro) are additive. It is important to realize that
2528 there is no relationship between the numbers of the headings
2529 and the numbers of the macro definitions.
2530
2531 @<P@>Now take a look at the notes beneath the body of each
2532 macro definition. All macro definitions are followed by a
2533 note indicating the definitions in which the macro is
2534 called. Additive macros have an additional list, listing the
2535 definitions in which they are defined.
2536
2537 @<P@>Finally, take a look at the macro @<I@>@(call@) of
2538 @<DQ@>@(Programmer's Cheer@) in section@<_@>3.2 of the printed
2539 documentation. Macro calls are set in slanted roman (so that
2540 they can be distinguished from the @<TT@>@(tt font@) code)
2541 and are followed by the number of the defining macro
2542 definition. In this case, the macro was defined in
2543 definition@<_@>1. Further down, the call to the @<DQ@>@(Hacker's
2544 Cheer@) macro indicates that the macro was defined in
2545 definition@<_@>2. In fact the macro is additive and definition@<_@>2
2546 is just the first of many definitions. To list all
2547 definitions in a call to an additive macro would be
2548 unnecessarily messy.
2549
2550 @<Nav@>@(@<Type_hierarchy FILE@>@,@<Type FILE@>@,@<Type_literals FILE@>@)
2551
2552 @<End FWTutMan page@>
2553 @}
2554
2555 @!==============================================================================
2556
2557 @$@<Type_literals HEADING@>@M@{@<SH@>@(3.5@)Literals and Emphasis@}
2558 @$@<Type_literals FILE@>@M@{type_literals.html@}
2559 @O@<type_literals.html@>@{@-
2560 @<Begin FWTutMan page/H1@>@(@<Type_literals HEADING@>@)
2561 @<X@>@(literal construct@)@<X@>@(emphasis construct@)
2562
2563 @<P@>When writing about program code, it is often desirable
2564 to be able to indicate that a particular word or phrase be
2565 typeset in the same manner as the code being discussed. For
2566 example, one might talk about the variable @<TT@>@(topval@)
2567 or the procedure @<TT@>@(stack_pop@) and wish for them to
2568 be typeset as they are in this sentence. This, of course, is
2569 simple to do using TeX macros, but use of the (more general)
2570 FunnelWeb typesetting directives to do the same work has the
2571 added benefit of keeping the document portable to other
2572 typesetters.
2573
2574 @<P@>FunnelWeb provides two in-text type modification
2575 constructs: @<TT@>@(@@{...@@}@) and
2576 @<TT@>@(@@/...@@/@)@<X@>@(@@slash@)@<X@>@(@@braces@) where
2577 @<LDots@> is raw text. The @<TT@>@(@@{...@@}@) construct
2578 sets the enclosed text in the same manner as the text of
2579 macro definitions is set. The @<TT@>@(@@/...@@/@) construct
2580 emphasises its enclosed text in some typesetter-dependent
2581 fashion. Typically the emphasised text is set in italics.
2582
2583 @<P@>Here is an example of how these constructs might be
2584 used:
2585
2586 @<P@>
2587 @<Begin verbatim@>
2588 The following procedure @@{put_sloth@@} writes the
2589 @@{sloth@@} variable to the output file. Note: @@/The output
2590 file must be opened for writing at this point or the program
2591 will crash!@@/
2592 @<End verbatim@>
2593
2594 @<Nav@>@(@<Type_printed FILE@>@,@<Type FILE@>@,@<Type_header FILE@>@)
2595
2596 @<End FWTutMan page@>
2597 @}
2598
2599 @!==============================================================================
2600
2601 @$@<Type_header HEADING@>@M@{@<SH@>@(3.6@)Adding A Header Page@}
2602 @$@<Type_header FILE@>@M@{type_header.html@}
2603 @O@<type_header.html@>@{@-
2604 @<Begin FWTutMan page/H1@>@(@<Type_header HEADING@>@)
2605 @<X@>@(header page@)
2606
2607 @<P@>FunnelWeb provides a few typesetter-independent
2608 typesetting constructs which are specifically designed for
2609 the construction of header pages. These constructs are
2610 usually best placed at the top of your input file, but can
2611 be placed anywhere the document if desired to create header
2612 pages right through. The two main restrictions on these
2613 constructs is that the @<TT@>@(@@t@) must start at the start
2614 of a line (which cannot contain comments), and that the
2615 constructs cannot appear inside a macro definition. Here is
2616 what the top of an input file might look like:
2617
2618 @<P@>
2619 @<Begin verbatim@>
2620 @@t vskip 40 mm
2621 @@t title titlefont centre "Hairy Wombat"
2622 @@t title titlefont centre "Simulation"
2623 @@t vskip 10 mm
2624 @@t title smalltitlefont centre "A Program in Six Parts"
2625 @@t title smalltitlefont centre "Simulating the Life of"
2626 @@t title smalltitlefont centre "Some Hairy Wombats"
2627 @@t vskip 20 mm
2628 @@t title normalfont left "By Zqitzypba Ypongslrzz"
2629 @@t new_page
2630 @@t table_of_contents
2631 @@t new_page
2632 @<End verbatim@>
2633
2634 @<P@>The @<TT@>@(@@t@) at the start of each line indicates
2635 that each entire line is a typesetter directive. The
2636 @<TT@>@(vskip@)@<XX@>@(vskip@,directive@) directive
2637 instructs FunnelWeb to skip some vertical space (measured in
2638 millimetres). The @<TT@>@(title@)
2639 directive@<XX@>@(title@,directive@) instructs FunnelWeb to
2640 position a string of text on a single line of its own.
2641 Options are provided for font and alignment. The first word
2642 after @<TT@>@(title@) is the font which can be one of (in
2643 decreasing order of size) @<TT@>@(titlefont@),
2644 @<TT@>@(smalltitlefont@), and @<TT@>@(normalfont@). The
2645 second word after @<TT@>@(title@) is the desired alignment
2646 of the text. The options here are @<TT@>@(left@),
2647 @<TT@>@(right@), and @<TT@>@(centre@). The
2648 @<TT@>@(new_page@) directive@<XX@>@(newpage@,directive@)
2649 instructs FunnelWeb to skip to a new page. Finally, the
2650 @<TT@>@(table_of_contents@) directive@<XX@>@(table of
2651 contents@,directive@) instructs FunnelWeb to insert a table
2652 of contents at that point in the text.
2653
2654 @<Nav@>@(@<Type_literals FILE@>@,@<Type FILE@>@,@<Type_comments FILE@>@)
2655
2656 @<End FWTutMan page@>
2657 @}
2658
2659 @!==============================================================================
2660
2661 @$@<Type_comments HEADING@>@M@{@<SH@>@(3.7@)Comments@}
2662 @$@<Type_comments FILE@>@M@{type_comments.html@}
2663 @O@<type_comments.html@>@{@-
2664 @<Begin FWTutMan page/H1@>@(@<Type_comments HEADING@>@)
2665 @<X@>@(comments@)
2666
2667 @<P@>A FunnelWeb comment commences with the
2668 @<TT@>@(@@!@)@<X@>@(@@!@) sequence and continues up to, but
2669 not including, the end of line marker at the end of the line
2670 that the comment sequence is on. Comments can be placed on
2671 any line except @<TT@>@(@@i@) include, @<TT@>@(@@p@) pragma,
2672 and @<TT@>@(@@t@) typesetter directive lines.
2673
2674 @<P@>The text following the FunnelWeb comment sequence
2675 @<TT@>@(@@!@) will not appear in the product files or the
2676 documentation file. It is only for the eyes of those who
2677 bother to look at the original @<TT@>@(.fw@) input file.
2678 Typically FunnelWeb comments are used to describe the way in
2679 which particular FunnelWeb constructs are being used.
2680 Example:
2681
2682 @<P@>
2683 @<Begin verbatim@>
2684 @@! This macro is really revolting.
2685 @@! Please forgive me. I had to do it!
2686 @@$@@@<<@>Revolt Me@@@<>@>==@@{@@-
2687 @@#X@@(@@#Y@@(@@#Z@@,@@"@@#Z@@"@@)=
2688 6@@,Teapot@@,@@"@@#Q@@(45@@)@@"@@,Tiger@@)@@}
2689 @<End verbatim@>
2690
2691 @<Nav/last@>@(@<Type_header FILE@>@,@<Type FILE@>@,@<Type FILE@>@)
2692
2693 @<End FWTutMan page@>
2694 @}
2695
2696 @!******************************************************************************
2697
2698 @$@<Example HEADING@>@M@{@<SH@>@(4@)A Complete Example@}
2699 @$@<Example HEADING/short@>@M@{@<SH@>@(4@)Example@}
2700 @$@<Example FILE@>@M@{example.html@}
2701 @O@<example.html@>@{@-
2702 @<Begin FWTutMan page/H1@>@(@<Example HEADING@>@)
2703 @<XX@>@(complete@,example@)@<XX@>@(FunnelWeb@,Example@)
2704
2705 @<P@>To finish off the chapter, a complete example of a
2706 FunnelWeb input file is presented. Although unrealistically
2707 short, it gives a better idea of what a typical FunnelWeb
2708 @<TT@>@(.fw@) file looks like.
2709
2710 @<P@>
2711 @<Begin verbatim@>
2712 @@!---------------------------------------!
2713 @@! Start of FunnelWeb Example .fw File !
2714 @@!---------------------------------------!
2715
2716 @@t vskip 40 mm
2717 @@t title titlefont centre "Powers:"
2718 @@t title titlefont centre "An Example of"
2719 @@t title titlefont centre "A Short"
2720 @@t title titlefont centre "FunnelWeb .fw File"
2721 @@t vskip 10 mm
2722 @@t title smalltitlefont centre "by Ross Williams"
2723 @@t title smalltitlefont centre "26 January 1992"
2724 @@t vskip 20 mm
2725 @@t table_of_contents
2726
2727 @@A@@@<<@>FunnelWeb Example Program@@@<>@>
2728
2729 This program writes out each of the first @@{p@@}
2730 powers of the first @@{n@@} integers. These constant
2731 parameters are located here so that they are easy to
2732 change.
2733
2734 @@$@@@<<@>Constants@@@<>@>==@@{@@-
2735 n : constant natural := 10; -- [1,n] numbers?
2736 p : constant natural := 5; -- [1,p]) powers?@@}
2737
2738 @@B Here is the outline of the program. This FunnelWeb
2739 file generates a single Ada output file called
2740 @@{Power.ada@@}. The main program consists of a loop that
2741 iterates once for each number to be written out.
2742
2743 @@O@@@<<@>Power.ada@@@<>@>==@@{@@-
2744 @@@<<@>Pull in packages@@@<>@>
2745
2746 procedure example is
2747 @@@<<@>Constants@@@<>@>
2748 begin -- example
2749 for i in 1..n loop
2750 @@@<<@>Write out the first p powers@@@<>@>
2751 end loop;
2752 end example;
2753 @@}
2754
2755 @@B In this section, we pull in the packages that this
2756 program needs to run. In fact, all we need is the IO
2757 package so that we can write out the results. To use the IO
2758 package, we first of all need to haul it in (@@{with
2759 text_io@@}) and then we need to make all its identifiers
2760 visible at the top level (@@{use text_io@@}).
2761
2762 @@$@@@<<@>Pull in packages@@@<>@>@@{@-
2763 with text_io; use text_io;@@}
2764
2765 @@B Here is the bit that writes out the first @@{p@@}
2766 powers of @@{i@@}. The power values are calculated
2767 incrementally in @@{ip@@} to avoid the use of the
2768 exponentiation operator.
2769
2770 @@$@@@<<@>Write out the first p powers@@@<>@>@@{@@-
2771 declare
2772 ip : natural := 1;
2773 begin
2774 for power in 1..p loop
2775 ip:=ip*i;
2776 put(natural'image(ip) & " ");
2777 end loop;
2778 new_line;
2779 end;@@}
2780
2781 @@!---------------------------------------!
2782 @@! End of FunnelWeb Example .fw File !
2783 @@!---------------------------------------!
2784 @<End verbatim@>
2785
2786 @<FWTutMan subheading@>@(Summary@)
2787
2788 @<P@>FunnelWeb's functionality can be split into two parts:
2789 a macro preprocessor, and support for typesetting. The
2790 reader should be aware that the examples in this manual,
2791 constructed as they have been to demonstrate particular
2792 features of FunnelWeb, do not present a realistic picture of
2793 the best use of the tool. Only the example above comes
2794 close.
2795
2796 @<Nav@>@(@<Type FILE@>@,@<Index FILE@>@,@<Hints FILE@>@)
2797
2798 @<End FWTutMan page@>
2799 @}
2800
2801 @!******************************************************************************
2802
2803 @$@<Hints HEADING@>@M@{@<SH@>@(5@)FunnelWeb Hints@}
2804 @$@<Hints HEADING/short@>@M@{@<SH@>@(5@)Hints@}
2805 @$@<Hints FILE@>@M@{hints.html@}
2806 @O@<hints.html@>@{@-
2807 @<Begin FWTutMan page/H1@>@(@<Hints HEADING@>@)
2808
2809 @<P@>This section contains a grab bag of hints about how
2810 FunnelWeb can be used. This chapter probably should not be
2811 read until you have commenced using FunnelWeb, or at the
2812 very least, tried out some of the examples in earlier
2813 chapters. Those who find themselves using FunnelWeb
2814 frequently should read this chapter at some stage so as to
2815 ensure that they are getting the most out of it.
2816
2817 @<P@>Most of the examples in this chapter have been placed in the
2818 FunnelWeb regression test suite. The files to
2819 examine are @<TT@>@(hi01.fw@) through @<TT@>@(hi10.fw@).
2820
2821 @<P@>
2822 @<Hints index@>
2823
2824 @<Nav@>@(@<Example FILE@>@,@<Index FILE@>@,@<Examples FILE@>@)
2825
2826 @<End FWTutMan page@>
2827 @}
2828
2829 @$@<Hints index@>@M@{
2830 @<Begin size3@>
2831 @<Begin indent/narrow@>
2832 @<Link@>@(@<Hints_names FILE@>@,@<Hints_names HEADING@>@)@<BR@>
2833 @<Link@>@(@<Hints_qnames FILE@>@,@<Hints_qnames HEADING@>@)@<BR@>
2834 @<Link@>@(@<Hints_martinet FILE@>@,@<Hints_martinet HEADING@>@)@<BR@>
2835 @<Link@>@(@<Hints_eols FILE@>@,@<Hints_eols HEADING@>@)@<BR@>
2836 @<Link@>@(@<Hints_conditionals FILE@>@,@<Hints_conditionals HEADING@>@)@<BR@>
2837 @<Link@>@(@<Hints_headings FILE@>@,@<Hints_headings HEADING@>@)@<BR@>
2838 @<Link@>@(@<Hints_efficiency FILE@>@,@<Hints_efficiency HEADING@>@)@<BR@>
2839 @<Link@>@(@<Hints_interactive FILE@>@,@<Hints_interactive HEADING@>@)@<BR@>
2840 @<Link@>@(@<Hints_default FILE@>@,@<Hints_default HEADING@>@)@<BR@>
2841 @<Link@>@(@<Hints_make FILE@>@,@<Hints_make HEADING@>@)@<BR@>
2842 @<Link@>@(@<Hints_dangers FILE@>@,@<Hints_dangers HEADING@>@)@<BR@>
2843 @<Link@>@(@<Hints_debugging FILE@>@,@<Hints_debugging HEADING@>@)@<BR@>
2844 @<Link@>@(@<Hints_tabs FILE@>@,@<Hints_tabs HEADING@>@)@<BR@>
2845 @<Link@>@(@<Hints_htmlstyle FILE@>@,@<Hints_htmlstyle HEADING@>@)@<BR@>
2846 @<Link@>@(@<Hints_emacs FILE@>@,@<Hints_emacs HEADING@>@)@<BR@>
2847 @<End indent/narrow@>
2848 @<End size3@>
2849 @}
2850
2851 @!==============================================================================
2852
2853 @$@<Hints_names HEADING@>@M@{@<SH@>@(5.1@)Macro Names@}
2854 @$@<Hints_names FILE@>@M@{hints_names.html@}
2855 @O@<hints_names.html@>@{@-
2856 @<Begin FWTutMan page/H1@>@(@<Hints_names HEADING@>@)
2857 @<XX@>@(macro@,names@)@<XX@>@(macro@,identifiers@)
2858
2859 @<P@>When using FunnelWeb, the choice of macro names can be
2860 as important to the readability of a program as the choice
2861 of program identifiers, and it is important that you
2862 know the range of options available.
2863
2864 @<Narrowthing@>@(Names are case sensitive and exact
2865 matching:@,Macro names are case sensitive and are matched
2866 exactly. The strings used as a macro name at the point of
2867 definition and call must be @<I@>@(identical@) for the
2868 connection to be made.@)
2869
2870 @<Narrowthing@>@(Names can contain any printable
2871 character:@,FunnelWeb is less restrictive about its macro
2872 names than most programming languages are about their
2873 identifiers. A FunnelWeb macro name can contain any sequence
2874 of printable characters, including blanks and punctuation.
2875 Names can start and end with any character. However, names cannot
2876 cross line boundaries. The following are all legal macro
2877 names:@)
2878
2879 @<Begin verbatim@>
2880 @@@<<@>This macro expands to some really bad code@@@<>@>
2881 @@@<<@>@@@<>@>
2882 @@@<<@>453 #$ %&# --===~~1"@<>@>@<>@>@<>@>@@@<>@>
2883 @@@<<@>@<<@>@@@<>@>
2884 @@@<<@>@<<@>@<>@>@@@<>@>
2885 @@@<<@>a b c d e f g@@@<>@>
2886 @@@<<@> ! @@@<>@>
2887 @@@<<@>?? ...@@@<>@>
2888 @@@<<@>"Who's been hacking MY program" said Father Bear.@@@<>@>
2889 @@@<<@>Update the maximum and return for more data@@@<>@>
2890 @<End verbatim@>
2891
2892 @<Narrowthing@>@(Names must be no more than a maximum limit
2893 in length:@,Names can be no longer than a predefined maximum
2894 length (80). Currently this length cannot be modified without
2895 recompiling FunnelWeb.@)
2896
2897 @<P@>Typically, macro names will consist of a short English
2898 phrase or sentence that describes the contents of the macro.
2899
2900 @<Nav/first@>@(@<Hints FILE@>@,@<Hints FILE@>@,@<Hints_qnames FILE@>@)
2901
2902 @<End FWTutMan page@>
2903 @}
2904
2905 @!==============================================================================
2906
2907 @$@<Hints_qnames HEADING@>@M@{@<SH@>@(5.2@)Quick Names@}
2908 @$@<Hints_qnames FILE@>@M@{hints_qnames.html@}
2909 @O@<hints_qnames.html@>@{@-
2910 @<Begin FWTutMan page/H1@>@(@<Hints_qnames HEADING@>@)
2911 @<XX@>@(quick@,names@)
2912
2913 @<P@>Sometimes a particular macro must be used extremely
2914 often. When this happens, it is desirable to make the macro's
2915 name as short as possible. The shortest ordinary FunnelWeb
2916 macro name is the empty name@<XX@>@(empty@,name@)
2917 @<DQP@>@(@@@<<@>@@@<>@>@), which is four characters long.
2918 Single-character names are five characters long.
2919
2920 @<P@>To cater for the cases where really short names are
2921 needed, FunnelWeb provides a @<NewTerm@>@(quick name@)
2922 syntax that allows one-character macro names to be specified
2923 in two less characters. Quick names take the form of the
2924 special character, followed by a hash (@<TT@>@(#@)) followed
2925 by a single character. Examples:
2926
2927 @<P@>
2928 @<Begin verbatim@>
2929 @@#A @@#| @@#& @@#m
2930 @<End verbatim@>
2931
2932 @<P@>This form of macro name has the same syntactic
2933 functionality as an ordinary name and can be substituted
2934 wherever an ordinary name can be. In fact quick names live
2935 in the same namespace as ordinary macro names. For example
2936 the quickname @<TT@>@(@@#A@) is the @<I@>@(same name@)
2937 (refers to the same macro) as the ordinary name
2938 @<TT@>@(@@@<<@>A@@@<>@>@).
2939
2940 @<P@>Because quick names look syntactically @<DQ@>@(open@)
2941 (@<ie@>they do not have a closing@<TT@>@(@@@<>@>@) as
2942 ordinary names do), it is best to avoid them except where a
2943 macro must be called very often.
2944
2945 @<Nav@>@(@<Hints_names FILE@>@,@<Hints FILE@>@,@<Hints_martinet FILE@>@)
2946
2947 @<End FWTutMan page@>
2948 @}
2949
2950 @!==============================================================================
2951
2952 @$@<Hints_martinet HEADING@>@M@{@<SH@>@(5.3@)FunnelWeb the Martinet@}
2953 @$@<Hints_martinet FILE@>@M@{hints_martinet.html@}
2954 @O@<hints_martinet.html@>@{@-
2955 @<Begin FWTutMan page/H1@>@(@<Hints_martinet HEADING@>@)
2956 @<XX@>@(FunnelWeb@,rules@)@<XX@>@(FunnelWeb@,martinet@)
2957
2958 @<P@>There are many ways in which a macro preprocessor can
2959 cause unexpected difficulties. FunnelWeb seeks to avoid many
2960 of these problems by performing a number of checks. This
2961 section describes some of the checks that FunnelWeb
2962 performs.
2963
2964 @<Narrowthing@>@(Trailing blanks in the input
2965 file:@,Trailing blanks@<XX@>@(trailing@,blanks@) are usually
2966 not dangerous, but FunnelWeb disallows them anyway. All
2967 trailing blanks in the @<I@>@(input@) (@<TT@>@(.fw@) file)
2968 are flagged as errors by FunnelWeb. FunnelWeb does not flag
2969 trailing blanks in any of its output files.@)
2970
2971 @<Narrowthing@>@(Input line length:@,FunnelWeb has a maximum
2972 input line length.@<XX@>@(input line@,length@) If FunnelWeb
2973 reads an input line longer than this length, it flags the
2974 line with an error message. The maximum length can be
2975 changed using a pragma (see the @<FunnelWeb Reference Manual@>).@)
2976
2977 @<Narrowthing@>@(Product file line length:@,FunnelWeb
2978 watches the length of output lines@<XX@>@(output
2979 line@,length@) and all output lines longer than the limit
2980 are flagged with error messages. The maximum length can be
2981 changed using a pragma. That FunnelWeb polices output lines
2982 is very important. Some programs can behave very strangely
2983 if they get an input line that is too long (@<eg@>Fortran
2984 compilers@<XX@>@(Fortran@,compilers@) can simply ignore text
2985 past a certain column!) and once FunnelWeb starts expanding
2986 macros using indentation, it is sometimes not obvious how
2987 wide the product file will be.@)
2988
2989 @<Narrowthing@>@(Control characters:@,The presence of
2990 control characters@<XX@>@(control@,characters@) in a text
2991 file can result in some confusing behaviour downstream when
2992 the file is presented to various programs. Unfortunately,
2993 some text editors@<XX@>@(text@,editors@) allow control
2994 characters to be inserted into the text rather too easily,
2995 and it is all too easy to be tripped up. FunnelWeb prevents
2996 these problems by flagging with diagnostics all
2997 non-end-of-line control characters detected in the input
2998 (@<TT@>@(.fw@)) file (even TABs@<X@>@(tabs@)). The result is
2999 that the user is guaranteed that product files generated
3000 from FunnelWeb contain no unintentional control characters.
3001 This said, FunnelWeb does allow the insertion of control
3002 characters in the output file by explicitly specifying them
3003 in the text using a @<TT@>@(@@^@) control sequence.@)
3004
3005 @<Narrowthing@>@(Number of invocations:@,FunnelWeb checks
3006 the number of times that@<XX@>@(invocations@,number@) each
3007 macro is called and issues an error if the total is not one.
3008 The @<TT@>@(@@Z@) (for zero) and @<TT@>@(@@M@) (for many)
3009 macro attributes can be used to bypass these checks.@)
3010
3011 @<Narrowthing@>@(Recursion:@,Because@<XX@>@(recursion@,macro@)
3012 FunnelWeb does not provide any conditional constructs, all
3013 recursively defined macros must, by definition, expand
3014 infinitely*, and are therefore unacceptable. FunnelWeb
3015 performs @<I@>@(static@) checks to detect recursion,
3016 detecting it before macro expansion commences. The user need
3017 not fear that FunnelWeb will lock up or spew forth if a
3018 recursive macro is accidentally specified.
3019 (* Note: A special case exists where there is
3020 recursion but no content. In this case, the expansion is
3021 finite (the empty string) even though the operation of
3022 expanding is infinite. FunnelWeb does not treat this case
3023 specially).@)
3024
3025 @<Nav@>@(@<Hints_qnames FILE@>@,@<Hints FILE@>@,@<Hints_eols FILE@>@)
3026
3027 @<End FWTutMan page@>
3028 @}
3029
3030 @!==============================================================================
3031
3032 @$@<Hints_eols HEADING@>@M@{@<SH@>@(5.4@)Fiddling With End of Lines@}
3033 @$@<Hints_eols FILE@>@M@{hints_eols.html@}
3034 @O@<hints_eols.html@>@{@-
3035 @<Begin FWTutMan page/H1@>@(@<Hints_eols HEADING@>@)
3036 @<XX@>@(EOL@,fiddling with@)@<XX@>@(end-of-line@,fiddling with@)@<X@>@(spacing@)
3037
3038 @<P@>One of the fiddly aspects of programming with
3039 FunnelWeb is coping with end of lines. If you want your
3040 product file to be well indented without multiple blank
3041 lines or code run-ons, you have to spend a little time
3042 working out how the end of line markers get moved around.
3043
3044 @<P@>The rule to remember is that, disregarding the
3045 effects of special sequences within a macro body,
3046 @<I@>@(the body of a macro consists of exactly the text
3047 between the opening @<TT@>@(@@{@) and the closing
3048 @<TT@>@(@@}@)@). This text includes end of line markers.
3049
3050 @<P@>If for example you call a macro in a sequence of
3051 code@<LDots@>
3052
3053 @<P@>
3054 @<Begin verbatim@>
3055 while the_walrus_is_sleepy do
3056 begin
3057 writeln('zzzzzzz');
3058 @@@<<@>Wake up the walrus@@@<>@>
3059 writeln('Umpharumpha...');
3060 end;
3061 @<End verbatim@>
3062
3063 @<P@>where @<TT@>@(@<<@>wake up the walrus@<>@>@) is defined
3064 as follows
3065
3066 @<P@>
3067 @<Begin verbatim@>
3068 @@$@@@<<@>Wake up the walrus@@@<>@>==@@{
3069 wake_up_the_walrus(the_walrus);
3070 @@}
3071 @<End verbatim@>
3072
3073 @<P@>then when @<TT@>@(@<<@>Wake up the walrus@<>@>@) is
3074 expanded you will get
3075
3076 @<P@>
3077 @<Begin verbatim@>
3078 while the_walrus_is_sleepy do
3079 begin
3080 writeln("zzzzzzz");
3081
3082 wake_up_the_walrus(the_walrus);
3083
3084 writeln("Umpharumpha...");
3085 end;
3086 @<End verbatim@>
3087
3088 @<P@>The blank lines were introduced by the end on line
3089 markers included in the definition of @<TT@>@(@<<@>Wake up
3090 the walrus@<>@>@). A good solution to this problem is to
3091 suppress the end of line markers by defining the macro as
3092 follows
3093
3094 @<P@>
3095 @<Begin verbatim@>
3096 @@$@@@<<@>Wake up the walrus@@@<>@>==@@{@@-
3097 wake_up_the_walrus(the_walrus);@@}
3098 @<End verbatim@>
3099
3100 @<P@>This is the usual form of macro definitions in
3101 FunnelWeb files.
3102
3103 @<P@>In additive macros, this format does not work properly
3104 because the end of line that is suppressed by the trailing
3105 @<TT@>@(@@}@) does not get replaced by the end of line at
3106 the end of the macro invocation. For example the definition
3107
3108 @<P@>
3109 @<Begin verbatim@>
3110 @@$@@@<<@>Wake up the walrus@@@<>@>+=@@{@@-
3111 wake_up_the_walrus_once(the_walrus);@@}
3112 @<End verbatim@>
3113
3114 @<P@>later followed by
3115
3116 @<P@>
3117 @<Begin verbatim@>
3118 @@$@@@<<@>Wake up the walrus@@@<>@>+=@@{@@-
3119 wake_up_the_walrus_again(the_walrus);@@}
3120 @<End verbatim@>
3121
3122 @<P@>is equivalent to the single definition
3123
3124 @<P@>
3125 @<Begin verbatim@>
3126 @@$@@@<<@>Wake up the walrus@@@<>@>==@@{@@-
3127 wake_up_the_walrus_once(the_walrus);@@-
3128 wake_up_the_walrus_again(the_walrus);@@}
3129 @<End verbatim@>
3130
3131 @<P@>Putting the trailing @<TT@>@(@@}@) on a new line at
3132 the end of the macro (except for the last definition part)
3133 solves the problem.
3134
3135 @<P@>
3136 @<Begin verbatim@>
3137 @@$@@@<<@>Wake up the walrus@@@<>@>+=@@{@@-
3138 wake_up_the_walrus_once(the_walrus);
3139 @@}
3140 @<End verbatim@>
3141
3142 @<P@>later followed by
3143
3144 @<P@>
3145 @<Begin verbatim@>
3146 @@$@@@<<@>Wake up the walrus@@@<>@>+=@@{@@-
3147 wake_up_the_walrus_again(the_walrus);@@}
3148 @<End verbatim@>
3149
3150 @<P@>is equivalent to the single definition
3151
3152 @<P@>
3153 @<Begin verbatim@>
3154 @@$@@@<<@>Wake up the walrus@@@<>@>==@@{@@-
3155 wake_up_the_walrus_once(the_walrus);
3156 wake_up_the_walrus_again(the_walrus);@@}
3157 @<End verbatim@>
3158
3159 @<P@>Managing end of line markers is tricky, but once you
3160 establish a convention for coping with them, the problem
3161 disappears into the background.
3162
3163 @<Nav@>@(@<Hints_martinet FILE@>@,@<Hints FILE@>@,@<Hints_conditionals FILE@>@)
3164
3165 @<End FWTutMan page@>
3166 @}
3167
3168 @!==============================================================================
3169
3170 @$@<Hints_conditionals HEADING@>@M@{@<SH@>@(5.5@)Fudging Conditionals@}
3171 @$@<Hints_conditionals FILE@>@M@{hints_conditionals.html@}
3172 @O@<hints_conditionals.html@>@{@-
3173 @<Begin FWTutMan page/H1@>@(@<Hints_conditionals HEADING@>@)
3174 @<XX@>@(fudging@,conditionals@)
3175
3176 @<P@>As a macro preprocessor, one facility that FunnelWeb
3177 lacks is a conditional facility (such as C's
3178 @<TT@>@(#ifdef@)). It might, therefore, come as a surprise
3179 to know that the FunnelWeb V1 actually had a
3180 built in conditional facility. The facility allowed the
3181 programmer to specify a construct that would select from one
3182 of a number of macro expressions depending on the value of a
3183 controlling macro expression.
3184
3185 @<P@>In three years the construct was never used.
3186
3187 @<P@>The reason was that conditional constructs could be
3188 fudged nearly as easily as they could be used. Because of
3189 this, the inbuilt conditional feature was removed in the
3190 FunnelWeb V2. Not only did this simplify the
3191 program, but is also allowed recursive macros to be detected
3192 through static analysis rather than during macro expansion.
3193
3194 @<P@>There are two basic ways to fudge a conditional. First,
3195 the comment facility of the target programming language may
3196 be employed. For example, in Ada,@<X@>@(Ada@) comments
3197 commence with @<DQP@>@(--@) and terminate at the end of the
3198 line. Using this fact, it is easy to construct macros that
3199 can be called at the start of each target line and which
3200 turn on and off the lines so marked by defining the macro to
3201 be the empty string (ON) or the comment symbol
3202 (@<TT@>@(--@)) (OFF). For example:
3203
3204 @<P@>@<Begin verbatim@>
3205 @@A@@@<<@>Debug Macro@@@<>@>
3206
3207 The following macro determines whether debug code
3208 will be included in the program. All lines of
3209 debug code commence with a call to this macro and
3210 so we can turn all that code on or off here by
3211 defining this macro to be either empty or the
3212 single-line comment symbol (@<TT@>@(--@)). Note
3213 the use of a quick macro name.
3214
3215 @@$@@#D@@M==@@{@@} @@! Turns the debug code ON.
3216 @@! Use this definition to turn
3217 @@! the debug code OFF: @@$@@#D==@@{--@@}
3218
3219 ... then later in the file...
3220
3221 @@$@@@<<@>Sloth incrementing loop@@@<>@>==@@{@@-
3222 while sloth@<<@>walrus loop
3223 @@#D assert(sloth@<<@>walrus,"Sloth bomb.");
3224 @@#D assert(timer@<<@>timermax,"Timer bomb.");
3225 inc(sloth);
3226 end loop@@}
3227 @<End verbatim@>
3228
3229 @<P@>The other way to fudge a conditional is to
3230 define a macro with a single parameter. A call to
3231 the macro is then wrapped around all the
3232 conditional code in the program. The macro can
3233 then be defined to present or ignore the code of
3234 its argument. For example:
3235
3236 @<P@>
3237 @<Begin verbatim@>
3238 @@A@@@<<@>Debug Macro@@@<>@>
3239
3240 The following macro determines whether debug code
3241 will be included in the program. All debug code is
3242 wrapped by a call to this macro and so we can turn
3243 all the debug code on or off here by defining this
3244 macro to be either empty or its parameter.
3245
3246 @@$@@#D@@(@@1@@)@@M==@@{@@1@@} @@! Debug code ON.
3247 @@! Use this definition to turn the
3248 @@! debug code OFF: @@$@@#D@@(@@1@@)==@@{@@}
3249
3250 ... then later in the file...
3251
3252 @@$@@@<<@>Sloth incrementing loop@@@<>@>==@@{@@-
3253 while sloth@<<@>walrus loop
3254 @@#D@@(assert(sloth@<<@>walrus,"Sloth bomb.");
3255 assert(timer@<<@>timermax,"Timer bomb");@@)
3256 inc(sloth);
3257 end loop@@}
3258 @<End verbatim@>
3259
3260 @<P@>In languages that allow multi-line comments (@<eg@>C
3261 with @<TT@>@(/*@) and @<TT@>@(*/@)), comments can be used to
3262 eliminate the conditioned code rather than absence. For
3263 example:
3264
3265 @<P@>
3266 @<Begin verbatim@>
3267 @@! Comments out the debug code
3268 @@$@@#D@@(@@1@@)@@M==@@{/* @@1 */@@}
3269 @<End verbatim@>
3270
3271 @<P@>(Note: If this example were ever actually used, the
3272 programmer would have to be careful not to place comments in
3273 the argument code. Nested comments in C are non-portable.)
3274
3275 @<P@>The parameterized macro idea can be generalized to
3276 support the choice of more than one mutually exclusive
3277 alternative. For example:
3278
3279 @<P@>
3280 @<Begin verbatim@>
3281 @@A This module contains non-portable code that
3282 must execute on Hewlett Packard, Sun, and DEC
3283 workstations. The following FunnelWeb macro is
3284 defined to choose between these three. The first
3285 parameter is the HP code, the second is the Sun
3286 code, and the third is the DEC code. Whichever
3287 parameter constitutes the body of this macro
3288 determines which machine the code is being
3289 targeted for.
3290
3291 @@$@@@<<@>Machine specific code@@@<>@>@@(@@3@@)@@M==@@{@@-
3292 @@1@@} @@! Configure for HP.
3293
3294 ...then later in the file...
3295
3296 @@@<<@>Machine specific code@@@<>@>@@(
3297 @@"get_command_line(comline)@@" @@, @@! HP.
3298 @@"scan_command_line(128,comline);@@" @@, @@! Sun.
3299 @@"dcl_get_command_line(comline,256);@@" @@) @@! DEC.
3300 @<End verbatim@>
3301
3302 @<P@>Of course, this could also be performed using three
3303 separate macros. The main advantage of using a single macro
3304 is that the mutual exclusivity is enforced. Also, because
3305 FunnelWeb ensures that the number of formal and actual
3306 parameters are the same, this method lessens the chance that
3307 a machine will be forgotten in some places.
3308
3309 @<Nav@>@(@<Hints_eols FILE@>@,@<Hints FILE@>@,@<Hints_headings FILE@>@)
3310
3311 @<End FWTutMan page@>
3312 @}
3313
3314 @!==============================================================================
3315
3316 @$@<Hints_headings HEADING@>@M@{@<SH@>@(5.6@)Changing the Strength of Headings@}
3317 @$@<Hints_headings FILE@>@M@{hints_headings.html@}
3318 @O@<hints_headings.html@>@{@-
3319 @<Begin FWTutMan page/H1@>@(@<Hints_headings HEADING@>@)
3320 @<XX@>@(headings@,strength@)@<XX@>@(typesetting@,strength@)
3321 @<XX@>@(section@,strength@)@<XX@>@(font@,size@)
3322
3323 @<P@>FunnelWeb provides five heading levels: @<TT@>@(@@A@),
3324 @<TT@>@(@@B@), @<TT@>@(@@C@), @<TT@>@(@@D@), and
3325 @<TT@>@(@@E@) to which it binds five different typographical
3326 strengths. These bindings are static; a level @<TT@>@(@@A@)
3327 heading will always be typeset in a particular font size
3328 regardless of the size of the document. The font sizes have
3329 been preset to be @<DQ@>@(reasonable@) for a range of
3330 document sizes, but may be inappropriate for very small or
3331 large documents.
3332
3333 @<P@>FunnelWeb does not currently provide an
3334 @<DQ@>@(official@) way (@<eg@>a pragma) to change the
3335 typesetting strength of headings. This feature might be
3336 added in later versions. Meanwhile, a hack is available that
3337 will do the job, providing that you do not mind the hack
3338 being TeX-specific and probably FunnelWeb-version specific.
3339
3340 @<P@>Inside the set of TeX macro definitions that FunnelWeb
3341 writes at the top of every documentation file are five
3342 @<DQ@>@(library@) definitions
3343 @<TT@>@(fwliba@)@<LDots@>@<TT@>@(fwlibe@) which provide five
3344 different typesetting strengths for headings. Near the end
3345 of the set of definitions, FunnelWeb binds these macros to
3346 five other macros @<TT@>@(fwseca@)@<LDots@>@<TT@>@(fwsece@)
3347 which are invoked directly in the generated TeX code to
3348 typeset the headings.
3349
3350 @<P@>
3351 @<Begin verbatim@>
3352 \def\fwseca#1#2{\fwliba{#1@@,#2}}
3353 \def\fwsecb#1#2{\fwlibb{#1@@,#2}}
3354 \def\fwsecc#1#2{\fwlibc{#1@@,#2}}
3355 \def\fwsecd#1#2{\fwlibd{#1@@,#2}}
3356 \def\fwsece#1#2{\fwlibe{#1@@,#2}}
3357 @<End verbatim@>
3358
3359 @<P@>This means that the typesetting strength of the
3360 headings in a FunnelWeb document can be changed by
3361 redefining these macros at the top of a FunnelWeb document.
3362 For example:
3363
3364 @<P@>
3365 @<Begin verbatim@>
3366 @@p typesetter = tex
3367 \def\fwseca#1#2{\fwlibc{#1@@,#2}}
3368 @<End verbatim@>
3369
3370 @<P@>would set @<TT@>@(@@A@) headings at the same strength
3371 as the default strength of @<TT@>@(@@C@) headings. The
3372 @<TT@>@(typesetter@) directive is necessary to ensure that
3373 the TeX control sequences get through to the documentation
3374 file unfiltered.
3375
3376 @<P@>The following will tone down all headings by two levels
3377 (with the @<TT@>@(@@D@) and @<TT@>@(@@E@) levels being
3378 allocated the default @<TT@>@(@@E@) typesetting strength
3379 because there is nothing weaker).
3380
3381 @<P@>
3382 @<Begin verbatim@>
3383 @@p typesetter = tex
3384 \def\fwseca#1#2{\fwlibc{#1@@,#2}}
3385 \def\fwsecb#1#2{\fwlibd{#1@@,#2}}
3386 \def\fwsecc#1#2{\fwlibe{#1@@,#2}}
3387 \def\fwsecd#1#2{\fwlibe{#1@@,#2}}
3388 \def\fwsece#1#2{\fwlibe{#1@@,#2}}
3389 @<End verbatim@>
3390
3391 @<P@>These definitions affect only the headings that follow
3392 them, and so they should be placed at the top of the
3393 FunnelWeb input file.
3394
3395 @<P@>To change the style of headings in HTML output, just
3396 modify the style settings near the top of the HTML file.
3397
3398 @<Nav@>@(@<Hints_conditionals FILE@>@,@<Hints FILE@>@,@<Hints_efficiency FILE@>@)
3399
3400 @<End FWTutMan page@>
3401 @}
3402
3403 @!==============================================================================
3404
3405 @$@<Hints_efficiency HEADING@>@M@{@<SH@>@(5.7@)Efficiency Notes@}
3406 @$@<Hints_efficiency FILE@>@M@{hints_efficiency.html@}
3407 @O@<hints_efficiency.html@>@{@-
3408 @<Begin FWTutMan page/H1@>@(@<Hints_efficiency HEADING@>@)
3409 @<XX@>@(FunnelWeb@,efficiency@)@<XX@>@(efficiency@,notes@)
3410
3411 @<P@>The following notes are worth keeping in mind when
3412 using FunnelWeb.
3413
3414 @<Narrowthing@>@(Memory:@,When@<X@>@(memory@)@<XX@>@(input@,files@)
3415 FunnelWeb processes an input file, it reads the entire input
3416 file, and all the included files into memory. (Note: If a
3417 file is included n times, FunnelWeb keeps n copies in
3418 memory). This organization does not pose a constraint on
3419 machines with large memories, but could present a problem on
3420 the smaller machines such as the PC.@)
3421
3422 @<Narrowthing@>@(Speed:@,FunnelWeb@<X@>@(speed@) is not a
3423 slow program. However, it is not particularly fast either.
3424 If the speed at which FunnelWeb runs is important to you,
3425 then the thing to keep in mind is that FunnelWeb has been
3426 optimized to deal efficiently with large slabs of text.
3427 FunnelWeb treats input files as a sequence of text slabs and
3428 special sequences (@<eg@>@<TT@>@(@@+@)) and whenever it hits
3429 a special sequence, it has to stop and think. Thus, while a
3430 ten megabyte text slab would be manipulated as a single
3431 token, in a few milliseconds, a similar ten megabyte chunk
3432 filled with special sequences would take a lot longer. If
3433 FunnelWeb is running slowly, look to see if the input
3434 contains a high density of special sequences. This can
3435 sometimes happen if FunnelWeb is being used as a backend
3436 macro processor and its input is being generated
3437 automatically by some other program.@)
3438
3439 @<Narrowthing@>@(Macro
3440 expansion:@,When@<XX@>@(macro@,expansion@) tangling
3441 (expanding macros), FunnelWeb never expands a macro
3442 expression into memory; it always writes it to the product
3443 file as it goes. This is a powerful fact, because it means
3444 that you can write macros containing an unlimited amount of
3445 text, and pass such macros as parameters to other macros
3446 without becoming concerned about overflowing some kind of
3447 buffer memory. In short, FunnelWeb does not impose any
3448 limits on the size of macro bodies or their expansions.@)
3449
3450 @<Nav@>@(@<Hints_headings FILE@>@,@<Hints FILE@>@,@<Hints_interactive FILE@>@)
3451
3452 @<End FWTutMan page@>
3453 @}
3454
3455 @!==============================================================================
3456
3457 @$@<Hints_interactive HEADING@>@M@{@<SH@>@(5.8@)Interactive Mode@}
3458 @$@<Hints_interactive FILE@>@M@{hints_interactive.html@}
3459 @O@<hints_interactive.html@>@{@-
3460 @<Begin FWTutMan page/H1@>@(@<Hints_interactive HEADING@>@)
3461 @<X@>@(interactive mode@)@<X@>@(keyboard mode@)
3462
3463 @<P@>As well as having a command line interface with lots of
3464 options, FunnelWeb also provides a command language and a
3465 mode (@<DQ@>@(interactive mode@)) in which commands in the
3466 language can be typed interactively. The FunnelWeb command
3467 interpreter was created primarily to support regression
3468 testing,@<XX@>@(regression@,testing@) but can also be useful
3469 to FunnelWeb users.
3470
3471 @<P@>FunnelWeb's command
3472 interpreter@<XX@>@(command@,interpreter@) reads one command
3473 per line and can read a stream of commands either from a
3474 text file, or from the console. The interpreter can
3475 understand over twenty commands. See the
3476 @<FunnelWeb Reference Manual@> for a full list. However,
3477 most of them
3478 were designed to support regression testing and will not be
3479 of use to the casual user.
3480
3481 @<P@>The commands that are of greatest use to the casual
3482 user are:@<XX@>@(useful@,commands@)
3483
3484 @<P@>
3485 @<Begin verbatim@>
3486 ! - Ignores the whole line.
3487 EXECUTE fn - Execute the specified file.
3488 FW options - Invoke FunnelWeb-proper once.
3489 SET options - Sets options.
3490 SHOW - Displays current options.
3491 TRACE ON - Turns command tracing ON.
3492 QUIT - Quits FunnelWeb.
3493 @<End verbatim@>
3494
3495 @<P@>To distinguish here between invocations of the
3496 FunnelWeb program and FunnelWeb runs inside the shell, we
3497 call the latter @<NewTerm@>@(FunnelWeb proper@). The
3498 @<DQP@>@(FW@) command invokes FunnelWeb proper with the
3499 specified options which take the same syntax as they do on
3500 the command line. The only restriction is that none of the
3501 action options can be turned on except @<DQP@>@(+F@) which
3502 must be turned on.
3503
3504 @<P@>The @<DQP@>@(SET@) command@<XX@>@(set@,command@) has
3505 the same syntax as the @<DQP@>@(FW@) command except that it
3506 does not allow @<I@>@(any@) action options to be specified.
3507 It's sole effect is to set default option values for the
3508 rest of the run.
3509
3510 @<P@>The @<DQP@>@(SHOW@)@<XX@>@(show@,command@) command
3511 displays the current default options.
3512
3513 @<P@>By default, FunnelWeb does not echo the commands that
3514 it processes in a script. The @<DQP@>@(TRACE
3515 ON@)@<XX@>@(trace on@,command@) command turns on such
3516 tracing.
3517
3518 @<P@>These commands can be combined to streamline the use of
3519 FunnelWeb. For example, you might wish to create a script
3520 called @<TT@>@(typeset.fws@) to process a whole group of
3521 files.
3522
3523 @<P@>
3524 @<Begin verbatim@>
3525 trace on
3526 !This script typesets the whole program.
3527 ! Set no listing file, no product files,
3528 ! but specify a documentation file
3529 ! and specify the directory into which
3530 ! it should be placed.
3531 set -L -O +T/usr/ross/typeset/
3532 fw prog1
3533 fw prog2
3534 fw prog3
3535 fw prog4
3536 @<End verbatim@>
3537
3538 @<P@>There are a few ways in which this script can be run.
3539 The simplest is simply to specify it in the @<DQP@>@(+X@)
3540 option of a FunnelWeb invocation. FunnelWeb shellscripts
3541 default to @<DQP@>@(@<<@>current_directory@<>@>@) and
3542 @<DQP@>@(.fws@).
3543
3544 @<P@>
3545 @<Begin verbatim@>
3546 fw +xtypeset
3547 @<End verbatim@>
3548
3549 @<P@>The second alternative is
3550 to enter interactive mode.
3551
3552 @<P@>
3553 @<Begin verbatim@>
3554 fw +k
3555 @<End verbatim@>
3556
3557 @<P@>From there, you can execute
3558 the script using:
3559
3560 @<P@>
3561 @<Begin verbatim@>
3562 execute typeset
3563 @<End verbatim@>
3564
3565 @<P@>Interactive mode could be very useful to those with
3566 multiple-window workstations.@<X@>@(workstations@) The user
3567 could create a window containing an interactive session of
3568 FunnelWeb, and then switch between windows, editing, and
3569 executing FunnelWeb proper and other programs.
3570
3571 @<P@>If you find yourself using the command interpreter a
3572 lot, be sure to read about the other commands that are
3573 available in the @<FunnelWeb Reference Manual@>.
3574
3575 @<Nav@>@(@<Hints_efficiency FILE@>@,@<Hints FILE@>@,@<Hints_default FILE@>@)
3576
3577 @<End FWTutMan page@>
3578 @}
3579
3580 @!==============================================================================
3581
3582 @$@<Hints_default HEADING@>@M@{@<SH@>@(5.9@)Setting Up Default Options@}
3583 @$@<Hints_default FILE@>@M@{hints_default.html@}
3584 @O@<hints_default.html@>@{@-
3585 @<Begin FWTutMan page/H1@>@(@<Hints_default HEADING@>@)
3586 @<XX@>@(options@,setting defaults@)@<XX@>@(default@,options@)
3587
3588 @<P@>If you do not like FunnelWeb's default settings for its
3589 command line options, there are a number of ways in which
3590 you can change them.
3591
3592 @<Narrowthing@>@(Define an @<DQ@>@(alias@):@,Use your
3593 operating system @<DQP@>@(alias@)@<X@>@(alias@) facility to
3594 create an alias for FunnelWeb containing the desired
3595 options. FunnelWeb processes options from left to right, so
3596 you can override these defaults later if you wish.@)
3597
3598 @<Narrowthing@>@(Create a script called
3599 @<DQP@>@(fwinit.fws@):@,When FunnelWeb starts up, it
3600 executes a script called
3601 @<DQP@>@(fwinit.fws@)@<X@>@(fwinit.fws@)
3602 if@<XX@>@(startup@,script@)@<XX@>@(initialization@,script@)
3603 such a script exists in the current directory. You can use
3604 this fact to set options before the run of FunnelWeb proper
3605 by creating such a script and placing a single
3606 @<DQP@>@(set@) command in it containing the desired options.
3607 The main trouble with this approach is that the options in
3608 the @<TT@>@(set@) command will be processed @<I@>@(after@)
3609 the command line options, which means that you won't be able
3610 to override them on the command line.@)
3611
3612 @<P@>For example, you might be involved more with presenting
3613 programs than with running them, and want FunnelWeb to
3614 generate a documentation file by default, but not to produce
3615 listing or product files by default. In Unix you could do
3616 this with:
3617
3618 @<P@>
3619 @<Begin verbatim@>
3620 alias fw fw -L -O +T
3621 @<End verbatim@>
3622
3623 @<Nav@>@(@<Hints_interactive FILE@>@,@<Hints FILE@>@,@<Hints_make FILE@>@)
3624
3625 @<End FWTutMan page@>
3626 @}
3627
3628 @!==============================================================================
3629
3630 @$@<Hints_make HEADING@>@M@{@<SH@>@(5.10@)FunnelWeb and Make@}
3631 @$@<Hints_make FILE@>@M@{hints_make.html@}
3632 @O@<hints_make.html@>@{@-
3633 @<Begin FWTutMan page/H1@>@(@<Hints_make HEADING@>@)
3634 @<X@>@(make utility@)@<XX@>@(file@,dependencies@)
3635
3636 @<P@>The Unix @<TT@>@(Make@) program allows a set of
3637 dependencies between a set of files to be described, and
3638 then uses these dependencies to control the way in which the
3639 files are created and updated. Typically, @<TT@>@(Make@) is
3640 used to control the process of transforming a collection of
3641 source code files to one or more executable files. As the
3642 use of FunnelWeb implies an extra stage to this process, it
3643 is natural to include the transformation of @<TT@>@(.fw@)
3644 files to source code files as part of the @<TT@>@(Make@)
3645 process. This is easy to do, but the user should be aware of
3646 one aspect of FunnelWeb which can cause problems.
3647
3648 @<P@>It is often useful, when using FunnelWeb, to create a
3649 FunnelWeb @<TT@>@(.fw@) file that generates more than one
3650 product file. That is, a single @<TT@>@(.fw@) file may have
3651 many macro definitions connected to product files so that
3652 when the FunnelWeb @<TT@>@(.fw@) file is processed by
3653 FunnelWeb, several files are created. For example, this
3654 facility is convenient for placing a single package's
3655 @<TT@>@(.h@) and @<TT@>@(.c@) files within the same
3656 FunnelWeb @<TT@>@(.fw@) file.
3657
3658 @<P@>The use of multiple product files, however, provokes a
3659 problem with dependencies. Suppose for example that a
3660 FunnelWeb @<TT@>@(prog.fw@) produces two product files
3661 @<TT@>@(proc.spec@) (a package specification) and
3662 @<TT@>@(prog.body@) (a package body). If the package is
3663 accessed in the way that packages normally are, it will be
3664 quite common for the programmer to want to modify the
3665 package body without modifying the program specification. So
3666 the programmer will edit the @<TT@>@(prog.fw@) file to
3667 change the package body. The result of running this through
3668 FunnelWeb will be the desired new package body file.
3669 However, FunnelWeb will also produce a new package
3670 specification product file @<I@>@(even though it may be
3671 identical to the previous version!@) The result is that the
3672 newly created (with a recent file date) specification
3673 package file could provoke a huge remake of much of the
3674 program in which it resides.
3675
3676 @<P@>To solve the problem, FunnelWeb includes a command line
3677 option (@<TT@>@(D@) for
3678 Delete),@<XX@>@(D@,option@)@<XX@>@(delete@,output files@)
3679 which when turned on (using @<DQP@>@(+D@)) causes FunnelWeb
3680 to suppress@<XX@>@(suppression@,file@) product and
3681 documentation files that are identical to the previously
3682 existing versions of the same files. For example, if, during
3683 a FunnelWeb run, a macro was connected to a product file
3684 called @<TT@>@(x.dat@), and the macro expanded to
3685 @<I@>@(exactly@) the same text as is contained in
3686 @<TT@>@(x.dat@) then FunnelWeb would simply @<I@>@(never
3687 write the product file@), the file @<TT@>@(x.dat@) would be
3688 untouched and, as a result, no further @<TT@>@(Make@)
3689 propagations would take place.
3690
3691 @<P@>FunnelWeb implements this feature by writing each
3692 product file to a temporary file with a temporary file name.
3693 It then compares the temporary file with the target file. If
3694 the two are identical, it deletes the temporary file. If the
3695 two are different it deletes the target file and renames the
3696 temporary file to the target file.
3697
3698 @<P@>Use of the @<TT@>@(D@) facility means that the
3699 programmer need not be punished (by extra @<TT@>@(Make@)
3700 propagations) for describing more than one product file in
3701 the same FunnelWeb file.
3702
3703 @<Nav@>@(@<Hints_default FILE@>@,@<Hints FILE@>@,@<Hints_dangers FILE@>@)
3704
3705 @<End FWTutMan page@>
3706 @}
3707
3708 @!==============================================================================
3709
3710 @$@<Hints_dangers HEADING@>@M@{@<SH@>@(5.11@)The Dangers Of FunnelWeb@}
3711 @$@<Hints_dangers FILE@>@M@{hints_dangers.html@}
3712 @O@<hints_dangers.html@>@{@-
3713 @<Begin FWTutMan page/H1@>@(@<Hints_dangers HEADING@>@)
3714 @<XX@>@(FunnelWeb@,dangers@)@<XX@>@(FunnelWeb@,pitfalls@)
3715
3716 @<P@>Like many tools that are general and flexible,
3717 FunnelWeb can be used in a variety of ways, both good and
3718 bad. One of the original appeals of the literate approach to
3719 programming for Knuth,@<XN@>@(Donald@,Knuth@) the inventor
3720 of literate programming,@<XX@>@(literate@,programming@) was
3721 that it allows the programmer to describe the target program
3722 bottom up, top down, size to side, or chaotically if
3723 desired.
3724
3725 @<P@>The flexibility that the literate style of
3726 programming leaves much room for bad documentation
3727 as well as good documentation. Years of experience
3728 with FunnelWeb has revealed the following
3729 stylistic pitfalls which the experienced FunnelWeb
3730 user should take care to avoid. (Note: The fact that
3731 these faults are listed here does not mean that
3732 the author has eliminated them in his own work.
3733 Rather, it is mainly the author's own mistakes
3734 that have resulted in this list being compiled.
3735 The author immediately confesses to several of the
3736 faults listed here, most notably that of Pavlov
3737 documentation).
3738
3739 @<Narrowthing@>@(Spaghetti
3740 organization:@,By@<XX@>@(spaghetti@,organization@) far the
3741 worst problem that arises in connection with the literate
3742 style occurs where the programmer has used the literate tool
3743 to completely scramble the program so that the program is
3744 described and layed out in an unordered, undisciplined
3745 @<DQ@>@(stream of consciousness@).@<X@>@(stream of
3746 consciousness@) In such cases the programmer may be using
3747 the literate style as a crutch to avoid having to think
3748 about structuring the presentation.@)
3749
3750 @<Narrowthing@>@(Boring
3751 organization:@,At@<XX@>@(boring@,organization@) the other
3752 extreme, a program may be organized in such a strict way
3753 that it is essentially laid out in the order most
3754 @<DQ@>@(desired@) by the target programming language. For
3755 example, each macro might contain a single procedure, with
3756 all the macros being called by a macro connected to a file
3757 at the top. In many cases a boring structure may be entirely
3758 appropriate, but the programmer should be warned that it is
3759 easy to slip into such a normative style, largely forgetting
3760 the descriptive structural power that FunnelWeb provides.@)
3761
3762 @<Narrowthing@>@(Poor random
3763 access:@,Using@<XX@>@(random@,access@) FunnelWeb, it is
3764 quite possible to write programs like novels@<X@>@(novels@)
3765 --- to be read from cover to cover. Sometimes the story is
3766 very exciting, with data structures making dashing triumphs
3767 and optimized code bringing the story to a satisfying
3768 conclusion. These programs can be works of art.
3769 Unfortunately, without careful construction, such
3770 @<DQ@>@(novel-programs@) can become very hard to access
3771 randomly by (say) a maintenance
3772 programmer@<XX@>@(maintenance@,programmer@) who wishes only
3773 to dive in and fix a specific problem. If the entire program
3774 is scrambled for sequential exposition, it can be hard to
3775 find the parts relating to a single function. Somehow a
3776 balance must be struck in the document between the needs of
3777 the sequential and of the random-access reader. This balance
3778 will depend on the intended use of the program.@)
3779
3780 @<Narrowthing@>@(Too-interdependent
3781 documentation:@,Sometimes,
3782 when@<XX@>@(documentation@,interdependent@) editing a
3783 program written using FunnelWeb, one knows how to modify the
3784 program, but one is unsure of how to update the surrounding
3785 documentation! The documentation may be woven into such a
3786 network of facts that it seems that changing a small piece
3787 of code could invalidate many pieces of documentation
3788 scattered throughout the document. The documentation becomes
3789 a big tar pit in which movement is impossible. For example,
3790 if you have talked about a particular data structure
3791 invariant throughout a document, changing that invariant in
3792 a small way could mean having to update all the
3793 documentation without touching much code. In such cases, the
3794 documentation is too interdependent. This could be
3795 symptomatic of an excessibly interconnected program, or of
3796 an excessively verbose or redundant documenting style. In
3797 any case, a balance must be struck between the
3798 conversational style that encourages redundancy (by
3799 mentioning things many times) and the normalized database
3800 approach where each fact is given at only one point, and the
3801 reader is left to figure out the implications throughout the
3802 document.@)
3803
3804 @<Narrowthing@>@(Pavlov
3805 documentation:@,By@<XX@>@(pavlov@,documentation@) placing so
3806 much emphasis on the documentation, FunnelWeb naturally
3807 provides slots where documentation @<DQ@>@(should@) go. For
3808 example, a FunnelWeb user may feel that there may be a
3809 rather unpleasant gap between a @<TT@>@(@@C@) marker and the
3810 following macro. In many cases @<I@>@(no@) commentary is
3811 needed, and the zone is better left blank rather than being
3812 filled with the kind of uninformative waffle one often finds
3813 filling the slots of structured documentation written
3814 according to a military standards
3815 (@<eg@>MIL-STD-2167A).@<X@>@(MIL-STD-2167A@)@<X@>@(2167A@) (Note:
3816 This is not a criticism of 2167A, only of the way it is
3817 sometimes used). The lesson is to add documentation only
3818 when it adds something. The lesson in Strunk and
3819 White@<Paper@>@(Strunk79@) (p.@<_@>23) holds for program
3820 documentation as it does for other writing: @<DQ@>@(Vigorous
3821 writing is concise. A sentence should contain no unnecessary
3822 words, a paragraph no unnecessary sentences, for the same
3823 reason that a drawing should have no unnecessary lines and a
3824 machine no unnecessary parts. This requires not that the
3825 writer make all his sentences short, or that he avoid all
3826 detail and treat his subjects only in outline, but that
3827 every word tell.@).@)
3828
3829 @<Narrowthing@>@(Duplicate
3830 documentation:@,Where@<XX@>@(duplicate@,documentation@) the
3831 programmer is generating product files that must exist on
3832 their own within the entire programming environment
3833 (@<eg@>the case of a programmer in a team who is using
3834 FunnelWeb for his own benefit but must generate (say)
3835 commented Ada@<X@>@(Ada@) specification package files) there
3836 is a tendency for the comments in the target code to
3837 duplicate the commentary in the FunnelWeb text. This may or
3838 may not be a problem, depending on the situation.
3839 However, if this is happening, it is certainly worth the
3840 programmer spending some time deciding if one or other of
3841 the FunnelWeb or inline-comment documentation should be
3842 discarded. In many cases, a mixture can be used, with the
3843 FunnelWeb documentation referring the reader to the inline
3844 comments where they are present. For example:@)
3845
3846 @<P@>
3847 @<Begin verbatim@>
3848 @@A Here is the header comment for the list package
3849 specification. The reader should read these comments
3850 carefully as they define a list. There is no need to
3851 duplicate the comments in this text.
3852
3853 @@$@@@<<@>Specification package comments@@@<>@>==@@{@@-
3854 -- LIST PACKAGE
3855 -- ============
3856 -- * A LIST consists of zero or more ITEMS.
3857 -- * The items are numbered 1 to N where N
3858 -- is the number of items in the list.
3859 -- * If the list is non-empty, item 1
3860 -- is called the HEAD of the list.
3861 -- * If the list is non-empty, item N
3862 -- is called the TAIL of the list.
3863 -- ...
3864 @@}
3865 @<End verbatim@>
3866
3867 @<Narrowthing@>@(Overdocumenting:@,Another@<XX@>@(over@,documentation@)
3868 evil that can arise when using FunnelWeb is to over-document
3869 the target program. In some of Knuth's earlier (@<eg@>1984)
3870 examples of literate programming, each variable is given its
3871 own description and each piece of code has a detailed
3872 explanation. This level of analysis, while justified for
3873 tricky tracts of code, is probably not warranted for most of
3874 the code that constitutes most programs. Such
3875 over-commenting can even have the detrimental affect of
3876 obscuring the code, making it hard to understand because it
3877 is so scattered (see @<DQ@>@(spaghetti organization@)
3878 earlier). It is up to the user to decide when a stretch of
3879 just a few lines of code should be pulled to bits and
3880 analysed and when it is clearer to leave it alone.@)
3881
3882 @<Narrowthing@>@(@,In the case where there are a few rather tricky
3883 lines of code, a detailed explanation may be appropriate.
3884 The following example contains a solution to a problem
3885 outlined in section 16.3 of the book @<DQ@>@(The Science of
3886 Programming@) by David Gries@<Paper@>@(Gries81@).@)
3887
3888 @<P@>
3889 @<Begin verbatim@>
3890 @@C@@@<<@>Calculation of the longest plateau in b@@@<>@>
3891
3892 This section contains a solution to a problem
3893 outlined in section 16.3 of the book @@/The
3894 Science of Programming@@/ by David Gries[Gries81].
3895
3896 @@D Given a sorted array @@{b[1..N]@@} of
3897 integers, we wish to determine the @@/length@@/ of
3898 the longest run of identically valued elements in
3899 the array. This problem is defined by the
3900 following precondition and postcondition.
3901
3902 @@$@@@<<@>Precondition@@@<>@>==@@{/* Pre: sorted(b). */@@}
3903 @@$@@@<<@>Postcondition@@@<>@>==@@{@@-
3904 /* Post: sorted(b) and p is the length */
3905 /* of the longest run in b[1..N]. */@@}
3906
3907 @@D We approach a solution to the problem by
3908 deciding to try the approach of scanning through
3909 the array one element at a time maintaining a
3910 useful invariant through each iteration. A loop
3911 variable array index @@{i@@} is created for this
3912 purpose. The bound function is @@{N-i@@}. Here is
3913 the invariant.
3914
3915 @@$@@@<<@>Invariant@@@<>@>==@@{@@-
3916 /* Invariant: sorted(b) and 1@<<@>=i@<<@>=N and */
3917 /* p is len of longest run in b[1..i]. */@@}
3918
3919 @@D Establishing the invariant above in the
3920 initial, degenerate case is easy.
3921
3922 @@$@@@<<@>Establish plateau loop invariant@@@<>@>@@{@-
3923 i=1; p=1;@@}
3924
3925 @@D At this stage, we have the following loop
3926 structure. Note that when both the invariant and
3927 @@{i == N@@} are true, the postcondition holds and
3928 the loop can terminate.
3929
3930 @@$@@@<<@>p=len(longest run in sorted b[1..N])@@@<>@>@@{@@-
3931 @@@<<@>Precondition@@@<>@>
3932 @@@<<@>Establish plateau loop invariant@@@<>@>
3933 while (i != N)
3934 {
3935 @@@<<@>Invariant@@@<>@>
3936 @@@<<@>Loop body@@@<>@>
3937 }
3938 @@@<<@>Postcondition@@@<>@>
3939 @@}
3940
3941 @@D Now there remains only the loop body whose
3942 sole task is to increase @@{i@@} (and so decrease
3943 the value of the bound function) while maintaining
3944 the invariant. If @@{p@@} is the length of the
3945 longest run seen so far (i.e. in b[1..i]), then,
3946 because the array is sorted, the extension of our
3947 array range to @@{b[1..i+1]@@} can only result in
3948 an increase in @@{p@@} if the new element
3949 terminates a run of length @@{p+1@@}. The increase
3950 can be at most 1. Because the array is sorted, we
3951 need only compare the endpoints of this possible
3952 run to see if it exists. This is performed as
3953 shown below.
3954
3955 @@$@@@<<@>Loop body@@@<>@>==@@{@-
3956 i++; if (b[i] != b[i-p]) p++;@@}
3957 @<End verbatim@>
3958
3959 @<P@>Where the code is more obvious,
3960 it is often better to let the code speak for itself.
3961
3962 @<P@>
3963 @<Begin verbatim@>
3964 @@C The following function compares two C
3965 strings and returns TRUE iff they are identical.
3966
3967 @@$@@@<<@>Function comp@@@<>@>==@@{@@-
3968 bool comp(p,q)
3969 char *p,*q;
3970 {
3971 while (TRUE)
3972 {
3973 if (*p != *q ) return FALSE;
3974 if (*p == '\0') return TRUE;
3975 p++; q++;
3976 }
3977 }
3978 @@}
3979 @<End verbatim@>
3980
3981 @<Nav@>@(@<Hints_make FILE@>@,@<Hints FILE@>@,@<Hints_debugging FILE@>@)
3982
3983 @<End FWTutMan page@>
3984 @}
3985
3986 @!==============================================================================
3987
3988 @$@<Hints_debugging HEADING@>@M@{@<SH@>@(5.12@)Wholistic Debugging@}
3989 @$@<Hints_debugging FILE@>@M@{hints_debugging.html@}
3990 @O@<hints_debugging.html@>@{@-
3991 @<Begin FWTutMan page/H1@>@(@<Hints_debugging HEADING@>@)
3992
3993 @<P@>Surprising though it may be, FunnelWeb has a role
3994 to play in the @<B@>@(debugging@) of programs. My
3995 experience in programming has led me to the concept of
3996 @<NewTerm@>@(wholistic debugging@). When many programmers
3997 detect a bug, their first reaction seems to be to jump into
3998 the debugger@<X@>@(debugger@) where they often spend many
3999 hours stepping through endless stretches of code and
4000 generally wasting a lot of time.
4001
4002 @<P@>In contrast, my first reaction when I detect a bug is
4003 to realize that @<B@>@(the code must not be in good enough
4004 shape if such a bug can arise!@) The presence of the bug is
4005 taken as symptomatic of the lack of general health of the
4006 code. If that bug occurred, why not another? In response to
4007 this realization, my reaction is not to enter the debugger,
4008 but rather to return to the original code and tend it like a
4009 garden,@<XX@>@(code@,gardening@) adding more comments,
4010 reworking the weaker parts, adding assertions, and looking
4011 for faults. In many cases, the search for faults does not
4012 even centre on the specific bug that arose, but does tend to
4013 focus on the area of code where the bug is likely to be.
4014
4015 @<P@>The result is often that the original bug is located
4016 more quickly than it would have been had the debugger been
4017 involved. But even if it isn't, there are other benefits. A
4018 programmer who enters the debugger may stay there for hours
4019 and still not find the bug. The result is frustration and no
4020 positive gain at all. In contrast, by tending to the code,
4021 the programmer is making forward progress at all times (the
4022 code is constantly improving) even if the bug is not
4023 immediately found. At the end of ten hours, the programmer
4024 can at least feel that the code is @<DQ@>@(ten hours
4025 better@), whereas the debugger freak will likely feel
4026 defeated. All this makes code tending better psychologically
4027 as well as a more efficient approach to debugging.
4028
4029 @<P@>I call this technique wholistic debugging, for it is
4030 like the difference between conventional and wholistic
4031 medicine.@<XX@>@(wholistic@,medicine@) Go to a conventional
4032 doctor with a headache and he might send off for head
4033 X-rays, perform allergy tests and perform many other
4034 debugging activities. Go to a wholistic doctor with the same
4035 problem and he might look to see if you are fit, assess your
4036 mental health, and ask you if your marriage is working. Both
4037 approaches are appropriate at different times, but I believe
4038 that, on balance, in programming the wholistic approach is
4039 not used enough.
4040
4041 @<Nav@>@(@<Hints_dangers FILE@>@,@<Hints FILE@>@,@<Hints_tabs FILE@>@)
4042
4043 @<End FWTutMan page@>
4044 @}
4045
4046 @!==============================================================================
4047
4048 @$@<Hints_tabs HEADING@>@M@{@<SH@>@(5.13@)TABs@}
4049 @$@<Hints_tabs FILE@>@M@{hints_tabs.html@}
4050 @O@<hints_tabs.html@>@{@-
4051 @<Begin FWTutMan page/wide/H1@>@(@<Hints_tabs HEADING@>@)
4052
4053 @<P@>FunnelWeb is designed to protect its user from spurious
4054 non-printable characters that might creep into a source file,
4055 and so it classifies any occurrence of such a character as
4056 an error.
4057
4058 @<P@>FunnelWeb's idea of printable is any character in the
4059 range ASCII [32..126]. A number of people have complained
4060 about this, saying that they want to include 8-bit
4061 characters in their FunnelWeb input files. Currently there
4062 is no fix for this except to insert characters explicitly
4063 into the output using a @<TT@>@(@@^@) sequence (see the
4064 @<FunnelWeb Reference Manual@> for more details).
4065
4066 @<P@>In particular, FunnelWeb flags TAB characters in its
4067 input file as errors because TABs are essentially invisible
4068 control characters with very poorly-defined semantics; it's
4069 FunnelWeb's job to keep an eye on the input file to ensure
4070 that the programmer doesn't get any nasty surprises and as
4071 TABs can cause several kinds of surprises, they are excluded.
4072
4073 @<P@>A lot of people have complained about this aspect of
4074 FunnelWeb. Unfortunately, this issue has not yet been
4075 resolved. If you actually @<I@>@(need@) TABs in the output
4076 file (@<eg@>for a makefile), then you should insert TABs
4077 explicitly using a @<TT@>@(@@^D(009)@) sequence (see the
4078 @<FunnelWeb Reference Manual@> for more details).
4079
4080 @<P@>The following C program removes TABs. The program was
4081 kindly donated by John Skaller. Warning: This program
4082 doesn't have any error checking.
4083
4084 @<Begin verbatim@>
4085 /* UNTAB Program */
4086 /* ============= */
4087 /* Author : John Skaller (maxtal@@extro.ucc.su.oz.au) */
4088 /* Organization : MAXTAL P/L 6 Mackay St ASHFIELD 2131. */
4089 /* Usage : untab 2 <infile >outfile */
4090 /* Status : Public domain. */
4091
4092 #include <stdio.h>
4093
4094 int main(int argv, char **argc)
4095 {
4096 int n=2;
4097 if(argv==2)sscanf(argc[1],"%d",&n);
4098 int ch=getchar();
4099 int column=0;
4100 while(ch!=-1){
4101 if(ch=='\n'){putchar('\n'); column=0;}
4102 else if(ch==9){
4103 putchar(' '); column++;
4104 while(column % n){putchar(' '); column++;}
4105 }
4106 else { putchar(ch); column++;}
4107 ch=getchar();
4108 }
4109 }
4110 @<End verbatim@>
4111
4112 @<Nav@>@(@<Hints_debugging FILE@>@,@<Hints FILE@>@,@<Hints_htmlstyle FILE@>@)
4113
4114 @<End FWTutMan page@>
4115 @}
4116
4117 @!==============================================================================
4118
4119 @$@<Hints_htmlstyle HEADING@>@M@{@<SH@>@(5.14@)HTML Style@}
4120 @$@<Hints_htmlstyle FILE@>@M@{hints_htmlstyle.html@}
4121 @O@<hints_htmlstyle.html@>@{@-
4122 @<Begin FWTutMan page/wide/H1@>@(@<Hints_htmlstyle HEADING@>@)
4123
4124 @<P@>If you specify the @<TT@>@(+U@) command line option,
4125 FunnelWeb will generate a @<TT@>@(.html@) documentation file
4126 containing HTML. In the @<TT@>@(@<<@>HEAD@<>@>@) section of
4127 this file, FunnelWeb defines the style of the file by including
4128 a style directive similar to the following:
4129
4130 @<P@>
4131 @<Begin verbatim@>
4132 @<<@>STYLE TYPE="text/css"@<>@>
4133 @<<@>!--
4134 A {text-decoration: none}
4135 H1 { font-family: sans-serif; font-size: large }
4136 H2 { font-family: sans-serif; font-size: medium;
4137 font-weight: bold }
4138 H3 { font-family: sans-serif; font-size: medium }
4139 H4 { font-family: sans-serif; font-size: small }
4140 H5 { font-family: sans-serif; font-size: small }
4141 // --@<>@>
4142 @<<@>/STYLE@<>@>
4143 @<End verbatim@>
4144
4145 @<P@>If you do not like this style, you can change it simply by
4146 editing the @<TT@>@(.html@) file and changing the style directive in
4147 the @<TT@>@(@<<@>HEAD@<>@>@) section. However, this change will be
4148 overwritten the next time you regenerate the HTML file.
4149
4150 @<P@>Another way to define your own style is to turn off FunnelWeb's
4151 automatic @<DQ@>@(escaping@) of special characters with:
4152
4153 @<P@>
4154 @<Begin verbatim@>
4155 @@p typesetter = html
4156 @<End verbatim@>
4157
4158 @<P@>You can then include a style directive in one one of the very
4159 early comment parts of your FunnelWeb source file, where it will
4160 override the one written by FunnelWeb in the @<TT@>@(@<<@>HEAD@<>@>@)
4161 section. The disadvantage is that your FunnelWeb source file becomes
4162 typesetter-dependent.
4163
4164
4165 @<Nav@>@(@<Hints_tabs FILE@>@,@<Hints FILE@>@,@<Hints_emacs FILE@>@)
4166
4167 @<End FWTutMan page@>
4168 @}
4169
4170 @!==============================================================================
4171
4172 @$@<Hints_emacs HEADING@>@M@{@<SH@>@(5.15@)A FunnelWeb Mode For Emacs@}
4173 @$@<Hints_emacs FILE@>@M@{hints_emacs.html@}
4174 @O@<hints_emacs.html@>@{@-
4175 @<Begin FWTutMan page/wide/H1@>@(@<Hints_emacs HEADING@>@)
4176
4177 @<P@>@<Tony Coates@> has created a FunnelWeb Emacs mode, which he has
4178 made generally available. The mode is written as a FunnelWeb file. To
4179 use the mode, click on the link below. A new window should appear
4180 containing a plain text file which is the FunnelWeb source for the
4181 mode. Save the plain text file on your disk as @<TT@>@(fwmode.fw@) and
4182 then invoke FunnelWeb using @<TT@>@(fw fwmode@) to generate the emacs
4183 mode files @<TT@>@(fw-mode.el@) and @<TT@>@(switch-mode.el@).
4184
4185 @<P@>
4186 @<Begin indent@>
4187 @<Size4@>@(@<Link/blank@>@(fwmode.txt@,FunnelWeb Emacs Mode FunnelWeb Source File@)@)
4188 @<End indent@>
4189
4190 @<Nav/last@>@(@<Hints_htmlstyle FILE@>@,@<Hints FILE@>@,@<Hints FILE@>@)
4191
4192 @<End FWTutMan page@>
4193 @}
4194
4195 @O@<fwmode.txt@>@{@-
4196 @i 0fwmode
4197 @}
4198
4199 @!******************************************************************************
4200
4201 @$@<Examples HEADING@>@M@{@<SH@>@(6@)Examples of FunnelWeb Applications@}
4202 @$@<Examples HEADING/short@>@M@{@<SH@>@(6@)Examples@}
4203 @$@<Examples FILE@>@M@{examples.html@}
4204 @O@<examples.html@>@{@-
4205 @<Begin FWTutMan page/H1@>@(@<Examples HEADING@>@)
4206 @<XX@>@(FunnelWeb@,example applications@)@<XX@>@(FunnelWeb@,applications@)
4207
4208 @<P@>Despite (or perhaps because of) its flexibility and
4209 simplicity, FunnelWeb can be applied to quite a number of
4210 different text processing and documenting problems. This
4211 section gives some examples of some of the more interesting
4212 real problems that FunnelWeb has solved.
4213
4214 @<P@>
4215 @<Examples index@>
4216
4217 @<Nav@>@(@<Hints FILE@>@,@<Index FILE@>@,@<Web FILE@>@)
4218
4219 @<End FWTutMan page@>
4220 @}
4221
4222 @$@<Examples index@>@M@{
4223 @<Begin size3@>
4224 @<Begin indent/narrow@>
4225 @<Link@>@(@<Examples_postscript FILE@>@,@<Examples_postscript HEADING@>@)@<BR@>
4226 @<Link@>@(@<Examples_adt FILE@>@,@<Examples_adt HEADING@>@)@<BR@>
4227 @<Link@>@(@<Examples_languages FILE@>@,@<Examples_languages HEADING@>@)@<BR@>
4228 @<Link@>@(@<Examples_function FILE@>@,@<Examples_function HEADING@>@)@<BR@>
4229 @<Link@>@(@<Examples_comments FILE@>@,@<Examples_comments HEADING@>@)@<BR@>
4230 @<Link@>@(@<Examples_sharing FILE@>@,@<Examples_sharing HEADING@>@)@<BR@>
4231 @<Link@>@(@<Examples_generics FILE@>@,@<Examples_generics HEADING@>@)@<BR@>
4232 @<End indent/narrow@>
4233 @<End size3@>
4234 @}
4235
4236 @!==============================================================================
4237
4238 @$@<Examples_postscript HEADING@>@M@{@<SH@>@(6.1@)Analyzing the Monster Postscript Header File@}
4239 @$@<Examples_postscript FILE@>@M@{examples_postscript.html@}
4240 @O@<examples_postscript.html@>@{@-
4241 @<Begin FWTutMan page/H1@>@(@<Examples_postscript HEADING@>@)
4242 @<XX@>@(macro@,names@)@<XX@>@(macro@,identifiers@)
4243 @<XX@>@(monster file@,postscript@)
4244
4245 @<P@>During my Ph.D. candidature, I determined at one point
4246 that it would be very desirable to automatically insert
4247 diagrams from the @<I@>@(MacDraw@)@<X@>@(MacDraw@) program
4248 on my Macintosh into TeX@<X@>@(TeX@) @<TT@>@(insert@)ions in
4249 my thesis.@<XX@>@(PhD@,thesis@) This would allow diagrams to
4250 float around with the text and be printed automatically
4251 rather than having to be printed separately and stuck in
4252 with real glue. On the face of it, the problem seemed
4253 inherently solvable, as the Macintosh@<X@>@(Macintosh@) could
4254 generate PostScript@<X@>@(PostScript@) for each diagram and
4255 this PostScript could presumably be inserted into the
4256 PostScript generated using TeX.
4257
4258 @<P@>The only trouble was that the Macintosh PostScript code
4259 for the diagrams relied on an Apple PostScript header
4260 file.@<XX@>@(postscript@,header file@) This meant that the
4261 header file had to be included at the start of the TeX
4262 PostScript if the inserted PostScript for the diagrams was
4263 to work. Unfortunately, merely including the header file at
4264 the top didn't work, and it turned out that a rather
4265 detailed analysis of some parts of the Apple header file was
4266 required in order to perform the necessary surgery on the
4267 header file to make it work. This analysis was severely
4268 aggravated by the fact that the PostScript header file was
4269 virtually unreadable. Basically it was about 50K of
4270 interwoven definitions, that looked as if it had been run
4271 through a word processor. There was no way that the code
4272 could be understood clearly without some kind of
4273 reformatting. Two other aspects of the problem further
4274 complicated the analysis:
4275
4276 @<P@>
4277 @<Begin list@>
4278
4279 @<Item@>The definitions of interest (@<ie@>the ones causing
4280 the problems) were scattered throughout the heaeder file.
4281
4282 @<Item@>Many definitions could not be moved within the
4283 header file. For one or more
4284 reasons (@<eg@>to keep a definition within the activation of
4285 a particular dictionary @<TT@>@(begin@) and @<TT@>@(end@))
4286 it would have been unwise to move the definitions of
4287 interest to the same point in the file.
4288
4289 @<End list@>
4290
4291 @<P@>In fact the file was so messy and complicated that, as
4292 a rule, it had to be handled with kid gloves. It would have
4293 been unwise to re-arrange the definitions or to insert
4294 comments.
4295
4296 @<P@>To my surprise, FunnelWeb provided an unexpected
4297 solution to the problem. First I replaced all occurrences of
4298 the @<TT@>@(@@@) in the header file with @<TT@>@(@@@@@).
4299 Second, I placed the entire header file in a FunnelWeb macro
4300 definition connected to a product file. I then processed the
4301 file and checked to make sure that the product file was
4302 identical to the original file. By doing all this I had
4303 placed the header file under FunnelWeb control. I then left
4304 the macro definition largely untouched, but replaced the
4305 PostScript definitions of interest with FunnelWeb macro
4306 calls, moving the actual PostScript definitions into
4307 FunnelWeb macro definitions at the end of the FunnelWeb
4308 file.
4309
4310 @<P@>
4311 @<Begin verbatim@>
4312 @@O@@@<<@>LaserHeader.ps@@@<>@>==@@{@@-
4313 Unreadable Postscript code
4314 @@@<<@>Print routine@@@<>@>
4315 Unreadable Postscript code
4316 @@@<<@>Zap routine@@@<>@>
4317 Unreadable Postscript code
4318 @@}
4319
4320 @@A This routine looks as if it does this, but really is
4321 does that, blah, blah blah.
4322
4323 @@$@@@<<@>Print routine@@@<>@>==@@{@@-
4324 /print { push pop pop push turn around
4325 and jump up and down and print it} def
4326 @@}
4327
4328 @@A This routine zaps the...
4329
4330 @@$@@@<<@>Zap routine@@@<>@>==@@{@@-
4331 /zap { push pop pop push turn around and
4332 jump up and down and print it} def
4333 @@}
4334 @<End verbatim@>
4335
4336 @<P@>Use of FunnelWeb meant that I was able to pluck out the
4337 definitions of interest (a very small part of the whole
4338 file) and collect them as a group at the end of the file
4339 where they could be studied. Because each definition was
4340 safely contained in a macro, it was possible to write a
4341 detailed commentary of each routine without fear of
4342 affecting the final PostScript code in any way at all. Once
4343 this analysis was completed, it was possible to perform
4344 surgery on the offending PostScript definitions in an
4345 extremely controlled way. In particular, the FunnelWeb input
4346 file served as a repository for all the different versions
4347 of particular routines that were tried in order to get the
4348 definitions to work. A new (@<B@>@(Z@)ero) macro was created for
4349 each version of each definition, and a commentary of how it
4350 performed added above it.
4351
4352 @<P@>This case demonstrates that FunnelWeb is an extremely
4353 powerful tool for dissecting and documenting cryptic text
4354 files.@<XX@>@(cryptic@,text files@) Through the use of
4355 macros, particular parts of the file can be isolated and
4356 discussed without affecting the final product file in any
4357 way. In the example above, only a small part of the file was
4358 analysed, the rest being left as a blob, but in the general
4359 case, a cryptic text file could be inserted into FunnelWeb
4360 and then incrementally dissected (and possibly modified)
4361 until the result is a fully documented literate program.
4362 That this can be done without affecting the actual product
4363 file demonstrates the high degree of descriptive control
4364 that FunnelWeb provides.
4365
4366 @<Nav/first@>@(@<Examples FILE@>@,@<Examples FILE@>@,@<Examples_adt FILE@>@)
4367
4368 @<End FWTutMan page@>
4369 @}
4370
4371 @!==============================================================================
4372
4373 @$@<Examples_adt HEADING@>@M@{@<SH@>@(6.2@)Making Ada ADTs More Abstract@}
4374 @$@<Examples_adt FILE@>@M@{examples_adt.html@}
4375 @O@<examples_adt.html@>@{@-
4376 @<Begin FWTutMan page/H1@>@(@<Examples_adt HEADING@>@)
4377 @<X@>@(Ada@)@<X@>@(abstract data type@)@<X@>@(ADT@)
4378
4379 @<P@>Like many modern programming languages, Ada provides
4380 mechanisms for hiding information and structure. In
4381 particular, Ada provides a @<NewTerm@>@(package@) facility
4382 that allows the programmer to declare objects in a package
4383 definition and define them in a corresponding package body.
4384 This works well for functions and procedures. However, in
4385 the case of types, implementation issues (in particular, the
4386 need to know the size of exported types) have led the
4387 designers of Ada to force the placement of private type
4388 definitions in the definition package rather than the
4389 implementation package. This means that some implementation
4390 details are present in the package definition for all to
4391 see. While not actually dangerous (the user of the package
4392 cannot make use of the information without recourse to
4393 @<DQ@>@(Chapter@<_@>13@) of the Ada Language Reference
4394 Manual@<Paper@>@(DOD83@)), this aspect of Ada is certainly
4395 unpleasant.
4396
4397 @<P@>During the development of some Ada programs, FunnelWeb
4398 was used to solve this problem. Instead of creating a
4399 separate file for the package specification and package
4400 body, a single FunnelWeb file was created containing two
4401 sections, one for the each package part. The
4402 @<DQ@>@(private@) part of the package specification was then
4403 moved (using a FunnelWeb macro definition) to the section
4404 describing the package body. Readers who wished only to read
4405 the package specification could read only the first part,
4406 which contained a fully documented description not
4407 containing the private definition.
4408
4409 @<Nav@>@(@<Examples_postscript FILE@>@,@<Examples FILE@>@,@<Examples_languages FILE@>@)
4410
4411 @<End FWTutMan page@>
4412 @}
4413
4414 @!==============================================================================
4415
4416 @$@<Examples_languages HEADING@>@M@{@<SH@>@(6.3@)Multiple Language Systems@}
4417 @$@<Examples_languages FILE@>@M@{examples_languages.html@}
4418 @O@<examples_languages.html@>@{@-
4419 @<Begin FWTutMan page/H1@>@(@<Examples_languages HEADING@>@)
4420 @<XX@>@(multiple@,languages@)
4421
4422 @<P@>With the prevalence of open systems@<X@>@(open
4423 systems@) and multi-vendor computing, it is often necessary
4424 to construct systems consisting of programs written in a
4425 number of different programming languages for a number of
4426 different systems. For example, a particular functionality
4427 might be implemented by a shellscript (invoked by the user)
4428 that calls a C@<_@>program that makes a network connection to a
4429 Pascal program that queries a database. Quite often all
4430 these programs must conspire closely to execute their
4431 function. In the normal case, they must be written
4432 separately. FunnelWeb allows them to be written as a whole.
4433
4434 @<P@>By creating a single FunnelWeb file that creates many
4435 product files in different languages, the programmer can
4436 describe the interaction between the different programs in
4437 any manner desired. Furthermore, because the different
4438 product files are all created in the same @<DQ@>@(text
4439 space@) (@<ie@>in a single FunnelWeb file), it is easy for
4440 them to share information.
4441
4442 @<P@>For example, in one real application FunnelWeb was used
4443 to create a system for printing
4444 files@<XX@>@(printing@,system@) on a laser
4445 printer@<XX@>@(laser@,printer@) connected to a remote Vax
4446 Unix machine from a local Vax VMS machine. The system
4447 consisted of two files: a VMS DCL command procedure to run
4448 on the local node, and a Unix shellscript to run on the
4449 remote node. The user, by giving the print command, invoked
4450 the local VMS command procedure, which in turn fired up the
4451 remote Unix shellscript. The two scripts then cooperated to
4452 transfer the files to be printed and print them.
4453
4454 @<P@>In addition to its usual documentation powers,
4455 FunnelWeb assisted in the creation of this system in two
4456 special ways. First, it allowed pieces of code from the two
4457 different command procedures to be partially interwoven in a
4458 description of their interaction. This is just not possible
4459 with comments. Second, it facilitated the use of shared
4460 information. For example, under some conditions, each file
4461 to be printed would be renamed and copied to the remote
4462 system using a particular constant filename
4463 (@<eg@>@<DQP@>@(printfile.tmp@)). FunnelWeb allowed this
4464 constant filename to be included in a single macro
4465 definition which was invoked in the definition of each of
4466 the scripts. This ensured that the two scripts used the same
4467 name.
4468
4469 @<P@>
4470 @<Begin verbatim@>
4471 @@A The following macro contains the temporary
4472 file name used to allow the two shellscripts to
4473 transfer each file to be printed.
4474
4475 @@$@@@<<@>printfile@@@<>@>@@M==@@{printme.txt@@}
4476
4477 @@A Here are the scripts for the local VMS node
4478 and the remote UNIX node.
4479
4480 @@O@@@<<@>vmscommandprocedure.com@@@<>@>==@@{@@-
4481 DCL commands
4482 copy @@@<<@>printfile@@@<>@> unixnode::
4483 DCL commands
4484 @@}
4485
4486 @@O@@@<<@>unixshellscript@@@<>@>==@@{@@-
4487 unix commands
4488 print @@@<<@>printfile@@@<>@>
4489 unix commands
4490 @@}
4491 @<End verbatim@>
4492
4493 @<P@>In the case of the printing system, the entire system
4494 was described and defined in a single FunnelWeb
4495 @<TT@>@(.fw@) file. In larger systems containing many
4496 FunnelWeb @<TT@>@(.fw@) files for many different modules in
4497 many different languages, the same trick can be pulled by
4498 placing FunnelWeb macro definitions for shared values into
4499 FunnelWeb include files. For example, a suite of
4500 implementations of network nodes, with each implementation
4501 being in a different programming language for a different
4502 target machine, could all share a table of configuration
4503 constants defined in macros in a FunnelWeb include file.
4504
4505 @<P@>In summary, FunnelWeb's macro and include file
4506 mechanisms provide a simple way for programs written in
4507 different languages to share information. This reduces
4508 redundancy between the systems and hence the chance of
4509 inconsistencies arising.@<X@>@(sharing information@)
4510
4511 @<Nav@>@(@<Examples_adt FILE@>@,@<Examples FILE@>@,@<Examples_function FILE@>@)
4512
4513 @<End FWTutMan page@>
4514 @}
4515
4516 @!==============================================================================
4517
4518 @$@<Examples_function HEADING@>@M@{@<SH@>@(6.4@)The Case of the Small Function@}
4519 @$@<Examples_function FILE@>@M@{examples_function.html@}
4520 @O@<examples_function.html@>@{@-
4521 @<Begin FWTutMan page/H1@>@(@<Examples_function HEADING@>@)
4522 @<XX@>@(small@,functions@)
4523
4524 @<P@>Often, when programming, there is a need for a code
4525 abstraction@<XX@>@(code@,abstraction@) facility that
4526 operates at the text level. If the statement
4527 @<DQP@>@(a:=3;@) occurs often, it may be best simply to
4528 repeat it verbatim. If a sequence of one hundred statements
4529 is repeated often, it is normal to remove the code to a
4530 function and replace the occurrences by a function call.
4531 However, in between these two extremes are cases where a
4532 particular sequence of code is long enough and appears often
4533 enough to be troublesome, but which is bound so messily to
4534 its environment as to make a function call cumbersome.
4535
4536 @<P@>For example, the following line of statements
4537 (referring to five variables declared @<I@>@(local@) to a
4538 function) might appear ten times in a function:
4539
4540 @<P@>
4541 @<Begin verbatim@>
4542 a=b*3.14159; c=d % 256; e=e+1;
4543 @<End verbatim@>
4544
4545 @<P@>Now the @<DQ@>@(normal@) rule of programming says that
4546 these statements should be placed in a procedure (also
4547 called a @<DQ@>@(function@) in the C programming language
4548 used in this example), but here five local variables are
4549 used. Use of a procedure (function) would result in a
4550 procedure definition looking something like:
4551
4552 @<P@>
4553 @<Begin verbatim@>
4554 void frobit(a,b,c,d,e)
4555 float *a,b;
4556 int *c,d;
4557 unsigned *e;
4558 {*a=b @<<@>@<<@> 8; *c=d % 256; *e=*e+1;}
4559 @<End verbatim@>
4560
4561 @<P@>and a procedure call something like
4562
4563 @<P@>
4564 @<Begin verbatim@>
4565 frobit(&a,b,&c,d,&e);
4566 @<End verbatim@>
4567
4568 @<P@>This might be workable in a language that allowed
4569 formal parameters to be specified to be bound only to
4570 particular variables. Similarly, it might be possible to
4571 avoid the parameter list in languages that support local
4572 procedures that can access non-local variables (such as
4573 Pascal@<X@>@(Pascal@)). However, in our example here, in the
4574 C programming language, these options are not available, and
4575 so we must either create a function with five parameters, or
4576 use the C macro preprocessor@<XX@>@(preprocessor@,C@) (the
4577 best solution). FunnelWeb provides the same macro facility
4578 for languages that do not have a built-in preprocessor.
4579
4580 @<P@>In particularly speed-stressed applications, the
4581 programmer may be reluctant to remove code to a procedure
4582 because of the procedure-call overhead.@<XX@>@(procedure
4583 call@,overhead@) FunnelWeb macros can help there too.
4584
4585 @<P@>In summary, there sometimes arises in programming
4586 situations where the cost of defining a procedure is higher
4587 than the benefits it will bestow. Common reasons for this
4588 are the run-time procedure overhead and the messy binding
4589 problems@<XX@>@(binding@,problems@) caused by removing
4590 target code from its target context. FunnelWeb can help in
4591 these situations by allowing the programmer to define a text
4592 macro. This avoids all the problems and provides an
4593 additional incentive for the programmer to describe the
4594 piece of code so isolated.
4595
4596 @<Nav@>@(@<Examples_languages FILE@>@,@<Examples FILE@>@,@<Examples_comments FILE@>@)
4597
4598 @<End FWTutMan page@>
4599 @}
4600
4601 @!==============================================================================
4602
4603 @$@<Examples_comments HEADING@>@M@{@<SH@>@(6.5@)When Comments are Bad@}
4604 @$@<Examples_comments FILE@>@M@{examples_comments.html@}
4605 @O@<examples_comments.html@>@{@-
4606 @<Begin FWTutMan page/H1@>@(@<Examples_comments HEADING@>@)
4607 @<XX@>@(comments@,abuse@)@<XX@>@(eliminating@,comments@)
4608
4609 @<P@>In the @<DQ@>@(good old days@)@<X@>@(good old days@) of
4610 small machine memories and interpreted BASIC,@<X@>@(BASIC@)
4611 programmers would eliminate the @<DQP@>@(REM@)
4612 statements@<XX@>@(REM@,statement@) (comments) from their
4613 BASIC programs so as to save space and increase execution
4614 speed. Whilst this was obviously an appalling programming
4615 practice, the small memories and slow microprocessors often
4616 made this tempting, if not necessary.
4617
4618 @<P@>Thankfully, times have changed since then, and most
4619 code is now compiled rather than interpreted. However, from
4620 time to time one still runs into an environment or
4621 situation, or special-purpose language, where comments are
4622 either unavailable (no comment feature) or undesirable. Here
4623 FunnelWeb can be used to fully document the code without
4624 resulting in any comments in the final code at all. For
4625 example:@<XX@>@(header@,files@)
4626
4627 @<P@> @<Begin list@>
4628
4629 @<Item@>Comments in frequently used @<TT@>@(.h@) header
4630 files in C programs@<XX@>@(C@,header@) can have a
4631 significant impact on compilation speed. Often such header
4632 files are fairly cryptic and really ought to be well
4633 commented, but their authors are reluctant to.
4634
4635 @<Item@>Comments are undesirable in
4636 PostScript@<X@>@(postscript@) header files that must be
4637 transferred repeatedly along communications channels
4638 (@<eg@>the Apple Macintosh LaserWriter header file).
4639
4640 @<Item@>Interpreted programs in embedded systems.
4641
4642 @<Item@>Hand written machine code in hex dump form could be
4643 commented.
4644
4645 @<Item@>A programmer may wish to annotate a text data file
4646 containing lists of numbers that is to be fed into a
4647 statistical program that does not provide any comment
4648 facility for its input file.
4649
4650 @<End list@>
4651
4652 @<P@>In all these situations, FunnelWeb allows full
4653 integrated documentation without any impact on the final
4654 code.
4655
4656 @<Nav@>@(@<Examples_function FILE@>@,@<Examples FILE@>@,@<Examples_sharing FILE@>@)
4657
4658 @<End FWTutMan page@>
4659 @}
4660
4661 @!==============================================================================
4662
4663 @$@<Examples_sharing HEADING@>@M@{@<SH@>@(6.6@)Documents That Share Text@}
4664 @$@<Examples_sharing FILE@>@M@{examples_sharing.html@}
4665 @O@<examples_sharing.html@>@{@-
4666 @<Begin FWTutMan page/H1@>@(@<Examples_sharing HEADING@>@)
4667 @<XX@>@(sharing@,text@)
4668
4669 @<P@>FunnelWeb is very useful when preparing multiple
4670 documents that must share large slabs of identical text that
4671 are being constantly modified.
4672
4673 @<P@>For example someone preparing two slightly different
4674 user manuals for two slightly different audiences might want
4675 the manuals to share large slabs of text, while still
4676 allowing differences between them. The following example
4677 shows how this can be done. The code is cluttered, but this
4678 clutter would not be a problem if the lumps of text were
4679 moderately large.
4680
4681 @<P@>
4682 @<Begin verbatim@>
4683 @@O@@@<<@>manual1.txt@@@<>@>==@@{@@@<<@>M1@@@<>@>@@+@@}
4684 @@O@@@<<@>manual2.txt@@@<>@>==@@{@@@<<@>M2@@@<>@>@@+@@}
4685
4686 @@$@@@<<@>M1@@@<>@>+=@@{@@@<<@>T1@@@<>@>@@}
4687 @@$@@@<<@>M2@@@<>@>+=@@{@@@<<@>T1@@@<>@>@@}
4688 @@$@@@<<@>T1@@@<>@>@@M==@@{@@-
4689 First lump of text shared by both documents.@@+@@}
4690
4691 @@$@@@<<@>M1@@@<>@>+=@@{Text for first document@@+@@}
4692 @@$@@@<<@>M2@@@<>@>+=@@{Text for second document@@+@@}
4693
4694 @@$@@@<<@>M1@@@<>@>+=@@{@@@<<@>T2@@@<>@>@@}
4695 @@$@@@<<@>M2@@@<>@>+=@@{@@@<<@>T2@@@<>@>@@}
4696 @@$@@@<<@>T2@@@<>@>@@M==@@{@@-
4697 Second lump of text shared by both documents.@@+@@}
4698 @<End verbatim@>
4699
4700 @<P@>An alternative approach, which might work better in
4701 situations where there are many small differences between
4702 the two documents rather than a few large ones, is to define
4703 a macro with two arguments, one for each product file
4704 document. Write the document from top to bottom, but place
4705 all stretches that differ between the two documents in a
4706 macro call.@<XX@>@(annual@,report@)
4707
4708 @<P@>
4709 @<Begin verbatim@>
4710 @@! Set the definition of @@#D to
4711 @@! @@1 to create the shareholders report.
4712 @@! @@2 to create the customers report.
4713 @@$@@#D@@(@@2@@)@@M==@@{@@1@@}
4714
4715 @@O@@@<<@>report.txt@@@<>@>==@@{@@-
4716 ANNUAL REPORT TO @@#D@@(Shareholders@@,Customers@@)
4717 =================@@#D@@(============@@,=========@@)
4718 This has been a very good year for The Very Big
4719 Corporation of America. With your help, we have
4720 been able to successfully
4721 @@#D@@(@@"screw the customers
4722 for every cent they have@@"@@,
4723 @@"knock the shareholders into
4724 submission to bring you lower prices@@"@@).
4725 With gross earnings approaching six trillion
4726 dollars, we have been able to
4727 @@#D@@(@@"increase dividends@@"@@,
4728 @@"lower prices@@"@@).
4729 We expect to have an even better year next year.
4730 @@}
4731 @<End verbatim@>
4732
4733 @<P@>One application where text sharing can be particularly
4734 useful is in the preparation of computer
4735 documentation@<XX@>@(examples@,documentation@) containing
4736 examples. For example, a book describing a new programming
4737 language might be full of examples of small programs written
4738 in the language which the user might want to try without
4739 having to type them all in. The @<DQ@>@(default@) approach
4740 of keeping a copy of the examples in the text of the book
4741 and another copy in separate files is cumbersome and error
4742 prone, because both files have to be updated whenever an
4743 example is changed. A more sophisticated approach is to
4744 store each example in a separate file, and then use the
4745 @<DQ@>@(include file@) facility of the word processor to
4746 include each example in the text. This is a better solution,
4747 but suffers from a few drawbacks. First, when editing the
4748 book in a word processor, the examples in the book will not
4749 be directly accessible or visible. To see an example, the
4750 writer would have to open the file containing the example in
4751 a separate window. This could become tedious if the text
4752 contained many examples, as many texts do. Furthermore,
4753 there is a risk that some example files will be included in
4754 the wrong place. Second, because the book is dependent on
4755 the included files, the book will end up consisting of a
4756 directory of a hundred or more files instead of just a few.
4757
4758 @<P@>An alternative solution is to construct a single
4759 FunnelWeb @<TT@>@(.fw@) file that, when processed, produces
4760 both the book file and the example files. This solution
4761 assumes that the book consists of a text file containing
4762 commands for a typesetter such as TeX.
4763
4764 @<Begin verbatim@>
4765 @@O@@@<<@>Book.tex@@@<>@>==@@{@@#B@@}
4766
4767 @@$@@#B+=@@{@@-
4768 The first step to learning the object oriented
4769 AdaCgol++ language is to examine a hello world
4770 program.
4771
4772 \start{verbatim}
4773 @@@<<@>Ex1@@@<>@>
4774 \finish{verbatim}
4775 @@}
4776
4777 @@$@@@<<@>Ex1@@@<>@>==@@{@@-
4778 read iopack@@+Enter !World~! !Hello~! ex pr flu X[1]@@}
4779 @@O@@@<<@>Ex1.c@@@<>@>==@@{@@@<<@>Ex1@@@<>@>@@}
4780
4781 @@$@@#B+=@@{@@-
4782 To understand the program, think of the execution
4783 state as a plate of cheese...
4784 @@}
4785 @<End verbatim@>
4786
4787 @<P@>Most of the file will consist of part
4788 definitions of the additive macro @<TT@>@(@@#B@).
4789 The definition is @<DQ@>@(broken@) to allow a
4790 macro definition, wherever an example appears.
4791
4792 @<P@>The example above is a little messy because
4793 FunnelWeb does not allow macros connected to
4794 product files to be called, and it does not have
4795 text expressions that write to an product file as
4796 well as evaluating to text. Nevertheless, it
4797 presents a fairly clean solution to the problem of
4798 keeping the example programs in a computing text
4799 up to date.
4800
4801 @<Nav@>@(@<Examples_comments FILE@>@,@<Examples FILE@>@,@<Examples_generics FILE@>@)
4802
4803 @<End FWTutMan page@>
4804 @}
4805
4806 @!==============================================================================
4807
4808 @$@<Examples_generics HEADING@>@M@{@<SH@>@(6.7@)Generics@}
4809 @$@<Examples_generics FILE@>@M@{examples_generics.html@}
4810 @O@<examples_generics.html@>@{@-
4811 @<Begin FWTutMan page/H1@>@(@<Examples_generics HEADING@>@)
4812 @<XX@>@(generics@,fudging@)
4813
4814 @<P@>It is well known that generics in programming languages
4815 are closely aligned with textual substitution. In fact, a
4816 good way to understand the generic facility of a new
4817 programming language is to ask oneself the question
4818 @<DQ@>@(In what way does this generic facility differ from
4819 simple text substitution?@) The differences, if any,
4820 typically have to do with the difference in scoping between
4821 textual and intelligent substitution and whether the generic
4822 code is shared or copied by the implementation. In most
4823 cases the differences are quite minor.
4824
4825 @<P@>Because generic facilities are so closely aligned with
4826 text substitution, it is possible to use FunnelWeb's
4827 parameterized macros to provide generics in programming
4828 languages that do not support generics. Simply write a
4829 FunnelWeb macro whose parameters are the parameters of the
4830 generic and whose body is the generic object.
4831
4832 @<P@>The following FunnelWeb file gives an example of a
4833 fully worked Vax Pascal@<X@>@(Pascal@) generic set package
4834 implemented using FunnelWeb parameterized macros. The
4835 package was written by Barry Dwyer@<XN@>@(Barry@,Dwyer@) of
4836 the Computer Science Department of the University of
4837 Adelaide@<XX@>@(University@,Adelaide@) in 1987 and was
4838 emailed to me on 11@<_@>November 1987. The generic package
4839 provides a set abstraction@<XX@>@(set@,abstraction@)
4840 implemented using linked lists. Note the clever use of the
4841 instantiation parameters in type, function, and procedure
4842 names.
4843
4844 @<P@>
4845 @<Begin verbatim@>
4846 @@$@@@<<@>Generic Set Module@@@<>@>@@(@@2@@)==@@{@@-
4847 @@! @@1 is the base type, @@2 is the set type.
4848 [inherit ('@@1'), environment ('@@2')]
4849
4850 module @@2;
4851
4852 type @@2 = ^@@2Record;
4853 @@2Record = record
4854 Member: @@1;
4855 Next: @@2;
4856 end;
4857
4858 procedure Null@@2 (var Result: @@2);
4859 begin new (Result);
4860 Result^.Member := (- MaxInt)::@@1;
4861 Result^.Next := nil end;
4862
4863 function IsNull@@2 (S: @@2): boolean;
4864 begin
4865 IsNull@@2 := S^.Member::integer = - MaxInt
4866 end;
4867
4868 procedure ForEach@@1 (S: @@2; procedure DoIt (i: @@1));
4869 var ThisS, NextS: @@2;
4870 begin ThisS := S;
4871 while ThisS^.Member::integer @<<@>@<>@> - MaxInt do
4872 begin NextS := ThisS^.Next;
4873 DoIt (ThisS^.Member);
4874 ThisS := NextS end;
4875 end;
4876
4877 function First@@1 (S: @@2): @@1;
4878 begin First@@1 := S^.Member end;
4879
4880 function Is@@1InSet (i: @@1; S: @@2): boolean;
4881 procedure TestEquals (j: @@1);
4882 begin if Equal@@1 (i, j) then Is@@1InSet := true; end;
4883 begin
4884 Is@@1InSet := false;
4885 ForEach@@1 (S, TestEquals);
4886 end;
4887
4888 function Includes@@2 (S1, S2: @@2): boolean;
4889 var Result: boolean;
4890 procedure TestIfInS1 (i: @@1);
4891 begin
4892 if Result then
4893 if not Is@@1InSet (i, S1) then
4894 Result := false;
4895 end;
4896 begin Result := true;
4897 ForEach@@1 (S2, TestIfInS1);
4898 Includes@@2 := Result end;
4899
4900 function Disjoint@@2s (S1, S2: @@2): boolean;
4901 var Result: boolean;
4902 procedure TestIfInS1 (i: @@1);
4903 begin
4904 if Result then
4905 if Is@@1InSet (i, S1) then
4906 Result := false;
4907 end;
4908 begin Result := true;
4909 ForEach@@1 (S2, TestIfInS1);
4910 Disjoint@@2s := Result end;
4911
4912 function Equal@@2 (S1, S2: @@2): boolean;
4913 begin
4914 Equal@@2 := Includes@@2 (S1, S2) and
4915 Includes@@2 (S2, S1);
4916 end;
4917
4918 procedure Insert@@1 (i: @@1; var S: @@2);
4919 var This, Pred, Succ: @@2;
4920 begin
4921 if not Is@@1InSet (i, S) then
4922 begin
4923 Pred := nil; Succ := S;
4924 while Succ^.Member::integer @<>@> i::integer do
4925 begin Pred := Succ; Succ := Succ^.Next end;
4926 if Succ^.Member::integer @<<@> i::integer then
4927 begin
4928 new (This);
4929 This^.Next := Succ;
4930 This^.Member := i;
4931 if Pred @<<@>@<>@> nil then
4932 Pred^.Next := This
4933 else
4934 S := This;
4935 end;
4936 end;
4937 end;
4938
4939 procedure Insert@@1s (S1: @@2; var S2: @@2);
4940 var This, Pred, Succ: @@2;
4941 procedure Add@@1 (i: @@1);
4942 begin Insert@@1 (i, S2) end;
4943 begin
4944 ForEach@@1 (S1, Add@@1);
4945 end;
4946
4947 procedure Remove@@1 (i: @@1; var S: @@2);
4948 var Pred, This: @@2;
4949 begin
4950 Pred := nil; This := S;
4951 while not Equal@@1 (This^.Member, i) do begin
4952 Pred := This; This := This^.Next end;
4953 if Pred @<<@>@<>@> nil then
4954 Pred^.Next := This^.Next
4955 else
4956 S := This^.Next;
4957 Dispose (This);
4958 end;
4959
4960 procedure Dispose@@2 (var S: @@2);
4961 var Old: @@2;
4962 begin
4963 while S @<<@>@<>@> nil do
4964 begin
4965 Old := S;
4966 S := S^.Next;
4967 Dispose (Old)
4968 end;
4969 end;
4970
4971 end.
4972 @@}
4973
4974 @@O@@@<<@>NaryTreeSet.pas@@@<>@>==@@{@@-
4975 @@@<<@>Generic Set Module@@@<>@>@@-
4976 @@(@@"NaryTree@@"@@,@@"NaryTreeSet@@"@@)@@}
4977 @@O@@@<<@>NaryTreeSetSet.pas@@@<>@>==@@{@@-
4978 @@@<<@>Generic Set Module@@@<>@>@@-
4979 @@(@@"NaryTreeSet@@"@@,@@"NaryTreeSetSet@@"@@)@@}
4980 @<End verbatim@>
4981
4982 @<P@>A great advantage of the approach reflected in the
4983 above example is that it allows the programmer to construct
4984 a generic object in a language that does not supply
4985 generics, @<I@>@(with complete
4986 typesafety.@)@<XX@>@(typesafe@,generics@) This contrasts to
4987 the approach that might be used in a language such as C
4988 where the programmer might choose to construct a
4989 @<DQ@>@(generic@) package by parameterizing a package with
4990 pointers to @<TT@>@(void@). The resulting package is
4991 powerful but extremely untypesafe. Such a generic list
4992 package is used in the code of FunnelWeb itself and caused
4993 no end of problems, as the compiler had no way of telling if
4994 pointers to the correctly typed object were being handed to
4995 the correct list-object/function combination.
4996
4997 @<P@>The major disadvantage of the text generic approach is
4998 that it causes the code of the generic object to be
4999 duplicated once for each instantiation. Depending on the
5000 number and size of the instantiations, this may or may not
5001 be acceptable.
5002
5003 @<P@>Where the duplication of code is unacceptable, a hybrid
5004 approach may be taken. As in the C@<_@>example, the programmer
5005 could write a single generic package using pointers to
5006 @<TT@>@(void@) or some other untypesafe mechanism. Then the
5007 programmer creates a FunnelWeb generic package whose
5008 functions do nothing more than call the functions of the
5009 untypesafe package, and whose types do nothing more than
5010 contain the types of the untypesafe package. This solution
5011 involves the use of untypesafe programming, but this is a
5012 one-off and if done carefully and correctly, the result can
5013 be a typesafe generic package involving minimal code
5014 duplication.
5015
5016 @<Nav/last@>@(@<Examples_sharing FILE@>@,@<Examples FILE@>@,@<Examples FILE@>@)
5017
5018 @<End FWTutMan page@>
5019 @}
5020
5021 @!******************************************************************************
5022
5023 @$@<Web HEADING@>@M@{@<SH@>@(7@)Making Webs With FunnelWeb@}
5024 @$@<Web HEADING/short@>@M@{@<SH@>@(7@)Webmaking@}
5025 @$@<Web FILE@>@M@{web.html@}
5026 @O@<web.html@>@{@-
5027 @<Begin FWTutMan page/H1@>@(@<Web HEADING@>@)
5028
5029 @<P@>FunnelWeb was designed for the purposes of literate
5030 programming and was first created in 1986, long before the
5031 internet's World Wide Web appeared. So it came as a pleasant
5032 surprise to discover that FunnelWeb is an excellent tool for
5033 the preparation of websites! All the FunnelWeb webs,
5034 including the web you are reading right now, were created
5035 using FunnelWeb itself. This chapter explains how you can
5036 use FunnelWeb to make websites.
5037
5038 @<P@>
5039 @<Web index@>
5040
5041 @<Nav/last@>@(@<Examples FILE@>@,@<Index FILE@>@,@<Index FILE@>@)
5042
5043 @<End FWTutMan page@>
5044 @}
5045
5046 @$@<Web index@>@M@{
5047 @<Begin size3@>
5048 @<Begin indent/narrow@>
5049 @<Link@>@(@<Web_introduction FILE@>@,@<Web_introduction HEADING@>@)@<BR@>
5050 @<Link@>@(@<Web_start FILE@>@,@<Web_start HEADING@>@)@<BR@>
5051 @<Link@>@(@<Web_messy FILE@>@,@<Web_messy HEADING@>@)@<BR@>
5052 @<Link@>@(@<Web_errors FILE@>@,@<Web_errors HEADING@>@)@<BR@>
5053 @<Link@>@(@<Web_style FILE@>@,@<Web_style HEADING@>@)@<BR@>
5054 @<Link@>@(@<Web_libraries FILE@>@,@<Web_libraries HEADING@>@)@<BR@>
5055 @<Link@>@(@<Web_param FILE@>@,@<Web_param HEADING@>@)@<BR@>
5056 @<Link@>@(@<Web_conventions FILE@>@,@<Web_conventions HEADING@>@)@<BR@>
5057 @<End indent/narrow@>
5058 @<End size3@>
5059 @}
5060
5061 @!==============================================================================
5062
5063 @$@<Web_introduction HEADING@>@M@{@<SH@>@(7.1@)Introduction@}
5064 @$@<Web_introduction FILE@>@M@{web_introduction.html@}
5065 @O@<web_introduction.html@>@{@-
5066 @<Begin FWTutMan page/H1@>@(@<Web_introduction HEADING@>@)
5067
5068 @<P@>How can FunnelWeb be used to make webs? Easy!
5069 Here's how it works. You create a single file called (say)
5070 @<TT@>@(daves_web.fw@) containing a Funnelweb output
5071 file macro (@<TT@>@(@@O@)) for each page in the the web
5072 that you want to create. The @<TT@>@(daves_web.fw@) file
5073 contains the entire web. When you feed it through FunnelWeb,
5074 FunnelWeb generates all the HTML files in your web.
5075
5076 @<P@>
5077 @<Begin verbatim@>
5078 +--------------+
5079 | daves_web.fw |
5080 +--------------+
5081 |
5082 V
5083 o-------------------o
5084 | FunnelWeb Program |
5085 o-------------------o
5086 |
5087 V
5088 +----------------+----------------+
5089 | | |
5090 +--------------+ +------------+ +------------+
5091 | contact.html | | index.html | | links.html |
5092 +--------------+ +------------+ +------------+
5093 @<End verbatim@>
5094
5095 @<P@>Here are some key points about this application:
5096
5097 @<P@>
5098 @<Begin list@>
5099
5100 @<Item@>First, FunnelWeb can only generate the text files in
5101 your web (such as the @<TT@>@(.html@) files). You will still
5102 need to create the image files using the image manipulation
5103 tools you usually use; FunnelWeb does not help with the
5104 graphics, nor does it provide a GUI. You have to write raw
5105 HTML. However, FunnelWeb provides power tools for writing
5106 the HTML.
5107
5108 @<Blank line@>
5109
5110 @<Item@>Second, this is not a literate-programming
5111 application of webs. Here, FunnelWeb is being used purely as
5112 a macro preprocessor, and there will never be any cause to
5113 use FunnelWeb to generate documentation files (weaving). The
5114 files generated as above are FunnelWeb @<I@>@(output@)
5115 files, not FunnelWeb HTML documentation produced by the
5116 FunnelWeb weaver. This is a raw macro preprocessor
5117 application.
5118
5119 @<End list@>
5120
5121 @<P@>So what benefit is there in converting one's web to a
5122 single FunnelWeb file? If you have just a small number of
5123 pages in your web (as in the above diagram), there is
5124 probably not much benefit. However, if you have several
5125 pages in your web, FunnelWeb can provide huge benefits by
5126 enabling you to control the relationships between the
5127 various parts of your web and to parameterize it in whatever
5128 ways you want to. The result is a consistent style, a
5129 reduction of errors, and the power to execute broad ranging
5130 changes to the web with very little fuss. For example,
5131 FunnelWeb makes it easy to change the background of each
5132 page in your web, or to add a copyright notice at the bottom
5133 of every page.
5134
5135 @<P@>
5136
5137 @<P@>The advantages of using FunnelWeb to make webs are as follows:
5138
5139 @<P@>
5140 @<Begin list@>
5141 @<Item@>Web is represented by a single file.
5142 @<Item@>No more multiple-file replace operations!
5143 @<Item@>Define a consistent style for the web.
5144 @<Item@>Parameterize the web. Make global changes easily.
5145 @<Item@>Use the power of HTML without the messy HTML syntax.
5146 @<Item@>Eliminates many syntax and spelling errors.
5147 @<Item@>Eliminates bad (internal) links.
5148 @<Item@>Eliminates form/CGI cross reference errors.
5149 @<Item@>A flexible text power tool always available.
5150 @<End list@>
5151
5152 @<P@>The disadvantages of using FunnelWeb to make webs are as
5153 follows:
5154
5155 @<P@>
5156 @<Begin list@>
5157 @<Item@>No GUI interface. You have to write your web directly.
5158 @<Item@>It is more difficult to position graphics precisely.
5159 @<Item@>FunnelWeb files can look cryptic and messy.
5160 @<Item@>You have to run FunnelWeb between changing your web and
5161 viewing the changed pages.
5162 @<End list@>
5163
5164 @<P@>Thus, if you make webs that are highly graphics
5165 intensive, or if you are uncertain about writing HTML, you
5166 should probably not use FunnelWeb. However, if you are
5167 generating large webs with many similar pages, FunnelWeb
5168 will eliminate much of the hassle in managing the whole
5169 complex. For large webs, this management capability is
5170 invaluable.
5171
5172 @<P@>Whatever its advantages and disadvantages, FunnelWeb is
5173 certainly a @<B@>@(practical@) production-quality webmaking tool.
5174 It has been used to make all of the webs in the following
5175 web spaces (each of which contains several subwebs):
5176
5177 @<P@>
5178 @<Begin indent@>
5179 @<Ross Williams@>@<BR@>
5180 @<Rocksoft@>@<BR@>
5181 @<Veracity@>@<BR@>
5182 @<End indent@>
5183
5184 @<Nav/first@>@(@<Web FILE@>@,@<Web FILE@>@,@<Web_start FILE@>@)
5185
5186 @<End FWTutMan page@>
5187 @}
5188
5189 @!==============================================================================
5190
5191 @$@<Web_start HEADING@>@M@{@<SH@>@(7.2@)Getting Started@}
5192 @$@<Web_start FILE@>@M@{web_start.html@}
5193 @O@<web_start.html@>@{@-
5194 @<Begin FWTutMan page/H1@>@(@<Web_start HEADING@>@)
5195
5196 @<P@>This page contains a brief hands-on tutorial to get you started
5197 in using FunnelWeb to make webs.
5198
5199 @<FWTutMan subheading@>@(Hello Web@)
5200
5201 @<P@>The best way to understand how FunnelWeb can help you make webs
5202 is to work through a simple example. Here is one:
5203
5204 @<P@>
5205 @<Begin verbatim@>@=#
5206 @!************************************************
5207
5208 @O@#<<#>index.html@>@{
5209 ##<HTML##>
5210
5211 ##<HEAD##>
5212 ##<TITLE##>Dave's Home Page##</TITLE##>
5213 ##</HEAD##>
5214
5215 ##<BODY BGCOLOR=#@FFFFFF##>
5216 ##<P##>Welcome to my home page. Check out my
5217 ##<A HREF="links.html"##>links page##</A##>.
5218 ##</BODY##>
5219
5220 ##</HTML##>
5221 @}
5222
5223 @!************************************************
5224
5225 @O@##<links.html@##>@{
5226 ##<HTML##>
5227
5228 ##<HEAD##>
5229 ##<TITLE##>Dave's Links##</TITLE##>
5230 ##</HEAD##>
5231
5232 ##<BODY BGCOLOR=#@FFFFFF##>
5233 ##<P##>Here are my links:
5234
5235 ##<P##>
5236 ##<A HREF="http://www.yahoo.com/"##>Yahoo##</A##>##<BR##>
5237 ##<A HREF="http://www.dilbert.com/"##>Dilbert##</A##>##<BR##>
5238 ##</BODY##>
5239
5240 ##</HTML##>
5241 @}
5242
5243 @!************************************************
5244 #=@@<End verbatim@>
5245
5246 @<P@>Cut and paste the above text into a file called @<TT@>@(dave.fw@)
5247 and run FunnelWeb on it by giving the command:
5248
5249 @<P@>
5250 @<Begin verbatim@>
5251 fw dave
5252 @<End verbatim@>
5253
5254 @<P@>
5255 @<Begin blockquote@>
5256 @<Begin size2@>
5257 @<B@>@(Note:@) On my computer, when you cut and paste text
5258 from a web page, the pasted text contains a block of blanks
5259 before each line; you will have to delete these to make the
5260 example work, as FunnelWeb requires the first line of macro
5261 definitions to be in column one.
5262 @<End size2@>
5263 @<End blockquote@>
5264
5265 @<P@>If all goes well, FunnelWeb should write out two files
5266 @<TT@>@(index.html@) and @<TT@>@(links.html@). That's the
5267 generated web, and you should be able to browse it using your
5268 favorite web browser.
5269
5270 @<FWTutMan subheading@>@(First Glimmers Of Usefulness@)
5271
5272 @<P@>The sole benefit we have obtained so far is that the web
5273 is represented as a single file. This confers quite a few benefits
5274 on its own for medium-sized webs, such as the elimination of
5275 the need to perform multiple-file search and replace operations,
5276 but it's really only a start.
5277
5278 @<P@>The next step is to recognise that the two pages above share
5279 quite a lot of text and that that text can be removed into FunnelWeb
5280 macros.
5281
5282 @<P@>
5283 @<Begin verbatim@>@=#
5284 @!************************************************
5285
5286 @$@##<Begin page@>@(@1@)@M@{
5287 ##<HTML##>
5288 ##<HEAD##>
5289 ##<TITLE##>@1##</TITLE##>
5290 ##</HEAD##>
5291 ##<BODY BGCOLOR=#@FFFFFF##>
5292 @}
5293
5294 @$@##<End page@##>@M@{
5295 ##</BODY##>
5296 ##</HTML##>
5297 @}
5298
5299 @!************************************************
5300
5301 @O@##<index.html@##>@{
5302
5303 @##<Begin page@##>@(Dave's Home Page@)
5304
5305 ##<P##>Welcome to my home page. Check out my
5306 ##<A HREF="links.html"##>links page##</A##>.
5307
5308 @##<End page@##>
5309 @}
5310
5311 @!************************************************
5312
5313 @O@##<links.html@##>@{
5314 @##<Begin page@##>@(Dave's Links@)
5315
5316 ##<P##>Here are my links:
5317
5318 ##<P##>
5319 ##<A HREF="http://www.yahoo.com/"##>Yahoo##</A##>##<BR##>
5320 ##<A HREF="http://www.dilbert.com/"##>Dilbert##</A##>##<BR##>
5321
5322 @##<End page@##>
5323 @}
5324
5325 @!************************************************
5326 #=@@<End verbatim@>
5327
5328 @<P@>Now, although the file has actually got a little longer and
5329 looks far more complicated than it did, we've actually managed
5330 to extract two significant benefits from this reorganization.
5331
5332 @<Narrowthing@>@(Page style:@,First, almost without even
5333 trying, we've created a page style. For example, to change
5334 the colour of all the pages in the web, we need just change
5335 the single body definition in the begin page macro.
5336 Similarly, if we wanted to add a copyright notice at the
5337 bottom of each page, we need change only the end page
5338 macro.@)
5339
5340 @<Narrowthing@>@(Page overhead:@,Second, we've reduced the
5341 amount of text required to define each page. Instead of
5342 requiring ten lines of HTML to set up each page, we need
5343 just two FunnelWeb calls (two lines); the rest is text
5344 particular to the page being defined.@)
5345
5346 @<P@>These advantages may seem minor, but when scaled up to a
5347 web containing a dozen or more pages, they become very significant.
5348
5349 @<P@>The newfound power, in the case of the example, can be demonstrated
5350 by changing the web from black on white to blue on white, and by adding
5351 another page:
5352
5353 @<P@>
5354 @<Begin verbatim@>@=#
5355 @!************************************************
5356
5357 @$@##<Begin page@##>@(@1@)@M@{
5358 ##<HTML##>
5359 ##<HEAD##>
5360 ##<TITLE##>@1##</TITLE##>
5361 ##</HEAD##>
5362 ##<BODY BGCOLOR=#@FFFFFF TEXT=#@000033##>
5363 @}
5364
5365 @$@##<End page@##>@m@{
5366 ##</BODY##>
5367 ##</HTML##>
5368 @}
5369
5370 @!************************************************
5371
5372 @O@##<index.html@##>@{
5373 @##<Begin page@##>@(Dave's Home Page@)
5374
5375 ##<P##>Welcome to my home page. Check out my
5376 ##<A HREF="links.html"##>links page##</A##> and my
5377 ##<A HREF="hobbies.html"##>hobbies page##</A##>.
5378
5379 @##<End page@##>
5380 @}
5381
5382 @!************************************************
5383
5384 @O@##<links.html@##>@{
5385 @##<Begin page@##>@(Dave's Links@)
5386
5387 ##<P##>Here are my links:
5388
5389 ##<P##>
5390 ##<A HREF="http://www.yahoo.com/"##>Yahoo##</A##>##<BR##>
5391 ##<A HREF="http://www.dilbert.com/"##>Dilbert##</A##>##<BR##>
5392
5393 @##<End page@##>
5394 @}
5395
5396 @!************************************************
5397
5398 @O@##<hobbies.html@##>@{
5399 @##<Begin page@##>@(Dave's Hobbies@)
5400
5401 ##<P##>This page is under construction!
5402
5403 @##<End page@##>
5404 @}
5405
5406 @!************************************************
5407 #=@@<End verbatim@>
5408
5409 @<P@>Now that you have a Hello World file to play with, the remaining
5410 sections of this chapter will discuss the ways in which you can
5411 use the macro power now at your fingertips.
5412
5413 @<Nav@>@(@<Web_introduction FILE@>@,@<Web FILE@>@,@<Web_messy FILE@>@)
5414
5415 @<End FWTutMan page@>
5416 @}
5417
5418 @!==============================================================================
5419
5420 @$@<Web_messy HEADING@>@M@{@<SH@>@(7.3@)Replacing Messy HTML Constructs@}
5421 @$@<Web_messy FILE@>@M@{web_messy.html@}
5422 @O@<web_messy.html@>@{@-
5423 @<Begin FWTutMan page/H1@>@(@<Web_messy HEADING@>@)
5424
5425 @<P@>One of the greatest benefits of using FunnelWeb is its ability
5426 to replace messy slabs of HTML with a simple macro call. This page
5427 provides lots of examples of this.
5428
5429 @<FWTutMan subheading@>@(Hyperlinks@)
5430
5431 @<P@>Hyperlinks are messy and you can eliminate their messiness
5432 from your FunnelWeb web source by defining a macro for each link
5433 you want to use. For example:
5434
5435 @<P@>
5436 @<Begin verbatim@>@=#
5437 @$@##<Dilbert@##>@Z@M@{@-
5438 ##<A HREF="http://www.dilbert.com/"##>Dilbert##</A##>@}
5439 @$@##<Yahoo@##>@Z@M@{@-
5440 ##<A HREF="http://www.yahoo.com/"##>Yahoo##</A##>@}
5441 #=@@<End verbatim@>
5442
5443 @<P@>While the definitions themselves are certainly messy,
5444 having made them, we are now free to refer to Dilbert and
5445 Yahoo within our webs in a very clean manner indeed. For
5446 example, the links page of the previous example now becomes
5447 just:
5448
5449 @<P@>
5450 @<Begin verbatim@>@=#
5451 @O@##<links.html@##>@{
5452 @##<Begin page@##>@(Dave's Links@)
5453
5454 ##<P##>Check out @##<Dilbert@##> and @##<Yahoo@##>!
5455
5456 @##<End page@##>
5457 @}
5458 #=@@<End verbatim@>
5459
5460 @<FWTutMan subheading@>@(Images@)
5461
5462 @<P@>Suppose we want to include a small image of a checkmark
5463 at various points without a web page. Here's the HTML that
5464 has to be included at each point:
5465
5466 @<P@>
5467 @<Begin verbatim@>@=#
5468 ##<IMG SRC="bin/tick_red_12.gif"
5469 WIDTH="12" HEIGHT="12"
5470 HSPACE=4 VSPACE=0
5471 ALT="*" BORDER="0"##>
5472 #=@@<End verbatim@>
5473
5474 @<P@>Yuk! To eliminate this mess in our FunnelWeb/HTML, we
5475 can define a macro for a tick mark as follows:
5476
5477 @<P@>
5478 @<Begin verbatim@>@=#
5479 @$@##<Tick@##>@M@{
5480 ##<IMG SRC="bin/tick_red_12.gif"
5481 WIDTH="12" HEIGHT="12"
5482 HSPACE=4 VSPACE=0
5483 ALT="*" BORDER="0"##>@}
5484 #=@@<End verbatim@>
5485
5486 @<P@>Now, using tick marks without your text is easy.
5487 Here's an example:
5488
5489 @<P@>
5490 @<Begin verbatim@>@=#
5491 @##<Tick@##>Low cost.##<BR##>
5492 @##<Tick@##>Easy installation.##<BR##>
5493 @##<Tick@##>Available now!##<BR##>
5494 #=@@<End verbatim@>
5495
5496 @<FWTutMan subheading@>@(Large Form Fields@)
5497
5498 @<P@>Another example is where you have form fields
5499 with lots of options. Here's an example of a commonly
5500 occurring form field that goes on for a couple of
5501 hundred lines!
5502
5503 @<P@>
5504 @<Begin verbatim@>@=#
5505 ##<SELECT NAME="Country"##>
5506 ##<OPTION##>United States
5507 ##<OPTION##>Afghanistan
5508 ##<OPTION##>Albania
5509 ...
5510 ##<OPTION##>Zambia
5511 ##<OPTION##>Zimbabwe
5512 ##</SELECT##>
5513 #=@@<End verbatim@>
5514
5515 @<P@>Using FunnelWeb, you can move all this to a single macro
5516 definition as follows:
5517
5518 @<P@>
5519 @<Begin verbatim@>@=#
5520 @$@##<Country form field@##>@M@(
5521 ##<SELECT NAME="Country"##>
5522 ##<OPTION##>United States
5523 ##<OPTION##>Afghanistan
5524 ##<OPTION##>Albania
5525 ...
5526 ##<OPTION##>Zambia
5527 ##<OPTION##>Zimbabwe
5528 ##</SELECT##>
5529 #=@@<End verbatim@>
5530
5531 @<P@>Now, whenever you want a country field in a form, you can
5532 just write:
5533
5534 @<P@>
5535 @<Begin verbatim@>@=#
5536 @##<Country form field@##>
5537 #=@@<End verbatim@>
5538
5539 @<FWTutMan subheading@>@(Navigation Buttons@)
5540
5541 @<P@>Sometimes the navigation constructs that appear
5542 within pages can become rather messy. Here's an example
5543 where we have three buttons at the bottom of each page.
5544
5545 @<P@>
5546 @<Begin verbatim@>@=#
5547 ##<TABLE WIDTH="100%"##>
5548 ##<TR##>
5549 ##<TD ALIGN="left" VALIGN="bottom"##>##<
5550 A HREF="links.html"##>##<IMG SRC="bin/left.gif"##>##</A##>##</TD##>
5551 ##<TD ALIGN="center" VALIGN="bottom"##>##<
5552 A HREF="home.html"##>##<IMG SRC="bin/up.gif"##>##</A##>##</TD##>
5553 ##<TD ALIGN="right" VALIGN="bottom"##>##<
5554 A HREF="hobbies.html"##>##<
5555 IMG SRC="bin/right.gif"##>##</A##>##</TD##>
5556 ##</TR##>
5557 ##</TABLE##>
5558 #=@@<End verbatim@>
5559
5560 @<P@>We can move all this to a single macro definition
5561 that has three parameters, one for each target page.
5562
5563 @<P@>
5564 @<Begin verbatim@>@=#
5565 @$@##<Nav@##>@(@3@)@Z@M@{
5566 @##<P@##>
5567 ##<TABLE WIDTH="100%"##>
5568 ##<TR##>
5569 ##<TD ALIGN="left" VALIGN="bottom"##>##<
5570 A HREF="@1"##>##<IMG SRC="bin/left.gif"##>##</A##>##</TD##>
5571 ##<TD ALIGN="center" VALIGN="bottom"##>##<
5572 A HREF="@2"##>##<IMG SRC="bin/up.gif"##>##</A##>##</TD##>
5573 ##<TD ALIGN="right" VALIGN="bottom"##>##<
5574 A HREF="@3"##>##<IMG SRC="bin/right.gif"##>##</A##>##</TD##>
5575 ##</TR##>
5576 ##</TABLE##>
5577 @}
5578 #=@@<End verbatim@>
5579
5580 @<P@>Now, to add navigation buttons to a page,
5581 we can just write (near the end of the page).
5582
5583 @<P@>
5584 @<Begin verbatim@>@=#
5585 @##<Nav@##>@(links.html@,home.html@,hobbies.html@)
5586 #=@@<End verbatim@>
5587
5588 @<P@>If you wanted to, you could build the navigation
5589 buttons into the @<TT@>@(@@@<<@>End page@@@<>@>@) macro
5590 and set it up with three parameters instead.
5591
5592 @<Nav@>@(@<Web_start FILE@>@,@<Web FILE@>@,@<Web_errors FILE@>@)
5593
5594 @<End FWTutMan page@>
5595 @}
5596
5597 @!==============================================================================
5598
5599 @$@<Web_errors HEADING@>@M@{@<SH@>@(7.4@)Avoiding Errors And Inconsistencies@}
5600 @$@<Web_errors FILE@>@M@{web_errors.html@}
5601 @O@<web_errors.html@>@{@-
5602 @<Begin FWTutMan page/H1@>@(@<Web_errors HEADING@>@)
5603
5604 @<P@>FunnelWeb provides the opportunity to eliminate all kinds of
5605 errors and inconsistencies by replacing text names with FunnelWeb
5606 macro names that cannot be misspelt without being detected by FunnelWeb.
5607 This page provides some examples of this.
5608
5609 @<FWTutMan subheading@>@(Minor Style Elements@)
5610
5611 @<P@>Have you ever done this:
5612
5613 @<P@>
5614 @<Begin verbatim@>@=#
5615 This is ##<B Very Important##</B##>!
5616 #=@@<End verbatim@>
5617
5618 @<P@>These kinds of errors can be eliminated by replacing HTML
5619 constructs, even simple ones, by FunnelWeb macros:
5620
5621 @<P@>
5622 @<Begin verbatim@>@=#
5623 @$@##<B@##>@(@1@)@M@{##<B##>@1##</B##>@}
5624 ...
5625 This is @##<B@##>@(Very Important@)!
5626 #=@@<End verbatim@>
5627
5628 @<P@>While this is a bit messier, it eliminates the chance of an
5629 error because if you get the syntax wrong, FunnelWeb will generate
5630 an error at "compile time", which is a lot better than receiving
5631 email from some random web visitor. It's true that the same level
5632 of checking can be obtained by running an HTML syntax checker
5633 over your web. However, if you're using FunnelWeb for all its
5634 other benefits, you might as well use this aspect too.
5635
5636 @<FWTutMan subheading@>@(File Names In Hyperlinks@)
5637
5638 @<P@>Another source of error in webs is bad internal links.
5639 This can occur when you rename a file and forget to "fix up"
5640 all the links to it, and when you make a typing error when
5641 typing in a filename in a hyperlink.
5642
5643 @<P@>You can use FunnelWeb to eliminate both of these kinds
5644 of error, by defining a macro for each output file. This is
5645 easier to do than explain:
5646
5647 @<P@>
5648 @<Begin verbatim@>@=#
5649 @!************************************************
5650
5651 @$@##<Begin page@##>@(@1@)@M@{
5652 ##<HTML##>
5653 ##<HEAD##>
5654 ##<TITLE##>@1##</TITLE##>
5655 ##</HEAD##>
5656 ##<BODY BGCOLOR=#@FFFFFF TEXT=#@000033##>
5657 @}
5658
5659 @$@##<End page@##>@M@{
5660 ##</BODY##>
5661 ##</HTML##>
5662 @}
5663
5664 @!************************************************
5665
5666 @O@##<index.html@##>@{
5667 @##<Begin page@##>@(Dave's Home Page@)
5668
5669 ##<P##>Welcome to my home page. Check out my
5670 ##<A HREF="@##<Links FILE@##>"##>links page##</A##> and my
5671 ##<A HREF="@##<Hobbies FILE@##>"##>hobbies page##</A##>.
5672
5673 @##<End page@##>
5674 @}
5675
5676 @!************************************************
5677
5678 @$@##<Links FILE@##>@M@{links.html@}
5679 @O@##<links.html@##>@{
5680 @##<Begin page@##>@(Dave's Links@)
5681
5682 ##<P##>Here are my links:
5683
5684 ##<P##>
5685 ##<A HREF="http://www.yahoo.com/"##>Yahoo##</A##>##<BR##>
5686 ##<A HREF="http://www.dilbert.com/"##>Dilbert##</A##>##<BR##>
5687
5688 @##<End page@##>
5689 @}
5690
5691 @!************************************************
5692
5693 @$@##<Hobbies FILE@##>@M@{hobbies.html@}
5694 @O@##<hobbies.html@##>@{
5695 @##<Begin page@##>@(Dave's Hobbies@)
5696
5697 ##<P##>This page is under construction!
5698
5699 @##<End page@##>
5700 @}
5701
5702 @!************************************************
5703 #=@@<End verbatim@>
5704
5705 @<P@>Again, this technique introduces a little messiness, but
5706 the benefits it brings are significant. Once you have deployed
5707 this technique throughout your web source file, you will then
5708 be free to change the names of any of your files without ever
5709 having to worry about fixing up any links - they will all be
5710 fixed automatically! Furthermore, if you delete an output
5711 file from your FunnelWeb source file, FunnelWeb will alert
5712 you to any "dangling links" because the references to the
5713 deleted page take the form of calls to a macro that is no
5714 longer defined! Of course, this only works if you don't mark
5715 your filename macros with @<TT@>@(@@Z@).
5716
5717 @<P@>The only thing you have to get right is to ensure that
5718 the filename of the output macro is the same as the value
5719 of the corresponding naming macro. This isn't too hard to
5720 do because they are always on adjacent lines.
5721
5722 @<P@>The benefit of eliminating all bad links from one's
5723 web is a benefit that can be obtained by running an external
5724 web analysis tool over your web. However, by using FunnelWeb
5725 file naming macros, you can be SURE that the web can never
5726 be generated with a bad link, whereas the web analysis tool
5727 only works if you remember to run it!
5728
5729 @<FWTutMan subheading@>@(People's Names@)
5730
5731 @<P@>Sometimes you might have to create a web that contains lots
5732 of long names that are hard to remember or spell. FunnelWeb
5733 can help here by eliminating the chance of error. Just define
5734 each name as macro and always call the macro when using the
5735 name. The benefit of doing this is that FunnelWeb will always
5736 detect a spelling error because if you make a spelling error
5737 in the macro name, FunnelWeb will generate a "macro not defined"
5738 error.
5739
5740 @<P@>
5741 @<Begin verbatim@>@=#
5742 @$@##<Marvin Hylrzbvwryvitz@##>@M@{Marvin Hylrzbvwryvitz@}
5743 #=@@<End verbatim@>
5744
5745 @<P@>If you want to, you could used a shortened form. For example:
5746
5747 @<P@>
5748 @<Begin verbatim@>@=#
5749 @$@##<Marvin@##>@M@{Marvin Hylrzbvwryvitz@}
5750 #=@@<End verbatim@>
5751
5752 @<FWTutMan subheading@>@(CGI Form Fields@)
5753
5754 @<P@>One of the organizational challenges of implementing
5755 CGI form processing is getting all the field names right.
5756 Because (normally) the form is in one file, and the CGI
5757 script that processes it is in another file, it's very
5758 easy to accidentally use different names for the same
5759 field. For example, you might use @<TT@>@(email_adr@) in
5760 one and @<TT@>@(email-adr@) in the other.
5761
5762 @<P@>FunnelWeb can be used to completely eliminate this
5763 problem as follows:
5764
5765 @<P@>
5766 @<Begin list/ordered@>
5767
5768 @<Item@>Put both the HTML file containing the form and the
5769 CGI file that processes it within the @<TT@>@(.fw@) file
5770 that embodies your web.
5771
5772 @<Blank line@>
5773
5774 @<Item@>Define a macro for the name of each field and use
5775 the macro in both the form and the CGI script.
5776
5777 @<End list/ordered@>
5778
5779 @<P@>Here's an example:
5780
5781 @<P@>
5782 @<Begin verbatim@>@=#
5783 @!************************************************
5784
5785 @$@##<Email FIELD@##>@M@{email_adr@}
5786
5787 @!************************************************
5788
5789 @O@##<order.html@##>@{
5790 @##<Begin page@##>@(Order Form@)
5791
5792 ##<P##>
5793 ##<FORM ...##>
5794 ##<INPUT TYPE="text" NAME="@##<Email FIELD@##>"##>
5795 ...
5796 ##</FORM##>
5797
5798 @##<End page@##>
5799 @}
5800
5801 @!************************************************
5802
5803 @O@##<order.cgi@##>@{@-
5804 @##<Begin CGI page@##>
5805 ...
5806 $v = $form{'@##<Email FIELD@##>'};
5807 @##<End CGI page@##>
5808 @}
5809
5810 @!************************************************
5811 #=@@<End verbatim@>
5812
5813 @<P@>This technique more or less completely eliminates
5814 mismatch errors in form field names, for if any such error
5815 is made, FunnelWeb will generate a "macro not defined"
5816 error. All you have to do to benefit from this technique
5817 is get into the habit of using it.
5818
5819 @<FWTutMan subheading@>@(When Global Replace Fails@)
5820
5821 @<P@>Many people who write HTML directly use nerve wracking
5822 multi-file global replaces to perform the kind of web
5823 parameterization that FunnelWeb makes so easy.
5824 Unfortunately, these global replacements can go badly wrong
5825 because the target text may be used in many different
5826 contexts. In some cases, this approach fails completely.
5827
5828 @<P@>For example, suppose that you have to create a hundred
5829 page web that has to be laced with two email addresses: a
5830 "business" email address and a "personal" email address. No
5831 problem so far. However, suppose that you haven't yet chosen
5832 a business domain name and, as a result, at the current
5833 time, the two email addresses are the same! If this were the
5834 case, you would have to put your address throughout all the
5835 pages and would LOSE the information of which were supposed
5836 to be business addresses and which were supposed to be
5837 personal ones.
5838
5839 @<P@>FunnelWeb solves this problem (and others like it)
5840 completely by allowing you to define two macros one for each
5841 context. For example:
5842
5843 @<P@>
5844 @<Begin verbatim@>@=#
5845 @$@##<Business EMAIL@##>@M@{dave@@someisp.com.au@}
5846 @$@##<Personal EMAIL@##>@M@{dave@@someisp.com.au@}
5847 #=@@<End verbatim@>
5848
5849 @<P@>These macros can then be used as appropriate. Later,
5850 when the domain name comes through and the business address
5851 changes, all that needs to be changed is a single definition:
5852
5853 @<P@>
5854 @<Begin verbatim@>@=#
5855 @$@##<Business EMAIL@##>@M@{dave@@megacorp.com.au@}
5856 @$@##<Personal EMAIL@##>@M@{dave@@someisp.com.au@}
5857 #=@@<End verbatim@>
5858
5859 @<P@>There is no need to perform a multi-file global replace
5860 and evaluate the context of the use of each email address,
5861 as the information was not lost when the web was originally
5862 created, because of the two macros.
5863
5864 @<P@>This example is just one of many similar situations that
5865 arise. By locating all the pages of your web in a single file
5866 and allowing you to define macros for different purposes,
5867 you can eliminate much of the time and danger of global
5868 replacements.
5869
5870 @<Nav@>@(@<Web_messy FILE@>@,@<Web FILE@>@,@<Web_style FILE@>@)
5871
5872 @<End FWTutMan page@>
5873 @}
5874
5875 @!==============================================================================
5876
5877 @$@<Web_style HEADING@>@M@{@<SH@>@(7.5@)Defining A Consistent Style@}
5878 @$@<Web_style FILE@>@M@{web_style.html@}
5879 @O@<web_style.html@>@{@-
5880 @<Begin FWTutMan page/H1@>@(@<Web_style HEADING@>@)
5881
5882 @<P@>We have already seen how FunnelWeb can be used, through the
5883 use of @<TT@>@(@@@<<@>Begin page@@@<>@>@) and
5884 @<TT@>@(@@@<<@>End page@@@<>@>@) macros to set up
5885 a particular page style throughout a web.
5886 However, this is really just the beginning of FunnelWeb's capacity
5887 to manage the style of a web. This page provides some other ideas.
5888
5889 @<FWTutMan subheading@>@(Generic Style Macros@)
5890
5891 @<P@>HTML contains some tags such as @<TT@>@(@<<@>em@<>@>@)
5892 that have a high-level meaning (@<DQ@>@(emphasis@)) rather than
5893 a low-level meaning such as @<DQ@>@(italics@). You can use FunnelWeb
5894 to create your own high level formatting macros so that you can later
5895 change the style of the web just by changing the macro definitions.
5896
5897 @<P@>For example, suppose that your web contains lots of latin names
5898 of plants. You've decided that you want to highlight the names, but
5899 haven't decided how. Using FunnelWeb you can just define a macro:
5900
5901 @<P@>
5902 @<Begin verbatim@>@=#
5903 @$@##<Latin@##>@(@1@)@M@{##<B##>@1##</B##>@}
5904 #=@@<End verbatim@>
5905
5906 @<P@>This means that all latin names will be set in bold. However,
5907 if at a later date, you change your mind, you can just change the
5908 definition to some other format.
5909
5910 @<FWTutMan subheading@>@(Margins@)
5911
5912 @<P@>Here's another example. Suppose that you want some parts of
5913 the text in your web to be narrower than others. You can achive
5914 this by defining and using a macro like this:
5915
5916 @<P@>
5917 @<Begin verbatim@>@=#
5918 @$@##<Narrower@##>@(@1@)@M@{@-
5919 ##<TABLE##>##<TR##>##<TD WIDTH="200"##>
5920 @1
5921 ##</TD##>##</TR##>##</TABLE##>
5922 @}
5923 #=@@<End verbatim@>
5924
5925 @<P@>If at a later date, you want to change all the widths, you
5926 just need to change the single definition.
5927
5928 @<Nav@>@(@<Web_errors FILE@>@,@<Web FILE@>@,@<Web_libraries FILE@>@)
5929
5930 @<End FWTutMan page@>
5931 @}
5932
5933 @!==============================================================================
5934
5935 @$@<Web_libraries HEADING@>@M@{@<SH@>@(7.6@)Defining Macro Libraries@}
5936 @$@<Web_libraries FILE@>@M@{web_libraries.html@}
5937 @O@<web_libraries.html@>@{@-
5938 @<Begin FWTutMan page/H1@>@(@<Web_libraries HEADING@>@)
5939
5940 @<FWTutMan subheading@>@(Separating Macros Into An Include File@)
5941
5942 @<P@>Once you start using FunnelWeb to make webs, you'll discover
5943 that you find yourself defining and using the same macros over and
5944 over. Rather than redefining them for each new web you make, you
5945 can place them all in a FunnelWeb include file, so that they can
5946 be included in the FunnelWeb file for each web you make. Suppose
5947 that we create a file called @<TT@>@(style.fwi@) containing the
5948 following text:
5949
5950 @<P@>
5951 @<Begin verbatim@>@=#
5952 @$@##<Begin page@##>@(@1@)@M@{
5953 ##<HTML##>
5954 ##<HEAD##>
5955 ##<TITLE##>@1##</TITLE##>
5956 ##</HEAD##>
5957 ##<BODY BGCOLOR=#@FFFFFF TEXT=#@000033##>
5958 @}
5959
5960 @$@##<End page@##>@{
5961 ##</BODY##>
5962 ##</HTML##>
5963 @}
5964
5965 @$@##<Dilbert@##>@Z@M@{@-
5966 ##<A HREF="http://www.dilbert.com/"##>Dilbert##</A##>@}
5967 @$@##<Yahoo@##>@Z@M@{@-
5968 ##<A HREF="http://www.yahoo.com/"##>Yahoo##</A##>@}
5969 #=@@<End verbatim@>
5970
5971 @<P@>Once this is done, the main web file can become:
5972
5973 @<P@>
5974 @<Begin verbatim@>@=#
5975 @!************************************************
5976
5977 @i style
5978
5979 @!************************************************
5980
5981 @O@##<index.html@##>@{
5982 @##<Begin page@##>@(Dave's Home Page@)
5983
5984 ##<P##>Welcome to my home page. Check out my
5985 ##<A HREF="@##<Links FILE@##>"##>links page##</A##>.
5986
5987 @##<End page@##>
5988 @}
5989
5990 @!************************************************
5991
5992 @$@##<Links FILE@##>@M@{links.html@}
5993 @O@##<links.html@##>@{
5994 @##<Begin page@##>@(Dave's Links@)
5995
5996 ##<P##>Check out @##<Yahoo@##> and @##<Dilbert@##>.
5997
5998 @##<End page@##>
5999 @}
6000
6001 @!************************************************
6002 #=@@<End verbatim@>
6003
6004 @<P@>Now we're starting to see some real simplification!
6005
6006 @<P@>Note: It's important to attach @<TT@>@(@@Z@) to any
6007 macro you place in an include file that you think might
6008 not be called in some webs. If you don't, FunnelWeb will issue
6009 @<DQ@>@(this macro is unused@) errors for the included
6010 macros you don't use.
6011
6012 @<FWTutMan subheading@>@(Library Macros@)
6013
6014 @<P@>Once you've created one or more macro libraries in the
6015 form of FunnelWeb include files, you might find that sometimes
6016 you want to redefine some of the macros that the include
6017 file provides. For example, suppose that we are preparing
6018 an Australian web page and that when we refer to Yahoo, we
6019 want to refer to the Australian Yahoo site. If we try to
6020 redefine the Yahoo macro:
6021
6022 @<P@>
6023 @<Begin verbatim@>@=#
6024
6025 @i style
6026
6027 ...
6028
6029 @$@##<Yahoo@##>@Z@M@{@-
6030 ##<A HREF="http://www.yahoo.com.au/"##>Yahoo##</A##>@}
6031 #=@@<End verbatim@>
6032
6033 @<P@>then FunnelWeb will issue an error @<DQ@>@(this macro
6034 is already defined@). FunnelWeb does not allow macros to
6035 be redefined because this could be dangerous in a programming
6036 context. It would be very bad if a programmer thought they
6037 was invoking one piece of text when they were really invoking
6038 another. So FunnelWeb complains.
6039
6040 @<P@>To stop FunnelWeb complaining, you can tag with a library
6041 macro marker @<TT@>@(@@L@) any macro in the include file that
6042 you want to be able to redefine. For example:
6043
6044 @<P@>
6045 @<Begin verbatim@>@=#
6046 @$@##<Dilbert@##>@Z@M@L@{@-
6047 ##<A HREF="http://www.dilbert.com/"##>Dilbert##</A##>@}
6048 @$@##<Yahoo@##>@Z@M@L@{@-
6049 ##<A HREF="http://www.yahoo.com/"##>Yahoo##</A##>@}
6050 #=@@<End verbatim@>
6051
6052 @<P@>This allows us to redefined the Yahoo and Dilbert macros.
6053
6054 @<FWTutMan subheading@>@(Modifying Default Behaviour@)
6055
6056 @<P@>The library macro mechanism allows you to set up all kinds
6057 of default behaviour that can be modified in specific webs. For
6058 example, suppose that we rewrote the macro library as:
6059
6060 @<P@>
6061 @<Begin verbatim@>@=#
6062 @$@##<Begin page@##>@(@1@)@M@{
6063 ##<HTML##>
6064 ##<HEAD##>
6065 ##<TITLE##>@1##</TITLE##>
6066 ##</HEAD##>
6067 @##<Body@##>
6068 @}
6069
6070 @$@##<End page@##>@{
6071 ##</BODY##>
6072 ##</HTML##>
6073 @}
6074
6075 @$@##<Body@##>@L@{@-
6076 ##<BODY BGCOLOR=#@FFFFFF TEXT=#@000033##>@}
6077 #=@@<End verbatim@>
6078
6079 @<P@>Once this is done, we can modify the page background
6080 and colours of any web by redefining the @<TT@>@(Body@)
6081 macro without having to redefine the start and end
6082 of page macros.
6083
6084 @<P@>
6085 @<Begin verbatim@>@=#
6086 @!************************************************
6087
6088 @i style
6089
6090 @$@##<Body@##>@{@-
6091 ##<BODY BGCOLOR=#@000000 TEXT=#@FFFFFF##>@}
6092
6093 @!************************************************
6094
6095 @O@##<index.html@##>@{
6096 @##<Begin page@##>@(Dave's Home Page@)
6097
6098 ##<P##>Welcome to my home page. Check out my
6099 ##<A HREF="@##<Links FILE@##>"##>links page##</A##>.
6100
6101 @##<End page@##>
6102 @}
6103
6104 @!************************************************
6105
6106 @$@##<Links FILE@##>@M@{links.html@}
6107 @O@##<links.html@##>@{
6108 @##<Begin page@##>@(Dave's Links@)
6109
6110 ##<P##>Check out @##<Yahoo@##> and @##<Dilbert@##>.
6111
6112 @##<End page@##>
6113 @}
6114
6115 @!************************************************
6116 #=@@<End verbatim@>
6117
6118 @<FWTutMan subheading@>@(Use Of Additive Macros@)
6119
6120 @<P@>Additive macros can be used to insert information into
6121 the middle of macros already defined. For example, suppose
6122 you defined:
6123
6124 @<P@>
6125 @<Begin verbatim@>@=#
6126 @$@##<Begin page@##>@(@1@)@M@{
6127 ##<HTML##>
6128 ##<HEAD##>
6129 ##<TITLE##>@1##</TITLE##>
6130 @##<Header fields@##>
6131 ##</HEAD##>
6132 ##<BODY BGCOLOR=#@FFFFFF TEXT=#@000033##>
6133 @}
6134
6135 @$@##<Header fields@##>+=@{@}
6136 #=@@<End verbatim@>
6137
6138 @<P@>Once the header fields macro is in place, you can add text such
6139 as style commands or keyword tags to each of the pages of your web
6140 without having to modify the header include file. Just add a definition,
6141 such as the following, to your main FunnelWeb file:
6142
6143 @<P@>
6144 @<Begin verbatim@>@=#
6145 @$@##<Header fields@##>+=@{
6146 ##<STYLE TYPE="text/css"##>
6147 ##<!-- A {text-decoration: none} // --##>
6148 ##</STYLE##>
6149 @}
6150 #=@@<End verbatim@>
6151
6152 @<FWTutMan subheading@>@(Selecting Absolute Or Relative Links@)
6153
6154 @<P@>Sometimes it's important to generate a web that uses
6155 relative hyperlinks, and sometimes it's important to generate
6156 a web that uses absolute hyperlinks. For example, it's important
6157 to use relative links if you want to browse a web offline, or
6158 if you want to ensure that username and password fields in
6159 the URL are not obliterated by the following of an absolute link.
6160 Absolute links are important where a web that is normally
6161 adjacent to another web (and hence usually links to it using
6162 a relative link) is separated and must be browsed offline.
6163
6164 @<P@>A good way to organize all this is to define FunnelWeb
6165 macros for the URLs of webs in include files, but allow them
6166 to be overruled by including files. For example, an
6167 file might contain the following definitions:
6168
6169 @<P@>
6170 @<Begin verbatim@>@=#
6171 @$@##<Rocksoft WWW@##>@Z@M@L@{http://www.rocksoft.com/@}
6172 @$@##<Ross WWW@##>@Z@M@L@{http://www.ross.net/@}
6173 @$@##<Veracity WWW@##>@Z@M@L@{http://www.veracity.com/@}
6174 #=@@<End verbatim@>
6175
6176 @<P@>These symbols are useful for referring to these various
6177 webs from within these webs. However, it is convenient for
6178 each subweb to refer to other subwebs using a relative path
6179 rather than an absolute path, so when generating (say) a
6180 subweb of the Ross webspace, the Ross macro could be redefined to:
6181
6182 @<P@>
6183 @<Begin verbatim@>@=#
6184 @$@##<Ross WWW@##>@Z@M@{../@}
6185 #=@@<End verbatim@>
6186
6187 @<P@>This technique can be used in various forms to manage
6188 the links in the online and offline versions of webs.
6189
6190 @<Nav@>@(@<Web_style FILE@>@,@<Web FILE@>@,@<Web_param FILE@>@)
6191
6192 @<End FWTutMan page@>
6193 @}
6194
6195 @!==============================================================================
6196
6197 @$@<Web_param HEADING@>@M@{@<SH@>@(7.7@)Parameterizing Entire Webs@}
6198 @$@<Web_param FILE@>@M@{web_param.html@}
6199 @O@<web_param.html@>@{@-
6200 @<Begin FWTutMan page/H1@>@(@<Web_param HEADING@>@)
6201
6202 @<P@>The previous section has shown how individual macros within
6203 included files can be redefined to modify the details of a web.
6204 A more radical approach to web parameterization is to swap in
6205 entire include files!
6206
6207 @<FWTutMan subheading@>@(Include Files As Parameter Sets@)
6208
6209 @<P@>Suppose that we have a web that we are providing to three
6210 different web customers, where each web customer wants the web
6211 customized for their business. One way to approach this
6212 situation is to embody all the elements of the web that must
6213 be changed into macros located in an include file. Then define
6214 a different include file for each customer. So the include
6215 file for one customer could be:
6216
6217 @<P@>
6218 @<Begin verbatim@>@=#
6219 @! Include file for MegaCorp
6220 @$@##<Home page title@##>@{Welcome To MegaCorp@}
6221 @$@##<Background colour@##>@{#@FFFFFF@}
6222 @$@##<Emphasis@##>@(@1@)@M@{##<B##>@1##</B##>@}
6223 #=@@<End verbatim@>
6224
6225 @<P@>whereas the include file for a different customer might be:
6226
6227 @<P@>
6228 @<Begin verbatim@>@=#
6229 @! Include file for MicroCorp
6230 @$@##<Home page title@##>@{MicroCorp Home Page@}
6231 @$@##<Background colour@##>@{#@000000@}
6232 @$@##<Emphasis@##>@(@1@)@M@{##<I##>@1##</I##>@}
6233 #=@@<End verbatim@>
6234
6235 @<P@>In this way you can parameterize the style of an entire
6236 web, and generate different versions for different situations.
6237
6238 @<Nav@>@(@<Web_libraries FILE@>@,@<Web FILE@>@,@<Web_conventions FILE@>@)
6239
6240 @<End FWTutMan page@>
6241 @}
6242
6243 @!==============================================================================
6244
6245 @$@<Web_conventions HEADING@>@M@{@<SH@>@(7.8@)Hints And Conventions@}
6246 @$@<Web_conventions FILE@>@M@{web_conventions.html@}
6247 @O@<web_conventions.html@>@{@-
6248 @<Begin FWTutMan page/H1@>@(@<Web_conventions HEADING@>@)
6249
6250 @<FWTutMan subheading@>@(Where To Include Include Files@)
6251
6252 @<P@>It's better to include your include files at the end of the
6253 main web file, as if FunnelWeb generates an error, the line number
6254 in the listing file is easier to correlate with the main file if
6255 several files have not been included.
6256
6257 @<FWTutMan subheading@>@(Separating Pages@)
6258
6259 @<P@>It's a good idea to separate the macro for each page in a web
6260 in the FunnelWeb file, by a line of asterisks in a FunnelWeb comment.
6261 This makes the FunnelWeb source file easier to work on in your
6262 text editor.
6263
6264 @<P@>
6265 @<Begin verbatim@>@=#
6266 @!************************************************
6267
6268 @O@##<index.html@##>@{
6269 @##<Begin page@##>@(Dave's Home Page@)
6270
6271 ##<P##>Welcome to my home page. Check out my
6272 ##<A HREF="@##<Links FILE@##>"##>links page##</A##>.
6273
6274 @##<End page@##>
6275 @}
6276
6277 @!************************************************
6278
6279 @$@##<Links FILE@##>@M@{links.html@}
6280 @O@##<links.html@##>@{
6281 @##<Begin page@##>@(Dave's Links@)
6282
6283 ##<P##>Check out @##<Yahoo@##> and @##<Dilbert@##>.
6284
6285 @##<End page@##>
6286 @}
6287
6288 @!************************************************
6289 #=@@<End verbatim@>
6290
6291 @<FWTutMan subheading@>@(Input And Output Line Lengths@)
6292
6293 @<P@>When using FunnelWeb to create webs, you will probably find
6294 that your input and output files have lines longer than the
6295 FunnelWeb standard 80 characters. So you may wish to include the
6296 following directives in your main and include files:
6297
6298 @<P@>
6299 @<Begin verbatim@>@=#
6300 @p maximum_input_line_length = 200
6301 @p maximum_output_line_length = 200
6302 #=@@<End verbatim@>
6303
6304 @<FWTutMan subheading@>@(Macro Naming Conventions@)
6305
6306 @<P@>Since 1994, I (@<Ross Williams@>) have been using FunnelWeb to
6307 generate all the webs in all my webspaces. During this time, I have
6308 developed some macro naming conventions which you may wish to adopt.
6309
6310 @<Narrowthing@>@(FILE:@,Use this suffix for macros that contain
6311 the names of files that form part of the web.@)
6312
6313 @<Narrowthing@>@(WWW:@,Use this suffix for macros that define
6314 web directory URLs, up to and including the trailing slash.
6315 The URL may be absolute or relative, depending on the context.@)
6316
6317 @<Narrowthing@>@(WWW/abs:@,Use this suffix where the URL must
6318 be absolute.@)
6319
6320 @<Narrowthing@>@(EMAIL:@,Use this suffix for email addresses.@)
6321
6322 @<Narrowthing@>@(FTP:@,Use this suffix for FTP directory addresses.@)
6323
6324 @<Narrowthing@>@(WINDOWNAME:@,Use this suffix for the names of
6325 browser windows.@)
6326
6327 @<P@>Here are some examples:
6328
6329 @<P@>
6330 @<Begin verbatim@>@=#
6331 @$@##<Home FILE@##>@Z@M@{index.html@}
6332 @$@##<Ross WWW@##>@Z@M@{http://www.ross.net/@}
6333 @$@##<Ross WWW/abs@##>@Z@M@{http://www.ross.net/@}
6334 @$@##<Ross EMAIL@##>@Z@M@{[email protected]@}
6335 @$@##<Ross FTP@##>@Z@M@{@-
6336 ftp://www.ross.net/clients/ross/@}
6337 @$@##<Ross WINDOWNAME@##>@Z@M@{ross@}
6338 #=@@<End verbatim@>
6339
6340 @<Nav/last@>@(@<Web_param FILE@>@,@<Web FILE@>@,@<Web FILE@>@)
6341
6342 @<End FWTutMan page@>
6343 @}
6344
6345 @!******************************************************************************
6346
6347 @$@<Copyright FILE@>@M@{copyright.html@}
6348 @O@<copyright.html@>@{@-
6349 @<Begin FWTutMan page/H1@>@(@<Page title prefix@>Copyright and Credits@)
6350
6351 @<FunnelWeb webs copyright page contents@>
6352
6353 @<End FWTutMan page@>
6354 @}
6355
6356 @!******************************************************************************
6357
6358 @B@<Search Form Section@>
6359
6360 The files in this section are all linked in with the FunnelWeb
6361 include file.
6362
6363 @O@<search.html@>@{@-
6364 @<Begin FWTutMan page/H1@>@(Search FunnelWeb Documentation@)
6365
6366 @<FunnelWeb search form@>@(@,@,checked@,@)
6367
6368 @<End FWTutMan page@>
6369 @}
6370
6371 @!==============================================================================
6372
6373 @O@<search_form.cgi@>@{@-
6374 @<FunnelWeb search CGICODE@>
6375 @}
6376
6377 @!==============================================================================
6378
6379 @O@<search_head.txt@>@{@-
6380 @<Begin FWTutMan page/H1@>@(Search Results@)
6381 @<P@>
6382 @}
6383
6384 @!==============================================================================
6385
6386 @O@<search_tail.txt@>@{@-
6387 @<BR@>
6388 @<P@>@<Back button@>@(Back To The Search Form@)
6389 @<BR@>
6390
6391 @<End FWTutMan page@>
6392 @}
6393
6394 @!==============================================================================
6395
6396 @O@<search_e_nokeywords.txt@>@{@-
6397 @<Begin FWTutMan page/H1@>@(Error: No Keywords Specified@)
6398
6399 @<P@>You must specify one or more keywords to perform a search.
6400
6401 @<P@>@<Back button@>@(Back To The Search Form@)
6402
6403 @<End FWTutMan page@>
6404 @}
6405
6406 @!==============================================================================
6407
6408 @O@<search_e_nomanual.txt@>@{@-
6409 @<Begin FWTutMan page/H1@>@(Error: No Manual Selected@)
6410
6411 @<P@>You must specify one or more manuals (using the checkboxes) to
6412 perform a search.
6413
6414 @<P@>@<Back button@>@(Back To The Search Form@)
6415
6416 @<End FWTutMan page@>
6417 @}
6418
6419 @!******************************************************************************
6420
6421 @O@<0cleanup.vxf@>@{@-
6422 eneo *.html
6423 eneo *.shtml
6424 eneo *.cgi
6425 eneo *.txt
6426 eneo *.lis
6427 eneo *.pl
6428 @}
6429
6430 @!******************************************************************************
6431 @!******************************************************************************
6432
6433 @! Include the FunnelWeb webs master include file.
6434 @! Specify a platform-specific relative (or absolute) path to the include file.
6435 @! Unix : @i ../0fw_inc.fwi
6436 @! MacOS : @i ::0fw_inc.fwi
6437 @! OpenVMS : @i [-]0fw_inc.fwi
6438
•6439 @i ../0fw_inc.fwi
6440 @i ../0www_style.fwi
6441 @i ../0www_links.fwi
6442 @i ../0www_ross.fwi
6443
6444 @!******************************************************************************
6445 @!******************************************************************************