updated git and svn scripts
[xrzperl.git] / doc-view
blob1fbd9b431de6b7a13b8d7d270444b01431669478
1 #!/usr/bin/perl -w
2 ###APPNAME: doc-view
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Thu Feb 14 14:30:06 2008
5 ###APPVER: 0.1
6 ###APPDESC: List and view documents of specified package
7 ###APPUSAGE: (package name)
8 ###APPEXAMPLE: doc-view aptitude
9 ###APPOPTION:
10 use strict;
11 use lib $ENV{XR_PERL_MODULE_DIR};
12 use MyPlace::Script::Usage qw/help_even_empty/;
13 exit 0 if(help_even_empty($0,@ARGV));
15 my @topdir = ( "/usr/share/doc" , "/usr/local/share/doc" );
16 my $dirname = $ARGV[0];
17 my $docdir;
18 my $zview = "zless";
19 my $view = "less";
21 print("Lookup document directory in \"",join("\", \"",@topdir),"\"\n");
22 foreach(@topdir) {
23 if(-d "$_/$dirname") {
24 $docdir = "$_/$dirname";
25 print("Found $docdir \n");
28 die("No document directory for $dirname found\n") unless($docdir);
30 chdir($docdir) or die("$!\n");
32 my @docs;
33 foreach(glob("*")) {
34 if(-f "$_") {
35 push(@docs,$_);
39 sub listDoc(@) {
40 my $idx=0;
41 print("Documents list:\n");
42 print("------------------------------------------\n");
43 foreach(@_) {
44 $idx++;
45 printf("%4s. %s\n",$idx,$_);
47 print("__________________________________________\n");
48 print("Your Choice(q to quit):")
51 listDoc(@docs);
53 sub getInput() {
54 my $lines = <STDIN>;
55 chomp($lines);
56 if($lines eq "q" || $lines eq "Q") {
57 return 0;
59 else {
60 return $lines;
64 sub viewdoc($) {
65 my $file = $_[0];
66 if(! -f "$file" ){
67 print STDERR "File not exist:$file\n";
69 else {
70 if($file =~ m/\.gz$/i) {
71 system($zview,"$file");
73 else {
74 system($view,"$file");
79 while(my $choice = getInput()) {
80 if($choice>0 and $choice<=@docs) {
81 viewdoc($docdir . "/" . $docs[$choice-1]);
83 listDoc(@docs);