Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / client / cmdline / main.c
index 1d3a9b3..76a5be7 100644 (file)
@@ -29,6 +29,7 @@
 #include <locale.h>
 
 #include <captive/client-vfs.h>
+#include <captive/client.h>
 
 #include "main.h"      /* self */
 #include "cmd_shell.h"
@@ -49,6 +50,7 @@
 #include "cmd_close.h"
 #include "cmd_quit.h"
 #include "cmd_help.h"
+#include "utf8.h"
 
 
 CaptiveVfsObject *cmdline_captive_vfs_object;
@@ -123,8 +125,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 +142,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 +155,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 +166,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 +194,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;
                }
 
@@ -230,8 +238,6 @@ gboolean errvfsresult_to_gerr(GError **errp,GnomeVFSResult errvfsresult)
        return FALSE;
 }
 
-static GIOChannel *main_giochannel;
-
 void main_exit(void) G_GNUC_NORETURN;
 void main_exit(void)
 {
@@ -239,10 +245,6 @@ void main_exit(void)
                g_object_unref(cmdline_captive_vfs_object);
                cmdline_captive_vfs_object=NULL;
                }
-       if (main_giochannel) {
-               g_io_channel_unref(main_giochannel);
-               main_giochannel=NULL;
-               }
        exit(EXIT_SUCCESS);
 }
 
@@ -259,17 +261,7 @@ struct captive_options options;
         * to restart failed children due to communication-failure alarms.
         */
 
-       /* Prevent output block buffering if redirecting stdout to file. */
-       setvbuf(stdout,(char *)NULL,_IONBF,0);
-       setvbuf(stderr,(char *)NULL,_IONBF,0);
-
-       /* Initialize the i18n stuff */
-       setlocale(LC_ALL,"");
-       bindtextdomain(PACKAGE,LOCALEDIR);
-       textdomain(PACKAGE);
-
-       /* Initialize GObject subsystem of GLib. */
-       g_type_init();
+       captive_standalone_init();
 
        captive_options_init(&options);
        captive_options=&options;       /* for parsing by 'CAPTIVE_POPT_INCLUDE' */