home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
txtutl
/
travesty.arc
/
TRAV.C
< prev
next >
Wrap
Text File
|
1988-11-17
|
2KB
|
79 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define BUFSIZE 32768
#define MAXORDER 16
#define MAXCANDS 256
char *buf;
unsigned int bs;
int order,linelen;
char lastout[MAXORDER];
char cands[MAXCANDS],outtahere;
unsigned int readbuf()
{ char temp[256];
int i;
buf = (char *) malloc(BUFSIZE);
strcpy(buf,"");
while (!feof(stdin)) {
scanf("%[^\n]\n",temp);
strcat(buf,strcat(temp," "));
}
return(strlen(buf));
}
findcands()
{ char *pp; int i;
strcpy(cands,"");
pp = buf;
while ((pp = strstr(pp,lastout))!=NULL)
{ i = strlen(cands);
cands[i] = *(pp+order); cands[++i] = '\0';
pp++;
}
}
restart()
{
strncpy(lastout,buf,order);
linelen = order;
printf("\n%s",lastout);
}
main(int argc, char *argv[])
{
randomize();
if (argc<1 || (!(order = atoi(argv[1]))))
{ puts("USAGE: TRAV <order> where <order> is an integer 2-16.");
puts(" Appreciative users are asked to send the implementer (Tony)");
puts(" a postcard. Address: 270 Highland Ave #23");
puts(" Somerville, MA 02143.");
puts(" Copyright 1988 Tony Lovell");
exit(1); }
bs = readbuf();
restart();
while (kbhit()) getch();
while (!kbhit()) {
findcands();
if (cands[0] == '\0')
{ restart(); findcands(); }
outtahere = cands[random(strlen(cands))];
putchar(outtahere);
lastout[order] = outtahere;
lastout[order+1] = '\0';
movmem(lastout+1,lastout,order+1);
linelen++;
if (linelen > 55 && isspace(outtahere))
{ puts(""); linelen = 0; }
}
}