/usr/bin/lnnmz is in namazu2-index-tools 2.0.21-6.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | #! /usr/bin/perl -w
# -*- Perl -*-
# lnnmz - program to make NMZ.field.link
# $Id: lnnmz.in,v 1.1.4.5 2005-09-24 12:25:07 opengl2772 Exp $
#
# Copyright (C) 2000 osamu2001@livedoor.com All rights reserved.
# Copyright (C) 2000 furukawa@tcp-ip.or.jp All rights reserved.
# Copyright (C) 2001 Hajime BABA All rights reserved.
# Copyright (C) 2001-2005 Namazu Project All rights reserved.
# This is free software with ABSOLUTELY NO WARRANTY.
#
# This program 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 versions 2, or (at your option)
# any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA
#
# This file must be encoded in EUC-JP encoding
#
package lnnmz;
use strict;
use English;
use Cwd;
use File::Spec;
my $PKGDATADIR = $ENV{'pkgdatadir'} || "/usr/share/namazu";
push(@INC, $PKGDATADIR . "/pl");
require 'nmzidx.pl';
sub rel2abs($;$);
# for example
my %inv_replace = (
"http://www.apache.org" => "/home/httpd/html",
);
my $backup;
while (@ARGV && $ARGV[0] =~ s/^\-//){
my $argv = shift;
&usage, exit if $argv eq '-help';
$backup = 0, next if $argv eq '-no-backup';
while ($argv =~ s/^(.)//){
$backup = 0 if $1 eq 'b';
}
}
if (@ARGV){
for my $argv (@ARGV){
$argv =~ s/NMZ$// unless -d $argv;
$argv = '.' if $argv eq '';
&lnnmz($argv, $backup);
}
} else {
&lnnmz('.', $backup);
}
exit(0);
# main routine
sub lnnmz{
my ($dir, $backup) = @_;
if (! -f "$dir/NMZ.i") {
print "Cannot open index. : $dir\n";
return;
}
my $nmzi = new nmzidx($dir, 'r');
my $fh = $nmzi->open_flist;
unless (defined $fh->{'t'}) {
$fh->close;
$nmzi->close;
return;
}
my $nmzo = new nmzidx($dir, 'w');
my $fo = $nmzo->open_field('link');
my %list_f;
while (defined $fh->read(\%list_f)){
my $fname = $list_f{'r'};
# print "@@ $fname\n";
open(F, $fname) || die;
my @href = get_href($fname, <F>);
close(F);
my $tmp = join(" ", @href);
$fo->{'link'}->putline("$tmp\n");
# print "@@ $tmp\n";
}
$nmzo->replace_db($backup);
$nmzi->close;
}
# mmm... tooooooooo dirty, but it seems to work good. X-(
# Pls clean up the code!
sub get_href {
my ($fname, @lines) = @_;
my ($basedir, $file) = splitpath($fname);
my (@href, %count);
foreach my $line (@lines) {
if ($line =~ /<a\s[^>]*href=([\"\'])(.*?)\1/ig) { #"
my $href = $2;
next if ($href =~ /^(ftp|mailto):/); # only http: or file:
if (($href !~ m:^/:) && ($href !~ m/^http:/)) {
$href = rel2abs($href, $basedir);
$href = canonpath($href) ;
}
$href =~ s/#.*$//g;
$href =~ s:([^/]*)/\.\.::g;
foreach my $url (sort keys %inv_replace) {
my $dir = $inv_replace{$url};
$href =~ s:^$url:$dir:g;
$href =~ s:^/$:$dir/index.html:g;
}
$href =~ s:/$:/index.html:g;
$href =~ s:/\.$:/index.html:g;
if ($href !~ m/^http:/) {
$href = canonpath($href) ;
}
push(@href, $href) unless $count{$href};
$count{$href}++;
}
}
{
# uniq and sort
my %count;
@href = grep(!$count{$_}++, @href);
@href = sort {$count{$a} <=> $count{$b}} @href;
}
return @href;
}
# Splits a path into directory and filename portions.
sub splitpath($) {
my ($path) = @_;
my ($dir, $file) = ('', '');
$path =~ m|^ ( (?: .* / (?: \.\.?\z )? )? ) ([^/]*) |xs;
$dir = $1;
$file = $2;
# print "dir=$dir, file=$file\n";
return ($dir, $file);
}
# Converts a relative path to an absolute path.
sub rel2abs($;$) {
my ($path,$base ) = @_;
# Clean up $path
if ( ! File::Spec->file_name_is_absolute( $path ) ) {
# Figure out the effective $base and clean it up.
if ( !defined( $base ) || $base eq '' ) {
$base = cwd() ;
}
elsif ( ! File::Spec->file_name_is_absolute( $base ) ) {
$base = rel2abs( $base ) ;
}
else {
$base = canonpath( $base ) ;
}
# Glom them together
$path = File::Spec->catdir( $base, $path ) ;
}
return canonpath( $path ) ;
}
sub canonpath {
my ($path) = @_;
$path =~ s|/+|/|g unless($English::OSNAME eq 'cygwin'); # xx////xx -> xx/xx
$path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx
$path =~ s|^(\./)+||s unless $path eq "./"; # ./xx -> xx
$path =~ s|^/(\.\./)+|/|s; # /../../xx -> xx
$path =~ s|/\z|| unless $path eq "/"; # xx/ -> xx
return $path;
}
sub usage{
print
("Usage: lnnmz [options] <target(s)>\n" .
" --help show this help and exit.\n" .
" -b, --no-backup do not backup original file.\n"
);
}
# EOF
|