www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/02/18/04:11:59

Date: Sun, 18 Feb 2001 11:09:28 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Alain Magloire <alain AT qnx DOT com>
cc: djgpp-workers AT delorie DOT com
Subject: Re: GNU_grep-2.5c_beta
In-Reply-To: <200102180625.BAA21110@qnx.com>
Message-ID: <Pine.SUN.3.91.1010218105550.5826C-100000@is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

[I took a liberty of CC'ing djgpp-workers.]

On Sun, 18 Feb 2001, Alain Magloire wrote:

>   - The new option --color will use the environment variable GREP_COLOR
>     (default is red) to highlight the matching string.

This is a welcome feature, but the way it is implemented is IMHO too 
Unix-centric.  Here's the relevant snippet from grep.c:

  if (color_option)
    {
      size_t match_size;
      size_t match_offset;
      while ((match_offset = (*execute) (beg, lim - beg, &match_size, 1))
             != (size_t) -1)
        {
          char const *b = beg + match_offset;
          /* Avoid matching the empty line at the end of the buffer.  */
          if (b == lim)
            break;
          fwrite (beg, sizeof (char), match_offset, stdout);
          printf ("\33[%sm", grep_color);
          fwrite (b, sizeof (char), match_size, stdout);
          fputs ("\33[00m", stdout);
          beg = b + match_size;
        }
    }

This assumes that the terminal device driver automatically supports ANSI 
escape sequences.  That assumption doesn't hold on DOS and Windows, and 
possibly also on other systems.

Now, I did port to DJGPP GNU `ls' that used the same technique, so the 
way to work around this is known.  But the solution is highly 
non-portable to anything but DJGPP (it uses the Filesystem Extension 
feature which AFAIK is unique to DJGPP), and is nothing but a cleverly 
disguised kludge.

I'd argue that, once printed text is anything beyond simple ASCII text, a 
text-mode application such as Grep should use specialized functions to 
print the text with whatever markup it wants.  Each platform then could 
supply its own implementation of the function(s) that deliver text with 
markup to the screen.  The default implementation, for Unix and GNU/Linux 
systems, could simply use the code above.

In other words, I'm asking for Grep to define special functions to print 
text to the screen and use them instead of fwrite/printf/fprintf it used 
until now.  Each non-Posix port will then have a chance to define its own 
implementation of those functions.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019