rofi/include/helper.h

227 lines
5.8 KiB
C
Raw Normal View History

2015-07-27 08:17:12 +00:00
#ifndef ROFI_HELPER_H
#define ROFI_HELPER_H
2015-03-27 19:28:53 +00:00
#include "rofi.h"
2016-01-07 07:54:24 +00:00
#include <pango/pango.h>
#include <theme.h>
2016-01-07 07:54:24 +00:00
/**
* @defgroup HELPERS Helpers
*/
/**
* @defgroup HELPER Helper
* @ingroup HELPERS
*
* @{
*/
2014-11-24 19:22:44 +00:00
/**
* @param string The input string.
* @param output Pointer to 2 dimensional array with parsed string.
* @param length Length of 2 dimensional array.
* @param ... 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.
2014-11-24 19:35:28 +00:00
*/
2014-11-24 19:22:44 +00:00
int helper_parse_setup ( char * string, char ***output, int *length, ... );
2014-11-24 19:22:44 +00:00
/**
* @param input The input string.
2015-01-12 13:13:46 +00:00
* @param case_sensitive Whether case is significant.
2014-11-24 19:22:44 +00:00
*
* Tokenize the string on spaces.
*
* @returns a newly allocated array of regex objest
2014-11-24 19:22:44 +00:00
*/
2016-05-22 15:47:34 +00:00
GRegex **tokenize ( const char *input, int case_sensitive );
/**
2016-10-14 14:46:54 +00:00
* @param tokens Array of regex objects
*
* Frees the array of regex expressions.
*/
2016-05-22 15:47:34 +00:00
void tokenize_free ( GRegex ** tokens );
2014-11-15 15:26:55 +00:00
2014-11-24 19:22:44 +00:00
/**
* @param key The key to search for
* @param val Pointer to the string to set to the key value (if found)
*
* Parse command line argument 'key' to character.
* This one supports character escaping.
*
2014-11-24 19:35:28 +00:00
* @returns TRUE if key was found and val was set.
2014-11-24 19:22:44 +00:00
*/
2015-03-11 17:32:37 +00:00
int find_arg_char ( const char * const key, char *val );
2014-11-15 15:26:55 +00:00
2014-11-24 19:22:44 +00:00
/**
* @param key The key to search for
* @param val Pointer to the string to set to the key value (if found)
*
* Parse command line argument 'key' to unsigned int.
*
2014-11-24 19:35:28 +00:00
* @returns TRUE if key was found and val was set.
2014-11-24 19:22:44 +00:00
*/
2015-03-11 17:32:37 +00:00
int find_arg_uint ( const char * const key, unsigned int *val );
2014-11-15 15:26:55 +00:00
2014-11-24 19:22:44 +00:00
/**
* @param key The key to search for
* @param val Pointer to the string to set to the key value (if found)
*
* Parse command line argument 'key' to int.
*
2014-11-24 19:35:28 +00:00
* @returns TRUE if key was found and val was set.
2014-11-24 19:22:44 +00:00
*/
2015-03-11 17:32:37 +00:00
int find_arg_int ( const char * const key, int *val );
2014-11-15 15:26:55 +00:00
2014-11-24 19:22:44 +00:00
/**
* @param key The key to search for
* @param val Pointer to the string to set to the key value (if found)
*
* Parse command line argument 'key' to string.
*
2014-11-24 19:35:28 +00:00
* @returns TRUE if key was found and val was set.
2014-11-24 19:22:44 +00:00
*/
2015-03-11 17:32:37 +00:00
int find_arg_str ( const char * const key, char** val );
2014-11-15 15:26:55 +00:00
/**
* @param key The key to search for
*
* Parse all command line options 'key' to string vector.
*
* @returns str vector. user should free array.
*/
const char ** find_arg_strv ( const char *const key );
2014-11-24 19:22:44 +00:00
/**
* @param key The key to search for
*
* Check if key is passed as argument.
*
2014-11-24 19:35:28 +00:00
* @returns return position of string or -1 if not found.
2014-11-24 19:22:44 +00:00
*/
2015-03-11 17:32:37 +00:00
int find_arg ( const char * const key );
2014-11-15 15:26:55 +00:00
2014-12-02 08:09:20 +00:00
/**
* @param tokens List of (input) tokens to match.
* @param input The entry to match against.
*
* Tokenized match, match tokens to line input.
*
2016-07-29 06:32:34 +00:00
* @returns TRUE when matches, FALSE otherwise
2014-12-02 08:09:20 +00:00
*/
2016-08-23 22:39:56 +00:00
int token_match ( GRegex * const *tokens, const char *input );
2015-01-05 20:53:50 +00:00
/**
* @param cmd The 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.
*/
2015-03-27 19:28:53 +00:00
int execute_generator ( const char * cmd ) __attribute__( ( nonnull ) );
/**
* @param pidfile The pidfile to create.
*
* returns file descriptor (or -1 when failed)
*/
int create_pid_file ( const char *pidfile );
/**
* Remove pid file
*/
void remove_pid_file ( int fd );
2015-02-03 07:21:59 +00:00
/**
* 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.
*/
2016-03-01 17:11:55 +00:00
int config_sanity_check ( void );
2015-03-17 19:05:37 +00:00
/**
* @param arg string to parse.
*
* Parses a string into an character.
*
* @returns character.
*/
char helper_parse_char ( const char *arg );
2015-03-17 19:05:37 +00:00
/**
* @param argc number of arguments.
* @param argv Array of arguments.
*
* Set the application arguments.
*/
2015-03-11 17:32:37 +00:00
void cmd_set_arguments ( int argc, char **argv );
2015-12-02 16:56:25 +00:00
/**
* @param input The path to expand
*
* Expand path, both `~` and `~<user>`
*
* @returns path
*/
char *rofi_expand_path ( const char *input );
/**
* @param needle The string to find match weight off
* @param needlelen The length of the needle
* @param haystack The string to match against
* @param haystacklen The length of the haystack
*
* UTF-8 aware levenshtein distance calculation
*
* @returns the levenshtein distance between needle and haystack
*/
unsigned int levenshtein ( const char *needle, const glong needlelen, const char *haystack, const glong haystacklen );
2016-01-07 07:54:24 +00:00
/**
* @param data the unvalidated character array holding possible UTF-8 data
* @param length the length of the data array
*
* Convert string to valid utf-8, replacing invalid parts with replacement character.
*
* @returns the converted UTF-8 string
*/
char * rofi_force_utf8 ( gchar *data, ssize_t length );
/**
2016-11-15 20:54:31 +00:00
* @param input the char array holding latin text
* @param length the length of the data array
*
* Converts latin to UTF-8.
*
* @return the UTF-8 representation of data
*/
char * rofi_latin_to_utf8_strdup ( const char *input, gssize length );
/**
* @param th The ThemeHighlight
* @param tokens Array of regexes used for matching
* @param input The input string to find the matches on
* @param retv The Attribute list to update with matches
*
* Creates a set of pango attributes highlighting the matches found in the input string.
*
* @returns the updated retv list.
*/
PangoAttrList *token_match_get_pango_attr ( ThemeHighlight th, GRegex **tokens, const char *input, PangoAttrList *retv );
2017-01-11 08:20:19 +00:00
/**
* @param pattern The user input to match against.
* @param plen Pattern length.
* @param str The input to match against pattern.
* @param slen Lenght of str.
*
* FZF like fuzzy sorting algorithm.
*
* @returns the sorting weight.
*/
int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *str, glong slen );
2016-01-07 07:54:24 +00:00
/*@}*/
2015-07-27 08:17:12 +00:00
#endif // ROFI_HELPER_H