本帖最后由 523066680 于 2015-6-10 15:17 编辑
修正问题: 正则表达式(考虑部分#include 采用的是 双引号,以及#include 尾部含有注释<>""的情况)
.- =info
- 523066680@163.com
- 2015-06-09
- =cut
-
- use feature 'state';
-
- our @dirs = (
- "C:/MinGW/lib/gcc/mingw32/4.7.2/include",
- "C:/MinGW/Include",
- );
-
- our %name;
- our %hash;
-
- my $headfile = "windows.h";
- func(0, ".", $headfile);
-
- sub func {
- our @dirs;
- our %name;
- my $fullpath;
- my ($Lv, $parent, $fname) = @_;
- my @all;
-
- foreach (@dirs) {
- if (-e "$_/$fname") {
- $fullpath = "$_/$fname";
- }
- }
-
- return if (exists $name{$fname});
- return if (! defined $fullpath);
-
- $name{$fname} = 1;
- Xprint($Lv, $parent, $fname);
- ReadFile(\@all, $fullpath);
-
- foreach (@all) {
- if (/#include ["<](.*?)[">]/) {
- func($Lv+1, $parent.":".$fname, $1);
- }
- }
- }
-
- sub Xprint {
- state $e = -1;
- my ($Lv, $parent, $fname) = @_;
- if ( $Lv <= $e) {
- print "\n";
- print " "x(length($parent) + ($Lv)*2 - 1);
- }
- print " > " . $fname;
- $e = $Lv;
- }
-
- sub ReadFile {
- my ($aref, $fullpath) = (shift, shift);
- open READ, "<", $fullpath or die "$!\n";
- @{$aref} = <READ>;
- close READ;
- }
复制代码 > windows.h > _mingw.h > sdkddkver.h
> winresrc.h > winuser.h
> winnt.h > winerror.h
> string.h > stddef.h
> basetsd.h
> pshpack4.h
> poppack.h
> winver.h
> dde.h
> dlgs.h
> commctrl.h > prsht.h
> stdarg.h
> windef.h
> wincon.h
> winbase.h
> wingdi.h
> winnls.h
> winnetwk.h
> winreg.h > reason.h
> winsvc.h
> cderr.h
> ddeml.h
> imm.h
> lzexpand.h
> mmsystem.h
> nb30.h
> rpc.h > rpcdce.h > basetyps.h
> rpcdcep.h
> rpcnsi.h
> rpcnterr.h
> excpt.h
> shellapi.h > pshpack2.h
> winperf.h
> commdlg.h > unknwn.h > objfwd.h
> wtypes.h > rpcndr.h > rpcnsip.h
> winspool.h
> winsock.h > mswsock.h
> ole2.h > objbase.h > stdlib.h
> objidl.h
> cguid.h
> olectlid.h
> oleauto.h > oaidl.h
> oleidl.h |