[gnome-commander/gcmd-1-2-8] Fixed problem #541891 (file names with % in advanced file rename tool)



commit 174a9c319ea5fb5a2597a4974d1141b4c80b7dfc
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Mon Oct 26 19:59:11 2009 +0100

    Fixed problem #541891 (file names with % in advanced file rename tool)

 NEWS                             |    1 +
 doc/C/gnome-commander.xml        |    3 +++
 src/gnome-cmd-advrename-lexer.ll |   29 +++++++++++++++++++++++++++--
 3 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index 59725dc..595a3de 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ gnome-commander 1.2.8.3
 ---------------
 
 Bug fixes:
+ * Fixed problem #541891 (file names with % in advanced file rename tool)
  * Fixed problem #581645 (uncomfortable quick search)
  * Fixed problem #596768 (build warnings for python)
  * Fixed problem #596973 (documentation build error)
diff --git a/doc/C/gnome-commander.xml b/doc/C/gnome-commander.xml
index 9f767aa..8358f35 100644
--- a/doc/C/gnome-commander.xml
+++ b/doc/C/gnome-commander.xml
@@ -6025,6 +6025,9 @@
                 <para>
                     <itemizedlist>
                         <listitem>
+                            <para>Fixed problem #541891 (file names with % in advanced file rename tool)</para>
+                        </listitem>
+                        <listitem>
                             <para>Fixed problem #581645 (uncomfortable quick search)</para>
                         </listitem>
                         <listitem>
diff --git a/src/gnome-cmd-advrename-lexer.ll b/src/gnome-cmd-advrename-lexer.ll
index 6291cc6..2a9b2f7 100644
--- a/src/gnome-cmd-advrename-lexer.ll
+++ b/src/gnome-cmd-advrename-lexer.ll
@@ -95,6 +95,10 @@ static vector<CHUNK *> fname_template;
 static gboolean      fname_template_has_counters = FALSE;
 static gboolean      fname_template_has_percent = FALSE;
 
+#define    SUB_S "\x1A"
+const char SUB = '\x1A';
+const char ESC = '\x1B';
+
 
 inline void echo(const gchar *s, gssize length)
 {
@@ -293,12 +297,12 @@ tag_name    {ape}|{audio}|{doc}|{exif}|{file}|{flac}|{id3}|{image}|{iptc}|{pdf}|
 \$\$                            echo("$",1);
 
 %[Dnt]                          {                                          // substitute %[Dnt] with %%[Dnt]
-                                  yytext[1] = '%';
-                                  ECHO;
+                                  echo(SUB_S SUB_S,2);
                                   fname_template_has_percent = TRUE;
                                 }
 
 %.                              {
+                                  *yytext = SUB;
                                   ECHO;
                                   fname_template_has_percent = TRUE;
                                 }
@@ -419,6 +423,21 @@ inline void find_dirs (const gchar *path, const gchar *&parent_dir, const gchar
 }
 
 
+inline gboolean convert (char *s, char from, char to)
+{
+  gboolean retval = FALSE;
+
+  for (; *s; ++s)
+    if (*s==from)
+    {
+      *s = to;
+      retval = TRUE;
+    }
+
+  return retval;
+}
+
+
 char *gnome_cmd_advrename_gen_fname (GnomeCmdFile *f, size_t new_fname_size)
 {
   if (fname_template.empty())
@@ -517,8 +536,14 @@ char *gnome_cmd_advrename_gen_fname (GnomeCmdFile *f, size_t new_fname_size)
 
   char *new_fname = g_new (char, new_fname_size+1);
 
+  gboolean new_fname_has_percent = convert ((char *) fmt.c_str(), '%', ESC);
+  convert ((char *) fmt.c_str(), SUB, '%');
+
   if (!strftime(new_fname, new_fname_size+1, fmt.c_str(), localtime(&f->info->mtime)))      // if new_fname is not big enough...
     new_fname[new_fname_size] = '\0';                                                       //      ... truncate
 
+  if (new_fname_has_percent)
+    convert (new_fname, ESC, '%');
+
   return new_fname;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]