Skip to content

Commit

Permalink
Preparations to extract possible completions from globit code
Browse files Browse the repository at this point in the history
For #297
  • Loading branch information
Code7R committed Sep 29, 2018
1 parent 8ae9b8b commit eeddcf2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/globit.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* Arguments:
* [in] const char *pattern
* [out] char **result
* [in] void (*callback)(const void *, const char **, unsigned) -- function to run in case there are multiple results (with count) and user specified parameter (first argument)
* [int] const void* cback_user_parm -- first parameter to callback
* Return value:
* (int) number of matches
* + if -1: an error occurred; *result is the error string (or NULL)
Expand Down Expand Up @@ -108,7 +110,8 @@ static bool my_glob_pattern_p(const char *pat, int quote)
/* main function */

int
globit_best(const char *pattern_, char **result)
globit_best(const char *pattern_, char **result,
void(*callback)(const void *, const char * const *, unsigned cnt), const void* cback_user_parm)
{
char c, *cp, **results = NULL;
size_t z, nresults = 0;
Expand Down Expand Up @@ -231,6 +234,7 @@ globit_best(const char *pattern_, char **result)
*result = globit_escape(glob_block.gl_pathv[0]);
break;
default:
if(callback) callback(cback_user_parm, glob_block.gl_pathv, i);
z = globit_pfxlen(glob_block.gl_pathv, i);
if (z == 0) {
i = 0;
Expand Down Expand Up @@ -288,6 +292,7 @@ globit_best(const char *pattern_, char **result)
case 0:
goto ok_out;
default:
if(callback) callback(cback_user_parm, results, i);
z = globit_pfxlen(results, i);
if (z == 0) {
i = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/globit.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
extern "C" {
#endif

extern int globit_best(const char *, char **);
extern int globit_best(const char *, char **,
void(*callback)(const void *, const char * const *, unsigned), const void* cback_user_parm);

#ifdef __cplusplus
}
Expand Down
6 changes: 4 additions & 2 deletions src/yinput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ YInputLine::~YInputLine() {

void YInputLine::setText(const ustring &text) {
fText = text;
markPos = curPos = leftOfs = 0;
markPos = leftOfs = 0;
curPos = fText.length();
limit();
repaint();
Expand Down Expand Up @@ -679,8 +679,10 @@ void YInputLine::autoScroll(int delta, const XMotionEvent *motion) {

void YInputLine::complete() {
char* res = 0;
if (1 <= globit_best(cstring(fText), &res))
if (1 <= globit_best(cstring(fText), &res, 0, 0))
setText(res);
// FIXME: even for max. prefix the text gets marked like for a full match;
// that might be intended or might be a bug in limit() or paint()
free(res);
}

Expand Down

0 comments on commit eeddcf2

Please sign in to comment.