summaryrefslogtreecommitdiffstats
path: root/fselect.c
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2013-06-17 10:00:48 +0000
committerbapt <bapt@FreeBSD.org>2013-06-17 10:00:48 +0000
commit2b5579c9bdbbca29e7b2df1ee9a9e5d1cce2b06f (patch)
treed48b8f5f4c81e26e8dbb6597554286f1d6d53d3a /fselect.c
parenta94245b3d36b447d1f761028da7e072210e64b43 (diff)
downloadFreeBSD-src-2b5579c9bdbbca29e7b2df1ee9a9e5d1cce2b06f.zip
FreeBSD-src-2b5579c9bdbbca29e7b2df1ee9a9e5d1cce2b06f.tar.gz
Update dialog to 1.2-20130523
Diffstat (limited to 'fselect.c')
-rw-r--r--fselect.c68
1 files changed, 46 insertions, 22 deletions
diff --git a/fselect.c b/fselect.c
index 123605e..e6d2a96 100644
--- a/fselect.c
+++ b/fselect.c
@@ -1,5 +1,5 @@
/*
- * $Id: fselect.c,v 1.87 2012/07/01 18:14:09 Zoltan.Kelemen Exp $
+ * $Id: fselect.c,v 1.93 2012/12/30 20:52:25 tom Exp $
*
* fselect.c -- implements the file-selector box
*
@@ -367,7 +367,7 @@ match(char *name, LIST * d_list, LIST * f_list, MATCH * match_list)
matches[data_len++] = f_list->data[i];
}
}
- matches = dlg_realloc(char *, data_len, matches);
+ matches = dlg_realloc(char *, data_len + 1, matches);
match_list->data = matches;
match_list->length = (int) data_len;
}
@@ -457,13 +457,18 @@ fill_lists(char *current, char *input, LIST * d_list, LIST * f_list, int keep)
}
if (rescan) {
+ size_t have = strlen(input);
- strcpy(current, input);
+ if (have > MAX_LEN)
+ have = MAX_LEN;
+ memcpy(current, input, have);
+ current[have] = '\0';
/* refill the lists */
free_list(d_list, TRUE);
free_list(f_list, TRUE);
- strcpy(path, current);
+ memcpy(path, current, have);
+ path[have] = '\0';
if ((leaf = strrchr(path, '/')) != 0) {
*++leaf = 0;
} else {
@@ -483,14 +488,18 @@ fill_lists(char *current, char *input, LIST * d_list, LIST * f_list, int keep)
}
(void) closedir(dp);
/* sort the lists */
- qsort(d_list->data,
- (size_t) d_list->length,
- sizeof(d_list->data[0]),
- compar);
- qsort(f_list->data,
- (size_t) f_list->length,
- sizeof(f_list->data[0]),
- compar);
+ if (d_list->data != 0 && d_list->length > 1) {
+ qsort(d_list->data,
+ (size_t) d_list->length,
+ sizeof(d_list->data[0]),
+ compar);
+ }
+ if (f_list->data != 0 && f_list->length > 1) {
+ qsort(f_list->data,
+ (size_t) f_list->length,
+ sizeof(f_list->data[0]),
+ compar);
+ }
}
(void) show_both_lists(input, d_list, f_list, FALSE);
@@ -573,7 +582,7 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel
int fkey = FALSE;
int code;
int result = DLG_EXIT_UNKNOWN;
- int state = dialog_vars.default_button >=0 ? dlg_default_button() : sTEXT;
+ int state = dialog_vars.default_button >= 0 ? dlg_default_button() : sTEXT;
int button;
int first = (state == sTEXT);
int first_trace = TRUE;
@@ -586,7 +595,7 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel
const char **buttons = dlg_ok_labels();
const char *d_label = _("Directories");
const char *f_label = _("Files");
- char *partial;
+ char *partial = 0;
int min_wide = MIN_WIDE;
int min_items = height ? 0 : 4;
LIST d_list, f_list;
@@ -631,8 +640,10 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel
tbox_x = (width - tbox_width) / 2;
w_text = derwin(dialog, tbox_height, tbox_width, tbox_y, tbox_x);
- if (w_text == 0)
- return DLG_EXIT_ERROR;
+ if (w_text == 0) {
+ result = DLG_EXIT_ERROR;
+ goto finish;
+ }
(void) keypad(w_text, TRUE);
dlg_draw_box(dialog, tbox_y - MARGIN, tbox_x - MARGIN,
@@ -656,8 +667,10 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel
dbox_x = tbox_x;
w_work = derwin(dialog, dbox_height, dbox_width, dbox_y, dbox_x);
- if (w_work == 0)
- return DLG_EXIT_ERROR;
+ if (w_work == 0) {
+ result = DLG_EXIT_ERROR;
+ goto finish;
+ }
(void) keypad(w_work, TRUE);
(void) mvwaddstr(dialog, dbox_y - (MARGIN + 1), dbox_x - MARGIN, d_label);
@@ -675,8 +688,10 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel
fbox_x = tbox_x + dbox_width + (2 * MARGIN);
w_work = derwin(dialog, fbox_height, fbox_width, fbox_y, fbox_x);
- if (w_work == 0)
- return DLG_EXIT_ERROR;
+ if (w_work == 0) {
+ result = DLG_EXIT_ERROR;
+ goto finish;
+ }
(void) keypad(w_work, TRUE);
(void) mvwaddstr(dialog, fbox_y - (MARGIN + 1), fbox_x - MARGIN, f_label);
@@ -791,7 +806,10 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel
continue;
case DLGK_SELECT:
completed = 0;
- partial = 0;
+ if (partial != 0) {
+ free(partial);
+ partial = 0;
+ }
if (state == sFILES && !dselect) {
completed = data_of(&f_list);
} else if (state == sDIRS) {
@@ -808,8 +826,10 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel
offset = (int) strlen(input);
dlg_show_string(w_text, input, offset, inputbox_attr,
0, 0, tbox_width, 0, first);
- if (partial != NULL)
+ if (partial != NULL) {
free(partial);
+ partial = 0;
+ }
continue;
} else { /* if (state < sTEXT) */
(void) beep();
@@ -882,6 +902,10 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel
dlg_mouse_free_regions();
free_list(&d_list, FALSE);
free_list(&f_list, FALSE);
+
+ finish:
+ if (partial != 0)
+ free(partial);
return result;
}
OpenPOWER on IntegriCloud