--- src/terminal-screen.c.orig	Thu Nov 27 07:04:20 2003
+++ src/terminal-screen.c	Thu Nov 27 07:32:02 2003
@@ -64,6 +64,7 @@
   double font_scale;
   guint recheck_working_dir_idle;
   guint gconf_connection_id;
+  char *command_line_encoding;
 };
 
 static GList* used_ids = NULL;
@@ -367,6 +368,7 @@
   g_free (screen->priv->matched_string);
   g_strfreev (screen->priv->override_command);
   g_free (screen->priv->working_dir);
+  g_free (screen->priv->command_line_encoding);
   
   g_free (screen->priv);
   
@@ -1071,7 +1073,7 @@
   terminal_app_new_terminal (terminal_app_get (),
                              terminal_profile_get_for_new_term (screen->priv->profile),
                              NULL,
-                             FALSE, FALSE, NULL, NULL, NULL, dir, NULL, 1.0,
+                             FALSE, FALSE, NULL, NULL, NULL, NULL, dir, NULL, 1.0,
                              NULL, name, -1);
 
   g_free (name);
@@ -1088,7 +1090,7 @@
   terminal_app_new_terminal (terminal_app_get (),
                              terminal_profile_get_for_new_term (screen->priv->profile),
                              screen->priv->window,
-                             FALSE, FALSE, NULL, NULL, NULL, dir, NULL, 1.0,
+                             FALSE, FALSE, NULL, NULL, NULL, NULL, dir, NULL, 1.0,
                              NULL, NULL, -1);
 }
 
@@ -2420,4 +2422,24 @@
   XFreeFontSet (GDK_DISPLAY (), fontset);
   
   return ret;
+}
+
+void
+terminal_screen_set_command_line_encoding (TerminalScreen *screen,
+					   const char *encoding)
+{
+  g_return_if_fail (TERMINAL_IS_SCREEN (screen));
+  g_return_if_fail (encoding != NULL);
+  g_return_if_fail (screen->priv->command_line_encoding == NULL); /* can only be set once */
+
+  screen->priv->command_line_encoding = g_strdup(encoding);
+  terminal_widget_set_encoding (screen->priv->term, encoding);
+}
+
+const char *
+terminal_screen_get_command_line_encoding (TerminalScreen *screen)
+{
+  g_return_val_if_fail (TERMINAL_IS_SCREEN (screen), NULL);
+
+  return screen->priv->command_line_encoding;
 }
--- src/terminal.c.orig	Thu Nov 27 07:09:22 2003
+++ src/terminal.c	Thu Nov 27 07:21:55 2003
@@ -156,6 +156,7 @@
   OPTION_GEOMETRY,
   OPTION_DISABLE_FACTORY,
   OPTION_STARTUP_ID,
+  OPTION_ENCODING,
   OPTION_TITLE,
   OPTION_WORKING_DIRECTORY,
   OPTION_ZOOM,
@@ -301,6 +302,15 @@
     NULL
   },
   {
+    "encoding",
+    '\0',
+    POPT_ARG_STRING,
+    NULL,
+    OPTION_ENCODING,
+    N_("Set the terminal's encoding"),
+    N_("ENCODING")
+  },
+  {
     "title",
     't',
     POPT_ARG_STRING,
@@ -534,6 +544,7 @@
   char *profile;
   gboolean profile_is_id;
   char **exec_argv;
+  char *encoding;
   char *title;
   char *working_dir;
   double zoom;
@@ -564,6 +575,7 @@
   it->profile = g_strdup (profile);
   it->profile_is_id = is_id;
   it->exec_argv = NULL;
+  it->encoding = NULL;
   it->title = NULL;
   it->working_dir = NULL;
   it->zoom = 1.0;
@@ -578,6 +590,7 @@
 {
   g_free (it->profile);
   g_strfreev (it->exec_argv);
+  g_free (it->encoding);
   g_free (it->title);
   g_free (it->working_dir);
   g_free (it);
@@ -976,6 +989,29 @@
       terminal_factory_disabled = TRUE;
       break;
 
+    case OPTION_ENCODING:
+      {
+        InitialTab *it;
+            
+
+        if (arg == NULL)
+          {
+            g_printerr (_("Option \"%s\" requires an argument giving the encoding\n"), "--encoding");
+            exit (1);
+          }
+
+        it = ensure_top_tab (results);
+
+        if (it->encoding)
+          {
+            g_printerr (_("Two \"%s\" options given for one tab\n"), "--encoding");
+            exit (1);
+          }
+
+        it->encoding = g_strdup (arg);
+      }
+      break;
+
     case OPTION_TITLE:
       {
         InitialTab *it;
@@ -1341,6 +1377,7 @@
                                          iw->menubar_state,
                                          it->exec_argv,
                                          iw->geometry,
+					 it->encoding,
                                          it->title,
                                          it->working_dir,
                                          iw->role,
@@ -1360,6 +1397,7 @@
                                          FALSE, FALSE,
                                          it->exec_argv,
                                          NULL,
+					 it->encoding,
                                          it->title,
                                          it->working_dir,
                                          NULL,
@@ -1711,6 +1749,7 @@
                            gboolean         forced_menubar_state,
                            char           **override_command,
                            const char      *geometry,
+			   const char      *command_line_encoding,
                            const char      *title,
                            const char      *working_dir,
                            const char      *role,
@@ -1774,6 +1813,9 @@
   screen = terminal_screen_new ();
   
   terminal_screen_set_profile (screen, profile);
+
+  if (command_line_encoding)
+    terminal_screen_set_command_line_encoding (screen, command_line_encoding);
 
   if (title)
     terminal_screen_set_dynamic_title (screen, title);
--- src/terminal-screen.h.orig	Thu Nov 27 07:09:07 2003
+++ src/terminal-screen.h	Thu Nov 27 07:09:12 2003
@@ -104,6 +104,10 @@
                                                double          factor);
 double      terminal_screen_get_font_scale    (TerminalScreen *screen);
 
+void        terminal_screen_set_command_line_encoding (TerminalScreen *screen,
+						       const char   *encoding);
+const char *terminal_screen_get_command_line_encoding (TerminalScreen *screen);
+
 /* Allow scales a bit smaller and a bit larger than the usual pango ranges */
 #define TERMINAL_SCALE_XXX_SMALL   (PANGO_SCALE_XX_SMALL/1.2)
 #define TERMINAL_SCALE_XXXX_SMALL  (TERMINAL_SCALE_XXX_SMALL/1.2)
--- src/terminal-window.c.orig	Thu Nov 27 07:16:27 2003
+++ src/terminal-window.c	Thu Nov 27 07:44:13 2003
@@ -596,7 +596,8 @@
   GSList *tmp;
   const char *charset;
   GtkWidget *w;
-
+  const char *command_line_encoding;
+  
   if (!terminal_widget_supports_dynamic_encoding ())
     return;
   
@@ -616,9 +617,23 @@
 
   w = terminal_screen_get_widget (window->priv->active_term);
   charset = terminal_widget_get_encoding (w);
-  
+
   group = NULL;
   encodings = terminal_get_active_encodings ();
+
+  command_line_encoding = terminal_screen_get_command_line_encoding(window->priv->active_term);
+  if (command_line_encoding)
+    {
+      /* add the command line encoding to the encodings list */
+      TerminalEncoding *encoding;
+
+      encoding = g_new(TerminalEncoding, 1);
+      encoding->charset = g_strdup(command_line_encoding);
+      encoding->name = g_strdup(_("Specified on the command line"));
+
+      encodings = g_slist_append(encodings, encoding);
+    }
+  
   tmp = encodings;
   while (tmp != NULL)
     {
@@ -2183,7 +2198,7 @@
       terminal_app_new_terminal (terminal_app_get (),
                                  profile,
                                  NULL,
-                                 FALSE, FALSE, NULL, NULL, NULL, dir, NULL, 1.0,
+                                 FALSE, FALSE, NULL, NULL, NULL, NULL, dir, NULL, 1.0,
                                  NULL, name, -1);
 
       g_free (name);
@@ -2210,7 +2225,7 @@
       terminal_app_new_terminal (terminal_app_get (),
                                  profile,
                                  window,
-                                 FALSE, FALSE, NULL, NULL, NULL, dir, NULL, 1.0,
+                                 FALSE, FALSE, NULL, NULL, NULL, NULL, dir, NULL, 1.0,
                                  NULL, NULL, -1);
     }
 }
--- src/terminal.h.orig	Thu Nov 27 07:17:11 2003
+++ src/terminal.h	Thu Nov 27 07:21:30 2003
@@ -46,6 +46,7 @@
                                 gboolean         forced_menubar_state,
                                 char           **override_command,
                                 const char      *geometry,
+				const char	*command_line_encoding,
                                 const char      *title,
                                 const char      *working_dir,
                                 const char      *role,
