Blame m4/fnmatch.m4

Packit 8f70b4
# Check for fnmatch - serial 9.  -*- coding: utf-8 -*-
Packit 8f70b4
Packit 8f70b4
# Copyright (C) 2000-2007, 2009-2018 Free Software Foundation, Inc.
Packit 8f70b4
# This file is free software; the Free Software Foundation
Packit 8f70b4
# gives unlimited permission to copy and/or distribute it,
Packit 8f70b4
# with or without modifications, as long as this notice is preserved.
Packit 8f70b4
Packit 8f70b4
# Autoconf defines AC_FUNC_FNMATCH, but that is obsolescent.
Packit 8f70b4
# New applications should use the macros below instead.
Packit 8f70b4
Packit 8f70b4
# Request a POSIX compliant fnmatch function.
Packit 8f70b4
AC_DEFUN([gl_FUNC_FNMATCH_POSIX],
Packit 8f70b4
[
Packit 8f70b4
  m4_divert_text([DEFAULTS], [gl_fnmatch_required=POSIX])
Packit 8f70b4
Packit 8f70b4
  dnl Persuade glibc <fnmatch.h> to declare FNM_CASEFOLD etc.
Packit 8f70b4
  dnl This is only needed if gl_fnmatch_required = GNU. It would be possible
Packit 8f70b4
  dnl to avoid this dependency for gl_FUNC_FNMATCH_POSIX by putting
Packit 8f70b4
  dnl gl_FUNC_FNMATCH_GNU into a separate .m4 file.
Packit 8f70b4
  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
Packit 8f70b4
Packit 8f70b4
  FNMATCH_H=
Packit 8f70b4
  gl_fnmatch_required_lowercase=`
Packit 8f70b4
    echo $gl_fnmatch_required | LC_ALL=C tr '[[A-Z]]' '[[a-z]]'
Packit 8f70b4
  `
Packit 8f70b4
  gl_fnmatch_cache_var="gl_cv_func_fnmatch_${gl_fnmatch_required_lowercase}"
Packit 8f70b4
  AC_CACHE_CHECK([for working $gl_fnmatch_required fnmatch],
Packit 8f70b4
    [$gl_fnmatch_cache_var],
Packit 8f70b4
    [dnl Some versions of Solaris, SCO, and the GNU C Library
Packit 8f70b4
     dnl have a broken or incompatible fnmatch.
Packit 8f70b4
     dnl So we run a test program.  If we are cross-compiling, take no chance.
Packit 8f70b4
     dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this
Packit 8f70b4
     dnl test.
Packit 8f70b4
     if test $gl_fnmatch_required = GNU; then
Packit 8f70b4
       gl_fnmatch_gnu_start=
Packit 8f70b4
       gl_fnmatch_gnu_end=
Packit 8f70b4
     else
Packit 8f70b4
       gl_fnmatch_gnu_start='#if 0'
Packit 8f70b4
       gl_fnmatch_gnu_end='#endif'
Packit 8f70b4
     fi
Packit 8f70b4
     AC_RUN_IFELSE(
Packit 8f70b4
       [AC_LANG_PROGRAM(
Packit 8f70b4
          [[#include <fnmatch.h>
Packit 8f70b4
            static int
Packit 8f70b4
            y (char const *pattern, char const *string, int flags)
Packit 8f70b4
            {
Packit 8f70b4
              return fnmatch (pattern, string, flags) == 0;
Packit 8f70b4
            }
Packit 8f70b4
            static int
Packit 8f70b4
            n (char const *pattern, char const *string, int flags)
Packit 8f70b4
            {
Packit 8f70b4
              return fnmatch (pattern, string, flags) == FNM_NOMATCH;
Packit 8f70b4
            }
Packit 8f70b4
          ]],
Packit 8f70b4
          [[char const *Apat = 'A' < '\\\\' ? "[A-\\\\\\\\]" : "[\\\\\\\\-A]";
Packit 8f70b4
            char const *apat = 'a' < '\\\\' ? "[a-\\\\\\\\]" : "[\\\\\\\\-a]";
Packit 8f70b4
            static char const A_1[] = { 'A' - 1, 0 };
Packit 8f70b4
            static char const A01[] = { 'A' + 1, 0 };
Packit 8f70b4
            static char const a_1[] = { 'a' - 1, 0 };
Packit 8f70b4
            static char const a01[] = { 'a' + 1, 0 };
Packit 8f70b4
            static char const bs_1[] = { '\\\\' - 1, 0 };
Packit 8f70b4
            static char const bs01[] = { '\\\\' + 1, 0 };
Packit 8f70b4
            int result = 0;
Packit 8f70b4
            if (!n ("a*", "", 0))
Packit 8f70b4
              return 1;
Packit 8f70b4
            if (!y ("a*", "abc", 0))
Packit 8f70b4
              return 1;
Packit 8f70b4
            if (!y ("[/b", "[/b", 0)) /*"]]"*/ /* glibc Bugzilla bug 12378 */
Packit 8f70b4
              return 1;
Packit 8f70b4
            if (!n ("d*/*1", "d/s/1", FNM_PATHNAME))
Packit 8f70b4
              return 2;
Packit 8f70b4
            if (!y ("a\\\\bc", "abc", 0))
Packit 8f70b4
              return 3;
Packit 8f70b4
            if (!n ("a\\\\bc", "abc", FNM_NOESCAPE))
Packit 8f70b4
              return 3;
Packit 8f70b4
            if (!y ("*x", ".x", 0))
Packit 8f70b4
              return 4;
Packit 8f70b4
            if (!n ("*x", ".x", FNM_PERIOD))
Packit 8f70b4
              return 4;
Packit 8f70b4
            if (!y (Apat, "\\\\", 0))
Packit 8f70b4
              return 5;
Packit 8f70b4
            if (!y (Apat, "A", 0))
Packit 8f70b4
              return 5;
Packit 8f70b4
            if (!y (apat, "\\\\", 0))
Packit 8f70b4
              return 5;
Packit 8f70b4
            if (!y (apat, "a", 0))
Packit 8f70b4
              return 5;
Packit 8f70b4
            if (!(n (Apat, A_1, 0) == ('A' < '\\\\')))
Packit 8f70b4
              return 5;
Packit 8f70b4
            if (!(n (apat, a_1, 0) == ('a' < '\\\\')))
Packit 8f70b4
              return 5;
Packit 8f70b4
            if (!(y (Apat, A01, 0) == ('A' < '\\\\')))
Packit 8f70b4
              return 5;
Packit 8f70b4
            if (!(y (apat, a01, 0) == ('a' < '\\\\')))
Packit 8f70b4
              return 5;
Packit 8f70b4
            if (!(y (Apat, bs_1, 0) == ('A' < '\\\\')))
Packit 8f70b4
              return 5;
Packit 8f70b4
            if (!(y (apat, bs_1, 0) == ('a' < '\\\\')))
Packit 8f70b4
              return 5;
Packit 8f70b4
            if (!(n (Apat, bs01, 0) == ('A' < '\\\\')))
Packit 8f70b4
              return 5;
Packit 8f70b4
            if (!(n (apat, bs01, 0) == ('a' < '\\\\')))
Packit 8f70b4
              return 5;
Packit 8f70b4
            $gl_fnmatch_gnu_start
Packit 8f70b4
            if (!y ("xxXX", "xXxX", FNM_CASEFOLD))
Packit 8f70b4
              result |= 8;
Packit 8f70b4
            if (!y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH))
Packit 8f70b4
              result |= 16;
Packit 8f70b4
            if (!n ("d*/*1", "d/s/1", FNM_FILE_NAME))
Packit 8f70b4
              result |= 32;
Packit 8f70b4
            if (!y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR))
Packit 8f70b4
              result |= 64;
Packit 8f70b4
            if (!y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR))
Packit 8f70b4
              result |= 64;
Packit 8f70b4
            if (!y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR))
Packit 8f70b4
              result |= 64;
Packit 8f70b4
            $gl_fnmatch_gnu_end
Packit 8f70b4
            return result;
Packit 8f70b4
          ]])],
Packit 8f70b4
       [eval "$gl_fnmatch_cache_var=yes"],
Packit 8f70b4
       [eval "$gl_fnmatch_cache_var=no"],
Packit 8f70b4
       [eval "$gl_fnmatch_cache_var=\"guessing no\""])
Packit 8f70b4
    ])
Packit 8f70b4
  eval "gl_fnmatch_result=\"\$$gl_fnmatch_cache_var\""
Packit 8f70b4
  if test "$gl_fnmatch_result" = yes; then
Packit 8f70b4
    dnl Not strictly necessary. Only to avoid spurious leftover files if people
Packit 8f70b4
    dnl don't do "make distclean".
Packit 8f70b4
    rm -f "$gl_source_base/fnmatch.h"
Packit 8f70b4
  else
Packit 8f70b4
    FNMATCH_H=fnmatch.h
Packit 8f70b4
  fi
Packit 8f70b4
  AC_SUBST([FNMATCH_H])
Packit 8f70b4
  AM_CONDITIONAL([GL_GENERATE_FNMATCH_H], [test -n "$FNMATCH_H"])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
# Request a POSIX compliant fnmatch function with GNU extensions.
Packit 8f70b4
AC_DEFUN([gl_FUNC_FNMATCH_GNU],
Packit 8f70b4
[
Packit 8f70b4
  m4_divert_text([INIT_PREPARE], [gl_fnmatch_required=GNU])
Packit 8f70b4
Packit 8f70b4
  AC_REQUIRE([gl_FUNC_FNMATCH_POSIX])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_PREREQ_FNMATCH],
Packit 8f70b4
[
Packit 8f70b4
  dnl We must choose a different name for our function, since on ELF systems
Packit 8f70b4
  dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
Packit 8f70b4
  dnl compiled into a shared library.
Packit 8f70b4
  AC_DEFINE_UNQUOTED([fnmatch], [${gl_fnmatch_required_lowercase}_fnmatch],
Packit 8f70b4
    [Define to a replacement function name for fnmatch().])
Packit 8f70b4
  dnl Prerequisites of lib/fnmatch.c.
Packit 8f70b4
  AC_REQUIRE([AC_TYPE_MBSTATE_T])
Packit 8f70b4
  AC_CHECK_DECLS([isblank], [], [], [[#include <ctype.h>]])
Packit 8f70b4
  AC_CHECK_FUNCS_ONCE([btowc isblank iswctype mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy])
Packit 8f70b4
  AC_CHECK_HEADERS_ONCE([wctype.h])
Packit 8f70b4
])