2015-02-12 21:34:06 +00:00
|
|
|
/**
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
|
|
|
* Copyright (c) 2012 Sean Pringle <sean.pringle@gmail.com>
|
|
|
|
* Modified 2013-2015 Qball Cow <qball@gmpclient.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
2015-02-03 07:00:33 +00:00
|
|
|
#include <config.h>
|
2014-09-06 12:57:30 +00:00
|
|
|
#include <stdio.h>
|
2014-11-15 15:26:55 +00:00
|
|
|
#include <stdlib.h>
|
2014-09-03 11:07:26 +00:00
|
|
|
#include <glib.h>
|
2014-11-15 15:26:55 +00:00
|
|
|
#include <string.h>
|
2015-02-03 07:00:33 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include "helper.h"
|
|
|
|
#include "rofi.h"
|
2014-09-03 11:07:26 +00:00
|
|
|
|
2014-11-25 11:57:34 +00:00
|
|
|
/**
|
|
|
|
* `fgets` implementation with custom separator.
|
|
|
|
*/
|
2014-10-19 17:42:02 +00:00
|
|
|
char* fgets_s ( char* s, int n, FILE *iop, char sep )
|
|
|
|
{
|
2014-11-25 11:57:34 +00:00
|
|
|
// Map these to registers.
|
2014-10-19 17:42:02 +00:00
|
|
|
register int c;
|
|
|
|
register char* cs;
|
|
|
|
cs = s;
|
2014-11-25 11:57:34 +00:00
|
|
|
// read until EOF or buffer is full.
|
2014-10-19 17:42:02 +00:00
|
|
|
while ( --n > 0 && ( c = getc ( iop ) ) != EOF ) {
|
|
|
|
// put the input char into the current pointer position, then increment it
|
|
|
|
// if a newline entered, break
|
|
|
|
if ( ( *cs++ = c ) == sep ) {
|
|
|
|
// Whipe separator
|
|
|
|
cs[-1] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-11-25 11:57:34 +00:00
|
|
|
// Always, 0 terminate the buffer.
|
2014-10-19 17:42:02 +00:00
|
|
|
*cs = '\0';
|
2014-11-25 11:57:34 +00:00
|
|
|
// if last read was end of file and current index is start, we are done:
|
|
|
|
// Return NULL.
|
2014-10-19 17:42:02 +00:00
|
|
|
return ( c == EOF && cs == s ) ? NULL : s;
|
|
|
|
}
|
|
|
|
|
2014-09-03 11:07:26 +00:00
|
|
|
/**
|
2014-11-25 11:57:34 +00:00
|
|
|
* @param info The Match informati on.
|
|
|
|
* @param res The string being generated.
|
|
|
|
* @param data User data
|
|
|
|
*
|
|
|
|
* Replace the entries. This function gets called by g_regex_replace_eval.
|
|
|
|
*
|
|
|
|
* @returns TRUE to stop replacement, FALSE to continue
|
2014-09-03 11:07:26 +00:00
|
|
|
*/
|
|
|
|
static gboolean helper_eval_cb ( const GMatchInfo *info,
|
|
|
|
GString *res,
|
|
|
|
gpointer data )
|
|
|
|
{
|
2015-01-15 16:59:59 +00:00
|
|
|
gchar *match;
|
2014-11-25 11:57:34 +00:00
|
|
|
// Get the match
|
2014-09-03 11:07:26 +00:00
|
|
|
match = g_match_info_fetch ( info, 0 );
|
2014-11-25 11:57:34 +00:00
|
|
|
if ( match != NULL ) {
|
|
|
|
// Lookup the match, so we can replace it.
|
2015-01-15 16:59:59 +00:00
|
|
|
gchar *r = g_hash_table_lookup ( (GHashTable *) data, match );
|
2014-11-25 11:57:34 +00:00
|
|
|
if ( r != NULL ) {
|
|
|
|
// Append the replacement to the string.
|
|
|
|
g_string_append ( res, r );
|
|
|
|
}
|
|
|
|
// Free match.
|
2014-09-03 11:07:26 +00:00
|
|
|
g_free ( match );
|
|
|
|
}
|
2014-11-25 11:57:34 +00:00
|
|
|
// Continue replacement.
|
2014-09-03 11:07:26 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int helper_parse_setup ( char * string, char ***output, int *length, ... )
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
GHashTable *h;
|
|
|
|
h = g_hash_table_new ( g_str_hash, g_str_equal );
|
2014-11-25 11:57:34 +00:00
|
|
|
// By default, we insert terminal and ssh-client
|
2014-09-03 11:07:26 +00:00
|
|
|
g_hash_table_insert ( h, "{terminal}", config.terminal_emulator );
|
|
|
|
g_hash_table_insert ( h, "{ssh-client}", config.ssh_client );
|
2014-11-25 11:57:34 +00:00
|
|
|
// Add list from variable arguments.
|
2014-09-03 11:07:26 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start ( ap, length );
|
|
|
|
while ( 1 ) {
|
|
|
|
char * key = va_arg ( ap, char * );
|
|
|
|
if ( key == NULL ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
char *value = va_arg ( ap, char * );
|
|
|
|
if ( value == NULL ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_hash_table_insert ( h, key, value );
|
|
|
|
}
|
|
|
|
va_end ( ap );
|
|
|
|
|
|
|
|
// Replace hits within {-\w+}.
|
|
|
|
GRegex *reg = g_regex_new ( "{[-\\w]+}", 0, 0, NULL );
|
|
|
|
char *res = g_regex_replace_eval ( reg,
|
|
|
|
string, -1,
|
|
|
|
0, 0, helper_eval_cb, h,
|
|
|
|
NULL );
|
2014-11-25 11:57:34 +00:00
|
|
|
// Free regex.
|
2014-09-03 11:07:26 +00:00
|
|
|
g_regex_unref ( reg );
|
2014-11-25 11:57:34 +00:00
|
|
|
// Destroy key-value storage.
|
2014-09-03 11:07:26 +00:00
|
|
|
g_hash_table_destroy ( h );
|
2014-11-25 11:57:34 +00:00
|
|
|
// Parse the string into shell arguments.
|
2014-09-03 11:07:26 +00:00
|
|
|
if ( g_shell_parse_argv ( res, length, output, &error ) ) {
|
|
|
|
g_free ( res );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
g_free ( res );
|
2014-11-25 11:57:34 +00:00
|
|
|
// Throw error if shell parsing fails.
|
2014-09-03 11:07:26 +00:00
|
|
|
if ( error ) {
|
|
|
|
char *msg = g_strdup_printf ( "Failed to parse: '%s'\nError: '%s'", string,
|
|
|
|
error->message );
|
|
|
|
#ifdef error_dialog
|
|
|
|
error_dialog ( msg );
|
2014-09-06 12:57:30 +00:00
|
|
|
#else
|
|
|
|
fputs ( msg, stderr );
|
2014-09-03 11:07:26 +00:00
|
|
|
#endif
|
|
|
|
g_free ( msg );
|
|
|
|
// print error.
|
|
|
|
g_error_free ( error );
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-11-15 15:26:55 +00:00
|
|
|
|
2015-01-12 13:13:46 +00:00
|
|
|
char *token_collate_key ( const char *token, int case_sensitive )
|
|
|
|
{
|
|
|
|
char *tmp, *compk;
|
|
|
|
|
|
|
|
if ( case_sensitive ) {
|
|
|
|
tmp = g_strdup ( token );
|
2015-01-13 10:48:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-01-12 13:13:46 +00:00
|
|
|
tmp = g_utf8_casefold ( token, -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
compk = g_utf8_collate_key ( tmp, -1 );
|
|
|
|
g_free ( tmp );
|
|
|
|
|
|
|
|
return compk;
|
|
|
|
}
|
|
|
|
|
|
|
|
char **tokenize ( const char *input, int case_sensitive )
|
2014-11-15 15:26:55 +00:00
|
|
|
{
|
|
|
|
if ( input == NULL ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *saveptr = NULL, *token;
|
|
|
|
char **retv = NULL;
|
|
|
|
// First entry is always full (modified) stringtext.
|
|
|
|
int num_tokens = 0;
|
|
|
|
|
|
|
|
// Copy the string, 'strtok_r' modifies it.
|
|
|
|
char *str = g_strdup ( input );
|
|
|
|
|
|
|
|
// Iterate over tokens.
|
|
|
|
// strtok should still be valid for utf8.
|
|
|
|
for ( token = strtok_r ( str, " ", &saveptr );
|
|
|
|
token != NULL;
|
|
|
|
token = strtok_r ( NULL, " ", &saveptr ) ) {
|
|
|
|
retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
|
2015-01-12 13:13:46 +00:00
|
|
|
retv[num_tokens] = token_collate_key ( token, case_sensitive );
|
2014-11-15 15:26:55 +00:00
|
|
|
retv[num_tokens + 1] = NULL;
|
|
|
|
num_tokens++;
|
|
|
|
}
|
|
|
|
// Free str.
|
|
|
|
g_free ( str );
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cli arg handling
|
|
|
|
int find_arg ( const int argc, char * const argv[], const char * const key )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; i < argc && strcasecmp ( argv[i], key ); i++ ) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i < argc ? i : -1;
|
|
|
|
}
|
|
|
|
int find_arg_str ( const int argc, char * const argv[], const char * const key, char** val )
|
|
|
|
{
|
|
|
|
int i = find_arg ( argc, argv, key );
|
|
|
|
|
|
|
|
if ( val != NULL && i > 0 && i < argc - 1 ) {
|
|
|
|
*val = argv[i + 1];
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-01-31 17:23:17 +00:00
|
|
|
int find_arg_str_alloc ( const int argc, char * const argv[], const char * const key, char** val )
|
|
|
|
{
|
|
|
|
int i = find_arg ( argc, argv, key );
|
|
|
|
|
|
|
|
if ( val != NULL && i > 0 && i < argc - 1 ) {
|
2015-02-03 07:00:33 +00:00
|
|
|
if ( *val != NULL ) {
|
|
|
|
g_free ( *val );
|
|
|
|
}
|
2015-01-31 17:23:17 +00:00
|
|
|
*val = g_strdup ( argv[i + 1] );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-11-15 15:26:55 +00:00
|
|
|
|
|
|
|
int find_arg_int ( const int argc, char * const argv[], const char * const key, int *val )
|
|
|
|
{
|
|
|
|
int i = find_arg ( argc, argv, key );
|
|
|
|
|
|
|
|
if ( val != NULL && i > 0 && i < ( argc - 1 ) ) {
|
|
|
|
*val = strtol ( argv[i + 1], NULL, 10 );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
int find_arg_uint ( const int argc, char * const argv[], const char * const key, unsigned int *val )
|
|
|
|
{
|
|
|
|
int i = find_arg ( argc, argv, key );
|
|
|
|
|
|
|
|
if ( val != NULL && i > 0 && i < ( argc - 1 ) ) {
|
|
|
|
*val = strtoul ( argv[i + 1], NULL, 10 );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int find_arg_char ( const int argc, char * const argv[], const char * const key, char *val )
|
|
|
|
{
|
|
|
|
int i = find_arg ( argc, argv, key );
|
|
|
|
|
|
|
|
if ( val != NULL && i > 0 && i < ( argc - 1 ) ) {
|
|
|
|
int len = strlen ( argv[i + 1] );
|
2014-11-25 11:57:34 +00:00
|
|
|
// If the length is 1, it is not escaped.
|
2014-11-15 15:26:55 +00:00
|
|
|
if ( len == 1 ) {
|
|
|
|
*val = argv[i + 1][0];
|
|
|
|
}
|
2014-11-25 11:57:34 +00:00
|
|
|
// If the length is 2 and the first character is '\', we unescape it.
|
2014-11-15 15:26:55 +00:00
|
|
|
else if ( len == 2 && argv[i + 1][0] == '\\' ) {
|
2014-11-25 11:57:34 +00:00
|
|
|
// New line
|
2014-11-15 15:26:55 +00:00
|
|
|
if ( argv[i + 1][1] == 'n' ) {
|
|
|
|
*val = '\n';
|
|
|
|
}
|
2014-11-25 11:57:34 +00:00
|
|
|
// Bell
|
2014-11-15 15:26:55 +00:00
|
|
|
else if ( argv[i + 1][1] == 'a' ) {
|
|
|
|
*val = '\a';
|
|
|
|
}
|
2014-11-25 11:57:34 +00:00
|
|
|
// Backspace
|
2014-11-15 15:26:55 +00:00
|
|
|
else if ( argv[i + 1][1] == 'b' ) {
|
|
|
|
*val = '\b';
|
|
|
|
}
|
2014-11-25 11:57:34 +00:00
|
|
|
// Tab
|
2014-11-15 15:26:55 +00:00
|
|
|
else if ( argv[i + 1][1] == 't' ) {
|
|
|
|
*val = '\t';
|
|
|
|
}
|
2014-11-25 11:57:34 +00:00
|
|
|
// Vertical tab
|
2014-11-15 15:26:55 +00:00
|
|
|
else if ( argv[i + 1][1] == 'v' ) {
|
|
|
|
*val = '\v';
|
|
|
|
}
|
2014-11-25 11:57:34 +00:00
|
|
|
// Form feed
|
2014-11-15 15:26:55 +00:00
|
|
|
else if ( argv[i + 1][1] == 'f' ) {
|
|
|
|
*val = '\f';
|
|
|
|
}
|
2014-11-25 11:57:34 +00:00
|
|
|
// Carriage return
|
2014-11-15 15:26:55 +00:00
|
|
|
else if ( argv[i + 1][1] == 'r' ) {
|
|
|
|
*val = '\r';
|
|
|
|
}
|
2014-11-25 11:57:34 +00:00
|
|
|
// Forward slash
|
2014-11-15 15:26:55 +00:00
|
|
|
else if ( argv[i + 1][1] == '\\' ) {
|
|
|
|
*val = '\\';
|
|
|
|
}
|
2014-11-25 11:57:34 +00:00
|
|
|
// Otherwise it is not valid and throw error
|
2014-11-15 15:26:55 +00:00
|
|
|
else {
|
|
|
|
fprintf ( stderr, "Failed to parse command-line argument." );
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
fprintf ( stderr, "Failed to parse command-line argument." );
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-12-02 08:09:20 +00:00
|
|
|
/**
|
|
|
|
* Shared 'token_match' function.
|
|
|
|
* Matches tokenized.
|
|
|
|
*/
|
2015-01-12 13:13:46 +00:00
|
|
|
int token_match ( char **tokens, const char *input, int case_sensitive,
|
2014-12-02 08:09:20 +00:00
|
|
|
__attribute__( ( unused ) ) int index,
|
|
|
|
__attribute__( ( unused ) ) void *data )
|
|
|
|
{
|
2015-01-13 10:48:38 +00:00
|
|
|
int match = 1;
|
2015-01-12 13:13:46 +00:00
|
|
|
char *compk = token_collate_key ( input, case_sensitive );
|
2014-12-02 08:09:20 +00:00
|
|
|
|
|
|
|
// Do a tokenized match.
|
|
|
|
if ( tokens ) {
|
|
|
|
for ( int j = 0; match && tokens[j]; j++ ) {
|
|
|
|
match = ( strstr ( compk, tokens[j] ) != NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free ( compk );
|
|
|
|
return match;
|
|
|
|
}
|
2015-01-05 20:53:50 +00:00
|
|
|
|
|
|
|
int execute_generator ( char * cmd )
|
|
|
|
{
|
|
|
|
char **args = NULL;
|
|
|
|
int argv = 0;
|
|
|
|
helper_parse_setup ( config.run_command, &args, &argv, "{cmd}", cmd, NULL );
|
|
|
|
|
|
|
|
int fd = -1;
|
|
|
|
GError *error = NULL;
|
|
|
|
g_spawn_async_with_pipes ( NULL,
|
|
|
|
args,
|
|
|
|
NULL,
|
|
|
|
G_SPAWN_SEARCH_PATH,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL, &fd, NULL,
|
|
|
|
&error );
|
|
|
|
|
|
|
|
if ( error != NULL ) {
|
|
|
|
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd,
|
|
|
|
error->message );
|
|
|
|
#ifdef error_dialog
|
|
|
|
error_dialog ( msg );
|
|
|
|
#else
|
|
|
|
fputs ( msg, stderr );
|
|
|
|
#endif
|
|
|
|
g_free ( msg );
|
|
|
|
// print error.
|
|
|
|
g_error_free ( error );
|
|
|
|
fd = -1;
|
|
|
|
}
|
|
|
|
g_strfreev ( args );
|
|
|
|
return fd;
|
|
|
|
}
|
2015-02-03 07:00:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
void create_pid_file ( const char *pidfile )
|
|
|
|
{
|
|
|
|
if ( pidfile == NULL ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fd = open ( pidfile, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR );
|
|
|
|
if ( fd < 0 ) {
|
|
|
|
fprintf ( stderr, "Failed to create pid file." );
|
|
|
|
exit ( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
// Set it to close the File Descriptor on exit.
|
|
|
|
int flags = fcntl ( fd, F_GETFD, NULL );
|
|
|
|
flags = flags | FD_CLOEXEC;
|
|
|
|
if ( fcntl ( fd, F_SETFD, flags, NULL ) < 0 ) {
|
|
|
|
fprintf ( stderr, "Failed to set CLOEXEC on pidfile." );
|
|
|
|
close ( fd );
|
|
|
|
exit ( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
// Try to get exclusive write lock on FD
|
|
|
|
int retv = flock ( fd, LOCK_EX | LOCK_NB );
|
|
|
|
if ( retv != 0 ) {
|
|
|
|
fprintf ( stderr, "Failed to set lock on pidfile: Rofi already running?\n" );
|
|
|
|
fprintf ( stderr, "%d %s\n", retv, strerror ( errno ) );
|
|
|
|
exit ( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
if ( ftruncate ( fd, (off_t) 0 ) == 0 ) {
|
|
|
|
// Write pid, not needed, but for completeness sake.
|
|
|
|
char buffer[64];
|
|
|
|
int length = snprintf ( buffer, 64, "%i", getpid () );
|
|
|
|
ssize_t l = 0;
|
|
|
|
while ( l < length ) {
|
|
|
|
l += write ( fd, &buffer[l], length - l );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-03 07:21:59 +00:00
|
|
|
|
|
|
|
void config_parse_cmd_options ( int argc, char ** argv )
|
|
|
|
{
|
|
|
|
find_arg_str ( argc, argv, "-switchers", &( config.switchers ) );
|
|
|
|
// Parse commandline arguments about the looks.
|
|
|
|
find_arg_uint ( argc, argv, "-opacity", &( config.window_opacity ) );
|
|
|
|
|
|
|
|
find_arg_int ( argc, argv, "-width", &( config.menu_width ) );
|
|
|
|
|
|
|
|
find_arg_uint ( argc, argv, "-lines", &( config.menu_lines ) );
|
|
|
|
find_arg_uint ( argc, argv, "-columns", &( config.menu_columns ) );
|
|
|
|
|
|
|
|
find_arg_str ( argc, argv, "-font", &( config.menu_font ) );
|
|
|
|
find_arg_str ( argc, argv, "-fg", &( config.menu_fg ) );
|
|
|
|
find_arg_str ( argc, argv, "-bg", &( config.menu_bg ) );
|
|
|
|
find_arg_str ( argc, argv, "-bgalt", &( config.menu_bg_alt ) );
|
|
|
|
find_arg_str ( argc, argv, "-hlfg", &( config.menu_hlfg ) );
|
|
|
|
find_arg_str ( argc, argv, "-hlbg", &( config.menu_hlbg ) );
|
|
|
|
find_arg_str ( argc, argv, "-bc", &( config.menu_bc ) );
|
|
|
|
find_arg_uint ( argc, argv, "-bw", &( config.menu_bw ) );
|
|
|
|
|
|
|
|
// Parse commandline arguments about size and position
|
|
|
|
find_arg_uint ( argc, argv, "-location", &( config.location ) );
|
|
|
|
find_arg_uint ( argc, argv, "-padding", &( config.padding ) );
|
|
|
|
find_arg_int ( argc, argv, "-xoffset", &( config.x_offset ) );
|
|
|
|
find_arg_int ( argc, argv, "-yoffset", &( config.y_offset ) );
|
|
|
|
if ( find_arg ( argc, argv, "-fixed-num-lines" ) >= 0 ) {
|
|
|
|
config.fixed_num_lines = 1;
|
|
|
|
}
|
|
|
|
if ( find_arg ( argc, argv, "-disable-history" ) >= 0 ) {
|
|
|
|
config.disable_history = TRUE;
|
|
|
|
}
|
|
|
|
if ( find_arg ( argc, argv, "-levenshtein-sort" ) >= 0 ) {
|
|
|
|
config.levenshtein_sort = TRUE;
|
|
|
|
}
|
|
|
|
if ( find_arg ( argc, argv, "-case-sensitive" ) >= 0 ) {
|
|
|
|
config.case_sensitive = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse commandline arguments about behavior
|
|
|
|
find_arg_str ( argc, argv, "-terminal", &( config.terminal_emulator ) );
|
|
|
|
|
|
|
|
find_arg_str ( argc, argv, "-ssh-client", &( config.ssh_client ) );
|
|
|
|
find_arg_str ( argc, argv, "-ssh-command", &( config.ssh_command ) );
|
|
|
|
find_arg_str ( argc, argv, "-run-command", &( config.run_command ) );
|
|
|
|
find_arg_str ( argc, argv, "-run-list-command", &( config.run_list_command ) );
|
|
|
|
find_arg_str ( argc, argv, "-run-shell-command", &( config.run_shell_command ) );
|
|
|
|
|
|
|
|
// Keybindings
|
|
|
|
find_arg_str ( argc, argv, "-key", &( config.window_key ) );
|
|
|
|
find_arg_str ( argc, argv, "-rkey", &( config.run_key ) );
|
|
|
|
find_arg_str ( argc, argv, "-skey", &( config.ssh_key ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
find_arg_char ( argc, argv, "-sep", &( config.separator ) );
|
|
|
|
|
|
|
|
|
|
|
|
find_arg_int ( argc, argv, "-eh", &( config.element_height ) );
|
|
|
|
|
|
|
|
find_arg_uint ( argc, argv, "-lazy-filter-limit", &( config.lazy_filter_limit ) );
|
|
|
|
|
|
|
|
if ( find_arg ( argc, argv, "-sidebar-mode" ) >= 0 ) {
|
|
|
|
config.sidebar_mode = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void config_sanity_check ( void )
|
|
|
|
{
|
|
|
|
if ( config.element_height < 1 ) {
|
|
|
|
fprintf ( stderr, "config.element_height is invalid. It needs to be atleast 1 line high.\n" );
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
|
|
|
if ( config.menu_columns == 0 ) {
|
|
|
|
fprintf ( stderr, "config.menu_columns is invalid. You need at least one visible column.\n" );
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
|
|
|
if ( config.menu_width == 0 ) {
|
|
|
|
fprintf ( stderr, "config.menu_width is invalid. You cannot have a window with no width.\n" );
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
|
|
|
if ( !( config.location >= WL_CENTER && config.location <= WL_WEST ) ) {
|
|
|
|
fprintf ( stderr, "config.location is invalid. ( %d >= %d >= %d) does not hold.\n",
|
|
|
|
WL_WEST, config.location, WL_CENTER );
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
|
|
|
// If alternative row is not set, copy the normal background color.
|
|
|
|
if ( config.menu_bg_alt == NULL ) {
|
|
|
|
config.menu_bg_alt = config.menu_bg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|