Valentine Program

joseph.a.brownlee jbr0 at cbnews.att.com
Thu Feb 14 08:19:39 AEST 1991


I am posting this for a friend.  The "Reply-To" line in the article is set to
go to the author.  Send all comments to him.

> From: Andrew Rogers <uunet!hicomb!rogers%calamari>
> 
> Here's a cute seasonal program I hacked many years ago.  If you can possibly
> post it to alt.sources before Valentine's Day, I'm sure lots of people will
> enjoy it.
> 
> Andrew


---------------------------- 8<  cut here  >8 ----------------------------------
/*
 * Valentine program
 *
 *	prog <string1> <string2> ...
 *
 * generates repeating pattern of <stringN> to stdout in one of two designs
 * (see below).
 *
 *	options:
 *
 *	-H	draw heart design (default)
 *	-L	draw Robert Indiana's "LOVE" design
 *	-r	shift successive lines to right (default)
 *	-n	do not shift successive lines
 *	-l	shift successive lines to left
 *
 * Author: A. W. Rogers, circa 1980
 */

#define MAXSKIP		4			/* maximum # of skip pairs */
#define NSKIP		(2 * MAXSKIP + 1)	/* array dimension */
#define STRSIZ		200			/* string buffer size */
#define NONE		{ 0 }			/* line has no skip pairs */
#define END		-1			/* flag for last line */
#define LASTLINE	{ -1 }			/* initializer for last line */

#define HEART	0				/* output designs */
#define LOVE	1
#define DEFAULT_DESIGN	HEART

#define NOSHIFT	0				/* direction of shifting */
#define RSHIFT	1
#define LSHIFT	2
#define DEFAULT_SHIFT	RSHIFT

#define FALSE	0				/* the usual... */
#define TRUE	1


/* initialization of fields to skip when drawing each type of design */

short skip_heart[][NSKIP] = {
	NONE,
	{  2, 59 }, {  2, 14,  21, 40,  47, 59 }, {  2, 11,  23, 38,  50, 59 },
	{  2,  8,  26, 35,  53, 59 }, {  2,  6,  29, 33,  55, 59 },
	{  2,  4,  30, 31,  57, 59 }, {  2,  3,  58, 59 }, {  2,  2,  59, 59 },
	{  2,  2,  59, 59 }, {  2,  2,  59, 59 }, {  2,  2,  59, 59 },
	{  2,  2,  59, 59 }, {  2,  2,  59, 59 }, {  2,  2,  59, 59 },
	{  2,  3,  58, 59 }, {  2,  3,  58, 59 }, {  2,  4,  57, 59 },
	{  2,  5,  56, 59 }, {  2,  5,  56, 59 }, {  2,  6,  55, 59 },
	{  2,  7,  54, 59 }, {  2,  8,  53, 59 }, {  2, 10,  51, 59 },
	{  2, 11,  50, 59 }, {  2, 12,  49, 59 }, {  2, 14,  47, 59 },
	{  2, 16,  45, 59 }, {  2, 19,  42, 59 }, {  2, 21,  40, 59 },
	{  2, 23,  38, 59 }, {  2, 25,  36, 59 }, {  2, 28,  33, 59 },
	{  2, 29,  32, 59 }, {  2, 59 }, NONE,
	LASTLINE
	} ;

short skip_love[][NSKIP] = {
	NONE ,
	{  2, 13,  40, 48 }, {  4, 11,  36, 52 }, {  5, 10,  34, 54 },
	{  5, 10,  33, 44,  50, 55 }, {  5, 10,  32, 42,  51, 56 },
	{  5, 10,  32, 41,  52, 56 }, {  5, 10,  32, 40,  52, 56 },
	{  5, 10,  32, 39,  51, 56 }, {  5, 10,  32, 38,  50, 56 },
	{  5, 10,  32, 37,  49, 56 }, {  5, 10,  32, 36,  48, 56 },
	{  5, 10,  30, 30,  32, 36,  47, 56 },
	{  5, 10,  29, 30,  32, 37,  46, 56 },
	{  5, 10,  28, 30,  32, 38,  44, 56 },
	{  5, 10,  26, 30,  33, 55 }, {  2, 30,  36, 52 },
	{  2, 30,  40, 48 }, {  2, 14,  20, 59 }, {  2, 14,  20, 59 },
	{  5, 10,  24, 26,  37, 42,  55, 59 },
	{  6, 11,  23, 25,  37, 42,  57, 59 },
	{  6, 11,  23, 25,  37, 42,  58, 59 },
	{  7, 12,  22, 24,  37, 42,  59, 59 },
	{  7, 12,  22, 24,  37, 42,  50, 50 },
	{  8, 13,  21, 23,  37, 42,  49, 50 },
	{  8, 13,  21, 23,  37, 50 },
	{  9, 14,  20, 22,  37, 42,  49, 50 },
	{  9, 14,  20, 22,  37, 42,  50, 50 },
	{ 10, 15,  19, 21,  37, 42,  59, 59 },
	{ 10, 15,  19, 21,  37, 42,  58, 59 },
	{ 11, 16,  18, 20,  37, 42,  57, 59 },
	{ 11, 20,  37, 42,  55, 59 }, { 12, 19,  33, 59 }, { 12, 19,  33, 59 },
	NONE ,
	LASTLINE
	} ;

struct {
	short (*lineskip)[NSKIP];		/* ptr to one of above arrays */
	int  width;				/* width of design */
	} design_info[] = {
		skip_heart,	60,		/* HEART */
		skip_love,	60		/* LOVE */
	};


void initstr(str, text, width, off)		/* set up output string */
	char *str;
	char *text;
	int  width;
	int  off;
{
	off %= strlen(text);
	strcpy(str, text+off);
	while (strlen(str) < width)
		strcat(str, text);
	str[width] = '\0';
}


main(argc, argv)
	int argc;
	char **argv;
{
	char str[STRSIZ], *parg;
	int i, off, incr;
	int first = TRUE;
	int design = DEFAULT_DESIGN, direction = DEFAULT_SHIFT;
	short (*ppskip)[NSKIP];
	short *pskip;

	while (parg = *++argv) {

		if (*parg == '-') {		/* get option */
			switch(*++parg) {
			case 'L':
				design = LOVE;
				break;
			case 'H':
				design = HEART;
				break;
			case 'l':
				direction = LSHIFT;
				break;
			case 'r':
				direction = RSHIFT;
				break;
			case 'n':
				direction = NOSHIFT;
				break;
			}
			continue;
		}
	
		if (*parg == '\0')		/* skip null args */
			continue;
	
		if (!first)			/* print design for arg */
			printf("\f\n");		/* <FF> between designs */
		first = FALSE;

		incr = direction == NOSHIFT ? 0 :
		       direction == LSHIFT ? 1 : strlen(parg) - 1;

		for (off = 0, ppskip = design_info[design].lineskip;
		     *(pskip = (short *)ppskip) != END;
		     off += incr, ppskip++) {
			initstr(str, parg, design_info[design].width, off);
			for ( ; pskip[0]; pskip += 2)
				for (i = pskip[0]; i <= pskip[1]; i++)
					str[i-1] = ' ';
			printf("\t%s\n", str);
		}
	}
}
-- 
   -      _   Joe Brownlee, Analysts International Corp. @ AT&T Network Systems
  /_\  @ / `  471 E Broad St, Suite 1610, Columbus, Ohio 43215   (614) 860-7461
 /   \ | \_,  E-mail: jbr at cblph.att.com     Who pays attention to what _I_ say?
 "Scotty, we need warp drive in 3 minutes or we're all dead!" --- James T. Kirk



More information about the Alt.sources mailing list