QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1572|回复: 2

[疑问]不知是否正确配置了linux下源代码阅读工具lxr

[复制链接]
发表于 2003-12-17 11:21:19 | 显示全部楼层 |阅读模式
我参照http://www.linuxfans.org/nuke/modules.php?name=Forums&file=viewtopic&t=26480的linux下源代码阅读工具lxr安装整理可用版
按照xdwjack贴出的步骤,做完后在http://localhost/lxr/http/source看到的是如下内容:
#!/usr/local/bin/perl
# $Id: source,v 1.4 1998/05/14 11:59:22 argggh Exp $

# source --        Present sourcecode as html, complete with references
#
#        Arne Georg Gleditsch <[email protected]>
#        Per Kristian Gjermshus <[email protected]>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

######################################################################

use lib 'lib/';
use SimpleParse;
use LXR::Common;
use LXR::Config;


sub descexpand {
    my $templ = shift;

    if ($index{$filename}) {
        return(&expandtemplate($templ,
                               ('desctext', sub {return($index{$filename})})
                               ));
    } else {
        return('');
    }
}


sub diricon {
    if ($filename eq '..') {
        return(&amp;fileref("<img src=\"/icons/back.gif\"".
                        " border=0 alt=\"Back\">",
                        $parentdir));
    } else {
        return(&amp;fileref("<img src=\"/icons/folder.gif\"".
                        " border=0 alt=\"Folder\">",
                        $Path-&gt;{'virt'}.$filename));
    }
}


sub dirname {
    if ($filename eq '..') {
        return(&amp;fileref("Parent directory", $parentdir));
    } else {
        return(&amp;fileref($filename, $Path-&gt;{'virt'}.$filename));
    }
}


sub fileicon {
    if ($filename =~ /^.*\.[ch]$/) {
        return(&amp;fileref("<img src=\"/icons/c.gif\"".
                        " border=0 alt=\"C file\">",
                        $Path-&gt;{'virt'}.$filename));
    } elsif ($filename =~ /^.*\.(cpp|cc)$/) {
        # TODO: Find a nice icon for c++ files (KDE?)
        return(&amp;fileref("<img src=\"/icons/c.gif\"".
                        " border=0 alt=\"C++ file\">",
                        $Path-&gt;{'virt'}.$filename));
    } else {               
        return(&amp;fileref("<img src=\"/icons/text.gif\"".
                        " border=0 alt=\"File\">",
                        $Path-&gt;{'virt'}.$filename));
    }
}


sub filename {
    return(&amp;fileref($filename,
                    $Path-&gt;{'virt'}.$filename));
}


sub filesize {
    my $templ = shift;
    my $s = (-s $Path-&gt;{'real'}.$filename);

    return(&amp;expandtemplate($templ,
                           ('bytes',        sub {return($s)}),
                           ('kbytes',        sub {return($s/1024)}),
                           ('mbytes',        sub {return($s/1048576)})
                           ));
}


sub modtime {
    my @t = gmtime((stat($Path-&gt;{'real'}.$filename))[9]);
    $t[5] += 1900;
    $t[4]++;
    return(sprintf("%04d-%02d-%02d %02d:%02d:%02d", reverse(splice(@t, 0, 6))));
}


sub direxpand {
    my $templ = shift;
    my $direx = '';
    local $filename;
    local $filestat;

    foreach $filename (@dirs) {
        $direx .= &amp;expandtemplate($templ,
                                  ('iconlink',                \&amp;diricon),
                                  ('namelink',                \&amp;dirname),
                                  ('filesize',                sub {return('')}),
                                  ('modtime',                \&amp;modtime),
                                  ('description',        \&amp;descexpand));
    }
       
    foreach $filename (@files) {
        next if $filename =~ /^.*\.[oa]$|^core$|^00-INDEX$/;
        $direx .= &amp;expandtemplate($templ,
                                  ('iconlink',                \&amp;fileicon),
                                  ('namelink',                \&amp;filename),
                                  ('filesize',                \&amp;filesize),
                                  ('modtime',                \&amp;modtime),
                                  ('description',        \&amp;descexpand));
    }

    return($direx);
}

sub printdir {
    my $template;
    my $index;
    local %index;
    local @dirs;
    local @files;
    local $parentdir;


    $template = "<ul>\n\$files{\n&lt;li&gt;\$iconlink \$namelink\n}</ul>\n";
    if ($Conf-&gt;htmldir) {
        unless (open(TEMPL, $Conf-&gt;htmldir)) {
            &amp;warning("Template ".$Conf-&gt;htmldir." does not exist.");
        } else {
            $save = $/; undef($/);
            $template = &lt;TEMPL&gt;;
            $/ = $save;
            close(TEMPL);
        }
    }
       
    if (opendir(DIR, $Path-&gt;{'real'})) {
        foreach $f (sort(grep/^[^\.]/,readdir(DIR))) {
            if (-d $Path-&gt;{'real'}.$f) {
                push(@dirs,"$f/");
            } else {
                push(@files,$f);
            }
        }
        closedir(DIR);
    } else {
        print("&lt;p align=center&gt;\nThis directory does not exist.\n");
        if ($Path-&gt;{'real'} =~ m#(.+[^/])[/]*$#) {
            if (-e $1) {
                &amp;warning("Unable to open ".$Path-&gt;{'real'});
            }
        }
        return;
    }
   
    if (-f $Path-&gt;{'real'}."00-INDEX") {
        open(INDEX,$Path-&gt;{'real'}."00-INDEX") ||
            &amp;warning("Existing \"00-INDEX\" could not be opened.");
        $save = $/; undef($/);
        $index = <INDEX>;
        $/ = $save;
       
        %index = $index =~ /\n(\S*)\s*\n\t-\s*([^\n]*)/gs;
    }

    if ($Path-&gt;{'virt'} =~ m#^(.*/)[^/]*/$#) {
        $parentdir = $1;
        unshift(@dirs, '..');
    }

    print(&amp;expandtemplate($template,
                          ('files',        \&amp;direxpand)));
}


sub printfile {

    unless ($Path-&gt;{'file'}) {
        &amp;printdir;

        if (open(SRCFILE, $Path-&gt;{'real'}.README)) {
            print("&lt;hr&gt;<pre>");
            &amp;markupfile(\*SRCFILE, $Path-&gt;{'virt'}, 'README',
                        sub { print shift });
            print("</pre>");
            close(SRCFILE);
        }

    } else {
        if (open(SRCFILE, $Path-&gt;{'realf'})) {
            print("<pre>");
            &amp;markupfile(\*SRCFILE, $Path-&gt;{'virt'}, $Path-&gt;{'file'},
                        sub { print shift });
            print("</pre>");
            close(SRCFILE);

        } else {
            print("&lt;p align=center&gt;\nThis file does not exist.\n");
            
            if (-f $Path-&gt;{'real'}.$Path-&gt;{'file'}) {
                &amp;warning("Unable to open ".$Path-&gt;{'realf'});
            }
        }
    }
}

($Conf, $HTTP, $Path) = &amp;init;

&amp;makeheader('source');
&amp;printfile;
&amp;makefooter('source');

不知道是否是正确的?!请大侠赐教,万分感谢!
发表于 2003-12-18 22:39:24 | 显示全部楼层
make sure this file is executable.
and u already set all needed .htaccess file.

u are supposed to run this per script. not to show its content
回复

使用道具 举报

发表于 2005-12-23 13:51:16 | 显示全部楼层
当时肯定没有正确配置,Dragonfly给涩兔子面子没有说罢了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-6-4 10:49 , Processed in 0.180295 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表