#!/usr/bin/perl -w #-- FILE: jsearch.pl #-- CODER: KUBO Takuya (kubo@ees.hokudai.ac.jp) #-- #-- (C)opyright 2000 KUBO Takuya (kubo@ees.hokudai.ac.jp). #-- All rights are reserved. #-- Do not modify without amending copyright, #-- distribute freely but retain this paragraph. #-- #-- CHANGE: Wed Aug 9 16:30:05 2000 # MODIFY: Wed Aug 9 15:58:22 2000 use Jcode; # Jcode モジュールを使用します use strict; # strict な (きっちりした) コードにします # 使いかたの説明 sub usage { print STDERR "\nUSAGE: jsearch.pl key file(s)\n\n"; exit 0; } # 引数の一つ目をとって my $key = Jcode->new(shift @ARGV); usage if ($key eq "" || $key eq "-h" || $key eq "--help"); # 結果を表示するサブルーチン sub output { my ($file, $number, $line) = @_; my $head = "$file($number): "; print $head; my $spaces = ' ' x 8; # 8 個の空白 $line =~ s/\t/$spaces/g; # tab -> 8 個の空白 my $counter = length($head) + length($line) - 79; while ($counter > 0) {# 出力する行が 79 文字 (?) になるよう my $deleted = chop $line; # $line を削る $counter -= length($deleted); } print "$line \n"; } # ひとつずつファイルを開いて一行ずづ点検するループ push @ARGV, "-" if @ARGV == 0; # ファイル名指定なければ標準入力 LOOP: foreach my $file (@ARGV) { if (!open IN, $file) { print STDERR "Can't open $file\n"; next LOOP; } my $number = 0; while () { chomp; $number++; my $line = Jcode->new(\$_); output $file, $number, $line if $line =~ m/$key/; } close IN; } exit 0;