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"
|
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-09-03 11:07:26 +00:00
|
|
|
|
2014-11-24 19:22:44 +00:00
|
|
|
/**
|
|
|
|
* Implementation of fgets with custom separator.
|
|
|
|
*/
|
2015-10-01 10:41:44 +00:00
|
|
|
char* fgets_s ( char* s, unsigned int n, FILE *iop, char sep );
|
2014-10-19 17:42:02 +00:00
|
|
|
|
2015-01-12 13:13:46 +00:00
|
|
|
/**
|
|
|
|
* @param token The string for which we want a collation key.
|
|
|
|
* @param case_sensitive Whether case is significant.
|
|
|
|
*
|
|
|
|
* Get a collation key for @p token. @p token must be a null-terminated string.
|
|
|
|
* This collation key can be used for matching the user input against the list
|
|
|
|
* of commands, windows, or ssh commands.
|
|
|
|
*
|
|
|
|
* @returns A newly allocated string containing the collation key.
|
|
|
|
*/
|
|
|
|
char *token_collate_key ( const char *token, int case_sensitive );
|
|
|
|
|
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 2 dimensional array of strings.
|
|
|
|
*/
|
2015-01-12 13:13:46 +00:00
|
|
|
char **tokenize ( const char *input, int case_sensitive );
|
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
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @params tokens
|
|
|
|
* @param tokens List of (input) tokens to match.
|
|
|
|
* @param input The entry to match against.
|
2015-01-12 13:13:46 +00:00
|
|
|
* @param case_sensitive Whether case is significant.
|
2014-12-02 08:09:20 +00:00
|
|
|
* @param index The current selected index.
|
|
|
|
* @param data User data.
|
|
|
|
*
|
|
|
|
* Tokenized match, match tokens to line input.
|
|
|
|
*
|
|
|
|
* @returns 1 when matches, 0 otherwise
|
|
|
|
*/
|
2015-10-01 11:16:41 +00:00
|
|
|
int token_match ( char **tokens, const char *input, int not_ascii, int case_sensitive,
|
2015-03-30 18:12:22 +00:00
|
|
|
__attribute__( ( unused ) ) unsigned int index,
|
2015-03-27 19:28:53 +00:00
|
|
|
__attribute__( ( unused ) ) Switcher * data );
|
2014-12-02 08:09:20 +00:00
|
|
|
|
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 ) );
|
2015-02-03 07:00:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param pidfile The pidfile to create.
|
|
|
|
*
|
2015-07-30 06:57:09 +00:00
|
|
|
* returns file descriptor (or -1 when failed)
|
2015-02-03 07:00:33 +00:00
|
|
|
*/
|
2015-07-30 06:57:09 +00:00
|
|
|
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.
|
|
|
|
*/
|
2015-10-18 11:40:39 +00:00
|
|
|
void config_sanity_check ( Display *display );
|
2015-03-17 19:05:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param arg string to parse.
|
|
|
|
*
|
|
|
|
* Parses a string into an character.
|
|
|
|
*
|
|
|
|
* @returns character.
|
|
|
|
*/
|
2015-02-17 09:31:59 +00:00
|
|
|
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-10-01 11:16:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param str a UTF8 string
|
|
|
|
* @return 1 if the string contains any non-ascii codepoints
|
|
|
|
*/
|
|
|
|
int is_not_ascii ( const char *str );
|
|
|
|
|
2015-07-27 08:17:12 +00:00
|
|
|
#endif // ROFI_HELPER_H
|