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