1*f41ccc36Sespie# $OpenBSD: Archive.pm,v 1.8 2023/07/06 08:29:26 espie Exp $ 2dd9b5fdeSespie 3dd9b5fdeSespie# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org> 4b8664c47Sespie# Copyright (c) 2012 Marc Espie <espie@openbsd.org> 5dd9b5fdeSespie# 6dd9b5fdeSespie# Permission to use, copy, modify, and distribute this software for any 7dd9b5fdeSespie# purpose with or without fee is hereby granted, provided that the above 8dd9b5fdeSespie# copyright notice and this permission notice appear in all copies. 9dd9b5fdeSespie# 10dd9b5fdeSespie# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11dd9b5fdeSespie# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12dd9b5fdeSespie# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13dd9b5fdeSespie# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14dd9b5fdeSespie# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15dd9b5fdeSespie# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16dd9b5fdeSespie# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17dd9b5fdeSespie 18*f41ccc36Sespieuse v5.36; 19dd9b5fdeSespie 20dd9b5fdeSespiepackage LT::Archive; 21dd9b5fdeSespieuse LT::Trace; 22dd9b5fdeSespieuse LT::Exec; 23807ec17aSzhukuse LT::UList; 24dd9b5fdeSespieuse LT::Util; 253d0c3a99Sespieuse File::Path; 26dd9b5fdeSespie 27*f41ccc36Sespiesub extract($self, $dir, $archive) 28dd9b5fdeSespie{ 29dd9b5fdeSespie if (! -d $dir) { 30f98ddbc5Sespie tsay {"mkdir -p $dir"}; 31dd9b5fdeSespie File::Path::mkpath($dir); 32dd9b5fdeSespie } 33dd9b5fdeSespie LT::Exec->chdir($dir)->link('ar', 'x', $archive); 34dd9b5fdeSespie} 35dd9b5fdeSespie 36*f41ccc36Sespiesub get_objlist($self, $a) 37dd9b5fdeSespie{ 38dd9b5fdeSespie open(my $arh, '-|', 'ar', 't', $a); 39dd9b5fdeSespie my @o = <$arh>; 40dd9b5fdeSespie close $arh; 41dd9b5fdeSespie map { chomp; } @o; 42dd9b5fdeSespie return @o; 43dd9b5fdeSespie} 44dd9b5fdeSespie 45*f41ccc36Sespiesub get_symbollist($self, $filepath, $regex, $objlist) 46dd9b5fdeSespie{ 47dd9b5fdeSespie 48dd9b5fdeSespie if (@$objlist == 0) { 49dd9b5fdeSespie die "get_symbollist: object list is empty\n"; 50dd9b5fdeSespie } 51dd9b5fdeSespie 52f98ddbc5Sespie tsay {"generating symbol list in file: $filepath"}; 530f7d6912Sespie tsay {"object list is @$objlist" }; 549761804bSzhuk my $symbols = LT::UList->new; 55f98ddbc5Sespie open(my $sh, '-|', 'nm', '--', @$objlist) or 56f98ddbc5Sespie die "Error running nm on object list @$objlist\n"; 57dd9b5fdeSespie my $c = 0; 58dd9b5fdeSespie while (my $line = <$sh>) { 59dd9b5fdeSespie chomp $line; 60f98ddbc5Sespie tsay {"$c: $line"}; 61dd9b5fdeSespie if ($line =~ m/\S+\s+[BCDEGRST]\s+(.*)/) { 62dd9b5fdeSespie my $s = $1; 63dd9b5fdeSespie if ($s =~ m/$regex/) { 64dd9b5fdeSespie push @$symbols, $s; 65f98ddbc5Sespie tsay {"matched"}; 66dd9b5fdeSespie } 67dd9b5fdeSespie } 68dd9b5fdeSespie $c++; 69dd9b5fdeSespie } 70dd9b5fdeSespie open(my $fh, '>', $filepath) or die "Cannot open $filepath\n"; 71807ec17aSzhuk print $fh map { "$_\n" } sort @$symbols; 72dd9b5fdeSespie} 73dd9b5fdeSespie 74dd9b5fdeSespie1; 75