diff -cbr orig/grep/dfa.c new/grep/dfa.c
*** orig/grep/dfa.c	Tue May 05 19:32:05 1992
--- new/grep/dfa.c	Thu Jun 18 15:42:18 1992
***************
*** 31,36 ****
--- 31,37 ----
  #endif
  
  #include "dfa.h"
+ #include "regex.h"
  
  #if __STDC__
  typedef void *ptr_t;
diff -cbr orig/grep/dfa.h new/grep/dfa.h
*** orig/grep/dfa.h	Mon May 04 13:43:28 1992
--- new/grep/dfa.h	Thu Jun 18 15:45:13 1992
***************
*** 48,53 ****
--- 48,55 ----
  #define ISLOWER(c) (isascii(c) && islower(c))
  #endif
  
+ #if 0 /* This is really defined in regex.h */
+ 
  /* 1 means plain parentheses serve as grouping, and backslash
       parentheses are needed for literal searching.
     0 means backslash-parentheses are grouping, and plain parentheses
***************
*** 84,89 ****
--- 86,94 ----
  #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK | RE_NEWLINE_OR)
  #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
  #define RE_SYNTAX_EMACS 0
+ 
+ #endif
+ 
  
  /* Number of bits in an unsigned char. */
  #define CHARBITS 8
diff -cbr orig/grep/grep.c new/grep/grep.c
*** orig/grep/grep.c	Tue May 05 19:40:10 1992
--- new/grep/grep.c	Thu Jun 18 16:11:12 1992
***************
*** 38,47 ****
  
  #ifndef STDC_HEADERS
  extern char *getenv();
- #endif
  extern int errno;
- 
  extern char *sys_errlist[];
  
  #include "dfa.h"
  #include "regex.h"
--- 38,46 ----
  
  #ifndef STDC_HEADERS
  extern char *getenv();
  extern int errno;
  extern char *sys_errlist[];
+ #endif
  
  #include "dfa.h"
  #include "regex.h"
***************
*** 534,550 ****
    return match_count;
  }
  
  void
  usage_and_die()
  {
!   fprintf(stderr, "\
! Usage: %s [-CVbchilnsvwx] [-num] [-A num] [-B num] [-f file]\n\
!        [-e] expr [file...]\n", prog);
    exit(ERROR);
  }
  
- static char version[] = "GNU e?grep, version 1.6";
- 
  int
  main(argc, argv)
       int argc;
--- 533,572 ----
    return match_count;
  }
  
+ static char version[] = "GNU e?grep, version 1.6";
+ 
  void
  usage_and_die()
  {
!   printf("\n%s\n", version);
!   printf("\nUsage: %s [-CVbchilnsvwx] [-<num>] [-A <num>] [-B <num>]"
!          "\n       [-f file] [-e] expr [files]\n\n", prog);
!   printf(
!   "  -A <num>  print <num> lines of context after every matching line\n"
!   "  -B <num>  print <num> lines of context before every matching line\n"
!   "  -C        print 2 lines of context on each side of every match\n"
!   "  -<num>    print <num> lines of context on each side\n"
!   "  -V        print the version number on stderr\n"
!   );
!   printf(
!   "  -b        print every match preceded by its byte offset\n"
!   "  -c        print a total count of matching lines only\n"
!   "  -e <expr> search for <expr>; useful if <expr> begins with -\n"
!   "  -f <file> take <expr> from the given <file>\n"
!   "  -h        don't display filenames on matches\n"
!   "  -i        ignore case difference when comparing strings\n"
!   );
!   printf(
!   "  -l        list files containing matches only\n"
!   "  -n        print each match preceded by its line number\n"
!   "  -s        run silently producing no output except error messages\n"
!   "  -v        print only lines that contain no matches for the <expr>\n"
!   "  -w        print only lines where the match is a complete word\n"
!   "  -x        print only lines where the match is a whole line\n");
! 
    exit(ERROR);
  }
  
  int
  main(argc, argv)
       int argc;
***************
*** 563,568 ****
--- 585,595 ----
    char translate[_NOTCHAR];	/* Translate table for case conversion
  				   (needed by the backtracking matcher). */
  
+ #ifdef __EMX__
+   _wildcard(&argc, &argv);
+   setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
+ #endif
+ 
    if (prog = index(argv[0], '/'))
      ++prog;
    else
***************
*** 607,613 ****
  	break;
  
        case 'V':
! 	fprintf(stderr, "%s\n", version);
  	break;
  
        case 'b':
--- 634,641 ----
  	break;
  
        case 'V':
!         fprintf(stderr, "\n%s\n", version);
!         exit(ERROR);
  	break;
  
        case 'b':
***************
*** 725,730 ****
--- 753,761 ----
    else
      regexp_len = strlen(the_regexp);
  
+   if (regex_errmesg = re_compile_pattern(the_regexp, regexp_len, &regex))
+     regerror(regex_errmesg);
+ 
    if (whole_word || whole_line)
      {
        /* In the whole-word case, we use the pattern:
***************
*** 734,766 ****
  	 BUG: Using [A-Za-z_] is locale-dependent!  */
  
        char *n = malloc(regexp_len + 50);
!       int i = 0;
  
  #ifdef EGREP
        if (whole_word)
! 	strcpy(n, "(^|[^A-Za-z_])(");
!       else
! 	strcpy(n, "^(");
  #else
        /* Todo:  Make *sure* this is the right syntax.  Down with grep! */
        if (whole_word)
! 	strcpy(n, "\\(^\\|[^A-Za-z_]\\)\\(");
!       else
! 	strcpy(n, "^\\(");
  #endif
        i = strlen(n);
        bcopy(the_regexp, n + i, regexp_len);
        i += regexp_len;
  #ifdef EGREP
        if (whole_word)
! 	strcpy(n + i, ")([^A-Za-z_]|$)");
!       else
! 	strcpy(n + i, ")$");
  #else
        if (whole_word)
! 	strcpy(n + i, "\\)\\([^A-Za-z_]\\|$\\)");
!       else
! 	strcpy(n + i, "\\)$");
  #endif
        i += strlen(n + i);
        regcompile(n, i, &reg, 1);
--- 765,799 ----
  	 BUG: Using [A-Za-z_] is locale-dependent!  */
  
        char *n = malloc(regexp_len + 50);
!       int i;
  
+       n[0] = 0;
  #ifdef EGREP
+       if (whole_line)
+ 	strcat(n, "^(");
        if (whole_word)
! 	strcat(n, "(^|[^A-Za-z_])(");
  #else
        /* Todo:  Make *sure* this is the right syntax.  Down with grep! */
+       if (whole_line)
+ 	strcat(n, "^\\(");
        if (whole_word)
! 	strcat(n, "\\(^\\|[^A-Za-z_]\\)\\(");
  #endif
        i = strlen(n);
        bcopy(the_regexp, n + i, regexp_len);
        i += regexp_len;
+       n[i] = 0;
  #ifdef EGREP
        if (whole_word)
! 	strcat(n + i, ")([^A-Za-z_]|$)");
!       if (whole_line)
! 	strcat(n + i, ")$");
  #else
        if (whole_word)
! 	strcat(n + i, "\\)\\([^A-Za-z_]\\|$\\)");
!       if (whole_line)
! 	strcat(n + i, "\\)$");
  #endif
        i += strlen(n + i);
        regcompile(n, i, &reg, 1);
***************
*** 768,776 ****
    else
      regcompile(the_regexp, regexp_len, &reg, 1);
  
- 
-   if (regex_errmesg = re_compile_pattern(the_regexp, regexp_len, &regex))
-     regerror(regex_errmesg);
  
    /*
      Find the longest metacharacter-free string which must occur in the
--- 801,806 ----
