Blame lib/glob_internal.h

Packit 8f70b4
/* Shared definition for glob and glob_pattern_p.
Packit 8f70b4
   Copyright (C) 2017-2018 Free Software Foundation, Inc.
Packit 8f70b4
   This file is part of the GNU C Library.
Packit 8f70b4
Packit 8f70b4
   The GNU C Library is free software; you can redistribute it and/or
Packit 8f70b4
   modify it under the terms of the GNU General Public
Packit 8f70b4
   License as published by the Free Software Foundation; either
Packit 8f70b4
   version 3 of the License, or (at your option) any later version.
Packit 8f70b4
Packit 8f70b4
   The GNU C Library is distributed in the hope that it will be useful,
Packit 8f70b4
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8f70b4
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 8f70b4
   General Public License for more details.
Packit 8f70b4
Packit 8f70b4
   You should have received a copy of the GNU General Public
Packit 8f70b4
   License along with the GNU C Library; if not, see
Packit 8f70b4
   <https://www.gnu.org/licenses/>.  */
Packit 8f70b4
Packit 8f70b4
#ifndef GLOB_INTERNAL_H
Packit 8f70b4
# define GLOB_INTERNAL_H
Packit 8f70b4
Packit 8f70b4
enum
Packit 8f70b4
{
Packit 8f70b4
  GLOBPAT_NONE      = 0x0,
Packit 8f70b4
  GLOBPAT_SPECIAL   = 0x1,
Packit 8f70b4
  GLOBPAT_BACKSLASH = 0x2,
Packit 8f70b4
  GLOBPAT_BRACKET   = 0x4
Packit 8f70b4
};
Packit 8f70b4
Packit 8f70b4
static inline int
Packit 8f70b4
__glob_pattern_type (const char *pattern, int quote)
Packit 8f70b4
{
Packit 8f70b4
  const char *p;
Packit 8f70b4
  int ret = GLOBPAT_NONE;
Packit 8f70b4
Packit 8f70b4
  for (p = pattern; *p != '\0'; ++p)
Packit 8f70b4
    switch (*p)
Packit 8f70b4
      {
Packit 8f70b4
      case '?':
Packit 8f70b4
      case '*':
Packit 8f70b4
        return GLOBPAT_SPECIAL;
Packit 8f70b4
Packit 8f70b4
      case '\\':
Packit 8f70b4
        if (quote)
Packit 8f70b4
          {
Packit 8f70b4
            if (p[1] != '\0')
Packit 8f70b4
              ++p;
Packit 8f70b4
            ret |= GLOBPAT_BACKSLASH;
Packit 8f70b4
          }
Packit 8f70b4
        break;
Packit 8f70b4
Packit 8f70b4
      case '[':
Packit 8f70b4
        ret |= GLOBPAT_BRACKET;
Packit 8f70b4
        break;
Packit 8f70b4
Packit 8f70b4
      case ']':
Packit 8f70b4
        if (ret & 4)
Packit 8f70b4
          return GLOBPAT_SPECIAL;
Packit 8f70b4
        break;
Packit 8f70b4
      }
Packit 8f70b4
Packit 8f70b4
  return ret;
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
#endif /* GLOB_INTERNAL_H  */