controllib.pl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use English;
  5. use POSIX qw(:errno_h);
  6. our $dpkglibdir;
  7. our $pkgdatadir;
  8. push(@INC,$dpkglibdir);
  9. require 'dpkg-gettext.pl';
  10. textdomain("dpkg-dev");
  11. our $sourcepackage; # - name of sourcepackage
  12. our %f; # - fields ???
  13. our %fi; # - map of fields values. keys are of the form "S# key"
  14. # where S is source (L is changelog, C is control)
  15. # and # is an index
  16. our %fieldimps;
  17. our %p2i; # - map from datafile+packagename to index in controlfile
  18. # (used if multiple packages can be listed). Key is
  19. # "S key" where S is the source and key is the packagename
  20. my $maxsubsts = 50;
  21. our %substvar; # - map with substitution variables
  22. my $parsechangelog = 'dpkg-parsechangelog';
  23. our @pkg_dep_fields = qw(Pre-Depends Depends Recommends Suggests Enhances
  24. Conflicts Replaces Provides);
  25. our @src_dep_fields = qw(Build-Depends Build-Depends-Indep
  26. Build-Conflicts Build-Conflicts-Indep);
  27. our $warnable_error = 1;
  28. our $quiet_warnings = 0;
  29. our $version;
  30. our $progname = $0;
  31. $progname = $& if $progname =~ m,[^/]+$,;
  32. sub getfowner
  33. {
  34. my $getlogin = getlogin();
  35. if (!defined($getlogin)) {
  36. open(SAVEIN, "<&STDIN");
  37. open(STDIN, "<&STDERR");
  38. $getlogin = getlogin();
  39. close(STDIN);
  40. open(STDIN, "<&SAVEIN");
  41. close(SAVEIN);
  42. }
  43. if (!defined($getlogin)) {
  44. open(SAVEIN, "<&STDIN");
  45. open(STDIN, "<&STDOUT");
  46. $getlogin = getlogin();
  47. close(STDIN);
  48. open(STDIN, "<&SAVEIN");
  49. close(SAVEIN);
  50. }
  51. my @fowner;
  52. if (defined($ENV{'LOGNAME'})) {
  53. @fowner = getpwnam($ENV{'LOGNAME'});
  54. if (!@fowner) {
  55. die(sprintf(_g('unable to get login information for username "%s"'), $ENV{'LOGNAME'}));
  56. }
  57. } elsif (defined($getlogin)) {
  58. @fowner = getpwnam($getlogin);
  59. if (!@fowner) {
  60. die(sprintf(_g('unable to get login information for username "%s"'), $getlogin));
  61. }
  62. } else {
  63. warning(sprintf(_g('no utmp entry available and LOGNAME not defined; using uid of process (%d)'), $<));
  64. @fowner = getpwuid($<);
  65. if (!@fowner) {
  66. die (sprintf(_g('unable to get login information for uid %d'), $<));
  67. }
  68. }
  69. @fowner = @fowner[2,3];
  70. return @fowner;
  71. }
  72. sub capit {
  73. my @pieces = map { ucfirst(lc) } split /-/, $_[0];
  74. return join '-', @pieces;
  75. }
  76. #
  77. # Architecture library
  78. #
  79. my (@cpu, @os);
  80. my (%cputable, %ostable);
  81. my (%cputable_re, %ostable_re);
  82. my %debtriplet_to_debarch;
  83. my %debarch_to_debtriplet;
  84. {
  85. my $host_arch;
  86. sub get_host_arch()
  87. {
  88. return $host_arch if defined $host_arch;
  89. $host_arch = `dpkg-architecture -qDEB_HOST_ARCH`;
  90. $? && subprocerr("dpkg-architecture -qDEB_HOST_ARCH");
  91. chomp $host_arch;
  92. return $host_arch;
  93. }
  94. }
  95. sub get_valid_arches()
  96. {
  97. read_cputable() if (!@cpu);
  98. read_ostable() if (!@os);
  99. foreach my $os (@os) {
  100. foreach my $cpu (@cpu) {
  101. my $arch = debtriplet_to_debarch(split(/-/, $os, 2), $cpu);
  102. print $arch."\n" if defined($arch);
  103. }
  104. }
  105. }
  106. sub read_cputable
  107. {
  108. local $_;
  109. open CPUTABLE, "$pkgdatadir/cputable"
  110. or syserr(_g("unable to open cputable"));
  111. while (<CPUTABLE>) {
  112. if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
  113. $cputable{$1} = $2;
  114. $cputable_re{$1} = $3;
  115. push @cpu, $1;
  116. }
  117. }
  118. close CPUTABLE;
  119. }
  120. sub read_ostable
  121. {
  122. local $_;
  123. open OSTABLE, "$pkgdatadir/ostable"
  124. or syserr(_g("unable to open ostable"));
  125. while (<OSTABLE>) {
  126. if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
  127. $ostable{$1} = $2;
  128. $ostable_re{$1} = $3;
  129. push @os, $1;
  130. }
  131. }
  132. close OSTABLE;
  133. }
  134. sub read_triplettable()
  135. {
  136. read_cputable() if (!@cpu);
  137. local $_;
  138. open TRIPLETTABLE, "$pkgdatadir/triplettable"
  139. or syserr(_g("unable to open triplettable"));
  140. while (<TRIPLETTABLE>) {
  141. if (m/^(?!\#)(\S+)\s+(\S+)/) {
  142. my $debtriplet = $1;
  143. my $debarch = $2;
  144. if ($debtriplet =~ /<cpu>/) {
  145. foreach my $_cpu (@cpu) {
  146. (my $dt = $debtriplet) =~ s/<cpu>/$_cpu/;
  147. (my $da = $debarch) =~ s/<cpu>/$_cpu/;
  148. $debarch_to_debtriplet{$da} = $dt;
  149. $debtriplet_to_debarch{$dt} = $da;
  150. }
  151. } else {
  152. $debarch_to_debtriplet{$2} = $1;
  153. $debtriplet_to_debarch{$1} = $2;
  154. }
  155. }
  156. }
  157. close TRIPLETTABLE;
  158. }
  159. sub debtriplet_to_gnutriplet(@)
  160. {
  161. read_cputable() if (!@cpu);
  162. read_ostable() if (!@os);
  163. my ($abi, $os, $cpu) = @_;
  164. return undef unless defined($abi) && defined($os) && defined($cpu) &&
  165. exists($cputable{$cpu}) && exists($ostable{"$abi-$os"});
  166. return join("-", $cputable{$cpu}, $ostable{"$abi-$os"});
  167. }
  168. sub gnutriplet_to_debtriplet($)
  169. {
  170. my ($gnu) = @_;
  171. return undef unless defined($gnu);
  172. my ($gnu_cpu, $gnu_os) = split(/-/, $gnu, 2);
  173. return undef unless defined($gnu_cpu) && defined($gnu_os);
  174. read_cputable() if (!@cpu);
  175. read_ostable() if (!@os);
  176. my ($os, $cpu);
  177. foreach my $_cpu (@cpu) {
  178. if ($gnu_cpu =~ /^$cputable_re{$_cpu}$/) {
  179. $cpu = $_cpu;
  180. last;
  181. }
  182. }
  183. foreach my $_os (@os) {
  184. if ($gnu_os =~ /^(.*-)?$ostable_re{$_os}$/) {
  185. $os = $_os;
  186. last;
  187. }
  188. }
  189. return undef if !defined($cpu) || !defined($os);
  190. return (split(/-/, $os, 2), $cpu);
  191. }
  192. sub debtriplet_to_debarch(@)
  193. {
  194. read_triplettable() if (!%debtriplet_to_debarch);
  195. my ($abi, $os, $cpu) = @_;
  196. if (!defined($abi) || !defined($os) || !defined($cpu)) {
  197. return undef;
  198. } elsif (exists $debtriplet_to_debarch{"$abi-$os-$cpu"}) {
  199. return $debtriplet_to_debarch{"$abi-$os-$cpu"};
  200. } else {
  201. return undef;
  202. }
  203. }
  204. sub debarch_to_debtriplet($)
  205. {
  206. read_triplettable() if (!%debarch_to_debtriplet);
  207. local ($_) = @_;
  208. if (/any/ || /all/) {
  209. return ($_, $_, $_);
  210. } elsif (/^([^-]*)-([^-]*)-(.*)/) {
  211. return ($1, $2, $3);
  212. } else {
  213. my $triplet = $debarch_to_debtriplet{$_};
  214. if (defined($triplet)) {
  215. return split('-', $triplet, 3);
  216. } else {
  217. return undef;
  218. }
  219. }
  220. }
  221. sub debarch_eq($$)
  222. {
  223. my ($a, $b) = @_;
  224. my @a = debarch_to_debtriplet($a);
  225. my @b = debarch_to_debtriplet($b);
  226. return 0 if grep(!defined, (@a, @b));
  227. return ($a[0] eq $b[0] && $a[1] eq $b[1] && $a[2] eq $b[2]);
  228. }
  229. sub debarch_is($$)
  230. {
  231. my ($real, $alias) = @_;
  232. my @real = debarch_to_debtriplet($real);
  233. my @alias = debarch_to_debtriplet($alias);
  234. return 0 if grep(!defined, (@real, @alias));
  235. if (($alias[0] eq $real[0] || $alias[0] eq 'any') &&
  236. ($alias[1] eq $real[1] || $alias[1] eq 'any') &&
  237. ($alias[2] eq $real[2] || $alias[2] eq 'any')) {
  238. return 1;
  239. }
  240. return 0;
  241. }
  242. sub substvars {
  243. my ($v) = @_;
  244. my $lhs;
  245. my $vn;
  246. my $rhs = '';
  247. my $count = 0;
  248. while ($v =~ m/\$\{([-:0-9a-z]+)\}/i) {
  249. # If we have consumed more from the leftover data, then
  250. # reset the recursive counter.
  251. $count= 0 if (length($POSTMATCH) < length($rhs));
  252. $count < $maxsubsts ||
  253. &error(sprintf(_g("too many substitutions - recursive ? - in \`%s'"), $v));
  254. $lhs=$`; $vn=$1; $rhs=$';
  255. if (defined($substvar{$vn})) {
  256. $v= $lhs.$substvar{$vn}.$rhs;
  257. $count++;
  258. } else {
  259. warning(sprintf(_g("unknown substitution variable \${%s}"), $vn));
  260. $v= $lhs.$rhs;
  261. }
  262. }
  263. return $v;
  264. }
  265. sub set_field_importance(@)
  266. {
  267. my @fields = @_;
  268. my $i = 1;
  269. grep($fieldimps{$_} = $i++, @fields);
  270. }
  271. sub sort_field_by_importance($$)
  272. {
  273. my ($a, $b) = @_;
  274. if (defined $fieldimps{$a} && defined $fieldimps{$b}) {
  275. $fieldimps{$a} <=> $fieldimps{$b};
  276. } elsif (defined($fieldimps{$a})) {
  277. -1;
  278. } elsif (defined($fieldimps{$b})) {
  279. 1;
  280. } else {
  281. $a cmp $b;
  282. }
  283. }
  284. sub outputclose {
  285. my ($varlistfile) = @_;
  286. for my $f (keys %f) {
  287. $substvar{"F:$f"} = $f{$f};
  288. }
  289. &parsesubstvars($varlistfile) if (defined($varlistfile));
  290. for my $f (sort sort_field_by_importance keys %f) {
  291. my $v = $f{$f};
  292. if (defined($varlistfile)) {
  293. $v= &substvars($v);
  294. }
  295. $v =~ m/\S/ || next; # delete whitespace-only fields
  296. $v =~ m/\n\S/ && &internerr(sprintf(_g("field %s has newline then non whitespace >%s<"), $f, $v));
  297. $v =~ m/\n[ \t]*\n/ && &internerr(sprintf(_g("field %s has blank lines >%s<"), $f, $v));
  298. $v =~ m/\n$/ && &internerr(sprintf(_g("field %s has trailing newline >%s<"), $f, $v));
  299. if (defined($varlistfile)) {
  300. $v =~ s/,[\s,]*,/,/g;
  301. $v =~ s/^\s*,\s*//;
  302. $v =~ s/\s*,\s*$//;
  303. }
  304. $v =~ s/\$\{\}/\$/g;
  305. print("$f: $v\n") || &syserr(_g("write error on control data"));
  306. }
  307. close(STDOUT) || &syserr(_g("write error on close control data"));
  308. }
  309. sub parsecontrolfile {
  310. my $controlfile = shift;
  311. $controlfile="./$controlfile" if $controlfile =~ m/^\s/;
  312. open(CDATA,"< $controlfile") || &error(sprintf(_g("cannot read control file %s: %s"), $controlfile, $!));
  313. binmode(CDATA);
  314. my $indices = parsecdata(\*CDATA, 'C', 1,
  315. sprintf(_g("control file %s"), $controlfile));
  316. $indices >= 2 || &error(_g("control file must have at least one binary package part"));
  317. for (my $i = 1; $i < $indices; $i++) {
  318. defined($fi{"C$i Package"}) ||
  319. &error(sprintf(_g("per-package paragraph %d in control ".
  320. "info file is missing Package line"),
  321. $i));
  322. }
  323. defined($fi{"C Source"}) ||
  324. &error(_g("source paragraph in control info file is ".
  325. "missing Source line"));
  326. }
  327. my $substvarsparsed = 0;
  328. sub parsesubstvars {
  329. my $varlistfile = shift;
  330. if (length($varlistfile) && !$substvarsparsed) {
  331. $varlistfile="./$varlistfile" if $varlistfile =~ m/\s/;
  332. if (open(SV,"< $varlistfile")) {
  333. binmode(SV);
  334. while (<SV>) {
  335. next if m/^\#/ || !m/\S/;
  336. s/\s*\n$//;
  337. m/^(\w[-:0-9A-Za-z]*)\=/ ||
  338. &error(sprintf(_g("bad line in substvars file %s at line %d"),
  339. $varlistfile, $.));
  340. $substvar{$1}= $';
  341. }
  342. close(SV);
  343. } elsif ($! != ENOENT ) {
  344. &error(sprintf(_g("unable to open substvars file %s: %s"),
  345. $varlistfile, $!));
  346. }
  347. $substvarsparsed = 1;
  348. }
  349. }
  350. sub parsedep {
  351. my ($dep_line, $use_arch, $reduce_arch) = @_;
  352. my @dep_list;
  353. my $host_arch = get_host_arch();
  354. foreach my $dep_and (split(/,\s*/m, $dep_line)) {
  355. my @or_list = ();
  356. ALTERNATE:
  357. foreach my $dep_or (split(/\s*\|\s*/m, $dep_and)) {
  358. my ($package, $relation, $version);
  359. $package = $1 if ($dep_or =~ s/^([a-zA-Z0-9][a-zA-Z0-9+._-]*)\s*//m);
  360. ($relation, $version) = ($1, $2)
  361. if ($dep_or =~ s/^\(\s*(=|<=|>=|<<?|>>?)\s*([^)]+).*\)\s*//m);
  362. my @arches;
  363. @arches = split(/\s+/m, $1) if ($use_arch && $dep_or =~ s/^\[([^]]+)\]\s*//m);
  364. if ($reduce_arch && @arches) {
  365. my $seen_arch='';
  366. foreach my $arch (@arches) {
  367. $arch=lc($arch);
  368. if ($arch =~ /^!/) {
  369. my $not_arch;
  370. ($not_arch = $arch) =~ s/^!//;
  371. if (debarch_is($host_arch, $not_arch)) {
  372. next ALTERNATE;
  373. } else {
  374. # This is equivilant to
  375. # having seen the current arch,
  376. # unless the current arch
  377. # is also listed..
  378. $seen_arch=1;
  379. }
  380. } elsif (debarch_is($host_arch, $arch)) {
  381. $seen_arch=1;
  382. next;
  383. }
  384. }
  385. if (! $seen_arch) {
  386. next;
  387. }
  388. }
  389. if (length($dep_or)) {
  390. warning(sprintf(_g("can't parse dependency %s"), $dep_and));
  391. return undef;
  392. }
  393. push @or_list, [ $package, $relation, $version, \@arches ];
  394. }
  395. push @dep_list, \@or_list;
  396. }
  397. \@dep_list;
  398. }
  399. sub showdep {
  400. my ($dep_list, $show_arch) = @_;
  401. my @and_list;
  402. foreach my $dep_and (@$dep_list) {
  403. my @or_list = ();
  404. foreach my $dep_or (@$dep_and) {
  405. my ($package, $relation, $version, $arch_list) = @$dep_or;
  406. push @or_list, $package . ($relation && $version ? " ($relation $version)" : '') . ($show_arch && @$arch_list ? " [@$arch_list]" : '');
  407. }
  408. push @and_list, join(' | ', @or_list);
  409. }
  410. join(', ', @and_list);
  411. }
  412. sub parsechangelog {
  413. my ($changelogfile, $changelogformat, $since) = @_;
  414. defined(my $c = open(CDATA, "-|")) || syserr(_g("fork for parse changelog"));
  415. if ($c) {
  416. binmode(CDATA);
  417. parsecdata(\*CDATA, 'L', 0, _g("parsed version of changelog"));
  418. close(CDATA);
  419. $? && subprocerr(_g("parse changelog"));
  420. } else {
  421. binmode(STDOUT);
  422. my @al = ($parsechangelog);
  423. push(@al,"-l$changelogfile");
  424. push(@al, "-F$changelogformat") if defined($changelogformat);
  425. push(@al, "-v$since") if defined($since);
  426. exec(@al) || &syserr("exec parsechangelog $parsechangelog");
  427. }
  428. }
  429. sub init_substvars
  430. {
  431. $substvar{'Format'} = 1.7;
  432. $substvar{'Newline'} = "\n";
  433. $substvar{'Space'} = " ";
  434. $substvar{'Tab'} = "\t";
  435. # XXX: Source-Version is now deprecated, remove in the future.
  436. $substvar{'Source-Version'}= $fi{"L Version"};
  437. $substvar{'binary:Version'} = $fi{"L Version"};
  438. $substvar{'source:Version'} = $fi{"L Version"};
  439. $substvar{'source:Version'} =~ s/\+b[0-9]+$//;
  440. $substvar{'source:Upstream-Version'} = $fi{"L Version"};
  441. $substvar{'source:Upstream-Version'} =~ s/-[^-]*$//;
  442. # FIXME: this needs all progs using controllib to set $version as 'our'.
  443. # We expect the calling program to set $version.
  444. $substvar{"dpkg:Version"} = $version;
  445. $substvar{"dpkg:Upstream-Version"} = $version;
  446. $substvar{"dpkg:Upstream-Version"} =~ s/-[^-]+$//;
  447. }
  448. sub init_substvar_arch()
  449. {
  450. $substvar{'Arch'} = get_host_arch();
  451. }
  452. sub checkpackagename {
  453. my $name = shift || '';
  454. $name =~ m/[^-+.0-9a-z]/o &&
  455. &error(sprintf(_g("source package name `%s' contains illegal character `%s'"), $name, $&));
  456. $name =~ m/^[0-9a-z]/o ||
  457. &error(sprintf(_g("source package name `%s' starts with non-alphanum"), $name));
  458. }
  459. sub checkversion {
  460. my $version = shift || '';
  461. $version =~ m/[^-+:.0-9a-zA-Z~]/o &&
  462. &error(sprintf(_g("version number contains illegal character `%s'"), $&));
  463. }
  464. sub setsourcepackage {
  465. my $v = shift;
  466. checkpackagename( $v );
  467. if (defined($sourcepackage)) {
  468. $v eq $sourcepackage ||
  469. &error(sprintf(_g("source package has two conflicting values - %s and %s"), $sourcepackage, $v));
  470. } else {
  471. $sourcepackage= $v;
  472. }
  473. }
  474. sub readmd5sum {
  475. (my $md5sum = shift) or return;
  476. $md5sum =~ s/^([0-9a-f]{32})\s*\*?-?\s*\n?$/$1/o
  477. || &failure(sprintf(_g("md5sum gave bogus output `%s'"), $md5sum));
  478. return $md5sum;
  479. }
  480. # XXX: Should not be a global!!
  481. my $whatmsg;
  482. sub parsecdata {
  483. my ($cdata, $source, $many);
  484. ($cdata, $source, $many, $whatmsg) = @_;
  485. # many=0: ordinary control data like output from dpkg-parsechangelog
  486. # many=1: many paragraphs like in source control file
  487. # many=-1: single paragraph of control data optionally signed
  488. my $index = '';
  489. my $cf = '';
  490. my $paraborder = 1;
  491. while (<$cdata>) {
  492. s/\s*\n$//;
  493. next if (m/^$/ and $paraborder);
  494. next if (m/^#/);
  495. $paraborder=0;
  496. if (m/^(\S+)\s*:\s*(.*)$/) {
  497. $cf = $1;
  498. my $v = $2;
  499. $cf= &capit($cf);
  500. $fi{"$source$index $cf"}= $v;
  501. $fi{"o:$source$index $cf"}= $1;
  502. if (lc $cf eq 'package') { $p2i{"$source $v"}= $index; }
  503. } elsif (m/^\s+\S/) {
  504. length($cf) || &syntax(_g("continued value line not in field"));
  505. $fi{"$source$index $cf"}.= "\n$_";
  506. } elsif (m/^-----BEGIN PGP/ && $many<0) {
  507. $many == -2 && syntax(_g("expected blank line before PGP signature"));
  508. while (<$cdata>) {
  509. last if m/^$/;
  510. }
  511. $many= -2;
  512. } elsif (m/^$/) {
  513. $paraborder = 1;
  514. if ($many>0) {
  515. $index++; $cf='';
  516. } elsif ($many == -2) {
  517. $_ = <$cdata> while defined($_) && $_ =~ /^\s*$/;
  518. length($_) ||
  519. &syntax(_g("expected PGP signature, found EOF after blank line"));
  520. s/\n$//;
  521. m/^-----BEGIN PGP/ ||
  522. &syntax(sprintf(_g("expected PGP signature, found something else \`%s'"), $_));
  523. $many= -3; last;
  524. } else {
  525. while (<$cdata>) {
  526. /^\s*$/ ||
  527. &syntax(_g("found several \`paragraphs' where only one expected"));
  528. }
  529. }
  530. } else {
  531. &syntax(_g("line with unknown format (not field-colon-value)"));
  532. }
  533. }
  534. $many == -2 && &syntax(_g("found start of PGP body but no signature"));
  535. if (length($cf)) { $index++; }
  536. $index || &syntax(_g("empty file"));
  537. return $index;
  538. }
  539. sub unknown {
  540. my $field = $_;
  541. warning(sprintf(_g("unknown information field '%s' in input data in %s"),
  542. $field, $_[0]));
  543. }
  544. sub syntax {
  545. &error(sprintf(_g("syntax error in %s at line %d: %s"), $whatmsg, $., $_[0]));
  546. }
  547. sub failure { die sprintf(_g("%s: failure: %s"), $progname, $_[0])."\n"; }
  548. sub syserr { die sprintf(_g("%s: failure: %s: %s"), $progname, $_[0], $!)."\n"; }
  549. sub error { die sprintf(_g("%s: error: %s"), $progname, $_[0])."\n"; }
  550. sub internerr { die sprintf(_g("%s: internal error: %s"), $progname, $_[0])."\n"; }
  551. sub warning
  552. {
  553. if (!$quiet_warnings) {
  554. warn sprintf(_g("%s: warning: %s"), $progname, $_[0])."\n";
  555. }
  556. }
  557. sub usageerr
  558. {
  559. printf(STDERR "%s: %s\n\n", $progname, "@_");
  560. &usage;
  561. exit(2);
  562. }
  563. sub warnerror
  564. {
  565. if ($warnable_error) {
  566. warning(@_);
  567. } else {
  568. error(@_);
  569. }
  570. }
  571. sub subprocerr {
  572. my ($p) = @_;
  573. require POSIX;
  574. if (POSIX::WIFEXITED($?)) {
  575. die sprintf(_g("%s: failure: %s gave error exit status %s"),
  576. $progname, $p, POSIX::WEXITSTATUS($?))."\n";
  577. } elsif (POSIX::WIFSIGNALED($?)) {
  578. die sprintf(_g("%s: failure: %s died from signal %s"),
  579. $progname, $p, POSIX::WTERMSIG($?))."\n";
  580. } else {
  581. die sprintf(_g("%s: failure: %s failed with unknown exit code %d"),
  582. $progname, $p, $?)."\n";
  583. }
  584. }
  585. 1;