home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2753 < prev    next >
Encoding:
Internet Message Format  |  1991-02-14  |  5.4 KB

  1. From: jbr0@cbnews.att.com (joseph.a.brownlee)
  2. Newsgroups: alt.sources
  3. Subject: Valentine Program
  4. Message-ID: <1991Feb13.211939.1547@cbnews.att.com>
  5. Date: 13 Feb 91 21:19:39 GMT
  6.  
  7. I am posting this for a friend.  The "Reply-To" line in the article is set to
  8. go to the author.  Send all comments to him.
  9.  
  10. > From: Andrew Rogers <uunet!hicomb!rogers%calamari>
  11. > Here's a cute seasonal program I hacked many years ago.  If you can possibly
  12. > post it to alt.sources before Valentine's Day, I'm sure lots of people will
  13. > enjoy it.
  14. > Andrew
  15.  
  16.  
  17. ---------------------------- 8<  cut here  >8 ----------------------------------
  18. /*
  19.  * Valentine program
  20.  *
  21.  *    prog <string1> <string2> ...
  22.  *
  23.  * generates repeating pattern of <stringN> to stdout in one of two designs
  24.  * (see below).
  25.  *
  26.  *    options:
  27.  *
  28.  *    -H    draw heart design (default)
  29.  *    -L    draw Robert Indiana's "LOVE" design
  30.  *    -r    shift successive lines to right (default)
  31.  *    -n    do not shift successive lines
  32.  *    -l    shift successive lines to left
  33.  *
  34.  * Author: A. W. Rogers, circa 1980
  35.  */
  36.  
  37. #define MAXSKIP        4            /* maximum # of skip pairs */
  38. #define NSKIP        (2 * MAXSKIP + 1)    /* array dimension */
  39. #define STRSIZ        200            /* string buffer size */
  40. #define NONE        { 0 }            /* line has no skip pairs */
  41. #define END        -1            /* flag for last line */
  42. #define LASTLINE    { -1 }            /* initializer for last line */
  43.  
  44. #define HEART    0                /* output designs */
  45. #define LOVE    1
  46. #define DEFAULT_DESIGN    HEART
  47.  
  48. #define NOSHIFT    0                /* direction of shifting */
  49. #define RSHIFT    1
  50. #define LSHIFT    2
  51. #define DEFAULT_SHIFT    RSHIFT
  52.  
  53. #define FALSE    0                /* the usual... */
  54. #define TRUE    1
  55.  
  56.  
  57. /* initialization of fields to skip when drawing each type of design */
  58.  
  59. short skip_heart[][NSKIP] = {
  60.     NONE,
  61.     {  2, 59 }, {  2, 14,  21, 40,  47, 59 }, {  2, 11,  23, 38,  50, 59 },
  62.     {  2,  8,  26, 35,  53, 59 }, {  2,  6,  29, 33,  55, 59 },
  63.     {  2,  4,  30, 31,  57, 59 }, {  2,  3,  58, 59 }, {  2,  2,  59, 59 },
  64.     {  2,  2,  59, 59 }, {  2,  2,  59, 59 }, {  2,  2,  59, 59 },
  65.     {  2,  2,  59, 59 }, {  2,  2,  59, 59 }, {  2,  2,  59, 59 },
  66.     {  2,  3,  58, 59 }, {  2,  3,  58, 59 }, {  2,  4,  57, 59 },
  67.     {  2,  5,  56, 59 }, {  2,  5,  56, 59 }, {  2,  6,  55, 59 },
  68.     {  2,  7,  54, 59 }, {  2,  8,  53, 59 }, {  2, 10,  51, 59 },
  69.     {  2, 11,  50, 59 }, {  2, 12,  49, 59 }, {  2, 14,  47, 59 },
  70.     {  2, 16,  45, 59 }, {  2, 19,  42, 59 }, {  2, 21,  40, 59 },
  71.     {  2, 23,  38, 59 }, {  2, 25,  36, 59 }, {  2, 28,  33, 59 },
  72.     {  2, 29,  32, 59 }, {  2, 59 }, NONE,
  73.     LASTLINE
  74.     } ;
  75.  
  76. short skip_love[][NSKIP] = {
  77.     NONE ,
  78.     {  2, 13,  40, 48 }, {  4, 11,  36, 52 }, {  5, 10,  34, 54 },
  79.     {  5, 10,  33, 44,  50, 55 }, {  5, 10,  32, 42,  51, 56 },
  80.     {  5, 10,  32, 41,  52, 56 }, {  5, 10,  32, 40,  52, 56 },
  81.     {  5, 10,  32, 39,  51, 56 }, {  5, 10,  32, 38,  50, 56 },
  82.     {  5, 10,  32, 37,  49, 56 }, {  5, 10,  32, 36,  48, 56 },
  83.     {  5, 10,  30, 30,  32, 36,  47, 56 },
  84.     {  5, 10,  29, 30,  32, 37,  46, 56 },
  85.     {  5, 10,  28, 30,  32, 38,  44, 56 },
  86.     {  5, 10,  26, 30,  33, 55 }, {  2, 30,  36, 52 },
  87.     {  2, 30,  40, 48 }, {  2, 14,  20, 59 }, {  2, 14,  20, 59 },
  88.     {  5, 10,  24, 26,  37, 42,  55, 59 },
  89.     {  6, 11,  23, 25,  37, 42,  57, 59 },
  90.     {  6, 11,  23, 25,  37, 42,  58, 59 },
  91.     {  7, 12,  22, 24,  37, 42,  59, 59 },
  92.     {  7, 12,  22, 24,  37, 42,  50, 50 },
  93.     {  8, 13,  21, 23,  37, 42,  49, 50 },
  94.     {  8, 13,  21, 23,  37, 50 },
  95.     {  9, 14,  20, 22,  37, 42,  49, 50 },
  96.     {  9, 14,  20, 22,  37, 42,  50, 50 },
  97.     { 10, 15,  19, 21,  37, 42,  59, 59 },
  98.     { 10, 15,  19, 21,  37, 42,  58, 59 },
  99.     { 11, 16,  18, 20,  37, 42,  57, 59 },
  100.     { 11, 20,  37, 42,  55, 59 }, { 12, 19,  33, 59 }, { 12, 19,  33, 59 },
  101.     NONE ,
  102.     LASTLINE
  103.     } ;
  104.  
  105. struct {
  106.     short (*lineskip)[NSKIP];        /* ptr to one of above arrays */
  107.     int  width;                /* width of design */
  108.     } design_info[] = {
  109.         skip_heart,    60,        /* HEART */
  110.         skip_love,    60        /* LOVE */
  111.     };
  112.  
  113.  
  114. void initstr(str, text, width, off)        /* set up output string */
  115.     char *str;
  116.     char *text;
  117.     int  width;
  118.     int  off;
  119. {
  120.     off %= strlen(text);
  121.     strcpy(str, text+off);
  122.     while (strlen(str) < width)
  123.         strcat(str, text);
  124.     str[width] = '\0';
  125. }
  126.  
  127.  
  128. main(argc, argv)
  129.     int argc;
  130.     char **argv;
  131. {
  132.     char str[STRSIZ], *parg;
  133.     int i, off, incr;
  134.     int first = TRUE;
  135.     int design = DEFAULT_DESIGN, direction = DEFAULT_SHIFT;
  136.     short (*ppskip)[NSKIP];
  137.     short *pskip;
  138.  
  139.     while (parg = *++argv) {
  140.  
  141.         if (*parg == '-') {        /* get option */
  142.             switch(*++parg) {
  143.             case 'L':
  144.                 design = LOVE;
  145.                 break;
  146.             case 'H':
  147.                 design = HEART;
  148.                 break;
  149.             case 'l':
  150.                 direction = LSHIFT;
  151.                 break;
  152.             case 'r':
  153.                 direction = RSHIFT;
  154.                 break;
  155.             case 'n':
  156.                 direction = NOSHIFT;
  157.                 break;
  158.             }
  159.             continue;
  160.         }
  161.     
  162.         if (*parg == '\0')        /* skip null args */
  163.             continue;
  164.     
  165.         if (!first)            /* print design for arg */
  166.             printf("\f\n");        /* <FF> between designs */
  167.         first = FALSE;
  168.  
  169.         incr = direction == NOSHIFT ? 0 :
  170.                direction == LSHIFT ? 1 : strlen(parg) - 1;
  171.  
  172.         for (off = 0, ppskip = design_info[design].lineskip;
  173.              *(pskip = (short *)ppskip) != END;
  174.              off += incr, ppskip++) {
  175.             initstr(str, parg, design_info[design].width, off);
  176.             for ( ; pskip[0]; pskip += 2)
  177.                 for (i = pskip[0]; i <= pskip[1]; i++)
  178.                     str[i-1] = ' ';
  179.             printf("\t%s\n", str);
  180.         }
  181.     }
  182. }
  183. -- 
  184.    -      _   Joe Brownlee, Analysts International Corp. @ AT&T Network Systems
  185.   /_\  @ / `  471 E Broad St, Suite 1610, Columbus, Ohio 43215   (614) 860-7461
  186.  /   \ | \_,  E-mail: jbr@cblph.att.com     Who pays attention to what _I_ say?
  187.  "Scotty, we need warp drive in 3 minutes or we're all dead!" --- James T. Kirk
  188.