home *** CD-ROM | disk | FTP | other *** search
/ Complete Bookshop / CompleteWorkshop.iso / jokes / murphy05 / murphy.c next >
Encoding:
Text File  |  1991-11-03  |  29.4 KB  |  686 lines

  1. /* Murphy's Law display program   Version II */
  2.  
  3. /**********************************************************
  4. *                                                         *
  5. *       Author: Charles J.C. Lyall                        *
  6. *               R.R. #2, Kingman                          *
  7. *               Alberta, Canada                           *
  8. *               T0B 2M0                                   *
  9. *               (403) 662-2119                            *
  10. *                                                         *
  11. *       Copyright (c) 1987 by Charles J.C. Lyall          *
  12. *                                                         *
  13. ***********************************************************
  14. *                                                         *
  15. *       Revision History:                                 *
  16. *                                                         *
  17. *       February 22, 1987                      3.00       *
  18. *         Original Version                                *
  19. *       June 10, 1987                          3.01       *
  20. *         Changed constant of multiplication used in      *
  21. *         computing filepos from 79 to 257                *
  22. *         Cleaned up code to handle boundary conditions   *
  23. *         Added 3 lines of documentation describing       *
  24. *         boundary conditions                             *
  25. *                                                         *
  26. *       June 29, 1987                          3.02       *
  27. *         Routine made compatible with Borland            *
  28. *         TURBO C compiler.  Added #define TURBOC         *
  29. *         to handle conditional compiles                  *
  30. *                                                         *
  31. *       January 29, 1988                                  *
  32. *         Minor documentation revisions.                  *
  33. *                                                         *
  34. *                                                         *
  35. *       February 12, 1990                                 *
  36. *         Changed output by character to output of a      *
  37. *         zero terminated ASCII string because print      *
  38. *         speed was too slow on an OS/2 LAN               *
  39. *                                                         *
  40. ***********************************************************
  41. *                                                         *
  42. *       NOTICE:                                           *
  43. *       This program may be copied by anyone              *
  44. *       for their own amusement. Anyone discovering a     *
  45. *       new fundamental law is requested to send it to    *
  46. *       the author who collects such things.              *
  47. *                                                         *
  48. ***********************************************************
  49. *                                                         *
  50. *       Brief Technical Note:                             *
  51. *                                                         *
  52. *       This routine is written in MicroSoft C with a     *
  53. * switch allowing compilation by Borland TURBO C.         *
  54. *                                                         *
  55. *       The major problem with this version of MURPHY is  *
  56. * that the text file is separate from the program. It is  *
  57. * necessary to search for the text if the text is not in  *
  58. * the current directory. The search for the text file has *
  59. * three phases:                                           *
  60. *                                                         *
  61. *     - look in the current directory and failing that    *
  62. *     - if MURPATH is defined in the environment, use it  *
  63. *         as a full pathname and failing that             *
  64. *     - search every directory in the path and failing    *
  65. *         that                                            *
  66. *     - complain bitterly and quit                        *
  67. *                                                         *
  68. *                                                         *
  69. *       The rest of the code is disgustingly simple.      *
  70. * This program has been used in some colleges as an       *
  71. * example of how to document a program. To the hardened   *
  72. * C programmer, it will therefore appear overdocumented.  *
  73. *                                                         *
  74. *       Tough.                                            *
  75. ***********************************************************
  76. *                                                         *
  77. *  A Note on Invoking the Program:                        *
  78. *                                                         *
  79. *  MURPHY ? or MURPHY HELP will generate a help message   *
  80. *                                                         *
  81. *  An alternative text file may be invoked in the         *
  82. * following manner. Assume that you have a new file named *
  83. * NEWFILE.TXT which you wish to have driven by MURPHY. If *
  84. * this text file is hidden in C:\SECRET\HIDDEN, then it   *
  85. * may be driven by MURPHY if you do the following: Type   *
  86. *                                                         *
  87. * set MURPATH=C:\secret\hidden\newfile.txt                *
  88. *                                                         *
  89. *   This defines MURPATH in the environment and MURPHY    *
  90. * will look in the environment for MURPATH if it fails to *
  91. * find MURPHY00.TXT in the current directory. When MURPHY *
  92. * finds MURPATH in the environment, it will open the file *
  93. * specified by the MURPATH variable.                      *
  94. *                                                         *
  95. ***********************************************************
  96. *                                                         *
  97. *  A note on how to add laws and prepare your own data    *
  98. *  file.                                                  *
  99. *                                                         *
  100. *  A proper data file for this program consists of an     *
  101. *  at symbol (@) followed by one or more law entries      *
  102. *  where a law entry is defined as text followed by an    *
  103. *  at symbol.  In other words, the at symbols are used to *
  104. *  delimit both the laws and the file.                    *
  105. *                                                         *
  106. *  For example:                                           *
  107. *                                                         *
  108. *  @                                                      *
  109. *     text of law 1                                       *
  110. *     more text of law 1                                  *
  111. *  @                                                      *
  112. *         text of law 2                                   *
  113. *  @                                                      *
  114. *     text of third and last law                          *
  115. *  @                                                      *
  116. *                                                         *
  117. *  Thats all it takes!                                    *
  118. ***********************************************************
  119. *                                                         *
  120. *     A financial note:                                   *
  121. *                                                         *
  122. *     Should you want up to date versions of the text or  *
  123. * the previous version (laws bound into program), they    *
  124. * can be obtained either from myself or (in the case of   *
  125. * the U of Alberta text files) from Peter Johnston.       *
  126. * Please send a disk or disks in a re-usable mailer with  *
  127. * return postage inside. Our American cousins can skip    *
  128. * the postage because they can't buy Canadian stamps,     *
  129. * and the Canadian Postal Service won't accept American   *
  130. * stamps. I will gratefully accept $2 in US funds for     *
  131. * return postage.                                         *  
  132. *                                                         *
  133. * Requests from outside North America should be           *
  134. * accompanied by a reasonable estimate of return postage. *
  135. * No reasonable estimate will be refused. Excess funds    *
  136. * will be used to support younger programmers who ask all *
  137. * sorts of reasonably intelligent questions.              *
  138. *                                                         *
  139. * No other donations are solicited. I did this one for    *
  140. * the fun of it.                                          *
  141. *                                                         *
  142. **********************************************************/
  143.  
  144. /*      An historical look at Murphy's laws.
  145.  
  146.     The inability of humanity to forsee the consequences
  147. of their actions has been known since ancient times.
  148. About 400 BC, the last of classical Athens's great dramatists,
  149. Euripides, wrote:
  150.  
  151.     What we look for does not come to pass.
  152.     God finds a way for what none forsaw.
  153.  
  154.     Perhaps Aeschlylus or Sophocles said it earlier. Still, 
  155. even allowing for a clumsy translation, Euripides doesn't 
  156. come close to the economy and precision of Murphy's Law 
  157. which requires only seven words to establish the most 
  158. fundamental truth concerning humanity and the universe.
  159.  
  160.          'If anything can go wrong, it will.'
  161.  
  162.  
  163.     I do not believe that there ever was a Mr. Murphy.
  164. There are many stories alleging his actual existence but
  165. if he did exist, his lawyers would surely have sued each
  166. and every one of the commercial publishers of Murphy's Laws.
  167.  
  168. The earliest extensive comment on the perversity of
  169. the universe that I have found so far dates to
  170. September 1864 when Katherine Child published "The
  171. Total Depravity of Inanimate Things".  She complained
  172. about "... the elusiveness of soap, the knottiness of strings,
  173. the transitory nature of buttons, the inclination of
  174. suspenders to twist and of hooks to forsake their lawful
  175. eyes ...."  Clearly, she was a woman of vision born far
  176. before her time -- she'd have been a great engineer!
  177.  
  178.     In British 'humour', the Irish are considered to be 
  179. congenitally stupid; a music hall comedian can bring the 
  180. house down by, "Did you hear about the Irish brain
  181. surgeon...."  The original Murphyisms were observations on
  182. human stupidity as such and hence would be attributed to
  183. an Irishman and who would  be more Irish than Murphy?  The
  184. metaphor of the actively malevolent universe came along in
  185. later years (excepting, of course, the redoubtable Ms. Child)
  186. although the maxim, "Toast always falls butter side down",
  187. belongs to the earliest collections of Murphy's Laws.  In
  188. Britain these observations are known as Sod's laws after
  189. the Brit phrase for a well meaning idiot, a "poor sod".
  190.  
  191.         To my knowledge, the first collection of Murphy's
  192. laws appeared in Astounding Science Fiction in the letters
  193. to the editor column over a period of months in the late
  194. 1950s.  The editor, John W. Campbell Jr, encouraged this
  195. and scientists and engineers dutifully submitted their
  196. hard earned knowledge of the general perversity of the
  197. universe to the delight and edification of the general
  198. readership.
  199.  
  200.         Things became much more serious when the IEEE
  201. (then the EEE) published "The Contributions of Edsel
  202. Murphy to the Understanding of the Behavior of Inanimate
  203. Objects" (EEE, Vol 15, No. 8, August 1967).  This dealt
  204. at length with the application of Murphy's law to general
  205. engineering, mathematics, prototyping and production, and
  206. specifying.  The author was one Mr. D. L. Klipstein which 
  207. explains why his name shows up so often.  Unfortunately, 
  208. some law listings attribute all the laws listed in the article 
  209. to Klipstein himself.  I have followed the attributions given
  210. by Klipstein.
  211.  
  212.         I am not making this up!
  213.  
  214.         The computer age entered in 1981, when H.J. Kuhman,
  215. one of the dwarves inhabiting the maze of twisty little
  216. passages of Data General, built a program to display Murphy's
  217. laws.  It was written in assembler which made it less
  218. transportable than the Great Lakes.  Data General never
  219. officially admitted that the program existed but every
  220. salesman had a copy and soon almost every Eclipse and MV
  221. installation ran MURPHY as part of the user start up
  222. procedure.
  223.  
  224.         A version of Murphy exists on the University of
  225. Alberta Amdahl mainframe using the MTS operating system.
  226. A dump of the laws from this version is completely compatible
  227. with this program. Dumps can be obtained from:
  228.  
  229.           Peter Johnston
  230.           PSC Consulting Ltd.
  231.           834 Geneva Crescent
  232.           St. Albert, Alberta
  233.           Canada T8N 0Z4
  234.  
  235.         Be warned that at the time of writing, February '87,
  236. this file contains over 300,000 bytes of text and it is growing.
  237. It will come in either backup or ZIP format.
  238.  
  239.         Peter Johnston will also supply the laws in
  240. MacIntosh format for those who are so inclined.  Send him a
  241. standard 3.5 inch disk in a reusable mailer and include
  242. sufficient stamps for return.  You will have to write your
  243. own program to drive it on the MacIntosh.
  244.  
  245.         This is the second version of MURPHY released into
  246. the public domain.  The original version bound the code and
  247. the laws together into one module which meant that as the
  248. number of laws grew, so did the program size.  The early
  249. version followed Kuhman's functionality and used the first
  250. 162 laws from his program.  This earlier version has been
  251. cut off at 291 laws.  It has the advantage that the program
  252. may be placed anyway on the DOS PATH and it will work.  The
  253. current version, requires that the text file also appear on
  254. the path or that a variable be set in the environment.
  255.  
  256.             This version was originally written to process
  257. files of laws dumped from the University of Alberta
  258. computer system.  MURPHY00.TXT as originally supplied contains
  259. the same set of laws as the original PC version of MURPHY,
  260. with many more additional laws tacked on as they were found.
  261. MURPHY01.TXT contains a 135,000 byte data file of laws, unlikely
  262. computer instructions, and aphorisms. as obtained from the
  263. University of Alberta system.  MURPHY02.TXT is a short
  264. list of Toronto jokes which are ever popular among those
  265. who live in what Toronto natives arrogantly refer to as
  266. "the regions."  Our American cousins will find them very
  267. puzzling.
  268.  
  269.       MURPHY04.TXT is available on a separate disk.
  270. It is a file of wisdom and aphorisms suitable for
  271. installation on Local Area Networks and on machines used
  272. by non-technical people.  The file is over 350,000 bytes
  273. long and is available on request.  Send a re-useable
  274. mailer and stamps (if in Canada) or money for return
  275. postage.
  276.  
  277.         In building the data files, I have gone to
  278. considerable lengths to give credit where it is due.
  279. Unlike some commercial publishers of Murphy's laws, I
  280. have not simply ripped off someone else's work and then
  281. put a copyright on it.  On the other hand, I have also
  282. avoided the temptation to indulge in wholesale raiding
  283. of authors who have created such aphorisms.  Some lists
  284. completely rip off authors like Robert A. Heinlein.  I
  285. took only two, gave credit, and recommend his books if
  286. you want more.  Since the text files may be readily edited
  287. by anyone, I am not responsible for their contents once the
  288. files pass out of my immediate control.
  289.  
  290.         Parenthetically, may we note Lyall's law of reciprocal
  291. copyright nastyness.  "Any publisher of Murphy's Laws who places
  292. a copyright on his publication and attempts to obtain redress
  293. in court for alleged violations will inevitably discover that he
  294. has published at least one of the alleged violator's laws and is
  295. in violation of the violator's copyright."  The first corollory
  296. states: "Their lordships (judges to our American cousins) tend
  297. to take a dim view of this!"
  298.  
  299.         Robert A. Heinlein was one of the leading figures
  300. in American science fiction.  His aphorisms are in
  301. "Time Enough For Love" as well as "The Notebooks of Lazarus
  302. Long" as illustrated by D.F. Vassallo.
  303. Any bookstore with a science fiction section will
  304. carry Heinlein's books.
  305.  
  306.         Piet Hein has 5 books of Grooks that I know of,
  307. although they may be out of print.  H.L. Mencken was a leading
  308. iconoclast in the first half of the century.  His works
  309. go in and out of print irregularly.  A master of the
  310. shavian essay but lacking G.B. Shaw's searing
  311. self-righteousness, Mencken made hamburger out of more
  312. sacred cows than McDonalds ever will.
  313.  
  314.         Bob Edwards, who is extensively quoted, was a
  315. Calgary journalist, crusader, moralist and drunkard of
  316. the first rank.  His newspaper, the "Eye Opener", was so
  317. outrageous that it was required reading all across Canada.
  318. The "Society Column" of the Eye Opener was full of true
  319. stories attributed to non-existent people and hilarious
  320. stories about real people.  Edwards expected the reader to
  321. sort it all out.  Consider the following "Social Note:"
  322.  
  323.      "The many friends of Peter F. Scratchley, the popular
  324. oil broker, will be glad to learn that he is rapidly recovering
  325. from a severe cold contracted while making a somewhat hasty
  326. departure, via the window, from the elegant mansion of the
  327. charming society matron, Mrs. J.T. Blinkbonny, at an early
  328. hour last Saturday morning."
  329.                          Summer Annual, 1922
  330.  
  331.      or:
  332.  
  333.      "Miss Maude de Vere of Drumheller arrived in the city Wednesday
  334. and was run out of town the same night.  It is a pity that Miss
  335. de Vere is not a racehorse, for she is very fast."
  336.                          Eye Opener, August 20, 1921
  337.  
  338.       By today's standards, Edwards was a chauvinist and a bit of
  339. a racist though he vented his intolerance on the English more
  340. than anyone else.  In his day, this kind of racism was almost as
  341. socially acceptable as anti-Americanism is among today's smart set.
  342. Unlike them, Edwards was uncompromisingly honest, even about his
  343. alcoholism and he campaigned tirelessly and occasionally successfully
  344. against callous bureaucrats, dishonest politicians, and rapacious
  345. corporations.
  346.  
  347.      One last "Society Note:"
  348.  
  349.      "Mr. Percy Redingot, who was recently caught in flagranto
  350. deplunko with a careless dame, has gone east for his health.
  351. Mr. Redingot has been suffering from his lungs for some time
  352. past, but there is nothing wrong with his gall."
  353.                               Eye Opener, Dec 6, 1919
  354.  
  355.         Murphy's military laws were collected over a
  356. period of years from Canadian subalterns.
  357.  
  358.         David Gerrold is a science fiction writer and
  359. wrote the script for the Star Trek episode "The Trouble With 
  360. Tribbles".  His contributions came second hand.  I do not
  361. have an original source.  The quotes in slightly modified
  362. form have re-appeared in Gerrold's "War against the Chtorr"
  363. trilogy.
  364.  
  365.         Dr. Edgar M. Horwood was the founder of geoprocessing
  366. or computer based mapping.  He had a thoroughly tongue in cheek
  367. attitude toward life in general and academia in particular.  Such
  368. people deserve immortality.
  369.  
  370.         The quotations attributed to Stan Kelly-Bootle, Gershwin's
  371. law, The Seven Catastrophes of Computing etc. are from:
  372.         The Devil's DP Dictionary
  373.         by Stan Kelly-Bootle
  374.         McGraw-Hill Inc.
  375.         ISBN 0-07-034022-6
  376.  
  377.         If you don't have a copy, get one.  Kelly-Bootle defines
  378. sequential as "of or pertaining to just one damned thing after
  379. another."
  380.  
  381.         Yup!
  382.  
  383.         Jon Bentley has two books which should be in every serious
  384. programmer's library, Programming Pearls, and More Programming
  385. Pearls.  They can be obtained from Addison-Wesley Publishing
  386. Company.  Excerpts from the second book are included in
  387. MURPHY00.TXT.
  388.  
  389.         Norman R. Augustine is president of Martin Marietta.  His
  390. trenchant observations appear in "Augustine's Laws", a paperback
  391. book.  I picked the included laws off a computer net.
  392.  
  393.         Jon H. Myer contributed his nine laws in the April 1958
  394. issue of Astounding Science Fiction.  Alma Hill's laws appeared
  395. in the May 1958 issue.  H.B. Fyfe's contributions appeared in the
  396. February 1958 issue.
  397.  
  398.         Kelvin Throop is a joint pseudonym used by the editors
  399. and contributors to Analog Science Fact - Science Fiction.
  400.  
  401.         Wm. Brasington is a consultant in Houston, Texas.
  402.  
  403.         Laws attributed to Lyall or Charles J.C. Lyall are
  404. original with yours truly and are copyright Charles J.C. Lyall.
  405. Reproduction on a not for profit basis is permitted.  All other
  406. rights are reserved.
  407.  
  408.         Murphy is normally included in the AUTOEXEC.BAT file
  409. immediately before one or more lengthy startup procedures which
  410. do not erase the screen.  This provides you with something to read
  411. while the computer gets its house in order.
  412.  
  413.         Enjoy.
  414.  
  415. */
  416.  
  417. /*    Other contributors include:
  418.     J.T. "Mitch" Mitchell    Edmonton, Alberta
  419.     J.A.E. Strong            Edmonton, Alberta
  420.     Pat Strong               Edmonton, Alberta
  421.     D.R.T. Reimer            Fort Saskatchewan, Alberta
  422.     Reg Jacklin              Calgary, Alberta
  423.     Peter Johnston           St. Albert, Alberta
  424.     Conrad Stenton           Midland, Ontario
  425.     Graham Newton            Montreal, Quebec
  426.     K.W. Tam                 Scarborough, Ontario
  427.     William A. Brasington    Houston, Texas, USA
  428.     W.A. Murphy (Really!)    St. John, New Brunswick
  429.     Michael K. Smith         Dallas, Texas, USA
  430.     Bev S.P. Bayer           Brisbane, Qld., Australia
  431.     Richard Patching         Calgary, Alberta
  432.     Don Cayo                 Quispamsis, New Brunswick
  433.     Richard E. Arndt         Sanford, Florida, USA
  434.     William A. Porter        Palo Alto, California, USA
  435.     L.J. Gaboury             Victoria, British Columbia
  436.     R. Swanson               Austin, Texas, USA
  437.     Don DeCuypere            Gloucester, Ontario
  438.     David Gordon             Austin, Texas, USA
  439.     Peter J. Otto            New York, N.Y. USA
  440.     Richard S. Mansfield     Camarillo, California, USA.
  441.     Brian R. Timmins         Emsworth, Hants., U.K.
  442.     Patricia Russell         Brighton, Ontario
  443.     Pat Monteith             St. Albert, Alberta
  444.     Arild Jensen             Keswick, Ontario
  445.     Ingrid A.L. Brown        Brisbane, Qld., Australia
  446.     John Hanlon              Chicago, Illinois, USA
  447.     F.L. Ferreri             Maple Hts, Ohio, USA
  448.     Dick Baker               Falls Church, Virginia, USA
  449.     David Hoeben             Beltsville, Maryland, USA
  450.     Jon Cereghino            Mountain View, California, USA
  451.     Kent Anderson            Austin, Texas, USA
  452.     Peter Skelton            Kingston, Ontario
  453.     J.C. Himanga             Kingwood, Texas, USA
  454. */
  455.  
  456.  
  457. char *help[] =
  458. {
  459.      "MURPHY looks for its text file first as MURPHY00.TXT in the",
  460.      "current directory. If that fails, MURPHY looks for the variable",
  461.      "MURPATH in the environment and uses its value as a full",
  462.      "pathname. For example:",
  463.      "   MURPATH = C:\SECRET\LAWS.TXT ",
  464.      "If this fails, MURPHY will retrieve the PATH from the",
  465.      "environment and search the PATH for MURPHY00.TXT",
  466.      "See source listing for more documentation.",
  467.      0
  468. };
  469.  
  470. char *notice[]=
  471. {
  472.         " Author Charles J.C. Lyall ",
  473.         "R.R. #2, Kingman, Alberta ",
  474.         "Canada, T0B 2M0 ",
  475.         "Phone/Fax (403) 662-2119 ",
  476.         "CompuServe 70674,313 ",
  477.         "This program is in the public domain and may be freely used ",
  478.         "by anyone for their own amusement. It is not to be used for ",
  479.         "profit without the author's permission. ",
  480.         "<Version 3.1 -- February 12, 1991>",
  481.         " Copyright (c) 1987, 1988, 1990, 1991 Charles J.C. Lyall ",
  482.         0
  483. };
  484.  
  485. /************************************************************
  486. *                                                           *
  487. *   Note:                                                   *
  488. *   By default, this routine is to be compiled under        *
  489. *   MicroSoft C 5.0. If you wish to use Borland's TURBO C   *
  490. *   to compile it, then you must uncomment the line         *
  491. *   "#define TURBOC"                                        *
  492. *                                                           *
  493. ************************************************************/
  494.  
  495. /* #define TURBOC  */                                 /*3.02*/
  496.  
  497. #include <io.h>
  498. #include <time.h>
  499. #include <string.h>
  500. #include <math.h>
  501. #include <stdio.h>
  502. #include <fcntl.h>
  503. #include <conio.h>
  504.  
  505. #ifndef TURBOC
  506.  
  507. #include <sys\types.h>
  508.  
  509. #endif
  510. #include <sys\stat.h>
  511.  
  512. char buffer[2048];                   /* 3.1                  */
  513. unsigned int one = 1;
  514. unsigned int bytesread;
  515. int fhl;                             /* file handle          */
  516. int i;
  517. char ipath[] = "MURPHY00.TXT";       /* data file            */
  518. long int filelen, filepos, ltime;
  519. long int minustwo = -2;             /* for backing up in file */
  520. char hold;                            /* hold read char here  */
  521. char *here = &hold;                   /* pointer to same      */
  522.  
  523. #include <stdlib.h>
  524. #define NULL 0
  525. #define GARDEN_PATH "MURPATH"
  526.  
  527. static char path_name[64];  /* assemble the path name here    */
  528. static char *name_end;
  529. static char *path_ptr;
  530. static char *str_ptr;
  531.  
  532.  
  533. /***************************display_help*************************/
  534.              
  535. void display_help()
  536. {
  537.      auto int i = 0;
  538.      while(help[i] != 0)
  539.           printf("%s\n", help[i++]);
  540.  
  541. }
  542.  
  543. /***************************search_path**************************/
  544.  
  545. int search_path(filename, flags)
  546. char *filename;
  547. int flags;
  548. {
  549.      if((path_ptr = getenv("PATH")) == NULL)
  550.            return (NULL);   /* no path hence no find on path  */
  551.      else
  552.      {
  553.           do           /* this has to work at least one time  */
  554.           {
  555.                name_end = path_name;
  556.                do
  557.                {
  558.                     *name_end++ = *path_ptr++;
  559.                }
  560.                while(*path_ptr != '\0' && *path_ptr != ';');
  561.                if( *(path_ptr - 1) != '\\')
  562.                     *name_end++ = '\\';
  563.                strcpy(name_end, filename);
  564.                if((fhl = open(path_name, flags)) != -1)
  565.                     return (fhl);
  566.                if(*path_ptr++ == '\0')
  567.                     return (NULL);
  568.           }while(1);
  569.      }
  570. }
  571.  
  572.  
  573. /******************************main*****************************/
  574.  
  575. main(argc)
  576. int argc;
  577. {
  578.      if(argc > 1)
  579.      {
  580.           display_help();
  581.           exit (0);
  582.      }
  583.      if((fhl = open(ipath, O_RDONLY | O_BINARY)) == -1)
  584.      {
  585.           if((str_ptr = getenv(GARDEN_PATH)) == NULL)
  586.           {
  587.                if((search_path(ipath, O_RDONLY | O_BINARY)) == NULL)
  588.                {
  589.                     printf("Failed to find text file. \n");
  590.                     printf("Run MURPHY ? \n");
  591.                     exit(1);
  592.                }
  593.           }
  594.           else
  595.           {
  596.                if((fhl = open(str_ptr, O_RDONLY | O_BINARY)) == -1)
  597.                {
  598.                     perror("Found text in path but failed to open it");
  599.                     printf("\nIncorrect environment variable \n");
  600.                     exit(1);
  601.                }
  602.           }
  603.      }
  604.  
  605.      if((filelen = filelength(fhl)) == -1L)
  606.      {
  607.           fprintf(stderr, "Failed to get length of text file \n");
  608.           exit(2);
  609.      }
  610.      time(<ime);   /* get time in seconds */
  611.  
  612. /*  a wee note about an otherwise senseless piece of code
  613.  *
  614.  *  ltime is a very large number, being the number of seconds
  615.  *  since January 1, 1970. Indeed, it will overflow into the
  616.  *  sign bit rather soon.  If one simply takes the time in
  617.  *  seconds mod the filelength as the pointer into the file,
  618.  *  then one has to wait up to a minute or more for enough
  619.  *  seconds (characters in the file) to pass so that the
  620.  *  printed law will change. If one simply multiplies the
  621.  *  system time in seconds by a suitably large number, one will
  622.  *  certainly have an overflow. Elderly programmers like
  623.  *  yours truly have a well developed fear of overflows.
  624.  *  Hence the following code which goes all the way around
  625.  *  Robin Hood's barn to avoid the overflow. Then it corrects
  626.  *  it anyway.
  627.  *
  628.  */
  629.  
  630.      filepos = ltime % filelen;        /* time mod filelength */
  631.      filepos *= 257;   /*3.01*/        /* multiply by a prime */
  632.      if((filepos = filepos % filelen) < 0)  /* can't be, eh? */
  633.           filepos = 0 - filepos;      /* correct overflow ! */
  634.  
  635. /* clear up the boundary value problems namely    3.01      */
  636. /*  - we can't back up from the zeroth char of the file     */
  637. /*  - we might be on a newline past the last "@" in the file*/
  638.  
  639.      if((filepos + 3) > filelen)        /*3.01*/
  640.          filepos -= 3;
  641.      else if(filepos < 3L)
  642.         filepos += 3;
  643.  
  644.      lseek(fhl, filepos, SEEK_SET);
  645.  
  646. /*  Now back up to the previous at symbol                 */
  647.  
  648.           do
  649.           {
  650.                filepos = lseek(fhl, minustwo, SEEK_CUR);
  651.                if((bytesread = read(fhl, here, one)) == -1)
  652.                     {
  653.                      fprintf(stderr, "Read of one char failed");
  654.                      exit(3);
  655.                     }
  656.            }while(hold != '@');
  657.  
  658. /*  Now point to the first character past the at symbol */
  659.  
  660.      bytesread = read(fhl, here, one);
  661.  
  662. /*  3.1 code to read into buffer, find end of law */
  663.  
  664. /*
  665. **  This complication is thrown in because the IBM/Microsoft
  666. **  LAN is a bit daft about character I/O when MURPHY runs
  667. **  on the LAN workstations.  This speeds things up a tad.
  668. **
  669. **  Other than that, it has nothing to recommend it
  670. */
  671.      do
  672.      {
  673.           buffer[i++] = hold;              /* print the char */
  674.           bytesread = read(fhl, here, one); /* read the next */
  675.           if(hold == 9)                         /*tab*/
  676.           {
  677.                hold = 32;                      /*space*/
  678.                buffer[i++] = hold;         /* print 4 spaces */
  679.                buffer[i++] = hold;         /* not 3          */
  680.                buffer[i++] = hold;         /* FOUR           */
  681.           }
  682.      }while((hold != '@') && (bytesread == 1));
  683.      buffer[i] = '\0';
  684.      printf("%s",buffer);
  685. }
  686.