controllib.pl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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 %p2i; # - map from datafile+packagename to index in controlfile
  15. # (used if multiple packages can be listed). Key is
  16. # "S key" where S is the source and key is the packagename
  17. my $maxsubsts = 50;
  18. our %substvar; # - map with substitution variables
  19. my $parsechangelog = 'dpkg-parsechangelog';
  20. our @pkg_dep_fields = qw(Pre-Depends Depends Recommends Suggests Enhances
  21. Conflicts Breaks Replaces Provides);
  22. our @src_dep_fields = qw(Build-Depends Build-Depends-Indep
  23. Build-Conflicts Build-Conflicts-Indep);
  24. our $warnable_error = 1;
  25. our $quiet_warnings = 0;
  26. sub getfowner
  27. {
  28. my $getlogin = getlogin();
  29. if (!defined($getlogin)) {
  30. open(SAVEIN, "<&STDIN");
  31. open(STDIN, "<&STDERR");
  32. $getlogin = getlogin();
  33. close(STDIN);
  34. open(STDIN, "<&SAVEIN");
  35. close(SAVEIN);
  36. }
  37. if (!defined($getlogin)) {
  38. open(SAVEIN, "<&STDIN");
  39. open(STDIN, "<&STDOUT");
  40. $getlogin = getlogin();
  41. close(STDIN);
  42. open(STDIN, "<&SAVEIN");
  43. close(SAVEIN);
  44. }
  45. my @fowner;
  46. if (defined($ENV{'LOGNAME'})) {
  47. @fowner = getpwnam($ENV{'LOGNAME'});
  48. if (!@fowner) {
  49. die(sprintf(_g('unable to get login information for username "%s"'), $ENV{'LOGNAME'}));
  50. }
  51. } elsif (defined($getlogin)) {
  52. @fowner = getpwnam($getlogin);
  53. if (!@fowner) {
  54. die(sprintf(_g('unable to get login information for username "%s"'), $getlogin));
  55. }
  56. } else {
  57. warning(sprintf(_g('no utmp entry available and LOGNAME not defined; using uid of process (%d)'), $<));
  58. @fowner = getpwuid($<);
  59. if (!@fowner) {
  60. die (sprintf(_g('unable to get login information for uid %d'), $<));
  61. }
  62. }
  63. @fowner = @fowner[2,3];
  64. return @fowner;
  65. }
  66. sub capit {
  67. my @pieces = map { ucfirst(lc) } split /-/, $_[0];
  68. return join '-', @pieces;
  69. }
  70. #
  71. # Architecture library
  72. #
  73. my (@cpu, @os);
  74. my (%cputable, %ostable);
  75. my (%cputable_re, %ostable_re);
  76. my %debtriplet_to_debarch;
  77. my %debarch_to_debtriplet;
  78. {
  79. my $host_arch;
  80. sub get_host_arch()
  81. {
  82. return $host_arch if defined $host_arch;
  83. $host_arch = `dpkg-architecture -qDEB_HOST_ARCH`;
  84. $? && subprocerr("dpkg-architecture -qDEB_HOST_ARCH");
  85. chomp $host_arch;
  86. return $host_arch;
  87. }
  88. }
  89. sub get_valid_arches()
  90. {
  91. read_cputable() if (!@cpu);
  92. read_ostable() if (!@os);
  93. foreach my $os (@os) {
  94. foreach my $cpu (@cpu) {
  95. my $arch = debtriplet_to_debarch(split(/-/, $os, 2), $cpu);
  96. print $arch."\n" if defined($arch);
  97. }
  98. }
  99. }
  100. sub read_cputable
  101. {
  102. local $_;
  103. open CPUTABLE, "$pkgdatadir/cputable"
  104. or syserr(_g("unable to open cputable"));
  105. while (<CPUTABLE>) {
  106. if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
  107. $cputable{$1} = $2;
  108. $cputable_re{$1} = $3;
  109. push @cpu, $1;
  110. }
  111. }
  112. close CPUTABLE;
  113. }
  114. sub read_ostable
  115. {
  116. local $_;
  117. open OSTABLE, "$pkgdatadir/ostable"
  118. or syserr(_g("unable to open ostable"));
  119. while (<OSTABLE>) {
  120. if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
  121. $ostable{$1} = $2;
  122. $ostable_re{$1} = $3;
  123. push @os, $1;
  124. }
  125. }
  126. close OSTABLE;
  127. }
  128. sub read_triplettable()
  129. {
  130. read_cputable() if (!@cpu);
  131. local $_;
  132. open TRIPLETTABLE, "$pkgdatadir/triplettable"
  133. or syserr(_g("unable to open triplettable"));
  134. while (<TRIPLETTABLE>) {
  135. if (m/^(?!\#)(\S+)\s+(\S+)/) {
  136. my $debtriplet = $1;
  137. my $debarch = $2;
  138. if ($debtriplet =~ /<cpu>/) {
  139. foreach my $_cpu (@cpu) {
  140. (my $dt = $debtriplet) =~ s/<cpu>/$_cpu/;
  141. (my $da = $debarch) =~ s/<cpu>/$_cpu/;
  142. $debarch_to_debtriplet{$da} = $dt;
  143. $debtriplet_to_debarch{$dt} = $da;
  144. }
  145. } else {
  146. $debarch_to_debtriplet{$2} = $1;
  147. $debtriplet_to_debarch{$1} = $2;
  148. }
  149. }
  150. }
  151. close TRIPLETTABLE;
  152. }
  153. sub debtriplet_to_gnutriplet(@)
  154. {
  155. read_cputable() if (!@cpu);
  156. read_ostable() if (!@os);
  157. my ($abi, $os, $cpu) = @_;
  158. return undef unless defined($abi) && defined($os) && defined($cpu) &&
  159. exists($cputable{$cpu}) && exists($ostable{"$abi-$os"});
  160. return join("-", $cputable{$cpu}, $ostable{"$abi-$os"});
  161. }
  162. sub gnutriplet_to_debtriplet($)
  163. {
  164. my ($gnu) = @_;
  165. return undef unless defined($gnu);
  166. my ($gnu_cpu, $gnu_os) = split(/-/, $gnu, 2);
  167. return undef unless defined($gnu_cpu) && defined($gnu_os);
  168. read_cputable() if (!@cpu);
  169. read_ostable() if (!@os);
  170. my ($os, $cpu);
  171. foreach my $_cpu (@cpu) {
  172. if ($gnu_cpu =~ /^$cputable_re{$_cpu}$/) {
  173. $cpu = $_cpu;
  174. last;
  175. }
  176. }
  177. foreach my $_os (@os) {
  178. if ($gnu_os =~ /^(.*-)?$ostable_re{$_os}$/) {
  179. $os = $_os;
  180. last;
  181. }
  182. }
  183. return undef if !defined($cpu) || !defined($os);
  184. return (split(/-/, $os, 2), $cpu);
  185. }
  186. sub debtriplet_to_debarch(@)
  187. {
  188. read_triplettable() if (!%debtriplet_to_debarch);
  189. my ($abi, $os, $cpu) = @_;
  190. if (!defined($abi) || !defined($os) || !defined($cpu)) {
  191. return undef;
  192. } elsif (exists $debtriplet_to_debarch{"$abi-$os-$cpu"}) {
  193. return $debtriplet_to_debarch{"$abi-$os-$cpu"};
  194. } else {
  195. return undef;
  196. }
  197. }
  198. sub debarch_to_debtriplet($)
  199. {
  200. read_triplettable() if (!%debarch_to_debtriplet);
  201. local ($_) = @_;
  202. my $arch;
  203. # FIXME: 'any' is handled here, to be able to do debarch_eq('any', foo).
  204. if (/^any$/ || /^all$/) {
  205. return ($_, $_, $_);
  206. } elsif (/^linux-([^-]*)/) {
  207. # XXX: Might disappear in the future, not sure yet.
  208. $arch = $1;
  209. } else {
  210. $arch = $_;
  211. }
  212. my $triplet = $debarch_to_debtriplet{$arch};
  213. if (defined($triplet)) {
  214. return split('-', $triplet, 3);
  215. } else {
  216. return undef;
  217. }
  218. }
  219. sub debwildcard_to_debtriplet($)
  220. {
  221. local ($_) = @_;
  222. if (/any/) {
  223. if (/^([^-]*)-([^-]*)-(.*)/) {
  224. return ($1, $2, $3);
  225. } elsif (/^([^-]*)-([^-]*)$/) {
  226. return ('any', $1, $2);
  227. } else {
  228. return ($_, $_, $_);
  229. }
  230. } else {
  231. return debarch_to_debtriplet($_);
  232. }
  233. }
  234. sub debarch_eq($$)
  235. {
  236. my ($a, $b) = @_;
  237. my @a = debarch_to_debtriplet($a);
  238. my @b = debarch_to_debtriplet($b);
  239. return 0 if grep(!defined, (@a, @b));
  240. return ($a[0] eq $b[0] && $a[1] eq $b[1] && $a[2] eq $b[2]);
  241. }
  242. sub debarch_is($$)
  243. {
  244. my ($real, $alias) = @_;
  245. my @real = debarch_to_debtriplet($real);
  246. my @alias = debwildcard_to_debtriplet($alias);
  247. return 0 if grep(!defined, (@real, @alias));
  248. if (($alias[0] eq $real[0] || $alias[0] eq 'any') &&
  249. ($alias[1] eq $real[1] || $alias[1] eq 'any') &&
  250. ($alias[2] eq $real[2] || $alias[2] eq 'any')) {
  251. return 1;
  252. }
  253. return 0;
  254. }
  255. sub substvars {
  256. my ($v) = @_;
  257. my $lhs;
  258. my $vn;
  259. my $rhs = '';
  260. my $count = 0;
  261. while ($v =~ m/\$\{([-:0-9a-z]+)\}/i) {
  262. # If we have consumed more from the leftover data, then
  263. # reset the recursive counter.
  264. $count= 0 if (length($POSTMATCH) < length($rhs));
  265. $count < $maxsubsts ||
  266. &error(sprintf(_g("too many substitutions - recursive ? - in \`%s'"), $v));
  267. $lhs=$`; $vn=$1; $rhs=$';
  268. if (defined($substvar{$vn})) {
  269. $v= $lhs.$substvar{$vn}.$rhs;
  270. $count++;
  271. } else {
  272. warning(sprintf(_g("unknown substitution variable \${%s}"), $vn));
  273. $v= $lhs.$rhs;
  274. }
  275. }
  276. return $v;
  277. }
  278. my %fieldimps;
  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;