]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilesel.c
Support added for building using a GNU toolchain on Win32,
[~andy/gtk] / gtk / gtkfilesel.c
index 1240f02264b45728c62f208f69f60be68a9d4ce3..5a654a072cb7557cc6e56a171508b4a098a5d610 100644 (file)
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
+
+/*
+ * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+#include "config.h"
+
+#include <glib.h>              /* To get stat->_stat redefinition
+                                *  for mingw32
+                                */
+
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
+#endif
+#ifdef HAVE_DIRENT_H
 #include <dirent.h>
+#endif
 #include <stdlib.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <string.h>
 #include <errno.h>
+#ifdef HAVE_PWD_H
 #include <pwd.h>
+#endif
+
 #include "fnmatch.h"
 
 #include "gdk/gdkkeysyms.h"
 #include "gtkoptionmenu.h"
 #include "gtkclist.h"
 #include "gtkdialog.h"
+#include "gtkintl.h"
+
+#ifdef WIN32
+#define STRICT
+#include <windows.h>
+
+#ifdef NATIVE_WIN32
+#include <direct.h>
+#include <io.h>
+#define mkdir(p,m) _mkdir(p)
+#ifndef S_ISDIR
+#define S_ISDIR(mode) ((mode)&_S_IFDIR)
+#endif
+
+#endif /* NATIVE_WIN32 */
+
+#endif /* WIN32 */
 
 #define DIR_LIST_WIDTH   180
 #define DIR_LIST_HEIGHT  180
@@ -158,7 +198,6 @@ struct _CompletionState
 
   gchar *user_dir_name_buffer;
   gint user_directories_len;
-  gchar *user_home_dir;
 
   gchar *last_completion_text;
 
@@ -245,13 +284,17 @@ static gchar*              cmpl_completion_fullname (gchar*, CompletionState* cm
 static CompletionDir* open_ref_dir         (gchar* text_to_complete,
                                            gchar** remaining_text,
                                            CompletionState* cmpl_state);
+#ifndef WIN32
 static gboolean       check_dir            (gchar *dir_name, 
                                            struct stat *result, 
                                            gboolean *stat_subdirs);
+#endif
 static CompletionDir* open_dir             (gchar* dir_name,
                                            CompletionState* cmpl_state);
+#ifdef HAVE_PWD_H
 static CompletionDir* open_user_dir        (gchar* text_to_complete,
                                            CompletionState *cmpl_state);
+#endif
 static CompletionDir* open_relative_dir    (gchar* dir_name, CompletionDir* dir,
                                            CompletionState *cmpl_state);
 static CompletionDirSent* open_new_dir     (gchar* dir_name, 
@@ -277,9 +320,11 @@ static CompletionDir* find_completion_dir(gchar* text_to_complete,
                                          CompletionState* cmpl_state);
 static PossibleCompletion* append_completion_text(gchar* text,
                                                  CompletionState* cmpl_state);
+#ifdef HAVE_PWD_H
 static gint get_pwdb(CompletionState* cmpl_state);
-static gint first_diff_index(gchar* pat, gchar* text);
 static gint compare_user_dir(const void* a, const void* b);
+#endif
+static gint first_diff_index(gchar* pat, gchar* text);
 static gint compare_cmpl_dir(const void* a, const void* b);
 static void update_cmpl(PossibleCompletion* poss,
                        CompletionState* cmpl_state);
@@ -322,6 +367,71 @@ static GtkWindowClass *parent_class = NULL;
 /* Saves errno when something cmpl does fails. */
 static gint cmpl_errno;
 
+#ifdef __CYGWIN32__
+/*
+ * Take the path currently in the file selection
+ * entry field and translate as necessary from
+ * a WIN32 style to CYGWIN32 style path.  For
+ * instance translate:
+ * x:\somepath\file.jpg
+ * to:
+ * //x/somepath/file.jpg
+ *
+ * Replace the path in the selection text field.
+ * Return a boolean value concerning whether a
+ * translation had to be made.
+ */
+int
+translate_win32_path(GtkFileSelection *filesel)
+{
+  int updated = 0;
+  gchar *path;
+
+  /*
+   * Retrieve the current path
+   */
+  path = gtk_entry_get_text (GTK_ENTRY (filesel->selection_entry));
+
+  /*
+   * Translate only if this looks like a DOS-ish
+   * path... First handle any drive letters.
+   */
+  if (isalpha(path[0]) && (path[1] == ':')) {
+    /*
+     * This part kind of stinks... It isn't possible
+     * to know if there is enough space in the current
+     * string for the extra character required in this
+     * conversion.  Assume that there isn't enough space
+     * and use the set function on the text field to
+     * set the newly created string.
+     */
+    gchar *newPath;
+
+    newPath = g_malloc(strlen(path) + 2);
+    sprintf(newPath, "//%c/%s", path[0], (path + 3));
+    gtk_entry_set_text (GTK_ENTRY (filesel->selection_entry), newPath);
+
+    path = newPath;
+    updated = 1;
+  }
+
+  /*
+   * Now, replace backslashes with forward slashes 
+   * if necessary.
+   */
+  if (strchr(path, '\\')) {
+    int index;
+    for (index = 0; path[index] != '\0'; index++)
+      if (path[index] == '\\')
+       path[index] = '/';
+
+    updated = 1;
+  }
+    
+  return updated;
+}
+#endif
+
 GtkType
 gtk_file_selection_get_type (void)
 {
@@ -369,8 +479,8 @@ gtk_file_selection_init (GtkFileSelection *filesel)
   GtkWidget *pulldown_hbox;
   GtkWidget *scrolled_win;
 
-  static const char *dir_title [] = { "Directories", NULL };
-  static const char *file_title [] = { "Files", NULL };
+  char *dir_title [2];
+  char *file_title [2];
   
   filesel->cmpl_state = cmpl_init_state ();
 
@@ -407,6 +517,8 @@ gtk_file_selection_init (GtkFileSelection *filesel)
   gtk_widget_show (list_hbox);
 
   /* The directories clist */
+  dir_title[0] = _("Directories");
+  dir_title[1] = NULL;
   filesel->dir_list = gtk_clist_new_with_titles (1, (gchar**) dir_title);
   gtk_widget_set_usize (filesel->dir_list, DIR_LIST_WIDTH, DIR_LIST_HEIGHT);
   gtk_signal_connect (GTK_OBJECT (filesel->dir_list), "select_row",
@@ -424,6 +536,8 @@ gtk_file_selection_init (GtkFileSelection *filesel)
   gtk_widget_show (scrolled_win);
 
   /* The files clist */
+  file_title[0] = _("Files");
+  file_title[1] = NULL;
   filesel->file_list = gtk_clist_new_with_titles (1, (gchar**) file_title);
   gtk_widget_set_usize (filesel->file_list, FILE_LIST_WIDTH, FILE_LIST_HEIGHT);
   gtk_signal_connect (GTK_OBJECT (filesel->file_list), "select_row",
@@ -454,14 +568,14 @@ gtk_file_selection_init (GtkFileSelection *filesel)
   gtk_widget_show (confirm_area);
 
   /*  The OK button  */
-  filesel->ok_button = gtk_button_new_with_label ("OK");
+  filesel->ok_button = gtk_button_new_with_label (_("OK"));
   GTK_WIDGET_SET_FLAGS (filesel->ok_button, GTK_CAN_DEFAULT);
   gtk_box_pack_start (GTK_BOX (confirm_area), filesel->ok_button, TRUE, TRUE, 0);
   gtk_widget_grab_default (filesel->ok_button);
   gtk_widget_show (filesel->ok_button);
 
   /*  The Cancel button  */
-  filesel->cancel_button = gtk_button_new_with_label ("Cancel");
+  filesel->cancel_button = gtk_button_new_with_label (_("Cancel"));
   GTK_WIDGET_SET_FLAGS (filesel->cancel_button, GTK_CAN_DEFAULT);
   gtk_box_pack_start (GTK_BOX (confirm_area), filesel->cancel_button, TRUE, TRUE, 0);
   gtk_widget_show (filesel->cancel_button);
@@ -492,9 +606,9 @@ gtk_file_selection_init (GtkFileSelection *filesel)
     {
       gchar err_buf[256];
 
-      sprintf (err_buf, "Directory unreadable: %s", cmpl_strerror (cmpl_errno));
+      sprintf (err_buf, _("Directory unreadable: %s"), cmpl_strerror (cmpl_errno));
 
-      gtk_label_set (GTK_LABEL (filesel->selection_text), err_buf);
+      gtk_label_set_text (GTK_LABEL (filesel->selection_text), err_buf);
     }
   else
     {
@@ -524,7 +638,7 @@ gtk_file_selection_show_fileop_buttons (GtkFileSelection *filesel)
   /* delete, create directory, and rename */
   if (!filesel->fileop_c_dir) 
     {
-      filesel->fileop_c_dir = gtk_button_new_with_label ("Create Dir");
+      filesel->fileop_c_dir = gtk_button_new_with_label (_("Create Dir"));
       gtk_signal_connect (GTK_OBJECT (filesel->fileop_c_dir), "clicked",
                          (GtkSignalFunc) gtk_file_selection_create_dir, 
                          (gpointer) filesel);
@@ -535,7 +649,7 @@ gtk_file_selection_show_fileop_buttons (GtkFileSelection *filesel)
        
   if (!filesel->fileop_del_file) 
     {
-      filesel->fileop_del_file = gtk_button_new_with_label ("Delete File");
+      filesel->fileop_del_file = gtk_button_new_with_label (_("Delete File"));
       gtk_signal_connect (GTK_OBJECT (filesel->fileop_del_file), "clicked",
                          (GtkSignalFunc) gtk_file_selection_delete_file, 
                          (gpointer) filesel);
@@ -546,7 +660,7 @@ gtk_file_selection_show_fileop_buttons (GtkFileSelection *filesel)
 
   if (!filesel->fileop_ren_file)
     {
-      filesel->fileop_ren_file = gtk_button_new_with_label ("Rename File");
+      filesel->fileop_ren_file = gtk_button_new_with_label (_("Rename File"));
       gtk_signal_connect (GTK_OBJECT (filesel->fileop_ren_file), "clicked",
                          (GtkSignalFunc) gtk_file_selection_rename_file, 
                          (gpointer) filesel);
@@ -596,7 +710,7 @@ gtk_file_selection_set_filename (GtkFileSelection *filesel,
   g_return_if_fail (GTK_IS_FILE_SELECTION (filesel));
   g_return_if_fail (filename != NULL);
 
-  last_slash = strrchr (filename, '/');
+  last_slash = strrchr (filename, G_DIR_SEPARATOR);
 
   if (!last_slash)
     {
@@ -629,6 +743,9 @@ gtk_file_selection_get_filename (GtkFileSelection *filesel)
   g_return_val_if_fail (filesel != NULL, nothing);
   g_return_val_if_fail (GTK_IS_FILE_SELECTION (filesel), nothing);
 
+#ifdef __CYGWIN32__
+  translate_win32_path(filesel);
+#endif
   text = gtk_entry_get_text (GTK_ENTRY (filesel->selection_entry));
   if (text)
     {
@@ -707,7 +824,7 @@ gtk_file_selection_fileop_error (gchar *error_message)
                      (GtkSignalFunc) gtk_file_selection_fileop_destroy, 
                      (gpointer) fs);
   */
-  gtk_window_set_title (GTK_WINDOW (dialog), "Error");
+  gtk_window_set_title (GTK_WINDOW (dialog), _("Error"));
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
   
   vbox = gtk_vbox_new(FALSE, 0);
@@ -725,7 +842,7 @@ gtk_file_selection_fileop_error (gchar *error_message)
   g_free (error_message);
   
   /* close button */
-  button = gtk_button_new_with_label ("Close");
+  button = gtk_button_new_with_label (_("Close"));
   gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                             (GtkSignalFunc) gtk_widget_destroy, 
                             (gpointer) dialog);
@@ -767,7 +884,7 @@ gtk_file_selection_create_dir_confirmed (GtkWidget *widget, gpointer data)
   cmpl_state = (CompletionState*) fs->cmpl_state;
   path = cmpl_reference_position (cmpl_state);
   
-  full_path = g_strconcat (path, "/", dirname, NULL);
+  full_path = g_strconcat (path, G_DIR_SEPARATOR_S, dirname, NULL);
   if ( (mkdir (full_path, 0755) < 0) ) 
     {
       buf = g_strconcat ("Error creating directory \"", dirname, "\":  ", 
@@ -800,7 +917,7 @@ gtk_file_selection_create_dir (GtkWidget *widget, gpointer data)
   gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
                      (GtkSignalFunc) gtk_file_selection_fileop_destroy, 
                      (gpointer) fs);
-  gtk_window_set_title (GTK_WINDOW (dialog), "Create Directory");
+  gtk_window_set_title (GTK_WINDOW (dialog), _("Create Directory"));
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
 
   /* If file dialog is grabbed, grab option dialog */
@@ -814,7 +931,7 @@ gtk_file_selection_create_dir (GtkWidget *widget, gpointer data)
                     FALSE, FALSE, 0);
   gtk_widget_show(vbox);
   
-  label = gtk_label_new("Directory name:");
+  label = gtk_label_new(_("Directory name:"));
   gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
   gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5);
   gtk_widget_show(label);
@@ -827,7 +944,7 @@ gtk_file_selection_create_dir (GtkWidget *widget, gpointer data)
   gtk_widget_show (fs->fileop_entry);
   
   /* buttons */
-  button = gtk_button_new_with_label ("Create");
+  button = gtk_button_new_with_label (_("Create"));
   gtk_signal_connect (GTK_OBJECT (button), "clicked",
                      (GtkSignalFunc) gtk_file_selection_create_dir_confirmed, 
                      (gpointer) fs);
@@ -836,7 +953,7 @@ gtk_file_selection_create_dir (GtkWidget *widget, gpointer data)
   GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
   gtk_widget_show(button);
   
-  button = gtk_button_new_with_label ("Cancel");
+  button = gtk_button_new_with_label (_("Cancel"));
   gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                             (GtkSignalFunc) gtk_widget_destroy, 
                             (gpointer) dialog);
@@ -864,7 +981,7 @@ gtk_file_selection_delete_file_confirmed (GtkWidget *widget, gpointer data)
   cmpl_state = (CompletionState*) fs->cmpl_state;
   path = cmpl_reference_position (cmpl_state);
   
-  full_path = g_strconcat (path, "/", fs->fileop_file, NULL);
+  full_path = g_strconcat (path, G_DIR_SEPARATOR_S, fs->fileop_file, NULL);
   if ( (unlink (full_path) < 0) ) 
     {
       buf = g_strconcat ("Error deleting file \"", fs->fileop_file, "\":  ", 
@@ -894,6 +1011,10 @@ gtk_file_selection_delete_file (GtkWidget *widget, gpointer data)
   if (fs->fileop_dialog)
          return;
 
+#ifdef __CYGWIN32__
+  translate_win32_path(fs);
+#endif
+
   filename = gtk_entry_get_text (GTK_ENTRY (fs->selection_entry));
   if (strlen(filename) < 1)
          return;
@@ -905,7 +1026,7 @@ gtk_file_selection_delete_file (GtkWidget *widget, gpointer data)
   gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
                      (GtkSignalFunc) gtk_file_selection_fileop_destroy, 
                      (gpointer) fs);
-  gtk_window_set_title (GTK_WINDOW (dialog), "Delete File");
+  gtk_window_set_title (GTK_WINDOW (dialog), _("Delete File"));
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
 
   /* If file dialog is grabbed, grab option dialog */
@@ -927,7 +1048,7 @@ gtk_file_selection_delete_file (GtkWidget *widget, gpointer data)
   g_free(buf);
   
   /* buttons */
-  button = gtk_button_new_with_label ("Delete");
+  button = gtk_button_new_with_label (_("Delete"));
   gtk_signal_connect (GTK_OBJECT (button), "clicked",
                      (GtkSignalFunc) gtk_file_selection_delete_file_confirmed, 
                      (gpointer) fs);
@@ -936,7 +1057,7 @@ gtk_file_selection_delete_file (GtkWidget *widget, gpointer data)
   GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
   gtk_widget_show(button);
   
-  button = gtk_button_new_with_label ("Cancel");
+  button = gtk_button_new_with_label (_("Cancel"));
   gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                             (GtkSignalFunc) gtk_widget_destroy, 
                             (gpointer) dialog);
@@ -968,8 +1089,8 @@ gtk_file_selection_rename_file_confirmed (GtkWidget *widget, gpointer data)
   cmpl_state = (CompletionState*) fs->cmpl_state;
   path = cmpl_reference_position (cmpl_state);
   
-  new_filename = g_strconcat (path, "/", file, NULL);
-  old_filename = g_strconcat (path, "/", fs->fileop_file, NULL);
+  new_filename = g_strconcat (path, G_DIR_SEPARATOR_S, file, NULL);
+  old_filename = g_strconcat (path, G_DIR_SEPARATOR_S, fs->fileop_file, NULL);
 
   if ( (rename (old_filename, new_filename)) < 0) 
     {
@@ -1009,7 +1130,7 @@ gtk_file_selection_rename_file (GtkWidget *widget, gpointer data)
   gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
                      (GtkSignalFunc) gtk_file_selection_fileop_destroy, 
                      (gpointer) fs);
-  gtk_window_set_title (GTK_WINDOW (dialog), "Rename File");
+  gtk_window_set_title (GTK_WINDOW (dialog), _("Rename File"));
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
 
   /* If file dialog is grabbed, grab option dialog */
@@ -1042,7 +1163,7 @@ gtk_file_selection_rename_file (GtkWidget *widget, gpointer data)
                              0, strlen (fs->fileop_file));
 
   /* buttons */
-  button = gtk_button_new_with_label ("Rename");
+  button = gtk_button_new_with_label (_("Rename"));
   gtk_signal_connect (GTK_OBJECT (button), "clicked",
                      (GtkSignalFunc) gtk_file_selection_rename_file_confirmed, 
                      (gpointer) fs);
@@ -1051,7 +1172,7 @@ gtk_file_selection_rename_file (GtkWidget *widget, gpointer data)
   GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
   gtk_widget_show(button);
   
-  button = gtk_button_new_with_label ("Cancel");
+  button = gtk_button_new_with_label (_("Cancel"));
   gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                             (GtkSignalFunc) gtk_widget_destroy, 
                             (gpointer) dialog);
@@ -1079,6 +1200,9 @@ gtk_file_selection_key_press (GtkWidget   *widget,
   if (event->keyval == GDK_Tab)
     {
       fs = GTK_FILE_SELECTION (user_data);
+#ifdef __CYGWIN32__
+      translate_win32_path(fs);
+#endif
       text = gtk_entry_get_text (GTK_ENTRY (fs->selection_entry));
 
       text = g_strdup (text);
@@ -1162,11 +1286,15 @@ gtk_file_selection_update_history_menu (GtkFileSelection *fs,
     {
       /* the i == dir_len is to catch the full path for the first 
        * entry. */
-      if ( (current_dir[i] == '/') || (i == dir_len))
+      if ( (current_dir[i] == G_DIR_SEPARATOR) || (i == dir_len))
        {
          /* another small hack to catch the full path */
          if (i != dir_len) 
                  current_dir[i + 1] = '\0';
+#ifdef __CYGWIN32__
+         if (!strcmp(current_dir, "//"))
+           continue;
+#endif
          menu_item = gtk_menu_item_new_with_label (current_dir);
          
          callback_arg = g_new (HistoryCallbackArg, 1);
@@ -1215,6 +1343,18 @@ gtk_file_selection_file_button (GtkWidget *widget,
   gtk_clist_get_text (GTK_CLIST (fs->file_list), row, 0, &temp);
   filename = g_strdup (temp);
 
+#ifdef __CYGWIN32__
+  /* Check to see if the selection was a drive selector */
+  if (isalpha(filename[0]) && (filename[1] == ':')) {
+    /* It is... map it to a CYGWIN32 drive */
+    char temp_filename[10];
+
+    sprintf(temp_filename, "//%c/", tolower(filename[0]));
+    g_free(filename);
+    filename = g_strdup(temp_filename);
+  }
+#endif /* CYGWIN32 */
+
   if (filename)
     {
       if (bevent)
@@ -1274,6 +1414,51 @@ gtk_file_selection_dir_button (GtkWidget *widget,
     }
 }
 
+#ifdef WIN32
+
+static void
+win32_gtk_add_drives_to_dir_list(GtkWidget *the_dir_list)
+{
+  gchar *text[2], *textPtr;
+  gchar buffer[128];
+  char volumeNameBuf[128];
+  char formatBuffer[128];
+  gint row;
+
+  text[1] = NULL;
+
+  /* Get the Drives string */
+  GetLogicalDriveStrings(sizeof(buffer), buffer);
+
+  /* Add the drives as necessary */
+  textPtr = buffer;
+  while (*textPtr != '\0') {
+    /* Get the volume information for this drive */
+    if ((tolower(textPtr[0]) != 'a') && (tolower(textPtr[0]) != 'b'))
+      {
+       /* Ignore floppies (?) */
+       DWORD maxComponentLength, flags;
+
+       GetVolumeInformation(textPtr,
+                            volumeNameBuf, sizeof(volumeNameBuf),
+                            NULL, &maxComponentLength,
+                            &flags, NULL, 0);
+       /* Build the actual displayable string */
+
+       sprintf(formatBuffer, "%c:\\", toupper(textPtr[0]));
+#if 0 /* HB: removed to allow drive change AND directory update with one click */
+       if (strlen(volumeNameBuf) > 0)
+         sprintf(formatBuffer, "%s (%s)", formatBuffer, volumeNameBuf);
+#endif
+       /* Add to the list */
+       text[0] = formatBuffer;
+       row = gtk_clist_append (GTK_CLIST (the_dir_list), text);
+      }
+    textPtr += (strlen(textPtr) + 1);
+  }
+}
+#endif
+
 static void
 gtk_file_selection_populate (GtkFileSelection *fs,
                             gchar            *rel_path,
@@ -1314,14 +1499,14 @@ gtk_file_selection_populate (GtkFileSelection *fs,
 
   /* Set the dir_list to include ./ and ../ */
   text[1] = NULL;
-  text[0] = "./";
+  text[0] = "." G_DIR_SEPARATOR_S;
   row = gtk_clist_append (GTK_CLIST (fs->dir_list), text);
 
-  text[0] = "../";
+  text[0] = ".." G_DIR_SEPARATOR_S;
   row = gtk_clist_append (GTK_CLIST (fs->dir_list), text);
 
   /*reset the max widths of the lists*/
-  dir_list_width = gdk_string_width(fs->dir_list->style->font,"../");
+  dir_list_width = gdk_string_width(fs->dir_list->style->font,".." G_DIR_SEPARATOR_S);
   gtk_clist_set_column_width(GTK_CLIST(fs->dir_list),0,dir_list_width);
   file_list_width = 1;
   gtk_clist_set_column_width(GTK_CLIST(fs->file_list),0,file_list_width);
@@ -1338,8 +1523,8 @@ gtk_file_selection_populate (GtkFileSelection *fs,
          
           if (cmpl_is_directory (poss))
             {
-              if (strcmp (filename, "./") != 0 &&
-                  strcmp (filename, "../") != 0)
+              if (strcmp (filename, "." G_DIR_SEPARATOR_S) != 0 &&
+                  strcmp (filename, ".." G_DIR_SEPARATOR_S) != 0)
                {
                  int width = gdk_string_width(fs->dir_list->style->font,
                                               filename);
@@ -1369,6 +1554,11 @@ gtk_file_selection_populate (GtkFileSelection *fs,
       poss = cmpl_next_completion (cmpl_state);
     }
 
+#ifdef WIN32
+  /* For Windows, add drives as potential selections */
+  win32_gtk_add_drives_to_dir_list (fs->dir_list);
+#endif
+
   gtk_clist_thaw (GTK_CLIST (fs->dir_list));
   gtk_clist_thaw (GTK_CLIST (fs->file_list));
 
@@ -1425,12 +1615,11 @@ gtk_file_selection_populate (GtkFileSelection *fs,
 
       if (fs->selection_entry)
        {
-         sel_text = g_new (char, strlen (cmpl_reference_position (cmpl_state)) +
-                           sizeof ("Selection: "));
-         strcpy (sel_text, "Selection: ");
-         strcat (sel_text, cmpl_reference_position (cmpl_state));
+         sel_text = g_strconcat (_("Selection: "),
+                                 cmpl_reference_position (cmpl_state),
+                                 NULL);
 
-         gtk_label_set (GTK_LABEL (fs->selection_text), sel_text);
+         gtk_label_set_text (GTK_LABEL (fs->selection_text), sel_text);
          g_free (sel_text);
        }
 
@@ -1447,12 +1636,12 @@ gtk_file_selection_abort (GtkFileSelection *fs)
 {
   gchar err_buf[256];
 
-  sprintf (err_buf, "Directory unreadable: %s", cmpl_strerror (cmpl_errno));
+  sprintf (err_buf, _("Directory unreadable: %s"), cmpl_strerror (cmpl_errno));
 
   /*  BEEP gdk_beep();  */
 
   if (fs->selection_entry)
-    gtk_label_set (GTK_LABEL (fs->selection_text), err_buf);
+    gtk_label_set_text (GTK_LABEL (fs->selection_text), err_buf);
 }
 
 /**********************************************************************/
@@ -1494,10 +1683,11 @@ cmpl_completion_fullname (gchar* text, CompletionState* cmpl_state)
     {
       return nothing;
     }
-  else if (text[0] == '/')
+  else if (g_path_is_absolute (text))
     {
       strcpy (cmpl_state->updated_text, text);
     }
+#ifdef HAVE_PWD_H
   else if (text[0] == '~')
     {
       CompletionDir* dir;
@@ -1516,16 +1706,18 @@ cmpl_completion_fullname (gchar* text, CompletionState* cmpl_state)
 
          strcpy (cmpl_state->updated_text, dir->fullname);
 
-         slash = strchr (text, '/');
+         slash = strchr (text, G_DIR_SEPARATOR);
 
          if (slash)
            strcat (cmpl_state->updated_text, slash);
        }
     }
+#endif
   else
     {
       strcpy (cmpl_state->updated_text, cmpl_state->reference_dir->fullname);
-      strcat (cmpl_state->updated_text, "/");
+      if (cmpl_state->updated_text[strlen (cmpl_state->updated_text) - 1] != G_DIR_SEPARATOR)
+       strcat (cmpl_state->updated_text, G_DIR_SEPARATOR_S);
       strcat (cmpl_state->updated_text, text);
     }
 
@@ -1559,38 +1751,18 @@ cmpl_is_a_completion (PossibleCompletion* pc)
 static CompletionState*
 cmpl_init_state (void)
 {
-  gchar getcwd_buf[2*MAXPATHLEN];
+  gchar *getcwd_buf;
   CompletionState *new_state;
 
   new_state = g_new (CompletionState, 1);
 
-  /* We don't use getcwd() on SUNOS, because, it does a popen("pwd")
-   * and, if that wasn't bad enough, hangs in doing so.
-   */
-#if defined(sun) && !defined(__SVR4)
-  if (!getwd (getcwd_buf))
-#else    
-  if (!getcwd (getcwd_buf, MAXPATHLEN))
-#endif    
-    {
-      /* Oh joy, we can't get the current directory. Um..., we should have
-       * a root directory, right? Right? (Probably not portable to non-Unix)
-       */
-      strcpy (getcwd_buf, "/");
-    }
+  getcwd_buf = g_get_current_dir ();
 
 tryagain:
 
   new_state->reference_dir = NULL;
   new_state->completion_dir = NULL;
   new_state->active_completion_dir = NULL;
-
-  if ((new_state->user_home_dir = getenv("HOME")) != NULL)
-    {
-      /* if this fails, get_pwdb will fill it in. */
-      new_state->user_home_dir = g_strdup(new_state->user_home_dir);
-    }
-
   new_state->directory_storage = NULL;
   new_state->directory_sent_storage = NULL;
   new_state->last_valid_char = 0;
@@ -1606,10 +1778,11 @@ tryagain:
   if (!new_state->reference_dir)
     {
       /* Directories changing from underneath us, grumble */
-      strcpy (getcwd_buf, "/");
+      strcpy (getcwd_buf, G_DIR_SEPARATOR_S);
       goto tryagain;
     }
 
+  g_free (getcwd_buf);
   return new_state;
 }
 
@@ -1647,8 +1820,6 @@ cmpl_free_state (CompletionState* cmpl_state)
 
   if (cmpl_state->user_dir_name_buffer)
     g_free (cmpl_state->user_dir_name_buffer);
-  if (cmpl_state->user_home_dir)
-    g_free (cmpl_state->user_home_dir);
   if (cmpl_state->user_directories)
     g_free (cmpl_state->user_directories);
   if (cmpl_state->the_completion.text)
@@ -1726,7 +1897,8 @@ cmpl_completion_matches (gchar* text_to_complete,
   cmpl_state->updated_text[0] = 0;
   cmpl_state->re_complete = FALSE;
 
-  first_slash = strchr (text_to_complete, '/');
+#ifdef HAVE_PWD_H
+  first_slash = strchr (text_to_complete, G_DIR_SEPARATOR);
 
   if (text_to_complete[0] == '~' && !first_slash)
     {
@@ -1739,7 +1911,7 @@ cmpl_completion_matches (gchar* text_to_complete,
 
       return poss;
     }
-
+#endif
   cmpl_state->reference_dir =
     open_ref_dir (text_to_complete, remaining_text, cmpl_state);
 
@@ -1776,10 +1948,14 @@ cmpl_next_completion (CompletionState* cmpl_state)
 
   cmpl_state->the_completion.text[0] = 0;
 
+#ifdef HAVE_PWD_H
   if(cmpl_state->user_completion_index >= 0)
     poss = attempt_homedir_completion(cmpl_state->last_completion_text, cmpl_state);
   else
     poss = attempt_file_completion(cmpl_state);
+#else
+  poss = attempt_file_completion(cmpl_state);
+#endif
 
   update_cmpl(poss, cmpl_state);
 
@@ -1799,15 +1975,39 @@ open_ref_dir(gchar* text_to_complete,
   gchar* first_slash;
   CompletionDir *new_dir;
 
-  first_slash = strchr(text_to_complete, '/');
+  first_slash = strchr(text_to_complete, G_DIR_SEPARATOR);
 
-  if (text_to_complete[0] == '/' || !cmpl_state->reference_dir)
+#ifdef __CYGWIN32__
+  if (text_to_complete[0] == '/' && text_to_complete[1] == '/')
     {
-      new_dir = open_dir("/", cmpl_state);
+      char root_dir[5];
+      sprintf(root_dir, "//%c", text_to_complete[2]);
 
-      if(new_dir)
-       *remaining_text = text_to_complete + 1;
+      new_dir = open_dir(root_dir, cmpl_state);
+
+      if (new_dir) {
+       *remaining_text = text_to_complete + 4;
+      }
+    }
+#else
+  if (FALSE)
+    ;
+#endif
+  else if (g_path_is_absolute (text_to_complete) || !cmpl_state->reference_dir)
+    {
+      char *root;
+      int rootlen;
+
+      rootlen = g_path_skip_root (text_to_complete) - text_to_complete;
+      root = g_malloc (rootlen + 1);
+      memcpy (root, text_to_complete, rootlen);
+      root[rootlen] = '\0';
+      new_dir = open_dir (root, cmpl_state);
+      if (new_dir)
+       *remaining_text = g_path_skip_root (text_to_complete);
+      g_free (root);
     }
+#ifdef HAVE_PWD_H
   else if (text_to_complete[0] == '~')
     {
       new_dir = open_user_dir(text_to_complete, cmpl_state);
@@ -1824,6 +2024,7 @@ open_ref_dir(gchar* text_to_complete,
          return NULL;
        }
     }
+#endif
   else
     {
       *remaining_text = text_to_complete;
@@ -1840,6 +2041,8 @@ open_ref_dir(gchar* text_to_complete,
   return new_dir;
 }
 
+#ifdef HAVE_PWD_H
+
 /* open a directory by user name */
 static CompletionDir*
 open_user_dir(gchar* text_to_complete,
@@ -1850,7 +2053,7 @@ open_user_dir(gchar* text_to_complete,
 
   g_assert(text_to_complete && text_to_complete[0] == '~');
 
-  first_slash = strchr(text_to_complete, '/');
+  first_slash = strchr(text_to_complete, G_DIR_SEPARATOR);
 
   if (first_slash)
     cmp_len = first_slash - text_to_complete - 1;
@@ -1860,10 +2063,12 @@ open_user_dir(gchar* text_to_complete,
   if(!cmp_len)
     {
       /* ~/ */
-      if (!cmpl_state->user_home_dir &&
-         !get_pwdb(cmpl_state))
+      gchar *homedir = g_get_home_dir ();
+
+      if (homedir)
+       return open_dir(homedir, cmpl_state);
+      else
        return NULL;
-      return open_dir(cmpl_state->user_home_dir, cmpl_state);
     }
   else
     {
@@ -1884,6 +2089,8 @@ open_user_dir(gchar* text_to_complete,
     }
 }
 
+#endif
+
 /* open a directory relative the the current relative directory */
 static CompletionDir*
 open_relative_dir(gchar* dir_name,
@@ -1902,8 +2109,13 @@ open_relative_dir(gchar* dir_name,
 
   if(dir->fullname_len > 1)
     {
-      path_buf[dir->fullname_len] = '/';
-      strcpy(path_buf + dir->fullname_len + 1, dir_name);
+      if (path_buf[dir->fullname_len - 1] != G_DIR_SEPARATOR)
+       {
+         path_buf[dir->fullname_len] = G_DIR_SEPARATOR;
+         strcpy (path_buf + dir->fullname_len + 1, dir_name);
+       }
+      else
+       strcpy (path_buf + dir->fullname_len, dir_name);
     }
   else
     {
@@ -1990,8 +2202,13 @@ open_new_dir(gchar* dir_name, struct stat* sbuf, gboolean stat_subdirs)
       *buffer_ptr = 0;
       buffer_ptr += 1;
 
-      path_buf[path_buf_len] = '/';
-      strcpy(path_buf + path_buf_len + 1, dirent_ptr->d_name);
+      if (path_buf[path_buf_len-1] != G_DIR_SEPARATOR)
+       {
+         path_buf[path_buf_len] = G_DIR_SEPARATOR;
+         strcpy(path_buf + path_buf_len + 1, dirent_ptr->d_name);
+       }
+      else
+       strcpy(path_buf + path_buf_len, dirent_ptr->d_name);
 
       if (stat_subdirs)
        {
@@ -2013,6 +2230,8 @@ open_new_dir(gchar* dir_name, struct stat* sbuf, gboolean stat_subdirs)
   return sent;
 }
 
+#ifndef WIN32
+
 static gboolean
 check_dir(gchar *dir_name, struct stat *result, gboolean *stat_subdirs)
 {
@@ -2066,6 +2285,8 @@ check_dir(gchar *dir_name, struct stat *result, gboolean *stat_subdirs)
   return TRUE;
 }
 
+#endif
+
 /* open a directory by absolute pathname */
 static CompletionDir*
 open_dir(gchar* dir_name, CompletionState* cmpl_state)
@@ -2075,6 +2296,7 @@ open_dir(gchar* dir_name, CompletionState* cmpl_state)
   CompletionDirSent *sent;
   GList* cdsl;
 
+#ifndef WIN32
   if (!check_dir (dir_name, &sbuf, &stat_subdirs))
     return NULL;
 
@@ -2091,6 +2313,9 @@ open_dir(gchar* dir_name, CompletionState* cmpl_state)
 
       cdsl = cdsl->next;
     }
+#else
+  stat_subdirs = TRUE;
+#endif
 
   sent = open_new_dir(dir_name, &sbuf, stat_subdirs);
 
@@ -2125,27 +2350,42 @@ static gint
 correct_dir_fullname(CompletionDir* cmpl_dir)
 {
   gint length = strlen(cmpl_dir->fullname);
+  gchar *first_slash = strchr(cmpl_dir->fullname, G_DIR_SEPARATOR);
   struct stat sbuf;
 
-  if (strcmp(cmpl_dir->fullname + length - 2, "/.") == 0)
+  /* Does it end with /. (\.) ? */
+  if (length >= 2 &&
+      strcmp(cmpl_dir->fullname + length - 2, G_DIR_SEPARATOR_S ".") == 0)
     {
-      if (length == 2) 
+      /* Is it just the root directory (on a drive) ? */
+      if (cmpl_dir->fullname + length - 2 == first_slash)
        {
-         strcpy(cmpl_dir->fullname, "/");
-         cmpl_dir->fullname_len = 1;
+         cmpl_dir->fullname[length - 1] = 0;
+         cmpl_dir->fullname_len = length - 1;
          return TRUE;
-       } else {
+       }
+      else
+       {
          cmpl_dir->fullname[length - 2] = 0;
        }
     }
-  else if (strcmp(cmpl_dir->fullname + length - 3, "/./") == 0)
+
+  /* Ends with /./ (\.\)? */
+  else if (length >= 3 &&
+          strcmp(cmpl_dir->fullname + length - 3,
+                 G_DIR_SEPARATOR_S "." G_DIR_SEPARATOR_S) == 0)
     cmpl_dir->fullname[length - 2] = 0;
-  else if (strcmp(cmpl_dir->fullname + length - 3, "/..") == 0)
+
+  /* Ends with /.. (\..) ? */
+  else if (length >= 3 &&
+          strcmp(cmpl_dir->fullname + length - 3,
+                 G_DIR_SEPARATOR_S "..") == 0)
     {
-      if(length == 3)
+      /* Is it just /.. (X:\..)? */
+      if(cmpl_dir->fullname + length - 3 == first_slash)
        {
-         strcpy(cmpl_dir->fullname, "/");
-         cmpl_dir->fullname_len = 1;
+         cmpl_dir->fullname[length - 2] = 0;
+         cmpl_dir->fullname_len = length - 2;
          return TRUE;
        }
 
@@ -2155,17 +2395,22 @@ correct_dir_fullname(CompletionDir* cmpl_dir)
          return FALSE;
        }
 
-      cmpl_dir->fullname[length - 2] = 0;
+      cmpl_dir->fullname[length - 3] = 0;
 
       if(!correct_parent(cmpl_dir, &sbuf))
        return FALSE;
     }
-  else if (strcmp(cmpl_dir->fullname + length - 4, "/../") == 0)
+
+  /* Ends with /../ (\..\)? */
+  else if (length >= 4 &&
+          strcmp(cmpl_dir->fullname + length - 4,
+                 G_DIR_SEPARATOR_S ".." G_DIR_SEPARATOR_S) == 0)
     {
-      if(length == 4)
+      /* Is it just /../ (X:\..\)? */
+      if(cmpl_dir->fullname + length - 4 == first_slash)
        {
-         strcpy(cmpl_dir->fullname, "/");
-         cmpl_dir->fullname_len = 1;
+         cmpl_dir->fullname[length - 3] = 0;
+         cmpl_dir->fullname_len = length - 3;
          return TRUE;
        }
 
@@ -2175,7 +2420,7 @@ correct_dir_fullname(CompletionDir* cmpl_dir)
          return FALSE;
        }
 
-      cmpl_dir->fullname[length - 3] = 0;
+      cmpl_dir->fullname[length - 4] = 0;
 
       if(!correct_parent(cmpl_dir, &sbuf))
        return FALSE;
@@ -2191,15 +2436,21 @@ correct_parent(CompletionDir* cmpl_dir, struct stat *sbuf)
 {
   struct stat parbuf;
   gchar *last_slash;
+  gchar *first_slash;
   gchar *new_name;
   gchar c = 0;
 
-  last_slash = strrchr(cmpl_dir->fullname, '/');
-
+  last_slash = strrchr(cmpl_dir->fullname, G_DIR_SEPARATOR);
   g_assert(last_slash);
+  first_slash = strchr(cmpl_dir->fullname, G_DIR_SEPARATOR);
 
-  if(last_slash != cmpl_dir->fullname)
-    { /* last_slash[0] = 0; */ }
+  /* Clever (?) way to check for top-level directory that works also on
+   * Win32, where there is a drive letter and colon prefixed...
+   */
+  if (last_slash != first_slash)
+    {
+      last_slash[0] = 0;
+    }
   else
     {
       c = last_slash[1];
@@ -2209,17 +2460,20 @@ correct_parent(CompletionDir* cmpl_dir, struct stat *sbuf)
   if (stat(cmpl_dir->fullname, &parbuf) < 0)
     {
       cmpl_errno = errno;
+      if (!c)
+       last_slash[0] = G_DIR_SEPARATOR;
       return FALSE;
     }
 
+#ifndef NATIVE_WIN32           /* No inode numbers on Win32 */
   if (parbuf.st_ino == sbuf->st_ino && parbuf.st_dev == sbuf->st_dev)
     /* it wasn't a link */
     return TRUE;
 
   if(c)
     last_slash[1] = c;
-  /* else
-    last_slash[0] = '/'; */
+  else
+    last_slash[0] = G_DIR_SEPARATOR;
 
   /* it was a link, have to figure it out the hard way */
 
@@ -2231,25 +2485,20 @@ correct_parent(CompletionDir* cmpl_dir, struct stat *sbuf)
   g_free(cmpl_dir->fullname);
 
   cmpl_dir->fullname = new_name;
+#endif
 
   return TRUE;
 }
 
+#ifndef NATIVE_WIN32
+
 static gchar*
 find_parent_dir_fullname(gchar* dirname)
 {
-  gchar buffer[MAXPATHLEN];
-  gchar buffer2[MAXPATHLEN];
+  gchar *orig_dir;
+  gchar *result;
 
-#if defined(sun) && !defined(__SVR4)
-  if(!getwd(buffer))
-#else
-  if(!getcwd(buffer, MAXPATHLEN))
-#endif    
-    {
-      cmpl_errno = errno;
-      return NULL;
-    }
+  orig_dir = g_get_current_dir ();
 
   if(chdir(dirname) != 0 || chdir("..") != 0)
     {
@@ -2257,31 +2506,26 @@ find_parent_dir_fullname(gchar* dirname)
       return NULL;
     }
 
-#if defined(sun) && !defined(__SVR4)
-  if(!getwd(buffer2))
-#else
-  if(!getcwd(buffer2, MAXPATHLEN))
-#endif
-    {
-      chdir(buffer);
-      cmpl_errno = errno;
+  result = g_get_current_dir ();
 
-      return NULL;
-    }
-
-  if(chdir(buffer) != 0)
+  if(chdir(orig_dir) != 0)
     {
       cmpl_errno = errno;
       return NULL;
     }
 
-  return g_strdup(buffer2);
+  g_free (orig_dir);
+  return result;
 }
 
+#endif
+
 /**********************************************************************/
 /*                        Completion Operations                       */
 /**********************************************************************/
 
+#ifdef HAVE_PWD_H
+
 static PossibleCompletion*
 attempt_homedir_completion(gchar* text_to_complete,
                           CompletionState *cmpl_state)
@@ -2321,7 +2565,7 @@ attempt_homedir_completion(gchar* text_to_complete,
                              user_directories[cmpl_state->user_completion_index].login,
                             cmpl_state);
 
-      return append_completion_text("/", cmpl_state);
+      return append_completion_text(G_DIR_SEPARATOR_S, cmpl_state);
     }
 
   if(text_to_complete[1] ||
@@ -2336,10 +2580,18 @@ attempt_homedir_completion(gchar* text_to_complete,
       cmpl_state->the_completion.is_a_completion = 1;
       cmpl_state->the_completion.is_directory = 1;
 
-      return append_completion_text("~/", cmpl_state);
+      return append_completion_text("~" G_DIR_SEPARATOR_S, cmpl_state);
     }
 }
 
+#endif
+
+#ifdef WIN32
+#define FOLD(c) (tolower(c))
+#else
+#define FOLD(c) (c)
+#endif
+
 /* returns the index (>= 0) of the first differing character,
  * PATTERN_MATCH if the completion matches */
 static gint
@@ -2347,7 +2599,7 @@ first_diff_index(gchar* pat, gchar* text)
 {
   gint diff = 0;
 
-  while(*pat && *text && *text == *pat)
+  while(*pat && *text && FOLD(*text) == FOLD(*pat))
     {
       pat += 1;
       text += 1;
@@ -2396,7 +2648,7 @@ find_completion_dir(gchar* text_to_complete,
                    gchar** remaining_text,
                    CompletionState* cmpl_state)
 {
-  gchar* first_slash = strchr(text_to_complete, '/');
+  gchar* first_slash = strchr(text_to_complete, G_DIR_SEPARATOR);
   CompletionDir* dir = cmpl_state->reference_dir;
   CompletionDir* next;
   *remaining_text = text_to_complete;
@@ -2456,7 +2708,7 @@ find_completion_dir(gchar* text_to_complete,
        }
       
       *remaining_text = first_slash + 1;
-      first_slash = strchr(*remaining_text, '/');
+      first_slash = strchr(*remaining_text, G_DIR_SEPARATOR);
 
       g_free (pat_buf);
     }
@@ -2537,7 +2789,7 @@ attempt_file_completion(CompletionState *cmpl_state)
 
   g_assert(dir->cmpl_text);
 
-  first_slash = strchr(dir->cmpl_text, '/');
+  first_slash = strchr(dir->cmpl_text, G_DIR_SEPARATOR);
 
   if(first_slash)
     {
@@ -2553,7 +2805,12 @@ attempt_file_completion(CompletionState *cmpl_state)
 
       pat_buf = g_new (gchar, len + 2);
       strcpy(pat_buf, dir->cmpl_text);
-      strcpy(pat_buf + len, "*");
+      /* Don't append a * if the user entered one herself.
+       * This way one can complete *.h and don't get matches
+       * on any .help files, for instance.
+       */
+      if (strchr(pat_buf, '*') == NULL)
+       strcpy(pat_buf + len, "*");
     }
 
   if(first_slash)
@@ -2603,7 +2860,7 @@ attempt_file_completion(CompletionState *cmpl_state)
          append_completion_text(dir->fullname +
                                 strlen(cmpl_state->completion_dir->fullname) + 1,
                                 cmpl_state);
-         append_completion_text("/", cmpl_state);
+         append_completion_text(G_DIR_SEPARATOR_S, cmpl_state);
        }
 
       append_completion_text(dir->sent->entries[dir->cmpl_index].entry_name, cmpl_state);
@@ -2614,13 +2871,14 @@ attempt_file_completion(CompletionState *cmpl_state)
 
       cmpl_state->the_completion.is_directory = dir->sent->entries[dir->cmpl_index].is_dir;
       if(dir->sent->entries[dir->cmpl_index].is_dir)
-       append_completion_text("/", cmpl_state);
+       append_completion_text(G_DIR_SEPARATOR_S, cmpl_state);
 
       g_free (pat_buf);
       return &cmpl_state->the_completion;
     }
 }
 
+#ifdef HAVE_PWD_H
 
 static gint
 get_pwdb(CompletionState* cmpl_state)
@@ -2641,21 +2899,6 @@ get_pwdb(CompletionState* cmpl_state)
       count += 1;
     }
 
-  if (!cmpl_state->user_home_dir)
-    {
-      /* the loser doesn't have $HOME set */
-      setpwent ();
-
-      pwd_ptr = getpwuid(getuid());
-      if(!pwd_ptr)
-       {
-         cmpl_errno = errno;
-         goto error;
-       }
-      /* Allocate this separately, since it might be filled in elsewhere */
-      cmpl_state->user_home_dir = g_strdup (pwd_ptr->pw_dir);
-    }
-
   setpwent ();
 
   cmpl_state->user_dir_name_buffer = g_new(gchar, len);
@@ -2712,11 +2955,18 @@ compare_user_dir(const void* a, const void* b)
                (((CompletionUserDir*)b))->login);
 }
 
+#endif
+
 static gint
 compare_cmpl_dir(const void* a, const void* b)
 {
+#ifndef WIN32
   return strcmp((((CompletionDirEntry*)a))->entry_name,
                (((CompletionDirEntry*)b))->entry_name);
+#else
+  return g_strcasecmp((((CompletionDirEntry*)a))->entry_name,
+                     (((CompletionDirEntry*)b))->entry_name);
+#endif
 }
 
 static gint