home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / m4 / part02 / test.m4 < prev   
Encoding:
Text File  |  1988-02-27  |  7.7 KB  |  203 lines

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