Initial commit
[platform/upstream/ccid.git] / src / create_Info_plist.pl
1 #!/usr/bin/env perl
2
3 #    create_Info_plist.pl: generate Info.plist from a template and a
4 #    list of supported readers
5 #
6 #    Copyright (C) 2004-2009  Ludovic Rousseau  <ludovic.rousseau@free.fr>
7 #
8 #    This program is free software; you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation; either version 2 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program; if not, write to the Free Software
20 #    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #    02110-1301 USA.
22
23 use warnings;
24 use strict;
25 use Getopt::Long;
26
27 my (@manuf, @product, @name);
28 my ($manuf, $product, $name);
29 my $target = "libccid.so";
30 my $version = "1.0.0";
31 my $class = "<key>CFBundleName</key>
32         <string>CCIDCLASSDRIVER</string>";
33 my $noclass = 0;
34
35 GetOptions(
36         "target=s" => \$target,
37         "version=s" => \$version,
38         "no-class" => \$noclass);
39
40 if ($#ARGV < 1)
41 {
42         print "usage: $0 supported_readers.txt Info.plist
43         --target=$target
44         --version=$version\n";
45         exit;
46 }
47
48 open IN, "< $ARGV[0]" or die "Can't open $ARGV[0]: $!";
49 while (<IN>)
50 {
51         next if (m/^#/);
52         next if (m/^$/);
53
54         chomp;
55         ($manuf, $product, $name) = split /:/;
56         # print "m: $manuf, p: $product, n: $name\n";
57         push @manuf, $manuf;
58         push @product, $product;
59         $name =~ s/&/&amp;/g;
60         push @name, $name
61 }
62 close IN;
63
64 map { $_ = "\t\t<string>$_</string>\n" } @manuf;
65 map { $_ = "\t\t<string>$_</string>\n" } @product;
66 map { $_ = "\t\t<string>$_</string>\n" } @name;
67
68 open IN, "< $ARGV[1]" or die "Can't open $ARGV[1]: $!";
69
70 while (<IN>)
71 {
72         if (m/MAGIC_VENDOR/)
73         {
74                 print @manuf;
75                 next;
76         }
77         if (m/MAGIC_PRODUCT/)
78         {
79                 print @product;
80                 next;
81         }
82         if (m/MAGIC_FRIENDLYNAME/)
83         {
84                 print @name;
85                 next;
86         }
87         if (m/MAGIC_TARGET/)
88         {
89                 s/MAGIC_TARGET/$target/;
90                 print;
91                 next;
92         }
93         if (m/MAGIC_VERSION/)
94         {
95                 s/MAGIC_VERSION/$version/;
96                 print;
97                 next;
98         }
99         if (m/MAGIC_CLASS/)
100         {
101                 next if ($noclass);
102
103                 s/MAGIC_CLASS/$class/;
104                 print;
105                 next;
106         }
107         print;
108 }
109
110 close IN;
111