Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / texinfo / util / infosrch
blob472df6c72b07424a2effedcddd7f192035b5d2c0
1 #!/usr/local/bin/perl -w
2 # Id: infosrch,v 1.2 2004/04/11 17:56:47 karl Exp
3 # infosrch does a regex search on an info manual.
4 # By Harry Putnam <reader@newsguy.com>.
6 ($myscript = $0) =~ s:^.*/::;
7 $six = '';
9 if($ARGV[0] eq "help"){
10 &usage;
11 exit;
13 if($ARGV[0] eq "-e"){
14 shift;
15 $six = "true";
17 if(!$ARGV[1]){
18 &usage;
19 exit;
22 $target = shift;
23 $regex = shift;
25 $shell_proc = "info --output - --subnodes 2>/dev/null $target";
27 open(SHELL_PROC," $shell_proc|");
28 while(<SHELL_PROC>){
29 chomp;
30 push @lines,$_;
32 close(SHELL_PROC);
33 $cnt = 0;
34 for(@lines){
35 if(/$regex/ && !$six){
36 print "$target\n $lines[($cnt-1)]\n<$cnt> $lines[$cnt]\n $lines[($cnt+1)]\n";
37 print "-- \n";
38 }elsif(/$regex/ && $six){
39 print "$target\n";
40 if($lines[($cnt-6)]){
41 print " $lines[($cnt-6)]\n";
43 if($lines[($cnt-5)]){
44 print " $lines[($cnt-5)]\n";
46 if($lines[($cnt-4)]){
47 print " $lines[($cnt-4)]\n";
49 if($lines[($cnt-3)]){
50 print " $lines[($cnt-3)]\n";
52 if($lines[($cnt-2)]){
53 print " $lines[($cnt-2)]\n";
55 if($lines[($cnt-1)]){
56 print " $lines[($cnt-1)]\n";
58 if($lines[$cnt]){
59 print "$cnt $lines[$cnt]\n";
61 if($lines[($cnt+1)]){
62 print " $lines[($cnt+1)]\n";
64 if($lines[($cnt+2)]){
65 print " $lines[($cnt+2)]\n";
67 if($lines[($cnt+3)]){
68 print " $lines[($cnt+3)]\n";
70 if($lines[($cnt+4)]){
71 print " $lines[($cnt+4)]\n";
73 if($lines[($cnt+5)]){
74 print " $lines[($cnt+5)]\n";
76 if($lines[($cnt+6)]){
77 print " $lines[($cnt+6)]\n";
79 print "-- \n";
81 $cnt++;
84 sub usage {
85 print <<EOM;
87 Purpose: Extract full text from info node and search it by regex
88 Usage: $myscript [-e] TARGET REGEX
90 Where TARGET is an info node such as `emacs', `bash' etc, and
91 REGEX is what you want to find in it.
93 The -e flag is not required but if used then 6 lines preceding and six
94 lines following any hits will be printed. The default (with no -e flag)
95 is to print one line before and after.
97 The output has the line number prepended to the line containing the
98 actual regex.
100 Info command used:
101 info --output - --subnodes 2>/dev/null TARGET