From: short <> Date: Sat, 13 Dec 2003 21:20:05 +0000 (+0000) Subject: +Unicode/UTF8 locale conversion support for 'G_BROKEN_FILENAMES' etc. X-Git-Tag: captive-1_1_4~5 X-Git-Url: http://git.jankratochvil.net/?p=captive.git;a=commitdiff_plain;h=80c78e769cb7c64e56378b53b04174bf47e284fa +Unicode/UTF8 locale conversion support for 'G_BROKEN_FILENAMES' etc. --- diff --git a/src/client/cmdline/Makefile.am b/src/client/cmdline/Makefile.am index 236b4ab..b456c70 100644 --- a/src/client/cmdline/Makefile.am +++ b/src/client/cmdline/Makefile.am @@ -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) diff --git a/src/client/cmdline/cmd_cd.c b/src/client/cmdline/cmd_cd.c index 2b0c762..84bb8e7 100644 --- a/src/client/cmdline/cmd_cd.c +++ b/src/client/cmdline/cmd_cd.c @@ -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; } diff --git a/src/client/cmdline/cmd_create.c b/src/client/cmdline/cmd_create.c index 98c2c85..ceef1f3 100644 --- a/src/client/cmdline/cmd_create.c +++ b/src/client/cmdline/cmd_create.c @@ -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; } diff --git a/src/client/cmdline/cmd_get.c b/src/client/cmdline/cmd_get.c index c852b22..87daf72 100644 --- a/src/client/cmdline/cmd_get.c +++ b/src/client/cmdline/cmd_get.c @@ -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)); } } diff --git a/src/client/cmdline/cmd_info.c b/src/client/cmdline/cmd_info.c index edc4f8d..f937429 100644 --- a/src/client/cmdline/cmd_info.c +++ b/src/client/cmdline/cmd_info.c @@ -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); diff --git a/src/client/cmdline/cmd_lcd.c b/src/client/cmdline/cmd_lcd.c index b2f1c8d..c1825b7 100644 --- a/src/client/cmdline/cmd_lcd.c +++ b/src/client/cmdline/cmd_lcd.c @@ -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); } diff --git a/src/client/cmdline/cmd_ls.c b/src/client/cmdline/cmd_ls.c index e594629..c87999c 100644 --- a/src/client/cmdline/cmd_ls.c +++ b/src/client/cmdline/cmd_ls.c @@ -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; } diff --git a/src/client/cmdline/cmd_mkdir.c b/src/client/cmdline/cmd_mkdir.c index 1a6c4f3..2ddb495 100644 --- a/src/client/cmdline/cmd_mkdir.c +++ b/src/client/cmdline/cmd_mkdir.c @@ -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; } diff --git a/src/client/cmdline/cmd_mv.c b/src/client/cmdline/cmd_mv.c index 7ccfdae..21f77c0 100644 --- a/src/client/cmdline/cmd_mv.c +++ b/src/client/cmdline/cmd_mv.c @@ -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; } diff --git a/src/client/cmdline/cmd_open.c b/src/client/cmdline/cmd_open.c index f058c7d..0220b93 100644 --- a/src/client/cmdline/cmd_open.c +++ b/src/client/cmdline/cmd_open.c @@ -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; } diff --git a/src/client/cmdline/cmd_put.c b/src/client/cmdline/cmd_put.c index 479c73d..910eb15 100644 --- a/src/client/cmdline/cmd_put.c +++ b/src/client/cmdline/cmd_put.c @@ -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)); } } diff --git a/src/client/cmdline/cmd_rm.c b/src/client/cmdline/cmd_rm.c index bf7e847..1c9e5ba 100644 --- a/src/client/cmdline/cmd_rm.c +++ b/src/client/cmdline/cmd_rm.c @@ -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; } diff --git a/src/client/cmdline/cmd_rmdir.c b/src/client/cmdline/cmd_rmdir.c index 5084e50..be2b8ca 100644 --- a/src/client/cmdline/cmd_rmdir.c +++ b/src/client/cmdline/cmd_rmdir.c @@ -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; } diff --git a/src/client/cmdline/file_info.c b/src/client/cmdline/file_info.c index 23b0cd4..eab9d62 100644 --- a/src/client/cmdline/file_info.c +++ b/src/client/cmdline/file_info.c @@ -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) { diff --git a/src/client/cmdline/handle.c b/src/client/cmdline/handle.c index d144009..6e7b7d7 100644 --- a/src/client/cmdline/handle.c +++ b/src/client/cmdline/handle.c @@ -24,6 +24,7 @@ #include #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; } diff --git a/src/client/cmdline/main.c b/src/client/cmdline/main.c index c6b263b..2bf5bd0 100644 --- a/src/client/cmdline/main.c +++ b/src/client/cmdline/main.c @@ -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;argciname;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_argcargsn_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 index 0000000..40a5ce0 --- /dev/null +++ b/src/client/cmdline/utf8.c @@ -0,0 +1,52 @@ +/* $Id$ + * client cmdline interface GnomeVFSFileInfo utils for libcaptive + * Copyright (C) 2003 Jan Kratochvil + * + * 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 +#include + + +#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 index 0000000..4042653 --- /dev/null +++ b/src/client/cmdline/utf8.h @@ -0,0 +1,58 @@ +/* $Id$ + * Include file for client cmdline interface GnomeVFSFileInfo utils for libcaptive + * Copyright (C) 2003 Jan Kratochvil + * + * 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 +#include +#include + + +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 */ diff --git a/src/client/lufs/captivefs-directory.c b/src/client/lufs/captivefs-directory.c index 692790f..c0d30a8 100644 --- a/src/client/lufs/captivefs-directory.c +++ b/src/client/lufs/captivefs-directory.c @@ -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); diff --git a/src/client/lufs/captivefs-file.c b/src/client/lufs/captivefs-file.c index 611689e..87fd586 100644 --- a/src/client/lufs/captivefs-file.c +++ b/src/client/lufs/captivefs-file.c @@ -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; diff --git a/src/client/lufs/captivefs-misc.c b/src/client/lufs/captivefs-misc.c index 8eeb397..5fa7f7b 100644 --- a/src/client/lufs/captivefs-misc.c +++ b/src/client/lufs/captivefs-misc.c @@ -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; +} diff --git a/src/client/lufs/captivefs-misc.h b/src/client/lufs/captivefs-misc.h index 6665720..76691d2 100644 --- a/src/client/lufs/captivefs-misc.h +++ b/src/client/lufs/captivefs-misc.h @@ -22,12 +22,33 @@ #include +#include 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 diff --git a/src/client/lufs/captivefs-vfs.c b/src/client/lufs/captivefs-vfs.c index 188442a..90c7b3a 100644 --- a/src/client/lufs/captivefs-vfs.c +++ b/src/client/lufs/captivefs-vfs.c @@ -23,6 +23,7 @@ #include #include "captivefs-misc.h" #include +#include #include #include @@ -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 */