Skip to content

Commit

Permalink
grep 3.1 fixes #6.
Browse files Browse the repository at this point in the history
grep-configure.patch:
    Activating WINDOWS_STAT_INODES fixes recursion.

grep-lock.patch:
    We still need to use SetConsoleCtrlHandler() to avoid leaking color.

grep.patch:
    Everything here has either been fixed upstream or decomposed into smaller patches.
    The distro's batch file needs `set GREP_COLORS=mt=01;32:fn=36:ln=33:bn=31:se=35`.
    It also needs a Doskey macro for `--color=auto`.

grep.sh:
    --disable-largefile was added in distro 11.0.
    It was still necessary for grep 2.10, but not for grep 3.1.
  • Loading branch information
StephanTLavavej committed Jul 31, 2017
1 parent d9ff15b commit 0ad9e1b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 315 deletions.
12 changes: 12 additions & 0 deletions grep-configure.patch
@@ -0,0 +1,12 @@
diff -aurN grep-3.1/configure grep-3.1-fixed/configure
--- grep-3.1/configure 2017-07-02 13:21:11.000000000 -0700
+++ grep-3.1-fixed/configure 2017-07-23 18:54:07.438394700 -0700
@@ -14896,7 +14896,7 @@



- WINDOWS_STAT_INODES=0
+ WINDOWS_STAT_INODES=1



55 changes: 55 additions & 0 deletions grep-lock.patch
@@ -0,0 +1,55 @@
diff -aurN grep-3.1/lib/colorize-w32.c grep-3.1-fixed/lib/colorize-w32.c
--- grep-3.1/lib/colorize-w32.c 2017-01-01 03:34:33.000000000 -0800
+++ grep-3.1-fixed/lib/colorize-w32.c 2017-07-30 16:43:02.773225700 -0700
@@ -32,6 +32,27 @@

static HANDLE hstdout = INVALID_HANDLE_VALUE;
static SHORT norm_attr;
+static CRITICAL_SECTION color_lock;
+static BOOL color_bool = TRUE;
+
+/* After Ctrl+C or Ctrl+Break,
+ restore the normal text attribute used by the console. */
+static BOOL WINAPI
+w32_color_handler (DWORD ctrl_type)
+{
+ if (ctrl_type == CTRL_C_EVENT
+ || ctrl_type == CTRL_BREAK_EVENT)
+ {
+ EnterCriticalSection (&color_lock);
+ if (hstdout != INVALID_HANDLE_VALUE)
+ {
+ SetConsoleTextAttribute (hstdout, norm_attr);
+ }
+ color_bool = FALSE;
+ LeaveCriticalSection (&color_lock);
+ }
+ return FALSE;
+}

/* Initialize the normal text attribute used by the console. */
void
@@ -45,6 +66,9 @@
norm_attr = csbi.wAttributes;
else
hstdout = INVALID_HANDLE_VALUE;
+
+ InitializeCriticalSectionAndSpinCount (&color_lock, 4000);
+ SetConsoleCtrlHandler (&w32_color_handler, TRUE);
}

/* Return non-zero if we should highlight matches in output. */
@@ -164,7 +188,12 @@
if (hstdout != INVALID_HANDLE_VALUE)
{
SHORT attr = w32_sgr2attr (sgr_seq);
- SetConsoleTextAttribute (hstdout, attr);
+ EnterCriticalSection (&color_lock);
+ if (color_bool)
+ {
+ SetConsoleTextAttribute (hstdout, attr);
+ }
+ LeaveCriticalSection (&color_lock);
}
else
printf (sgr_start, sgr_seq);
308 changes: 0 additions & 308 deletions grep.patch

This file was deleted.

0 comments on commit 0ad9e1b

Please sign in to comment.