From eeddcf2b96e042598b28d1f6dc5c7d874596daf3 Mon Sep 17 00:00:00 2001 From: Eduard Bloch Date: Sun, 30 Sep 2018 00:27:55 +0200 Subject: [PATCH] Preparations to extract possible completions from globit code For #297 --- src/globit.c | 7 ++++++- src/globit.h | 3 ++- src/yinput.cc | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/globit.c b/src/globit.c index 726c8bd80..ef7fa1f36 100644 --- a/src/globit.c +++ b/src/globit.c @@ -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) @@ -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; @@ -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; @@ -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; diff --git a/src/globit.h b/src/globit.h index 941358f28..4845dadd0 100644 --- a/src/globit.h +++ b/src/globit.h @@ -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 } diff --git a/src/yinput.cc b/src/yinput.cc index e5995c516..2545b323f 100644 --- a/src/yinput.cc +++ b/src/yinput.cc @@ -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(); @@ -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); }