summaryrefslogtreecommitdiffabout
authorAndy Shevchenko <andy@smile.org.ua>2006-09-02 18:53:16 (GMT)
committer Andy Shevchenko <andy@smile.org.ua>2006-09-02 18:53:16 (GMT)
commitd47ef491bc21b75f0b55bb190945929001f95cfd (patch) (side-by-side diff)
tree437b9971a2c8c0ba4a56954e1b1aff07ae10cc51
parent165a725a6cf238b9bf25e858a1c2af566e7c9655 (diff)
downloadrenrot-d47ef491bc21b75f0b55bb190945929001f95cfd.tar.gz
renrot-d47ef491bc21b75f0b55bb190945929001f95cfd.tar.bz2
Optimize hash parser.
Spelling fix. Add 'tag' target to Makefile. git-svn-id: file:///svnroot/renrot/branches/RENROT_STABLE@254 fe2816f4-e837-0410-b10a-f608c9d244a1
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ChangeLog6
-rw-r--r--Makefile.PL4
-rwxr-xr-xrenrot96
3 files changed, 47 insertions, 59 deletions
diff --git a/ChangeLog b/ChangeLog
index 97b215c..7343c30 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
$Log$
+Revision 1.148.2.5 2006/09/02 18:53:16 andy
+Optimize hash parser.
+Spelling fix.
+Add 'tag' target to Makefile.
+
Revision 1.148.2.4 2006/08/22 07:18:22 andy
The colorization for output has been implemented, the options --use-color and
--color were added.
@@ -609,4 +614,3 @@ Id keyword is added to renrot file.
Revision 1.1 2005/10/17 13:39:38 zeus
ChangeLog file is added. Its the very begining.
-
diff --git a/Makefile.PL b/Makefile.PL
index 9b83ebe..4579c16 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -19,6 +19,10 @@ sub postamble {
rpm : tardist
rpmbuild -ta $(DISTVNAME).tar.$(SUFFIX)
$(RM_F) $(DISTVNAME).tar.$(SUFFIX)
+
+# CVS tagging
+tag :
+ cvs tag "renrot_$(shell date +'%Y%m%d%H%M%S')"
END
return $postamble;
}
diff --git a/renrot b/renrot
index 7307d3d..83416a4 100755
--- a/renrot
+++ b/renrot
@@ -191,12 +191,12 @@ my @multOpts = (
# Colors hash
#
my %colors = (
- debug => 'green',
- error => 'magenta',
- fatal => 'red',
- info => 'bold',
- process => 'white',
- warning => 'cyan',
+ debug => {value => 'green'},
+ error => {value => 'magenta'},
+ fatal => {value => 'red'},
+ info => {value => 'bold'},
+ process => {value => 'white'},
+ warning => {value => 'cyan'},
);
# Prints colored message to STDERR
@@ -205,7 +205,7 @@ sub printColored {
if (defined $useColor and $useColor != 0) {
if (defined $facility and defined $colors{$facility}) {
- print STDERR colored [$colors{$facility}], @_;
+ print STDERR colored [$colors{$facility}{value}], @_;
return;
}
}
@@ -216,10 +216,10 @@ sub printColored {
# processing message
sub procmsg {
return if ($quiet != 0);
-
+
if (defined $useColor and $useColor != 0) {
if (defined $colors{'process'}) {
- print colored [$colors{'process'}], @_;
+ print colored [$colors{'process'}{value}], @_;
return;
}
}
@@ -397,7 +397,7 @@ sub getOptions {
# Convert multiple color parameters to colors hash
foreach my $colorStr (@tmpColors) {
- my %color = colorParser($colorStr);
+ my %color = strToHash($colorStr, 'reset');
foreach my $key (keys %color) {
$colorsFromCli{$key} = $color{$key};
}
@@ -405,7 +405,7 @@ sub getOptions {
# Convert multiple tag parameters to tags hash
foreach my $tagStr (@tmpTags) {
- my %tag = tagParser($tagStr);
+ my %tag = strToHash($tagStr);
foreach my $key (keys %tag) {
$tagsFromCli{$key} = $tag{$key};
}
@@ -427,60 +427,42 @@ sub trimValue {
# parsePair() gets (key, value) pair from the string like [multiword] key = "value"
#
sub parsePair {
- my $value = shift;
- my ($key, $val) = (undef, undef);
- if ($value =~ m/^([^=]+)=(.+)/) {
- ($key, $val) = (trimValue($1), trimValue($2));
- $val =~ s/^[\'\"](.+)[\'\"]/$1/; # trim quotes
- dbgmsg (4, "parsePair(): Parsed: '$key' <- '$val'\n");
- } elsif ($value =~ m/^([^=]+)=$/) {
+ my $str = shift;
+ my ($key, $value) = (undef, shift);
+ if ($str =~ m/^([^=]+)=(.+)/) {
+ ($key, $value) = (trimValue($1), trimValue($2));
+ $value =~ s/^[\'\"](.+)[\'\"]/$1/; # trim quotes
+ dbgmsg (4, "parsePair(): Parsed: '$key' <- '$value'\n");
+ } elsif ($str =~ m/^([^=]+)=$/) {
$key = trimValue($1);
- dbgmsg (4, "parsePair(): Parsed empty '$key'\n");
+ dbgmsg (4, "parsePair(): Parsed empty '$key', applying default value: ", defined $value ? "'$value'" : "undef", "\n");
}
- return ($key, $val);
+ return ($key, $value);
}
########################################################################################
#
-# tagParser() parses given string to a tag hash
+# strToHash() parses given string to a hash
#
-sub tagParser {
- my $tagStr = shift;
- my %tag;
- $tagStr =~ s/:/=/; # change first ':' to '='
- my ($key, $value) = parsePair($tagStr);
+sub strToHash {
+ my $str = shift;
+ my $default = shift;
+ my %hash;
+ $str =~ s/:/=/; # change first entrance of ':' to '='
+ my ($key, $value) = parsePair($str, $default);
if (defined $key) {
$key =~ s/\s*[\(\[]([^\(\)\[\]]*)[\)\]]$//;
my $group = (defined $1 and $1 ne "") ? $1 : undef;
- $tag{$key} = {value => $value, group => $group};
+ $hash{$key} = {value => $value, group => $group};
+
# Print debug message
$value = "" if (not defined $value);
$group = "" if (not defined $group);
- dbgmsg (4, "tagParser(): Parsed: $key [$group] = '$value'\n");
- } else {
- warnmsg ("Invalid tag format: $tagStr\n");
- }
- return %tag;
-}
-
-########################################################################################
-#
-# colorParser() parses given string to a color hash
-#
-sub colorParser {
- my $colorStr = shift;
- my %color;
- $colorStr =~ s/:/=/; # change first ':' to '='
- my ($key, $value) = parsePair($colorStr);
- if (defined $key) {
- $color{$key} = $value;
- # Print debug message
- $value = 'reset' if (not defined $value);
- dbgmsg (4, "colorParser(): Parsed: $key = '$value'\n");
+ dbgmsg (4, "strToHash(): Parsed: $key [$group] = '$value'\n");
} else {
- warnmsg ("Invalid color format: $colorStr\n");
+ warnmsg ("Invalid line format: $str\n");
}
- return %color;
+ return %hash;
}
########################################################################################
@@ -616,16 +598,14 @@ sub switchColor {
# Parse configuration file color set
foreach my $cKey (keys %configOptions) {
next if ($cKey !~ m/^color#\d+#\d+$/); # skip not a color
- my %color = colorParser($configOptions{$cKey});
+ my %color = strToHash($configOptions{$cKey}, 'reset');
foreach my $key (keys %color) {
$colors{$key} = $color{$key};
}
}
# Merge colors from configuration file with command line arguments
- foreach my $key (keys %colorsFromCli) {
- $colors{$key} = $colorsFromCli{$key};
- }
+ map { $colors{$_} = $colorsFromCli{$_} } keys %colorsFromCli;
}
########################################################################################
@@ -715,7 +695,7 @@ if (scalar(@filenames) == 0) {
# Parse configuration file tag set
foreach my $cKey (keys %configOptions) {
next if ($cKey !~ m/^tag(file)?#\d+#\d+$/); # skip not a tag or tagfile
- my %tag = tagParser($configOptions{$cKey});
+ my %tag = strToHash($configOptions{$cKey});
foreach my $key (keys %tag) {
$tags{$key} = $tag{$key};
if ($cKey =~ m/^tagfile/) {
@@ -835,7 +815,7 @@ sub renRotProcess {
# analyzing whether and how to rename file
$newFileName = renameFile($exifTool, $info, $file, $fileCounter);
- # Writting tags.
+ # Writing tags.
tagWriter($exifTool, $newFileName) if ($noTags == 0);
# seting mtime for the file if been asked for
@@ -1015,7 +995,7 @@ sub tagWriter {
# writing the changes to the EXIFs
if ($dryRun == 0) { exifWriter($exifToolObj, $file); }
- else { procmsg ("Writting user defined EXIF tags to $file.\n"); }
+ else { procmsg ("Writing user defined EXIF tags to $file.\n"); }
}
########################################################################################
@@ -1314,7 +1294,7 @@ sub rotateThumbnail {
}
my $origThumb = ${$$infoObj{ThumbnailImage}};
-
+
if ($configOptions{'use ipc'} == 0) {
# extracting the thumbnail image
my $ThumbnailOriginal = $file . "_thumborig";

Return to:

Send suggestions and report system problems to the System administrator.