mirror of https://github.com/davatorium/rofi.git
Update some code.
This commit is contained in:
parent
3c8b757930
commit
86b6beb1e9
|
@ -46,16 +46,16 @@ typedef struct
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
TB_AUTOHEIGHT = 1 << 0,
|
TB_AUTOHEIGHT = 1 << 0,
|
||||||
TB_AUTOWIDTH = 1 << 1,
|
TB_AUTOWIDTH = 1 << 1,
|
||||||
TB_LEFT = 1 << 16,
|
TB_LEFT = 1 << 16,
|
||||||
TB_RIGHT = 1 << 17,
|
TB_RIGHT = 1 << 17,
|
||||||
TB_CENTER = 1 << 18,
|
TB_CENTER = 1 << 18,
|
||||||
TB_EDITABLE = 1 << 19,
|
TB_EDITABLE = 1 << 19,
|
||||||
TB_MARKUP = 1 << 20,
|
TB_MARKUP = 1 << 20,
|
||||||
TB_WRAP = 1 << 21,
|
TB_WRAP = 1 << 21,
|
||||||
TB_PASSWORD = 1 << 22,
|
TB_PASSWORD = 1 << 22,
|
||||||
TB_INDICATOR = 1 << 23,
|
TB_INDICATOR = 1 << 23,
|
||||||
} TextboxFlags;
|
} TextboxFlags;
|
||||||
/**
|
/**
|
||||||
* Flags indicating current state of the textbox.
|
* Flags indicating current state of the textbox.
|
||||||
|
|
|
@ -198,7 +198,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length )
|
||||||
// Reading one line per time.
|
// Reading one line per time.
|
||||||
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
|
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
|
||||||
// Evaluate one line.
|
// Evaluate one line.
|
||||||
unsigned int index = 0, ti = 0;
|
unsigned int index = 0, ti = 0;
|
||||||
char *token = buffer;
|
char *token = buffer;
|
||||||
|
|
||||||
// Tokenize it.
|
// Tokenize it.
|
||||||
|
|
|
@ -194,7 +194,7 @@ static GRegex * create_regex ( const char *input, int case_sensitive )
|
||||||
{
|
{
|
||||||
#define R( s ) g_regex_new ( s, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL )
|
#define R( s ) g_regex_new ( s, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL )
|
||||||
GRegex * retv = NULL;
|
GRegex * retv = NULL;
|
||||||
gchar *r;
|
gchar *r;
|
||||||
switch ( config.matching_method )
|
switch ( config.matching_method )
|
||||||
{
|
{
|
||||||
case MM_GLOB:
|
case MM_GLOB:
|
||||||
|
@ -234,7 +234,7 @@ GRegex **tokenize ( const char *input, int case_sensitive )
|
||||||
}
|
}
|
||||||
|
|
||||||
char *saveptr = NULL, *token;
|
char *saveptr = NULL, *token;
|
||||||
GRegex **retv = NULL;
|
GRegex **retv = NULL;
|
||||||
if ( !config.tokenize ) {
|
if ( !config.tokenize ) {
|
||||||
retv = g_malloc0 ( sizeof ( GRegex* ) * 2 );
|
retv = g_malloc0 ( sizeof ( GRegex* ) * 2 );
|
||||||
retv[0] = (GRegex *) create_regex ( input, case_sensitive );
|
retv[0] = (GRegex *) create_regex ( input, case_sensitive );
|
||||||
|
@ -306,47 +306,35 @@ int find_arg_uint ( const char * const key, unsigned int *val )
|
||||||
|
|
||||||
char helper_parse_char ( const char *arg )
|
char helper_parse_char ( const char *arg )
|
||||||
{
|
{
|
||||||
int len = strlen ( arg );
|
const size_t len = strlen ( arg );
|
||||||
// If the length is 1, it is not escaped.
|
// If the length is 1, it is not escaped.
|
||||||
if ( len == 1 ) {
|
if ( len == 1 ) {
|
||||||
return arg[0];
|
return arg[0];
|
||||||
}
|
}
|
||||||
// If the length is 2 and the first character is '\', we unescape it.
|
// If the length is 2 and the first character is '\', we unescape it.
|
||||||
if ( len == 2 && arg[0] == '\\' ) {
|
if ( len == 2 && arg[0] == '\\' ) {
|
||||||
|
switch ( arg[1] )
|
||||||
|
{
|
||||||
// New line
|
// New line
|
||||||
if ( arg[1] == 'n' ) {
|
case 'n': return '\n';
|
||||||
return '\n';
|
|
||||||
}
|
|
||||||
// Bell
|
// Bell
|
||||||
else if ( arg[1] == 'a' ) {
|
case 'a': return '\a';
|
||||||
return '\a';
|
|
||||||
}
|
|
||||||
// Backspace
|
// Backspace
|
||||||
else if ( arg[1] == 'b' ) {
|
case 'b': return '\b';
|
||||||
return '\b';
|
|
||||||
}
|
|
||||||
// Tab
|
// Tab
|
||||||
else if ( arg[1] == 't' ) {
|
case 't': return '\t';
|
||||||
return '\t';
|
|
||||||
}
|
|
||||||
// Vertical tab
|
// Vertical tab
|
||||||
else if ( arg[1] == 'v' ) {
|
case 'v': return '\v';
|
||||||
return '\v';
|
|
||||||
}
|
|
||||||
// Form feed
|
// Form feed
|
||||||
else if ( arg[1] == 'f' ) {
|
case 'f': return '\f';
|
||||||
return '\f';
|
|
||||||
}
|
|
||||||
// Carriage return
|
// Carriage return
|
||||||
else if ( arg[1] == 'r' ) {
|
case 'r': return '\r';
|
||||||
return '\r';
|
|
||||||
}
|
|
||||||
// Forward slash
|
// Forward slash
|
||||||
else if ( arg[1] == '\\' ) {
|
case '\\': return '\\';
|
||||||
return '\\';
|
// 0 line.
|
||||||
}
|
case '0': return '\0';
|
||||||
else if ( arg[1] == '0' ) {
|
default:
|
||||||
return '\0';
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( len > 2 && arg[0] == '\\' && arg[1] == 'x' ) {
|
if ( len > 2 && arg[0] == '\\' && arg[1] == 'x' ) {
|
||||||
|
@ -397,12 +385,10 @@ PangoAttrList *token_match_get_pango_attr ( GRegex **tokens, const char *input,
|
||||||
|
|
||||||
int token_match ( GRegex * const *tokens, const char *input )
|
int token_match ( GRegex * const *tokens, const char *input )
|
||||||
{
|
{
|
||||||
int match = 1;
|
int match = ( tokens != NULL );
|
||||||
// Do a tokenized match.
|
// Do a tokenized match.
|
||||||
if ( tokens ) {
|
for ( int j = 0; match && tokens[j]; j++ ) {
|
||||||
for ( int j = 0; match && tokens[j]; j++ ) {
|
match = g_regex_match ( (const GRegex *) tokens[j], input, 0, NULL );
|
||||||
match = g_regex_match ( (const GRegex *) tokens[j], input, 0, NULL );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
@ -614,26 +600,25 @@ char *rofi_expand_path ( const char *input )
|
||||||
|
|
||||||
unsigned int levenshtein ( const char *needle, const char *haystack )
|
unsigned int levenshtein ( const char *needle, const char *haystack )
|
||||||
{
|
{
|
||||||
unsigned int x, y, lastdiag, olddiag;
|
const size_t needlelen = g_utf8_strlen ( needle, -1 );
|
||||||
size_t needlelen = g_utf8_strlen ( needle, -1 );
|
const size_t haystacklen = g_utf8_strlen ( haystack, -1 );
|
||||||
size_t haystacklen = g_utf8_strlen ( haystack, -1 );
|
|
||||||
unsigned int column[needlelen + 1];
|
unsigned int column[needlelen + 1];
|
||||||
for ( y = 0; y <= needlelen; y++ ) {
|
for ( unsigned int y = 0; y <= needlelen; y++ ) {
|
||||||
column[y] = y;
|
column[y] = y;
|
||||||
}
|
}
|
||||||
for ( x = 1; x <= haystacklen; x++ ) {
|
for ( unsigned int x = 1; x <= haystacklen; x++ ) {
|
||||||
const char *needles = needle;
|
const char *needles = needle;
|
||||||
column[0] = x;
|
column[0] = x;
|
||||||
gunichar haystackc = g_utf8_get_char ( haystack );
|
gunichar haystackc = g_utf8_get_char ( haystack );
|
||||||
if ( !config.case_sensitive ) {
|
if ( !config.case_sensitive ) {
|
||||||
haystackc = g_unichar_tolower ( haystackc );
|
haystackc = g_unichar_tolower ( haystackc );
|
||||||
}
|
}
|
||||||
for ( y = 1, lastdiag = x - 1; y <= needlelen; y++ ) {
|
for ( unsigned int y = 1, lastdiag = x - 1; y <= needlelen; y++ ) {
|
||||||
gunichar needlec = g_utf8_get_char ( needles );
|
gunichar needlec = g_utf8_get_char ( needles );
|
||||||
if ( !config.case_sensitive ) {
|
if ( !config.case_sensitive ) {
|
||||||
needlec = g_unichar_tolower ( needlec );
|
needlec = g_unichar_tolower ( needlec );
|
||||||
}
|
}
|
||||||
olddiag = column[y];
|
unsigned int olddiag = column[y];
|
||||||
column[y] = MIN3 ( column[y] + 1, column[y - 1] + 1, lastdiag + ( needlec == haystackc ? 0 : 1 ) );
|
column[y] = MIN3 ( column[y] + 1, column[y - 1] + 1, lastdiag + ( needlec == haystackc ? 0 : 1 ) );
|
||||||
lastdiag = olddiag;
|
lastdiag = olddiag;
|
||||||
needles = g_utf8_next_char ( needles );
|
needles = g_utf8_next_char ( needles );
|
||||||
|
|
|
@ -352,7 +352,7 @@ static int add_mode ( const char * token )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif // WINDOW_MODE
|
#endif // WINDOW_MODE
|
||||||
// SSh dialog
|
// SSh dialog
|
||||||
if ( strcasecmp ( token, "ssh" ) == 0 ) {
|
if ( strcasecmp ( token, "ssh" ) == 0 ) {
|
||||||
modi[num_modi] = &ssh_mode;
|
modi[num_modi] = &ssh_mode;
|
||||||
num_modi++;
|
num_modi++;
|
||||||
|
|
Loading…
Reference in New Issue