Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!lll-lcc!ptsfa!ihnp4!homxb!houxm!hjuxa!petsd!pedsgo!chip From: chip@pedsgo.UUCP Newsgroups: comp.lang.c Subject: ignore case option for grep Message-ID: <745@pedsgo.UUCP> Date: Wed, 18-Mar-87 09:09:07 EST Article-I.D.: pedsgo.745 Posted: Wed Mar 18 09:09:07 1987 Date-Received: Sat, 21-Mar-87 04:41:07 EST Distribution: na Organization: Concurrent Computer Corp. Tinton Falls, N.J. Lines: 78 Way back when I was using an Altos 586 running Xenix 2.something or other, I became dependent on the -y option for grep which ignores case when doing its pattern match. When I came to the wonderful world of sysV, I was disapointed to learn that the -y option was not supported, meaning I couldn't use shell scripts I wrote under Xenix. So, I took the source to grep and modified it to suite my needs, to which I am supplying the diff below. The major modifications are in and I wasn't about to change the actual file, so, in grep.c where it says #include I read in the actual source. Tacky, sloppy, and unprofessional yes, but it got the job done. If anyone can see any dangerous side effects from what I did, I would surely appreciate knowing so. It seems harmless enough, but you never know. Of course, this should NOT replace /bin/grep, but it could be placed somewhere where it can be used in a productive manner. I wasn't sure as to whether to post this to net.sources, comp.unix.questions, or comp.lang.c. Flames about wrong newsgroups to /dev/null&void please. Note that the diff is on grep.c after regexp.h has been read in. Also note that actual line numbers may be different due to proprietary comments and other garbage placed in grep.c and regexp.h. $diff grep.c grep.c.old ----------------------------- begin grep.diff ----------------------- 46d45 < int yflag; 310,318c309,310 < if (!yflag){ < if(*p1 != c) < continue; < } < else{ < if(toupper(*p1) != toupper(c)) < continue; < } < --- > if(*p1 != c) > continue; 341d332 < char side1, side2; 349,360c340,341 < if(!yflag){ < if(*ep++ == *lp++) < continue; < } < else { < side1=(isupper(*ep)) ? *ep : toupper(*ep); < ep++; < side2=(isupper(*lp)) ? *lp : toupper(*lp); < lp++; < if(side1 == side2) < continue < } --- > if(*ep++ == *lp++) > continue; 502a484 > 552c534 < while((c=getopt(argc, argv, "blcnsviy")) != EOF) --- > while((c=getopt(argc, argv, "blcnsvi")) != EOF) 563,565d544 < case 'y': < yflag++; < break; 583c562 < errmsg("Usage: grep -blcnsviy pattern file . . .\n", --- > errmsg("Usage: grep -blcnsvi pattern file . . .\n", ---------------------------- end grep.diff ---------------------------- -- | Chip Maurer | | Concurrent Computer Corporation | | Tinton Falls, NJ | | {topaz|hjuxa|vax135}!petsd!{pedsgo|pedsga}!chip |