controllib.pl 18 KB

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