bogatko@lzga.ATT.COM (George Bogatko) (08/01/90)
HI: This code is eons old, but I saw a couple of text generation joke programs lately, and thought I'd put it on the net again. It generates bogus tax statements. usage: taxlaw [number of sentences] GB ******* CUT HERE ******* CUT HERE ******* CUT HERE ******* CUT HERE ****** #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # tax # This archive created: Tue Jul 31 13:59:46 1990 export PATH; PATH=/bin:/usr/bin:$PATH if test ! -d 'tax' then echo shar: "creating directory 'tax'" mkdir 'tax' fi echo shar: "entering directory 'tax'" cd 'tax' echo shar: "extracting 'index.c'" '(834 characters)' if test -f 'index.c' then echo shar: "will not over-write existing file 'index.c'" else sed 's/^ X//' << \SHAR_EOF > 'index.c' X/*************************************************************************** XNAME: index.c X XPURPOSE: return the position of the token in a string X K&R, converted to use pointers X****************************************************************************/ X#include <stdio.h> X Xchar *index(source, token) Xchar *source, *token; X{ Xchar *ptsource, *pttoken, *ptmatch; X X for(ptsource = source; *ptsource != '\0'; ptsource++) X { X for(ptmatch = ptsource, pttoken = token; X X *pttoken != '\0' && X *ptmatch == *pttoken; X X ptmatch++, pttoken++) X X ; X X if(*pttoken == '\0') X return ptsource; X } X return (char *)NULL; X} SHAR_EOF if test 834 -ne "`wc -c < 'index.c'`" then echo shar: "error transmitting 'index.c'" '(should have been 834 characters)' fi chmod +x 'index.c' fi echo shar: "extracting 'makefile'" '(107 characters)' if test -f 'makefile' then echo shar: "will not over-write existing file 'makefile'" else sed 's/^ X//' << \SHAR_EOF > 'makefile' XCFLAGS=-I. X XOBJS=\ Xtaxmain.o \ Xtaxlaw.o \ Xindex.o \ Xwrap.o \ Xrnd.o X X Xtaxlaw: $(OBJS) X cc -o taxlaw $(OBJS) SHAR_EOF if test 107 -ne "`wc -c < 'makefile'`" then echo shar: "error transmitting 'makefile'" '(should have been 107 characters)' fi chmod +x 'makefile' fi echo shar: "extracting 'rnd.c'" '(279 characters)' if test -f 'rnd.c' then echo shar: "will not over-write existing file 'rnd.c'" else sed 's/^ X//' << \SHAR_EOF > 'rnd.c' X/************************************************************************* XFUNCTION: RND X XPURPOSE: return a random number less than n X***************************************************************************/ Xrnd(n) Xint n; X{ X return(((rand() & 0x7FFF) % n)); X} SHAR_EOF if test 279 -ne "`wc -c < 'rnd.c'`" then echo shar: "error transmitting 'rnd.c'" '(should have been 279 characters)' fi chmod +x 'rnd.c' fi echo shar: "extracting 'taxlaw.c'" '(9610 characters)' if test -f 'taxlaw.c' then echo shar: "will not over-write existing file 'taxlaw.c'" else sed 's/^ X//' << \SHAR_EOF > 'taxlaw.c' X#include <stdio.h> X#include <ctype.h> X#include <string.h> X Xextern long time(); Xextern char *index(); Xextern void srand(); X X#define first 1 X#define second 2 X Xchar *_article[]={ X "the ", X "a ", X "this ", X "that ", X "each " X}; X Xchar *_connect[]={ X "and ", X "if it ", X "or ", X "unless it ", X "until it ", X "before it " X}; X Xchar *_join[]= { X "while ", X "because ", X "although ", X "even though ", X "despite the fact that ", X "for the simple reason that ", X "because ", X "due to the fact that ", X "since ", X "whether or not ", X "inasmuch as ", X "as " X}; X Xchar *_pronoun[]={ X "alternate ", X "first ", X "large ", X "limited ", X "long ", X "second ", X "serious ", X "simple ", X "subsequent ", X "third ", X "unusable ", X "one-time ", X "add-back ", X "city, state or local ", X "minimum ", X "maximum ", X "qualified ", X "exempt ", X "appropriate ", X "real ", X "authorized ", X "requested ", X "nonresident " X}; X Xchar *_noun[]={ X "deduction ", X "accumulation distribution credit ", X "addition ", X "adjustment ", X "amended return ", X "amortization ", X "amount owed ", X "basis ", X "beneficiary ", X "business income ", X "deduction ", X "dependant ", X "depletion ", X "depreciation ", X "education expense ", X "estate ", X "trust ", X "estimated tax ", X "exemption ", X "family adjustment ", X "gift for wildlife ", X "house-hold credit ", X "investment credit ", X "retail enterprise credit ", X "refund ", X "lump sum distribution ", X "maximum tax on personal service income ", X "minimum income tax ", X "new business investment ", X "deferral ", X "exclusion ", X "overpayment ", X "partner ", X "payment ", X "penalty and interest ", X "pension and annuity income ", X "real property tax credit ", X "research and development credit ", X "resident credit ", X "retail enterprise credit ", X "seperate tax ", X "tuition deduction ", X "group term life insurance policy ", X "package ", X "solar and wind energy credit " X}; X Xchar *_prep[]={ X "across ", X "by ", X "in ", X "near ", X "under ", X "over ", X "in back of ", X "below ", X "behind ", X "connected with ", X "centered around ", X "centered about ", X "in close proximity to ", X "following after ", X "in between ", X "in conflict with ", X "in conjunction with ", X "in the area of ", X "in the neighborhood of ", X "in the proximity of ", X "in the field of ", X "for the purpose of ", X "giving rise to ", X "based upon ", X "being caused by ", X "being used with ", X "being collected together with ", X "being combined together with ", X "connected up to ", X "exhibiting a tendency towards ", X "being facilitated by ", X "being employed with ", X "having a deleterious effect upon ", X "impacting ", X "being joined together with ", X "being merged together with ", X "in the vicinity of ", X "above ", X "across from ", X "along ", X "among ", X "beneath ", X "between ", X "beyond ", X "by ", X "covering ", X "enclosing ", X "for ", X "from ", X "in ", X "inside ", X "inbetween ", X "joining ", X "opposite ", X "outside ", X "over ", X "under ", X "with " }; X Xchar *_adverb[]= { X "that ", X "which " X}; X Xchar *_verb[]={ X "applies ", X "collects ", X "deducts ", X "distributes ", X "enters ", X "exempts ", X "figures ", X "files ", X "has ", X "keeps ", X "refunds ", X "receives ", X "subtracts ", X "signs ", X "states ", X "with-holds ", X "multiplies ", X "adds ", X "subtracts ", X "divides ", X "pays ", X "enjoins ", X "makes ", X "obtains ", X "recovers ", X "exempts ", X "expects ", X "computes ", X "changes ", X "debits ", X "credits ", X "produces ", X "develops ", X "invents ", X "claims ", X "checks ", X "qualifies ", X "removed ", X "ends ", X "retires ", X "chooses ", X "seperates ", X "trusts ", X "invests ", X "looses ", X "buys ", X "sells " X}; X Xchar buffer[3000]; Xint _rflag = first; Xint connectflag = 0; X X Xtaxlaw() X{ X char *pb = buffer; X _taxlaw(); X *(pb + strlen(buffer)-1) = '\0'; X strcat(buffer, ".\n"); X *pb = _toupper(*pb); X wrap_puts(buffer); X _rflag = first; X connectflag = 0; X} X X_taxlaw() X{ X static int _time = first; X char *pick(); X int whichflag = 0; X char bullbuf[80]; X X if(strlen(buffer) > 2998) X { X#ifdef EBUG X printf("buffer overflow"); X#endif X return; X } X X if(_rflag == first) X { X buffer[0] = '\0'; X _rflag = second; X setbuf(stdout, NULL); X } X X if(_time == first) X { X srand( (unsigned)time( (long *)0 ) ); X _time = second; X } X X for(;;) X { X while(rnd(10) > 4) X { X strcat(buffer, pick(_article,sizeof(_article),1)); X while(rnd(3) == 1) X strcat(buffer, pick(_pronoun,sizeof(_pronoun),0)); X strcat(buffer, pick(_noun,sizeof(_noun),0)); X strcat(buffer, pick(_prep,sizeof(_prep),0)); X } X strcat(buffer, pick(_article,sizeof(_article),1)); X while(rnd(3) == 1) X strcat(buffer, pick(_pronoun,sizeof(_pronoun),0)); X strcat(buffer, pick(_noun,sizeof(_noun),0)); X if(rnd(8)==1) X { X strcat(buffer, pick(_adverb,sizeof(_adverb),1)); X whichflag = 1; X } X strcat(buffer, pick(_verb,sizeof(_verb),0)); X strcat(buffer, pick(_article,sizeof(_article),1)); X while(rnd(3) == 1) X strcat(buffer, pick(_pronoun,sizeof(_pronoun),0)); X strcat(buffer, pick(_noun,sizeof(_noun),0)); X if(rnd(10) > 4) X { X sprintf(bullbuf,"(See sect. &%d, para. %d) ",rnd(80),rnd(999)); X strcat(buffer,bullbuf); X } X X if(rnd(10) >= 7) X { X strcat(buffer,pick(_join,sizeof(_join),0)); X#ifdef EBUG X puts("beginning recursion"); X#endif X _taxlaw(); X#ifdef EBUG X puts("ending recursion"); X#endif X strcat(buffer,pick(_join,sizeof(_join),0)); X connectflag = 1; X } X else X break; X } X if(whichflag) X { X if(connectflag) X strcat(buffer, pick(_connect,sizeof(_connect),1)); X else X connectflag = 1; X strcat(buffer, pick(_verb,sizeof(_verb),0)); X strcat(buffer, pick(_article,sizeof(_article),1)); X while(rnd(3) == 1) X strcat(buffer, pick(_pronoun,sizeof(_pronoun),0)); X strcat(buffer, pick(_noun,sizeof(_noun),0)); X whichflag = 0; X } X X} X Xchar *pick(tokenbuf,size,flag) Xchar *tokenbuf[]; Xint size; Xint flag; X{ X static char inter[80]; X int j = 0; X static int a_flag = 0; X int u_flag; X int offset; X X for(;;) X { X offset = size/sizeof(char *); X strcpy(inter, tokenbuf[rnd(offset)]); X if( index(buffer,inter) == (char *)NULL) X break; X else if(flag) X break; X else if(j++ > 10) X { X#ifdef EBUG X puts("unique word overflow"); X#endif X break; X } X } X if(a_flag) X { X u_flag = 0; X switch(inter[0]) X { X case 'a': X case 'e': X case 'i': X case 'o': X u_flag = 1; X break; X case 'u': X if(inter[1] == 'n') X u_flag = 1; X break; X } X X if(u_flag) X strcpy( X (buffer + (strlen(buffer)) - strlen("a ")), X "an "); X } X if( ! (strcmp(inter,"a "))) X a_flag = 1; X else X a_flag = 0; X return(inter); X} SHAR_EOF if test 9610 -ne "`wc -c < 'taxlaw.c'`" then echo shar: "error transmitting 'taxlaw.c'" '(should have been 9610 characters)' fi fi echo shar: "extracting 'taxmain.c'" '(289 characters)' if test -f 'taxmain.c' then echo shar: "will not over-write existing file 'taxmain.c'" else sed 's/^ X//' << \SHAR_EOF > 'taxmain.c' X Xextern void exit(); X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ Xint i,j; X X if(argc < 2) X { X puts("usage: taxlaw [number of sentences]"); X exit(-1); X } X X j = atoi(argv[1]); X for(i = 0; i < j;i++) X taxlaw(); X} SHAR_EOF if test 289 -ne "`wc -c < 'taxmain.c'`" then echo shar: "error transmitting 'taxmain.c'" '(should have been 289 characters)' fi chmod +x 'taxmain.c' fi echo shar: "extracting 'wrap.c'" '(898 characters)' if test -f 'wrap.c' then echo shar: "will not over-write existing file 'wrap.c'" else sed 's/^ X//' << \SHAR_EOF > 'wrap.c' X#include <stdio.h> X/* Xmain() X{ Xchar buffer[200]; X X gets(buffer); X wrap_puts(buffer); X} X*/ X#define endcol 75 X Xwrap_puts(string) Xchar *string; X{ Xchar *ps,*psp; Xint counter; X X ps = psp = string; X counter = 0; X for(;;) X { X while( (*psp != ' ') && (*psp != '\0') ) X { X psp++; X counter++; X } X counter++; X X if(counter > endcol) X { X putchar('\n'); X ps++; X counter = 0; X } X else X counter++; X X while(ps != psp) X putchar(*ps++); X X if(*psp == '\0') X break; X X psp++; X } X putchar('\n'); X} SHAR_EOF if test 898 -ne "`wc -c < 'wrap.c'`" then echo shar: "error transmitting 'wrap.c'" '(should have been 898 characters)' fi chmod +x 'wrap.c' fi echo shar: "done with directory 'tax'" cd .. exit 0 # End of shell archive