home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / tc-book.zip / POEMS.C < prev    next >
Text File  |  1987-08-20  |  5KB  |  197 lines

  1. /* ---------------- poems.c ----------------- */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include "twindow.h"
  7. #include "keys.h"
  8.  
  9. /* -------- local prototypes ----------- */
  10. void get_poem(int s);
  11. int ht (char **tb);
  12. int wd (char **tb);
  13. char *titles [] = {
  14.     " 1: TELL ALL THE TRUTH BUT TELL IT SLANT ",
  15.     " 2: AFTER LONG SILENCE ",
  16.     " 3: A MAN SAID TO THE UNIVERSE ",
  17.     " 4: FLYING CROOKED ",
  18.     " 5: THE IDLE LIFE I LEAD ",0
  19. };
  20. WINDOW *pno [] = {0, 0, 0, 0, 0};
  21. static int x [] = {20, 15, 29, 10, 17};
  22. static int y [] = {5, 10, 13, 18, 6};
  23. static int wcl [] [2] = {    {BLUE, WHITE},
  24.                             {MAGENTA, WHITE},
  25.                             {RED, WHITE},
  26.                             {GREEN, WHITE},
  27.                             {AQUA, WHITE}    };
  28. char *poem1 [] = {
  29.     "Tell all the truth but tell it slant -",
  30.     "Success in Circuit lies",
  31.     "Too bright for our infirm Delight",
  32.     "The Truth's superb surprise",
  33.     "",
  34.     "As Lightning to the Children eased",
  35.     "With explanation kind",
  36.     "The Truth must dazzle gradually",
  37.     "Or every man be blind -",
  38.     "                Emily Dickenson",
  39.     0
  40. };
  41.  
  42. char *poem2 [] = {
  43.     "Speech after long silence; it is right,",
  44.     "All other lovers being estranged or dead,",
  45.     "Unfriendly lamplight hid under its shade,",
  46.     "The curtains drawn upon unfriendly night,",
  47.     "That we descant and yet again descant",
  48.     "Upon the supreme theme of Art and Song:",
  49.     "Bodily decrepitude is wisdom; young",
  50.     "We loved each other and were ignorant.",
  51.     "              William Butler Yeats",
  52.     0
  53. };
  54.  
  55. char *poem3 [] = {
  56.     "A man said to the universe:",
  57.     "\"Sir, I exist!\"",
  58.     "\"However,\" replied the universe,",
  59.     "\"The fact has not created in me",
  60.     "A sense of obligation.\"",
  61.     "               Stephen Crane",
  62.     0
  63. };
  64.  
  65. char *poem4 [] = {
  66.     "The butterfly, a cabbage-white,",
  67.     "(His honest idiocy of flight)",
  68.     "Will never now, it is too late,",
  69.     "Master the art of flying straight,",
  70.     "Yet has - who knows so well as I? -",
  71.     "A just sense of how not to fly:",
  72.     "He lurches here and there by guess",
  73.     "And God and hope and hopelessness.",
  74.     "Even the aerobatic swift",
  75.     "Has not his flying-crooked gift.",
  76.     "              Robert Graves",
  77.     0
  78. };
  79. /*page*/
  80. char *poem5 [] = {
  81.     "The idle life I lead",
  82.     "Is like a pleasant sleep,",
  83.     "Wherein I rest and heed",
  84.     "The dreams that by me sweep.",
  85.     "",
  86.     "And still of all my dreams",
  87.     "In turn so swiftly past,",
  88.     "Each in its fancy seems,",
  89.     "A nobler than the last.",
  90.     "",
  91.     "And every eve I say,",
  92.     "Noting my step in bliss,",
  93.     "That I have known no day",
  94.     "In all my life like this.",
  95.     "         Robert Bridges",
  96.     0
  97. };
  98. char **poem [] = {poem1,poem2,poem3,poem4,poem5,0};
  99.  
  100. void poems()
  101. {
  102.     int s = 0, i, c;
  103.     WINDOW *mn;
  104.     char **cp;
  105.  
  106.     cursor(0, 25);
  107.     mn = establish_window(0, 0, 7, 45);
  108.     set_title(mn, " Select A Poem ");
  109.     set_colors(mn, ALL, BLUE, GREEN, BRIGHT);
  110.     set_colors(mn, ACCENT, GREEN, WHITE, BRIGHT);
  111.     display_window(mn);
  112.     cp = titles;
  113.     while (*cp)
  114.         wprintf(mn, "\n%s", *cp++);
  115.     while (1)    {
  116.         set_help("poemmenu", 40, 10);
  117.         s = get_selection(mn, s+1, "12345");
  118.         if (s == 0)
  119.             break;
  120.         if (s == FWD || s == BS)    {
  121.             s = 0;
  122.             continue;
  123.         }
  124.         hide_window(mn);
  125.         get_poem(--s);
  126.         c = 0;
  127.         set_help("poems   ", 5, 15);
  128.         while (c != ESC)    {
  129.             c = get_char();
  130.             switch (c)    {
  131.                 case FWD:    rmove_window(pno[s], 1, 0);
  132.                             break;
  133.                 case BS:    rmove_window(pno[s], -1, 0);
  134.                             break;
  135.                 case UP:    rmove_window(pno[s], 0, -1);
  136.                             break;
  137.                 case DN:    rmove_window(pno[s], 0, 1);
  138.                             break;
  139.                 case DEL:    delete_window(pno[s]);
  140.                             pno[s] = NULL;
  141.                             break;
  142.                 case '+':    forefront(pno[s]);
  143.                             break;
  144.                 case '-':    rear_window(pno[s]);
  145.                 default:    break;
  146.             }
  147.             if (c > '0' && c < '6')
  148.                 get_poem(s = c - '1');
  149.         }
  150.         forefront(mn);
  151.         display_window(mn);
  152.     }
  153.     close_all();
  154.     for (i = 0; i < 5; i++)
  155.         pno[i] = NULL;
  156. }
  157. /*page*/
  158. /* --- activate a poem by number ---- */
  159. static void get_poem(int s)
  160. {
  161.     char **cp;
  162.     static int lastp = -1;
  163.     if (lastp != -1)
  164.         set_intensity(pno[lastp], DIM);
  165.     lastp = s;
  166.     if (pno [s])
  167.         set_intensity(pno[s], BRIGHT);
  168.     else    {
  169.         pno [s] = establish_window
  170.             (x[s], y[s], ht(poem[s]), wd(poem[s]));
  171.         set_title(pno[s], titles[s]);
  172.         set_colors(pno[s],ALL,wcl[s][0],wcl[s][1],BRIGHT);
  173.         set_border(pno[s], 1);
  174.         display_window(pno[s]);
  175.         cp = poem[s];
  176.         while (*cp)
  177.             wprintf(pno[s], "\n %s", *cp++);
  178.     }
  179. }
  180. /* ------- compute height of a window display table ---- */
  181. static int ht(char **tb)
  182. {
  183.     int h = 0;
  184.     while (*(tb + h++))    ;
  185.     return h + 3;
  186. }
  187. /* ------- compute width of a window display table ------- */
  188. static int wd(char **tb)
  189. {
  190.     int w = 0;
  191.     while (*tb)        {
  192.         w = max(w, strlen(*tb));
  193.         tb++;
  194.     }
  195.     return w + 4;
  196. }
  197.