1 /* gmisc.c -- miscellaneous pattern matching utility functions for Bush.
3 Copyright (C) 2010-2020 Free Software Foundation, Inc.
5 This file is part of GNU Bush, the Bourne-Again SHell.
7 Bush is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bush is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bush. If not, see <http://www.gnu.org/licenses/>.
23 #include "bushtypes.h"
25 #if defined (HAVE_UNISTD_H)
31 #include "chartypes.h"
36 # include "strmatch.h"
40 /* Make sure these names continue to agree with what's in smatch.c */
41 extern char *glob_patscan
PARAMS((char *, char *, int));
43 /* Compile `gm_loop.c' for single-byte characters. */
47 #define EXTGLOB_PATTERN_P extglob_pattern_p
48 #define MATCH_PATTERN_CHAR match_pattern_char
49 #define MATCHLEN umatchlen
50 #define FOLD(c) ((flags & FNM_CASEFOLD) \
51 ? TOLOWER ((unsigned char)c) \
59 /* Compile `gm_loop.c' again for multibyte characters. */
65 #define EXTGLOB_PATTERN_P wextglob_pattern_p
66 #define MATCH_PATTERN_CHAR match_pattern_wchar
67 #define MATCHLEN wmatchlen
69 #define FOLD(c) ((flags & FNM_CASEFOLD) && iswupper (c) ? towlower (c) : (c))
74 #endif /* HANDLE_MULTIBYTE */
77 #if defined (EXTENDED_GLOB)
78 /* Skip characters in PAT and return the final occurrence of DIRSEP. This
79 is only called when extended_glob is set, so we have to skip over extglob
82 glob_dirscan (pat
, dirsep
)
86 char *p
, *d
, *pe
, *se
;
89 for (p
= pat
; p
&& *p
; p
++)
91 if (extglob_pattern_p (p
))
94 se
= p
+ strlen (p
) - 1;
95 pe
= glob_patscan (p
+ 2, se
, 0);
100 p
= pe
- 1; /* will do increment above */
108 #endif /* EXTENDED_GLOB */