[gnome-commander] Fixed problem #541891 (file names with % in advanced file rename tool)



commit 0c6f72b1d6faa815610000f3b1f76cbed822ea53
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Mon Oct 26 19:47:36 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 |   30 ++++++++++++++++++++++++++++--
 3 files changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index 05f1428..724d316 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,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 b1e58e7..4fb61f0 100644
--- a/doc/C/gnome-commander.xml
+++ b/doc/C/gnome-commander.xml
@@ -6018,6 +6018,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 676e071..aa72b6f 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,13 @@ tag_name    {ape}|{audio}|{doc}|{exif}|{file}|{flac}|{id3}|{image}|{iptc}|{pdf}|
 \$\$                            echo("$",1);
 
 %[Dnt]                          {                                          // substitute %[Dnt] with %%[Dnt]
-                                  echo("%",1);
-                                  ECHO;
+                                  echo(SUB_S SUB_S,2);
+                                  echo(yytext+1,1);
                                   fname_template_has_percent = TRUE;
                                 }
 
 %.                              {
+                                  *yytext = SUB;
                                   ECHO;
                                   fname_template_has_percent = TRUE;
                                 }
@@ -419,6 +424,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 +537,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]