[comp.sources.misc] v05i032: dotplan - Program to generate interesting .plan files

rem@remsit.UUCP (Roger Murray) (11/07/88)

Posting-number: Volume 5, Issue 32
Submitted-by: "Roger Murray" <rem@remsit.UUCP>
Archive-name: dotplan

[It works and seems to contain no system dependencies.  Except that it uses
a few long identifiers (expand_* and bounce_*).  ++bsa]

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#	Run the following text with /bin/sh to create:
#	Makefile
#	dotplan.1
#	dotplan.c
# This archive created: Fri Oct 28 22:42:37 1988
# By:	Roger Murray (REM's IT)
echo shar: extracting Makefile
sed 's/^XX//' << \SHAR_EOF > Makefile
XXBINDIR = /usr/local/bin
XX
XXdotplan: dotplan.c
XX	cc -s -o dotplan dotplan.c
XX
XXinstall: dotplan
XX	mv dotplan $(BINDIR)
SHAR_EOF
if test 112 -ne "`wc -c Makefile`"
then
echo shar: error transmitting Makefile '(should have been 112 characters)'
fi
echo shar: extracting dotplan.1
sed 's/^XX//' << \SHAR_EOF > dotplan.1
XX.TH DOTPLAN 1
XX.SH NAME
XXdotplan \- Generate interesting .plan files
XX.SH SYNOPSIS
XX.B dotplan
XX[
XX.I style
XX| s | d ]
XX.I text
XX.SH DESCRIPTION
XX.I dotplan
XXtakes the supplied text (optionally between quotes to reduce the possibility
XXof conflict with a shell metacharater) and displays it in one of many ways.
XXThe results can be redirected (via '>') to the user's
XX.I .plan
XXfile.
XX.PP
XXThe meanings of the options are:
XX.TP 6
XX.B style
XXtells
XX.I dotplan
XXto display the given text in one of its many styles.
XX.TP 6
XX.B s
XXdisplays the list of styles, using each style on its description.  It's
XXnice to be able to compare various styles and it helps when the user
XXcan't think of anything to display.
XX.TP 6
XX.B d
XXdisplays the given text in all styles, one at a time.
XX.SH EXAMPLES
XX.nf
XXdotplan 3 This is sample text # Display string using style 3
XXdotplan                       # Display usage information
XXdotplan s                     # Display styles in all styles
XXdotplay d This is more text   # Display string in all styles
XX.fi
XX.SH AUTHORS
XX.nf
XXRoger Murray <rem@remsit.UUCP>
XXMarc Kriguer <kriguer@ernie.bekeley.edu>
XX.fi
XX.SH DIAGNOSTICS
XX"Huh? (bad style number)" means the user has tried to select a style that
XXdoesn't exist.  "Huh? (bad letter)" means the user has chosen an option
XXthat doesn't exist.
XX.SH BUGS
XXThe resulting
XX.I .plan
XXfiles can look pretty nice.  However, people using high speed terminals
XX(terminals on cluster lines, Xenix consoles, etc.) won't really get the full
XXeffect when viewing them.  I suppose there are worse things in the world.
XX.SH SEE ALSO
XXfinger(1)
XXrn(1)
XXwarp(6)
SHAR_EOF
if test 1572 -ne "`wc -c dotplan.1`"
then
echo shar: error transmitting dotplan.1 '(should have been 1572 characters)'
fi
echo shar: extracting dotplan.c
sed 's/^XX//' << \SHAR_EOF > dotplan.c
XX/*
XX * dotplan.c - Program to generate interesting .plan files
XX *
XX * By Roger Murray (ucla-an!remsit!rem@ee.ucla.edu) and
XX *    Marc Kriguer (kriguer@ernie.berkeley.edu)
XX *
XX * Last Update: Mon Oct 17 13:55:14 PDT 1988
XX *
XX * If you'd like to add algorithms to this program, please follow the
XX * following guidelines:
XX *
XX * 1) Write them as functions passed a (char *) and returning an int.
XX * 2) Don't use backspaces.  Some fingers translate them.
XX * 3) Be careful with malloc().  Make sure strings are NULL-terminated.
XX *    free() what you malloc().
XX * 4) Send the function, its long name (for list[]), and an address
XX *    (to give credit where credit is due) to one of us.  "Anon" is fine.
XX */
XX
XX#include <stdio.h>
XX
XX/* REM */
XX
XXint shift_right(string)
XXchar *string;
XX{
XX   char *ptr;
XX
XX   ptr = &string[strlen(string)-1];
XX   while(ptr >= string)
XX      {
XX         printf("%s\r", ptr);
XX         ptr--;
XX      }
XX   putchar('\n');
XX}
XX
XX/* REM */
XX
XXint shift_left(string)
XXchar *string;
XX{
XX   int loop;
XX
XX   for(loop = strlen(string)-1; loop >= 1; loop--)
XX      printf("%*s%.*s\r", loop, " ", strlen(string)-loop, string);
XX   printf("%s\n", string);
XX}
XX
XX/* MDK */
XX
XXint fill_right(string)
XXchar *string;
XX{
XX   int i;
XX
XX   for (i = 1; i <= strlen(string); i++)
XX      printf("%.*s\r", i, string);
XX   putchar('\n');
XX}
XX
XX/* MDK */
XX
XXint fill_left(string)
XXchar *string;
XX{
XX   int i;
XX
XX   for (i = 1; i < strlen(string) - 1; i++)
XX      printf("%*s%c\r", strlen(string)-i, " ", string[strlen(string)-i]);
XX   printf("%s\n", string);
XX}
XX
XX/* MDK */
XX
XXint ASCIIbet(string)
XXchar *string;
XX{
XX   char *ptr;
XX   int i, j, flag;
XX
XX   ptr = (char *) malloc(strlen(string)+1);
XX   sprintf(ptr, "%*s", strlen(string), " ");
XX
XX   for (j = 1; j < 128; j++)
XX   {
XX      flag = 0;
XX      for (i = 0; i < strlen(string) ; i++)
XX         {
XX	    if (string[i] == j)
XX	    {
XX	       flag = 1;
XX	       ptr[i] = j;
XX            }
XX         }
XX      if (flag)
XX            printf("%s\r", ptr);
XX   }
XX   putchar('\n');
XX   free(ptr);
XX}
XX
XX/* MDK */
XX
XXint Robot_Attack(string)
XXchar *string;
XX{
XX   char *ptr;
XX   int i, j, flag=0;
XX
XX   ptr = (char *) malloc(strlen(string)+1);
XX
XX   for (i = 0; i < strlen(string); i++)
XX   {
XX      ptr[i] = ' ';
XX      if (string[i] > flag)
XX	 flag = string[i];
XX      if (string[i] < 'a')		/* only one pass for lower case letters;
XX			                it took too long going from 32 to 127 */
XX	 ptr[i] = string[i];
XX   }
XX
XX   ptr[strlen(string)] = '\0';
XX
XX   for (j = 'a'; j <= flag; j++)
XX   {
XX      for (i = 0; i < strlen(string) ; i++)
XX         {
XX	    if (string[i] >= j)
XX	    {
XX	       ptr[i] = j;
XX            }
XX         }
XX      printf("%s\r", ptr);
XX   }
XX   putchar('\n');
XX   free(ptr);
XX}
XX
XX/* REM */
XX
XXint expand_out(string)
XXchar *string;
XX{
XX   char *ptr;
XX   int loop, halfsize;
XX
XX   if(strlen(string) % 2)
XX      {
XX         ptr = (char *) malloc(strlen(string)+2);
XX         sprintf(ptr, "%s ", string);
XX      }
XX   else
XX      ptr = string;
XX   for(loop = 1; loop <= (halfsize = strlen(ptr)/2)-1; loop++)
XX      printf("%*s%.*s%s%*s\r", halfsize-loop, " ", loop, ptr,
XX         &ptr[strlen(ptr)-1-loop], halfsize-loop, " ");
XX   printf("%s\n", ptr);
XX   if(ptr != string)
XX      free(ptr);
XX}
XX
XX/* REM */
XX
XXint expand_in(string)
XXchar *string;
XX{
XX   char *ptr;
XX   int loop, halfsize;
XX
XX   if(strlen(string) % 2)
XX      {
XX         ptr = (char *) malloc(strlen(string)+2);
XX         sprintf(ptr, "%s ", string);
XX      }
XX   else
XX      ptr = string;
XX   for(loop = 1; loop <= (halfsize = strlen(ptr)/2)-1; loop++)
XX      printf("%.*s%*s%.*s\r", loop, &ptr[halfsize-loop],
XX         2 * (halfsize-loop), " ", loop, &ptr[halfsize]);
XX   printf("%s\n", ptr);
XX   if(ptr != string)
XX      free(ptr);
XX}
XX
XX/* MDK */
XX
XXint merge_one(string)
XXchar *string;
XX{
XX   char *ptr, *model;
XX   int loop, i, len=strlen(string);
XX
XX   if(len % 2)
XX      {
XX         ptr = (char *) malloc(++len +1);
XX         sprintf(ptr, "%*s", len, " ");
XX         model = (char *) malloc(len +1);
XX         sprintf(model, "%s ", string);
XX      }
XX   else
XX      {
XX         ptr = (char *) malloc(len +1);
XX         sprintf(ptr, "%*s", len, " ");
XX         model = string;
XX      }
XX
XX   for(loop = 0; loop < len/2; loop++)
XX   {
XX      for (i = 0; i <= loop; i++)
XX      {
XX         ptr[2*i] = model[len + 2*(i - loop -1)];
XX         ptr[len-1 - 2*i] = model[2*(loop - i) + 1];
XX      }
XX      printf ("%s\r", ptr); 
XX   }
XX   putchar('\n');
XX   free(ptr);
XX   if(model != string)
XX      free(model);
XX}
XX
XX/* REM */
XX
XXint bounce_right(string)
XXchar *string;
XX{
XX   char *ptr, *backward;
XX   int loop, len = strlen(string);
XX
XX   backward = (char *) malloc(len+1);
XX   for(loop = 0; loop < len; loop++)
XX      backward[len-1-loop] = string[loop];
XX   backward[len] = '\0';
XX   ptr = &backward[len-1];
XX   while(ptr >= backward)
XX      {
XX         printf("%s\r", ptr);
XX         ptr--;
XX      }
XX   ptr = (char *) malloc(len+1);
XX   for(loop = 1; loop < len; loop++)
XX      {
XX         sprintf(ptr, "%*s%.*s", loop, " ", len-loop, backward);
XX         sprintf(&ptr[len-loop], "%.*s", loop, string);
XX         printf("%s\r", ptr);
XX      }
XX   printf("%s\n", string);
XX   free(ptr);
XX   free(backward);
XX}
XX
XX/* REM */
XX
XXint bounce_left(string)
XXchar *string;
XX{
XX   char *ptr, *backward, *from, *to;
XX   int loop, len = strlen(string);
XX
XX   backward = (char *) malloc(len+1);
XX   for(loop = 0; loop < len; loop++)
XX      backward[len-1-loop] = string[loop];
XX   backward[len] = '\0';
XX   for(loop = len-1; loop >= 1; loop--)
XX      printf("%*s%.*s\r", loop, " ", len-loop, backward);
XX   printf("%s\r", backward);
XX   ptr = (char *) malloc(len+1);
XX   for(loop = 1; loop < len; loop++)
XX      {
XX         sprintf(ptr, "%s%*s", &backward[loop], loop, " ");
XX         from = &string[len-loop];
XX         to = ptr;
XX         while(*from != '\0')
XX            *to++ = *from++;
XX         printf("%s\r", ptr);
XX      }
XX   printf("%s\n", string);
XX   free(ptr);
XX   free(backward);
XX}
XX
XX/* MDK */
XX
XX#define swap(A,B)  temp = (A); (A) = (B); (B) = temp
XX
XXint bubble(string)
XXchar *string;
XX{
XX   char *ptr;
XX   int   i, j, temp, 
XX         swaps = 0,
XX         len = strlen(string),
XX         *indices = (int *) malloc(len * sizeof(int));
XX
XX   ptr = (char *) malloc(len + 1);
XX   strcpy (ptr, string);
XX
XX   for (i = 0; i < len; i++)
XX      indices[i] = i;
XX
XX   for (i = 0; i <= len-2; i++)			/* first, bubble sort the */
XX      for (j = i+1; j <= len-1; j++)		/* string, to create an   */
XX	 if (ptr[i] > ptr[j])			/* array of indices that  */
XX	 {					/* correspond to our	  */
XX            swap(ptr[i], ptr[j]);		/* characters. */
XX	    swap(indices[i], indices[j]);
XX         }
XX
XX   for (i = 0; i <= len-2; i++)			/* Now, bubble sort the   */
XX      for (j = i+1; j <= len-1; j++)		/* numbers back into      */
XX	 if (indices[i] > indices[j])		/* place to "unsort" the  */	
XX	 {					/* sorted letters into    */
XX	    printf ("%s\r", ptr);		/* out desired string.    */
XX            swap(ptr[i], ptr[j]);
XX	    swap(indices[i], indices[j]);
XX         }
XX
XX   puts(ptr);
XX   free(ptr);
XX   free(indices);
XX}
XX
XX/* REM */
XX
XXint insert(string)
XXchar *string;
XX{
XX   char *ptr, *load;
XX   int len = strlen(string),
XX       loop, *iptr, min = 255, max = 0,
XX       *pos = (int *) malloc(len * sizeof(int));
XX
XX   ptr = (char *) malloc(len+1);
XX   for(loop = 0; loop < len; loop++)
XX      {
XX         pos[loop] = 0;
XX         if(string[loop] < min)
XX            min = string[loop];
XX         else
XX            if(string[loop] > max)
XX               max = string[loop];
XX      }
XX   for(; min <= max; min++)
XX      {
XX         for(loop = 0; loop < len; loop++)
XX            if(string[loop] == min)
XX               {
XX                  pos[loop] = 1;
XX                  load = ptr;
XX                  iptr = pos;
XX                  while(iptr <= &pos[len-1])
XX                     if (*iptr++)
XX                        *load++ = string[(iptr-1)-pos];
XX                  *load = '\0';
XX                  printf("%s\r", ptr);
XX               }
XX      }
XX   putchar('\n');
XX   free(ptr);
XX   free(pos);
XX}
XX
XXtypedef struct array_elem {
XX   char *name;
XX   int (*function)();
XX};
XX
XX/*
XX * Nick:    Address:
XX * REM      ucla-an!remsit!rem@ee.ucla.edu
XX * MDK      kriguer@ernie.berkeley.edu
XX */
XX
XXstruct array_elem list[] = {
XX
XX{ "Shift text to right", shift_right },     /* REM */
XX{ "Shift text to left", shift_left},        /* REM */
XX{ "Fill text to right", fill_right },       /* MDK */
XX{ "Fill text to left", fill_left },         /* MDK */
XX{ "Expand text outward", expand_out },      /* REM */
XX{ "Expand text inward", expand_in },        /* REM */
XX{ "Bounce text on right", bounce_right },   /* REM */
XX{ "Bounce text on left", bounce_left },     /* REM */
XX{ "Merge text inward", merge_one },         /* MDK */
XX{ "Un-Bubble Sort text", bubble },          /* MDK */
XX{ "Insertion Sort text", insert },          /* REM */
XX{ "Fill text ASCIIbetically", ASCIIbet },   /* MDK */
XX{ "Robot Attack technique", Robot_Attack }, /* MDK */
XX
XX};
XX
XX#define LISTSIZE sizeof(list) / sizeof(struct array_elem)
XX
XXchar *author[2] = { "Roger Murray (ucla-an!remsit!rem@ee.ucla.edu)",
XX                    "Marc Kriguer (kriguer@ernie.berkeley.edu)", };
XX
XXmain(argc, argv)
XXint argc;
XXchar *argv[];
XX{
XX   int loop, style, arglen;
XX   char temp_string[80];
XX   char *textptr;
XX
XX   if(argc < 3 && !(argc == 2 && argv[1][0] == 's'))
XX      {
XX         printf("Usage: %s [style|s|d] \"Text to display\"\n\n", argv[0]);
XX         printf("Styles:\n");
XX         for(loop = 0; loop < LISTSIZE; loop++)
XX            printf("   %2d. %s\n", loop+1, list[loop].name);
XX         printf("\ns = help with styles  :-)\n");
XX         printf("d = display in all styles\n");
XX         printf("\nBy: %s and\n    %s\n", author[getpid() % 2],
XX            author[!(getpid() % 2)]);
XX         exit(0);
XX      }
XX   if((style = atoi(argv[1])) == 0)
XX      switch(argv[1][0])
XX         {
XX            case 's': printf("Styles:\n");
XX                      for(loop = 0; loop < LISTSIZE; loop++)
XX                         {
XX                            sprintf(temp_string, "   %2d. %s", loop+1, list[loop].name);
XX                            (void) (*list[loop].function)(temp_string);
XX                         }
XX                      break;
XX            case 'd': arglen = 0;
XX                      for(loop = 2; loop < argc; loop++)
XX                         arglen += strlen(argv[loop]) + 1;
XX                      textptr = (char *) malloc(arglen);
XX                      *textptr = '\0';
XX                      for(loop = 2; loop < argc; loop++)
XX                         {
XX                            strcat(textptr, argv[loop]);
XX                            if(loop != argc-1)
XX                               strcat(textptr, " ");
XX                         }
XX                      for(loop = 0; loop < LISTSIZE; loop++)
XX                         (void) (*list[loop].function)(textptr);
XX                      break;
XX            default: printf("Huh? (bad letter)\n");
XX                     break;
XX         }
XX   else
XX      if(style >= 1 && style <= LISTSIZE+1)
XX         {
XX            arglen = 0;
XX            for(loop = 2; loop < argc; loop++)
XX               arglen += strlen(argv[loop]) + 1;
XX            textptr = (char *) malloc(arglen);
XX            *textptr = '\0';
XX            for(loop = 2; loop < argc; loop++)
XX               {
XX                  strcat(textptr, argv[loop]);
XX                  if(loop != argc-1)
XX                     strcat(textptr, " ");
XX               }
XX            (void) (*list[style-1].function)(textptr);
XX         }
XX      else
XX         printf("Huh? (bad style number)\n");
XX}
SHAR_EOF
if test 11316 -ne "`wc -c dotplan.c`"
then
echo shar: error transmitting dotplan.c '(should have been 11316 characters)'
fi
#	End of shell archive
exit 0
-- 
Roger Murray
"Look ma!  No ihnp4!"  :-)
UUCP: ...!{randvax,sdcrdcf,ucbvax}!ucla-cs!cepu!ucla-an!remsit!rem
ARPA: cepu!ucla-an!remsit!rem@CS.UCLA.EDU