Use gboolean instead of int in file/dir sort related functions.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2018-01-20 10:55:37 +03:00
parent d78fc418ec
commit 8b6f4ef2c2
8 changed files with 73 additions and 75 deletions

View File

@ -134,7 +134,7 @@
#define TMPDIR_DEFAULT "/tmp"
#define SCRIPT_SUFFIX ""
#define get_default_editor() "vi"
#define OS_SORT_CASE_SENSITIVE_DEFAULT 1
#define OS_SORT_CASE_SENSITIVE_DEFAULT TRUE
#define UTF8_CHAR_LEN 6
/* Used to distinguish between a normal MC termination and */

View File

@ -136,20 +136,20 @@ struct str_class
/*I*/ const char *(*trunc) (const char *, int);
/*I*/ int (*offset_to_pos) (const char *, size_t);
/*I*/ int (*column_to_pos) (const char *, size_t);
/*I*/ char *(*create_search_needle) (const char *, int);
void (*release_search_needle) (char *, int);
const char *(*search_first) (const char *, const char *, int);
const char *(*search_last) (const char *, const char *, int);
/*I*/ char *(*create_search_needle) (const char *, gboolean);
void (*release_search_needle) (char *, gboolean);
const char *(*search_first) (const char *, const char *, gboolean);
const char *(*search_last) (const char *, const char *, gboolean);
int (*compare) (const char *, const char *);
/*I*/ int (*ncompare) (const char *, const char *);
/*I*/ int (*casecmp) (const char *, const char *);
/*I*/ int (*ncasecmp) (const char *, const char *);
/*I*/ int (*prefix) (const char *, const char *);
/*I*/ int (*caseprefix) (const char *, const char *);
/*I*/ char *(*create_key) (const char *text, int case_sen);
/*I*/ char *(*create_key_for_filename) (const char *text, int case_sen);
/*I*/ int (*key_collate) (const char *t1, const char *t2, int case_sen);
/*I*/ void (*release_key) (char *key, int case_sen);
/*I*/ char *(*create_key) (const char *text, gboolean case_sen);
/*I*/ char *(*create_key_for_filename) (const char *text, gboolean case_sen);
/*I*/ int (*key_collate) (const char *t1, const char *t2, gboolean case_sen);
/*I*/ void (*release_key) (char *key, gboolean case_sen);
/*I*/};
/*** global variables defined in .c file *********************************************************/
@ -455,19 +455,19 @@ const char *str_trunc (const char *text, int width);
* so needle can be reused
* in UTF-8 return normalized form of needle
*/
char *str_create_search_needle (const char *needle, int case_sen);
char *str_create_search_needle (const char *needle, gboolean case_sen);
/* free needle returned by str_create_search_needle
*/
void str_release_search_needle (char *needle, int case_sen);
void str_release_search_needle (char *needle, gboolean case_sen);
/* search for first occurrence of search in text
*/
const char *str_search_first (const char *text, const char *needle, int case_sen);
const char *str_search_first (const char *text, const char *needle, gboolean case_sen);
/* search for last occurrence of search in text
*/
const char *str_search_last (const char *text, const char *needle, int case_sen);
const char *str_search_last (const char *text, const char *needle, gboolean case_sen);
/* case sensitive compare two strings
* I
@ -507,25 +507,25 @@ int str_caseprefix (const char *text, const char *prefix);
/* create a key that is used by str_key_collate
* I
*/
char *str_create_key (const char *text, int case_sen);
char *str_create_key (const char *text, gboolean case_sen);
/* create a key that is used by str_key_collate
* should aware dot '.' in text
* I
*/
char *str_create_key_for_filename (const char *text, int case_sen);
char *str_create_key_for_filename (const char *text, gboolean case_sen);
/* compare two string using LC_COLLATE, if is possible
* if case_sen is set, comparing is case sensitive,
* case_sen must be same for str_create_key, str_key_collate and str_release_key
* I
*/
int str_key_collate (const char *t1, const char *t2, int case_sen);
int str_key_collate (const char *t1, const char *t2, gboolean case_sen);
/* release_key created by str_create_key, only rigth way to release key
* I
*/
void str_release_key (char *key, int case_sen);
void str_release_key (char *key, gboolean case_sen);
/* return TRUE if codeset_name is utf8 or utf-8
* I

View File

@ -787,7 +787,7 @@ str_trunc (const char *text, int width)
/* --------------------------------------------------------------------------------------------- */
char *
str_create_search_needle (const char *needle, int case_sen)
str_create_search_needle (const char *needle, gboolean case_sen)
{
return used_class.create_search_needle (needle, case_sen);
}
@ -795,7 +795,7 @@ str_create_search_needle (const char *needle, int case_sen)
/* --------------------------------------------------------------------------------------------- */
void
str_release_search_needle (char *needle, int case_sen)
str_release_search_needle (char *needle, gboolean case_sen)
{
used_class.release_search_needle (needle, case_sen);
}
@ -803,7 +803,7 @@ str_release_search_needle (char *needle, int case_sen)
/* --------------------------------------------------------------------------------------------- */
const char *
str_search_first (const char *text, const char *search, int case_sen)
str_search_first (const char *text, const char *search, gboolean case_sen)
{
return used_class.search_first (text, search, case_sen);
}
@ -811,7 +811,7 @@ str_search_first (const char *text, const char *search, int case_sen)
/* --------------------------------------------------------------------------------------------- */
const char *
str_search_last (const char *text, const char *search, int case_sen)
str_search_last (const char *text, const char *search, gboolean case_sen)
{
return used_class.search_last (text, search, case_sen);
}
@ -883,7 +883,7 @@ str_fix_string (char *text)
/* --------------------------------------------------------------------------------------------- */
char *
str_create_key (const char *text, int case_sen)
str_create_key (const char *text, gboolean case_sen)
{
return used_class.create_key (text, case_sen);
}
@ -891,7 +891,7 @@ str_create_key (const char *text, int case_sen)
/* --------------------------------------------------------------------------------------------- */
char *
str_create_key_for_filename (const char *text, int case_sen)
str_create_key_for_filename (const char *text, gboolean case_sen)
{
return used_class.create_key_for_filename (text, case_sen);
}
@ -899,7 +899,7 @@ str_create_key_for_filename (const char *text, int case_sen)
/* --------------------------------------------------------------------------------------------- */
int
str_key_collate (const char *t1, const char *t2, int case_sen)
str_key_collate (const char *t1, const char *t2, gboolean case_sen)
{
return used_class.key_collate (t1, t2, case_sen);
}
@ -907,7 +907,7 @@ str_key_collate (const char *t1, const char *t2, int case_sen)
/* --------------------------------------------------------------------------------------------- */
void
str_release_key (char *key, int case_sen)
str_release_key (char *key, gboolean case_sen)
{
used_class.release_key (key, case_sen);
}

View File

@ -553,7 +553,7 @@ str_8bit_column_to_pos (const char *text, size_t pos)
/* --------------------------------------------------------------------------------------------- */
static char *
str_8bit_create_search_needle (const char *needle, int case_sen)
str_8bit_create_search_needle (const char *needle, gboolean case_sen)
{
(void) case_sen;
return (char *) needle;
@ -562,7 +562,7 @@ str_8bit_create_search_needle (const char *needle, int case_sen)
/* --------------------------------------------------------------------------------------------- */
static void
str_8bit_release_search_needle (char *needle, int case_sen)
str_8bit_release_search_needle (char *needle, gboolean case_sen)
{
(void) case_sen;
(void) needle;
@ -589,14 +589,14 @@ str_8bit_strdown (const char *str)
/* --------------------------------------------------------------------------------------------- */
static const char *
str_8bit_search_first (const char *text, const char *search, int case_sen)
str_8bit_search_first (const char *text, const char *search, gboolean case_sen)
{
char *fold_text;
char *fold_search;
const char *match;
fold_text = (case_sen) ? (char *) text : str_8bit_strdown (text);
fold_search = (case_sen) ? (char *) search : str_8bit_strdown (search);
fold_text = case_sen ? (char *) text : str_8bit_strdown (text);
fold_search = case_sen ? (char *) search : str_8bit_strdown (search);
match = g_strstr_len (fold_text, -1, fold_search);
if (match != NULL)
@ -619,14 +619,14 @@ str_8bit_search_first (const char *text, const char *search, int case_sen)
/* --------------------------------------------------------------------------------------------- */
static const char *
str_8bit_search_last (const char *text, const char *search, int case_sen)
str_8bit_search_last (const char *text, const char *search, gboolean case_sen)
{
char *fold_text;
char *fold_search;
const char *match;
fold_text = (case_sen) ? (char *) text : str_8bit_strdown (text);
fold_search = (case_sen) ? (char *) search : str_8bit_strdown (search);
fold_text = case_sen ? (char *) text : str_8bit_strdown (text);
fold_search = case_sen ? (char *) search : str_8bit_strdown (search);
match = g_strrstr_len (fold_text, -1, fold_search);
if (match != NULL)
@ -775,26 +775,23 @@ str_8bit_fix_string (char *text)
/* --------------------------------------------------------------------------------------------- */
static char *
str_8bit_create_key (const char *text, int case_sen)
str_8bit_create_key (const char *text, gboolean case_sen)
{
return (case_sen) ? (char *) text : str_8bit_strdown (text);
return case_sen ? (char *) text : str_8bit_strdown (text);
}
/* --------------------------------------------------------------------------------------------- */
static int
str_8bit_key_collate (const char *t1, const char *t2, int case_sen)
str_8bit_key_collate (const char *t1, const char *t2, gboolean case_sen)
{
if (case_sen)
return strcmp (t1, t2);
else
return strcoll (t1, t2);
return case_sen ? strcmp (t1, t2) : strcoll (t1, t2);
}
/* --------------------------------------------------------------------------------------------- */
static void
str_8bit_release_key (char *key, int case_sen)
str_8bit_release_key (char *key, gboolean case_sen)
{
if (!case_sen)
g_free (key);

View File

@ -551,7 +551,7 @@ str_ascii_column_to_pos (const char *text, size_t pos)
/* --------------------------------------------------------------------------------------------- */
static char *
str_ascii_create_search_needle (const char *needle, int case_sen)
str_ascii_create_search_needle (const char *needle, gboolean case_sen)
{
(void) case_sen;
return (char *) needle;
@ -560,7 +560,7 @@ str_ascii_create_search_needle (const char *needle, int case_sen)
/* --------------------------------------------------------------------------------------------- */
static void
str_ascii_release_search_needle (char *needle, int case_sen)
str_ascii_release_search_needle (char *needle, gboolean case_sen)
{
(void) case_sen;
(void) needle;
@ -570,14 +570,14 @@ str_ascii_release_search_needle (char *needle, int case_sen)
/* --------------------------------------------------------------------------------------------- */
static const char *
str_ascii_search_first (const char *text, const char *search, int case_sen)
str_ascii_search_first (const char *text, const char *search, gboolean case_sen)
{
char *fold_text;
char *fold_search;
const char *match;
fold_text = (case_sen) ? (char *) text : g_ascii_strdown (text, -1);
fold_search = (case_sen) ? (char *) search : g_ascii_strdown (search, -1);
fold_text = case_sen ? (char *) text : g_ascii_strdown (text, -1);
fold_search = case_sen ? (char *) search : g_ascii_strdown (search, -1);
match = g_strstr_len (fold_text, -1, fold_search);
if (match != NULL)
@ -600,14 +600,14 @@ str_ascii_search_first (const char *text, const char *search, int case_sen)
/* --------------------------------------------------------------------------------------------- */
static const char *
str_ascii_search_last (const char *text, const char *search, int case_sen)
str_ascii_search_last (const char *text, const char *search, gboolean case_sen)
{
char *fold_text;
char *fold_search;
const char *match;
fold_text = (case_sen) ? (char *) text : g_ascii_strdown (text, -1);
fold_search = (case_sen) ? (char *) search : g_ascii_strdown (search, -1);
fold_text = case_sen ? (char *) text : g_ascii_strdown (text, -1);
fold_search = case_sen ? (char *) search : g_ascii_strdown (search, -1);
match = g_strrstr_len (fold_text, -1, fold_search);
if (match != NULL)
@ -671,7 +671,7 @@ str_ascii_fix_string (char *text)
/* --------------------------------------------------------------------------------------------- */
static char *
str_ascii_create_key (const char *text, int case_sen)
str_ascii_create_key (const char *text, gboolean case_sen)
{
(void) case_sen;
return (char *) text;
@ -680,15 +680,15 @@ str_ascii_create_key (const char *text, int case_sen)
/* --------------------------------------------------------------------------------------------- */
static int
str_ascii_key_collate (const char *t1, const char *t2, int case_sen)
str_ascii_key_collate (const char *t1, const char *t2, gboolean case_sen)
{
return (case_sen) ? strcmp (t1, t2) : g_ascii_strcasecmp (t1, t2);
return case_sen ? strcmp (t1, t2) : g_ascii_strcasecmp (t1, t2);
}
/* --------------------------------------------------------------------------------------------- */
static void
str_ascii_release_key (char *key, int case_sen)
str_ascii_release_key (char *key, gboolean case_sen)
{
(void) key;
(void) case_sen;

View File

@ -956,7 +956,7 @@ str_utf8_column_to_pos (const char *text, size_t pos)
/* --------------------------------------------------------------------------------------------- */
static char *
str_utf8_create_search_needle (const char *needle, int case_sen)
str_utf8_create_search_needle (const char *needle, gboolean case_sen)
{
char *fold, *result;
@ -966,7 +966,6 @@ str_utf8_create_search_needle (const char *needle, int case_sen)
if (case_sen)
return g_utf8_normalize (needle, -1, G_NORMALIZE_ALL);
fold = g_utf8_casefold (needle, -1);
result = g_utf8_normalize (fold, -1, G_NORMALIZE_ALL);
g_free (fold);
@ -976,7 +975,7 @@ str_utf8_create_search_needle (const char *needle, int case_sen)
/* --------------------------------------------------------------------------------------------- */
static void
str_utf8_release_search_needle (char *needle, int case_sen)
str_utf8_release_search_needle (char *needle, gboolean case_sen)
{
(void) case_sen;
g_free (needle);
@ -985,7 +984,7 @@ str_utf8_release_search_needle (char *needle, int case_sen)
/* --------------------------------------------------------------------------------------------- */
static const char *
str_utf8_search_first (const char *text, const char *search, int case_sen)
str_utf8_search_first (const char *text, const char *search, gboolean case_sen)
{
char *fold_text;
char *deco_text;
@ -993,7 +992,7 @@ str_utf8_search_first (const char *text, const char *search, int case_sen)
const char *result = NULL;
const char *m;
fold_text = (case_sen) ? (char *) text : g_utf8_casefold (text, -1);
fold_text = case_sen ? (char *) text : g_utf8_casefold (text, -1);
deco_text = g_utf8_normalize (fold_text, -1, G_NORMALIZE_ALL);
match = deco_text;
@ -1029,7 +1028,7 @@ str_utf8_search_first (const char *text, const char *search, int case_sen)
/* --------------------------------------------------------------------------------------------- */
static const char *
str_utf8_search_last (const char *text, const char *search, int case_sen)
str_utf8_search_last (const char *text, const char *search, gboolean case_sen)
{
char *fold_text;
char *deco_text;
@ -1037,7 +1036,7 @@ str_utf8_search_last (const char *text, const char *search, int case_sen)
const char *result = NULL;
const char *m;
fold_text = (case_sen) ? (char *) text : g_utf8_casefold (text, -1);
fold_text = case_sen ? (char *) text : g_utf8_casefold (text, -1);
deco_text = g_utf8_normalize (fold_text, -1, G_NORMALIZE_ALL);
do
@ -1343,7 +1342,7 @@ str_utf8_caseprefix (const char *text, const char *prefix)
/* --------------------------------------------------------------------------------------------- */
static char *
str_utf8_create_key_gen (const char *text, int case_sen,
str_utf8_create_key_gen (const char *text, gboolean case_sen,
gchar * (*keygen) (const gchar * text, gssize size))
{
char *result;
@ -1417,7 +1416,7 @@ str_utf8_create_key_gen (const char *text, int case_sen,
/* --------------------------------------------------------------------------------------------- */
static char *
str_utf8_create_key (const char *text, int case_sen)
str_utf8_create_key (const char *text, gboolean case_sen)
{
return str_utf8_create_key_gen (text, case_sen, g_utf8_collate_key);
}
@ -1426,7 +1425,7 @@ str_utf8_create_key (const char *text, int case_sen)
#ifdef MC__USE_STR_UTF8_CREATE_KEY_FOR_FILENAME
static char *
str_utf8_create_key_for_filename (const char *text, int case_sen)
str_utf8_create_key_for_filename (const char *text, gboolean case_sen)
{
return str_utf8_create_key_gen (text, case_sen, g_utf8_collate_key_for_filename);
}
@ -1435,7 +1434,7 @@ str_utf8_create_key_for_filename (const char *text, int case_sen)
/* --------------------------------------------------------------------------------------------- */
static int
str_utf8_key_collate (const char *t1, const char *t2, int case_sen)
str_utf8_key_collate (const char *t1, const char *t2, gboolean case_sen)
{
(void) case_sen;
return strcmp (t1, t2);
@ -1444,7 +1443,7 @@ str_utf8_key_collate (const char *t1, const char *t2, int case_sen)
/* --------------------------------------------------------------------------------------------- */
static void
str_utf8_release_key (char *key, int case_sen)
str_utf8_release_key (char *key, gboolean case_sen)
{
(void) case_sen;
g_free (key);

View File

@ -68,7 +68,7 @@
static int reverse = 1;
/* Are the files sorted case sensitively? */
static int case_sensitive = OS_SORT_CASE_SENSITIVE_DEFAULT;
static gboolean case_sensitive = OS_SORT_CASE_SENSITIVE_DEFAULT;
/* Are the exec_bit files top in list */
static gboolean exec_first = TRUE;
@ -391,7 +391,7 @@ sort_ext (file_entry_t * a, file_entry_t * b)
b->second_sort_key = str_create_key (extension (b->fname), case_sensitive);
r = str_key_collate (a->second_sort_key, b->second_sort_key, case_sensitive);
if (r)
if (r != 0)
return r * reverse;
else
return sort_name (a, b);

View File

@ -1456,12 +1456,13 @@ panel_load_setup (WPanel * panel, const char *section)
size_t i;
char *buffer, buffer2[BUF_TINY];
panel->sort_info.reverse = mc_config_get_int (mc_global.panels_config, section, "reverse", 0);
panel->sort_info.reverse =
mc_config_get_bool (mc_global.panels_config, section, "reverse", FALSE);
panel->sort_info.case_sensitive =
mc_config_get_int (mc_global.panels_config, section, "case_sensitive",
OS_SORT_CASE_SENSITIVE_DEFAULT);
mc_config_get_bool (mc_global.panels_config, section, "case_sensitive",
OS_SORT_CASE_SENSITIVE_DEFAULT);
panel->sort_info.exec_first =
mc_config_get_int (mc_global.panels_config, section, "exec_first", 0);
mc_config_get_bool (mc_global.panels_config, section, "exec_first", FALSE);
/* Load sort order */
buffer = mc_config_get_string (mc_global.panels_config, section, "sort_order", "name");
@ -1514,10 +1515,11 @@ panel_save_setup (WPanel * panel, const char *section)
char buffer[BUF_TINY];
size_t i;
mc_config_set_int (mc_global.panels_config, section, "reverse", panel->sort_info.reverse);
mc_config_set_int (mc_global.panels_config, section, "case_sensitive",
panel->sort_info.case_sensitive);
mc_config_set_int (mc_global.panels_config, section, "exec_first", panel->sort_info.exec_first);
mc_config_set_bool (mc_global.panels_config, section, "reverse", panel->sort_info.reverse);
mc_config_set_bool (mc_global.panels_config, section, "case_sensitive",
panel->sort_info.case_sensitive);
mc_config_set_bool (mc_global.panels_config, section, "exec_first",
panel->sort_info.exec_first);
mc_config_set_string (mc_global.panels_config, section, "sort_order", panel->sort_field->id);