[gnome-commander/gcmd-1-3] advrename: call strftime() only if template contains % character



commit 0ccf17ec76a81cb1bc704b54c3b2026f503e8fc4
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Sat Oct 24 16:21:00 2009 +0200

    advrename: call strftime() only if template contains % character

 src/gnome-cmd-advrename-lexer.ll |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/src/gnome-cmd-advrename-lexer.ll b/src/gnome-cmd-advrename-lexer.ll
index 61db48b..0e8ef53 100644
--- a/src/gnome-cmd-advrename-lexer.ll
+++ b/src/gnome-cmd-advrename-lexer.ll
@@ -93,6 +93,7 @@ struct CHUNK
 static vector<CHUNK *> fname_template;
 
 static gboolean      fname_template_has_counters = FALSE;
+static gboolean      fname_template_has_percent = FALSE;
 
 
 inline void echo(const gchar *s, gssize length)
@@ -291,7 +292,16 @@ tag_name    {ape}|{audio}|{doc}|{exif}|{file}|{flac}|{id3}|{image}|{iptc}|{pdf}|
 
 \$\$                            echo("$",1);
 
-%[Dnt]                          echo("%",1);  ECHO;                        // substitute %[Dnt] with %%[Dnt]
+%[Dnt]                          {                                          // substitute %[Dnt] with %%[Dnt]
+                                  echo("%",1);
+                                  ECHO;
+                                  fname_template_has_percent = TRUE;
+                                }
+
+%.                              {
+                                  ECHO;
+                                  fname_template_has_percent = TRUE;
+                                }
 
 [^%$]+                          ECHO;                                      // concatenate consecutive non-[%$] chars into single TEXT chunk
 %%
@@ -331,6 +341,7 @@ void gnome_cmd_advrename_parse_template(const char *template_string, gboolean &h
 
   fname_template.clear();
   fname_template_has_counters = FALSE;
+  fname_template_has_percent = FALSE;
 
   yy_scan_string(template_string);
   yylex();
@@ -501,6 +512,9 @@ char *gnome_cmd_advrename_gen_fname (GnomeCmdFile *f, size_t new_fname_size)
 
   g_free (fname);
 
+  if (!fname_template_has_percent)
+    return g_strdup (fmt.c_str());
+
   char *new_fname = g_new (char, new_fname_size+1);
 
   if (!strftime(new_fname, new_fname_size+1, fmt.c_str(), localtime(&f->info->mtime)))      // if new_fname is not big enough...



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