diff options
author | Luis Ontanon <luis.ontanon@gmail.com> | 2006-09-07 22:38:16 +0000 |
---|---|---|
committer | Luis Ontanon <luis.ontanon@gmail.com> | 2006-09-07 22:38:16 +0000 |
commit | a81d83486ad6b34ba751b3ea39a8d2a365718ba6 (patch) | |
tree | a47095148796c0b53bf3d6f3a082598514d9481a /epan/make-sminmpec.pl | |
parent | ac76ad1c64f287daf81b93618543276e40ba2454 (diff) |
removed options.
now it can either be called as
make-sminmpec.pl
so it will fetch the file only if it has been modified since we last loaded it
or
make-sminmpec.pl enterprise-numbers
to regenerate the C file from the given file.
Luis
svn path=/trunk/; revision=19177
Diffstat (limited to 'epan/make-sminmpec.pl')
-rwxr-xr-x | epan/make-sminmpec.pl | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/epan/make-sminmpec.pl b/epan/make-sminmpec.pl index 38dc2e0464..fa1b57f5a7 100755 --- a/epan/make-sminmpec.pl +++ b/epan/make-sminmpec.pl @@ -22,53 +22,60 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use strict; -use Getopt::Long; - -my $opt_gen; -GetOptions("gen" => \$opt_gen ); my $in = shift; -my $out = shift; -if (! defined $in && ! defined $out and $opt_gen) { - $in = "http://www.iana.org/assignments/enterprise-numbers"; - $out = "sminmpec.c"; -} +$in = "http://www.iana.org/assignments/enterprise-numbers" unless(defined $in); my @in_lines; -open OUT, "> $out"; - if($in =~ m/^http:/i) { - eval "require LWP::UserAgent;"; - if ( $@ ) { - die "LWP isn't installed. It is part of the standard Perl\n" . - " module libwww. Bailing.\n"; - } - my $agent = LWP::UserAgent->new; + eval "require LWP::UserAgent;"; + die "LWP isn't installed. It is part of the standard Perl module libwww." if $@; + + my $agent = LWP::UserAgent->new; + + warn "starting to fetch $in ...\n"; - warn "starting to fetch $in ...\n"; - - my $request = HTTP::Request->new(GET => $in); - my $result = $agent->request($request); + my $request = HTTP::Request->new(GET => $in); - warn "done fetching $in ...\n"; + + if (-f "enterprise-numbers") { + my $mtime; + (undef,undef,undef,undef,undef,undef,undef,undef,undef,$mtime,undef,undef,undef) = stat("enterprise-numbers"); + $request->if_modified_since( $mtime ); + } + + my $result = $agent->request($request); + + if ($result->code eq 200) { + warn "done fetching $in\n"; + @in_lines = split /\n/, $result->content; + open ENFILE, "> enterprise-numbers"; + + for (@in_lines) { + chomp; + print ENFILE "$_\n"; + } + + close ENFILE; + } elsif ($result->code eq 304) { + warn "enterprise-numbers was up-to-date\n"; + open IN, "< enterprise-numbers"; + @in_lines = <IN>; + close IN; + } else { + die "request for $in failed with result code:" . $result->code; + } - @in_lines = split /\n/, $result->content; } else { open IN, "< $in"; @in_lines = <IN>; close IN; } -if ($opt_gen) { - for (@in_lines) { - chomp; - print OUT "$_\n"; - } - exit; -} +open OUT, "> sminmpec.c"; my $body = ''; my $code; |