rofi  1.5.1
Helper
Collaboration diagram for Helper:

Functions

int helper_parse_setup (char *string, char ***output, int *length,...)
 
rofi_int_matcher ** helper_tokenize (const char *input, int case_sensitive)
 
void helper_tokenize_free (rofi_int_matcher **tokens)
 
int find_arg_char (const char *const key, char *val)
 
int find_arg_uint (const char *const key, unsigned int *val)
 
int find_arg_int (const char *const key, int *val)
 
int find_arg_str (const char *const key, char **val)
 
const char ** find_arg_strv (const char *const key)
 
int find_arg (const char *const key)
 
int helper_token_match (rofi_int_matcher *const *tokens, const char *input)
 
int execute_generator (const char *cmd) __attribute__((nonnull))
 
int create_pid_file (const char *pidfile)
 
void remove_pid_file (int fd)
 
int config_sanity_check (void)
 
char helper_parse_char (const char *arg)
 
void cmd_set_arguments (int argc, char **argv)
 
char * rofi_expand_path (const char *input)
 
unsigned int levenshtein (const char *needle, const glong needlelen, const char *haystack, const glong haystacklen)
 
char * rofi_force_utf8 (const gchar *data, ssize_t length)
 
char * rofi_latin_to_utf8_strdup (const char *input, gssize length)
 
gchar * rofi_escape_markup (gchar *text)
 
int rofi_scorer_fuzzy_evaluate (const char *pattern, glong plen, const char *str, glong slen)
 

Detailed Description

Function Documentation

◆ cmd_set_arguments()

void cmd_set_arguments ( int  argc,
char **  argv 
)
Parameters
argcnumber of arguments.
argvArray of arguments.

Set the application arguments.

Definition at line 73 of file helper.c.

References stored_argc, and stored_argv.

Referenced by main().

Here is the caller graph for this function:

◆ config_sanity_check()

int config_sanity_check ( void  )

Do some input validation, especially the first few could break things. It is good to catch them beforehand.

This functions exits the program with 1 when it finds an invalid configuration.

Definition at line 574 of file helper.c.

References config, Settings::element_height, Settings::fullscreen, Settings::location, Settings::matching, Settings::matching_method, Settings::menu_columns, Settings::menu_font, Settings::menu_width, MM_FUZZY, MM_GLOB, MM_NORMAL, MM_REGEX, mon, Settings::monitor, monitor_active(), monitor_position_entries, rofi_add_error_message(), and WL_CENTER.

Referenced by startup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_pid_file()

int create_pid_file ( const char *  pidfile)
Parameters
pidfileThe pidfile to create.

returns file descriptor (or -1 when failed)

Definition at line 508 of file helper.c.

References flags, pidfile, and remove_pid_file().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute_generator()

int execute_generator ( const char *  cmd)
Parameters
cmdThe command to execute.

Execute cmd using config.run_command and outputs the result (stdout) to the opened file descriptor.

Returns
a valid file descriptor on success, or -1 on failure.

Definition at line 486 of file helper.c.

References config, helper_parse_setup(), rofi_view_error_dialog(), and Settings::run_command.

Referenced by get_apps_external().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_arg()

int find_arg ( const char *const  key)
Parameters
keyThe key to search for

Check if key is passed as argument.

Returns
return position of string or -1 if not found.

Definition at line 295 of file helper.c.

References stored_argc, and stored_argv.

Referenced by config_parse_cmd_option(), display_late_setup(), dmenu_finalize(), dmenu_mode_init(), dmenu_switcher_dialog(), find_arg_char(), find_arg_int(), find_arg_str(), find_arg_uint(), help(), main(), rofi_collect_modi(), and startup().

Here is the caller graph for this function:

◆ find_arg_char()

int find_arg_char ( const char *const  key,
char *  val 
)
Parameters
keyThe key to search for
valPointer to the string to set to the key value (if found)

Parse command line argument 'key' to character. This one supports character escaping.

Returns
TRUE if key was found and val was set.

Definition at line 399 of file helper.c.

References find_arg(), helper_parse_char(), stored_argc, and stored_argv.

Referenced by config_parse_cmd_option(), and dmenu_mode_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_arg_int()

int find_arg_int ( const char *const  key,
int *  val 
)
Parameters
keyThe key to search for
valPointer to the string to set to the key value (if found)

Parse command line argument 'key' to int.

Returns
TRUE if key was found and val was set.

Definition at line 337 of file helper.c.

References find_arg(), stored_argc, and stored_argv.

Referenced by config_parse_cmd_option().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_arg_str()

int find_arg_str ( const char *const  key,
char **  val 
)
Parameters
keyThe key to search for
valPointer to the string to set to the key value (if found)

Parse command line argument 'key' to string.

Returns
TRUE if key was found and val was set.

Definition at line 305 of file helper.c.

References find_arg(), stored_argc, and stored_argv.

Referenced by config_parse_cmd_option(), display_setup(), dmenu_mode_init(), dmenu_switcher_dialog(), main(), rofi_collect_modi(), and startup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_arg_strv()

const char** find_arg_strv ( const char *const  key)
Parameters
keyThe key to search for

Parse all command line options 'key' to string vector.

Returns
str vector. user should free array.

Definition at line 316 of file helper.c.

References stored_argc, and stored_argv.

Referenced by main().

Here is the caller graph for this function:

◆ find_arg_uint()

int find_arg_uint ( const char *const  key,
unsigned int *  val 
)
Parameters
keyThe key to search for
valPointer to the string to set to the key value (if found)

Parse command line argument 'key' to unsigned int.

Returns
TRUE if key was found and val was set.

Definition at line 347 of file helper.c.

References find_arg(), stored_argc, and stored_argv.

Referenced by config_parse_cmd_option(), dmenu_mode_init(), dmenu_switcher_dialog(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ helper_parse_char()

char helper_parse_char ( const char *  arg)
Parameters
argstring to parse.

Parses a string into an character.

Returns
character.

Definition at line 358 of file helper.c.

Referenced by config_parser_set(), and find_arg_char().

Here is the caller graph for this function:

◆ helper_parse_setup()

int helper_parse_setup ( char *  string,
char ***  output,
int *  length,
  ... 
)
Parameters
stringThe input string.
outputPointer to 2 dimensional array with parsed string.
lengthLength of 2 dimensional array.
...Key, value parse. Replaces the string Key with value.

Parses a string into arguments. While replacing keys with values.

Returns
TRUE when successful, FALSE when failed.

Definition at line 107 of file helper.c.

References config, helper_eval_cb(), rofi_view_error_dialog(), Settings::ssh_client, and Settings::terminal_emulator.

Referenced by execshssh(), execute_generator(), and helper_execute_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ helper_token_match()

int helper_token_match ( rofi_int_matcher *const *  tokens,
const char *  input 
)
Parameters
tokensList of (input) tokens to match.
inputThe entry to match against.

Tokenized match, match tokens to line input.

Returns
TRUE when matches, FALSE otherwise

Definition at line 473 of file helper.c.

Referenced by dmenu_switcher_dialog(), dmenu_token_match(), help_keys_token_match(), run_token_match(), script_token_match(), and ssh_token_match().

Here is the caller graph for this function:

◆ helper_tokenize()

rofi_int_matcher** helper_tokenize ( const char *  input,
int  case_sensitive 
)
Parameters
inputThe input string.
case_sensitiveWhether case is significant.

Tokenize the string on spaces.

Returns
a newly allocated array of matching objects

Definition at line 256 of file helper.c.

References config, create_regex(), and Settings::tokenize.

Referenced by dmenu_switcher_dialog(), and rofi_view_refilter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ helper_tokenize_free()

void helper_tokenize_free ( rofi_int_matcher **  tokens)
Parameters
tokensArray of regex objects

Frees the array of matching objects.

Definition at line 155 of file helper.c.

Referenced by dmenu_switcher_dialog(), rofi_view_free(), and rofi_view_refilter().

Here is the caller graph for this function:

◆ levenshtein()

unsigned int levenshtein ( const char *  needle,
const glong  needlelen,
const char *  haystack,
const glong  haystacklen 
)
Parameters
needleThe string to find match weight off
needlelenThe length of the needle
haystackThe string to match against
haystacklenThe length of the haystack

UTF-8 aware levenshtein distance calculation

Returns
the levenshtein distance between needle and haystack

Definition at line 702 of file helper.c.

References Settings::case_sensitive, config, and MIN3.

Referenced by filter_elements().

Here is the caller graph for this function:

◆ remove_pid_file()

void remove_pid_file ( int  fd)

Remove pid file

Definition at line 547 of file helper.c.

Referenced by create_pid_file(), and teardown().

Here is the caller graph for this function:

◆ rofi_escape_markup()

gchar* rofi_escape_markup ( gchar *  text)
Parameters
textthe string to escape

Escape XML markup from the string.

Parameters
textis freed.
Returns
the escaped string

Definition at line 743 of file helper.c.

◆ rofi_expand_path()

char* rofi_expand_path ( const char *  input)
Parameters
inputThe path to expand

Expand path, both ~ and ~<user>

Returns
path

Definition at line 669 of file helper.c.

Referenced by dmenu_mode_init(), get_apps(), helper_get_theme_path(), main(), parse_ssh_config_file(), rofi_theme_parse_prepare_file(), rofi_view_setup_fake_transparency(), and script_switcher_parse_setup().

Here is the caller graph for this function:

◆ rofi_force_utf8()

char* rofi_force_utf8 ( const gchar *  data,
ssize_t  length 
)
Parameters
datathe unvalidated character array holding possible UTF-8 data
lengththe length of the data array

Convert string to valid utf-8, replacing invalid parts with replacement character.

Returns
the converted UTF-8 string

Definition at line 753 of file helper.c.

Referenced by read_add().

Here is the caller graph for this function:

◆ rofi_latin_to_utf8_strdup()

char* rofi_latin_to_utf8_strdup ( const char *  input,
gssize  length 
)
Parameters
inputthe char array holding latin text
lengththe length of the data array

Converts latin to UTF-8.

Returns
the UTF-8 representation of data

Definition at line 737 of file helper.c.

Referenced by window_get_text_prop().

Here is the caller graph for this function:

◆ rofi_scorer_fuzzy_evaluate()

int rofi_scorer_fuzzy_evaluate ( const char *  pattern,
glong  plen,
const char *  str,
glong  slen 
)
Parameters
patternThe user input to match against.
plenPattern length.
strThe input to match against pattern.
slenLength of str.

FZF like fuzzy sorting algorithm.

Returns
the sorting weight.
Parameters
patternThe user input to match against.
plenPattern length.
strThe input to match against pattern.
slenLength of str.

rofi_scorer_fuzzy_evaluate implements a global sequence alignment algorithm to find the maximum accumulated score by aligning pattern to str. It applies when pattern is a subsequence of str.

Scoring criteria

  • Prefer matches at the start of a word, or the start of subwords in CamelCase/camelCase/camel123 words. See WORD_START_SCORE/CAMEL_SCORE.
  • Non-word characters matter. See NON_WORD_SCORE.
  • The first characters of words of pattern receive bonus because they usually have more significance than the rest. See PATTERN_START_MULTIPLIER/PATTERN_NON_START_MULTIPLIER.
  • Superfluous characters in str will reduce the score (gap penalty). See GAP_SCORE.
  • Prefer early occurrence of the first character. See LEADING_GAP_SCORE/GAP_SCORE.

The recurrence of the dynamic programming: dp[i][j]: maximum accumulated score by aligning pattern[0..i] to str[0..j] dp[0][j] = leading_gap_penalty(0, j) + score[j] dp[i][j] = max(dp[i-1][j-1] + CONSECUTIVE_SCORE, max(dp[i-1][k] + gap_penalty(k+1, j) + score[j] : k < j))

The first dimension can be suppressed since we do not need a matching scheme, which reduces the space complexity from O(N*M) to O(M)

Returns
the sorting weight.

Definition at line 891 of file helper.c.

References Settings::case_sensitive, config, CONSECUTIVE_SCORE, FUZZY_SCORER_MAX_LENGTH, GAP_SCORE, LEADING_GAP_SCORE, MIN_SCORE, NON_WORD, PATTERN_NON_START_MULTIPLIER, PATTERN_START_MULTIPLIER, rofi_scorer_get_character_class(), and rofi_scorer_get_score_for().

Referenced by filter_elements().

Here is the call graph for this function:
Here is the caller graph for this function: