rofi  1.7.0
helper.c File Reference
#include "config.h"
#include "display.h"
#include "helper-theme.h"
#include "rofi.h"
#include "settings.h"
#include "view.h"
#include "xcb.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <limits.h>
#include <pango/pango-fontmap.h>
#include <pango/pango.h>
#include <pango/pangocairo.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
Include dependency graph for helper.c:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "Helper"
 
#define MIN3(a, b, c)    ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)))
 
#define FUZZY_SCORER_MAX_LENGTH   256
 
#define MIN_SCORE   (INT_MIN / 2)
 
#define LEADING_GAP_SCORE   -4
 
#define GAP_SCORE   -5
 
#define WORD_START_SCORE   50
 
#define NON_WORD_SCORE   40
 
#define CAMEL_SCORE   (WORD_START_SCORE + GAP_SCORE - 1)
 
#define CONSECUTIVE_SCORE   (WORD_START_SCORE + GAP_SCORE)
 
#define PATTERN_NON_START_MULTIPLIER   1
 
#define PATTERN_START_MULTIPLIER   2
 

Enumerations

enum  CharClass { LOWER , UPPER , DIGIT , NON_WORD }
 

Functions

char * helper_string_replace_if_exists_v (char *string, GHashTable *h)
 
void cmd_set_arguments (int argc, char **argv)
 
int helper_parse_setup (char *string, char ***output, int *length,...)
 
void helper_tokenize_free (rofi_int_matcher **tokens)
 
static gchar * glob_to_regex (const char *input)
 
static gchar * fuzzy_to_regex (const char *input)
 
static gchar * prefix_regex (const char *input)
 
static char * utf8_helper_simplify_string (const char *s)
 
static GRegex * R (const char *s, int case_sensitive)
 
static rofi_int_matchercreate_regex (const char *input, int case_sensitive)
 
rofi_int_matcher ** helper_tokenize (const char *input, int case_sensitive)
 
int find_arg (const char *const key)
 
int find_arg_str (const char *const key, char **val)
 
const char ** find_arg_strv (const char *const key)
 
int find_arg_int (const char *const key, int *val)
 
int find_arg_uint (const char *const key, unsigned int *val)
 
char helper_parse_char (const char *arg)
 
int find_arg_char (const char *const key, char *val)
 
PangoAttrList * helper_token_match_get_pango_attr (RofiHighlightColorStyle th, rofi_int_matcher **tokens, const char *input, PangoAttrList *retv)
 
int helper_token_match (rofi_int_matcher *const *tokens, const char *input)
 
int execute_generator (const char *cmd)
 
int create_pid_file (const char *pidfile)
 
void remove_pid_file (int fd)
 
gboolean helper_validate_font (PangoFontDescription *pfd, const char *font)
 
int config_sanity_check (void)
 
char * rofi_expand_path (const char *input)
 
unsigned int levenshtein (const char *needle, const glong needlelen, const char *haystack, const glong haystacklen)
 
char * rofi_latin_to_utf8_strdup (const char *input, gssize length)
 
gchar * rofi_escape_markup (gchar *text)
 
char * rofi_force_utf8 (const gchar *data, ssize_t length)
 
static enum CharClass rofi_scorer_get_character_class (gunichar c)
 
static int rofi_scorer_get_score_for (enum CharClass prev, enum CharClass curr)
 
int rofi_scorer_fuzzy_evaluate (const char *pattern, glong plen, const char *str, glong slen)
 
int utf8_strncmp (const char *a, const char *b, size_t n)
 
gboolean helper_execute (const char *wd, char **args, const char *error_precmd, const char *error_cmd, RofiHelperExecuteContext *context)
 
gboolean helper_execute_command (const char *wd, const char *cmd, gboolean run_in_term, RofiHelperExecuteContext *context)
 
char * helper_get_theme_path (const char *file, const char *ext)
 
static gboolean parse_pair (char *input, rofi_range_pair *item)
 
void parse_ranges (char *input, rofi_range_pair **list, unsigned int *length)
 
void rofi_output_formatted_line (const char *format, const char *string, int selected_line, const char *filter)
 
static gboolean helper_eval_cb2 (const GMatchInfo *info, GString *res, gpointer data)
 
char * helper_string_replace_if_exists (char *string,...)
 

Variables

const char *const monitor_position_entries []
 
int stored_argc = 0
 
char ** stored_argv = NULL
 

Macro Definition Documentation

◆ CAMEL_SCORE

#define CAMEL_SCORE   (WORD_START_SCORE + GAP_SCORE - 1)

CamelCase score

Definition at line 841 of file helper.c.

◆ CONSECUTIVE_SCORE

#define CONSECUTIVE_SCORE   (WORD_START_SCORE + GAP_SCORE)

Consecutive score

Definition at line 843 of file helper.c.

◆ FUZZY_SCORER_MAX_LENGTH

#define FUZZY_SCORER_MAX_LENGTH   256

Max length of input to score.

Definition at line 829 of file helper.c.

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "Helper"

The log domain for this helper.

Definition at line 30 of file helper.c.

◆ GAP_SCORE

#define GAP_SCORE   -5

gap score

Definition at line 835 of file helper.c.

◆ LEADING_GAP_SCORE

#define LEADING_GAP_SCORE   -4

Leading gap score

Definition at line 833 of file helper.c.

◆ MIN3

#define MIN3 (   a,
  b,
 
)     ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)))

Return the minimum value of a,b,c

Definition at line 742 of file helper.c.

◆ MIN_SCORE

#define MIN_SCORE   (INT_MIN / 2)

minimum score

Definition at line 831 of file helper.c.

◆ NON_WORD_SCORE

#define NON_WORD_SCORE   40

non-word score

Definition at line 839 of file helper.c.

◆ PATTERN_NON_START_MULTIPLIER

#define PATTERN_NON_START_MULTIPLIER   1

non-start multiplier

Definition at line 845 of file helper.c.

◆ PATTERN_START_MULTIPLIER

#define PATTERN_START_MULTIPLIER   2

start multiplier

Definition at line 847 of file helper.c.

◆ WORD_START_SCORE

#define WORD_START_SCORE   50

start of word score

Definition at line 837 of file helper.c.

Enumeration Type Documentation

◆ CharClass

enum CharClass

Character classification.

Enumerator
LOWER 
UPPER 
DIGIT 
NON_WORD 

Definition at line 852 of file helper.c.

Function Documentation

◆ create_regex()

static rofi_int_matcher* create_regex ( const char *  input,
int  case_sensitive 
)
static

Definition at line 221 of file helper.c.

References config, fuzzy_to_regex(), glob_to_regex(), rofi_int_matcher_t::invert, Settings::matching_method, Settings::matching_negate_char, MM_FUZZY, MM_GLOB, MM_PREFIX, MM_REGEX, prefix_regex(), R(), and rofi_int_matcher_t::regex.

Referenced by helper_tokenize().

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

◆ fuzzy_to_regex()

static gchar* fuzzy_to_regex ( const char *  input)
static

Definition at line 142 of file helper.c.

Referenced by create_regex().

Here is the caller graph for this function:

◆ glob_to_regex()

static gchar* glob_to_regex ( const char *  input)
static

Definition at line 127 of file helper.c.

Referenced by create_regex().

Here is the caller graph for this function:

◆ helper_eval_cb2()

static gboolean helper_eval_cb2 ( const GMatchInfo *  info,
GString *  res,
gpointer  data 
)
static

Definition at line 1203 of file helper.c.

Referenced by helper_string_replace_if_exists_v().

Here is the caller graph for this function:

◆ helper_string_replace_if_exists_v()

char * helper_string_replace_if_exists_v ( char *  string,
GHashTable *  h 
)
Parameters
stringThe string with elements to be replaced
hHash table with set of {key}, value that will be replaced, terminated by a NULL

Items {key} are replaced by the value if '{key}' is passed as key/value pair, otherwise removed from string. If the {key} is in between [] all the text between [] are removed if {key} is not found. Otherwise key is replaced and [ & ] removed.

This allows for optional replacement, f.e. '{ssh-client} [-t {title}] -e "{cmd}"' the '-t {title}' is only there if {title} is set.

Returns
a new string with the keys replaced.

Definition at line 1284 of file helper.c.

References helper_eval_cb2(), and rofi_view_error_dialog().

Referenced by helper_parse_setup(), and helper_string_replace_if_exists().

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

◆ parse_pair()

static gboolean parse_pair ( char *  input,
rofi_range_pair item 
)
static

Definition at line 1112 of file helper.c.

References rofi_range_pair::start, and rofi_range_pair::stop.

Referenced by parse_ranges().

Here is the caller graph for this function:

◆ prefix_regex()

static gchar* prefix_regex ( const char *  input)
static

Definition at line 171 of file helper.c.

Referenced by create_regex().

Here is the caller graph for this function:

◆ R()

static GRegex* R ( const char *  s,
int  case_sensitive 
)
inlinestatic

Definition at line 206 of file helper.c.

References config, Settings::normalize_match, and utf8_helper_simplify_string().

Referenced by create_regex().

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

◆ rofi_scorer_get_character_class()

static enum CharClass rofi_scorer_get_character_class ( gunichar  c)
static
Parameters
cThe character to determine class of
Returns
the class of the character c.

Definition at line 796 of file helper.c.

Referenced by rofi_scorer_fuzzy_evaluate().

Here is the caller graph for this function:

◆ rofi_scorer_get_score_for()

static int rofi_scorer_get_score_for ( enum CharClass  prev,
enum CharClass  curr 
)
static
Parameters
prevThe previous character.
currThe current character

Scrore the transition.

Returns
score of the transition.

Definition at line 889 of file helper.c.

References CAMEL_SCORE, DIGIT, LOWER, NON_WORD, NON_WORD_SCORE, UPPER, and WORD_START_SCORE.

Referenced by rofi_scorer_fuzzy_evaluate().

Here is the caller graph for this function:

◆ utf8_helper_simplify_string()

static char* utf8_helper_simplify_string ( const char *  s)
static

Definition at line 178 of file helper.c.

Referenced by helper_token_match(), and R().

Here is the caller graph for this function:

◆ utf8_strncmp()

int utf8_strncmp ( const char *  a,
const char *  b,
size_t  n 
)
Parameters
aUTF-8 string to compare
bUTF-8 string to compare
nMaximum number of characters to compare

Compares the G_NORMALIZE_ALL_COMPOSE forms of the two strings.

Returns
less than, equal to, or greater than zero if the first n characters (not bytes) of a are found, respectively, to be less than, to match, or be greater than the first n characters (not bytes) of b.

Definition at line 973 of file helper.c.

Referenced by combi_mode_result(), and combi_preprocess_input().

Here is the caller graph for this function:

Variable Documentation

◆ monitor_position_entries

const char* const monitor_position_entries[]
Initial value:
= {
"on focused monitor", "on focused window", "at mouse pointer",
"on monitor with focused window", "on monitor that has mouse pointer"}

Textual description of positioning rofi.

Definition at line 60 of file helper.c.

Referenced by config_sanity_check().

◆ stored_argc

int stored_argc = 0

copy of the argc for use in commandline argument parser.

Definition at line 64 of file helper.c.

Referenced by cmd_set_arguments(), config_parse_cmd_options(), find_arg(), find_arg_char(), find_arg_int(), find_arg_str(), find_arg_strv(), and find_arg_uint().

◆ stored_argv

char** stored_argv = NULL

copy of the argv pointer for use in the commandline argument parser

Definition at line 66 of file helper.c.

Referenced by cmd_set_arguments(), config_parse_cmd_options(), find_arg(), find_arg_char(), find_arg_int(), find_arg_str(), find_arg_strv(), and find_arg_uint().