* cmd.c (select_unselect_cmd): Collect repeated code from

(un)?select_cmd here.  Fix rare off-by-one and memory leak if
        empty pattern passed.

        (select_cmd): Use select_unselect_cmd().
        (unselect_cmd): Likewise.
This commit is contained in:
Andrew V. Samoilov 2004-10-25 09:38:59 +00:00
parent 2c8db2c43d
commit bcaf2b272b
2 changed files with 42 additions and 62 deletions

View File

@ -1,3 +1,12 @@
2004-10-25 Andrew V. Samoilov <sav@bcs.zp.ua>
* cmd.c (select_unselect_cmd): Collect repeated code from
(un)?select_cmd here. Fix rare off-by-one and memory leak if
empty pattern passed.
(select_cmd): Use select_unselect_cmd().
(unselect_cmd): Likewise.
2004-10-23 Roland Illig <roland.illig@gmx.de>
* complete.c (environ): Don't declare environ on Cygwin.

View File

@ -471,95 +471,66 @@ void reverse_selection_cmd (void)
}
}
void select_cmd (void)
static void
select_unselect_cmd (const char *title, int cmd)
{
char *reg_exp, *reg_exp_t;
int i;
int c;
int dirflag = 0;
reg_exp = input_dialog (_(" Select "), "", easy_patterns ? "*" : ".");
reg_exp = input_dialog (title, "", easy_patterns ? "*" : ".");
if (!reg_exp)
return;
if (!*reg_exp) {
g_free (reg_exp);
return;
}
reg_exp_t = reg_exp;
/* Check if they specified a directory */
if (*reg_exp_t == PATH_SEP){
dirflag = 1;
reg_exp_t++;
if (*reg_exp_t == PATH_SEP) {
dirflag = 1;
reg_exp_t++;
}
if (reg_exp_t [strlen(reg_exp_t) - 1] == PATH_SEP){
dirflag = 1;
reg_exp_t [strlen(reg_exp_t) - 1] = 0;
if (reg_exp_t[strlen (reg_exp_t) - 1] == PATH_SEP) {
dirflag = 1;
reg_exp_t[strlen (reg_exp_t) - 1] = 0;
}
for (i = 0; i < current_panel->count; i++){
if (!strcmp (current_panel->dir.list [i].fname, ".."))
continue;
if (S_ISDIR (current_panel->dir.list [i].st.st_mode)){
for (i = 0; i < current_panel->count; i++) {
if (!strcmp (current_panel->dir.list[i].fname, ".."))
continue;
if (S_ISDIR (current_panel->dir.list[i].st.st_mode)) {
if (!dirflag)
continue;
} else {
if (dirflag)
continue;
continue;
} else {
if (dirflag)
continue;
}
c = regexp_match (reg_exp_t, current_panel->dir.list [i].fname, match_file);
if (c == -1){
c = regexp_match (reg_exp_t, current_panel->dir.list[i].fname,
match_file);
if (c == -1) {
message (1, MSG_ERROR, _(" Malformed regular expression "));
g_free (reg_exp);
return;
}
if (c){
do_file_mark (current_panel, i, 1);
if (c) {
do_file_mark (current_panel, i, cmd);
}
}
g_free (reg_exp);
}
void select_cmd (void)
{
select_unselect_cmd (_(" Select "), 1);
}
void unselect_cmd (void)
{
char *reg_exp, *reg_exp_t;
int i;
int c;
int dirflag = 0;
reg_exp = input_dialog (_(" Unselect "),"", easy_patterns ? "*" : ".");
if (!reg_exp)
return;
reg_exp_t = reg_exp;
/* Check if they specified directory matching */
if (*reg_exp_t == PATH_SEP){
dirflag = 1;
reg_exp_t ++;
}
if (reg_exp_t [strlen(reg_exp_t) - 1] == PATH_SEP){
dirflag = 1;
reg_exp_t [strlen(reg_exp_t) - 1] = 0;
}
for (i = 0; i < current_panel->count; i++){
if (!strcmp (current_panel->dir.list [i].fname, ".."))
continue;
if (S_ISDIR (current_panel->dir.list [i].st.st_mode)){
if (!dirflag)
continue;
} else {
if (dirflag)
continue;
}
c = regexp_match (reg_exp_t, current_panel->dir.list [i].fname, match_file);
if (c == -1){
message (1, MSG_ERROR, _(" Malformed regular expression "));
g_free (reg_exp);
return;
}
if (c){
do_file_mark (current_panel, i, 0);
}
}
g_free (reg_exp);
select_unselect_cmd (_(" Unselect "), 0);
}
/* Check if the file exists */