infosrch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/local/bin/perl -w
  2. # infosrch does a regex search on an info manual.
  3. # By Harry Putnam <reader@newsguy.com>.
  4. ($myscript = $0) =~ s:^.*/::;
  5. $six = '';
  6. if($ARGV[0] eq "help"){
  7. &usage;
  8. exit;
  9. }
  10. if($ARGV[0] eq "-e"){
  11. shift;
  12. $six = "true";
  13. }
  14. if(!$ARGV[1]){
  15. &usage;
  16. exit;
  17. }
  18. $target = shift;
  19. $regex = shift;
  20. $shell_proc = "info --output - --subnodes 2>/dev/null $target";
  21. open(SHELL_PROC," $shell_proc|");
  22. while(<SHELL_PROC>){
  23. chomp;
  24. push @lines,$_;
  25. }
  26. close(SHELL_PROC);
  27. $cnt = 0;
  28. for(@lines){
  29. if(/$regex/ && !$six){
  30. print "$target\n $lines[($cnt-1)]\n<$cnt> $lines[$cnt]\n $lines[($cnt+1)]\n";
  31. print "-- \n";
  32. }elsif(/$regex/ && $six){
  33. print "$target\n";
  34. if($lines[($cnt-6)]){
  35. print " $lines[($cnt-6)]\n";
  36. }
  37. if($lines[($cnt-5)]){
  38. print " $lines[($cnt-5)]\n";
  39. }
  40. if($lines[($cnt-4)]){
  41. print " $lines[($cnt-4)]\n";
  42. }
  43. if($lines[($cnt-3)]){
  44. print " $lines[($cnt-3)]\n";
  45. }
  46. if($lines[($cnt-2)]){
  47. print " $lines[($cnt-2)]\n";
  48. }
  49. if($lines[($cnt-1)]){
  50. print " $lines[($cnt-1)]\n";
  51. }
  52. if($lines[$cnt]){
  53. print "$cnt $lines[$cnt]\n";
  54. }
  55. if($lines[($cnt+1)]){
  56. print " $lines[($cnt+1)]\n";
  57. }
  58. if($lines[($cnt+2)]){
  59. print " $lines[($cnt+2)]\n";
  60. }
  61. if($lines[($cnt+3)]){
  62. print " $lines[($cnt+3)]\n";
  63. }
  64. if($lines[($cnt+4)]){
  65. print " $lines[($cnt+4)]\n";
  66. }
  67. if($lines[($cnt+5)]){
  68. print " $lines[($cnt+5)]\n";
  69. }
  70. if($lines[($cnt+6)]){
  71. print " $lines[($cnt+6)]\n";
  72. }
  73. print "-- \n";
  74. }
  75. $cnt++;
  76. }
  77. sub usage {
  78. print <<EOM;
  79. Purpose: Extract full text from info node and search it by regex
  80. Usage: $myscript [-e] TARGET REGEX
  81. Where TARGET is an info node such as `emacs', `bash' etc, and
  82. REGEX is what you want to find in it.
  83. The -e flag is not required but if used then 6 lines preceding and six
  84. lines following any hits will be printed. The default (with no -e flag)
  85. is to print one line before and after.
  86. The output has the line number prepended to the line containing the
  87. actual regex.
  88. Info command used:
  89. info --output - --subnodes 2>/dev/null TARGET
  90. EOM
  91. }