annotate bins_edit @ 2:c44d020e5f8a 1.1.29-extended

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