You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fw-data-convert 1.9KB

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