]>
| Commit | Line | Data |
|---|---|---|
| 1 | /* pathexp.h -- The shell interface to the globbing library. */ | |
| 2 | ||
| 3 | /* Copyright (C) 1987-2023 Free Software Foundation, Inc. | |
| 4 | ||
| 5 | This file is part of GNU Bash, the Bourne Again SHell. | |
| 6 | ||
| 7 | Bash 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. | |
| 11 | ||
| 12 | Bash 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. | |
| 16 | ||
| 17 | You should have received a copy of the GNU General Public License | |
| 18 | along with Bash. If not, see <http://www.gnu.org/licenses/>. | |
| 19 | */ | |
| 20 | ||
| 21 | #if !defined (_PATHEXP_H_) | |
| 22 | #define _PATHEXP_H_ | |
| 23 | ||
| 24 | #define GLOB_FAILED(glist) (glist) == (char **)&glob_error_return | |
| 25 | ||
| 26 | extern int noglob_dot_filenames; | |
| 27 | extern char *glob_error_return; | |
| 28 | ||
| 29 | /* Flag values for quote_string_for_globbing */ | |
| 30 | #define QGLOB_CVTNULL 0x01 /* convert QUOTED_NULL strings to '\0' */ | |
| 31 | #define QGLOB_FILENAME 0x02 /* do correct quoting for matching filenames */ | |
| 32 | #define QGLOB_REGEXP 0x04 /* quote an ERE for regcomp/regexec */ | |
| 33 | #define QGLOB_CTLESC 0x08 /* turn CTLESC CTLESC into CTLESC for BREs */ | |
| 34 | #define QGLOB_DEQUOTE 0x10 /* like dequote_string but quote glob chars */ | |
| 35 | ||
| 36 | #if defined (EXTENDED_GLOB) | |
| 37 | /* Flags to OR with other flag args to strmatch() to enabled the extended | |
| 38 | pattern matching. */ | |
| 39 | # define FNMATCH_EXTFLAG (extended_glob ? FNM_EXTMATCH : 0) | |
| 40 | #else | |
| 41 | # define FNMATCH_EXTFLAG 0 | |
| 42 | #endif /* !EXTENDED_GLOB */ | |
| 43 | ||
| 44 | #define FNMATCH_IGNCASE (match_ignore_case ? FNM_CASEFOLD : 0) | |
| 45 | #define FNMATCH_NOCASEGLOB (glob_ignore_case ? FNM_CASEFOLD : 0) | |
| 46 | ||
| 47 | extern int glob_dot_filenames; | |
| 48 | extern int extended_glob; | |
| 49 | extern int glob_star; | |
| 50 | extern int match_ignore_case; /* doesn't really belong here */ | |
| 51 | ||
| 52 | extern int unquoted_glob_pattern_p (char *); | |
| 53 | ||
| 54 | /* PATHNAME can contain characters prefixed by CTLESC; this indicates | |
| 55 | that the character is to be quoted. We quote it here in the style | |
| 56 | that the glob library recognizes. If flags includes QGLOB_CVTNULL, | |
| 57 | we change quoted null strings (pathname[0] == CTLNUL) into empty | |
| 58 | strings (pathname[0] == 0). If this is called after quote removal | |
| 59 | is performed, (flags & QGLOB_CVTNULL) should be 0; if called when quote | |
| 60 | removal has not been done (for example, before attempting to match a | |
| 61 | pattern while executing a case statement), flags should include | |
| 62 | QGLOB_CVTNULL. If flags includes QGLOB_FILENAME, appropriate quoting | |
| 63 | to match a filename should be performed. */ | |
| 64 | extern char *quote_string_for_globbing (const char *, int); | |
| 65 | ||
| 66 | extern int glob_char_p (const char *); | |
| 67 | extern char *quote_globbing_chars (const char *); | |
| 68 | ||
| 69 | /* Call the glob library to do globbing on PATHNAME. FLAGS is additional | |
| 70 | flags to pass to QUOTE_STRING_FOR_GLOBBING, mostly having to do with | |
| 71 | whether or not we've already performed quote removal. */ | |
| 72 | extern char **shell_glob_filename (const char *, int); | |
| 73 | ||
| 74 | extern char **noquote_glob_filename (char *); | |
| 75 | ||
| 76 | /* Filename completion ignore. Used to implement the "fignore" facility of | |
| 77 | tcsh, GLOBIGNORE (like ksh-93 FIGNORE), and EXECIGNORE. | |
| 78 | ||
| 79 | It is passed a NULL-terminated array of (char *)'s that must be | |
| 80 | free()'d if they are deleted. The first element (names[0]) is the | |
| 81 | least-common-denominator string of the matching patterns (i.e. | |
| 82 | u<TAB> produces names[0] = "und", names[1] = "under.c", names[2] = | |
| 83 | "undun.c", name[3] = NULL). */ | |
| 84 | ||
| 85 | struct ign { | |
| 86 | char *val; | |
| 87 | size_t len; | |
| 88 | int flags; | |
| 89 | }; | |
| 90 | ||
| 91 | typedef int sh_iv_item_func_t (struct ign *); | |
| 92 | ||
| 93 | struct ignorevar { | |
| 94 | char *varname; /* FIGNORE, GLOBIGNORE, or EXECIGNORE */ | |
| 95 | struct ign *ignores; /* Store the ignore strings here */ | |
| 96 | int num_ignores; /* How many are there? */ | |
| 97 | char *last_ignoreval; /* Last value of variable - cached for speed */ | |
| 98 | sh_iv_item_func_t *item_func; /* Called when each item is parsed from $`varname' */ | |
| 99 | }; | |
| 100 | ||
| 101 | extern void setup_ignore_patterns (struct ignorevar *); | |
| 102 | ||
| 103 | extern void setup_glob_ignore (const char *); | |
| 104 | extern int should_ignore_glob_matches (void); | |
| 105 | extern void ignore_glob_matches (char **); | |
| 106 | ||
| 107 | /* Definitions for glob sorting */ | |
| 108 | #define SORT_NONE 0 | |
| 109 | #define SORT_NAME 1 | |
| 110 | #define SORT_SIZE 2 | |
| 111 | #define SORT_MTIME 3 | |
| 112 | #define SORT_ATIME 4 | |
| 113 | #define SORT_CTIME 5 | |
| 114 | #define SORT_BLOCKS 6 | |
| 115 | #define SORT_NUMERIC 7 | |
| 116 | #define SORT_NOSORT 8 | |
| 117 | ||
| 118 | #define SORT_REVERSE 128 | |
| 119 | ||
| 120 | extern void setup_globsort (const char *); | |
| 121 | ||
| 122 | #endif |