[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[gftp] Re: A native encoding patch for gftp 2.0.14



I already have this working in my latest test code. Please check out the
latest CVS (http://developer.gnome.org/tools/cvs.html) or download
http://www.gftp.org/gftp-test.tar.bz2. If the filename is not in UTF-8, it
will try to convert it from the current locale and if that fails, it will then
try to convert it from the locales that are specified in the remote_charsets
option.

Brian



On Wed, Jul 16, 2003 at 08:03:01AM +0800, Ling Li wrote:
> Hi all.
> 
> I have write a patch for gFTP 2.0.14, which make gFTP process filenames
> in native encoding correctly, and I have tested it on my system with
> LC_CTYPE set to zh_CN.GBK.
> 
> Ling Li 2003.07.16

> 
> *** /home/liling/src/gftp/gftp-2.0.14/lib/gftp.h	Wed Dec  4 10:35:44 2002
> --- /home/liling/src/gftp/gftp-2.0.14.patched/lib/gftp.h	Tue Jul 15 21:15:01 2003
> ***************
> *** 844,848 ****
> --- 844,853 ----
>   void gftp_swap_socks 			( gftp_request * dest, 
>   					  gftp_request * source );
>   
> + #if GLIB_MAJOR_VERSION > 1
> + char* gftp_locale_to_utf8               ( const char *from );
> + char* gftp_locale_from_utf8             ( const char *from );
> + #endif
> + 
>   #endif
>   
> 
> *** /home/liling/src/gftp/gftp-2.0.14/lib/protocols.c	Thu Dec  5 08:43:06 2002
> --- /home/liling/src/gftp/gftp-2.0.14.patched/lib/protocols.c	Wed Jul 16 00:52:02 2003
> ***************
> *** 152,163 ****
>   gftp_get_file (gftp_request * request, const char *filename, int fd,
>                  size_t startsize)
>   {
>     g_return_val_if_fail (request != NULL, -2);
>   
>     request->cached = 0;
>     if (request->get_file == NULL)
>       return (-2);
> !   return (request->get_file (request, filename, fd, startsize));
>   }
>   
>   
> --- 152,176 ----
>   gftp_get_file (gftp_request * request, const char *filename, int fd,
>                  size_t startsize)
>   {
> +   int ret;
> + #if GLIB_MAJOR_VERSION > 1
> +   char *tempstr;
> + #endif
> + 
>     g_return_val_if_fail (request != NULL, -2);
>   
>     request->cached = 0;
>     if (request->get_file == NULL)
>       return (-2);
> ! #if GLIB_MAJOR_VERSION > 1
> !   tempstr = gftp_locale_from_utf8(filename);
> !   ret = request->get_file (request, tempstr, fd, startsize);
> !   g_free(tempstr);
> ! #else
> !   ret = request->get_file (request, filename, fd, startsize);
> ! #endif
> ! 
> !   return (ret);
>   }
>   
>   
> ***************
> *** 165,176 ****
>   gftp_put_file (gftp_request * request, const char *filename, int fd,
>                  size_t startsize, size_t totalsize)
>   {
>     g_return_val_if_fail (request != NULL, -2);
>   
>     request->cached = 0;
>     if (request->put_file == NULL)
>       return (-2);
> !   return (request->put_file (request, filename, fd, startsize, totalsize));
>   }
>   
>   
> --- 178,202 ----
>   gftp_put_file (gftp_request * request, const char *filename, int fd,
>                  size_t startsize, size_t totalsize)
>   {
> +   int ret;
> + #if GLIB_MAJOR_VERSION > 1
> +   char *tempstr;
> + #endif
> + 
>     g_return_val_if_fail (request != NULL, -2);
>   
>     request->cached = 0;
>     if (request->put_file == NULL)
>       return (-2);
> ! #if GLIB_MAJOR_VERSION > 1
> !   tempstr = gftp_locale_from_utf8(filename);
> !   ret = request->put_file (request, tempstr, fd, startsize, totalsize);
> !   g_free(tempstr);
> ! #else
> !   ret = request->put_file (request, filename, fd, startsize, totalsize);
> ! #endif
> ! 
> !   return (ret);
>   }
>   
>   
> ***************
> *** 181,186 ****
> --- 207,218 ----
>                       int tofd, size_t tosize)
>   {
>     long size;
> +   long ret;
> + #if GLIB_MAJOR_VERSION > 1
> +   char *lfromfile, *ltofile;
> +   gsize bread, bwrite;
> +   GError * error;
> + #endif
>   
>     g_return_val_if_fail (fromreq != NULL, -2);
>     g_return_val_if_fail (fromfile != NULL, -2);
> ***************
> *** 191,210 ****
>       {
>         if (fromreq->transfer_file == NULL)
>   	return (-2);
> !       return (fromreq->transfer_file (fromreq, fromfile, fromsize, toreq, 
> !                                       tofile, tosize));
>       }
>   
>     fromreq->cached = 0;
>     toreq->cached = 0;
> !   if ((size = gftp_get_file (fromreq, fromfile, fromfd, tosize)) < 0)
>       return (-2);
> - 
>     if (gftp_put_file (toreq, tofile, tofd, tosize, size) != 0)
>       {
>         if (gftp_abort_transfer (fromreq) != 0)
>           gftp_end_transfer (fromreq);
> - 
>         return (-2);
>       }
>   
> --- 223,251 ----
>       {
>         if (fromreq->transfer_file == NULL)
>   	return (-2);
> ! #if GLIB_MAJOR_VERSION > 1
> !       lfromfile = gftp_locale_from_utf8 (fromfile);
> !       ltofile = gftp_locale_from_utf8 (tofile);
> !       ret = fromreq->transfer_file (fromreq, lfromfile, fromsize, toreq, 
> !                                     ltofile, tosize);
> !       g_free(lfromfile);
> !       g_free(ltofile);
> ! #else
> !       ret = fromreq->transfer_file (fromreq, fromfile, fromsize, toreq, 
> !                                     tofile, tosize);
> ! #endif
> !       return (ret);
>       }
>   
>     fromreq->cached = 0;
>     toreq->cached = 0;
> !   size = gftp_get_file (fromreq, fromfile, fromfd, tosize);
> !   if (size < 0)
>       return (-2);
>     if (gftp_put_file (toreq, tofile, tofd, tosize, size) != 0)
>       {
>         if (gftp_abort_transfer (fromreq) != 0)
>           gftp_end_transfer (fromreq);
>         return (-2);
>       }
>   
> ***************
> *** 286,295 ****
>   int
>   gftp_list_files (gftp_request * request)
>   {
> !   int fd;
>   
>     g_return_val_if_fail (request != NULL, -2);
>   
>     request->cached = 0;
>     if (request->use_cache && (fd = gftp_find_cache_entry (request)) > 0)
>       {
> --- 327,343 ----
>   int
>   gftp_list_files (gftp_request * request)
>   {
> !   int fd, ret;
> ! #if GLIB_MAJOR_VERSION > 1
> !     char *tempstr;
> ! #endif
>   
>     g_return_val_if_fail (request != NULL, -2);
>   
> + #if GLIB_MAJOR_VERSION > 1
> +   tempstr = request->directory;
> +   request->directory = gftp_locale_from_utf8(request->directory);
> + #endif
>     request->cached = 0;
>     if (request->use_cache && (fd = gftp_find_cache_entry (request)) > 0)
>       {
> ***************
> *** 299,304 ****
> --- 347,356 ----
>   
>         request->cachefd = fd;
>         request->cached = 1;
> + #if GLIB_MAJOR_VERSION > 1
> +       g_free(request->directory);
> +       request->directory = tempstr;
> + #endif
>         return (0);
>       }
>     else if (request->use_cache)
> ***************
> *** 308,315 ****
>       }
>   
>     if (request->list_files == NULL)
> !     return (-2);
> !   return (request->list_files (request));
>   }
>   
>   
> --- 360,375 ----
>       }
>   
>     if (request->list_files == NULL)
> !     ret = -2;
> !   else
> !     ret = request->list_files (request);
> ! 
> ! #if GLIB_MAJOR_VERSION > 1
> !   g_free(request->directory);
> !   request->directory = tempstr;
> ! #endif
> ! 
> !   return (ret);
>   }
>   
>   
> ***************
> *** 340,358 ****
>         ret = request->get_next_file (request, fle, fd);
>   
>   #if GLIB_MAJOR_VERSION > 1
> !       if (fle->file != NULL && !g_utf8_validate (fle->file, -1, NULL))
> !         {
> !           error = NULL;
> !           if ((tempstr = g_locale_to_utf8 (fle->file, -1, &bread, 
> !                                            &bwrite, &error)) != NULL)
> !             {
> !               g_free (fle->file);
> !               fle->file = tempstr;
> !             }
> !           else
> !             g_warning ("Error when converting %s to UTF-8: %s\n", fle->file,
> !                        error->message);
> !         }
>   #endif
>   
>         if (ret >= 0 && !request->cached && request->cachefd > 0 && 
> --- 400,410 ----
>         ret = request->get_next_file (request, fle, fd);
>   
>   #if GLIB_MAJOR_VERSION > 1
> !       if (fle->file != NULL) {
> !         tempstr = gftp_locale_to_utf8(fle->file);
> !         g_free (fle->file);
> !         fle->file = tempstr;
> !       }
>   #endif
>   
>         if (ret >= 0 && !request->cached && request->cachefd > 0 && 
> ***************
> *** 556,565 ****
>   int
>   gftp_set_directory (gftp_request * request, const char *directory)
>   {
>     g_return_val_if_fail (request != NULL, -2);
>     g_return_val_if_fail (directory != NULL, -2);
>   
> - 
>     if (request->sockfd <= 0 && !request->always_connected)
>       {
>         if (directory != request->directory)
> --- 608,621 ----
>   int
>   gftp_set_directory (gftp_request * request, const char *directory)
>   {
> +   int ret;
> + #if GLIB_MAJOR_VERSION > 1
> +   char *tempstr;
> + #endif
> + 
>     g_return_val_if_fail (request != NULL, -2);
>     g_return_val_if_fail (directory != NULL, -2);
>   
>     if (request->sockfd <= 0 && !request->always_connected)
>       {
>         if (directory != request->directory)
> ***************
> *** 569,579 ****
>   	  request->directory = g_malloc (strlen (directory) + 1);
>   	  strcpy (request->directory, directory);
>   	}
> !       return (0);
>       }
>     else if (request->chdir == NULL)
> !     return (-2);
> !   return (request->chdir (request, directory));
>   }
>   
>   
> --- 625,650 ----
>   	  request->directory = g_malloc (strlen (directory) + 1);
>   	  strcpy (request->directory, directory);
>   	}
> !       ret = 0;
>       }
>     else if (request->chdir == NULL)
> !     ret = -2;
> !   else
> !     {
> ! #if GLIB_MAJOR_VERSION > 1
> !       tempstr = gftp_locale_from_utf8 (directory);
> !       g_free (request->directory);
> !       request->directory = tempstr;
> !       ret = request->chdir (request, request->directory);
> !       tempstr = gftp_locale_to_utf8 (request->directory);
> !       g_free (request->directory);
> !       request->directory = tempstr;
> ! #else
> !       ret = request->chdir (request, directory);
> ! #endif
> !     }
> !   
> !   return (ret);
>   }
>   
>   
> ***************
> *** 650,682 ****
>   int
>   gftp_remove_directory (gftp_request * request, const char *directory)
>   {
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->rmdir == NULL)
>       return (-2);
> !   return (request->rmdir (request, directory));
>   }
>   
>   
>   int
>   gftp_remove_file (gftp_request * request, const char *file)
>   {
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->rmfile == NULL)
>       return (-2);
> !   return (request->rmfile (request, file));
>   }
>   
>   
>   int
>   gftp_make_directory (gftp_request * request, const char *directory)
>   {
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->mkdir == NULL)
>       return (-2);
> !   return (request->mkdir (request, directory));
>   }
>   
>   
> --- 721,795 ----
>   int
>   gftp_remove_directory (gftp_request * request, const char *directory)
>   {
> +   int ret;
> + #if GLIB_MAJOR_VERSION > 1
> +   char* tempstr;
> + #endif
> + 
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->rmdir == NULL)
>       return (-2);
> ! 
> ! #if GLIB_MAJOR_VERSION > 1
> !   tempstr = gftp_locale_from_utf8(directory);
> !   ret = request->rmdir (request, tempstr);
> !   g_free(tempstr);
> ! #else
> !   ret = request->rmdir (request, directory);
> ! #endif
> ! 
> !   return (ret);
>   }
>   
>   
>   int
>   gftp_remove_file (gftp_request * request, const char *file)
>   {
> +   int ret;
> + #if GLIB_MAJOR_VERSION > 1
> +   char* tempstr;
> + #endif
> + 
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->rmfile == NULL)
>       return (-2);
> ! 
> ! #if GLIB_MAJOR_VERSION > 1
> !   tempstr = gftp_locale_from_utf8(file);
> !   ret = request->rmfile (request, tempstr);
> !   g_free(tempstr);
> ! #else
> !   ret = request->rmfile (request, file);
> ! #endif
> ! 
> !   return (ret);
>   }
>   
>   
>   int
>   gftp_make_directory (gftp_request * request, const char *directory)
>   {
> +   int ret;
> + #if GLIB_MAJOR_VERSION > 1
> +   char* tempstr;
> + #endif
> + 
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->mkdir == NULL)
>       return (-2);
> ! 
> ! #if GLIB_MAJOR_VERSION > 1
> !   tempstr = gftp_locale_from_utf8(directory);
> !   ret = request->mkdir (request, tempstr);
> !   g_free(tempstr);
> ! #else
> !   ret = request->mkdir (request, directory);
> ! #endif
> ! 
> !   return (ret);
>   }
>   
>   
> ***************
> *** 684,716 ****
>   gftp_rename_file (gftp_request * request, const char *oldname,
>   		  const char *newname)
>   {
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->rename == NULL)
>       return (-2);
> !   return (request->rename (request, oldname, newname));
>   }
>   
>   
>   int
>   gftp_chmod (gftp_request * request, const char *file, int mode)
>   {
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->chmod == NULL)
>       return (-2);
> !   return (request->chmod (request, file, mode));
>   }
>   
>   
>   int
>   gftp_set_file_time (gftp_request * request, const char *file, time_t datetime)
>   {
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->set_file_time == NULL)
>       return (-2);
> !   return (request->set_file_time (request, file, datetime));
>   }
>   
>   
> --- 797,872 ----
>   gftp_rename_file (gftp_request * request, const char *oldname,
>   		  const char *newname)
>   {
> +   int ret;
> + #if GLIB_MAJOR_VERSION > 1
> +   char *tempstr, *tempstr1;
> + #endif
> + 
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->rename == NULL)
>       return (-2);
> ! 
> ! #if GLIB_MAJOR_VERSION > 1
> !   tempstr = gftp_locale_from_utf8(oldname);
> !   tempstr1 = gftp_locale_from_utf8(newname);
> !   ret = request->rename (request, tempstr, tempstr1);
> !   g_free(tempstr);
> !   g_free(tempstr1);
> ! #else
> !   ret = request->rename (request, oldname, newname);
> ! #endif
> ! 
> !   return (ret);
>   }
>   
>   
>   int
>   gftp_chmod (gftp_request * request, const char *file, int mode)
>   {
> +   int ret;
> + #if GLIB_MAJOR_VERSION > 1
> +   char *tempstr;
> + #endif
> + 
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->chmod == NULL)
>       return (-2);
> ! 
> ! #if GLIB_MAJOR_VERSION > 1
> !   tempstr = gftp_locale_from_utf8(file);
> !   ret = request->chmod (request, tempstr, mode);
> !   g_free(tempstr);
> ! #else
> !   ret = request->chmod (request, file, mode);
> ! #endif
> !   
> !   return (ret);
>   }
>   
>   
>   int
>   gftp_set_file_time (gftp_request * request, const char *file, time_t datetime)
>   {
> +   int ret;
> + #if GLIB_MAJOR_VERSION > 1
> +   char *tempstr;
> + #endif
> + 
>     g_return_val_if_fail (request != NULL, -2);
>   
>     if (request->set_file_time == NULL)
>       return (-2);
> ! #if GLIB_MAJOR_VERSION > 1
> !   tempstr = gftp_locale_from_utf8(file);
> !   ret = request->set_file_time (request, tempstr, datetime);
> !   g_free(tempstr);
> ! #else
> !   ret = request->set_file_time (request, file, datetime);
> ! #endif
> ! 
> !   return (ret);
>   }
>   
>   
> ***************
> *** 761,771 ****
>   off_t
>   gftp_get_file_size (gftp_request * request, const char *filename)
>   {
>     g_return_val_if_fail (request != NULL, 0);
>   
>     if (request->get_file_size == NULL)
>       return (0);
> !   return (request->get_file_size (request, filename));
>   }
>   
>   
> --- 917,941 ----
>   off_t
>   gftp_get_file_size (gftp_request * request, const char *filename)
>   {
> +   int ret;
> + #if GLIB_MAJOR_VERSION > 1
> +   char *tempstr;
> + #endif
> + 
>     g_return_val_if_fail (request != NULL, 0);
>   
>     if (request->get_file_size == NULL)
>       return (0);
> ! 
> ! #if GLIB_MAJOR_VERSION > 1
> !   tempstr = gftp_locale_from_utf8(filename);
> !   ret = request->get_file_size (request, tempstr);
> !   g_free(tempstr);
> ! #else
> !   ret = request->get_file_size (request, filename);
> ! #endif
> ! 
> !   return (ret);
>   }
>   
>   
> ***************
> *** 1481,1486 ****
> --- 1651,1657 ----
>     unsigned long *newsize;
>     GHashTable * dirhash;
>     gftp_file * curfle;
> +   int set_dir_ret;
>   
>     g_return_val_if_fail (transfer != NULL, -1);
>     g_return_val_if_fail (transfer->fromreq != NULL, -1);
> ***************
> *** 1530,1543 ****
>                 transfer->toreq->directory = curfle->destfile;
>               } 
>             forcecd = 1;
> !           if (gftp_set_directory (transfer->fromreq, 
> !                                   transfer->fromreq->directory) == 0)
>               {
>                 if (curfle->startsize > 0 && transfer->toreq)
>                   {
>                     remotechanged = 1;
> !                   if (gftp_set_directory (transfer->toreq, 
> !                                           transfer->toreq->directory) != 0)
>                       curfle->startsize = 0;
>                   } 
>   
> --- 1701,1719 ----
>                 transfer->toreq->directory = curfle->destfile;
>               } 
>             forcecd = 1;
> !           set_dir_ret = gftp_set_directory (transfer->fromreq, 
> !                                             transfer->fromreq->directory);
> !           curfle->file = transfer->fromreq->directory;
> !           if (set_dir_ret == 0)
>               {
>                 if (curfle->startsize > 0 && transfer->toreq)
>                   {
>                     remotechanged = 1;
> !                   set_dir_ret = 
> !                     gftp_set_directory (transfer->toreq, 
> !                                         transfer->toreq->directory);
> !                   curfle->destfile = transfer->toreq->directory;
> !                   if (set_dir_ret != 0)
>                       curfle->startsize = 0;
>                   } 
>   
> ***************
> *** 2194,2196 ****
> --- 2370,2419 ----
>       dest->swap_socks (dest, source);
>   }
>   
> + #if GLIB_MAJOR_VERSION > 1
> + char*
> + gftp_locale_to_utf8(const char *from)
> + {
> +   char *result = NULL;
> +   gsize bread, bwrite;
> +   GError * error;
> +   
> +   if (from != NULL)
> +     {
> +       error = NULL;
> +       if ((result = g_locale_to_utf8 (from, -1, &bread,
> +                                       &bwrite, &error)) == NULL)
> +         g_warning ("Error when converting %s from UTF-8: %s\n", from,
> +                    error->message);
> +     }
> +   else
> +     {
> +       result = g_memdup(from, (strlen (from) + 1));
> +     }
> +   
> +   return result;
> + }
> + 
> + char*
> + gftp_locale_from_utf8(const char *from)
> + {
> +   char *result;
> +   gsize bread, bwrite;
> +   GError * error;
> + 
> +   if (from != NULL && g_utf8_validate (from, -1, NULL))
> +     {
> +       error = NULL;
> +       if ((result = g_locale_from_utf8 (from, -1, &bread,
> +                                         &bwrite, &error)) == NULL)
> +         g_warning ("Error when converting %s from UTF-8: %s\n", from,
> +                    error->message);
> +     }
> +   else
> +     {
> +       result = g_memdup(from, (strlen (from) + 1));
> +     }
> +   
> +   return result;
> + }
> + #endif
> 
> *** /home/liling/src/gftp/gftp-2.0.14/src/gtk/transfer.c	Thu Dec  5 08:43:07 2002
> --- /home/liling/src/gftp/gftp-2.0.14.patched/src/gtk/transfer.c	Wed Jul 16 01:02:10 2003
> ***************
> *** 768,774 ****
> --- 768,780 ----
>               {
>                 if (transfer->toreq->mkdir != NULL)
>                   {
> + #if GLIB_MAJOR_VERSION > 1
> +                   tempstr = gftp_locale_from_utf8(curfle->destfile);
> +                   transfer->toreq->mkdir (transfer->toreq, tempstr);
> +                   g_free(tempstr);
> + #else
>                     transfer->toreq->mkdir (transfer->toreq, curfle->destfile);
> + #endif
>                     if (!GFTP_IS_CONNECTED (transfer->toreq))
>                       break;
>                   }
> 
> *** /home/liling/src/gftp/gftp-2.0.14/src/gtk/view_dialog.c	Thu Nov 21 08:33:51 2002
> --- /home/liling/src/gftp/gftp-2.0.14.patched/src/gtk/view_dialog.c	Tue Jul 15 21:15:01 2003
> ***************
> *** 29,34 ****
> --- 29,37 ----
>     gftp_window_data * fromwdata, * towdata;
>     gftp_file * new_fle;
>     int num;
> + #if GLIB_MAJOR_VERSION > 1
> +   char * tempstr;
> + #endif
>   
>     fromwdata = data;
>     towdata = fromwdata == &window1 ? &window2 : &window1;
> ***************
> *** 49,55 ****
>       }
>   
>     if (strcmp (GFTP_GET_PROTOCOL_NAME (fromwdata->request), "Local") == 0)
> !     view_file (curfle->file, 0, 1, 0, 1, 1, NULL, fromwdata);
>     else
>       {
>         new_fle = copy_fdata (curfle);
> --- 52,66 ----
>       }
>   
>     if (strcmp (GFTP_GET_PROTOCOL_NAME (fromwdata->request), "Local") == 0)
> !     {
> ! #if GLIB_MAJOR_VERSION > 1
> !       tempstr = gftp_locale_from_utf8 (curfle->file);
> !       view_file (tempstr, 0, 1, 0, 1, 1, NULL, fromwdata);
> !       g_free (tempstr);
> ! #else
> !       view_file (curfle->file, 0, 1, 0, 1, 1, NULL, fromwdata);
> ! #endif
> !     }
>     else
>       {
>         new_fle = copy_fdata (curfle);
> ***************
> *** 84,89 ****
> --- 95,103 ----
>     GList * templist, * filelist, * newfile;
>     gftp_file * new_fle;
>     int num;
> + #if GLIB_MAJOR_VERSION > 1
> +   char * tempstr;
> + #endif
>   
>     fromwdata = data;
>     towdata = fromwdata == &window1 ? &window2 : &window1;
> ***************
> *** 111,117 ****
>       }
>   
>     if (strcmp (GFTP_GET_PROTOCOL_NAME (fromwdata->request), "Local") == 0)
> !     view_file (curfle->file, 0, 0, 0, 1, 1, NULL, fromwdata);
>     else
>       {
>         new_fle = copy_fdata (curfle);
> --- 125,139 ----
>       }
>   
>     if (strcmp (GFTP_GET_PROTOCOL_NAME (fromwdata->request), "Local") == 0)
> !     {
> ! #if GLIB_MAJOR_VERSION > 1
> !       tempstr = gftp_locale_from_utf8 (curfle->file);
> !       view_file (tempstr, 0, 0, 0, 1, 1, NULL, fromwdata);
> !       g_free (tempstr);
> ! #else
> !       view_file (curfle->file, 0, 0, 0, 1, 1, NULL, fromwdata);
> ! #endif
> !     }
>     else
>       {
>         new_fle = copy_fdata (curfle);
> 
> *** /home/liling/src/gftp/gftp-2.0.14/src/text/gftp-text.c	Wed Nov 27 22:29:56 2002
> --- /home/liling/src/gftp/gftp-2.0.14.patched/src/text/gftp-text.c	Tue Jul 15 21:15:01 2003
> ***************
> *** 389,401 ****
> --- 389,411 ----
>   int
>   gftp_text_pwd (gftp_request * request, char *command, gpointer *data)
>   {
> + #if GLIB_MAJOR_VERSION > 1
> +   char *tempstr;
> + #endif
> + 
>     if (!GFTP_IS_CONNECTED (request))
>       {
>         gftp_text_log (gftp_logging_error, NULL,
>                        _("Error: Not connected to a remote site\n"));
>         return (1);
>       }
> + #if GLIB_MAJOR_VERSION > 1
> +   tempstr = gftp_locale_from_utf8(request->directory);
> +   gftp_text_log (gftp_logging_misc, NULL, "%s\n", tempstr);
> +   g_free(tempstr);
> + #else
>     gftp_text_log (gftp_logging_misc, NULL, "%s\n", request->directory);
> + #endif
>     return (1);
>   }
>   
> ***************
> *** 458,463 ****
> --- 468,477 ----
>   int
>   gftp_text_rmdir (gftp_request * request, char *command, gpointer *data)
>   {
> + #if GLIB_MAJOR_VERSION > 1
> +   char * tempstr;
> + #endif
> + 
>     if (!GFTP_IS_CONNECTED (request))
>       {
>         gftp_text_log (gftp_logging_error, NULL, 
> ***************
> *** 471,477 ****
> --- 485,497 ----
>       }
>     else
>       {
> + #if GLIB_MAJOR_VERSION > 1
> +       tempstr = gftp_locale_to_utf8(command);
> +       gftp_remove_directory (request, tempstr);
> +       g_free(tempstr);
> + #else
>         gftp_remove_directory (request, command);
> + #endif
>       }
>     return (1);
>   }
> ***************
> *** 480,485 ****
> --- 500,508 ----
>   int
>   gftp_text_delete (gftp_request * request, char *command, gpointer *data)
>   {
> + #if GLIB_MAJOR_VERSION > 1
> +   char * tempstr;
> + #endif
>     if (!GFTP_IS_CONNECTED (request))
>       {
>         gftp_text_log (gftp_logging_error, NULL,
> ***************
> *** 493,499 ****
> --- 516,528 ----
>       }
>     else
>       {
> + #if GLIB_MAJOR_VERSION > 1
> +       tempstr = gftp_locale_to_utf8(command);
> +       gftp_remove_file (request, tempstr);
> +       g_free(tempstr);
> + #else
>         gftp_remove_file (request, command);
> + #endif
>       }
>     return (1);
>   }
> ***************
> *** 503,508 ****
> --- 532,540 ----
>   gftp_text_rename (gftp_request * request, char *command, gpointer *data)
>   {
>     char *pos;
> + #if GLIB_MAJOR_VERSION > 1
> +   char * tempstr;
> + #endif
>   
>     if (!GFTP_IS_CONNECTED (request))
>       {
> ***************
> *** 521,527 ****
> --- 553,565 ----
>       }
>     else
>       {
> + #if GLIB_MAJOR_VERSION > 1
> +       tempstr = gftp_locale_to_utf8(command);
> +       gftp_rename_file (request, tempstr, pos);
> +       g_free(tempstr);
> + #else
>         gftp_rename_file (request, command, pos);
> + #endif
>       }
>     return (1);
>   }
> ***************
> *** 531,536 ****
> --- 569,577 ----
>   gftp_text_chmod (gftp_request * request, char *command, gpointer *data)
>   {
>     char *pos;
> + #if GLIB_MAJOR_VERSION > 1
> +   char * tempstr;
> + #endif
>   
>     if (!GFTP_IS_CONNECTED (request))
>       {
> ***************
> *** 549,555 ****
> --- 590,602 ----
>       }
>     else
>       {
> + #if GLIB_MAJOR_VERSION > 1
> +       tempstr = gftp_locale_to_utf8(command);
> +       gftp_chmod (request, pos, strtol (tempstr, NULL, 10));
> +       g_free(tempstr);
> + #else
>         gftp_chmod (request, pos, strtol (command, NULL, 10));
> + #endif
>       }
>     return (1);
>   }
> ***************
> *** 563,568 ****
> --- 610,620 ----
>     int sortcol, sortasds;
>     gftp_file * fle;
>     time_t curtime;
> + #if GLIB_MAJOR_VERSION > 1
> +   gsize bread, bwrite;
> +   char *tempstr;
> +   GError * error;
> + #endif
>   
>     time (&curtime);
>     if (!GFTP_IS_CONNECTED (request))
> ***************
> *** 618,623 ****
> --- 670,681 ----
>   
>         fle = templist->data;
>   
> + #if GLIB_MAJOR_VERSION > 1
> +       tempstr = gftp_locale_from_utf8 (fle->file);
> +       g_free (fle->file);
> +       fle->file = tempstr;
> + #endif
> + 
>         if (*fle->attribs == 'd')
>           color = COLOR_BLUE;
>         else if (*fle->attribs == 'l')
> ***************
> *** 696,701 ****
> --- 754,762 ----
>   {
>     gftp_transfer * transfer;
>     gftp_file * fle;
> + #if GLIB_MAJOR_VERSION > 1
> +   char * tempstr;
> + #endif
>   
>     if (!GFTP_IS_CONNECTED (gftp_text_remreq))
>       {
> ***************
> *** 723,729 ****
> --- 784,795 ----
>         return (1);
>       }
>     fle = g_malloc0 (sizeof (*fle));
> + #if GLIB_MAJOR_VERSION > 1
> +   tempstr = gftp_locale_to_utf8(command);
> +   while (gftp_get_next_file (transfer->fromreq, tempstr, fle) > 0)
> + #else
>     while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
> + #endif
>       {
>         if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
>           {
> ***************
> *** 735,740 ****
> --- 801,809 ----
>       }
>     g_free (fle);
>     gftp_end_transfer (transfer->fromreq);
> + #if GLIB_MAJOR_VERSION > 1
> +   g_free(tempstr);
> + #endif
>   
>     if (transfer->files == NULL)
>       {
> ***************
> *** 769,774 ****
> --- 838,846 ----
>   {
>     gftp_transfer * transfer;
>     gftp_file * fle;
> + #if GLIB_MAJOR_VERSION > 1
> +   char * tempstr;
> + #endif
>   
>     if (!GFTP_IS_CONNECTED (gftp_text_remreq))
>       {
> ***************
> *** 795,801 ****
> --- 867,878 ----
>         return (1);
>       }
>     fle = g_malloc (sizeof (*fle));
> + #if GLIB_MAJOR_VERSION > 1
> +   tempstr = gftp_locale_to_utf8(command);
> +   while (gftp_get_next_file (transfer->fromreq, tempstr, fle) > 0)
> + #else
>     while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
> + #endif
>       {
>         if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
>           {
> ***************
> *** 807,812 ****
> --- 884,892 ----
>       }
>     g_free (fle);
>     gftp_end_transfer (transfer->fromreq);
> + #if GLIB_MAJOR_VERSION > 1
> +   g_free(tempstr);
> + #endif
>   
>     if (transfer->files == NULL)
>       {