repo: rxvt-unicode-sixel
action: commit
revision: 
path_from: 
revision_from: 035daeffa80ecb7be78a3e3cd5e19ce18a6bafa1:
path_to: 
revision_to: 
git.thebackupbox.net
rxvt-unicode-sixel
git clone git://git.thebackupbox.net/rxvt-unicode-sixel
commit 035daeffa80ecb7be78a3e3cd5e19ce18a6bafa1
Author: Marc Lehmann 
Date:   Sat Dec 17 23:17:33 2011 +0000

    hopefully clearer handling of argv/envv

diff --git a/src/init.C b/src/init.C
index a5a1b7e7bdd08b809c906ff0015730e0a7c6f1a9..
index ..fa8ebabd8ee1bc66d11f9f3d31240885ccfa1b39 100644
--- a/src/init.C
+++ b/src/init.C
@@ -749,7 +749,38 @@ rxvt_term::init_resources (int argc, const char *const *argv)

 /*----------------------------------------------------------------------*/
 void
-rxvt_term::init (int argc, const char *const *argv)
+rxvt_term::init (stringvec *argv, stringvec *envv)
+{
+  argv->push_back (0);
+  envv->push_back (0);
+
+  this->argv = argv;
+  this->envv = envv;
+
+  init2 (argv->size () - 1, argv->begin ());
+}
+
+void
+rxvt_term::init (int argc, const char *const *argv, const char *const *envv)
+{
+#if ENABLE_PERL
+  // perl might want to access the stringvecs later, so we need to copy them
+  stringvec *args = new stringvec;
+  for (int i = 0; i < argc; i++)
+    args->push_back (strdup (argv [i]));
+
+  stringvec *envs = new stringvec;
+  for (const char *const *var = envv; *var; var++)
+    envs->push_back (strdup (*var));
+
+  init (args, envs);
+#else
+  init2 (argc, argv);
+#endif
+}
+
+void
+rxvt_term::init2 (int argc, const char *const *argv)
 {
   SET_R (this);
   set_locale ("");
@@ -826,11 +857,9 @@ rxvt_term::init (int argc, const char *const *argv)

 #ifdef BG_IMAGE_FROM_FILE
     if (rs[Rs_backgroundPixmap])
-      {
-        if (bg_set_file (rs[Rs_backgroundPixmap]))
-          if (!bg_window_position_sensitive ())
-            update_background ();
-      }
+      if (bg_set_file (rs[Rs_backgroundPixmap]))
+        if (!bg_window_position_sensitive ())
+          update_background ();
 #endif
   }
 #endif
@@ -962,10 +991,6 @@ rxvt_term::init_env ()
 }

 /*----------------------------------------------------------------------*/
-/*
- * This is more or less stolen straight from XFree86 xterm.
- * This should support all European type languages.
- */
 void
 rxvt_term::set_locale (const char *locale)
 {
@@ -995,13 +1020,12 @@ rxvt_term::set_locale (const char *locale)
 #endif

 #if HAVE_NL_LANGINFO
-  char *codeset = strdup (nl_langinfo (CODESET));
+  char *codeset = nl_langinfo (CODESET);
   // /^UTF.?8/i
   enc_utf8 = (codeset[0] == 'U' || codeset[0] == 'u')
           && (codeset[1] == 'T' || codeset[1] == 't')
           && (codeset[2] == 'F' || codeset[2] == 'f')
           && (codeset[3] == '8' || codeset[4] == '8');
-  free (codeset);
 #else
   enc_utf8 = 0;
 #endif
@@ -1014,14 +1038,14 @@ rxvt_term::init_xlocale ()

 #ifdef USE_XIM
   if (!locale)
-    rxvt_warn ("setting locale failed, working without locale support.\n");
+    rxvt_warn ("setting locale failed, continuing without locale support.\n");
   else
     {
       set_string_property (xa[XA_WM_LOCALE_NAME], locale);

       if (!XSupportsLocale ())
         {
-          rxvt_warn ("the locale is not supported by Xlib, working without locale support.\n");
+          rxvt_warn ("the locale is not supported by Xlib, continuing without locale support.\n");
           return;
         }

diff --git a/src/main.C b/src/main.C
index 36d631536872cb78128884a71980d4e59e7ce43f..
index ..332b76e4f51a4abfe2341bd3c1cc81e3fac86d15 100644
--- a/src/main.C
+++ b/src/main.C
@@ -199,8 +199,6 @@ rxvt_term::rxvt_term ()
 #ifdef KEYSYM_RESOURCE
   keyboard = new keyboard_manager;
 #endif
-
-  // this->envv = 0;
 }

 // clean up the most important stuff, do *not* call x or free mem etc.
diff --git a/src/rxvt.C b/src/rxvt.C
index 85a4b99e0bc64f1c9c24a234f37c769abd4d3828..
index ..a7bb52eb8a5bcb0908fb47ef71bf03d0c898727a 100644
--- a/src/rxvt.C
+++ b/src/rxvt.C
@@ -27,29 +27,14 @@
 #include 

 int
-main (int argc, const char *const *argv)
+main (int argc, char *argv[])
 try
   {
     ptytty::init ();
     rxvt_init ();

     rxvt_term *t = new rxvt_term;
-
-#if ENABLE_PERL
-    stringvec *args = new stringvec;
-    stringvec *envv = new stringvec;
-
-    for (int i = 0; i < argc; i++)
-      args->push_back (strdup (argv [i]));
-
-    for (char **var = environ; *var; var++)
-      envv->push_back (strdup (*var));
-
-    t->init (args, envv);
-#else
-    t->init (argc, argv);
-#endif
-
+    t->init (argc, argv, environ);
     ev_run ();

     return EXIT_SUCCESS;
diff --git a/src/rxvt.h b/src/rxvt.h
index 3350e8a8ff8608a6ed19a17b620b3ce3c94e12cb..
index ..1a4403ef5e941ff91f2cfe846d1c0bbffe3e060c 100644
--- a/src/rxvt.h
+++ b/src/rxvt.h
@@ -1318,15 +1318,6 @@ struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen
   void tt_write (const char *data, unsigned int len);
   void pty_write ();

-  void init (stringvec *argv, stringvec *envv)
-  {
-    this->argv = argv;
-    this->envv = envv;
-    argv->push_back (0);
-    envv->push_back (0);
-    init (argv->size () - 1, argv->begin ());
-  }
-
   void make_current () const // make this the "currently active" urxvt instance
   {
     SET_R (this);
@@ -1393,9 +1384,11 @@ struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen
   void process_terminal_mode (int mode, int priv, unsigned int nargs, const int *arg);
   void process_sgr_mode (unsigned int nargs, const int *arg);
   // init.C
+  void init (stringvec *argv, stringvec *envv);
+  void init (int argc, const char *const *argv, const char *const *envv);
+  void init2 (int argc, const char *const *argv);
   void init_vars ();
   const char **init_resources (int argc, const char *const *argv);
-  void init (int argc, const char *const *argv);
   void init_env ();
   void set_locale (const char *locale);
   void init_xlocale ();
diff --git a/src/rxvtd.C b/src/rxvtd.C
index bc31c6f18ed76678f10ba7cc5913b38f65e9c5c5..
index ..4dd81b304700447cc94b4fc963760579cf93058d 100644
--- a/src/rxvtd.C
+++ b/src/rxvtd.C
@@ -223,7 +223,7 @@ void server::read_cb (ev::io &w, int revents)
 }

 int
-main (int argc, const char *const *argv)
+main (int argc, char *argv[])
 {
   ptytty::init ();

diff --git a/src/rxvtperl.xs b/src/rxvtperl.xs
index b1029af78245e7ec1fd1ab80b1f71b4d5ca3cb74..
index ..f2d4b50c02cfe523b96dc362efbb07d8b9219c47 100644
--- a/src/rxvtperl.xs
+++ b/src/rxvtperl.xs
@@ -922,11 +922,10 @@ _new (AV *env, AV *arg)
         rxvt_term *term = new rxvt_term;

 	stringvec *argv = new stringvec;
-	stringvec *envv = new stringvec;
-
         for (int i = 0; i <= AvFILL (arg); i++)
           argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));

+	stringvec *envv = new stringvec;
         for (int i = AvFILL (env) + 1; i--; )
           envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));

-----END OF PAGE-----