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