-
Notifications
You must be signed in to change notification settings - Fork 20
/
man.pl
executable file
·107 lines (81 loc) · 3.17 KB
/
man.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/perl -w
# SPDX-FileCopyrightText: 2001-2023 Pragmatic Software <[email protected]>
# SPDX-License-Identifier: MIT
# quick and dirty by :pragma
use LWP::Simple;
my ($result, $manpage, $section, $text, $name, $includes, $prototype, $conforms, $description);
if ($#ARGV < 0) {
print "Which command would you like information about?\n";
die;
}
$manpage = join("+", @ARGV);
$section = 8;
my $loop = 1;
if ($manpage =~ m/([0-9]+)\+(.*)/) {
$section = $1;
$manpage = $2;
$loop = 0;
}
$manpage =~ s/\+.*$//;
my $get_text;
do {
# $text = get("http://www.freebsd.org/cgi/man.cgi?query=$manpage&sektion=$section&apropos=0&manpath=FreeBSD+6.2-RELEASE&format=ascii");
$get_text = get("http://www.freebsd.org/cgi/man.cgi?query=$manpage&sektion=$section&apropos=0&manpath=SuSE+Linux%2Fi386+11.3&format=ascii");
$text = substr($get_text, 0, 5000);
# print '['.length($text).']'."\n";
if ($text =~ m/Sorry, no data found/) {
$section--;
if ($section == 0 || $loop == 0) {
$section++;
if ($section == 1 && $loop == 1) { print "No information found for $manpage in any of the sections.\n"; }
else { print "No information found for $manpage in section $section.\n"; }
exit 0;
}
} else {
$loop = 0;
}
} while ($loop);
$text =~ m/^\s+NAME/gsm;
if ($text =~ m/(.*?)SYNOPSIS/gsi) { $name = $1; }
my $i = 0;
while ($text =~ m/#include <(.*?)>/gsi) {
if (not $includes =~ /$1/) {
$includes .= ", " if ($i > 0);
$includes .= "$1";
$i++;
}
}
$prototype = "$1 $2$manpage($3);" if ($text =~ m/SYNOPSIS.*^\s+(.*?)\s+(\*?)$manpage\s*\((.*?)\)\;?\n.*DESC/ms);
if ($text =~ m/DESCRIPTION(.*?)$manpage(.*?)\./si) {
my $foo = $1;
my $bar = $2;
$foo =~ s/\r//g;
$foo =~ s/\n//g;
$foo =~ s/\s+/ /g;
$foo =~ s/^\s+//;
if ($foo =~ /^NOTE/) { $description = "$foo$manpage$bar"; }
else { $description = "$manpage$bar"; }
$description =~ s/\-\s+//g;
}
if ($get_text =~ m/^CONFORMING TO.*?^\s+The\s$manpage\s.*conforms to\s(.*?)$/ms) { $conforms = $1; }
elsif ($get_text =~ m/^CONFORMING TO.*?^\s+The\s+$manpage\s+.*?is\s+compatible\s+with\s+(.*?)$/ms) { $conforms = "$1 ..."; }
elsif ($get_text =~ m/^CONFORMING TO.*?^\s+(.*?)\.\s/ms or $get_text =~ m/^CONFORMING TO.*?^\s+(.*?)$/ms) { $conforms = $1; }
$result = "";
$result .= "$name - " if (not defined $includes and defined $name);
$result .= "Includes: $includes - " if (defined $includes);
$result .= "$prototype - " if (defined $prototype);
$result .= $description;
if ($section == 3) { $result .= " - http://www.iso-9899.info/man?$manpage"; }
else { $result .= " - http://www.freebsd.org/cgi/man.cgi?sektion=$section&query=$manpage"; }
$result .= " - $conforms" if (defined $conforms);
$result =~ s/^\s+//g;
$result =~ s/\s+/ /g;
$result =~ s/ANSI - C/ANSI C/g;
$result =~ s/\(these.*?appeared in .*?\)//g;
$result =~ s/(\w)- /$1/g;
$result =~ s/\n//g;
$result =~ s/\r//g;
$result =~ s/\<A HREF.*?>//g;
$result =~ s/\<\/A>//g;
$result =~ s/"//g;
print "$result\n";