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