-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetchconfig.pl
executable file
·132 lines (100 loc) · 2.76 KB
/
fetchconfig.pl
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#! /usr/bin/perl -w
#
# fetchconfig - Retrieving configuration for multiple devices
# Copyright (C) 2006 Everton da Silva Marques
#
# fetchconfig 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; either version 2, or (at your option)
# any later version.
#
# fetchconfig 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.
#
# You should have received a copy of the GNU General Public License
# along with fetchconfig; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301 USA.
#
# $Id: fetchconfig.pl,v 1.8 2012/11/27 21:42:28 evertonm Exp $
use strict;
use fetchconfig::Logger;
use fetchconfig::Constants;
use fetchconfig::model::Detector;
sub basename {
my ($path) = @_;
my @list;
if ($^O eq 'MSWin32') {
@list = split /\\/, $path;
}
else {
@list = split /\//, $path;
}
pop @list;
}
my $me = basename($0);
my $log = fetchconfig::Logger->new({ prefix => $me });
$log->info('version ' . fetchconfig::Constants::version);
my @device_file_list;
my @line_list;
foreach my $opt (@ARGV) {
if ($opt eq '-v') {
exit; # only show version
}
if ($opt =~ /^-devices=(.+)$/) {
push @device_file_list, $1;
next;
}
if ($opt =~ /^-line=(.+)$/) {
push @line_list, $1;
next;
}
$log->error("unexpected argument: $opt");
&usage;
die;
}
if ((@device_file_list < 1) && (@line_list < 1)){
$log->error("at least one -devices=filename or one -line=string is required");
&usage;
die;
}
fetchconfig::model::Detector->init($log);
foreach my $dev_file (@device_file_list) {
&load_device_list($dev_file);
}
my $line_num = 0;
foreach my $line (@line_list) {
++$line_num;
&load_line($line, $line_num);
}
$log->info("done");
exit;
sub usage {
warn "usage: $me [-v] [-devices=file] [-line=string]\n";
}
sub load_device_list {
my ($filename) = @_;
local *IN;
if (!open(IN, "<$filename")) {
$log->error("could not read device list: $filename: $!");
return;
}
$log->debug("loading device list: $filename");
my $line_num = 0;
while (<IN>) {
chomp;
++$line_num;
#$log->debug("[$line_num] $_");
next if (/^\s*(#|$)/);
fetchconfig::model::Detector->parse($filename, $line_num, $_);
}
close IN;
}
sub load_line {
my ($line, $num) = @_;
$log->debug("loading line: line=$num [$line]");
return if ($line =~ /^\s*(#|$)/);
fetchconfig::model::Detector->parse('<cmdline>', $num, $line);
}