[gnome-commander/gcmd-1-2-8] advrename: call strftime() only if template contains % character
- From: Piotr Eljasiak <epiotr src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-commander/gcmd-1-2-8] advrename: call strftime() only if template contains % character
- Date: Sat, 24 Oct 2009 21:34:37 +0000 (UTC)
commit 3b2771a570a4faa41c568c67238b531b1aab6e42
Author: Piotr Eljasiak <epiotr src gnome org>
Date: Sat Oct 24 23:33:20 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 ac08f1b..6291cc6 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] yytext[1] = '%'; ECHO;
+%[Dnt] { // substitute %[Dnt] with %%[Dnt]
+ yytext[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]