/[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.108 by charles_levert, Tue Jun 21 15:46:13 2005 UTC revision 1.109 by charles_levert, Tue Jun 21 15:54:35 2005 UTC
# Line 776  print_line_head (char const *beg, char c Line 776  print_line_head (char const *beg, char c
776      }      }
777  }  }
778    
779    const char *
780    print_line_middle (const char *beg, const char *lim)
781    {
782      size_t match_size;
783      size_t match_offset;
784      char *buf;            /* XXX */
785      const char *ibeg;     /* XXX */
786    
787      if (match_icase)      /* XXX - None of the -i stuff should be here.  */
788        {
789          int i = lim - beg;
790    
791          ibeg = buf = (char *) xmalloc(i);
792          /* This can't possibly be correct with UTF-8,
793             but it's equivalent to what was there so far.  */
794          while (--i >= 0)
795            buf[i] = tolower(beg[i]);
796        }
797      else
798        {
799          buf = NULL;
800          ibeg = beg;
801        }
802    
803      while (   lim > beg
804             && (   (match_offset = (*execute) (ibeg, lim - beg, &match_size, 1))
805                 != (size_t) -1))
806        {
807          char const *b = beg + match_offset;
808    
809          /* Avoid matching the empty line at the end of the buffer. */
810          if (b == lim)
811            break;
812    
813          /* Avoid hanging on grep --color "" foo */
814          if (match_size == 0)
815            break;
816    
817          if (only_matching)
818            print_line_head(b, lim, SEP_CHAR_MATCH);
819          else
820            {
821              if (pseudo_markup >= 0)
822                {
823                  PR_SGR_START(mlines_color);
824                  if (pseudo_markup)
825                    pseudo_markup = -1;
826                }
827              fwrite (beg, sizeof (char), match_offset, stdout);
828            }
829    
830          PR_SGR_START_IF(grep_color);
831          fwrite (b, sizeof (char), match_size, stdout);
832          PR_SGR_END_IF(grep_color);
833          if (only_matching)
834            fputs("\n", stdout);
835          beg = b + match_size;
836          ibeg += match_offset + match_size;        /* XXX */
837        }
838    
839      if (buf)
840        free(buf);  /* XXX */
841    
842      if (only_matching)
843        beg = lim;
844    
845      return beg;
846    }
847    
848    const char *
849    print_line_tail (const char *beg, const char *lim, const char *color)
850    {
851      size_t  eol_size;
852      size_t tail_size;
853    
854      eol_size   = (lim > beg && lim[-1] == eolbyte);
855      eol_size  += (lim - eol_size > beg && lim[-(1 + eol_size)] == '\r');
856      tail_size  =  lim - eol_size - beg;
857    
858      if (tail_size > 0)
859        {
860          if (pseudo_markup >= 0)
861            PR_SGR_START(color);
862          fwrite(beg, 1, tail_size, stdout);
863          beg += tail_size;
864        }
865    
866      if (tail_size > 0 || pseudo_markup < 0)
867        PR_SGR_END(color);
868    
869      return beg;
870    }
871    
872  static void  static void
873  prline (char const *beg, char const *lim, int sep)  prline (char const *beg, char const *lim, int sep)
874  {  {

Legend:
Removed from v.1.108  
changed lines
  Added in v.1.109

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