/[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.111 by charles_levert, Wed Jun 22 01:47:43 2005 UTC revision 1.112 by charles_levert, Thu Jul 7 05:32:30 2005 UTC
# Line 79  static int mmap_option; Line 79  static int mmap_option;
79  /* If nonzero, use grep_color marker.  */  /* If nonzero, use grep_color marker.  */
80  static int color_option;  static int color_option;
81    
 /* If nonzero, do pseudo-markup instead of actual colors.  */  
 static int pseudo_markup;  
   
82  /* If nonzero, show only the part of a line matching the expression. */  /* If nonzero, show only the part of a line matching the expression. */
83  static int only_matching;  static int only_matching;
84    
# Line 224  struct color_cap Line 221  struct color_cap
221  static const char *  static const char *
222  color_cap_ne_fct(void)  color_cap_ne_fct(void)
223  {  {
   if (pseudo_markup)  
     return "makes no sense after the \"xm\" capability; ignored";  
   
224    sgr_start = "\33[%sm";    sgr_start = "\33[%sm";
225    sgr_end   = "\33[m";    sgr_end   = "\33[m";
226    
227    return NULL;    return NULL;
228  }  }
229    
 static const char *  
 color_cap_xm_fct(void)  
 {  
   /* This experimental feature should stay undocumented for now.  */  
   pseudo_markup = 1;  
   
   sgr_start = "<grep:%s>";  
   sgr_end   = "</grep:%s>";  
   
   /* The user can just redefine them to the empty string afterwards.  */  
   grep_color     = "matched-text";  
   filename_color = "filename";  
   line_num_color = "line-number";  
   byte_num_color = "byte-offset";  
   sep_color      = "separator";  
   mlines_color   = "matching-line";  
   context_color  = "context-line";  
   
   return NULL;  
 }  
   
230  /* For GREP_COLORS.  */  /* For GREP_COLORS.  */
231  static struct color_cap color_dict[] =  static struct color_cap color_dict[] =
232    {    {
# Line 265  static struct color_cap color_dict[] = Line 238  static struct color_cap color_dict[] =
238      { "ml", &mlines_color,      NULL },                 /* matching lines */      { "ml", &mlines_color,      NULL },                 /* matching lines */
239      { "cx", &context_color,     NULL },                 /* context lines */      { "cx", &context_color,     NULL },                 /* context lines */
240      { "ne", NULL,               color_cap_ne_fct },     /* no EL on SGR_* */      { "ne", NULL,               color_cap_ne_fct },     /* no EL on SGR_* */
     { "xm", NULL,               color_cap_xm_fct },     /* pseudo-markup */  
241      { NULL, NULL,               NULL }      { NULL, NULL,               NULL }
242    };    };
243    
# Line 818  print_line_middle (const char *beg, cons Line 790  print_line_middle (const char *beg, cons
790          print_line_head(b, lim, SEP_CHAR_MATCH);          print_line_head(b, lim, SEP_CHAR_MATCH);
791        else        else
792          {          {
793            if (pseudo_markup >= 0)            PR_SGR_START(mlines_color);
             {  
               PR_SGR_START(mlines_color);  
               if (pseudo_markup)  
                 pseudo_markup = -1;  
             }  
794            fwrite (beg, sizeof (char), match_offset, stdout);            fwrite (beg, sizeof (char), match_offset, stdout);
795          }          }
796    
# Line 857  print_line_tail (const char *beg, const Line 824  print_line_tail (const char *beg, const
824    
825    if (tail_size > 0)    if (tail_size > 0)
826      {      {
827        if (pseudo_markup >= 0)        PR_SGR_START(color);
         PR_SGR_START(color);  
828        fwrite(beg, 1, tail_size, stdout);        fwrite(beg, 1, tail_size, stdout);
829        beg += tail_size;        beg += tail_size;
830          PR_SGR_END(color);
831      }      }
832    
   if (tail_size > 0 || pseudo_markup < 0)  
     PR_SGR_END(color);  
   
833    return beg;    return beg;
834  }  }
835    
# Line 888  prline (char const *beg, char const *lim Line 852  prline (char const *beg, char const *lim
852    
853        if (!only_matching && *line_color);        if (!only_matching && *line_color);
854          beg = print_line_tail(beg, lim, line_color);          beg = print_line_tail(beg, lim, line_color);
   
       /* This global is modified by print_line_middle()  
          and checked by print_line_tail().  Now reset it.  */  
       if (pseudo_markup < 0)  
         pseudo_markup = 1;  
855      }      }
856    
857    if (!only_matching && lim > beg)    if (!only_matching && lim > beg)

Legend:
Removed from v.1.111  
changed lines
  Added in v.1.112

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