move from agrep-based to perl
authorMichael Prokop <mika@grml.org>
Sat, 3 Mar 2007 14:41:57 +0000 (15:41 +0100)
committerMichael Prokop <mika@grml.org>
Sat, 3 Mar 2007 14:41:57 +0000 (15:41 +0100)
debian/changelog
debian/control
debian/rules
grml-tips
grml-tips.1 [deleted file]

index aaeeb97..e000969 100644 (file)
@@ -1,3 +1,10 @@
+grml-tips (0.3-22) unstable; urgency=low
+
+  * Rewrite of grml-tips script to get rid of (non-free) agrep.
+    Thanks, formorer!
+
+ -- Michael Prokop <mika@grml.org>  Sat,  3 Mar 2007 15:37:20 +0100
+
 grml-tips (0.3-21) unstable; urgency=low
 
   * Add mercurial tip.
index 2b90ae5..0df2564 100644 (file)
@@ -4,11 +4,11 @@ Priority: optional
 Maintainer: Michael Prokop <mika@grml.org>
 Build-Depends: debhelper (>= 4.0.0)
 Standards-Version: 3.7.2
+XS-Vcs-hg: http://hg.grml.org/grml-tips
 
 Package: grml-tips
 Architecture: all
 Depends: ${shlibs:Depends}, ${misc:Depends}
-Suggests: agrep
 Description: search for tips and hints via a keyword
  The provided script grml-tips queries a signature file
  for a specific keyword and displays results on stdout.
index 60efac7..09d2268 100755 (executable)
 #export DH_VERBOSE=1
 
 build:
-       echo "nothing to be done"
+        pod2man grml-tips > grml-tips.1
 
 clean:
        dh_testdir
        dh_testroot
        dh_clean 
+       rm -f grml-tips.1
 
 install:
        dh_testdir
index 7742578..0103730 100755 (executable)
--- a/grml-tips
+++ b/grml-tips
-#!/bin/sh
+#!/usr/bin/perl
 # Filename:      grml-tips
 # Purpose:       query a signature file for a specific keyword and display results
-# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
+# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>, (c) Alexander Wirt <formorer@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is licensed under the GPL v2.
-# Latest change: Sam Nov 11 20:01:35 CET 2006 [mika]
+# Latest change: Sam Mär 03 15:35:38 CET 2007 [mika]
 ################################################################################
 
-TIPSFILE='/usr/share/grml-tips/grml_tips'
-
-if ! [ -r "$TIPSFILE" ] ; then
-   echo "Error: $TIPSFILE not found. Exiting." >&2
-   exit 1
-fi
-
-if [ -x /usr/bin/agrep ] ; then
-   if [ -n "$1" ] ; then
-     agrep -d "^-- $" -i "$1" $TIPSFILE && echo "" || \
-     ( echo "Sorry, could not find a tip for '$1'. :-(" >&2
-       echo 'If you want to submit a tip please mail it to tips@grml.org - thank you!' >&2
-       exit 1 )
-   else
-     echo "Usage: $0 <keyword>" >&2 ; exit 1
-   fi
-else # workaround solution for systems without agrep :-/
-  if [ -n "$1" ] ; then
-     TIP=$(awk "BEGIN { RS = \"-- \" } /$1/" "$TIPSFILE")
-     if [ -n "$TIP" ] ; then
-        echo "$TIP"
-     else
-        echo "Sorry, could not find a tip for '$1'. :-(" >&2
-        echo 'If you want to submit a tip please mail it to tips@grml.org - thank you!' >&2
-        exit 1
-     fi
-  else
-    echo "Usage: $0 <keyword>" >&2 ; exit 1
-  fi
-fi
+use strict;
+use Pod::Usage;
+
+=head1 NAME
+
+B<grml-tips> - query a signature file for a specific keyword and display results
+
+=head1 SYNOPSIS
+
+B<grml-tips> [OPTION] I<keyword>
+
+=head1 DESCRIPTION
+
+This manual page documents briefly the B<grml-tips> command.
+
+=head1 OPTIONS
+
+=over 8
+
+=item B<--help>
+
+Print this help and exit.
+
+=back
+
+=head1 EXAMPLES
+
+=over 8
+
+=item B<grml-tips> I<ntfs>
+
+Query grml-tips file for tips / hints including keyword  "ntfs".
+
+=item B<grml-tips> I<.>
+
+Display all available B<grml-tips> at once.
+
+=back
+
+=head1 FILES
+
+/usr/share/grml-tips/grml_tips
+
+Signature file containing the tips.
+
+=head1 SEE ALSO
+
+L<grml(1)>
+
+=head1 AUTHOR
+
+grml-tips was written by Alexander Wirt <formorer@grml.org>
+
+=cut
+
+
+my $grml_tips = '/usr/share/grml-tips/grml_tips';
+my $pattern = shift;
+
+if ($pattern eq '') {
+    pod2usage( {
+           -message => 'No search pattern provided',
+           -exitval => -1, });
+} elsif ($pattern eq  '--help') {
+    pod2usage();
+}
+
+my @tips;
+my $fh;
+if (! open ($fh, '<', "$grml_tips")) {
+       print "Error: $grml_tips not found.\nExiting.";
+       exit -1;
+}
+
+my $tip = '';
+my $tip_flag = 0;
+
+while (my $line = <$fh>) {
+    if ($line !~ /^--/) {
+       $tip .= $line;
+    } else {
+       if ( "$tip" =~ /$pattern/m ) {
+           $tip .= $line;
+           print "$tip";
+           $tip = '';
+           $tip_flag = 1;
+       } else {
+           $tip = '';
+       }
+    }
+}
+close($fh);
+
+print "Sorry, could not find a tip for '$pattern'. :-(\n"
+    . "If you want to submit a tip please mail it to tips\@grml.org - thank "
+    . "you!\n\n" unless $tip_flag;
 
 ## END OF FILE #################################################################
diff --git a/grml-tips.1 b/grml-tips.1
deleted file mode 100644 (file)
index 3b21ebf..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-.TH GRML-TIPS 1
-.SH NAME
-grml-tips \- query a signature file for a specific keyword and display results
-.SH SYNOPSIS
-.B grml-tips
-.RI " keyword"
-.SH DESCRIPTION
-This manual page documents briefly the
-.B grml-tips
-command.
-.PP
-.SH Usage example
-.TP
-.BR "grml-tips ntfs"
-Query grml-tips file for tips / hints including keyword "ntfs".
-.TP
-.BR "grml-tips ."
-Display all available grml-tips at once.
-.SH FILES
-.PP
-/usr/share/grml-tips/grml_tips
-.PP
-Signature file containing the tips.
-.SH NOTES
-By default grml-tips uses agrep for searching through the signature file.
-If agrep is not available it falls back to use of awk.
-.SH OPTIONS
-This program does not support any options.
-.SH SEE ALSO
-.BR grml (1)
-.SH AUTHOR
-grml-tips was written by Michael Prokop <mika@grml.org>
-.PP
-This manual page was written by Michael Prokop <mika@grml.org>
-for the grml project (but may be used by others).