-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfw-data-convert
More file actions
executable file
·69 lines (68 loc) · 1.91 KB
/
fw-data-convert
File metadata and controls
executable file
·69 lines (68 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl
#
# Script to convert fw-data.ini file to shella
#
# Copyright (C) 2009, Niall Walsh <niallwalsh@users.berlios.de>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 of the
# License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
use strict;
my $file=$1;
if (length($file)==0)
{
$file='fw-data.ini';
}
unless (-f $file)
{
die "you must supply a valid filename to load from if fw-data.ini is not in the working directory";
}
# Using Config::Any instead would allow to switch to anything it supports
#use Config::Any;
#my $cfg = Config::Any->load_files({files => [ $file ] });
#my $cards = $$cfg[0]{$file};
use Config::Tiny;
my $cards = Config::Tiny->read($file);
my $name;
my $num=0;
my (@names, @fw, @url, @file, @dev, @map, @ok);
foreach $name (sort(keys(%$cards)))
{
push(@names,$name);
my $props = $$cards{$name};
my $field;
# can't use string as ref with strict so map name to array
my %fmap = ('fw'=>\@fw, 'url'=>\@url, 'ok'=> \@ok);
foreach $field ('fw','url','ok')
{
my $a = $fmap{$field};
if (length($$props{$field}))
{
push(@$a,"$$props{$field}");
}
else
{
push(@$a,'""');
}
}
my $prop;
my $drivers=$$props{'drivers'};
$drivers=~s/^\s*\"(.*)\"\s*$/$1/;
foreach $prop (split(/\s+/,$drivers))
{
push(@dev,'"'.$prop.'"');
push(@map,@names-1);
}
}
print 'FW_CARDS=( "'.join('" "',@names).'")'."\n";
print 'FW_CARDS_FW=( '.join(' ',@fw).')'."\n";
print 'FW_CARDS_FW_URL=( '.join(' ',@url).')'."\n";
print 'FW_CARDS_FW_OK=( '.join(' ',@ok).')'."\n";
print 'FW_CARDS_FW_DEV_STR=( '.join(' ',@dev).')'."\n";
print 'FW_CARDS_FW_DEV_NUM=( '.join(' ',@map).')'."\n";