[AD] file_select_ex patch

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


This patch fixes file_select_ex so that passing an empty string for the 
extension doesn't append a '.' to the end of the selected file, and so that 
clicking Cancel restores the original path string.
Index: src/fsel.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/fsel.c,v
retrieving revision 1.42
diff -u -r1.42 fsel.c
--- src/fsel.c	12 Mar 2005 05:59:51 -0000	1.42
+++ src/fsel.c	11 Sep 2005 23:47:07 -0000
@@ -843,11 +843,15 @@
 {
    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 +922,19 @@
       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, '.');


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/