2011-12-27 03:18:46 +00:00
|
|
|
/** \file wildcard.h
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
My own globbing implementation. Needed to implement this instead
|
2005-12-07 15:57:17 +00:00
|
|
|
of using libs globbing to support tab-expansion of globbed
|
2005-09-20 13:26:39 +00:00
|
|
|
paramaters.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2005-10-04 15:11:39 +00:00
|
|
|
#ifndef FISH_WILDCARD_H
|
2005-10-24 15:26:25 +00:00
|
|
|
/**
|
|
|
|
Header guard
|
|
|
|
*/
|
2005-10-04 15:11:39 +00:00
|
|
|
#define FISH_WILDCARD_H
|
|
|
|
|
|
|
|
#include <wchar.h>
|
2011-12-27 03:18:46 +00:00
|
|
|
#include <vector>
|
2005-10-04 15:11:39 +00:00
|
|
|
|
|
|
|
#include "util.h"
|
2011-12-27 03:18:46 +00:00
|
|
|
#include "common.h"
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/*
|
2005-10-20 11:27:54 +00:00
|
|
|
Use unencoded private-use keycodes for internal characters
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
|
|
|
|
2005-10-20 11:27:54 +00:00
|
|
|
#define WILDCARD_RESERVED 0xf400
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2012-02-02 00:27:14 +00:00
|
|
|
class completion_t;
|
2005-10-24 15:26:25 +00:00
|
|
|
/**
|
|
|
|
Enumeration of all wildcard types
|
|
|
|
*/
|
2005-10-20 11:27:54 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
/** Character representing any character except '/' */
|
|
|
|
ANY_CHAR = WILDCARD_RESERVED,
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2005-10-20 11:27:54 +00:00
|
|
|
/** Character representing any character string not containing '/' (A slash) */
|
|
|
|
ANY_STRING,
|
|
|
|
|
|
|
|
/** Character representing any character string */
|
|
|
|
ANY_STRING_RECURSIVE,
|
|
|
|
}
|
|
|
|
;
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
2011-12-27 03:18:46 +00:00
|
|
|
Expand the wildcard by matching against the filesystem.
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
New strings are allocated using malloc and should be freed by the caller.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
\param wc The wildcard string
|
|
|
|
\param base_dir The base directory of the filesystem to perform the match against
|
2006-06-17 13:07:08 +00:00
|
|
|
\param flags flags for the search. Can be any combination of ACCEPT_INCOMPLETE and EXECUTABLES_ONLY
|
2005-09-20 13:26:39 +00:00
|
|
|
\param out The list in which to put the output
|
|
|
|
|
2007-01-09 16:47:05 +00:00
|
|
|
\return 1 if matches where found, 0 otherwise. Return -1 on abort (I.e. ^C was pressed).
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2012-01-16 16:56:47 +00:00
|
|
|
int wildcard_expand_string(const wcstring &wc, const wcstring &base_dir, int flags, std::vector<completion_t> &out );
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
|
|
|
Test whether the given wildcard matches the string
|
|
|
|
|
|
|
|
\param str The string to test
|
|
|
|
\param wc The wildcard to test against
|
|
|
|
\return true if the wildcard matched
|
|
|
|
*/
|
2012-02-08 01:06:45 +00:00
|
|
|
int wildcard_match( const wcstring &str, const wcstring &wc );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Check if the specified string contains wildcards
|
|
|
|
*/
|
|
|
|
int wildcard_has( const wchar_t *str, int internal );
|
|
|
|
|
|
|
|
/**
|
|
|
|
Test wildcard completion
|
|
|
|
*/
|
|
|
|
int wildcard_complete( const wchar_t *str,
|
2007-02-25 09:05:24 +00:00
|
|
|
const wchar_t *wc,
|
2011-12-27 03:18:46 +00:00
|
|
|
const wchar_t *desc,
|
2012-02-19 17:25:15 +00:00
|
|
|
const wchar_t *(*desc_func)(const wcstring &),
|
2012-01-16 16:56:47 +00:00
|
|
|
std::vector<completion_t> &out,
|
2007-02-25 09:05:24 +00:00
|
|
|
int flags );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2005-10-04 15:11:39 +00:00
|
|
|
#endif
|