[Perl]枚举(遍历)某个C语言库的依赖关系

There's more than one way to do it!
https://metacpan.org http://perlmonks.org
回复
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

[Perl]枚举(遍历)某个C语言库的依赖关系

帖子 523066680 »

tree.pl
=info 523066680@163.com 2015-06-09 =cut use IO::Handle; STDOUT->autoflush(1); our @dirs = ( "C:/MinGW/x86_64-w64-mingw32/include/GL", "C:/MinGW/x86_64-w64-mingw32/include", "C:/MinGW/Include" ); our %name; our %hash; my $headfile = "gl.h"; func(0, ".", $headfile); tree(\%hash); sub func { our @dirs; our %hash; our %name; my $fullpath; my ($Lv, $parent, $fname) = @_; my @all; return if (exists $name{$fname}); $name{$fname} = 1; $hash{$parent.":".$fname} = $Lv; foreach (@dirs) { $fullpath = "$_/$fname" if (-e "$_/$fname"); } return 0 if (! defined $fullpath); ReadFile(\@all, $fullpath); foreach (@all) { if (/#include\s+["<](.*)[">]/) { if ($Lv < 5) { func($Lv+1, $parent.":".$fname, $1); } } } } sub tree { my $ref = shift; my ($a, $b); my ($e, $v) = (-1, undef); foreach (sort keys %$ref) { $v = $ref->{$_}; s/(.*:)([^:]+)$/$2/; if ( $v <= $e) { print "\n" . " "x(length($1) - $v - 2 + ($v)*3); } print " > " . $2; $e = $v; } } sub ReadFile { my ($aref, $fullpath) = (shift, shift); open READ, "<", $fullpath or die "$!\n"; @{$aref} = <READ>; close READ; }
> gl.h > windows.h > _mingw.h > _cygwin.h > stddef.h > crtdefs.h
> _mingw_mac.h
> _mingw_secapi.h
> sdks/_mingw_ddk.h
> sdks/_mingw_directx.h
> vadefs.h
> cderr.h
> commdlg.h
> dde.h
> ddeml.h
> excpt.h
> imm.h
> lzexpand.h
> mcx.h
> mmsystem.h
> nb30.h
> ole.h
> rpc.h > rpcasync.h
> rpcdce.h > rpcdcep.h
> rpcnsi.h
> rpcnterr.h
> sdkddkver.h
> shellapi.h
> stdarg.h > _mingw_stdarg.h
> stralign.h > sec_api/stralign_s.h
> virtdisk.h
> winbase.h > apisetcconv.h
> bemapiset.h
> debugapi.h
> errhandlingapi.h
> fibersapi.h
> fileapi.h
> handleapi.h
> heapapi.h
> interlockedapi.h
> ioapiset.h
> jobapi.h
> libloaderapi.h
> memoryapi.h
> minwinbase.h
> namedpipeapi.h
> namespaceapi.h
> processenv.h
> processthreadsapi.h
> processtopologyapi.h
> profileapi.h
> realtimeapiset.h
> securityappcontainer.h
> securitybaseapi.h
> synchapi.h
> sysinfoapi.h
> systemtopologyapi.h
> threadpoolapiset.h
> threadpoollegacyapiset.h
> timezoneapi.h
> utilapiset.h
> winerror.h > fltwinerror.h
> wow64apiset.h
> wincon.h
> wincrypt.h > bcrypt.h
> ncrypt.h
> windef.h > minwindef.h > specstrings.h > sal.h
> winapifamily.h
> winnt.h > apiset.h
> basetsd.h
> ctype.h
> guiddef.h
> ktmtypes.h
> poppack.h
> psdk_inc/intrin-impl.h
> pshpack2.h
> pshpack4.h
> pshpack8.h
> string.h
> winefs.h
> wingdi.h > pshpack1.h
> winnetwk.h > wnnc.h
> winnls.h > datetimeapi.h
> stringapiset.h
> winperf.h
> winreg.h > reason.h
> winresrc.h > commctrl.rh
> dde.rh
> dlgs.h
> winnt.rh
> winuser.rh
> winver.h > _mingw_unicode.h
> winscard.h > SCardErr.h
> winioctl.h
> winsmcrd.h
> wtypes.h > ole2.h > objbase.h
> oleauto.h
> oleidl.h
> rpcndr.h > rpcnsip.h
> rpcsal.h
> wtypesbase.h
> winsock.h > _bsd_types.h
> _timeval.h
> inaddr.h
> psdk_inc/_fd_types.h
> psdk_inc/_ip_mreq1.h
> psdk_inc/_ip_types.h
> psdk_inc/_socket_types.h
> psdk_inc/_wsa_errnos.h
> psdk_inc/_wsadata.h
> psdk_inc/_xmitfile.h
> winspool.h > prsht.h
> winsvc.h
> winuser.h > tvout.h[Finished in 2.3s]
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 1 访客