grep.pl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('grep.pl');
  18. our ($q, @MyRules);
  19. push(@MyRules, \&GrepRule);
  20. sub GrepRule {
  21. if (/\G(&lt;grep "(.*?)"&gt;)/cgis) {
  22. # <search "regexp">
  23. Clean(CloseHtmlEnvironments());
  24. Dirty($1);
  25. my $oldpos = pos;
  26. print '<ul class="grep">';
  27. PrintGrep($2);
  28. print '</ul>';
  29. pos = $oldpos; # restore \G after searching
  30. return '';
  31. }
  32. return;
  33. }
  34. sub PrintGrep {
  35. my $regexp = shift;
  36. foreach my $id (AllPagesList()) {
  37. my $text = GetPageContent($id);
  38. next if (TextIsFile($text)); # skip files
  39. while ($text =~ m{($regexp)}gi) {
  40. print $q->li(GetPageLink($id) . ': ' . $1);
  41. }
  42. }
  43. }