From owner-freebsd-hackers Mon Jul 5 3:14:16 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from leap.innerx.net (leap.innerx.net [38.179.176.25]) by hub.freebsd.org (Postfix) with ESMTP id 3AB2A152CC for ; Mon, 5 Jul 1999 03:14:12 -0700 (PDT) (envelope-from chris@holly.dyndns.org) Received: from holly.dyndns.org (ip145.houston3.tx.pub-ip.psi.net [38.12.169.145]) by leap.innerx.net (Postfix) with ESMTP id 099B0370E3 for ; Mon, 5 Jul 1999 06:14:08 -0400 (EDT) Received: (from chris@localhost) by holly.dyndns.org (8.9.3/8.9.3) id FAA00399 for hackers@FreeBSD.org; Mon, 5 Jul 1999 05:11:58 -0500 (CDT) (envelope-from chris) Date: Mon, 5 Jul 1999 05:11:57 -0500 From: Chris Costello To: hackers@FreeBSD.org Subject: 'rtfm' script Message-ID: <19990705051156.B97224@holly.dyndns.org> Reply-To: chris@calldei.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=M9NhX3UHpAaciwkO User-Agent: Mutt/0.96.3i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --M9NhX3UHpAaciwkO Content-Type: text/plain; charset=us-ascii I've been encountering people recently who, for one reason or another, are unable to find information for themselves when they have a question on FreeBSD. I propose an rtfm(1) command, and I've got some Perl code that works. If people are interested, I will continue with it, and write a man page. The source is attached. Sample output: (-s = simple, don't search sections 3, 4, or 9, and 'e' means 'exact', or 'use whatis instead of apropos') --------- $ rtfm -s -e ASCII Manual pages found: ascii(7) hexdump(1) map3270(5) mset(1) neqn(1) od(1) pfbtops(1) Found FAQ entries: 1.18. Where can I get ASCII/PostScript versions of the FAQ? http://www.freebsd.org/FAQ/FAQ19.html#19 1.19. Where can I get ASCII/PostScript versions of the Handbook? http://www.freebsd.org/FAQ/FAQ20.html#20 1.20. The ASCII handbook isn't plain text! http://www.freebsd.org/FAQ/FAQ21.html#21 -- Chris Costello "I'll rob that rich person and give it to some poor deserving slob. That will *prove* I'm Robin Hood." -- Daffy Duck, "Robin Hood Daffy", [1958, Chuck Jones] --M9NhX3UHpAaciwkO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=rtfm #!/usr/bin/perl -w # Copyright (c) 1999 Chris Costello # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. use IO::Socket; my ($mancnt, $line, @manuals, $manual, $simple, $exactword, @faqs); my ($http_socket); $mancnt = 0; $simple = 0; $exactword = 0; # Somehow I need to be able to try and find a 'closest mirror'. $http_server = 'www.freebsd.org'; $faq_path = '/FAQ'; &usage if $#ARGV < 0; while ($_ = $ARGV[0], /^-/) { shift(@ARGV); if (/^-s/) { $simple++; } # see simple description in man page elsif (/^-e/) { $exactword++; } elsif (/^-h/) { &usage } } $ent = $ARGV[0]; $prog = "whatis" if $exactword; $prog = "apropos" unless defined($prog); # First check to see if we have a man page. open(APROPOS, "$prog $ent|") || die "error encountered running $prog: $!"; while (defined($line = )) { chomp($line); $mancnt++; if ($line =~ /$ent: nothing appropriate/) { last; } # innovation. $line =~ s/^(.+?)\(([0-9nqt]+?)\).*/$2 $1/g; push(@manuals, $line); } close(APROPOS); if ($mancnt > 0) { print "Manual pages found:\n"; foreach $manual (@manuals) { my ($sect, $mman) = split(/ /, $manual); if ($simple > 0 && ($sect =~ /[349qt]+/)) { next; } print " $mman($sect)\n"; } } $http_socket = IO::Socket::INET->new($http_server . ':80'); print $http_socket "GET $faq_path/ HTTP/1.0\r\n\r\n"; while (defined($line = <$http_socket>)) { chomp($line); # superiority. if ($line =~ /^
(.+?)(.+?)<.*$/) { my ($faq_ent, $faq_page, $faq_question); $faq_ent = $1; $faq_page = $2; $faq_question = $3; if ($faq_question =~ /$ent/) { push(@faqs, sprintf("%s|%s|%s", $faq_ent, $faq_page, $faq_question)); } } } close($http_socket); print "\nFound FAQ entries:\n"; foreach (@faqs) { my ($faq_ent, $faq_page, $faq_question) = split(/\|/); print " $faq_ent $faq_question\n http://$http_server/FAQ/$faq_page\n"; } # usage: # prints usage info and exits. sub usage { print STDERR "usage: rtfm command\n"; exit 1; } --M9NhX3UHpAaciwkO-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message