Re: [AD] file_select_ex patch |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: alleg-developers@xxxxxxxxxx
- Subject: Re: [AD] file_select_ex patch
- From: Chris <chris.kcat@xxxxxxxxxx>
- Date: Thu, 15 Sep 2005 16:09:39 -0700
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:message-id; b=g1hsdYtf/wFV3B+PHgwBlVeogRdgoxj1NZCisDTWAi7uEQdN1Za5ie85S74V+veyycgyRyEWmb/5deCksY+Cz9xc+NSpBvzzZKdeFRkhUWN9bObAPlWAW9j3PHAZrn9gTSGcAUdjJZquQRY3dAcnyLW8DasHQv21pHTg3C6UtcQ=
Updated patch. This should behave the same as the last, but it's cleaned up a
bit, removed redundant code, and what-not.
Index: src/fsel.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/fsel.c,v
retrieving revision 1.42
diff -u -p -r1.42 fsel.c
--- src/fsel.c 12 Mar 2005 05:59:51 -0000 1.42
+++ src/fsel.c 15 Sep 2005 22:58:53 -0000
@@ -417,20 +417,10 @@ static int fs_flist_putter(AL_CONST char
ext = get_extension(s);
for (c=0; c<fext_size; c++) {
if (ustricmp(ext, fext_p[c]) == 0)
- goto Next;
+ break;
}
- return 0;
- }
-
- Next:
- /* Check if file attributes match. */
- if (check_attrib) {
- for (c=0; c<ATTRB_MAX; c++) {
- if ((attrb_state[c] == ATTRB_SET) && (!(attrib & attrb_flag[c])))
- return 0;
- if ((attrb_state[c] == ATTRB_UNSET) && (attrib & attrb_flag[c]))
- return 0;
- }
+ if (c == fext_size)
+ return 0;
}
}
@@ -570,17 +560,10 @@ static int fs_flist_proc(int msg, DIALOG
replace_filename(flist->dir, s, uconvert_ascii("*.*", tmp), sizeof(flist->dir));
- /* The semantics of the attributes passed to file_select_ex() is
- * different from that of for_each_file_ex() in one case: when
- * the 'd' attribute is not mentioned in the set of characters,
- * the other attributes are not taken into account for directories,
- * i.e the directories are all included. So we can't filter with
- * for_each_file_ex() in that case.
+ /* File attributes are checked against directories too, now. This
+ * better follows other file selectors' behavior
*/
- if (attrb_state[ATTRB_DIREC] == ATTRB_ABSENT)
- for_each_file_ex(flist->dir, 0 /* accept all dirs */, FA_LABEL, fs_flist_putter, (void *)1UL /* check */);
- else
- for_each_file_ex(flist->dir, build_attrb_flag(ATTRB_SET), build_attrb_flag(ATTRB_UNSET) | FA_LABEL, fs_flist_putter, (void *)0UL /* don't check */);
+ for_each_file_ex(flist->dir, build_attrb_flag(ATTRB_SET), build_attrb_flag(ATTRB_UNSET) | FA_LABEL, fs_flist_putter, NULL);
usetc(get_filename(flist->dir), 0);
d->d1 = d->d2 = 0;
@@ -843,11 +826,15 @@ int file_select_ex(AL_CONST char *messag
{
static attrb_state_t default_attrb_state[ATTRB_MAX] = DEFAULT_ATTRB_STATE;
int ret;
- char *p;
+ char *p, *backup;
char tmp[32];
ASSERT(message);
ASSERT(path);
+ backup = ustrdup(path);
+ if (!backup)
+ return FALSE;
+
if (width == OLD_FILESEL_WIDTH)
width = 305;
@@ -918,11 +905,19 @@ int file_select_ex(AL_CONST char *messag
fext_p = NULL;
}
- if ((ret == FS_CANCEL) || (!ugetc(get_filename(path))))
+ if (ret == FS_CANCEL) {
+ ustrcpy(path, backup);
+ free(backup);
+ return FALSE;
+ }
+
+ free(backup);
+
+ if (!ugetc(get_filename(path)))
return FALSE;
p = get_extension(path);
- if ((!ugetc(p)) && (ext) && (!ustrpbrk(ext, uconvert_ascii(" ,;", tmp)))) {
+ if ((!ugetc(p)) && (ext) && (ugetc(ext)) && (!ustrpbrk(ext, uconvert_ascii(" ,;", tmp)))) {
size -= ((long)p - (long)path + ucwidth('.'));
if (size >= uwidth_max(U_CURRENT) + ucwidth(0)) { /* do not end with '.' */
p += usetc(p, '.');