Merge branch 'vendor/NCURSES'
[dragonfly.git] / usr.bin / m4 / TEST / test.m4
1 #
2 # Copyright (c) 1989, 1993
3 #       The Regents of the University of California.  All rights reserved.
4 #
5 # This code is derived from software contributed to Berkeley by
6 # Ozan Yigit.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 # 1. Redistributions of source code must retain the above copyright
12 #    notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 #    notice, this list of conditions and the following disclaimer in the
15 #    documentation and/or other materials provided with the distribution.
16 # 3. All advertising materials mentioning features or use of this software
17 #    must display the following acknowledgement:
18 #       This product includes software developed by the University of
19 #       California, Berkeley and its contributors.
20 # 4. Neither the name of the University nor the names of its contributors
21 #    may be used to endorse or promote products derived from this software
22 #    without specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 # SUCH DAMAGE.
35 #
36 #       @(#)test.m4     8.1 (Berkeley) 6/6/93
37 #
38
39 # test file for mp (not comprehensive)
40 #
41 # v7 m4 does not have `decr'.
42 #
43 define(DECR,`eval($1-1)')
44 #
45 # include string macros
46 #
47 include(string.m4)
48 #
49 # create some fortrash strings for an even uglier language
50 #
51 string(TEXT, "text")
52 string(DATA, "data")
53 string(BEGIN, "begin")
54 string(END, "end")
55 string(IF, "if")
56 string(THEN, "then")
57 string(ELSE, "else")
58 string(CASE, "case")
59 string(REPEAT, "repeat")
60 string(WHILE, "while")
61 string(DEFAULT, "default")
62 string(UNTIL, "until")
63 string(FUNCTION, "function")
64 string(PROCEDURE, "procedure")
65 string(EXTERNAL, "external")
66 string(FORWARD, "forward")
67 string(TYPE, "type")
68 string(VAR, "var")
69 string(CONST, "const")
70 string(PROGRAM, "program")
71 string(INPUT, "input")
72 string(OUTPUT, "output")
73 #
74 divert(2)
75 diversion #1
76 divert(3)
77 diversion #2
78 divert(4)
79 diversion #3
80 divert(5)
81 diversion #4
82 divert(0)
83 define(abc,xxx)
84 ifdef(`abc',defined,undefined)
85 #
86 # v7 m4 does this wrong. The right output is 
87 #       this is A vEry lon sEntEnCE
88 # see m4 documentation for translit.
89 #
90 translit(`this is a very long sentence', abcdefg, ABCDEF)
91 #
92 # include towers-of-hanoi
93 #
94 include(hanoi.m4)
95 #
96 # some reasonable set of disks
97 #
98 hanoi(6)
99 #
100 # include ackermann's function
101 #
102 include(ack.m4)
103 #
104 # something like (3,3) will blow away un*x m4.
105 #
106 ack(2,3)
107 #
108 # include a square_root function for fixed nums
109 #
110 include(sqroot.m4)
111 #
112 # some square roots.
113 #
114 square_root(15)
115 square_root(100)
116 square_root(-4)
117 square_root(21372)
118 #
119 # some textual material for enjoyment.
120 #
121 [taken from the 'Clemson University Computer Newsletter',
122  September 1981, pp. 6-7]
123      
124 I am a wizard in the magical Kingdom of Transformation and I
125 slay dragons for a living.  Actually, I am a systems programmer.
126 One of the problems with systems programming is explaining to
127 non-computer enthusiasts what that is.  All of the terms I use to
128 describe my job are totally meaningless to them.  Usually my response
129 to questions about my work is to say as little as possible.  For
130 instance, if someone asks what happened at work this week, I say
131 "Nothing much" and then I change the subject.
132      
133 With the assistance of my brother, a mechanical engineer, I have devised
134 an analogy that everyone can understand.  The analogy describes the
135 "Kingdom of Transformation" where travelers wander and are magically
136 transformed.  This kingdom is the computer and the travelers are information.
137 The purpose of the computer is to change information to a more meaningful
138 forma.  The law of conservation applies here:  The computer never creates
139 and never intentionally destroys data.  With no further ado, let us travel
140 to the Kingdom of Transformation:
141      
142 In a land far, far away, there is a magical kingdom called the Kingdom of
143 Transformation.  A king rules over this land and employs a Council of
144 Wizardry.  The main purpose of this kingdom is to provide a way for
145 neighboring kingdoms to transform citizens into more useful citizens.  This
146 is done by allowing the citizens to enter the kingdom at one of its ports
147 and to travel any of the many routes in the kingdom.  They are magically
148 transformed along the way.  The income of the Kingdom of Transformation
149 comes from the many toll roads within its boundaries.
150      
151 The Kingdom of Transformation was created when several kingdoms got
152 together and discovered a mutual need for new talents and abilities for
153 citizens.  They employed CTK, Inc. (Creators of Transformation, Inc.) to
154 create this kingdom.  CTK designed the country, its transportation routes,
155 and its laws of transformation, and created the major highway system.
156      
157 Hazards
158 =======
159      
160 Because magic is not truly controllable, CTK invariably, but unknowingly,
161 creates dragons.  Dragons are huge fire-breathing beasts which sometimes
162 injure or kill travelers.  Fortunately, they do not travel, but always
163 remain near their den.
164      
165 Other hazards also exist which are potentially harmful.  As the roads
166 become older and more weatherbeaten, pot-holes will develop, trees will
167 fall on travelers, etc.  CTK maintenance men are called to fix these
168 problems.
169      
170 Wizards
171 =======
172      
173 The wizards play a major role in creating and maintaining the kingdom but
174 get little credit for their work because it is performed secretly.  The
175 wizards do not wan the workers or travelers to learn their incantations
176 because many laws would be broken and chaos would result.
177      
178 CTK's grand design is always general enough to be applicable in many
179 different situations.  As a result, it is often difficult to use.  The
180 first duty of the wizards is to tailor the transformation laws so as to be
181 more beneficial and easier to use in their particular environment.
182      
183 After creation of the kingdom, a major duty of the wizards is to search for
184 and kill dragons.  If travelers do not return on time or if they return
185 injured, the ruler of the country contacts the wizards.  If the wizards
186 determine that the injury or death occurred due to the traveler's
187 negligence, they provide the traveler's country with additional warnings.
188 If not, they must determine if the cause was a road hazard or a dragon.  If
189 the suspect a road hazard, they call in a CTK maintenance man to locate the
190 hazard and to eliminate it, as in repairing the pothole in the road.  If
191 they think that cause was a dragon, then they must find and slay it.
192      
193 The most difficult part of eliminating a dragon is finding it.  Sometimes
194 the wizard magically knows where the dragon's lair it, but often the wizard
195 must send another traveler along the same route and watch to see where he
196 disappears.  This sounds like a failsafe method for finding dragons (and a
197 suicide mission for thr traveler) but the second traveler does not always
198 disappear.  Some dragons eat any traveler who comes too close; others are
199 very picky.
200      
201 The wizards may call in CTK who designed the highway system and
202 transformation laws to help devise a way to locate the dragon.  CTK also
203 helps provide the right spell or incantation to slay the dragon. (There is
204 no general spell to slay dragons; each dragon must be eliminated with a
205 different spell.)
206      
207 Because neither CTK nor wizards are perfect, spells to not always work
208 correctly.  At best, nothing happens when the wrong spell is uttered.  At
209 worst, the dragon becomes a much larger dragon or multiplies into several
210 smaller ones.  In either case, new spells must be found.
211      
212 If all existing dragons are quiet (i.e. have eaten sufficiently), wizards
213 have time to do other things.  They hide in castles and practice spells and
214 incatations.  They also devise shortcuts for travelers and new laws of
215 transformation.
216      
217 Changes in the Kingdom
218 ======================
219      
220 As new transformation kingdoms are created and old ones are maintained,
221 CTK, Inc. is constantly learning new things.  It learns ways to avoid
222 creating some of the dragons that they have previously created.  It also
223 discovers new and better laws of transformation.  As a result, CTK will
224 periodically create a new grand design which is far better than the old.
225 The wizards determine when is a good time to implement this new design.
226 This is when the tourist season is slow or when no important travelers
227 (VIPs) are to arrive.  The kingdom must be closed for the actual
228 implementation and is leter reopened as a new and better place to go.
229      
230 A final question you might ask is what happens when the number of tourists
231 becomes too great for the kingdom to handle in a reasonable period of time
232 (i.e., the tourist lines at the ports are too long).  The Kingdom of
233 Transformation has three options: (1) shorten the paths that a tourist must
234 travel, or (2) convince CTK to develop a faster breed of horses so that the
235 travelers can finish sooner, or (3) annex more territories so that the
236 kingdom can handle more travelers.
237      
238 Thus ends the story of the Kingdom of Transformation.  I hope this has
239 explained my job to you:  I slay dragons for a living.
240
241 #
242 #should do an automatic undivert..
243 #