chip@pedsgo.UUCP (03/18/87)
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 <regexp.h> and I wasn't about to change the actual file, so, in grep.c where it says #include <regexp.h> 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 |
mouse@mcgill-vision.UUCP (03/25/87)
In article <745@pedsgo.UUCP>, chip@pedsgo.UUCP writes: > [about an ignore-case option to grep] > $ diff grep.c grep.c.old > [diff follows] In article <746@pedsgo.UUCP>, chip@pedsgo.UUCP writes: > Please ignore my last posting about grep. I totally forgot about > '-i' for ignoring case in searches. Talk about RTFM!!!!! Actually, how about trying it too? On my system, and therefore probably on most BSD systems, -i works only for fgrep and grep, not egrep, which is easily the most useful of the three (fastest, accepts the most general expressions, etc). Yes, even for fixed strings, in my experience egrep is much faster than fgrep (and grep). I will probably write something for VAXen using the matchc instruction, so the (presumably tuned) microcode does the searching. If I do and it turns out to be usefully fast, I will probably submit it for consideration for mod.sources. der Mouse Smart mailers: mouse@mcgill-vision.uucp USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!musocs!mcgill-vision!mouse think!mosart!mcgill-vision!mouse ARPAnet: think!mosart!mcgill-vision!mouse@harvard.harvard.edu