Some cleanups and re-ordering of parameters to be consistent.

This commit is contained in:
Dave Davenport 2015-11-23 22:14:26 +01:00
parent ad778b7dc1
commit cbba58914f
10 changed files with 41 additions and 50 deletions

View File

@ -79,7 +79,7 @@ typedef enum
*
* @returns 1 when it matches, 0 if not.
*/
typedef int ( *menu_match_cb )( char **tokens, int not_ascii, int case_sensitive, unsigned int index, const Switcher *data );
typedef int ( *menu_match_cb )( const Switcher *data, char **tokens, int not_ascii, int case_sensitive, unsigned int index );
/**
* @param sw the Switcher to show.
@ -289,15 +289,14 @@ struct _Switcher
*/
void ( *init )( struct _Switcher *sw );
unsigned int ( *get_num_entries )( const struct _Switcher *sw );
int ( *match )( char **tokens, const char *input, int case_sensitive, int index, struct _Switcher *data );
SwitcherMode ( *result )( int menu_retv, char **input, unsigned int selected_line, struct _Switcher *pd );
SwitcherMode ( *result )( struct _Switcher *sw, int menu_retv, char **input, unsigned int selected_line );
void ( *destroy )( struct _Switcher *pd );
// Token match.
menu_match_cb token_match;
get_display_value mgrv;
int (*is_not_ascii)( const struct _Switcher *sw, unsigned int index );
int ( *is_not_ascii )( const struct _Switcher *sw, unsigned int index );
// Pointer to private data.
void *private_data;

View File

@ -31,14 +31,14 @@ typedef struct
typedef enum
{
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
} TextboxFlags;
typedef enum

View File

@ -122,7 +122,7 @@ static void combi_mode_init ( Switcher *sw )
}
static unsigned int combi_mode_get_num_entries ( const Switcher *sw )
{
const CombiModePrivateData *pd = (const CombiModePrivateData *)sw->private_data;
const CombiModePrivateData *pd = (const CombiModePrivateData *) sw->private_data;
return pd->cmd_list_length;
}
static void combi_mode_destroy ( Switcher *sw )
@ -140,8 +140,7 @@ static void combi_mode_destroy ( Switcher *sw )
sw->private_data = NULL;
}
}
static SwitcherMode combi_mode_result ( int mretv, char **input, unsigned int selected_line,
Switcher *sw )
static SwitcherMode combi_mode_result ( Switcher *sw, int mretv, char **input, unsigned int selected_line )
{
CombiModePrivateData *pd = sw->private_data;
if ( *input[0] == '!' ) {
@ -156,9 +155,8 @@ static SwitcherMode combi_mode_result ( int mretv, char **input, unsigned int se
// skip whitespace
if ( n != NULL ) {
n++;
return pd->switchers[switcher]->result ( mretv, &n,
selected_line - pd->starts[switcher],
pd->switchers[switcher] );
return pd->switchers[switcher]->result ( pd->switchers[switcher], mretv, &n,
selected_line - pd->starts[switcher] );
}
return MODE_EXIT;
}
@ -167,14 +165,13 @@ static SwitcherMode combi_mode_result ( int mretv, char **input, unsigned int se
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( selected_line >= pd->starts[i] &&
selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
return pd->switchers[i]->result ( mretv, input, selected_line - pd->starts[i],
pd->switchers[i] );
return pd->switchers[i]->result ( pd->switchers[i], mretv, input, selected_line - pd->starts[i] );
}
}
return MODE_EXIT;
}
static int combi_mode_match ( char **tokens, int not_ascii,
int case_sensitive, unsigned int index, const Switcher *sw )
static int combi_mode_match ( const Switcher *sw, char **tokens, int not_ascii,
int case_sensitive, unsigned int index )
{
CombiModePrivateData *pd = sw->private_data;
@ -182,14 +179,14 @@ static int combi_mode_match ( char **tokens, int not_ascii,
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
if ( tokens && tokens[0][0] == '!' ) {
if ( tokens[0][1] == pd->switchers[i]->name[0] ) {
return pd->switchers[i]->token_match ( &tokens[1], not_ascii, case_sensitive,
index - pd->starts[i], pd->switchers[i] );
return pd->switchers[i]->token_match ( pd->switchers[i], &tokens[1], not_ascii, case_sensitive,
index - pd->starts[i] );
}
return 0;
}
else {
return pd->switchers[i]->token_match ( tokens, not_ascii, case_sensitive,
index - pd->starts[i], pd->switchers[i] );
return pd->switchers[i]->token_match ( pd->switchers[i], tokens, not_ascii, case_sensitive,
index - pd->starts[i] );
}
}
}

View File

@ -279,7 +279,7 @@ static void dmenu_mode_init ( Switcher *sw )
pd->cmd_list = get_dmenu ( &( pd->cmd_list_length ) );
}
static int dmenu_token_match ( char **tokens, int not_ascii, int case_sensitive, unsigned int index, const Switcher *sw )
static int dmenu_token_match ( const Switcher *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
{
DmenuModePrivateData *rmpd = (DmenuModePrivateData *) sw->private_data;
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );

View File

@ -235,8 +235,7 @@ static void drun_mode_init ( Switcher *sw )
}
}
static SwitcherMode drun_mode_result ( int mretv, char **input, unsigned int selected_line,
Switcher *sw )
static SwitcherMode drun_mode_result ( Switcher *sw, int mretv, char **input, unsigned int selected_line )
{
DRunModePrivateData *rmpd = (DRunModePrivateData *) sw->private_data;
SwitcherMode retv = MODE_EXIT;
@ -298,11 +297,12 @@ static char *mgrv ( unsigned int selected_line, const Switcher *sw, int *state,
}
}
static int drun_token_match ( char **tokens,
static int drun_token_match ( const Switcher *data,
char **tokens,
int not_ascii,
int case_sensitive,
unsigned int index,
const Switcher *data )
unsigned int index
)
{
DRunModePrivateData *rmpd = (DRunModePrivateData *) data->private_data;
if ( rmpd->entry_list[index].name &&

View File

@ -282,8 +282,7 @@ static unsigned int run_mode_get_num_entries ( const Switcher *sw )
return rmpd->cmd_list_length;
}
static SwitcherMode run_mode_result ( int mretv, char **input, unsigned int selected_line,
Switcher *sw )
static SwitcherMode run_mode_result ( Switcher *sw, int mretv, char **input, unsigned int selected_line )
{
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;
SwitcherMode retv = MODE_EXIT;
@ -332,7 +331,7 @@ static char *mgrv ( unsigned int selected_line, const Switcher *sw, G_GNUC_UNUSE
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
}
static int run_token_match ( char **tokens, int not_ascii, int case_sensitive, unsigned int index, const Switcher *sw )
static int run_token_match ( const Switcher *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
{
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );

View File

@ -111,8 +111,7 @@ static unsigned int script_mode_get_num_entries ( const Switcher *sw )
return rmpd->cmd_list_length;
}
static SwitcherMode script_mode_result ( int mretv, char **input, unsigned int selected_line,
Switcher *sw )
static SwitcherMode script_mode_result ( Switcher *sw, int mretv, char **input, unsigned int selected_line )
{
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
SwitcherMode retv = MODE_EXIT;
@ -163,7 +162,7 @@ static char *mgrv ( unsigned int selected_line, const Switcher *sw, G_GNUC_UNUSE
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
}
static int script_token_match ( char **tokens, int not_ascii, int case_sensitive, unsigned int index, const Switcher *sw )
static int script_token_match ( const Switcher *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
{
ScriptModePrivateData *rmpd = sw->private_data;
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );

View File

@ -336,8 +336,7 @@ static unsigned int ssh_mode_get_num_entries ( const Switcher *sw )
const SSHModePrivateData *rmpd = (const SSHModePrivateData *) sw->private_data;
return rmpd->cmd_list_length;
}
static SwitcherMode ssh_mode_result ( int mretv, char **input, unsigned int selected_line,
Switcher *sw )
static SwitcherMode ssh_mode_result ( Switcher *sw, int mretv, char **input, unsigned int selected_line )
{
SwitcherMode retv = MODE_EXIT;
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
@ -382,7 +381,7 @@ static char *mgrv ( unsigned int selected_line, const Switcher *sw, G_GNUC_UNUSE
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
}
static int ssh_token_match ( char **tokens, int not_ascii, int case_sensitive, unsigned int index, const Switcher *sw )
static int ssh_token_match ( const Switcher *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
{
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );

View File

@ -320,9 +320,9 @@ typedef struct _SwitcherModePrivateData
char *cache;
} SwitcherModePrivateData;
static int window_match ( char **tokens,
static int window_match ( const Switcher *sw, char **tokens,
__attribute__( ( unused ) ) int not_ascii,
int case_sensitive, unsigned int index, const Switcher *sw )
int case_sensitive, unsigned int index )
{
SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data;
int match = 1;
@ -510,9 +510,8 @@ static void window_mode_init_cd ( Switcher *sw )
_window_mode_load_data ( sw, TRUE );
}
}
static SwitcherMode window_mode_result ( int mretv, G_GNUC_UNUSED char **input,
unsigned int selected_line,
Switcher *sw )
static SwitcherMode window_mode_result ( Switcher *sw, int mretv, G_GNUC_UNUSED char **input,
unsigned int selected_line )
{
SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data;
SwitcherMode retv = MODE_EXIT;

View File

@ -756,11 +756,10 @@ static void filter_elements ( thread_state *t, G_GNUC_UNUSED gpointer user_data
// input changed
for ( unsigned int i = t->start; i < t->stop; i++ ) {
int st;
int match = t->state->sw->token_match ( t->tokens,
int match = t->state->sw->token_match ( t->state->sw, t->tokens,
t->state->lines_not_ascii[i],
config.case_sensitive,
i,
t->state->sw );
i );
// If each token was matched, add it to list.
if ( match ) {
t->state->line_map[t->start + t->count] = i;
@ -2234,7 +2233,7 @@ SwitcherMode switcher_run ( char **input, Switcher *sw )
unsigned int selected_line = UINT32_MAX;
int mretv = menu ( sw, input, prompt, &selected_line, NULL, NULL );
g_free ( prompt );
return sw->result ( mretv, input, selected_line, sw );
return sw->result ( sw, mretv, input, selected_line );
}
/**