.plan

Steve Harrold swh at hpcupt1.HP.COM
Fri Sep 15 00:52:12 AEST 1989


Here's a small C program that will produce interesting ".plan" files.
It's not mine, so you'll have to thank the authors.
      Roger Murray (ucla-an!remsit!rem at ee.ucla.edu) and
      Marc Kriguer (kriguer at ernie.berkeley.edu)

#! /bin/sh
# This is a shell archive.  Remove anything before this line,
# then unwrap it by saving it in a file and typing "sh file".
#
# Wrapped by swh at hpmxo01 on Thu Sep 14 07:47:50 1989
# Contents:
#	dotplan.1 	dotplan.c 	

PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:$PATH; export PATH
echo 'At the end, you should see the message "End of shell archive."'

if test -f dotplan.1
then	echo OK to overwrite dotplan.1\?; read answer
	case "$answer" in
	[yY]*)	: ok;;
	*)	echo Quitting.; exit 1;;
	esac
	rm dotplan.1 || echo ! dotplan.1 is here to stay.
fi

echo Extracting dotplan.1
sed 's/^@//' >dotplan.1 <<'@//E*O*F dotplan.1//'
@.TH DOTPLAN 1
@.SH NAME
dotplan \- Generate interesting .plan files
@.SH SYNOPSIS
@.B dotplan
[
@.I style
| s | d ]
@.I text
@.SH DESCRIPTION
@.I dotplan
takes the supplied text (optionally between quotes to reduce the possibility
of conflict with a shell metacharater) and displays it in one of many ways.
The results can be redirected (via '>') to the user's
@.I .plan
file.
@.PP
The meanings of the options are:
@.TP 6
@.B style
tells
@.I dotplan
to display the given text in one of its many styles.
@.TP 6
@.B s
displays the list of styles, using each style on its description.  It's
nice to be able to compare various styles and it helps when the user
can't think of anything to display.
@.TP 6
@.B d
displays the given text in all styles, one at a time.
@.SH EXAMPLES
@.nf
dotplan 3 This is sample text # Display string using style 3
dotplan                       # Display usage information
dotplan s                     # Display styles in all styles
dotplay d This is more text   # Display string in all styles
@.fi
@.SH AUTHORS
@.nf
Roger Murray <rem at remsit.UUCP>
Marc Kriguer <kriguer at ernie.bekeley.edu>
@.fi
@.SH DIAGNOSTICS
"Huh? (bad style number)" means the user has tried to select a style that
doesn't exist.  "Huh? (bad letter)" means the user has chosen an option
that doesn't exist.
@.SH BUGS
The resulting
@.I .plan
files can look pretty nice.  However, people using high speed terminals
(terminals on cluster lines, Xenix consoles, etc.) won't really get the full
effect when viewing them.  I suppose there are worse things in the world.
@.SH SEE ALSO
finger(1)
rn(1)
warp(6)
@//E*O*F dotplan.1//

set `wc -lwc <dotplan.1`
if test $1 -ne 57 -o $2 -ne 273 -o $3 -ne 1572
then	echo ! dotplan.1 should have 57 lines, 273 words, and 1572 characters
	echo ! but has $1 lines, $2 words, and $3 characters
fi
chmod 644 dotplan.1

if test -f dotplan.c
then	echo OK to overwrite dotplan.c\?; read answer
	case "$answer" in
	[yY]*)	: ok;;
	*)	echo Quitting.; exit 1;;
	esac
	rm dotplan.c || echo ! dotplan.c is here to stay.
fi

echo Extracting dotplan.c
cat >dotplan.c <<'@//E*O*F dotplan.c//'
/*
 * dotplan.c - Program to generate interesting .plan files
 *
 * By Roger Murray (ucla-an!remsit!rem at ee.ucla.edu) and
 *    Marc Kriguer (kriguer at ernie.berkeley.edu)
 *
 * Last Update: Mon Oct 17 13:55:14 PDT 1988
 *
 * If you'd like to add algorithms to this program, please follow the
 * following guidelines:
 *
 * 1) Write them as functions passed a (char *) and returning an int.
 * 2) Don't use backspaces.  Some fingers translate them.
 * 3) Be careful with malloc().  Make sure strings are NULL-terminated.
 *    free() what you malloc().
 * 4) Send the function, its long name (for list[]), and an address
 *    (to give credit where credit is due) to one of us.  "Anon" is fine.
 */

#include <stdio.h>

/* REM */

int shift_right(string)
char *string;
{
   char *ptr;

   ptr = &string[strlen(string)-1];
   while(ptr >= string)
      {
         printf("%s\r", ptr);
         ptr--;
      }
   putchar('\n');
}

/* REM */

int shift_left(string)
char *string;
{
   int loop;

   for(loop = strlen(string)-1; loop >= 1; loop--)
      printf("%*s%.*s\r", loop, " ", strlen(string)-loop, string);
   printf("%s\n", string);
}

/* MDK */

int fill_right(string)
char *string;
{
   int i;

   for (i = 1; i <= strlen(string); i++)
      printf("%.*s\r", i, string);
   putchar('\n');
}

/* MDK */

int fill_left(string)
char *string;
{
   int i;

   for (i = 1; i < strlen(string) - 1; i++)
      printf("%*s%c\r", strlen(string)-i, " ", string[strlen(string)-i]);
   printf("%s\n", string);
}

/* MDK */

int ASCIIbet(string)
char *string;
{
   char *ptr;
   int i, j, flag;

   ptr = (char *) malloc(strlen(string)+1);
   sprintf(ptr, "%*s", strlen(string), " ");

   for (j = 1; j < 128; j++)
   {
      flag = 0;
      for (i = 0; i < strlen(string) ; i++)
         {
	    if (string[i] == j)
	    {
	       flag = 1;
	       ptr[i] = j;
            }
         }
      if (flag)
            printf("%s\r", ptr);
   }
   putchar('\n');
   free(ptr);
}

/* MDK */

int Robot_Attack(string)
char *string;
{
   char *ptr;
   int i, j, flag=0;

   ptr = (char *) malloc(strlen(string)+1);

   for (i = 0; i < strlen(string); i++)
   {
      ptr[i] = ' ';
      if (string[i] > flag)
	 flag = string[i];
      if (string[i] < 'a')		/* only one pass for lower case letters;
			                it took too long going from 32 to 127 */
	 ptr[i] = string[i];
   }

   ptr[strlen(string)] = '\0';

   for (j = 'a'; j <= flag; j++)
   {
      for (i = 0; i < strlen(string) ; i++)
         {
	    if (string[i] >= j)
	    {
	       ptr[i] = j;
            }
         }
      printf("%s\r", ptr);
   }
   putchar('\n');
   free(ptr);
}

/* REM */

int expand_out(string)
char *string;
{
   char *ptr;
   int loop, halfsize;

   if(strlen(string) % 2)
      {
         ptr = (char *) malloc(strlen(string)+2);
         sprintf(ptr, "%s ", string);
      }
   else
      ptr = string;
   for(loop = 1; loop <= (halfsize = strlen(ptr)/2)-1; loop++)
      printf("%*s%.*s%s%*s\r", halfsize-loop, " ", loop, ptr,
         &ptr[strlen(ptr)-1-loop], halfsize-loop, " ");
   printf("%s\n", ptr);
   if(ptr != string)
      free(ptr);
}

/* REM */

int expand_in(string)
char *string;
{
   char *ptr;
   int loop, halfsize;

   if(strlen(string) % 2)
      {
         ptr = (char *) malloc(strlen(string)+2);
         sprintf(ptr, "%s ", string);
      }
   else
      ptr = string;
   for(loop = 1; loop <= (halfsize = strlen(ptr)/2)-1; loop++)
      printf("%.*s%*s%.*s\r", loop, &ptr[halfsize-loop],
         2 * (halfsize-loop), " ", loop, &ptr[halfsize]);
   printf("%s\n", ptr);
   if(ptr != string)
      free(ptr);
}

/* MDK */

int merge_one(string)
char *string;
{
   char *ptr, *model;
   int loop, i, len=strlen(string);

   if(len % 2)
      {
         ptr = (char *) malloc(++len +1);
         sprintf(ptr, "%*s", len, " ");
         model = (char *) malloc(len +1);
         sprintf(model, "%s ", string);
      }
   else
      {
         ptr = (char *) malloc(len +1);
         sprintf(ptr, "%*s", len, " ");
         model = string;
      }

   for(loop = 0; loop < len/2; loop++)
   {
      for (i = 0; i <= loop; i++)
      {
         ptr[2*i] = model[len + 2*(i - loop -1)];
         ptr[len-1 - 2*i] = model[2*(loop - i) + 1];
      }
      printf ("%s\r", ptr); 
   }
   putchar('\n');
   free(ptr);
   if(model != string)
      free(model);
}

/* REM */

int bounce_right(string)
char *string;
{
   char *ptr, *backward;
   int loop, len = strlen(string);

   backward = (char *) malloc(len+1);
   for(loop = 0; loop < len; loop++)
      backward[len-1-loop] = string[loop];
   backward[len] = '\0';
   ptr = &backward[len-1];
   while(ptr >= backward)
      {
         printf("%s\r", ptr);
         ptr--;
      }
   ptr = (char *) malloc(len+1);
   for(loop = 1; loop < len; loop++)
      {
         sprintf(ptr, "%*s%.*s", loop, " ", len-loop, backward);
         sprintf(&ptr[len-loop], "%.*s", loop, string);
         printf("%s\r", ptr);
      }
   printf("%s\n", string);
   free(ptr);
   free(backward);
}

/* REM */

int bounce_left(string)
char *string;
{
   char *ptr, *backward, *from, *to;
   int loop, len = strlen(string);

   backward = (char *) malloc(len+1);
   for(loop = 0; loop < len; loop++)
      backward[len-1-loop] = string[loop];
   backward[len] = '\0';
   for(loop = len-1; loop >= 1; loop--)
      printf("%*s%.*s\r", loop, " ", len-loop, backward);
   printf("%s\r", backward);
   ptr = (char *) malloc(len+1);
   for(loop = 1; loop < len; loop++)
      {
         sprintf(ptr, "%s%*s", &backward[loop], loop, " ");
         from = &string[len-loop];
         to = ptr;
         while(*from != '\0')
            *to++ = *from++;
         printf("%s\r", ptr);
      }
   printf("%s\n", string);
   free(ptr);
   free(backward);
}

/* MDK */

#define swap(A,B)  temp = (A); (A) = (B); (B) = temp

int bubble(string)
char *string;
{
   char *ptr;
   int   i, j, temp, 
         swaps = 0,
         len = strlen(string),
         *indices = (int *) malloc(len * sizeof(int));

   ptr = (char *) malloc(len + 1);
   strcpy (ptr, string);

   for (i = 0; i < len; i++)
      indices[i] = i;

   for (i = 0; i <= len-2; i++)			/* first, bubble sort the */
      for (j = i+1; j <= len-1; j++)		/* string, to create an   */
	 if (ptr[i] > ptr[j])			/* array of indices that  */
	 {					/* correspond to our	  */
            swap(ptr[i], ptr[j]);		/* characters. */
	    swap(indices[i], indices[j]);
         }

   for (i = 0; i <= len-2; i++)			/* Now, bubble sort the   */
      for (j = i+1; j <= len-1; j++)		/* numbers back into      */
	 if (indices[i] > indices[j])		/* place to "unsort" the  */	
	 {					/* sorted letters into    */
	    printf ("%s\r", ptr);		/* out desired string.    */
            swap(ptr[i], ptr[j]);
	    swap(indices[i], indices[j]);
         }

   puts(ptr);
   free(ptr);
   free(indices);
}

/* REM */

int insert(string)
char *string;
{
   char *ptr, *load;
   int len = strlen(string),
       loop, *iptr, min = 255, max = 0,
       *pos = (int *) malloc(len * sizeof(int));

   ptr = (char *) malloc(len+1);
   for(loop = 0; loop < len; loop++)
      {
         pos[loop] = 0;
         if(string[loop] < min)
            min = string[loop];
         else
            if(string[loop] > max)
               max = string[loop];
      }
   for(; min <= max; min++)
      {
         for(loop = 0; loop < len; loop++)
            if(string[loop] == min)
               {
                  pos[loop] = 1;
                  load = ptr;
                  iptr = pos;
           
       while(iptr <= &pos[len-1])
                     if (*iptr++)
                        *load++ = string[(iptr-1)-pos];
                  *load = '\0';
                  printf("%s\r", ptr);
               }
      }
   putchar('\n');
   free(ptr);
   free(pos);
}

typedef struct array_elem {
   char *name;
   int (*function)();
};

/*
 * Nick:    Address:
 * REM      ucla-an!remsit!rem at ee.ucla.edu
 * MDK      kriguer at ernie.berkeley.edu
 */

struct array_elem list[] = {

{ "Shift text to right", shift_right },     /* REM */
{ "Shift text to left", shift_left},        /* REM */
{ "Fill text to right", fill_right },       /* MDK */
{ "Fill text to left", fill_left },         /* MDK */
{ "Expand text outward", expand_out },      /* REM */
{ "Expand text inward", expand_in },        /* REM */
{ "Bounce text on right", bounce_right },   /* REM */
{ "Bounce text on left", bounce_left },     /* REM */
{ "Merge text inward", merge_one },         /* MDK */
{ "Un-Bubble Sort text", bubble },          /* MDK */
{ "Insertion Sort text", insert },          /* REM */
{ "Fill text ASCIIbetically", ASCIIbet },   /* MDK */
{ "Robot Attack technique", Robot_Attack }, /* MDK */

};

#define LISTSIZE sizeof(list) / sizeof(struct array_elem)

char *author[2] = { "Roger Murray (ucla-an!remsit!rem at ee.ucla.edu)",
                    "Marc Kriguer (kriguer at ernie.berkeley.edu)", };

main(argc, argv)
int argc;
char *argv[];
{
   int loop, style, arglen;
   char temp_string[80];
   char *textptr;

   if(argc < 3 && !(argc == 2 && argv[1][0] == 's'))
      {
         printf("Usage: %s [style|s|d] \"Text to display\"\n\n", argv[0]);
         printf("Styles:\n");
         for(loop = 0; loop < LISTSIZE; loop++)
            printf("   %2d. %s\n", loop+1, list[loop].name);
         printf("\ns = help with styles  :-)\n");
         printf("d = display in all styles\n");
         printf("\nBy: %s and\n    %s\n", author[getpid() % 2],
            author[!(getpid() % 2)]);
         exit(0);
      }
   if((style = atoi(argv[1])) == 0)
      switch(argv[1][0])
         {
            case 's': printf("Styles:\n");
                      for(loop = 0; loop < LISTSIZE; loop++)
                         {
                            sprintf(temp_string, "   %2d. %s", loop+1, list[loop].name);
                            (void) (*list[loop].function)(temp_string);
                         }
                      break;
            case 'd': arglen = 0;
                      for(loop = 2; loop < argc; loop++)
                         arglen += strlen(argv[loop]) + 1;
                      textptr = (char *) malloc(arglen);
                      *textptr = '\0';
                      for(loop = 2; loop < argc; loop++)
                         {
                            strcat(textptr, argv[loop]);
                            if(loop != argc-1)
                               strcat(textptr, " ");
                         }
                      for(loop = 0; loop < LISTSIZE; loop++)
                         (void) (*list[loop].function)(textptr);
                      break;
            default: printf("Huh? (bad letter)\n");
                     break;
         }
   else
      if(style >= 1 && style <= LISTSIZE+1)
         {
            arglen = 0;
            for(loop = 2; loop < argc; loop++)
               arglen += strlen(argv[loop]) + 1;
            textptr = (char *) malloc(arglen);
            *textptr = '\0';
            for(loop = 2; loop < argc; loop++)
               {
                  strcat(textptr, argv[loop]);
                  if(loop != argc-1)
                     strcat(textptr, " ");
               }
            (void) (*list[style-1].function)(textptr);
         }
      else
         printf("Huh? (bad style number)\n");
}
@//E*O*F dotplan.c//

set `wc -lwc <dotplan.c`
if test $1 -ne 463 -o $2 -ne 1430 -o $3 -ne 11316
then	echo ! dotplan.c should have 463 lines, 1430 words, and 11316 characters
	echo ! but has $1 lines, $2 words, and $3 characters
fi
chmod 644 dotplan.c

echo "End of shell archive."
exit 0



More information about the Alt.sources mailing list