/[grep]/grep/src/grep.c
ViewVC logotype

Diff of /grep/src/grep.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.98 by charles_levert, Mon May 2 09:47:48 2005 UTC revision 1.99 by charles_levert, Tue Jun 14 20:56:42 2005 UTC
# Line 82  static int only_matching; Line 82  static int only_matching;
82     variable GREP_COLOR.  The default is to print red.  */     variable GREP_COLOR.  The default is to print red.  */
83  static const char *grep_color = "01;31";  static const char *grep_color = "01;31";
84    
85    /* Select Graphic Rendition (SGR) strings.  */
86    /* Also Erase in Line (EL) to Right by default.  */
87    #define SGR_START "\33[%sm\33[K"
88    #define SGR_END   "\33[m\33[K"
89    
90    /* SGR utility macros.  */
91    #define PR_SGR_FMT(fmt, s) do { if (*(s)) printf((fmt), (s)); } while (0)
92    #define PR_SGR_FMT_IF(fmt, s) \
93      do { if (color_option && *(s)) printf((fmt), (s)); } while (0)
94    #define PR_SGR_START(s)    PR_SGR_FMT(   SGR_START, (s))
95    #define PR_SGR_END(s)      PR_SGR_FMT(   SGR_END,   (s))
96    #define PR_SGR_START_IF(s) PR_SGR_FMT_IF(SGR_START, (s))
97    #define PR_SGR_END_IF(s)   PR_SGR_FMT_IF(SGR_END,   (s))
98    
99  static struct exclude *excluded_patterns;  static struct exclude *excluded_patterns;
100  static struct exclude *included_patterns;  static struct exclude *included_patterns;
101  /* Short options.  */  /* Short options.  */
# Line 543  prline (char const *beg, char const *lim Line 557  prline (char const *beg, char const *lim
557                  break;                  break;
558                if (match_size == 0)                if (match_size == 0)
559                  break;                  break;
560                if(color_option)                PR_SGR_START_IF(grep_color);
                 printf("\33[%sm", grep_color);  
561                fwrite(b, sizeof (char), match_size, stdout);                fwrite(b, sizeof (char), match_size, stdout);
562                if(color_option)                PR_SGR_END_IF(grep_color);
                 fputs("\33[00m", stdout);  
563                fputs("\n", stdout);                fputs("\n", stdout);
564                beg = b + match_size;                beg = b + match_size;
565                ibeg += match_offset + match_size;                ibeg += match_offset + match_size;
# Line 566  prline (char const *beg, char const *lim Line 578  prline (char const *beg, char const *lim
578              break;              break;
579            if (match_size == 0)            if (match_size == 0)
580              break;              break;
581            if(color_option)            PR_SGR_START_IF(grep_color);
             printf("\33[%sm", grep_color);  
582            fwrite(b, sizeof (char), match_size, stdout);            fwrite(b, sizeof (char), match_size, stdout);
583            if(color_option)            PR_SGR_END_IF(grep_color);
             fputs("\33[00m", stdout);  
584            fputs("\n", stdout);            fputs("\n", stdout);
585            beg = b + match_size;            beg = b + match_size;
586          }          }
# Line 601  prline (char const *beg, char const *lim Line 611  prline (char const *beg, char const *lim
611                if (match_size == 0)                if (match_size == 0)
612                  break;                  break;
613                fwrite (beg, sizeof (char), match_offset, stdout);                fwrite (beg, sizeof (char), match_offset, stdout);
614                printf ("\33[%sm", grep_color);                PR_SGR_START(grep_color);
615                fwrite (b, sizeof (char), match_size, stdout);                fwrite (b, sizeof (char), match_size, stdout);
616                fputs ("\33[00m", stdout);                PR_SGR_END(grep_color);
617                beg = b + match_size;                beg = b + match_size;
618                ibeg = ibeg + match_offset + match_size;                ibeg = ibeg + match_offset + match_size;
619              }              }
# Line 623  prline (char const *beg, char const *lim Line 633  prline (char const *beg, char const *lim
633            if (match_size == 0)            if (match_size == 0)
634              break;              break;
635            fwrite (beg, sizeof (char), match_offset, stdout);            fwrite (beg, sizeof (char), match_offset, stdout);
636            printf ("\33[%sm", grep_color);            PR_SGR_START(grep_color);
637            fwrite (b, sizeof (char), match_size, stdout);            fwrite (b, sizeof (char), match_size, stdout);
638            fputs ("\33[00m", stdout);            PR_SGR_END(grep_color);
639            beg = b + match_size;            beg = b + match_size;
640          }          }
641      }      }

Legend:
Removed from v.1.98  
changed lines
  Added in v.1.99

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26