C++标准函数查询
man page只能查Linux系统调用,C标准函数和其它一些glibc函数,不能查C++标准库函数。怎么才能像man那样查询C++的函数呢?我写了下面这么个Perl脚本来完成。
用法:
$ ./mancpp cmath::sin
$ ./mancpp cmath::cos
$ ./mancpp vector::size
$ ./mancpp algorithm::count_if
代码:
[perl]
!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
die “Please provide one argument.n” unless @ARGV==1;
die “Use class::function format.n” unless $ARGV[0] =~ /S::S/;
my ($class, $func) = split(/::/, $ARGV[0]);
my $file = “/tmp/$class.$func.html”;
if ( ! -f “$file”) {
my $url;
if ($class =~ /^c/) {
$url = "http://www.cplusplus.com/reference/clibrary/$class"."/".$func.".html";
} elsif ($class eq "filebuf" || $class eq "fstream"
|| $class eq "ifstream" || $class eq "ios"
|| $class eq "iostream" || $class eq "ios_base"
|| $class eq "istream" || $class eq "istringstream"
|| $class eq "ofstream" || $class eq "ostream"
|| $class eq "ostringstream" || $class eq "streambuf"
|| $class eq "stringbuf" || $class eq "stringstream"){
$url = "http://www.cplusplus.com/reference/iostream/$class"."/".$func.".html";
} elsif($class eq "vector" || $class eq "bitset" || $class eq "deque"
|| $class eq "list" || $class eq "stack" || $class eq "map"
|| $class eq "queue" || $class eq "set" || $class eq "multiset"
|| $class eq "priority_queue" || $class eq "multimap") {
$url = "http://www.cplusplus.com/reference/stl/$class"."/".$func.".html";
} elsif ($class eq "functional" || $class eq "iterator"
|| $class eq "memory" || $class eq "utility") {
$url = "http://www.cplusplus.com/reference/misc/$class"."/".$func.".html";
} elsif ($class eq "algorithm") {
$url = "http://www.cplusplus.com/reference/$class"."/".$func.".html";
} elsif ($class eq "string") {
$url = "http://www.cplusplus.com/reference/string/$class"."/".$func.".html";
}
print "Retrieving $url", "...n";
LWP::Simple::getstore($url, "$file");
}
open my $fd, “$file” or die “No such class or function!n”;
my $found = 0;
my @ret;
while(){
if (m/
$found = 1;
}
if ($found) {
s/]*>//g;
s//g;
s/</</g;
s/Parameters/n==Parameters==/;
s/Example/n==Example==/;
s/See also/n==See also==/;
push @ret, $_;
}
if (m/SuOptions()/) {
$found = 0;
pop @ret;
}
}
open my $hd, "|less" or die "Can't open pipe!n";
foreach (@ret){
print $hd $_;
}
close $hd;
close $fd;
exit 0;
[/perl]