changeset 1278:700dc6818431

Some code in dw_file_browse() seems to have gotten clobbered. This reenables defpath support on OS/2... memset() screwed it up.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 30 Oct 2011 12:33:07 +0000
parents 107e38a29eeb
children ee9a233f1b42
files os2/dw.c
diffstat 1 files changed, 34 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/os2/dw.c	Sun Oct 30 11:50:45 2011 +0000
+++ b/os2/dw.c	Sun Oct 30 12:33:07 2011 +0000
@@ -33,6 +33,7 @@
 #include <direct.h>
 #endif
 #include <sys/time.h>
+#include <sys/stat.h>
 #include "dw.h"
 
 #define QWP_USER 0
@@ -10091,31 +10092,49 @@
    }
    else
    {
-      FILEDLG fild;
+      FILEDLG fild = { 0 };
       HWND hwndFile;
       int len;
+      struct stat buf;
 
       if(defpath)
          strcpy(fild.szFullFile, defpath);
-      else
-         strcpy(fild.szFullFile, "");
 
       len = strlen(fild.szFullFile);
 
+      /* If we have a defpath */
       if(len)
       {
-         if(fild.szFullFile[len-1] != '\\')
-            strcat(fild.szFullFile, "\\");
-      }
-      strcat(fild.szFullFile, "*");
-
-      if(ext)
-      {
-         strcat(fild.szFullFile, ".");
-         strcat(fild.szFullFile, ext);
-      }
-
-      memset(&fild, 0, sizeof(FILEDLG));
+          /* Check to see if it exists */
+          if(stat(defpath, &buf) == 0)
+          {
+              /* If it is a directory... make sure there is a trailing \ */
+              if(buf.st_mode & S_IFDIR)
+              {
+                  if(fild.szFullFile[len-1] != '\\')
+                      strcat(fild.szFullFile, "\\");
+                  /* Set len to 0 so the wildcard gets added below */
+                  len = 0;
+              }
+          }
+      }
+
+      /* If we need a wildcard (defpath isn't a file) */
+      if(!len)
+      {
+          /* Add a * to get all files... */
+          strcat(fild.szFullFile, "*");
+
+          /* If an extension was requested... */
+          if(ext)
+          {
+              /* Limit the results further */
+              strcat(fild.szFullFile, ".");
+              strcat(fild.szFullFile, ext);
+          }
+      }
+
+      /* Setup the structure */
       fild.cbSize = sizeof(FILEDLG);
       fild.fl = FDS_CENTER | FDS_OPEN_DIALOG;
       fild.pszTitle = title;