summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/texinfo/util/infosrch
blob: 7fae78e8b84e56dfd357741225186d4c418faee9 (plain)
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
#!/usr/local/bin/perl -w
# $Id: infosrch,v 1.1.1.1 2006/07/17 16:03:50 espie Exp $
# infosrch does a regex search on an info manual.
# By Harry Putnam <reader@newsguy.com>.

($myscript = $0) =~ s:^.*/::; 
$six = '';

if($ARGV[0] eq "help"){
   &usage;
   exit;
}
if($ARGV[0] eq "-e"){
   shift;
   $six = "true";
}
if(!$ARGV[1]){
   &usage;
   exit;
}

$target = shift;
$regex  = shift;

$shell_proc  =  "info --output - --subnodes 2>/dev/null $target";

open(SHELL_PROC," $shell_proc|");
while(<SHELL_PROC>){
  chomp;
  push @lines,$_;
} 
close(SHELL_PROC);
$cnt = 0;
for(@lines){
   if(/$regex/ && !$six){
      print "$target\n   $lines[($cnt-1)]\n<$cnt> $lines[$cnt]\n   $lines[($cnt+1)]\n";
      print "-- \n";
   }elsif(/$regex/ && $six){
        print "$target\n";
        if($lines[($cnt-6)]){
           print "    $lines[($cnt-6)]\n";
        }
        if($lines[($cnt-5)]){
           print "    $lines[($cnt-5)]\n";
        }
        if($lines[($cnt-4)]){
           print "    $lines[($cnt-4)]\n";
        }
        if($lines[($cnt-3)]){
           print "    $lines[($cnt-3)]\n";
        }
        if($lines[($cnt-2)]){
           print "    $lines[($cnt-2)]\n";
        }
        if($lines[($cnt-1)]){
           print "    $lines[($cnt-1)]\n";
        }
        if($lines[$cnt]){
           print "$cnt $lines[$cnt]\n";
        }
        if($lines[($cnt+1)]){
           print "    $lines[($cnt+1)]\n";
        }
        if($lines[($cnt+2)]){
           print "    $lines[($cnt+2)]\n";
        }
        if($lines[($cnt+3)]){
           print "    $lines[($cnt+3)]\n";
        }
        if($lines[($cnt+4)]){
           print "    $lines[($cnt+4)]\n";
        }
        if($lines[($cnt+5)]){
           print "    $lines[($cnt+5)]\n";
        }
        if($lines[($cnt+6)]){
           print "    $lines[($cnt+6)]\n";
        }
        print "-- \n";
     }
     $cnt++;
}        

sub usage {
  print <<EOM;

Purpose: Extract full text from info node and search it by regex
Usage: $myscript [-e] TARGET REGEX

Where TARGET is an info node such as `emacs', `bash' etc, and
REGEX is what you want to find in it.

The -e flag is not required but if used then 6 lines preceding and six
lines following any hits will be printed.  The default (with no -e flag)
is to print one line before and after.

The output has the line number prepended to the line containing the
actual regex.

Info command used:
  info --output - --subnodes 2>/dev/null TARGET

EOM
}