annotate bins_edit @ 10:f962189bab94

Added tag 1.1.29.e2 for changeset 0f248ad86f9f
author Peter Gervai <grin@grin.hu>
date Thu, 16 Oct 2008 00:16:50 +0200
parents 0f248ad86f9f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
1 #!/usr/bin/perl -w
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
2
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
3 # bins_edit for BINS Photo Album version 1.1.29
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
4 # Copyright (C) 2001-2004 J?r?me Sautret (Jerome@Sautret.org)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
5 #
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
6 # $Id: bins_edit,v 1.21 2004/10/24 13:19:16 jerome Exp $
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
7 #
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
8 # This program is free software; you can redistribute it and/or modify
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
9 # it under the terms of the GNU General Public License as published by
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
10 # the Free Software Foundation; either version 2 of the License, or
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
11 # (at your option) any later version.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
12 #
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
16 # GNU General Public License for more details.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
17 #
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
18 # You should have received a copy of the GNU General Public License
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
19 # along with this program; see the file COPYING. If not, write to
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
20 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
21 # Boston, MA 02111-1307, USA.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
22
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
23 # Type "bins_edit -h" on command line for usage information.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
24
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
25 use strict;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
26
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
27 use Getopt::Long;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
28 use IO::File;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
29 use UNIVERSAL qw(isa);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
30
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
31 # XML parsing & writing
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
32 use XML::Grove;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
33 use XML::Grove::Builder;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
34 use XML::Grove::Path;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
35 use XML::Grove::PerlSAX;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
36 use XML::Parser::PerlSAX;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
37 #use XML::Handler::XMLWriter;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
38 use XML::Handler::YAWriter;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
39 use Text::Iconv;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
40 use HTML::Entities;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
41
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
42 my $verbose = 1;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
43 my $html=0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
44
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
45 my $localEncoding;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
46
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
47 # decode HTML entites which doesn't exist in XML
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
48 sub decodeEntites{
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
49 my $s = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
50
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
51 my %entities = (
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
52 AElig => '?', # capital AE diphthong (ligature)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
53 Aacute => '?', # capital A, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
54 Acirc => '?', # capital A, circumflex accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
55 Agrave => '?', # capital A, grave accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
56 Aring => '?', # capital A, ring
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
57 Atilde => '?', # capital A, tilde
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
58 Auml => '?', # capital A, dieresis or umlaut mark
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
59 Ccedil => '?', # capital C, cedilla
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
60 ETH => '?', # capital Eth, Icelandic
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
61 Eacute => '?', # capital E, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
62 Ecirc => '?', # capital E, circumflex accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
63 Egrave => '?', # capital E, grave accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
64 Euml => '?', # capital E, dieresis or umlaut mark
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
65 Iacute => '?', # capital I, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
66 Icirc => '?', # capital I, circumflex accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
67 Igrave => '?', # capital I, grave accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
68 Iuml => '?', # capital I, dieresis or umlaut mark
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
69 Ntilde => '?', # capital N, tilde
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
70 Oacute => '?', # capital O, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
71 Ocirc => '?', # capital O, circumflex accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
72 Ograve => '?', # capital O, grave accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
73 Oslash => '?', # capital O, slash
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
74 Otilde => '?', # capital O, tilde
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
75 Ouml => '?', # capital O, dieresis or umlaut mark
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
76 THORN => '?', # capital THORN, Icelandic
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
77 Uacute => '?', # capital U, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
78 Ucirc => '?', # capital U, circumflex accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
79 Ugrave => '?', # capital U, grave accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
80 Uuml => '?', # capital U, dieresis or umlaut mark
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
81 Yacute => '?', # capital Y, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
82 aacute => '?', # small a, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
83 acirc => '?', # small a, circumflex accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
84 aelig => '?', # small ae diphthong (ligature)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
85 agrave => '?', # small a, grave accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
86 aring => '?', # small a, ring
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
87 atilde => '?', # small a, tilde
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
88 auml => '?', # small a, dieresis or umlaut mark
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
89 ccedil => '?', # small c, cedilla
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
90 eacute => '?', # small e, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
91 ecirc => '?', # small e, circumflex accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
92 egrave => '?', # small e, grave accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
93 eth => '?', # small eth, Icelandic
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
94 euml => '?', # small e, dieresis or umlaut mark
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
95 iacute => '?', # small i, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
96 icirc => '?', # small i, circumflex accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
97 igrave => '?', # small i, grave accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
98 iuml => '?', # small i, dieresis or umlaut mark
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
99 ntilde => '?', # small n, tilde
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
100 oacute => '?', # small o, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
101 ocirc => '?', # small o, circumflex accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
102 ograve => '?', # small o, grave accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
103 oslash => '?', # small o, slash
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
104 otilde => '?', # small o, tilde
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
105 ouml => '?', # small o, dieresis or umlaut mark
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
106 szlig => '?', # small sharp s, German (sz ligature)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
107 thorn => '?', # small thorn, Icelandic
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
108 uacute => '?', # small u, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
109 ucirc => '?', # small u, circumflex accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
110 ugrave => '?', # small u, grave accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
111 uuml => '?', # small u, dieresis or umlaut mark
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
112 yacute => '?', # small y, acute accent
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
113 yuml => '?', # small y, dieresis or umlaut mark
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
114
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
115 # Some extra Latin 1 chars that are listed in the HTML3.2 draft (21-May-96)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
116 copy => '?', # copyright sign
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
117 reg => '?', # registered sign
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
118 nbsp => "\240", # non breaking space
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
119
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
120 # Additional ISO-8859/1 entities listed in rfc1866 (section 14)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
121 iexcl => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
122 cent => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
123 pound => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
124 curren => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
125 yen => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
126 brvbar => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
127 sect => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
128 uml => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
129 ordf => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
130 laquo => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
131 'not' => '?', # not is a keyword in perl
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
132 shy => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
133 macr => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
134 deg => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
135 plusmn => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
136 sup1 => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
137 sup2 => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
138 sup3 => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
139 acute => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
140 micro => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
141 para => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
142 middot => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
143 cedil => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
144 ordm => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
145 raquo => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
146 frac14 => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
147 frac12 => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
148 frac34 => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
149 iquest => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
150 'times' => '?', # times is a keyword in perl
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
151 divide => '?',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
152 );
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
153
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
154 while (my($entity, $char) = each(%entities)) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
155 $s =~ s/\&$entity\;/$char/g;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
156 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
157 return $s;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
158 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
159
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
160 sub charac_indent{
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
161 my $n = shift(@_);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
162 my $s="\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
163 for (1..$n){
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
164 $s .= " ";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
165 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
166 return XML::Grove::Characters->new ( Data => $s );
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
167 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
168
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
169 sub setField{
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
170 my $field = shift(@_); # field to add or modify
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
171 my $value = shift(@_); # value to set to field
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
172 my $fileType = shift(@_); # type of file (iamge or album)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
173 my $document = shift(@_); # XML document as a Grove
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
174
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
175 if (! $html) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
176 $value = encode_entities($value, '\00-\31<&"');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
177 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
178
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
179 my $characters =
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
180 XML::Grove::Characters->new( Data =>
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
181 decodeEntites($value));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
182 #my $characters = XML::Grove::Characters->new ( Data => $value );
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
183
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
184 my $fieldName;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
185 my $fieldValue;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
186 foreach my $element
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
187 (@{$document->at_path('/'.$fileType.'/description')->{Contents}}) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
188 if (isa($element, 'XML::Grove::Element') && $element->{Name} eq "field") {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
189 $fieldName = $element->{Attributes}{'name'};
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
190 $fieldValue = "";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
191 if ($fieldName eq $field) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
192 print " Modifying field '$fieldName' to '$value'... "
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
193 if ($verbose >= 3);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
194 @{$element->{Contents}} = ( charac_indent(3),
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
195 $characters,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
196 charac_indent(2));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
197 print "OK.\n" if ($verbose >= 3);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
198 return;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
199 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
200 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
201 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
202
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
203 print " Adding field '$field' with value '$value'... " if ($verbose >= 2);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
204 my $element = XML::Grove::Element->new ( Name => 'field',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
205 Contents => [charac_indent(3),
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
206 $characters,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
207 charac_indent(2)],
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
208 Attributes => {"name" => $field});
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
209 push @{$document->at_path('/'.$fileType.'/description')->{Contents}},
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
210 (charac_indent(2), $element, charac_indent(1));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
211
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
212 print "OK.\n" if ($verbose >= 2);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
213 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
214
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
215 sub setFields{
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
216 my $file = shift(@_);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
217 my $fields = shift(@_);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
218 my $album = shift(@_); # type of file (0 if image or 1 if album)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
219 my $document;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
220
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
221 my $fileType;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
222 if ($album) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
223 $fileType = "album";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
224 } else{
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
225 $fileType = "image";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
226 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
227
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
228 if (-e $file) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
229 # Get XML document as a Grove
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
230 print " Reading file '$file'... " if ($verbose >= 2);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
231 my $grove_builder = XML::Grove::Builder->new;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
232 my $parser = XML::Parser::PerlSAX->new ( Handler => $grove_builder );
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
233 $document = $parser->parse ( Source => { SystemId => $file } );
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
234 print "OK.\n" if ($verbose >= 2);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
235 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
236 print " Creating file '$file'... " if ($verbose >= 2);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
237 my @elements;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
238 push @elements, (charac_indent(1),
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
239 XML::Grove::Element->new ( Name => 'description',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
240 Contents => [charac_indent(1)]),
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
241 charac_indent(1),
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
242 XML::Grove::Element->new ( Name => 'bins',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
243 Contents => [charac_indent(1)]),
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
244 );
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
245 if (!$album) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
246 push @elements, ( charac_indent(1),
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
247 XML::Grove::Element->new ( Name => 'exif',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
248 Contents =>
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
249 [charac_indent(1)]),
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
250 );
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
251 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
252 push @elements, charac_indent(0);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
253 my $element =
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
254 XML::Grove::Element->new ( Name => $fileType,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
255 Contents => \@elements);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
256 $document = XML::Grove::Document->new ( Contents => [ $element ] );
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
257 print "OK.\n" if ($verbose >= 3);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
258 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
259
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
260 my $fieldName;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
261 my $fieldValue;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
262 while ( ($fieldName, $fieldValue) = each(%$fields) ) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
263 if (defined $fieldValue) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
264 setField($fieldName, $fieldValue, $fileType, $document);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
265 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
266 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
267
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
268 print " Writing file '$file'... " if ($verbose >= 2);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
269 # Write the Grove to the desc file
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
270 my $fileHandler = new IO::File;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
271 open($fileHandler, '>', $file)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
272 or die("Cannot open file $file to write Exif tag ($!)");
6
3021deef1599 Encoding related fixes
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
273 if( $localEncoding !~ /utf-?8/i ) {
3021deef1599 Encoding related fixes
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
274 # if input is UTF-8 do not re-convert it again
3021deef1599 Encoding related fixes
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
275 binmode($fileHandler, ":utf8") if $^V ge v5.8.0;
3021deef1599 Encoding related fixes
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
276 }
0
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
277
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
278 my $my_handler = new XML::Handler::YAWriter( 'Output' => $fileHandler,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
279 # 'Escape' => {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
280 # '--' => '&mdash;',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
281 #'&' => '&amp;',
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
282 # },
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
283 'Encoding' => "UTF-8",
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
284 );
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
285 # my $my_handler = XML::Handler::XMLWriter->new( Output => $fileHandler,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
286 # Newlines => 0);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
287 $document->parse(DocumentHandler => $my_handler);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
288 close ($fileHandler) || bail ("can't close $file ($!)");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
289 print "OK.\n" if ($verbose >= 2);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
290 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
291
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
292 sub copyleft{
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
293 print "\nbins_edit for BINS Photo Album 1.1.29 (http://bins.sautret.org/)\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
294 print "Copyright ? 2001-2004 J?r?me Sautret (Jerome\@Sautret.org)\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
295 print "This is free software with ABSOLUTELY NO WARRANTY.\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
296 print "See COPYING file for details.\n\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
297 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
298
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
299 sub usage{
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
300 my $exit=shift; # should we exit after usage information ?
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
301 copyleft();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
302
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
303 print <<EoF ;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
304 bins_edit is a script to set fields in XML pictures description files for BINS.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
305
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
306 usage:
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
307 bins_edit [-a|--album] [-m|--html]
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
308 [-t|--title title] [-e|--event event] [-l|--location location]
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
309 [-p|--people people] [-y|--date date] [-d|--description description]
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
310 [--longdesc longDescription] [--shortdesc shortDesription]
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
311 [--sample pictureFileName]
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
312 [-g|--generic tag=value]
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
313 [-h|--help] [-v|--verbose] [-q|--quiet] file [files...]
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
314
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
315 EoF
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
316
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
317 if ($exit){
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
318 print "Type bins_edit --help for complete help.\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
319 exit ($exit);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
320 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
321 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
322
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
323
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
324 sub help{
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
325 usage(0);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
326 print <<EoF ;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
327 Options:
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
328 -t, --title, -e, --event event, -l, --location,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
329 -p, --people, -y, --date, -d, --description :
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
330 these switchs are used to set a value to a picture
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
331 desciption field.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
332 -t, --title, --longdesc, --shortdesc, --sample :
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
333 these switchs are used to set a value to an album
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
334 desciption field (with --album option)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
335 -a, --album : edit album description.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
336 (default is editing image description)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
337 In this case, the file parameter must be the
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
338 source directory of the album.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
339 Only the --title, --longdesc, --shortdesc and --sample
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
340 switchs have sense with this option.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
341 -m, --html : input value will be considering as HTML code, thus,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
342 no HTML encoding will be done.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
343 -v, --verbose : this switch can appear several times to increase
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
344 verbosity level.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
345 -q, --quiet : suppress output
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
346
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
347 If filenames have no .xml suffix, it is added, so you can directly give
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
348 picture names on the command line.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
349 Spaces and other special characters (even newlines) can be used in values
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
350 given as parameters as long as they are enclosed between quotes.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
351
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
352 Examples:
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
353 Set the title of the Image.jpg file to "My picture":
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
354 bins_edit -t "My picture" Image.jpg
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
355
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
356 Set the title and location of all JPEG pictures in the directory:
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
357 bins_edit --title Holiday --location Paris *.jpg
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
358
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
359 Use of HTML values:
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
360 bins_edit --html --description '<b>BINS</b> is cool' file.jpg
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
361
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
362 Set the title short description and sample image of the album
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
363 in the current directory (note the dot as final parameter):
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
364 bins_edit -a -t "My Album" --sample image.jpg --shortdesc "This is my album" .
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
365
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
366 EoF
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
367
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
368 exit 1;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
369 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
370
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
371
9
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
372 sub determine_encoding {
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
373 $localEncoding = `locale charmap`;
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
374 chomp $localEncoding;
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
375 if ($? != 0 ) {
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
376 $localEncoding = "LATIN1";
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
377 } else {
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
378 if (! $localEncoding or ($localEncoding eq "ANSI_X3.4-1968")) {
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
379 chop($localEncoding);
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
380 # ANSI is unspeakably primitive, promote it.
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
381 $localEncoding = "LATIN1";
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
382 print "Forcing encoding to $localEncoding\n" if ($verbose >=2);
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
383 }
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
384 }
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
385 my $converter = Text::Iconv->new($localEncoding, "UTF-8");
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
386 print "Using $localEncoding encoding on input\n" if ($verbose >=2);
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
387 }
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
388
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
389
0
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
390 sub main{
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
391 my %values;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
392 my $album = 0; # 1 if it a album description file
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
393
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
394
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
395 # process args
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
396 Getopt::Long::Configure("bundling");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
397 GetOptions('t|title:s' => \$values{title},
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
398 'e|event:s' => \$values{event},
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
399 'l|location:s' => \$values{location},
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
400 'p|people:s' => \$values{people},
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
401 'y|date:s' => \$values{date},
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
402 'd|description:s' => \$values{description},
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
403 'longdesc:s' => \$values{longdesc},
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
404 'shortdesc:s' => \$values{shortdesc},
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
405 'sample:s' => \$values{sampleimage},
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
406 'g|generic=s%' => \%values,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
407 'm|html' => \$html,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
408 'a|album' => \$album,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
409 'v|verbose+' => \$verbose,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
410 'q|quiet' => sub { $verbose = 0 },
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
411 'h|help' => sub { help() },
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
412 'copyright' => sub { copyleft() },
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
413 )
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
414 or usage(1);
7
69923c621cfe log verbosity
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
415
8
c28af937b9bd log verbosity fix (entr)
Peter Gervai <grin@grin.hu>
parents: 7
diff changeset
416 print "Verbosity is $verbose\n" if $verbose>1;
7
69923c621cfe log verbosity
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
417
9
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
418 &determine_encoding;
0f248ad86f9f bins_edit: try to get encoding stuff right, move it into main
Peter Gervai <grin@grin.hu>
parents: 8
diff changeset
419
0
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
420 my @files;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
421 if ($#ARGV < 0) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
422 if ($album) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
423 @files = (".");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
424 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
425 print "No files specified.\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
426 usage(1)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
427 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
428 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
429 @files = @ARGV;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
430 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
431
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
432 copyleft() if ($verbose >=2);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
433
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
434 foreach my $file (@files) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
435 if ($album) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
436 $file .= "/album.xml";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
437 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
438 if ($file !~ m/.xml$/) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
439 $file .= ".xml";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
440 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
441 print "Processing file '$file'... " if ($verbose >= 1);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
442 print "\n" if ($verbose >= 2);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
443 setFields($file, \%values, $album);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
444 print "OK.\n" if ($verbose == 1);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
445 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
446 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
447
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
448 main();