1259262Stijl#	$OpenBSD: test.m4,v 1.3 2003/06/03 02:56:11 millert Exp $
216748Sjmallett#	$NetBSD: test.m4,v 1.4 1995/09/28 05:38:05 tls Exp $
31590Srgrimes#
41590Srgrimes# Copyright (c) 1989, 1993
51590Srgrimes#	The Regents of the University of California.  All rights reserved.
61590Srgrimes#
71590Srgrimes# This code is derived from software contributed to Berkeley by
81590Srgrimes# Ozan Yigit.
91590Srgrimes#
101590Srgrimes# Redistribution and use in source and binary forms, with or without
111590Srgrimes# modification, are permitted provided that the following conditions
121590Srgrimes# are met:
131590Srgrimes# 1. Redistributions of source code must retain the above copyright
141590Srgrimes#    notice, this list of conditions and the following disclaimer.
151590Srgrimes# 2. Redistributions in binary form must reproduce the above copyright
161590Srgrimes#    notice, this list of conditions and the following disclaimer in the
171590Srgrimes#    documentation and/or other materials provided with the distribution.
18259262Stijl# 3. Neither the name of the University nor the names of its contributors
191590Srgrimes#    may be used to endorse or promote products derived from this software
201590Srgrimes#    without specific prior written permission.
211590Srgrimes#
221590Srgrimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231590Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241590Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251590Srgrimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261590Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271590Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281590Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291590Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301590Srgrimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311590Srgrimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321590Srgrimes# SUCH DAMAGE.
331590Srgrimes#
34216370Sjoel# $FreeBSD$
35216370Sjoel#
361590Srgrimes#	@(#)test.m4	8.1 (Berkeley) 6/6/93
371590Srgrimes#
381590Srgrimes
391590Srgrimes# test file for mp (not comprehensive)
401590Srgrimes#
411590Srgrimes# v7 m4 does not have `decr'.
421590Srgrimes#
431590Srgrimesdefine(DECR,`eval($1-1)')
441590Srgrimes#
451590Srgrimes# include string macros
461590Srgrimes#
471590Srgrimesinclude(string.m4)
481590Srgrimes#
491590Srgrimes# create some fortrash strings for an even uglier language
501590Srgrimes#
511590Srgrimesstring(TEXT, "text")
521590Srgrimesstring(DATA, "data")
531590Srgrimesstring(BEGIN, "begin")
541590Srgrimesstring(END, "end")
551590Srgrimesstring(IF, "if")
561590Srgrimesstring(THEN, "then")
571590Srgrimesstring(ELSE, "else")
581590Srgrimesstring(CASE, "case")
591590Srgrimesstring(REPEAT, "repeat")
601590Srgrimesstring(WHILE, "while")
611590Srgrimesstring(DEFAULT, "default")
621590Srgrimesstring(UNTIL, "until")
631590Srgrimesstring(FUNCTION, "function")
641590Srgrimesstring(PROCEDURE, "procedure")
651590Srgrimesstring(EXTERNAL, "external")
661590Srgrimesstring(FORWARD, "forward")
671590Srgrimesstring(TYPE, "type")
681590Srgrimesstring(VAR, "var")
691590Srgrimesstring(CONST, "const")
701590Srgrimesstring(PROGRAM, "program")
711590Srgrimesstring(INPUT, "input")
721590Srgrimesstring(OUTPUT, "output")
731590Srgrimes#
741590Srgrimesdivert(2)
751590Srgrimesdiversion #1
761590Srgrimesdivert(3)
771590Srgrimesdiversion #2
781590Srgrimesdivert(4)
791590Srgrimesdiversion #3
801590Srgrimesdivert(5)
811590Srgrimesdiversion #4
821590Srgrimesdivert(0)
831590Srgrimesdefine(abc,xxx)
841590Srgrimesifdef(`abc',defined,undefined)
851590Srgrimes#
861590Srgrimes# v7 m4 does this wrong. The right output is 
871590Srgrimes# 	this is A vEry lon sEntEnCE
881590Srgrimes# see m4 documentation for translit.
891590Srgrimes#
901590Srgrimestranslit(`this is a very long sentence', abcdefg, ABCDEF)
911590Srgrimes#
921590Srgrimes# include towers-of-hanoi
931590Srgrimes#
941590Srgrimesinclude(hanoi.m4)
951590Srgrimes#
961590Srgrimes# some reasonable set of disks
971590Srgrimes#
981590Srgrimeshanoi(6)
991590Srgrimes#
1001590Srgrimes# include ackermann's function
1011590Srgrimes#
1021590Srgrimesinclude(ack.m4)
1031590Srgrimes#
1041590Srgrimes# something like (3,3) will blow away un*x m4.
1051590Srgrimes#
1061590Srgrimesack(2,3)
1071590Srgrimes#
1081590Srgrimes# include a square_root function for fixed nums
1091590Srgrimes#
1101590Srgrimesinclude(sqroot.m4)
1111590Srgrimes#
1121590Srgrimes# some square roots.
1131590Srgrimes#
1141590Srgrimessquare_root(15)
1151590Srgrimessquare_root(100)
1161590Srgrimessquare_root(-4)
1171590Srgrimessquare_root(21372)
1181590Srgrimes#
1191590Srgrimes# some textual material for enjoyment.
1201590Srgrimes#
1211590Srgrimes[taken from the 'Clemson University Computer Newsletter',
1221590Srgrimes September 1981, pp. 6-7]
1231590Srgrimes     
1241590SrgrimesI am a wizard in the magical Kingdom of Transformation and I
1251590Srgrimesslay dragons for a living.  Actually, I am a systems programmer.
1261590SrgrimesOne of the problems with systems programming is explaining to
1271590Srgrimesnon-computer enthusiasts what that is.  All of the terms I use to
1281590Srgrimesdescribe my job are totally meaningless to them.  Usually my response
1291590Srgrimesto questions about my work is to say as little as possible.  For
1301590Srgrimesinstance, if someone asks what happened at work this week, I say
1311590Srgrimes"Nothing much" and then I change the subject.
1321590Srgrimes     
1331590SrgrimesWith the assistance of my brother, a mechanical engineer, I have devised
1341590Srgrimesan analogy that everyone can understand.  The analogy describes the
1351590Srgrimes"Kingdom of Transformation" where travelers wander and are magically
1361590Srgrimestransformed.  This kingdom is the computer and the travelers are information.
1371590SrgrimesThe purpose of the computer is to change information to a more meaningful
1381590Srgrimesforma.  The law of conservation applies here:  The computer never creates
1391590Srgrimesand never intentionally destroys data.  With no further ado, let us travel
1401590Srgrimesto the Kingdom of Transformation:
1411590Srgrimes     
1421590SrgrimesIn a land far, far away, there is a magical kingdom called the Kingdom of
1431590SrgrimesTransformation.  A king rules over this land and employs a Council of
1441590SrgrimesWizardry.  The main purpose of this kingdom is to provide a way for
1451590Srgrimesneighboring kingdoms to transform citizens into more useful citizens.  This
1461590Srgrimesis done by allowing the citizens to enter the kingdom at one of its ports
1471590Srgrimesand to travel any of the many routes in the kingdom.  They are magically
1481590Srgrimestransformed along the way.  The income of the Kingdom of Transformation
1491590Srgrimescomes from the many toll roads within its boundaries.
1501590Srgrimes     
1511590SrgrimesThe Kingdom of Transformation was created when several kingdoms got
1521590Srgrimestogether and discovered a mutual need for new talents and abilities for
1531590Srgrimescitizens.  They employed CTK, Inc. (Creators of Transformation, Inc.) to
1541590Srgrimescreate this kingdom.  CTK designed the country, its transportation routes,
1551590Srgrimesand its laws of transformation, and created the major highway system.
1561590Srgrimes     
1571590SrgrimesHazards
1581590Srgrimes=======
1591590Srgrimes     
1601590SrgrimesBecause magic is not truly controllable, CTK invariably, but unknowingly,
1611590Srgrimescreates dragons.  Dragons are huge fire-breathing beasts which sometimes
1621590Srgrimesinjure or kill travelers.  Fortunately, they do not travel, but always
1631590Srgrimesremain near their den.
1641590Srgrimes     
1651590SrgrimesOther hazards also exist which are potentially harmful.  As the roads
1661590Srgrimesbecome older and more weatherbeaten, pot-holes will develop, trees will
1671590Srgrimesfall on travelers, etc.  CTK maintenance men are called to fix these
1681590Srgrimesproblems.
1691590Srgrimes     
1701590SrgrimesWizards
1711590Srgrimes=======
1721590Srgrimes     
1731590SrgrimesThe wizards play a major role in creating and maintaining the kingdom but
1741590Srgrimesget little credit for their work because it is performed secretly.  The
1751590Srgrimeswizards do not wan the workers or travelers to learn their incantations
1761590Srgrimesbecause many laws would be broken and chaos would result.
1771590Srgrimes     
1781590SrgrimesCTK's grand design is always general enough to be applicable in many
1791590Srgrimesdifferent situations.  As a result, it is often difficult to use.  The
1801590Srgrimesfirst duty of the wizards is to tailor the transformation laws so as to be
1811590Srgrimesmore beneficial and easier to use in their particular environment.
1821590Srgrimes     
1831590SrgrimesAfter creation of the kingdom, a major duty of the wizards is to search for
1841590Srgrimesand kill dragons.  If travelers do not return on time or if they return
1851590Srgrimesinjured, the ruler of the country contacts the wizards.  If the wizards
1861590Srgrimesdetermine that the injury or death occurred due to the traveler's
1871590Srgrimesnegligence, they provide the traveler's country with additional warnings.
1881590SrgrimesIf not, they must determine if the cause was a road hazard or a dragon.  If
1891590Srgrimesthe suspect a road hazard, they call in a CTK maintenance man to locate the
1901590Srgrimeshazard and to eliminate it, as in repairing the pothole in the road.  If
1911590Srgrimesthey think that cause was a dragon, then they must find and slay it.
1921590Srgrimes     
1931590SrgrimesThe most difficult part of eliminating a dragon is finding it.  Sometimes
1941590Srgrimesthe wizard magically knows where the dragon's lair it, but often the wizard
1951590Srgrimesmust send another traveler along the same route and watch to see where he
1961590Srgrimesdisappears.  This sounds like a failsafe method for finding dragons (and a
1971590Srgrimessuicide mission for thr traveler) but the second traveler does not always
1981590Srgrimesdisappear.  Some dragons eat any traveler who comes too close; others are
1991590Srgrimesvery picky.
2001590Srgrimes     
2011590SrgrimesThe wizards may call in CTK who designed the highway system and
2021590Srgrimestransformation laws to help devise a way to locate the dragon.  CTK also
2031590Srgrimeshelps provide the right spell or incantation to slay the dragon. (There is
2041590Srgrimesno general spell to slay dragons; each dragon must be eliminated with a
2051590Srgrimesdifferent spell.)
2061590Srgrimes     
2071590SrgrimesBecause neither CTK nor wizards are perfect, spells to not always work
2081590Srgrimescorrectly.  At best, nothing happens when the wrong spell is uttered.  At
2091590Srgrimesworst, the dragon becomes a much larger dragon or multiplies into several
2101590Srgrimessmaller ones.  In either case, new spells must be found.
2111590Srgrimes     
2121590SrgrimesIf all existing dragons are quiet (i.e. have eaten sufficiently), wizards
2131590Srgrimeshave time to do other things.  They hide in castles and practice spells and
2141590Srgrimesincatations.  They also devise shortcuts for travelers and new laws of
2151590Srgrimestransformation.
2161590Srgrimes     
2171590SrgrimesChanges in the Kingdom
2181590Srgrimes======================
2191590Srgrimes     
2201590SrgrimesAs new transformation kingdoms are created and old ones are maintained,
2211590SrgrimesCTK, Inc. is constantly learning new things.  It learns ways to avoid
2221590Srgrimescreating some of the dragons that they have previously created.  It also
2231590Srgrimesdiscovers new and better laws of transformation.  As a result, CTK will
2241590Srgrimesperiodically create a new grand design which is far better than the old.
2251590SrgrimesThe wizards determine when is a good time to implement this new design.
2261590SrgrimesThis is when the tourist season is slow or when no important travelers
2271590Srgrimes(VIPs) are to arrive.  The kingdom must be closed for the actual
2281590Srgrimesimplementation and is leter reopened as a new and better place to go.
2291590Srgrimes     
2301590SrgrimesA final question you might ask is what happens when the number of tourists
2311590Srgrimesbecomes too great for the kingdom to handle in a reasonable period of time
2321590Srgrimes(i.e., the tourist lines at the ports are too long).  The Kingdom of
2331590SrgrimesTransformation has three options: (1) shorten the paths that a tourist must
2341590Srgrimestravel, or (2) convince CTK to develop a faster breed of horses so that the
2351590Srgrimestravelers can finish sooner, or (3) annex more territories so that the
2361590Srgrimeskingdom can handle more travelers.
2371590Srgrimes     
2381590SrgrimesThus ends the story of the Kingdom of Transformation.  I hope this has
2391590Srgrimesexplained my job to you:  I slay dragons for a living.
2401590Srgrimes
2411590Srgrimes#
2421590Srgrimes#should do an automatic undivert..
2431590Srgrimes#
244