2012-11-18 18:23:22 +08:00
|
|
|
/** \file wildcard.h
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
My own globbing implementation. Needed to implement this instead
|
2005-12-07 23:57:17 +08:00
|
|
|
of using libs globbing to support tab-expansion of globbed
|
2005-09-20 21:26:39 +08:00
|
|
|
paramaters.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#ifndef FISH_WILDCARD_H
|
2005-10-24 23:26:25 +08:00
|
|
|
/**
|
|
|
|
Header guard
|
|
|
|
*/
|
2005-10-04 23:11:39 +08:00
|
|
|
#define FISH_WILDCARD_H
|
|
|
|
|
|
|
|
#include <wchar.h>
|
2011-12-27 11:18:46 +08:00
|
|
|
#include <vector>
|
2005-10-04 23:11:39 +08:00
|
|
|
|
|
|
|
#include "util.h"
|
2011-12-27 11:18:46 +08:00
|
|
|
#include "common.h"
|
2012-02-25 04:13:35 +08:00
|
|
|
#include "expand.h"
|
2013-05-26 06:41:18 +08:00
|
|
|
#include "complete.h"
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/*
|
2005-10-20 19:27:54 +08:00
|
|
|
Use unencoded private-use keycodes for internal characters
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
|
|
|
|
2005-10-20 19:27:54 +08:00
|
|
|
#define WILDCARD_RESERVED 0xf400
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-02-02 08:27:14 +08:00
|
|
|
class completion_t;
|
2005-10-24 23:26:25 +08:00
|
|
|
/**
|
|
|
|
Enumeration of all wildcard types
|
|
|
|
*/
|
2005-10-20 19:27:54 +08:00
|
|
|
enum
|
|
|
|
{
|
2012-11-19 08:30:30 +08:00
|
|
|
/** Character representing any character except '/' */
|
|
|
|
ANY_CHAR = WILDCARD_RESERVED,
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
/** Character representing any character string not containing '/' (A slash) */
|
|
|
|
ANY_STRING,
|
2005-10-20 19:27:54 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
/** Character representing any character string */
|
|
|
|
ANY_STRING_RECURSIVE,
|
2005-10-20 19:27:54 +08:00
|
|
|
}
|
2012-11-19 08:30:30 +08:00
|
|
|
;
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
/**
|
2012-11-18 18:23:22 +08:00
|
|
|
Expand the wildcard by matching against the filesystem.
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-11-18 18:23:22 +08:00
|
|
|
New strings are allocated using malloc and should be freed by the caller.
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-11-18 18:23:22 +08:00
|
|
|
wildcard_expand works by dividing the wildcard into segments at
|
|
|
|
each directory boundary. Each segment is processed separatly. All
|
|
|
|
except the last segment are handled by matching the wildcard
|
|
|
|
segment against all subdirectories of matching directories, and
|
|
|
|
recursively calling wildcard_expand for matches. On the last
|
|
|
|
segment, matching is made to any file, and all matches are
|
|
|
|
inserted to the list.
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-11-18 18:23:22 +08:00
|
|
|
If wildcard_expand encounters any errors (such as insufficient
|
|
|
|
priviliges) during matching, no error messages will be printed and
|
|
|
|
wildcard_expand will continue the matching process.
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-11-18 18:23:22 +08:00
|
|
|
\param wc The wildcard string
|
|
|
|
\param base_dir The base directory of the filesystem to perform the match against
|
|
|
|
\param flags flags for the search. Can be any combination of ACCEPT_INCOMPLETE and EXECUTABLES_ONLY
|
|
|
|
\param out The list in which to put the output
|
|
|
|
|
|
|
|
\return 1 if matches where found, 0 otherwise. Return -1 on abort (I.e. ^C was pressed).
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
int wildcard_expand_string(const wcstring &wc, const wcstring &base_dir, expand_flags_t flags, std::vector<completion_t> &out);
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
2012-02-27 05:27:31 +08:00
|
|
|
Test whether the given wildcard matches the string. Does not perform any I/O.
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
\param str The string to test
|
|
|
|
\param wc The wildcard to test against
|
2013-04-21 03:41:02 +08:00
|
|
|
\param leading_dots_fail_to_match if set, strings with leading dots are assumed to be hidden files and are not matched
|
2005-09-20 21:26:39 +08:00
|
|
|
\return true if the wildcard matched
|
|
|
|
*/
|
2013-04-21 03:41:02 +08:00
|
|
|
bool wildcard_match(const wcstring &str, const wcstring &wc, bool leading_dots_fail_to_match = false);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2013-05-26 06:41:18 +08:00
|
|
|
/** Check if the specified string contains wildcards */
|
2014-08-25 05:28:31 +08:00
|
|
|
bool wildcard_has(const wcstring &, bool internal);
|
|
|
|
bool wildcard_has(const wchar_t *, bool internal);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
/**
|
2014-09-25 13:01:33 +08:00
|
|
|
Matches the string against the wildcard, and if the wildcard is a
|
|
|
|
possible completion of the string, the remainder of the string is
|
|
|
|
inserted into the out vector.
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
2012-05-09 17:33:42 +08:00
|
|
|
bool wildcard_complete(const wcstring &str,
|
2012-11-19 08:30:30 +08:00
|
|
|
const wchar_t *wc,
|
|
|
|
const wchar_t *desc,
|
|
|
|
wcstring(*desc_func)(const wcstring &),
|
|
|
|
std::vector<completion_t> &out,
|
2013-05-26 06:41:18 +08:00
|
|
|
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
|