[Xfce4-commits] <libxfce4util:master> Fix some issues in the previous commit.

Nick Schermer noreply at xfce.org
Wed Oct 27 23:52:01 CEST 2010


Updating branch refs/heads/master
         to 1b60b746e0d9d4ff80213cd9544b1447c69cb11c (commit)
       from 961df68e955f4ca185cd886d12b0e617a1f0fd3b (commit)

commit 1b60b746e0d9d4ff80213cd9544b1447c69cb11c
Author: Nick Schermer <nick at xfce.org>
Date:   Wed Oct 27 23:48:02 2010 +0200

    Fix some issues in the previous commit.
    
    When a valid variable name is not found in the buffer, replace
    it with nothing so the behavious is the same as the old implementation.
    
    Allow multiple variable put together like $HOME$HOME$HOME.

 libxfce4util/xfce-miscutils.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/libxfce4util/xfce-miscutils.c b/libxfce4util/xfce-miscutils.c
index fd9bec8..b568ea1 100644
--- a/libxfce4util/xfce-miscutils.c
+++ b/libxfce4util/xfce-miscutils.c
@@ -546,6 +546,8 @@ xfce_expand_variables (const gchar *command,
 
   for (p = command; *p != '\0'; ++p)
     {
+      continue_without_increase:
+
       if (*p == '~'
           && (p == command
               || xfce_is_valid_tilde_prefix (p - 1)))
@@ -573,6 +575,9 @@ xfce_expand_variables (const gchar *command,
 #endif
                 buf = g_string_append_len (buf, start - 1, p - start + 1);
             }
+
+          /* we are either at the end of the string or *p is a separator,
+           * so continue to add it to the result buffer */
         }
       else if (*p == '$')
         {
@@ -611,14 +616,19 @@ xfce_expand_variables (const gchar *command,
                 }
               else
                 {
-                  /* unable the parse the string, reset and continue
-                   * adding the characters */
-                  p = start - 1;
+                  /* the variable name was valid, but no value was
+                   * found, insert nothing and continue */
                 }
+
+              /* *p is at the start of the charater after the variable,
+               * so continue scanning without advancing the string offset
+               * so two variables are replaced properly */
+              goto continue_without_increase;
             }
           else
             {
-              /* add the $ character and continue */
+              /* invalid variable format, add the
+               * $ character and continue */
               --p;
             }
         }



More information about the Xfce4-commits mailing list