home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1635 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  10.6 KB

  1. From: chad@qip.UUCP (Chad R. Larson)
  2. Newsgroups: alt.sources
  3. Subject: Re: sifi
  4. Message-ID: <3875@qip.UUCP>
  5. Date: 31 Jul 90 23:14:51 GMT
  6.  
  7. Ok, I admit it.  I'm a compulsive frobber.  I took the posting of
  8. "sifi" and de-ANSIfied it so it would compile on SysVr3 (and
  9. probably most UNIXes).  This probably broke it for an ANSI
  10. compiler.  I don't know; I don't have one handy.
  11.  
  12. I also ran it through the C beautifier and linted it.  Lint
  13. discovered a couple of descriptions were unused (weapon results
  14. and being type) so I added code to output them.  I fixed the
  15. "chapters" hack at the end.
  16.  
  17. This has changed so many lines that "diff" and "patch" would be
  18. useless, so here it is again.
  19. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  20. /*
  21. ** From: kdq@demott.COM (Kevin D. Quitt)
  22. ** Newsgroups: alt.sources
  23. ** Subject: Sifi generator
  24. ** Message-ID: <439@demott.COM>
  25. ** Date: 30 Jul 90 19:37:53 GMT
  26. ** Reply-To: kdq@demott.COM (Kevin D. Quitt)
  27. ** Organization: DeMott Electronics Co., Van Nuys CA
  28. ** Lines: 422
  29. */
  30.  
  31. /*
  32. Kevin D. Quitt         demott!kdq   kdq@demott.com
  33. DeMott Electronics Co. 14707 Keswick St.   Van Nuys, CA 91405-1266
  34. VOICE (818) 988-4975   FAX (818) 997-1190  MODEM (818) 997-4496 PEP last
  35.  
  36.     96.37% of all statistics are made up.
  37. */
  38.  
  39. /* De-ansified by chad@anasaz.UUCP - Tue Jul 31 08:13:33 MST 1990 */
  40.  
  41. /**
  42. Please note: This program was converted on the date shown from a
  43. spaghetti-coded BASIC program (that almost worked).  I am the original
  44. author of both works, though G*d only knows why someone would claim
  45. otherwise.  I make no claims that the code below is optimal, or even
  46. particularly good - most of the translation was done with editor macros.
  47.  
  48. Note that the original flowchart for this program is *not* my creation -
  49. I believe that Gahan Wilson did it originally, I think about 81,
  50. published in OMNI magazine.  I do know that he published such a chart
  51. for horror-films (somewhere, I have that one, too) - I believe this
  52. latter was in National Lampoon.  I would appreciate authoritative
  53. information about the original author and chart.  I would *really*
  54. appreciate a copy of that chart - which I'll copy and mail to everyone. 
  55.  
  56.  
  57. Useful Improvements:
  58.  
  59.   Some way of encoding the story produced to prevent duplication
  60.     of plot lines (within, oh, say, 50-100 plots).
  61.  
  62.   Perhaps a better random number generator, or better seed.
  63.  
  64.   More phrases, more "au curant" phrases (I just added the Captain Kirk
  65.     shtick), maybe some more original paths.
  66.  
  67.   A better way to encode the phrase data perhaps, so that a switch-less
  68.     or switch-minimal engine can create all the phrases.
  69.  
  70.  
  71. Looking for comments on whether to keep the phrases in a separate file,
  72. something like:
  73.  
  74.     SIZE:
  75.     tiny
  76.     large
  77.     "incredibly phenomenally huge"
  78.  
  79.     BUT:
  80.     ...
  81.  
  82. I already have code for parsing such files.
  83.  
  84.  
  85. This code is ANSI C, but compiled with MSC 6.0.  Let me know if ANSI
  86. gives you problems; obviously it doesn't matter a whole lot.  Please let
  87. me know what changes you have to make to get it to run on your system -
  88. I'll incorporate all I can.  This is fairly simple; my goal is for it to
  89. compile without warnings on any system.
  90.  
  91. I will periodically inform you of "improvements" via e-mail.
  92.  
  93. Mostly it's silly, and for fun.  Let's see what we can do with it before
  94. we release it on an unsuspecting net.
  95. **/
  96.  
  97. /*
  98. ** SIFI.C  24-Jul-90 21:21:51 by Kevin D. Quitt
  99. **     Science fiction plot generator
  100. */
  101.  
  102. #include    <stdio.h>
  103. #include    <string.h>
  104. #include    <ctype.h>
  105. #ifdef MSDOS
  106. # include    <stdlib.h>
  107. # include    <time.h>
  108. #else
  109. typedef long time_t;
  110. #endif
  111.  
  112. /* function definitions */
  113. #if __STDC__ == 1
  114. char    *skip_blanks(char *);
  115. void    print (char *);
  116. int    describe_being (void);
  117. int    do_but (void);
  118. void    sifi (void);
  119. int    main(int, char *);
  120. long    atol(char *);
  121. void    exit(int);
  122. void    srand(unsigned int);
  123. time_t    time(time_t *);
  124. #else
  125. char    *skip_blanks();
  126. void    print ();
  127. int    describe_being ();
  128. int    do_but ();
  129. void    sifi ();
  130. int    main();
  131. long    atol();
  132. void    exit();
  133. void    srand();
  134. time_t    time();
  135. #endif
  136.  
  137. int    col;                            /* characters on line */
  138. #define TRUE    (1)
  139. #define FALSE   (0)
  140.  
  141. #define LINE_WIDTH  (75)
  142.  
  143. #define SIZE_COUNT  (6)
  144. char    *size[ SIZE_COUNT ] = 
  145. {
  146.     "tiny",
  147.     "giant",
  148.     "microscopic",
  149.     "planet-sized",
  150.     "humongous",
  151.     "itty-bitty"
  152. };
  153.  
  154.  
  155. #define BEING_COUNT (5)
  156. char    *being[ BEING_COUNT ] = 
  157. {
  158.     "bugs, which",
  159.     "reptiles, which",
  160.     "mechanical devices, which",
  161.     "super persons, who",
  162.     "icky things, which"
  163. };
  164.  
  165.  
  166. #define BEING_TYPE_COUNT    (4)
  167. char    *being_type[ BEING_TYPE_COUNT ] = 
  168. {
  169.     "extra-galactic",
  170.     "Martian",
  171.     "Moon",
  172.     "Betelgeusian"
  173. };
  174.  
  175.  
  176. #define COMET_RESULTS_COUNT (4)
  177. char    *comet_results[ COMET_RESULTS_COUNT ] = 
  178. {
  179.     "destroyed.",
  180.     "saved by Jesus and the J.D.L.",
  181.     "not destroyed, but everybody dies.",
  182.     "not destroyed, but almost everybody dies."
  183. };
  184.  
  185.  
  186. #define KILLED_BY_COUNT (3)
  187. char    *killed_by[ KILLED_BY_COUNT ]   = 
  188. {
  189.     "the Atomic Bomb",
  190.     "a crowd of peasants with torches",
  191.     "the Army, Navy, Air Force, Marine Corps and/or Coast Guard"
  192. };
  193.  
  194.  
  195. #define BUT_COUNT   (4)
  196. char    *but[ BUT_COUNT ]   = 
  197. {
  198.     "they fall in love with this beautiful girl",
  199.     "a cute little kid convinces them that people are O.K.",
  200.     "a priest talks to them of God",
  201.     "Captain Kirk uses logic on them"
  202. };
  203.  
  204.  
  205. #define TERMINAL1_COUNT (3)
  206. char    *term1[ TERMINAL1_COUNT ]   = 
  207. {
  208.     "and they die.",
  209.     "and they leave.",
  210.     "and they turn into disgusting lumps."
  211. };
  212.  
  213.  
  214. #define TERMINAL2_COUNT (4)
  215. char    *term2[ TERMINAL2_COUNT ]   = 
  216. {
  217.     "but they die from catching chicken pox.",
  218.     "so they kill us.",
  219.     "so they put us under a benign dictatorship.",
  220.     "so they eat us."
  221. };
  222.  
  223.  
  224. #define WEAPON_RESULTS_COUNT    (3)
  225. char    *weapon_results[ WEAPON_RESULTS_COUNT ] = 
  226. {
  227.     "which fails",
  228.     "which kills them.",
  229.     "which turns them into disgusting lumps.",
  230. };
  231.  
  232.  
  233.  
  234. char    *skip_blanks(line)
  235.     char    *line;
  236. {
  237.     while ( isspace( *line++) )
  238.     ;
  239.  
  240.     return  --line;
  241. }
  242.  
  243.  
  244.  
  245. /*
  246. **   Output text broken on word boundaries.
  247. ** 
  248. ** Text is automatically preceeded by a blank, unless a period
  249. ** starts the line.  Leading blanks are tossed when we're at the
  250. ** start of a line.
  251. */
  252.  
  253. void    print (line)
  254.     char    *line;
  255. {
  256.     int        len = strlen( line );
  257.     int        c, l;
  258.     char    myline[ LINE_WIDTH + 1 ];
  259.  
  260.     if ( (col  !=  0)  &&  !ispunct( *line ) ) {
  261.     putchar( ' ' );
  262.     col++;
  263.     }
  264.  
  265.     /*  If the input text won't fit on the current line, we split it */
  266.     while ( (len + col)  >  LINE_WIDTH ) {
  267.     if ( col  >=  LINE_WIDTH ) {    /* Safety play from blank above */
  268.         puts( "" );
  269.         col     = 0;
  270.         line    = skip_blanks( line );
  271.         continue;
  272.     }
  273.  
  274.     for ( l = LINE_WIDTH - col; l >= 0; l--) {
  275.         if ( isspace( c = line[ l ] )  ||  ( c  ==  '-' ) ) {
  276.         if ( c  == '-' )
  277.             l++;
  278.         strncpy( myline, line, l );
  279.         myline[ l ] = 0;
  280.         puts( myline );
  281.         col         = 0;
  282.         len     -= l;
  283.         line    += l + 1;
  284.         break;
  285.         }
  286.     }
  287.  
  288.     /*
  289.         ** If we couldn't split it, the are two possibilites.  If we're
  290.         ** not on column 0, then it may be that the *first* word is too
  291.         ** long to fit.  If we *are* on column zero, then the string
  292.         ** can't be split.  In the former case we start a new line and
  293.         ** try again.  In the latter, we punt.
  294.     */
  295.  
  296.     if ( l  <  0 ) {
  297.         if ( col  ==  0 ) {         /* Can't be split! */
  298.         puts( line );           /* Joke it */
  299.         return;
  300.         }
  301.         col = LINE_WIDTH;           /* First word can't be split */
  302.     }
  303.     }
  304.  
  305.     printf( "%s", line );
  306.     col += len;
  307. }
  308.  
  309.  
  310.  
  311. int    describe_being ()
  312. {
  313.     int    done    = FALSE;
  314.  
  315.     print( size[ rand() % SIZE_COUNT ] );
  316.     print( being_type[ rand() % BEING_TYPE_COUNT ] );
  317.     print( being[ rand() % BEING_COUNT ] );
  318.     switch ( rand() % 6 ) {
  319.     case 0:
  320.     {
  321.         print( "want our women,");
  322.         if ( rand()  & 1 ) {
  323.         print( "take a few and leave.");
  324.         done = TRUE;
  325.         break;
  326.         }
  327.         break;
  328.     }
  329.  
  330.     case 1:
  331.     {
  332.         print( "are friendly.");
  333.         done = TRUE;
  334.         break;
  335.     }
  336.  
  337.     case 2:
  338.     {
  339.         print( "are friendly, but misunderstood,");
  340.         break;
  341.     }
  342.  
  343.     case 3:
  344.     {
  345.         print( "misunderstand us");
  346.         break;
  347.     }
  348.  
  349.     case 4:
  350.     {
  351.         print( "understand us too well");
  352.         break;
  353.     }
  354.  
  355.     case 5:
  356.     {
  357.         print( 
  358.           "look upon us only as a source of nourishment");
  359.         if ( rand()  &  1 ) {
  360.         print( "and eat us.");
  361.         done = TRUE;
  362.         break;
  363.         }
  364.         break;
  365.     }
  366.     }
  367.  
  368.     return  done;
  369. }
  370.  
  371.  
  372.  
  373. int    do_but ()
  374. {
  375.     int    choice;
  376.  
  377.     print( ", but");
  378.     choice = rand() % BUT_COUNT;
  379.     print( but[ choice ] );
  380.     if ( (choice == 0)  &&  (rand() & 1) )
  381.     print( "and they get married and live happily ever after.");
  382.     else
  383.     print( term1[ rand() % TERMINAL1_COUNT ] );
  384.  
  385.     return  TRUE;
  386. }
  387.  
  388.  
  389.  
  390. void    sifi ()
  391. {
  392.     int    done = FALSE;
  393.     int    choice;
  394.  
  395.     switch ( rand() % 6 ) {
  396.     case 0:
  397.     {
  398.         print( "Earth is struck by a giant comet and");
  399.         print( comet_results[ rand() %  COMET_RESULTS_COUNT ] );
  400.         done = TRUE;
  401.         break;
  402.     }
  403.     case 1:
  404.     case 2:
  405.     {
  406.         print( "Scientists discover or invent");
  407.         done = describe_being();
  408.         break;
  409.     }
  410.     case 3:
  411.     case 4:
  412.     {
  413.         print( "Earth is attacked by");
  414.         done = describe_being();
  415.         break;
  416.     }
  417.     case 5:
  418.     {
  419.         print( "Earth burns up or freezes or falls into the sun");
  420.         if ( rand()  &  1 )
  421.         print( "and everybody dies.");
  422.         else
  423.         print( "and almost everybody dies.");
  424.         done = TRUE;
  425.         break;
  426.     }
  427.     }
  428.  
  429.     if ( !done ) {
  430.     if ( rand()  &  1 )
  431.         print( "and are radioactive, and");
  432.     else
  433.         print( "and are not radioactive, and");
  434.  
  435.     if ( rand()  &  1 )
  436.         print( "can be killed by");
  437.     else
  438.         print( "cannot be killed by");
  439.  
  440.     print( killed_by[ rand() % KILLED_BY_COUNT ] );
  441.  
  442.     if ( rand()  &  1 ) {
  443. what_to_do:
  444.         if ( rand()  &  3 )
  445.         done = do_but();
  446.         else
  447.         {
  448.         if ( rand() % 3 )
  449.             print( term2[ rand() % TERMINAL2_COUNT ] );
  450.         else
  451.         {
  452.             print( "so scientists invent a weapon");
  453.             choice = rand() % WEAPON_RESULTS_COUNT;
  454.             print( weapon_results[ choice ] );
  455.             if ( choice  ==  0 )
  456.             goto    what_to_do;
  457.         }
  458.         }
  459.     } else
  460.         print( ".");
  461.     }
  462. }
  463.  
  464.  
  465.  
  466. int    main(argc, argv)
  467.     int        argc;
  468.     char    *argv[];
  469. {
  470.     long    how_many    = 1;
  471.     int        chapters    = FALSE;
  472.     time_t    seed;
  473.  
  474.     if ( argc  >  1 ) {
  475.     if ( *argv[1]  ==  '-' ) {
  476.         how_many = atol( &argv[1][1] );
  477.         chapters = TRUE;
  478.     } else {
  479.         puts( "Science Fiction plot generator");
  480.         puts( "sifi -number_of_chapters");
  481.         exit( 0 );
  482.     }
  483.     }
  484.  
  485.     time( &seed );
  486.     srand( (unsigned int)(seed & -1) );
  487.  
  488.     while ( how_many--) {
  489.     col = 0;
  490.     sifi();
  491.     puts("\n");
  492.     }
  493.     if (chapters)
  494.     puts( "The End.");
  495.  
  496.     return  0;
  497. }
  498. -- 
  499. Chad R. Larson          ...{mcdphx,asuvax}!anasaz!chad or chad@anasaz.UUCP
  500. Anasazi, Inc. - 7500 North Dreamy Draw Drive, Suite 120, Phoenix, Az 85020
  501. (602) 870-3330            "I read the news today, oh boy!"  -- John Lennon
  502.