1# 2# -*- Perl -*- 3# $Id: deb.pl,v 1.5.4.10 2008-05-09 07:22:08 opengl2772 Exp $ 4# Copyright (C) 2000-2008 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 25package deb; 26use strict; 27require 'util.pl'; 28require 'gfilter.pl'; 29 30my $dpkgpath = undef; 31my @dpkgopts = undef; 32 33sub mediatype() { 34 return ('application/x-deb'); 35} 36 37sub status() { 38 $dpkgpath = util::checkcmd('dpkg'); 39 @dpkgopts = ("--info"); 40 return 'no' unless (defined $dpkgpath); 41 return 'yes'; 42} 43 44sub recursive() { 45 return 0; 46} 47 48sub pre_codeconv() { 49 return 0; 50} 51 52sub post_codeconv () { 53 return 0; 54} 55 56sub add_magic ($) { 57 my ($magic) = @_; 58 59 # FIXME: very ad hoc. 60 $magic->addFileExts('\\.deb$', 'application/x-deb'); 61 return; 62} 63 64sub filter ($$$$$) { 65 my ($orig_cfile, $cont, $weighted_str, $headings, $fields) 66 = @_; 67 my $cfile = defined $orig_cfile ? $$orig_cfile : ''; 68 69 util::vprint("Processing deb file ... (using '$dpkgpath')\n"); 70 71 my $tmpfile = util::tmpnam('NMZ.deb'); 72 { 73 my $fh = util::efopen("> $tmpfile"); 74 print $fh $$cont; 75 util::fclose($fh); 76 } 77 { 78 my %env = ( 79 "LC_ALL" => $util::LANG, 80 "LANGUAGE" => $util::LANG, 81 ); 82 my @cmd = ($dpkgpath, @dpkgopts, $tmpfile); 83 my $fh_out = IO::File->new_tmpfile(); 84 my $status = util::syscmd( 85 command => \@cmd, 86 option => { 87 "stdout" => $fh_out, 88 "stderr" => "/dev/null", 89 }, 90 env => \%env, 91 ); 92 my $size = util::filesize($fh_out); 93 if ($size == 0) { 94 util::fclose($fh_out); 95 unlink $tmpfile; 96 return "Unable to convert file ($dpkgpath error occurred)"; 97 } 98 if ($size > $conf::FILE_SIZE_MAX) { 99 util::fclose($fh_out); 100 unlink $tmpfile; 101 return 'Too large deb file'; 102 } 103 $$cont = util::readfile($fh_out); 104 util::fclose($fh_out); 105 } 106 unlink $tmpfile; 107 108 codeconv::normalize_document($cont); 109 110 dpkg_filter($cont, $weighted_str, $fields, $headings); 111 112 gfilter::line_adjust_filter($cont); 113 gfilter::line_adjust_filter($weighted_str); 114 gfilter::white_space_adjust_filter($cont); 115 $fields->{'title'} = gfilter::filename_to_title($cfile, $weighted_str) 116 unless $fields->{'title'}; 117 gfilter::show_filter_debug_info($cont, $weighted_str, 118 $fields, $headings); 119 120 return undef; 121} 122 123sub dpkg_filter ($$$$) { 124 my ($contref, $weighted_str, $fields, $headings) = @_; 125 126 deb::get_title($contref, $weighted_str, $fields); 127 deb::get_author($contref, $fields); 128# deb::get_date($contref, $fields); 129 deb::get_size($contref, $fields); 130 deb::get_summary($contref, $fields); 131 132 return; 133} 134 135 136# Below is the sample result of 'dpkg --info deb'. 137# 138# new debian package, version 2.0. 139# size 30606 bytes: control archive= 1247 bytes. 140# 351 bytes, 12 lines control 141# 1174 bytes, 18 lines md5sums 142# 389 bytes, 11 lines * postinst #!/bin/sh 143# 143 bytes, 4 lines * postrm #!/bin/sh 144# 184 bytes, 6 lines * prerm #!/bin/sh 145# Package: irb 146# Version: 1.6.2-1 147# Section: interpreters 148# Priority: optional 149# Architecture: all 150# Depends: ruby (>= 1.6.2-1), libreadline-ruby (>= 1.6.2-1) 151# Installed-Size: 139 152# Maintainer: akira yamada <akira@debian.org> 153# Source: ruby 154# Description: The Intaractive Ruby. 155# The irb is acronym for Interactive RuBy. It evaluates ruby expression 156# from the terminal. 157 158sub get_title ($$$) { 159 my ($contref, $weighted_str, $fields) = @_; 160 161 if ($$contref =~ /^ Description: (.*)/m) { 162 my $tmp = $1; 163 $fields->{'title'} = $tmp; 164 my $weight = $conf::Weight{'html'}->{'title'}; 165 $$weighted_str .= "\x7f$weight\x7f$tmp\x7f/$weight\x7f\n"; 166 } 167} 168 169sub get_author ($$) { 170 my ($contref, $fields) = @_; 171 172 if ($$contref =~ /^ Maintainer: (.*)/m) { 173 my $tmp = $1; 174 $fields->{'author'} = $tmp; 175 } 176} 177 178sub get_size ($$) { 179 my ($contref, $fields) = @_; 180 181 if ($$contref =~ /^ size (\d+) bytes:/m) { 182 my $tmp = $1; 183 $fields->{'size'} = $tmp; 184 } 185} 186 187sub get_summary ($$) { 188 my ($contref, $fields) = @_; 189 190 if ($$contref =~ /^.*Description:[^\n]*\n(.*)/is) { 191 my $tmp = $1; 192 $fields->{'summary'} = $tmp; 193 } 194} 195 1961; 197