home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / txtutl / travesty.arc / TRAV.C < prev    next >
Text File  |  1988-11-17  |  2KB  |  79 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. #define BUFSIZE 32768
  7. #define MAXORDER 16
  8. #define MAXCANDS 256
  9.  
  10. char *buf;
  11. unsigned int bs;
  12. int order,linelen;
  13. char lastout[MAXORDER];
  14. char cands[MAXCANDS],outtahere;
  15.  
  16. unsigned int readbuf()
  17. {   char temp[256];
  18.     int i;
  19.  
  20.     buf = (char *) malloc(BUFSIZE);
  21.     strcpy(buf,"");
  22.     while (!feof(stdin)) {
  23.        scanf("%[^\n]\n",temp);
  24.        strcat(buf,strcat(temp," "));
  25.        }
  26.     return(strlen(buf));
  27. }
  28.  
  29. findcands()
  30. { char *pp; int i;
  31.  
  32.   strcpy(cands,"");
  33.   pp = buf;
  34.   while ((pp = strstr(pp,lastout))!=NULL)
  35.      { i = strlen(cands);
  36.        cands[i] = *(pp+order); cands[++i] = '\0';
  37.        pp++;
  38.        }
  39. }
  40.  
  41. restart()
  42. {
  43.   strncpy(lastout,buf,order);
  44.   linelen = order;
  45.   printf("\n%s",lastout);
  46. }
  47.  
  48.  
  49. main(int argc, char *argv[])
  50. {
  51.   randomize();
  52.  
  53.   if (argc<1 || (!(order = atoi(argv[1]))))
  54.      { puts("USAGE:  TRAV <order>   where <order> is an integer 2-16.");
  55.        puts("      Appreciative users are asked to send the implementer (Tony)");
  56.        puts("       a postcard.  Address:  270 Highland Ave #23");
  57.        puts("                              Somerville, MA 02143.");
  58.        puts("      Copyright 1988 Tony Lovell");
  59.        exit(1); }
  60.  
  61.   bs = readbuf();
  62.  
  63.   restart();
  64.   while (kbhit()) getch();
  65.   while (!kbhit()) {
  66.      findcands();
  67.      if (cands[0] == '\0')
  68.        { restart(); findcands(); }
  69.      outtahere = cands[random(strlen(cands))];
  70.      putchar(outtahere);
  71.      lastout[order] = outtahere;
  72.      lastout[order+1] = '\0';
  73.      movmem(lastout+1,lastout,order+1);
  74.  
  75.      linelen++;
  76.      if (linelen > 55 && isspace(outtahere))
  77.        { puts(""); linelen = 0; }
  78.      }
  79. }