2016-05-04 06:18:24 +08:00
|
|
|
// My own globbing implementation. Needed to implement this instead of using libs globbing to
|
2019-11-25 19:03:25 +08:00
|
|
|
// support tab-expansion of globbed parameters.
|
2005-10-04 23:11:39 +08:00
|
|
|
#ifndef FISH_WILDCARD_H
|
|
|
|
#define FISH_WILDCARD_H
|
|
|
|
|
2016-05-04 06:18:24 +08:00
|
|
|
#include <vector>
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2011-12-27 11:18:46 +08:00
|
|
|
#include "common.h"
|
2013-05-26 06:41:18 +08:00
|
|
|
#include "complete.h"
|
2016-05-04 06:18:24 +08:00
|
|
|
#include "expand.h"
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2021-11-04 19:05:12 +08:00
|
|
|
/// Description for generic executable.
|
2021-11-04 21:17:47 +08:00
|
|
|
#define COMPLETE_EXEC_DESC _(L"command")
|
2021-11-04 19:05:12 +08:00
|
|
|
/// Description for link to executable.
|
2021-11-04 21:17:47 +08:00
|
|
|
#define COMPLETE_EXEC_LINK_DESC _(L"command link")
|
2021-11-04 19:05:12 +08:00
|
|
|
/// Description for character device.
|
|
|
|
#define COMPLETE_CHAR_DESC _(L"char device")
|
|
|
|
/// Description for block device.
|
|
|
|
#define COMPLETE_BLOCK_DESC _(L"block device")
|
|
|
|
/// Description for fifo buffer.
|
|
|
|
#define COMPLETE_FIFO_DESC _(L"fifo")
|
|
|
|
/// Description for fifo buffer.
|
|
|
|
#define COMPLETE_FILE_DESC _(L"file")
|
|
|
|
/// Description for symlink.
|
|
|
|
#define COMPLETE_SYMLINK_DESC _(L"symlink")
|
|
|
|
/// Description for symlink.
|
|
|
|
#define COMPLETE_DIRECTORY_SYMLINK_DESC _(L"dir symlink")
|
|
|
|
/// Description for Rotten symlink.
|
2021-11-20 03:51:48 +08:00
|
|
|
#define COMPLETE_BROKEN_SYMLINK_DESC _(L"broken symlink")
|
2021-11-04 19:05:12 +08:00
|
|
|
/// Description for symlink loop.
|
|
|
|
#define COMPLETE_LOOP_SYMLINK_DESC _(L"symlink loop")
|
|
|
|
/// Description for socket files.
|
|
|
|
#define COMPLETE_SOCKET_DESC _(L"socket")
|
|
|
|
/// Description for directories.
|
|
|
|
#define COMPLETE_DIRECTORY_DESC _(L"directory")
|
|
|
|
|
2016-05-04 06:18:24 +08:00
|
|
|
// Enumeration of all wildcard types.
|
|
|
|
enum {
|
2018-05-06 10:11:57 +08:00
|
|
|
/// Character representing any character except '/' (slash).
|
|
|
|
ANY_CHAR = WILDCARD_RESERVED_BASE,
|
2016-05-04 06:18:24 +08:00
|
|
|
/// Character representing any character string not containing '/' (slash).
|
2018-05-06 10:11:57 +08:00
|
|
|
ANY_STRING,
|
2016-05-04 06:18:24 +08:00
|
|
|
/// Character representing any character string.
|
2012-11-19 08:30:30 +08:00
|
|
|
ANY_STRING_RECURSIVE,
|
2019-11-25 19:03:25 +08:00
|
|
|
/// This is a special pseudo-char that is not used other than to mark the
|
2016-05-04 06:18:24 +08:00
|
|
|
/// end of the the special characters so we can sanity check the enum range.
|
2020-03-01 07:56:52 +08:00
|
|
|
ANY_SENTINEL
|
2016-01-22 11:56:39 +08:00
|
|
|
};
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2016-05-04 06:18:24 +08:00
|
|
|
/// Expand the wildcard by matching against the filesystem.
|
|
|
|
///
|
|
|
|
/// wildcard_expand works by dividing the wildcard into segments at each directory boundary. Each
|
2020-12-29 03:08:54 +08:00
|
|
|
/// segment is processed separately. All except the last segment are handled by matching the
|
|
|
|
/// wildcard segment against all subdirectories of matching directories, and recursively calling
|
2016-05-04 06:18:24 +08:00
|
|
|
/// wildcard_expand for matches. On the last segment, matching is made to any file, and all matches
|
|
|
|
/// are inserted to the list.
|
|
|
|
///
|
2019-11-25 19:03:25 +08:00
|
|
|
/// If wildcard_expand encounters any errors (such as insufficient privileges) during matching, no
|
2016-05-04 06:18:24 +08:00
|
|
|
/// error messages will be printed and wildcard_expand will continue the matching process.
|
|
|
|
///
|
|
|
|
/// \param wc The wildcard string
|
|
|
|
/// \param working_directory The working directory
|
2019-04-26 02:34:49 +08:00
|
|
|
/// \param flags flags for the search. Can be any combination of for_completions and
|
|
|
|
/// executables_only
|
2020-12-02 05:19:34 +08:00
|
|
|
/// \param output The list in which to put the output
|
2016-05-04 06:18:24 +08:00
|
|
|
///
|
2020-12-06 05:07:19 +08:00
|
|
|
enum class wildcard_result_t {
|
2020-01-16 03:09:09 +08:00
|
|
|
no_match, /// The wildcard did not match.
|
|
|
|
match, /// The wildcard did match.
|
|
|
|
cancel, /// Expansion was cancelled (e.g. control-C).
|
2020-12-04 04:04:17 +08:00
|
|
|
overflow, /// Expansion produced too many results.
|
2020-01-16 03:09:09 +08:00
|
|
|
};
|
2020-12-06 05:07:19 +08:00
|
|
|
wildcard_result_t wildcard_expand_string(const wcstring &wc, const wcstring &working_directory,
|
|
|
|
expand_flags_t flags,
|
|
|
|
const cancel_checker_t &cancel_checker,
|
|
|
|
completion_receiver_t *output);
|
2016-05-04 06:18:24 +08:00
|
|
|
|
|
|
|
/// Test whether the given wildcard matches the string. Does not perform any I/O.
|
|
|
|
///
|
|
|
|
/// \param str The string to test
|
|
|
|
/// \param wc The wildcard to test against
|
|
|
|
/// \param leading_dots_fail_to_match if set, strings with leading dots are assumed to be hidden
|
|
|
|
/// files and are not matched
|
|
|
|
///
|
|
|
|
/// \return true if the wildcard matched
|
|
|
|
bool wildcard_match(const wcstring &str, const wcstring &wc,
|
|
|
|
bool leading_dots_fail_to_match = false);
|
|
|
|
|
2021-11-28 04:46:15 +08:00
|
|
|
// Check if the string has any unescaped wildcards (e.g. ANY_STRING).
|
|
|
|
bool wildcard_has_internal(const wchar_t *s, size_t len);
|
|
|
|
inline bool wildcard_has_internal(const wcstring &s) {
|
|
|
|
return wildcard_has_internal(s.c_str(), s.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Check if the specified string contains wildcards (e.g. *).
|
|
|
|
bool wildcard_has(const wchar_t *s, size_t len);
|
|
|
|
inline bool wildcard_has(const wcstring &s) { return wildcard_has(s.c_str(), s.size()); }
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2016-05-04 06:18:24 +08:00
|
|
|
/// Test wildcard completion.
|
2020-12-06 05:07:19 +08:00
|
|
|
wildcard_result_t wildcard_complete(const wcstring &str, const wchar_t *wc,
|
|
|
|
const description_func_t &desc_func, completion_receiver_t *out,
|
|
|
|
expand_flags_t expand_flags, complete_flags_t flags);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#endif
|