xref: /netbsd-src/external/gpl2/diffutils/dist/m4/regex.m4 (revision 75f6d617e282811cb173c2ccfbf5df0dd71f7045)
1*75f6d617Schristos#serial 12
2*75f6d617Schristos
3*75f6d617Schristosdnl Initially derived from code in GNU grep.
4*75f6d617Schristosdnl Mostly written by Jim Meyering.
5*75f6d617Schristos
6*75f6d617Schristosdnl Usage: jm_INCLUDED_REGEX([lib/regex.c])
7*75f6d617Schristosdnl
8*75f6d617SchristosAC_DEFUN([jm_INCLUDED_REGEX],
9*75f6d617Schristos  [
10*75f6d617Schristos    dnl Even packages that don't use regex.c can use this macro.
11*75f6d617Schristos    dnl Of course, for them it doesn't do anything.
12*75f6d617Schristos
13*75f6d617Schristos    # Assume we'll default to using the included regex.c.
14*75f6d617Schristos    ac_use_included_regex=yes
15*75f6d617Schristos
16*75f6d617Schristos    # However, if the system regex support is good enough that it passes the
17*75f6d617Schristos    # the following run test, then default to *not* using the included regex.c.
18*75f6d617Schristos    # If cross compiling, assume the test would fail and use the included
19*75f6d617Schristos    # regex.c.  The first failing regular expression is from `Spencer ere
20*75f6d617Schristos    # test #75' in grep-2.3.
21*75f6d617Schristos    AC_CACHE_CHECK([for working re_compile_pattern],
22*75f6d617Schristos		   jm_cv_func_working_re_compile_pattern,
23*75f6d617Schristos      AC_TRY_RUN(
24*75f6d617Schristos[#include <stdio.h>
25*75f6d617Schristos#include <regex.h>
26*75f6d617Schristos	  int
27*75f6d617Schristos	  main ()
28*75f6d617Schristos	  {
29*75f6d617Schristos	    static struct re_pattern_buffer regex;
30*75f6d617Schristos	    const char *s;
31*75f6d617Schristos	    struct re_registers regs;
32*75f6d617Schristos	    re_set_syntax (RE_SYNTAX_POSIX_EGREP);
33*75f6d617Schristos	    [s = re_compile_pattern ("a[[:@:>@:]]b\n", 9, &regex);]
34*75f6d617Schristos	    /* This should fail with _Invalid character class name_ error.  */
35*75f6d617Schristos	    if (!s)
36*75f6d617Schristos	      exit (1);
37*75f6d617Schristos
38*75f6d617Schristos	    /* This should succeed, but doesn't for e.g. glibc-2.1.3.  */
39*75f6d617Schristos	    s = re_compile_pattern ("{1", 2, &regex);
40*75f6d617Schristos
41*75f6d617Schristos	    if (s)
42*75f6d617Schristos	      exit (1);
43*75f6d617Schristos
44*75f6d617Schristos	    /* The following example is derived from a problem report
45*75f6d617Schristos               against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>.  */
46*75f6d617Schristos	    s = re_compile_pattern ("[[an�]]*n", 7, &regex);
47*75f6d617Schristos	    if (s)
48*75f6d617Schristos	      exit (1);
49*75f6d617Schristos
50*75f6d617Schristos	    /* This should match, but doesn't for e.g. glibc-2.2.1.  */
51*75f6d617Schristos	    if (re_match (&regex, "an", 2, 0, &regs) != 2)
52*75f6d617Schristos	      exit (1);
53*75f6d617Schristos
54*75f6d617Schristos	    exit (0);
55*75f6d617Schristos	  }
56*75f6d617Schristos	],
57*75f6d617Schristos	       jm_cv_func_working_re_compile_pattern=yes,
58*75f6d617Schristos	       jm_cv_func_working_re_compile_pattern=no,
59*75f6d617Schristos	       dnl When crosscompiling, assume it's broken.
60*75f6d617Schristos	       jm_cv_func_working_re_compile_pattern=no))
61*75f6d617Schristos    if test $jm_cv_func_working_re_compile_pattern = yes; then
62*75f6d617Schristos      ac_use_included_regex=no
63*75f6d617Schristos    fi
64*75f6d617Schristos
65*75f6d617Schristos    test -n "$1" || AC_MSG_ERROR([missing argument])
66*75f6d617Schristos    m4_syscmd([test -f $1])
67*75f6d617Schristos    ifelse(m4_sysval, 0,
68*75f6d617Schristos      [
69*75f6d617Schristos	AC_ARG_WITH(included-regex,
70*75f6d617Schristos	[  --without-included-regex don't compile regex; this is the default on
71*75f6d617Schristos                          systems with version 2 of the GNU C library
72*75f6d617Schristos                          (use with caution on other system)],
73*75f6d617Schristos		    jm_with_regex=$withval,
74*75f6d617Schristos		    jm_with_regex=$ac_use_included_regex)
75*75f6d617Schristos	if test "$jm_with_regex" = yes; then
76*75f6d617Schristos	  AC_LIBOBJ(regex)
77*75f6d617Schristos	fi
78*75f6d617Schristos      ],
79*75f6d617Schristos    )
80*75f6d617Schristos  ]
81*75f6d617Schristos)
82