1 |
# |
2 |
# -*- Perl -*- |
3 |
# $Id: deb.pl,v 1.5 2001/06/24 09:36:35 rug Exp $ |
4 |
# Copyright (C) 2000 Namazu Project All rights reserved , |
5 |
# This is free software with ABSOLUTELY NO WARRANTY. |
6 |
# |
7 |
# This program is free software; you can redistribute it and/or modify |
8 |
# it under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either versions 2, or (at your option) |
10 |
# any later version. |
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 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with this program; if not, write to the Free Software |
19 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
20 |
# 02111-1307, USA |
21 |
# |
22 |
# This file must be encoded in EUC-JP encoding |
23 |
# |
24 |
|
25 |
package deb; |
26 |
use strict; |
27 |
require 'util.pl'; |
28 |
require 'gfilter.pl'; |
29 |
|
30 |
my $dpkgpath = undef; |
31 |
|
32 |
sub mediatype() { |
33 |
return ('application/x-deb'); |
34 |
} |
35 |
|
36 |
sub status() { |
37 |
$dpkgpath = util::checkcmd('dpkg'); |
38 |
return 'no' unless (defined $dpkgpath); |
39 |
return 'yes'; |
40 |
} |
41 |
|
42 |
sub recursive() { |
43 |
return 0; |
44 |
} |
45 |
|
46 |
sub pre_codeconv() { |
47 |
return 0; |
48 |
} |
49 |
|
50 |
sub post_codeconv () { |
51 |
return 0; |
52 |
} |
53 |
|
54 |
sub add_magic ($) { |
55 |
my ($magic) = @_; |
56 |
|
57 |
$magic->addFileExts('\\.deb$', 'application/x-deb'); |
58 |
return; |
59 |
} |
60 |
|
61 |
sub filter ($$$$$) { |
62 |
my ($orig_cfile, $cont, $weighted_str, $headings, $fields) |
63 |
= @_; |
64 |
my $cfile = defined $orig_cfile ? $$orig_cfile : ''; |
65 |
|
66 |
my $tmpfile = util::tmpnam('NMZ.deb'); |
67 |
|
68 |
util::vprint("Processing deb file ... (using '$dpkgpath')\n"); |
69 |
|
70 |
#FIXME: needed more smart solutions. |
71 |
system("env LC_ALL=$util::LANG LANGUAGE=$util::LANG $dpkgpath --info $cfile > $tmpfile"); |
72 |
|
73 |
my $fh = util::efopen("$tmpfile"); |
74 |
my $size = util::filesize($fh); |
75 |
if ($size > $conf::FILE_SIZE_MAX) { |
76 |
return 'too_large_dpkg_file'; |
77 |
} |
78 |
$$cont = util::readfile($fh); |
79 |
undef $fh; |
80 |
unlink($tmpfile); |
81 |
|
82 |
dpkg_filter($cont, $weighted_str, $fields, $headings); |
83 |
|
84 |
gfilter::line_adjust_filter($cont); |
85 |
gfilter::line_adjust_filter($weighted_str); |
86 |
gfilter::white_space_adjust_filter($cont); |
87 |
gfilter::show_filter_debug_info($cont, $weighted_str, |
88 |
$fields, $headings); |
89 |
|
90 |
return undef; |
91 |
} |
92 |
|
93 |
sub dpkg_filter ($$$$) { |
94 |
my ($contref, $weighted_str, $fields, $headings) = @_; |
95 |
|
96 |
deb::get_title($contref, $weighted_str, $fields); |
97 |
deb::get_author($contref, $fields); |
98 |
# deb::get_date($contref, $fields); |
99 |
deb::get_size($contref, $fields); |
100 |
deb::get_summary($contref, $fields); |
101 |
|
102 |
return; |
103 |
} |
104 |
|
105 |
|
106 |
# Below is the sample result of 'dpkg --info deb'. |
107 |
# |
108 |
# new debian package, version 2.0. |
109 |
# size 30606 bytes: control archive= 1247 bytes. |
110 |
# 351 bytes, 12 lines control |
111 |
# 1174 bytes, 18 lines md5sums |
112 |
# 389 bytes, 11 lines * postinst #!/bin/sh |
113 |
# 143 bytes, 4 lines * postrm #!/bin/sh |
114 |
# 184 bytes, 6 lines * prerm #!/bin/sh |
115 |
# Package: irb |
116 |
# Version: 1.6.2-1 |
117 |
# Section: interpreters |
118 |
# Priority: optional |
119 |
# Architecture: all |
120 |
# Depends: ruby (>= 1.6.2-1), libreadline-ruby (>= 1.6.2-1) |
121 |
# Installed-Size: 139 |
122 |
# Maintainer: akira yamada <akira@debian.org> |
123 |
# Source: ruby |
124 |
# Description: The Intaractive Ruby. |
125 |
# The irb is acronym for Interactive RuBy. It evaluates ruby expression |
126 |
# from the terminal. |
127 |
|
128 |
sub get_title ($$$) { |
129 |
my ($contref, $weighted_str, $fields) = @_; |
130 |
|
131 |
if ($$contref =~ /^ Description: (.*)/m) { |
132 |
my $tmp = $1; |
133 |
$fields->{'title'} = $tmp; |
134 |
my $weight = $conf::Weight{'html'}->{'title'}; |
135 |
$$weighted_str .= "\x7f$weight\x7f$tmp\x7f/$weight\x7f\n"; |
136 |
} |
137 |
} |
138 |
|
139 |
sub get_author ($$) { |
140 |
my ($contref, $fields) = @_; |
141 |
|
142 |
if ($$contref =~ /^ Maintainer: (.*)/m) { |
143 |
my $tmp = $1; |
144 |
$fields->{'author'} = $tmp; |
145 |
} |
146 |
} |
147 |
|
148 |
sub get_size ($$) { |
149 |
my ($contref, $fields) = @_; |
150 |
|
151 |
if ($$contref =~ /^ size (\d+) bytes:/m) { |
152 |
my $tmp = $1; |
153 |
$fields->{'size'} = $tmp; |
154 |
} |
155 |
} |
156 |
|
157 |
sub get_summary ($$) { |
158 |
my ($contref, $fields) = @_; |
159 |
|
160 |
if ($$contref =~ /^.*Description:[^\n]*\n(.*)/is) { |
161 |
my $tmp = $1; |
162 |
$fields->{'summary'} = $tmp; |
163 |
} |
164 |
} |
165 |
|
166 |
1; |