2016-05-03 22:18:24 +00:00
|
|
|
// My own globbing implementation. Needed to implement this instead of using libs globbing to
|
2019-11-25 11:03:25 +00:00
|
|
|
// support tab-expansion of globbed parameters.
|
2005-10-04 15:11:39 +00:00
|
|
|
#ifndef FISH_WILDCARD_H
|
|
|
|
#define FISH_WILDCARD_H
|
|
|
|
|
2022-08-21 06:14:48 +00:00
|
|
|
#include <stddef.h>
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2011-12-27 03:18:46 +00:00
|
|
|
#include "common.h"
|
2013-05-25 22:41:18 +00:00
|
|
|
#include "complete.h"
|
2016-05-03 22:18:24 +00:00
|
|
|
#include "expand.h"
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2021-11-04 11:05:12 +00:00
|
|
|
/// Description for generic executable.
|
2021-11-04 13:17:47 +00:00
|
|
|
#define COMPLETE_EXEC_DESC _(L"command")
|
2021-11-04 11:05:12 +00:00
|
|
|
/// Description for link to executable.
|
2021-11-04 13:17:47 +00:00
|
|
|
#define COMPLETE_EXEC_LINK_DESC _(L"command link")
|
2021-11-04 11:05:12 +00: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-19 19:51:48 +00:00
|
|
|
#define COMPLETE_BROKEN_SYMLINK_DESC _(L"broken symlink")
|
2021-11-04 11:05:12 +00: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-03 22:18:24 +00:00
|
|
|
// Enumeration of all wildcard types.
|
|
|
|
enum {
|
2018-05-06 02:11:57 +00:00
|
|
|
/// Character representing any character except '/' (slash).
|
|
|
|
ANY_CHAR = WILDCARD_RESERVED_BASE,
|
2016-05-03 22:18:24 +00:00
|
|
|
/// Character representing any character string not containing '/' (slash).
|
2018-05-06 02:11:57 +00:00
|
|
|
ANY_STRING,
|
2016-05-03 22:18:24 +00:00
|
|
|
/// Character representing any character string.
|
2012-11-19 00:30:30 +00:00
|
|
|
ANY_STRING_RECURSIVE,
|
2019-11-25 11:03:25 +00:00
|
|
|
/// This is a special pseudo-char that is not used other than to mark the
|
2016-05-03 22:18:24 +00:00
|
|
|
/// end of the the special characters so we can sanity check the enum range.
|
2020-02-29 23:56:52 +00:00
|
|
|
ANY_SENTINEL
|
2016-01-22 03:56:39 +00:00
|
|
|
};
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2016-05-03 22:18:24 +00: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-28 19:08:54 +00: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-03 22:18:24 +00: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 11:03:25 +00:00
|
|
|
/// If wildcard_expand encounters any errors (such as insufficient privileges) during matching, no
|
2016-05-03 22:18:24 +00: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-25 18:34:49 +00:00
|
|
|
/// \param flags flags for the search. Can be any combination of for_completions and
|
|
|
|
/// executables_only
|
2020-12-01 21:19:34 +00:00
|
|
|
/// \param output The list in which to put the output
|
2016-05-03 22:18:24 +00:00
|
|
|
///
|
2020-12-05 21:07:19 +00:00
|
|
|
enum class wildcard_result_t {
|
2020-01-15 19:09:09 +00:00
|
|
|
no_match, /// The wildcard did not match.
|
|
|
|
match, /// The wildcard did match.
|
|
|
|
cancel, /// Expansion was cancelled (e.g. control-C).
|
2020-12-03 20:04:17 +00:00
|
|
|
overflow, /// Expansion produced too many results.
|
2020-01-15 19:09:09 +00:00
|
|
|
};
|
2020-12-05 21:07:19 +00: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-03 22:18:24 +00: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-27 20:46:15 +00: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 13:26:39 +00:00
|
|
|
|
2016-05-03 22:18:24 +00:00
|
|
|
/// Test wildcard completion.
|
2020-12-05 21:07:19 +00: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 13:26:39 +00:00
|
|
|
|
2005-10-04 15:11:39 +00:00
|
|
|
#endif
|