Plan'

Kevin Carothers kevin at ttidca.TTI.COM
Sat Sep 16 02:58:39 AEST 1989


In article <151 at ra.abo.fi> rosenber at ra.abo.fi (Robin Rosenberg INF) writes:
>A .plan file is created with a text editor that allows you to insert terminal
>control codes. There was a time two-three years ago here when everybody tried
>to have the most advanced plan file. There was everything from simple scrolling
>text to redefinition of character sets with smooth scroll. I think almost 
 [---]
>  For the one that asked: .plan files are used on VMS and UNIX systems. 
>Typically they contain the user's address, telephone numbers and other 
>information the user want to make available to other. I.e your not suppose
>to have animations and such garbage in it. Typically you get at the plan file
>with a command like FINGER username.
 [---]

 There seems to be quite a plethora of postings about .plans. Since enough
 interest seems to be out there, I am posting the "dotplan.c" program that
 was plunked into alt.s  over a year ago.

BTW
 Pardons if this is taking up too much bandwidth, but IMHO the time seems
 to be ripe for re-posting this.


---------C  U  T-----H  E  R  E-----------------------------------------
# This is a shell archive.  Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file".  (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# dotplan.c

echo x - 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//

exit 0



More information about the Alt.sources mailing list