rolf@warwick.UUCP (Rolf Howarth) (07/25/89)
Another quickie. With all the commands like `who', `where', and `what' that abound on the system, there would appear to be a major omission... ----------------------------- cut here --------------------------------------- #!/bin/csh -f # why - Rolf Howarth 27/5/87 if $#argv then echo "I don't know, why" $argv \? else if ($$ % 2 == 0) then echo "Why not?" else echo "Just because." endif ------------------------------------------------------------------------- Rolf Howarth, Tel: +44 203 523523 ext.2485 Dept. of Computer Science, Fax: 203 525714 University of Warwick, JANET: rolf@uk.ac.warwick.flame Coventry, CV4 7AL, England. UUCP: {uunet,mcvax}!ukc!warwick!rolf -------------------------------------------------------------------------
davek@lakesys.UUCP (Dave Kraft) (07/27/89)
Here's the same thing, only in C:
--cut here--
int argc;
char *argv[];
{
int w;
w = argc -1;
if(w)
printf("I don't know why %s.\n",argv[w]);
else
if((getpid() % 2) == 0)
printf("Why not?\n");
else
printf("Just because.\n");
}
--cut here--
Feel free to modify this. All I ask is that the modifier tell me via email
what he/she has modified. Flames to /dev/null.
Dave
--
davek@lakesys.lakesys.com
uunet!marque!lakesys!davek
------------------------------------------------------------------------------
Forgetting your superuser password is just God's way of saying "BOOGA, BOOGA!"
kevin@ttidca.TTI.COM (Kevin Carothers) (07/29/89)
Howdy I took dave k's "why.c" and improved it -- at least *I* like it ================================================================ main (argc, argv) int argc; char *argv[]; { int w; int i; char *p; w = argc -1; if(w) { printf("I don't know why "); for (i=1; i <= w; i++) { if(!(strcmp(argv[i], "I") && strcmp(argv[i], "i"))) { printf("you "); argv[i] = ""; } else if(!(strcmp(argv[i], "me"))) { argv[i] = "you "; if (argc >2) { p = argv[2]; argv[2] = argv[1]; argv[1] = p; } } } for (i=1; i <= w; i++) { printf("%s ", argv[i]); } } else { if((getpid() % 2) == 0) printf("Why not?"); else printf("Just because."); } printf("\n"); } == try me === -- U.S. Out of North America The Name: Kevin Carothers !{csun,psivax,rdlvax}!ttidca!kevin
rolf@warwick.UUCP (Rolf Howarth) (07/30/89)
In article <4938@ttidca.TTI.COM> kevin@ttidcb.tti.com (Kevin Carothers) writes: >Howdy > >I took dave k's "why.c" and improved it -- at least *I* like it Yes, I think Dave missed the point that why can be called with more than one argument so you need to go through the whole argv list. I like your "I/me" -> "you" translation; that was always an omission in the original version that I never got round to adding. Of course, you should also cope with abuse aimed at the computer and convert "you" to "I" or "me" as appropriate, but perhaps one should leave that as an exercise... -Rolf ------------------------------------------------------------------------- Rolf Howarth, Tel: +44 203 523523 ext.2485 Dept. of Computer Science, Fax: 203 525714 University of Warwick, JANET: rolf@uk.ac.warwick.flame Coventry, CV4 7AL, England. UUCP: {uunet,mcvax}!ukc!warwick!rolf -------------------------------------------------------------------------
allbery@nc386.UUCP (Brandon S. Allbery) (08/02/89)
: when lo=`expr $$ % 2` if [ $lo -eq 0 ]; then echo Now. else echo Never. fi exit 0 ;-) ++Brandon -- Brandon S. Allbery, moderator of comp.sources.misc allbery@NCoast.ORG uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu * This message brought to you courtesy the "Watcher" for the 4th NCoast * "ncoast #4 regenerates into ncoast #5 on 8/6/89!" -- the Watcher (aka nc386)
jonathan@jarthur.Claremont.EDU (Jonathan Ball) (08/10/89)
Here's the why.c program again, but this time with a little smarter statement to reply parser. Handles most questions well. why.c: ----------(Cute Hare)--------------(Cat Hair)--------------(Cant Hear)-------- main (argc, argv) int argc; char *argv[]; { int w; int i, r; char *p; w = argc -1; if(w) { printf("I don't know why "); if (argc >2) { if((strcmp(argv[1], "not")) && (strcmp(argv[1], "in"))) { p = argv[2]; argv[2] = argv[1]; argv[1] = p; if(!(strcmp(argv[1], "the"))) { p = argv[3]; argv[3] = argv[2]; argv[2] = p; } } } for (i=1; i <= w; i++) { if(!(strcmp(argv[i], "I") && strcmp(argv[i], "i"))) argv[i] = "you"; else if(!(strcmp(argv[i], "me"))) argv[i] = "you"; else if(!(strcmp(argv[i], "my"))) argv[i] = "your"; else if(!(strcmp(argv[i], "mine"))) argv[i] = "yours"; else if(!(strcmp(argv[i], "you"))) { argv[i] = "I"; if(!(strcmp(argv[++i], "are"))) argv[i] = "am"; } else if(!(strcmp(argv[i], "your"))) { argv[i] = "my"; p = argv[i+2]; argv[i+2] = argv[i+1]; argv[i+1] = p; } else if(!(strcmp(argv[i], "yours"))) argv[i] = "mine"; else if(!(strcmp(argv[i], "am"))) argv[i] = "are"; } for (i=1; i <= w; i++) { printf("%s ", argv[i]); } } else { if((r = (getpid() % 4)) == 0) printf("Why not?"); else if(r == 1) printf("Just because."); else if(r == 2) printf("Don't ask."); else if(r == 3) printf("Because I feel like it."); } printf("\n"); } -------(Cut Here)--------------(Cut Here)----------------(Cut Here)--------- Feel free to continue modifying this, and I would be interested in knowing about any upgrades. -- Jonathan M. Ball | A UNIX saleslady, Lenore, liked her work jonathan@jarthur.claremont.EDU | but she loved the sea more. She found a uunet!jarthur!jonathan | good way to combine work and play: jball@hmcvax.bitnet | She sells C shells at the sea shore.