+Unicode/UTF8 locale conversion support for 'G_BROKEN_FILENAMES' etc.
authorshort <>
Sat, 13 Dec 2003 21:20:05 +0000 (21:20 +0000)
committershort <>
Sat, 13 Dec 2003 21:20:05 +0000 (21:20 +0000)
23 files changed:
src/client/cmdline/Makefile.am
src/client/cmdline/cmd_cd.c
src/client/cmdline/cmd_create.c
src/client/cmdline/cmd_get.c
src/client/cmdline/cmd_info.c
src/client/cmdline/cmd_lcd.c
src/client/cmdline/cmd_ls.c
src/client/cmdline/cmd_mkdir.c
src/client/cmdline/cmd_mv.c
src/client/cmdline/cmd_open.c
src/client/cmdline/cmd_put.c
src/client/cmdline/cmd_rm.c
src/client/cmdline/cmd_rmdir.c
src/client/cmdline/file_info.c
src/client/cmdline/handle.c
src/client/cmdline/main.c
src/client/cmdline/utf8.c [new file with mode: 0644]
src/client/cmdline/utf8.h [new file with mode: 0644]
src/client/lufs/captivefs-directory.c
src/client/lufs/captivefs-file.c
src/client/lufs/captivefs-misc.c
src/client/lufs/captivefs-misc.h
src/client/lufs/captivefs-vfs.c

index 236b4ab..b456c70 100644 (file)
@@ -60,7 +60,9 @@ captive_cmdline_SOURCES= \
                handle.c \
                handle.h \
                main.c \
-               main.h
+               main.h \
+               utf8.c \
+               utf8.h
 captive_cmdline_CFLAGS=                   $(GNOME_VFS_CFLAGS)
 captive_cmdline_LDADD =$(captive_library) $(GNOME_VFS_LIBS)   $(READLINE_LIBS) $(INTLLIBS)
 captive_cmdline_LDFLAGS=$(READLINE_LDFLAGS)
index 2b0c762..84bb8e7 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "cmd_cd.h"    /* self */
 #include "main.h"
+#include "utf8.h"
 
 
 /* Config: */
@@ -99,7 +100,7 @@ CaptiveDirectoryObject *captive_directory_object;
                        targetdir))) {  /* pathname */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_CD_ERROR,CMDLINE_CMD_CD_ERROR_CANNOT_OPEN_DIRECTORY,
-                               _("Cannot open directory: %s"),targetdir);
+                               _("Cannot open directory: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
                return;
                }
 
index 98c2c85..ceef1f3 100644 (file)
@@ -28,6 +28,7 @@
 #include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
 #include "main.h"
 #include "handle.h"
+#include "utf8.h"
 
 
 GQuark cmdline_cmd_create_error_quark(void)
@@ -100,7 +101,7 @@ gboolean read_only;
                        (read_only ? 0400 : 0000)))) {  /* perm */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_CREATE_ERROR,CMDLINE_CMD_CREATE_ERROR_CREATING_FILE,
-                               _("Error creating guest-os file '%s'"),filename);
+                               _("Error creating guest-os file '%s'"),CMD_LOCALE_FROM_UTF8_ALLOCA(filename));
                return;
                }
 
index c852b22..87daf72 100644 (file)
@@ -32,6 +32,7 @@
 #include "cmd_get.h"   /* self */
 #include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
 #include "main.h"
+#include "utf8.h"
 
 
 /* Config: */
@@ -80,7 +81,7 @@ char *endptr;
                transfer_buffer_size=strtol(string,&endptr,0);
                if (transfer_buffer_size<=0 || transfer_buffer_size>=LONG_MAX || (endptr && *endptr)) {
                        g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_PARSING_TRANSFER_BUFFER_SIZE,
-                                       _("Error parsing transfer buffer size: %s"),string);
+                                       _("Error parsing transfer buffer size: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(string));
                        return;
                        }
                }
@@ -96,7 +97,7 @@ char *s;
                        targetfile=s+1;
                }
 
-       if (-1==(fdtgt=open(targetfile,
+       if (-1==(fdtgt=open(CMD_FILENAME_FROM_UTF8_ALLOCA(targetfile),
                        O_CREAT|O_EXCL|O_WRONLY /* flags */
 #ifdef O_BINARY
                                        | O_BINARY
@@ -107,7 +108,7 @@ char *s;
                                        ,
                        perm))) {       /* mode */
                g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_CANNOT_CREATE_TARGET_HOSTOS_FILE,
-                               _("Cannot create target host-os file '%s': %s"),targetfile,g_strerror(errno));
+                               _("Cannot create target host-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile),g_strerror(errno));
                return;
                }
 
@@ -118,7 +119,7 @@ char *s;
                        GNOME_VFS_OPEN_READ))) {        /* mode */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_OPENING_SOURCE_FILE,
-                               _("Error opening source guest-os file: %s"),sourcefile);
+                               _("Error opening source guest-os file: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile));
                goto err_close_fdtgt;
                }
 
@@ -146,13 +147,13 @@ gboolean errbool;
                        g_assert(errbool==FALSE);
                        err_cleanup(errp);
                        g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_READING_SOURCE_FILE,
-                                       _("Error reading source guest-os file '%s': %s"),sourcefile,g_strerror(errno));
+                                       _("Error reading source guest-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile),g_strerror(errno));
                        goto err_free_transfer_buffer;
                        }
 
                if (bytes_read!=(GnomeVFSFileSize)(gotssize=write(fdtgt,transfer_buffer,bytes_read))) {
                        g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_WRITING_TARGET_HOSTOS_FILE,
-                                       _("Error writing target host-os file: %s"),targetfile);
+                                       _("Error writing target host-os file: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
                        goto err_free_transfer_buffer;
                        }
                }
@@ -165,6 +166,6 @@ err_close_fdtgt:
        if (close(fdtgt)) {
                err_cleanup(errp);      /* may be clean */
                g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_CLOSING_TARGET_HOSTOS_FILE,
-                               _("Error closing target host-os file '%s': %s"),targetfile,g_strerror(errno));
+                               _("Error closing target host-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile),g_strerror(errno));
                }
 }
index edc4f8d..f937429 100644 (file)
@@ -30,6 +30,7 @@
 #include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
 #include "main.h"
 #include "file_info.h"
+#include "utf8.h"
 
 
 GQuark cmdline_cmd_info_error_quark(void)
@@ -66,7 +67,7 @@ const gchar *filepath;
                        GNOME_VFS_OPEN_READ))) {        /* mode */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_INFO_ERROR,CMDLINE_CMD_INFO_ERROR_CANNOT_OPEN_FILE,
-                               _("Cannot open file: %s"),filepath);
+                               _("Cannot open file: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(filepath));
                return;
                }
 
@@ -75,7 +76,7 @@ const gchar *filepath;
                        &file_info))) { /* file_info */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_INFO_ERROR,CMDLINE_CMD_INFO_ERROR_GETTING_FILE_INFO,
-                               _("Cannot get file information about: %s"),filepath);
+                               _("Cannot get file information about: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(filepath));
                goto err_unref;
                }
        file_info_dump_full(&file_info,errp);
index b2f1c8d..c1825b7 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "cmd_lcd.h"   /* self */
 #include "main.h"      /* for CMDLINE_POPT_AUTOHELP */
+#include "utf8.h"
 
 
 const gchar *cmdline_cwd;
@@ -55,19 +56,19 @@ const struct poptOption cmd_lcd_table[]={
 
 void cmd_lcd(const char **cmd_argv,GError **errp)
 {
-gchar *currentdir;
+gchar *currentdir_filename;
 
        g_return_if_fail(!errp || !*errp);
 
        if (cmd_argv[0]) {
-               if (chdir(cmd_argv[0])) {
+               if (chdir(CMD_FILENAME_FROM_UTF8_ALLOCA(cmd_argv[0]))) {
                        g_set_error(errp,CMDLINE_CMD_LCD_ERROR,CMDLINE_CMD_LCD_ERROR_CANNOT_CHANGE_HOSTOS_DIRECTORY,
-                                       _("Cannot change host-os directory to '%s': %s"),cmd_argv[0],g_strerror(errno));
+                                       _("Cannot change host-os directory to '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_argv[0]),g_strerror(errno));
                        return;
                        }
                }
 
-       currentdir=g_get_current_dir();
-       printf("Host-OS CWD: %s\n",currentdir);
-       g_free(currentdir);
+       currentdir_filename=g_get_current_dir();
+       printf("Host-OS CWD: %s\n",CMD_LOCALE_FROM_UTF8_ALLOCA(CMD_FILENAME_TO_UTF8_ALLOCA(currentdir_filename)));
+       g_free(currentdir_filename);
 }
index e594629..c87999c 100644 (file)
@@ -30,6 +30,7 @@
 #include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
 #include "main.h"
 #include "file_info.h"
+#include "utf8.h"
 
 
 GQuark cmdline_cmd_ls_error_quark(void)
@@ -66,7 +67,7 @@ const gchar *targetdir;
                        targetdir))) {  /* pathname */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_LS_ERROR,CMDLINE_CMD_LS_ERROR_CANNOT_OPEN_DIRECTORY,
-                               _("Cannot open directory: %s"),targetdir);
+                               _("Cannot open directory: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
                return;
                }
 
@@ -84,7 +85,7 @@ gboolean errbool;
                g_assert(errbool==FALSE);
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_LS_ERROR,CMDLINE_CMD_LS_ERROR_READING_DIRECTORY,
-                               _("Error reading directory: %s"),targetdir);
+                               _("Error reading directory: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
                goto err_unref;
                }
 
index 1a6c4f3..2ddb495 100644 (file)
@@ -27,6 +27,7 @@
 #include "cmd_mkdir.h" /* self */
 #include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
 #include "main.h"
+#include "utf8.h"
 
 
 GQuark cmdline_cmd_mkdir_error_quark(void)
@@ -63,7 +64,7 @@ const gchar *targetdir;
                        perms))) {      /* perms */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_MKDIR_ERROR,CMDLINE_CMD_MKDIR_ERROR_CANNOT_CREATE_DIRECTORY,
-                               _("Cannot create directory: %s"),targetdir);
+                               _("Cannot create directory: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
                return;
                }
 
index 7ccfdae..21f77c0 100644 (file)
@@ -27,6 +27,7 @@
 #include "cmd_mv.h"    /* self */
 #include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
 #include "main.h"
+#include "utf8.h"
 
 
 GQuark cmdline_cmd_mv_error_quark(void)
@@ -63,7 +64,7 @@ const gchar *sourcefile,*targetfile;
                        GNOME_VFS_OPEN_NONE))) {        /* mode */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_MV_ERROR,CMDLINE_CMD_MV_ERROR_CANNOT_OPEN_FILE_TO_MOVE,
-                               _("Cannot open file to be moved: %s"),targetfile);
+                               _("Cannot open file to be moved: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
                return;
                }
 
@@ -73,7 +74,8 @@ const gchar *sourcefile,*targetfile;
                        FALSE))) {      /* force_replace */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_MV_ERROR,CMDLINE_CMD_MV_ERROR_CANNOT_MOVE_FILE,
-                               _("Cannot move file '%s' to its target name '%s'"),sourcefile,targetfile);
+                               _("Cannot move file '%s' to its target name '%s'"),
+                               CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
                goto err_unref;
                }
 
index f058c7d..0220b93 100644 (file)
@@ -28,6 +28,7 @@
 #include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
 #include "main.h"
 #include "handle.h"
+#include "utf8.h"
 
 
 GQuark cmdline_cmd_open_error_quark(void)
@@ -86,7 +87,7 @@ const gchar *handle_name;
                        mode))) {       /* mode */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_OPEN_ERROR,CMDLINE_CMD_OPEN_ERROR_OPENING_FILE,
-                               _("Error opening guest-os file '%s'"),filename);
+                               _("Error opening guest-os file '%s'"),CMD_LOCALE_FROM_UTF8_ALLOCA(filename));
                return;
                }
 
index 479c73d..910eb15 100644 (file)
@@ -32,6 +32,7 @@
 #include "cmd_put.h"   /* self */
 #include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
 #include "main.h"
+#include "utf8.h"
 
 
 /* Config: */
@@ -81,7 +82,7 @@ char *endptr;
                transfer_buffer_size=strtol(string,&endptr,0);
                if (transfer_buffer_size<=0 || transfer_buffer_size>=LONG_MAX || (endptr && *endptr)) {
                        g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_PARSING_TRANSFER_BUFFER_SIZE,
-                                       _("Error parsing transfer buffer size: %s"),string);
+                                       _("Error parsing transfer buffer size: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(string));
                        return;
                        }
                }
@@ -97,7 +98,7 @@ gchar *sourcefile_basename;
                g_free(sourcefile_basename);
                }
 
-       if (-1==(fdsrc=open(sourcefile,O_RDONLY
+       if (-1==(fdsrc=open(CMD_FILENAME_FROM_UTF8_ALLOCA(sourcefile),O_RDONLY
 #ifdef O_BINARY
                        | O_BINARY
 #endif /* O_BINARY */
@@ -106,7 +107,7 @@ gchar *sourcefile_basename;
 #endif /* O_LARGEFILE */
                        ))) {
                g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_OPENING_SOURCE_FILE,
-                               _("Error opening source host-os file '%s': %s"),sourcefile,g_strerror(errno));
+                               _("Error opening source host-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile),g_strerror(errno));
                return;
                }
 
@@ -119,7 +120,7 @@ gchar *sourcefile_basename;
                        perm))) {       /* perm */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_CANNOT_CREATE_TARGET_GUESTOS_FILE,
-                               _("Cannot create target guest-os file: %s"),targetfile);
+                               _("Cannot create target guest-os file: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
                goto err_close_fdsrc;
                }
 
@@ -136,19 +137,19 @@ GnomeVFSFileSize bytes_written;
                                &bytes_written))) {     /* bytes_written_return */
                        err_cleanup(errp);
                        g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_WRITING_TARGET_GUESTOS_FILE,
-                                       _("Error writing target guest-os file: %s"),targetfile);
+                                       _("Error writing target guest-os file: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
                        goto err_free_transfer_buffer;
                        }
                if (bytes_written!=(GnomeVFSFileSize)got) {
                        g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_WRITING_TARGET_GUESTOS_FILE,
                                        _("Error writing target guest-os file '%s': requested %d, written %Lu"),
-                                       targetfile,got,(unsigned long long)bytes_written);
+                                       CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile),got,(unsigned long long)bytes_written);
                        goto err_free_transfer_buffer;
                        }
                }
        if (got==-1) {
                g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_READING_SOURCE_FILE,
-                               _("Error reading source host-os file '%s': %s"),sourcefile,g_strerror(errno));
+                               _("Error reading source host-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile),g_strerror(errno));
                goto err_free_transfer_buffer;
                }
        g_assert(got==0);
@@ -161,6 +162,6 @@ err_close_fdsrc:
        if (close(fdsrc)) {
                err_cleanup(errp);      /* may be clean */
                g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_CLOSING_SOURCE_FILE,
-                               _("Error closing source host-os file '%s': %s"),sourcefile,g_strerror(errno));
+                               _("Error closing source host-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile),g_strerror(errno));
                }
 }
index bf7e847..1c9e5ba 100644 (file)
@@ -27,6 +27,7 @@
 #include "cmd_rm.h"    /* self */
 #include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
 #include "main.h"
+#include "utf8.h"
 
 
 GQuark cmdline_cmd_rm_error_quark(void)
@@ -62,7 +63,7 @@ const gchar *targetfile;
                        GNOME_VFS_OPEN_NONE))) {        /* mode */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_RM_ERROR,CMDLINE_CMD_RM_ERROR_CANNOT_CREATE_REMOVAL_FILE,
-                               _("Cannot open file for removal: %s"),targetfile);
+                               _("Cannot open file for removal: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
                return;
                }
 
@@ -70,7 +71,7 @@ const gchar *targetfile;
                        captive_file_object))) {        /* captive_file_object */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_RM_ERROR,CMDLINE_CMD_RM_ERROR_CANNOT_SET_FILE_REMOVAL,
-                               _("Cannot set file removal state: %s"),targetfile);
+                               _("Cannot set file removal state: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
                goto err_unref;
                }
 
index 5084e50..be2b8ca 100644 (file)
@@ -27,6 +27,7 @@
 #include "cmd_rmdir.h" /* self */
 #include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
 #include "main.h"
+#include "utf8.h"
 
 
 GQuark cmdline_cmd_rmdir_error_quark(void)
@@ -61,7 +62,7 @@ const gchar *targetdir;
                        targetdir))) {  /* pathname */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_RMDIR_ERROR,CMDLINE_CMD_RMDIR_ERROR_CANNOT_CREATE_REMOVAL_DIRECTORY,
-                               _("Cannot open directory for removal: %s"),targetdir);
+                               _("Cannot open directory for removal: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
                return;
                }
 
@@ -69,7 +70,7 @@ const gchar *targetdir;
                        captive_directory_object))) {   /* captive_directory_object */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_RMDIR_ERROR,CMDLINE_CMD_RMDIR_ERROR_CANNOT_SET_DIRECTORY_REMOVAL,
-                               _("Cannot set directory removal state: %s"),targetdir);
+                               _("Cannot set directory removal state: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
                goto err_unref;
                }
 
index 23b0cd4..eab9d62 100644 (file)
@@ -28,6 +28,7 @@
 
 
 #include "file_info.h" /* self */
+#include "utf8.h"
 
 
 GQuark cmdline_file_info_error_quark(void)
@@ -68,7 +69,7 @@ gchar *file_size;
                file_size=g_strdup_printf("%8s","???");
 
        /*      type pm sz nm */
-       printf("[%s] %s %s %s\n",file_type,file_perms,file_size,file_info->name);
+       printf("[%s] %s %s %s\n",file_type,file_perms,file_size,CMD_LOCALE_FROM_UTF8_ALLOCA(file_info->name));
        
        g_free(file_size);
 }
@@ -78,7 +79,7 @@ void file_info_dump_full(const GnomeVFSFileInfo *file_info,GError **errp)
 {
        g_return_if_fail(!errp || !*errp);
 
-       printf("Filename: %s\n",file_info->name);
+       printf("Filename: %s\n",CMD_LOCALE_FROM_UTF8_ALLOCA(file_info->name));
 
        fputs("File type: ",stdout);
        switch (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) ? GNOME_VFS_FILE_TYPE_UNKNOWN : file_info->type) {
index d144009..6e7b7d7 100644 (file)
@@ -24,6 +24,7 @@
 #include <captive/client-file.h>
 
 #include "handle.h"    /* self */
+#include "utf8.h"
 
 
 GQuark cmdline_handle_error_quark(void)
@@ -75,7 +76,7 @@ CaptiveFileObject *r;
 
        if (!(r=g_hash_table_lookup(handle_hash,handle_name)))
                g_set_error(errp,CMDLINE_HANDLE_ERROR,CMDLINE_HANDLE_ERROR_LOOKUP,
-                               _("Error looking up existing handle: %s"),handle_name);
+                               _("Error looking up existing handle: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(handle_name));
 
        return r;
 }
@@ -92,7 +93,7 @@ gboolean r;
 
        if (!(r=!g_hash_table_lookup(handle_hash,handle_name)))
                g_set_error(errp,CMDLINE_HANDLE_ERROR,CMDLINE_HANDLE_ERROR_ALREADY_USED,
-                               _("Specified handle already used: %s"),handle_name);
+                               _("Specified handle already used: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(handle_name));
 
        return r;
 }
@@ -120,7 +121,7 @@ void handle_delete(const gchar *handle_name,GError **errp)
 
        if (!g_hash_table_remove(handle_hash,handle_name)) {
                g_set_error(errp,CMDLINE_HANDLE_ERROR,CMDLINE_HANDLE_ERROR_DELETE,
-                               _("Handle to be deleted not found: %s"),handle_name);
+                               _("Handle to be deleted not found: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(handle_name));
                return;
                }
 
index c6b263b..2bf5bd0 100644 (file)
@@ -49,6 +49,7 @@
 #include "cmd_close.h"
 #include "cmd_quit.h"
 #include "cmd_help.h"
+#include "utf8.h"
 
 
 CaptiveVfsObject *cmdline_captive_vfs_object;
@@ -123,8 +124,8 @@ const char *cmd_name=NULL;
 poptContext cmd_context;
 int errint;
 const char **cmdarg_argv;
-int cmdarg_argc;
-const char **csp;
+int cmdarg_argc,argci;
+const char **csp,*cs;
 const char *emptyargv_NULL=NULL;
 
        g_return_if_fail(cmd_argc>=0);
@@ -140,6 +141,11 @@ const char *stub_shell[]={ cmdline_command_table[0].name,NULL };
                cmd_argv=stub_shell;
                }
 
+       for (argci=0;argci<cmd_argc;argci++) {
+               if ((cs=CMD_LOCALE_TO_UTF8_ALLOCA(cmd_argv[argci])))
+                       cmd_argv[argci]=cs;
+               }
+
        cmd_name=*cmd_argv;
        for (commandp=cmdline_command_table;commandp->name;commandp++) {
                if (!cmd_name   /* NULL cmd_name fallback to the first table entry - "shell" */
@@ -148,7 +154,7 @@ const char *stub_shell[]={ cmdline_command_table[0].name,NULL };
                }
        if (!commandp->name) {
                g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_UNKNOWN_COMMAND,
-                               _("Unknown command, try 'help': %s"),cmd_name);
+                               _("Unknown command, try 'help': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_name));
                return;
                }
        displayArgs_hit=FALSE;
@@ -159,20 +165,21 @@ const char *stub_shell[]={ cmdline_command_table[0].name,NULL };
                        POPT_CONTEXT_POSIXMEHARDER);    /* flags; !POPT_CONTEXT_KEEP_FIRST */
        if (cmd_context==NULL) {
                g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_INVALID_COMMAND_ARGUMENTS,
-                               _("Invalid arguments for command: %s"),cmd_name);
+                               _("Invalid arguments for command: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_name));
                return;
                }
        errint=poptReadDefaultConfig(cmd_context,
                        TRUE);  /* useEnv */
        if (errint!=0) {
                g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_READING_COMMAND_CONFIG,
-                               _("Error '%s' reading default configuration for command: %s"),poptStrerror(errint),cmd_name);
+                               _("Error '%s' reading default configuration for command: %s"),
+                               poptStrerror(errint),CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_name));
                goto err_free_context;
                }
        errint=poptGetNextOpt(cmd_context);
        if (errint!=-1) {
                g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_EXCEEDING_COMMAND_OPTION,
-                               _("Exceeding command option for command: %s"),cmd_name);
+                               _("Exceeding command option for command: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_name));
                goto err_free_context;
                }
        if (!(cmdarg_argv=poptGetArgs(cmd_context)))
@@ -186,7 +193,7 @@ const char *stub_shell[]={ cmdline_command_table[0].name,NULL };
        if (cmdarg_argc<commandp->argsn_min || cmdarg_argc>commandp->argsn_max) {
                g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_INVALID_COMMAND_ARGUMENT_COUNT,
                                _("Invalid number of command '%s' arguments: %d; expected from %d to %d incl."),
-                               cmd_name,cmdarg_argc,commandp->argsn_min,commandp->argsn_max);
+                               CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_name),cmdarg_argc,commandp->argsn_min,commandp->argsn_max);
                goto err_free_context;
                }
 
diff --git a/src/client/cmdline/utf8.c b/src/client/cmdline/utf8.c
new file mode 100644 (file)
index 0000000..40a5ce0
--- /dev/null
@@ -0,0 +1,52 @@
+/* $Id$
+ * client cmdline interface GnomeVFSFileInfo utils for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include <glib/gerror.h>
+
+
+#include "utf8.h"      /* self */
+
+
+gchar *cmd_utf8_macro_malloc_errorchecking(
+               gchar *(*func)(const gchar *string,gssize len,gsize *bytes_read,gsize *bytes_written,GError **error),
+               const gchar *string)
+{
+GError *error;
+gchar *r;
+
+       g_return_val_if_fail(func!=NULL,NULL);
+       g_return_val_if_fail(string!=NULL,NULL);
+
+       error=NULL;
+       r=(*func)(
+                       string, /* opsysstring/utf8string */
+                       -1,     /* len; '\0'-terminated */
+                       NULL,   /* bytes_read */
+                       NULL,   /* bytes_written */
+                       &error);        /* error */
+       if (error) {
+               g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,"captivefs g_filename_from_utf8(): name=\"%s\": %s",
+                               string,error->message);
+               g_clear_error(&error);
+               }
+       return r;
+}
diff --git a/src/client/cmdline/utf8.h b/src/client/cmdline/utf8.h
new file mode 100644 (file)
index 0000000..4042653
--- /dev/null
@@ -0,0 +1,58 @@
+/* $Id$
+ * Include file for client cmdline interface GnomeVFSFileInfo utils for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_CMDLINE_UTF8_H
+#define _CAPTIVE_CLIENT_CMDLINE_UTF8_H 1
+
+
+#include <captive/macros.h>
+#include <glib/gconvert.h>
+#include <glib/gtypes.h>
+
+
+gchar *cmd_utf8_macro_malloc_errorchecking(
+               gchar *(*func)(const gchar *string,gssize len,gsize *bytes_read,gsize *bytes_written,GError **error),
+               const gchar *name);
+
+
+#define CMD_UTF8_MACRO_ALLOCA(func,string) ({ \
+               const gchar *_cmd_utf8_macro_alloca_string=(string); \
+               gchar *_cmd_utf8_macro_alloca_r_malloc; \
+               const gchar *_cmd_utf8_macro_alloca_r; \
+                \
+               _cmd_utf8_macro_alloca_r_malloc=cmd_utf8_macro_malloc_errorchecking( \
+                               func, \
+                               _cmd_utf8_macro_alloca_string); \
+               if (!_cmd_utf8_macro_alloca_r_malloc) \
+                       _cmd_utf8_macro_alloca_r=_cmd_utf8_macro_alloca_string; \
+               else { \
+                       _cmd_utf8_macro_alloca_r=captive_strdup_alloca(_cmd_utf8_macro_alloca_r_malloc); \
+                       g_free(_cmd_utf8_macro_alloca_r_malloc); \
+                       } \
+               _cmd_utf8_macro_alloca_r; \
+               })
+
+
+#define CMD_FILENAME_TO_UTF8_ALLOCA(string)   CMD_UTF8_MACRO_ALLOCA(g_filename_to_utf8,(string))
+#define CMD_FILENAME_FROM_UTF8_ALLOCA(string) CMD_UTF8_MACRO_ALLOCA(g_filename_from_utf8,(string))
+#define CMD_LOCALE_TO_UTF8_ALLOCA(string)     CMD_UTF8_MACRO_ALLOCA(g_locale_to_utf8,(string))
+#define CMD_LOCALE_FROM_UTF8_ALLOCA(string)   CMD_UTF8_MACRO_ALLOCA(g_locale_from_utf8,(string))
+
+
+#endif /* _CAPTIVE_CLIENT_CMDLINE_UTF8_H */
index 692790f..c0d30a8 100644 (file)
@@ -61,6 +61,8 @@ const char *dots[]={".","..",NULL},**csp;
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_readdir: dir_name=%s",dir_name);
 
+       dir_name=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(dir_name);
+
        G_LOCK(libcaptive);
        errvfsresult=captive_directory_new_open(&captive_directory_object,captivefs_vfs->captive_vfs_object,dir_name);
        G_UNLOCK(libcaptive);
@@ -78,6 +80,9 @@ const char *dots[]={".","..",NULL},**csp;
                        }
 
        for (;;) {
+char *file_info_name_filename;
+int errint;
+
                G_LOCK(libcaptive);
                errvfsresult=captive_directory_read(captive_directory_object,&file_info);
                G_UNLOCK(libcaptive);
@@ -91,7 +96,12 @@ const char *dots[]={".","..",NULL},**csp;
                if (!captivefs_GnomeVFSFileInfo_to_lufs_fattr(captivefs_vfs,&fattr,&file_info))
                        goto fail_unref;
 
-               if (0>lu_cache_add2dir(ddir,file_info.name,NULL,&fattr)) {
+               file_info_name_filename=captivefs_filename_from_utf8_malloc_errorchecking(file_info.name);
+               errint=lu_cache_add2dir(ddir,
+                               (file_info_name_filename ? file_info_name_filename : file_info.name),
+                               NULL,&fattr);
+               g_free(file_info_name_filename);        /* may be NULL */
+               if (0>errint) {
                        g_warning("Failed lu_cache_add2dir() for: %s",file_info.name);
                        goto fail_unref;
                        }
@@ -128,6 +138,8 @@ GnomeVFSResult errvfsresult;
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_mkdir: dir=%s,mode=0x%X",dir,mode);
 
+       dir=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(dir);
+
        G_LOCK(libcaptive);
        errvfsresult=captive_directory_new_make(&captive_directory_object,captivefs_vfs->captive_vfs_object,dir,mode);
        G_UNLOCK(libcaptive);
@@ -155,6 +167,8 @@ GnomeVFSResult errvfsresult;
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_rmdir: dir=%s",dir);
 
+       dir=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(dir);
+
        G_LOCK(libcaptive);
        errvfsresult=captive_directory_new_open(&captive_directory_object,captivefs_vfs->captive_vfs_object,dir);
        G_UNLOCK(libcaptive);
index 611689e..87fd586 100644 (file)
@@ -36,7 +36,7 @@
 #define CLIENT_LUFS_USE_COUNT "client-lufs-use_count"
 
 
-/* map: (const gchar *) -> (CaptiveFileObject *) */
+/* map: (const gchar *utf8) -> (CaptiveFileObject *) */
 static GHashTable *FileHandle_hash;
 G_LOCK_DEFINE_STATIC(FileHandle_hash);
 
@@ -252,6 +252,8 @@ GnomeVFSFileInfo file_info;
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_stat: name=%s",name);
 
+       name=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(name);
+
        captive_file_object=FileHandle_lookup_open_enter(captivefs_vfs,name,FALSE);
        if (!captive_file_object)
                return -1;
@@ -284,6 +286,8 @@ CaptiveFileObject *captive_file_object;
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_create: file=%s,mode=0x%X",file,mode);
 
+       file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
        captive_file_object=FileHandle_lookup_open_enter(captivefs_vfs,file,TRUE);
        if (!captive_file_object)
                return -1;
@@ -307,6 +311,8 @@ CaptiveFileObject *captive_file_object;
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_unlink: file=%s",file);
 
+       file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
        captive_file_object=FileHandle_lookup_open_enter(captivefs_vfs,file,FALSE);
        if (!captive_file_object)
                return -1;
@@ -339,6 +345,9 @@ gint use_count;
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_rename: old_name=%s,new_name=%s",old_name,new_name);
 
+       old_name=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(old_name);
+       new_name=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(new_name);
+
        captive_file_object=FileHandle_lookup_open_enter(captivefs_vfs,old_name,FALSE);
        if (!captive_file_object)
                return -1;
@@ -394,6 +403,8 @@ GnomeVFSOpenMode gnome_vfs_open_mode;
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_open: file=%s,mode=0x%X",file,mode);
 
+       file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
        if (!captivefs_vfs_validate(captivefs_vfs))
                return -1;
 
@@ -429,6 +440,8 @@ CaptiveFileObject *captive_file_object;
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_release: file=%s",file);
 
+       file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
        if (!(captive_file_object=FileHandle_lookup_enter(file)))
                return -1;
 
@@ -456,6 +469,8 @@ GnomeVFSResult errvfsresult;
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_read: file=%s,offset=%" G_GINT64_FORMAT ",count=0x%lX",
                                file,(gint64)offset,count);
 
+       file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
        if (!(captive_file_object=FileHandle_lookup_enter(file)))
                return -1;
 
@@ -500,6 +515,8 @@ GnomeVFSResult errvfsresult;
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_write: file=%s,offset=%" G_GINT64_FORMAT ",count=0x%lX",
                                file,(gint64)offset,count);
 
+       file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
        if (!(captive_file_object=FileHandle_lookup_enter(file)))
                return -1;
 
@@ -543,6 +560,8 @@ CaptiveFileObject *captive_file_object;
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_setattr: file=%s",file);
 
+       file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
        if (!captivefs_lufs_fattr_to_GnomeVFSFileInfo(&file_info,fattr))
                return -1;
 
index 8eeb397..5fa7f7b 100644 (file)
@@ -75,3 +75,51 @@ int captivefs_symlink(struct captivefs_vfs *captivefs_vfs,const char *target,con
 
        return -1;      /* unsupported by W32 */
 }
+
+
+char *captivefs_filename_to_utf8_malloc_errorchecking(const char *name)
+{
+GError *error;
+char *r;
+
+       g_return_val_if_fail(name!=NULL,NULL);
+
+       error=NULL;
+       r=g_filename_to_utf8(
+                       name,   /* opsysstring */
+                       -1,     /* len; '\0'-terminated */
+                       NULL,   /* bytes_read */
+                       NULL,   /* bytes_written */
+                       &error);        /* error */
+       if (error) {
+               g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,
+                               _("captivefs %s(): name=\"%s\": %s (see locale(7) and mount(8) environment variables)"),
+                               "g_filename_to_utf8",name,error->message);
+               g_clear_error(&error);
+               }
+       return r;
+}
+
+
+char *captivefs_filename_from_utf8_malloc_errorchecking(const char *name)
+{
+GError *error;
+char *r;
+
+       g_return_val_if_fail(name!=NULL,NULL);
+
+       error=NULL;
+       r=g_filename_from_utf8(
+                       name,   /* utf8string */
+                       -1,     /* len; '\0'-terminated */
+                       NULL,   /* bytes_read */
+                       NULL,   /* bytes_written */
+                       &error);        /* error */
+       if (error) {
+               g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,
+                               _("captivefs %s(): name=\"%s\": %s (see locale(7) and mount(8) environment variables)"),
+                               "g_filename_from_utf8",name,error->message);
+               g_clear_error(&error);
+               }
+       return r;
+}
index 6665720..76691d2 100644 (file)
 
 
 #include <glib/gthread.h>
+#include <captive/macros.h>
 
 
 G_BEGIN_DECLS
 
 G_LOCK_EXTERN(libcaptive);
 
+
+char *captivefs_filename_to_utf8_malloc_errorchecking(const char *name);
+char *captivefs_filename_from_utf8_malloc_errorchecking(const char *name);
+
+#define CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(name) ({ \
+               const char *_captivefs_filename_to_utf8_alloca_name=(name); \
+               char *_captivefs_filename_to_utf8_alloca_r_malloc; \
+               const char *_captivefs_filename_to_utf8_alloca_r; \
+                \
+               _captivefs_filename_to_utf8_alloca_r_malloc=captivefs_filename_to_utf8_malloc_errorchecking( \
+                               _captivefs_filename_to_utf8_alloca_name); \
+               if (!_captivefs_filename_to_utf8_alloca_r_malloc) \
+                       _captivefs_filename_to_utf8_alloca_r=_captivefs_filename_to_utf8_alloca_name; \
+               else { \
+                       _captivefs_filename_to_utf8_alloca_r=captive_strdup_alloca(_captivefs_filename_to_utf8_alloca_r_malloc); \
+                       g_free(_captivefs_filename_to_utf8_alloca_r_malloc); \
+                       } \
+               _captivefs_filename_to_utf8_alloca_r; \
+               })
+
 G_END_DECLS
 
 
index 188442a..90c7b3a 100644 (file)
@@ -23,6 +23,7 @@
 #include <glib/gmessages.h>
 #include "captivefs-misc.h"
 #include <unistd.h>
+#include <locale.h>
 
 #include <captive/client-vfs.h>
 #include <captive/options.h>
@@ -105,6 +106,9 @@ gchar *gs,*captive_options_string;
                }
        G_UNLOCK(libcaptive);
 
+       /* Initialize i18n for proper nl_langinfo(CODESET) for _g_locale_charset_raw() for g_filename_from_utf8(). */
+       setlocale(LC_ALL,"");
+
        if (!g_thread_supported())
                g_thread_init(NULL);    /* g_thread_init() fails on second initialization */