dpkg-source.pl 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. #! /usr/bin/perl
  2. my $dpkglibdir = ".";
  3. my $version = "1.3.0"; # This line modified by Makefile
  4. my @filesinarchive;
  5. my %dirincluded;
  6. my %notfileobject;
  7. my $fn;
  8. $diff_ignore_default_regexp = '^.*~$|^\..*\.swp|DEAD_JOE|(?:/CVS|/RCS|/.deps)(?:$|/.*$)';
  9. $sourcestyle = 'X';
  10. $dscformat = "1.0";
  11. use POSIX;
  12. use POSIX qw (:errno_h :signal_h);
  13. use strict 'refs';
  14. push (@INC, $dpkglibdir);
  15. require 'controllib.pl';
  16. # Make sure patch doesn't get any funny ideas
  17. delete $ENV{'POSIXLY_CORRECT'};
  18. sub usageversion {
  19. print STDERR
  20. "Debian GNU/Linux dpkg-source $version. Copyright (C) 1996
  21. Ian Jackson and Klee Dienes. This is free software; see the GNU
  22. General Public Licence version 2 or later for copying conditions.
  23. There is NO warranty.
  24. Usage: dpkg-source -x <filename>.dsc
  25. dpkg-source -b <directory> [<orig-directory>|<orig-targz>|\'\']
  26. Build options: -c<controlfile> get control info from this file
  27. -l<changelogfile> get per-version info from this file
  28. -F<changelogformat> force change log format
  29. -V<name>=<value> set a substitution variable
  30. -T<varlistfile> read variables here, not debian/substvars
  31. -D<field>=<value> override or add a .dsc field and value
  32. -U<field> remove a field
  33. -sa auto select orig source (-sA is default)
  34. -i[<regexp>] filter out files to ignore diffs of.
  35. Defaults to: '$diff_ignore_default_regexp'
  36. -sk use packed orig source (unpack & keep)
  37. -sp use packed orig source (unpack & remove)
  38. -su use unpacked orig source (pack & keep)
  39. -sr use unpacked orig source (pack & remove)
  40. -ss trust packed & unpacked orig src are same
  41. -sn there is no diff, do main tarfile only
  42. -sA,-sK,-sP,-sU,-sR like -sa,-sp,-sk,-su,-sr but may overwrite
  43. Extract options: -sp (default) leave orig source packed in current dir
  44. -sn do not copy original source to current dir
  45. -su unpack original source tree too
  46. General options: -h print this message
  47. ";
  48. }
  49. $i = 100;
  50. grep ($fieldimps {$_} = $i--,
  51. qw (Format Source Version Binary Origin Maintainer Architecture
  52. Standards-Version Build-Depends Build-Depends-Indep Build-Conflicts
  53. Build-Conflicts-Indep));
  54. while (@ARGV && $ARGV[0] =~ m/^-/) {
  55. $_=shift(@ARGV);
  56. if (m/^-b$/) {
  57. &setopmode('build');
  58. } elsif (m/^-x$/) {
  59. &setopmode('extract');
  60. } elsif (m/^-s([akpursnAKPUR])$/) {
  61. $sourcestyle= $1;
  62. } elsif (m/^-c/) {
  63. $controlfile= $';
  64. } elsif (m/^-l/) {
  65. $changelogfile= $';
  66. } elsif (m/^-F([0-9a-z]+)$/) {
  67. $changelogformat=$1;
  68. } elsif (m/^-D([^\=:]+)[=:]/) {
  69. $override{$1}= $';
  70. } elsif (m/^-U([^\=:]+)$/) {
  71. $remove{$1}= 1;
  72. } elsif (m/^-i(.*)$/) {
  73. $diff_ignore_regexp = $1 ? $1 : $diff_ignore_default_regexp;
  74. } elsif (m/^-V(\w[-:0-9A-Za-z]*)[=:]/) {
  75. $substvar{$1}= $';
  76. } elsif (m/^-T/) {
  77. $varlistfile= $';
  78. } elsif (m/^-h$/) {
  79. &usageversion; exit(0);
  80. } elsif (m/^--$/) {
  81. last;
  82. } else {
  83. &usageerr("unknown option $_");
  84. }
  85. }
  86. defined($opmode) || &usageerr("need -x or -b");
  87. if ($opmode eq 'build') {
  88. $sourcestyle =~ y/X/A/;
  89. $sourcestyle =~ m/[akpursnAKPUR]/ ||
  90. &usageerr("source handling style -s$sourcestyle not allowed with -b");
  91. @ARGV || &usageerr("-b needs a directory");
  92. @ARGV<=2 || &usageerr("-b takes at most a directory and an orig source argument");
  93. $dir= shift(@ARGV);
  94. $dir= "./$dir" unless $dir =~ m:^/:; $dir =~ s,/*$,,;
  95. stat($dir) || &error("cannot stat directory $dir: $!");
  96. -d $dir || &error("directory argument $dir is not a directory");
  97. $changelogfile= "$dir/debian/changelog" unless defined($changelogfile);
  98. $controlfile= "$dir/debian/control" unless defined($controlfile);
  99. &parsechangelog;
  100. &parsecontrolfile;
  101. $f{"Format"}=$dscformat;
  102. $archspecific=0;
  103. for $_ (keys %fi) {
  104. $v= $fi{$_};
  105. if (s/^C //) {
  106. #print STDERR "G key >$_< value >$v<\n";
  107. if (m/^Source$/) { &setsourcepackage; }
  108. elsif (m/^(Standards-Version|Origin|Maintainer)$/) { $f{$_}= $v; }
  109. elsif (m/^Build-(Depends|Conflicts)(-Indep)?$/i) { $f{$_}= $v; }
  110. elsif (s/^X[BC]*S[BC]*-//i) { $f{$_}= $v; }
  111. elsif (m/^(Section|Priority|Files|Bugs)$/ || m/^X[BC]+-/i) { }
  112. else { &unknown('general section of control info file'); }
  113. } elsif (s/^C(\d+) //) {
  114. #print STDERR "P key >$_< value >$v<\n";
  115. $i=$1; $p=$fi{"C$i Package"};
  116. push(@binarypackages,$p) unless $packageadded{$p}++;
  117. if (m/^Architecture$/) {
  118. #print STDERR "$p >$v< >".join(' ',@sourcearch)."<\n";
  119. if ($v eq 'any') {
  120. @sourcearch= ('any');
  121. } elsif ($v eq 'all') {
  122. if (!@sourcearch || $sourcearch[0] eq 'all') {
  123. @sourcearch= ('all');
  124. } else {
  125. @sourcearch= ('any');
  126. }
  127. } else {
  128. if (grep($sourcearch[0] eq $_, 'any','all')) {
  129. @sourcearch= ('any');
  130. } else {
  131. for $a (split(/\s+/,$v)) {
  132. &error("architecture $a only allowed on its own".
  133. " (list for package $p is \`$a')")
  134. if grep($a eq $_, 'any','all');
  135. push(@sourcearch,$a) unless $archadded{$a}++;
  136. }
  137. }
  138. }
  139. $f{'Architecture'}= join(' ',@sourcearch);
  140. } elsif (s/^X[BC]*S[BC]*-//i) {
  141. $f{$_}= $v;
  142. } elsif (m/^(Package|Essential|Pre-Depends|Depends|Provides)$/ ||
  143. m/^(Recommends|Suggests|Optional|Conflicts|Replaces)$/ ||
  144. m/^(Description|Section|Priority)$/ ||
  145. m/^X[CS]+-/i) {
  146. } else {
  147. &unknown("package's section of control info file");
  148. }
  149. } elsif (s/^L //) {
  150. #print STDERR "L key >$_< value >$v<\n";
  151. if (m/^Source$/) {
  152. &setsourcepackage;
  153. } elsif (m/^Version$/) {
  154. $f{$_}= $v;
  155. } elsif (s/^X[BS]*C[BS]*-//i) {
  156. $f{$_}= $v;
  157. } elsif (m/^(Maintainer|Changes|Urgency|Distribution|Date|Closes)$/ ||
  158. m/^X[BS]+-/i) {
  159. } else {
  160. &unknown("parsed version of changelog");
  161. }
  162. } else {
  163. &internerr("value from nowhere, with key >$_< and value >$v<");
  164. }
  165. }
  166. $f{'Binary'}= join(', ',@binarypackages);
  167. for $f (keys %override) { $f{&capit($f)}= $override{$f}; }
  168. for $f (qw(Version)) {
  169. defined($f{$f}) || &error("missing information for critical output field $f");
  170. }
  171. for $f (qw(Maintainer Architecture Standards-Version)) {
  172. defined($f{$f}) || &warn("missing information for output field $f");
  173. }
  174. defined($sourcepackage) || &error("unable to determine source package name !");
  175. $f{'Source'}= $sourcepackage;
  176. for $f (keys %remove) { delete $f{&capit($f)}; }
  177. $version= $f{'Version'};
  178. $version =~ s/^\d+://; $upstreamversion= $version; $upstreamversion =~ s/-[^-]*$//;
  179. $basenamerev= $sourcepackage.'_'.$version;
  180. $basename= $sourcepackage.'_'.$upstreamversion;
  181. $basedirname= $basename;
  182. #print STDERR ">$basedirname<\n";
  183. $basedirname =~ s/_/-/;
  184. #print STDERR ">$basedirname<\n";
  185. $origdir= "$dir.orig";
  186. $origtargz= "$basename.orig.tar.gz";
  187. if (@ARGV) {
  188. $origarg= shift(@ARGV);
  189. if (length($origarg)) {
  190. stat($origarg) || &error("cannot stat orig argument $origarg: $!");
  191. if (-d _) {
  192. $origdir= $origarg;
  193. $origdir= "./$origdir" unless $origdir =~ m,^/,; $origdir =~ s,/*$,,;
  194. $sourcestyle =~ y/aA/rR/;
  195. $sourcestyle =~ m/[ursURS]/ ||
  196. &error("orig argument is unpacked but source handling style".
  197. " -s$sourcestyle calls for packed (.orig.tar.gz)");
  198. } elsif (-f _) {
  199. $origtargz= $origarg;
  200. $sourcestyle =~ y/aA/pP/;
  201. $sourcestyle =~ m/[kpsKPS]/ ||
  202. &error("orig argument is packed but source handling style".
  203. " -s$sourcestyle calls for unpacked (.orig/)");
  204. } else {
  205. &error("orig argument $origarg is not a plain file or directory");
  206. }
  207. } else {
  208. $sourcestyle =~ y/aA/nn/;
  209. $sourcestyle =~ m/n/ ||
  210. &error("orig argument is empty (means no orig, no diff)".
  211. " but source handling style -s$sourcestyle wants something");
  212. }
  213. }
  214. if ($sourcestyle =~ m/[aA]/) {
  215. if (stat("$origtargz")) {
  216. -f _ || &error("packed orig \`$origtargz' exists but is not a plain file");
  217. $sourcestyle =~ y/aA/pP/;
  218. } elsif ($! != ENOENT) {
  219. &syserr("unable to stat putative packed orig \`$origtargz'");
  220. } elsif (stat("$origdir")) {
  221. -d _ || &error("unpacked orig \`$origdir' exists but is not a directory");
  222. $sourcestyle =~ y/aA/rR/;
  223. } elsif ($! != ENOENT) {
  224. &syserr("unable to stat putative unpacked orig \`$origdir'");
  225. } else {
  226. $sourcestyle =~ y/aA/nn/;
  227. }
  228. }
  229. $dirbase= $dir; $dirbase =~ s,/?$,,; $dirbase =~ s,[^/]+$,,; $dirname= $&;
  230. $dirname eq $basedirname || &warn("source directory \`$dir' is not <sourcepackage>".
  231. "-<upstreamversion> \`$basedirname'");
  232. if ($sourcestyle ne 'n') {
  233. $origdirbase= $origdir; $origdirbase =~ s,/?$,,;
  234. $origdirbase =~ s,[^/]+$,,; $origdirname= $&;
  235. $origdirname eq "$basedirname.orig" ||
  236. &warn(".orig directory name $origdirname is not <package>".
  237. "-<upstreamversion> (wanted $basedirname.orig)");
  238. $tardirbase= $origdirbase; $tardirname= $origdirname;
  239. $tarname= $origtargz;
  240. $tarname eq "$basename.orig.tar.gz" ||
  241. &warn(".orig.tar.gz name $tarname is not <package>_<upstreamversion>".
  242. ".orig.tar.gz (wanted $basename.orig.tar.gz)");
  243. } else {
  244. $tardirbase= $dirbase; $tardirname= $dirname;
  245. $tarname= "$basenamerev.tar.gz";
  246. }
  247. #print STDERR ">$dir|$origdir|$origtargz|$sourcestyle<\n";
  248. if ($sourcestyle =~ m/[nurUR]/) {
  249. if (stat($tarname)) {
  250. $sourcestyle =~ m/[nUR]/ ||
  251. &error("tarfile \`$tarname' already exists, not overwriting,".
  252. " giving up; use -sU or -sR to override");
  253. } elsif ($! != ENOENT) {
  254. &syserr("unable to check for existence of \`$tarname'");
  255. }
  256. #print STDERR ">$tarname|$tardirbase|$tardirname<\n";
  257. print("$progname: building $sourcepackage in $tarname\n")
  258. || &syserr("write building tar message");
  259. &forkgzipwrite("$tarname.new");
  260. defined($c2= fork) || &syserr("fork for tar");
  261. if (!$c2) {
  262. chdir($tardirbase) || &syserr("chdir to above (orig) source $tardirbase");
  263. #system('pwd && ls');
  264. open(STDOUT,">&GZIP") || &syserr("reopen gzip for tar");
  265. # FIXME: put `--' argument back when tar is fixed
  266. exec('tar','-cf','-',$tardirname); &syserr("exec tar");
  267. }
  268. close(GZIP);
  269. &reapgzip;
  270. $c2 == waitpid($c2,0) || &syserr("wait for tar");
  271. $? && !(WIFSIGNALED($c2) && WTERMSIG($c2) == SIGPIPE) && subprocerr("tar");
  272. rename("$tarname.new",$tarname) ||
  273. &syserr("unable to rename \`$tarname.new' (newly created) to \`$tarname'");
  274. } else {
  275. print("$progname: building $sourcepackage using existing $tarname\n")
  276. || &syserr("write using existing tar message");
  277. }
  278. addfile("$tarname");
  279. if ($sourcestyle =~ m/[kpKP]/) {
  280. if (stat($origdir)) {
  281. $sourcestyle =~ m/[KP]/ ||
  282. &error("orig dir \`$origdir' already exists, not overwriting,".
  283. " giving up; use -sA, -sK or -sP to override");
  284. erasedir($origdir);
  285. } elsif ($! != ENOENT) {
  286. &syserr("unable to check for existence of orig dir \`$origdir'");
  287. }
  288. $expectprefix= $origdir; $expectprefix =~ s,^\./,,;
  289. checktarsane($origtargz,$expectprefix);
  290. mkdir("$origtargz.tmp-nest",0755) ||
  291. &syserr("unable to create \`$origtargz.tmp-nest'");
  292. extracttar($origtargz,"$origtargz.tmp-nest",$expectprefix);
  293. rename("$origtargz.tmp-nest/$expectprefix",$expectprefix) ||
  294. &syserr("unable to rename \`$origtargz.tmp-nest/$expectprefix' to ".
  295. "\`$expectprefix'");
  296. rmdir("$origtargz.tmp-nest") ||
  297. &syserr("unable to remove \`$origtargz.tmp-nest'");
  298. }
  299. if ($sourcestyle =~ m/[kpursKPUR]/) {
  300. print("$progname: building $sourcepackage in $basenamerev.diff.gz\n")
  301. || &syserr("write building diff message");
  302. &forkgzipwrite("$basenamerev.diff.gz");
  303. defined($c2= open(FIND,"-|")) || &syserr("fork for find");
  304. if (!$c2) {
  305. chdir($dir) || &syserr("chdir to $dir for find");
  306. exec('find','.','-print0'); &syserr("exec find");
  307. }
  308. $/= "\0";
  309. file:
  310. while (defined($fn= <FIND>)) {
  311. $fn =~ s/\0$//;
  312. next file if $fn =~ m/$diff_ignore_regexp/o;
  313. $fn =~ s,^\./,,;
  314. lstat("$dir/$fn") || &syserr("cannot stat file $dir/$fn");
  315. if (-l _) {
  316. $type{$fn}= 'symlink';
  317. &checktype('-l') || next;
  318. defined($n= readlink("$dir/$fn")) ||
  319. &syserr("cannot read link $dir/$fn");
  320. defined($n2= readlink("$origdir/$fn")) ||
  321. &syserr("cannot read orig link $origdir/$fn");
  322. $n eq $n2 || &unrepdiff2("symlink to $n2","symlink to $n");
  323. } elsif (-f _) {
  324. $type{$fn}= 'plain file';
  325. if (!lstat("$origdir/$fn")) {
  326. $! == ENOENT || &syserr("cannot stat orig file $origdir/$fn");
  327. $ofn= '/dev/null';
  328. $ofnread= '/dev/null';
  329. } elsif (-f _) {
  330. $ofn= "$basedirname.orig/$fn";
  331. $ofnread= "$origdir/$fn";
  332. } else {
  333. &unrepdiff2("something else","plain file");
  334. next;
  335. }
  336. defined($c3= open(DIFFGEN,"-|")) || &syserr("fork for diff");
  337. if (!$c3) {
  338. $ENV{'LANG'}= 'C';
  339. $ENV{'LC_ALL'}= 'C';
  340. exec('diff','-u',
  341. '-L',"$basedirname.orig/$fn",
  342. '-L',"$ofn",
  343. '--',"$ofnread","$dir/$fn"); &syserr("exec diff");
  344. }
  345. $difflinefound= 0;
  346. $/= "\n";
  347. while (<DIFFGEN>) {
  348. if (m/^binary/i) {
  349. close(DIFFGEN); $/= "\0";
  350. &unrepdiff("binary file contents changed");
  351. next file;
  352. } elsif (m/^[-+\@ ]/) {
  353. $difflinefound=1;
  354. } elsif (m/^\\ No newline at end of file$/) {
  355. &warn("file $fn has no final newline ".
  356. "(either original or modified version)");
  357. } else {
  358. s/\n$//;
  359. &internerr("unknown line from diff -u on $fn: \`$_'");
  360. }
  361. print(GZIP $_) || &syserr("failed to write to gzip");
  362. }
  363. close(DIFFGEN); $/= "\0";
  364. if (WIFEXITED($?) && (($es=WEXITSTATUS($?))==0 || $es==1)) {
  365. if ($es==1 && !$difflinefound) {
  366. &unrepdiff("diff gave 1 but no diff lines found");
  367. }
  368. } else {
  369. subprocerr("diff on $dir/$fn");
  370. }
  371. } elsif (-p _) {
  372. $type{$fn}= 'pipe';
  373. &checktype('-p');
  374. } elsif (-b _ || -c _ || -S _) {
  375. &unrepdiff("device or socket is not allowed");
  376. } elsif (-d _) {
  377. $type{$fn}= 'directory';
  378. } else {
  379. &unrepdiff("unknown file type ($!)");
  380. }
  381. }
  382. close(FIND); $? && subprocerr("find on $dir");
  383. close(GZIP) || &syserr("finish write to gzip pipe");
  384. &reapgzip;
  385. defined($c2= open(FIND,"-|")) || &syserr("fork for 2nd find");
  386. if (!$c2) {
  387. chdir($origdir) || &syserr("chdir to $origdir for 2nd find");
  388. exec('find','.','-print0'); &syserr("exec 2nd find");
  389. }
  390. $/= "\0";
  391. while (defined($fn= <FIND>)) {
  392. $fn =~ s/\0$//;
  393. next if $fn =~ m/$diff_ignore_regexp/o;
  394. $fn =~ s,^\./,,;
  395. next if defined($type{$fn});
  396. lstat("$origdir/$fn") || &syserr("cannot check orig file $origdir/$fn");
  397. if (-f _) {
  398. &warn("ignoring deletion of file $fn");
  399. } elsif (-d _) {
  400. &warn("ignoring deletion of directory $fn");
  401. } elsif (-l _) {
  402. &warn("ignoring deletion of symlink $fn");
  403. } else {
  404. &unrepdiff2('not a file, directory or link','nonexistent');
  405. }
  406. }
  407. close(FIND); $? && subprocerr("find on $dirname");
  408. &addfile("$basenamerev.diff.gz");
  409. }
  410. if ($sourcestyle =~ m/[prPR]/) {
  411. erasedir($origdir);
  412. }
  413. print("$progname: building $sourcepackage in $basenamerev.dsc\n")
  414. || &syserr("write building message");
  415. open(STDOUT,"> $basenamerev.dsc") || &syserr("create $basenamerev.dsc");
  416. &outputclose(1);
  417. if ($ur) {
  418. print(STDERR "$progname: unrepresentable changes to source\n")
  419. || &syserr("write error msg: $!");
  420. exit(1);
  421. }
  422. exit(0);
  423. } else {
  424. $sourcestyle =~ y/X/p/;
  425. $sourcestyle =~ m/[pun]/ ||
  426. &usageerr("source handling style -s$sourcestyle not allowed with -x");
  427. @ARGV==1 || &usageerr("-x needs exactly one argument, the .dsc");
  428. $dsc= shift(@ARGV);
  429. $dsc= "./$dsc" unless $dsc =~ m:^/:;
  430. $dscdir= $dsc; $dscdir= "./$dscdir" unless $dsc =~ m,^/|^\./,;
  431. $dscdir =~ s,/[^/]+$,,;
  432. open(CDATA,"< $dsc") || &error("cannot open .dsc file $dsc: $!");
  433. &parsecdata('S',-1,"source control file $dsc");
  434. close(CDATA);
  435. for $f (qw(Source Version Files)) {
  436. defined($fi{"S $f"}) ||
  437. &error("missing critical source control field $f");
  438. }
  439. if (defined $fi{'S Format'}) {
  440. $dscformat=$fi{'S Format'};
  441. if (not $dscformat =~ /^1\./) {
  442. &error("Unsupported format of .dsc file ($dscformat)");
  443. }
  444. }
  445. $sourcepackage =~ m/[^.0-9]/ &&
  446. &error("dsc format contains illegal character \`$&'");
  447. $sourcepackage= $fi{'S Source'};
  448. $sourcepackage =~ m/[^-+.0-9a-z]/ &&
  449. &error("source package name contains illegal character \`$&'");
  450. $sourcepackage =~ m/^[0-9a-z]./ ||
  451. &error("source package name is too short or starts with non-alphanum");
  452. $version= $fi{'S Version'};
  453. $version =~ m/[^-+:.0-9a-zA-Z]/ &&
  454. &error("version number contains illegal character \`$&'");
  455. $version =~ s/^\d+://;
  456. if ($version =~ m/-([^-]+)$/) {
  457. $baseversion= $`; $revision= $1;
  458. } else {
  459. $baseversion= $version; $revision= '';
  460. }
  461. $files= $fi{'S Files'};
  462. for $file (split(/\n /,$files)) {
  463. next if $file eq '';
  464. $file =~ m/^([0-9a-f]{32})[ \t]+(\d+)[ \t]+([0-9a-zA-Z][-+:.,=0-9a-zA-Z_]+)$/
  465. || &error("Files field contains bad line \`$file'");
  466. ($md5sum{$3},$size{$3},$file) = ($1,$2,$3);
  467. &setfile(\$tarfile) if $file =~ m/\.tar\.gz$/;
  468. &setfile(\$difffile) if $file =~ m/\.diff\.gz$/;
  469. }
  470. $newdirectory= $sourcepackage.'-'.$baseversion;
  471. $expectprefix= $newdirectory; $expectprefix.= '.orig' if length($difffile);
  472. length($tarfile) || &error("no tarfile in Files field");
  473. checkstats($tarfile);
  474. checkstats($difffile) if length($difffile);
  475. checktarsane("$dscdir/$tarfile",$expectprefix);
  476. if (length($difffile)) {
  477. &forkgzipread("$dscdir/$difffile");
  478. $/="\n";
  479. $_ = <GZIP>;
  480. while ($_ || !eof(GZIP)) {
  481. # read file header (---/+++ pair)
  482. s/\n$// or &error("diff is missing trailing newline");
  483. /^--- / or &error("expected ^--- in line $. of diff");
  484. $fn= $';
  485. substr($fn,0,length($expectprefix)+1) eq "$expectprefix/" ||
  486. &error("diff patches file ($fn) not in expected subdirectory");
  487. $fn =~ m/\.dpkg-orig$/ &&
  488. &error("diff patches file with name ending .dpkg-orig");
  489. $dirname= $fn;
  490. if ($dirname =~ s,/[^/]+$,, && !defined($dirincluded{$dirname})) {
  491. $dirtocreate{$dirname} = 1;
  492. }
  493. defined($notfileobject{$fn}) &&
  494. &error("diff patches something which is not a plain file");
  495. $_= <GZIP>; s/\n$// ||
  496. &error("diff finishes in middle of ---/+++ (line $.)");
  497. $_ eq '+++ '.$newdirectory.substr($fn,length($expectprefix)) ||
  498. &error("line after --- for file $fn isn't as expected");
  499. $filepatched{$fn}++ && &error("diff patches file $fn twice");
  500. # read hunks
  501. my $hunk = 0;
  502. while (($_ = <GZIP>) && !/^--- /) {
  503. # read hunk header (@@)
  504. s/\n$// or &error("diff is missing trailing newline");
  505. next if /^\\ No newline/;
  506. /^@@ -\d+(,(\d+))? \+\d+(,(\d+))? @\@$/ or
  507. &error("Expected ^@@ in line $. of diff");
  508. my ($olines, $nlines) = ($1 ? $2 : 1, $3 ? $4 : 1);
  509. ++$hunk;
  510. # read hunk
  511. while ($olines || $nlines) {
  512. $_ = <GZIP> or &error("unexpected end of diff");
  513. s/\n$// or &error("diff is missing trailing newline");
  514. next if /^\\ No newline/;
  515. if (/^ /) { --$olines; --$nlines; }
  516. elsif (/^-/) { --$olines; }
  517. elsif (/^\+/) { --$nlines; }
  518. else { &error("expected [ +-] at start of line $. of diff"); }
  519. }
  520. }
  521. $hunk or &error("expected ^\@\@ at line $. of diff");
  522. }
  523. close(GZIP);
  524. &reapgzip;
  525. }
  526. print("$progname: extracting $sourcepackage in $newdirectory\n")
  527. || &syserr("write extracting message");
  528. &erasedir($newdirectory);
  529. &erasedir("$newdirectory.orig");
  530. mkdir("$expectprefix.tmp-nest",0755)
  531. || &syserr("unable to create \`$expectprefix.tmp-nest'");
  532. system "chmod", "g-s", "$expectprefix.tmp-nest";
  533. extracttar("$dscdir/$tarfile","$expectprefix.tmp-nest","$expectprefix");
  534. rename("$expectprefix.tmp-nest/$expectprefix","$expectprefix")
  535. || &syserr("unable to rename \`$expectprefix.tmp-nest/$expectprefix' "
  536. ."to \`$expectprefix'");
  537. rmdir("$expectprefix.tmp-nest")
  538. || &syserr("unable to remove \`$expectprefix.tmp-nest'");
  539. for $dircreate (keys %dirtocreate) {
  540. $dircreatem= "";
  541. for $dircreatep (split("/",$dirc)) {
  542. $dircreatem.= $dircreatep;
  543. if (!lstat($dircreatem)) {
  544. $! == ENOENT || &syserr("cannot stat $dircreatem");
  545. mkdir($dircreatem,0777)
  546. || &syserr("failed to create $dircreatem subdirectory");
  547. }
  548. else {
  549. -d _ || &error("diff patches file in directory \`$dircreate',"
  550. ." but $dircreatem isn't a directory !");
  551. }
  552. }
  553. }
  554. if (length($difffile)) {
  555. rename($expectprefix,$newdirectory) ||
  556. &syserr("failed to rename newly-extracted $expectprefix to $newdirectory");
  557. if ($sourcestyle =~ m/u/) {
  558. mkdir("$expectprefix.tmp-nest",0755)
  559. || &syserr("unable to create \`$expectprefix.tmp-nest'");
  560. system "chmod", "g-s", "$expectprefix.tmp-nest";
  561. extracttar("$dscdir/$tarfile","$expectprefix.tmp-nest",
  562. "$expectprefix");
  563. rename("$expectprefix.tmp-nest/$expectprefix","$expectprefix")
  564. || &syserr("unable to rename \`$expectprefix.tmp-nest/"
  565. ."$expectprefix' to \`$expectprefix'");
  566. rmdir("$expectprefix.tmp-nest")
  567. || &syserr("unable to remove \`$expectprefix.tmp-nest'");
  568. } elsif ($sourcestyle =~ m/p/) {
  569. stat("$dscdir/$tarfile") ||
  570. &syserr("failed to stat \`$dscdir/$tarfile' to see if need to copy");
  571. ($dsctardev,$dsctarino) = stat _;
  572. $dumptar= $sourcepackage.'_'.$baseversion.'.orig.tar.gz';
  573. if (!stat($dumptar)) {
  574. $! == ENOENT || &syserr("failed to check destination \`$dumptar'".
  575. " to see if need to copy");
  576. } else {
  577. ($dumptardev,$dumptarino) = stat _;
  578. if ($dumptardev == $dsctardev && $dumptarino == $dsctarino) {
  579. $dumptar= '';
  580. }
  581. }
  582. if (length($dumptar)) {
  583. system('cp','--',"$dscdir/$tarfile","$dumptar");
  584. $? && subprocerr("cp $dscdir/$tarfile to $dumptar");
  585. }
  586. }
  587. &forkgzipread("$dscdir/$difffile");
  588. defined($c2= fork) || &syserr("fork for patch");
  589. if (!$c2) {
  590. open(STDIN,"<&GZIP") || &syserr("reopen gzip for patch");
  591. chdir($newdirectory) || &syserr("chdir to $newdirectory for patch");
  592. $ENV{'LANG'}= 'C';
  593. exec('patch','-s','-t','-F','0','-N','-p1','-u',
  594. '-V','never','-g0','-b','-z','.dpkg-orig');
  595. &syserr("exec patch");
  596. }
  597. close(GZIP);
  598. $c2 == waitpid($c2,0) || &syserr("wait for patch");
  599. $? && subprocerr("patch");
  600. &reapgzip;
  601. for $fn (keys %filepatched) {
  602. $ftr= "$newdirectory/".substr($fn,length($expectprefix)+1).".dpkg-orig";
  603. unlink($ftr) || &syserr("remove patch backup file $ftr");
  604. }
  605. if (!(@s= lstat("$newdirectory/debian/rules"))) {
  606. $! == ENOENT || &syserr("cannot stat $newdirectory/debian/rules");
  607. &warn("$newdirectory/debian/rules does not exist");
  608. } elsif (-f _) {
  609. chmod($s[2] | 0111, "$newdirectory/debian/rules") ||
  610. &syserr("cannot make $newdirectory/debian/rules executable");
  611. } else {
  612. &warn("$newdirectory/debian/rules is not a plain file");
  613. }
  614. }
  615. $execmode= 0777 & ~umask;
  616. (@s= stat('.')) || &syserr("cannot stat \`.'");
  617. $dirmode= $execmode | ($s[2] & 02000);
  618. $plainmode= $execmode & ~0111;
  619. $fifomode= ($plainmode & 0222) | (($plainmode & 0222) << 1);
  620. for $fn (@filesinarchive) {
  621. $fn= substr($fn,length($expectprefix)+1);
  622. $fn= "$newdirectory/$fn";
  623. (@s= lstat($fn)) || &syserr("cannot stat extracted object \`$fn'");
  624. $mode= $s[2];
  625. if (-d _) {
  626. $newmode= $dirmode;
  627. } elsif (-f _) {
  628. $newmode= ($mode & 0111) ? $execmode : $plainmode;
  629. } elsif (-p _) {
  630. $newmode= $fifomode;
  631. } elsif (!-l _) {
  632. &internerr("unknown object \`$fn' after extract (mode ".
  633. sprintf("0%o",$mode).")");
  634. } else { next; }
  635. next if ($mode & 07777) == $newmode;
  636. chmod($newmode,$fn) ||
  637. &syserr(sprintf("cannot change mode of \`%s' to 0%o from 0%o",
  638. $fn,$newmode,$mode));
  639. }
  640. exit(0);
  641. }
  642. sub checkstats {
  643. my ($f) = @_;
  644. my @s;
  645. my $m;
  646. open(STDIN,"< $dscdir/$f") || &syserr("cannot read $dscdir/$f");
  647. (@s= stat(STDIN)) || &syserr("cannot fstat $dscdir/$f");
  648. $s[7] == $size{$f} || &error("file $f has size $s[7] instead of expected $size{$f}");
  649. $m= `md5sum`; $? && subprocerr("md5sum $f"); $m =~ s/\n$//;
  650. $m =~ m/^[0-9a-f]{32}$/ || &failure("md5sum of $f gave bad output \`$m'");
  651. $m eq $md5sum{$f} || &error("file $f has md5sum $m instead of expected $md5sum{$f}");
  652. open(STDIN,"</dev/null") || &syserr("reopen stdin from /dev/null");
  653. }
  654. sub erasedir {
  655. my ($dir) = @_;
  656. if (!lstat($dir)) {
  657. $! == ENOENT && return;
  658. &syserr("cannot stat directory $dir (before removal)");
  659. }
  660. system 'rm','-rf','--',$dir;
  661. $? && subprocerr("rm -rf $dir");
  662. if (!stat($dir)) {
  663. $! == ENOENT && return;
  664. &syserr("unable to check for removal of dir \`$dir'");
  665. }
  666. &failure("rm -rf failed to remove \`$dir'");
  667. }
  668. use strict 'vars';
  669. sub checktarcpio {
  670. my ($tarfileread, $wpfx) = @_;
  671. my ($tarprefix, $c2);
  672. @filesinarchive = ();
  673. # make <CPIO> read from the uncompressed archive file
  674. &forkgzipread ("$tarfileread");
  675. if (! defined ($c2 = open (CPIO,"-|"))) { &syserr ("fork for cpio"); }
  676. if (!$c2) {
  677. open (STDIN,"<&GZIP") || &syserr ("reopen gzip for cpio");
  678. &cpiostderr;
  679. exec ('cpio','-0t');
  680. &syserr ("exec cpio");
  681. }
  682. close (GZIP);
  683. $/ = "\0";
  684. open (CPIO, "<cpiolog");
  685. while (defined ($fn = <CPIO>)) {
  686. $fn =~ s/\0$//;
  687. # store printable name of file for error messages
  688. my $pname = $fn;
  689. $pname =~ y/ -~/?/c;
  690. if (! $tarprefix) {
  691. if ($fn =~ m/\n/) {
  692. &error("first output from cpio -0t (from \`$tarfileread') ".
  693. "contains newline - you probably have an out of ".
  694. "date version of cpio. GNU cpio 2.4.2-2 is known to work");
  695. }
  696. $tarprefix = ($fn =~ m,([^/]*)[/],)[0];
  697. # need to check for multiple dots on some operating systems
  698. # empty tarprefix (due to regex failer) will match emptry string
  699. if ($tarprefix =~ /^[.]*$/) {
  700. &error("tarfile \`$tarfileread' does not extract into a ".
  701. "directory off the current directory ($tarprefix from $pname)");
  702. }
  703. }
  704. if ($fn =~ m/\n/) {
  705. &error ("tarfile \`$tarfileread' contains object with".
  706. " newline in its name ($pname)");
  707. }
  708. next if ($fn eq '././@LongLink');
  709. my $fprefix = substr ($fn, 0, length ($tarprefix));
  710. my $slash = substr ($fn, length ($tarprefix), 1);
  711. if ((($slash ne '/') && ($slash ne '')) || ($fprefix ne $tarprefix)) {
  712. &error ("tarfile \`$tarfileread' contains object ($pname) ".
  713. "not in expected directory ($tarprefix)");
  714. }
  715. # need to check for multiple dots on some operating systems
  716. if ($fn =~ m/[.]{2,}/) {
  717. &error ("tarfile \`$tarfileread' contains object with".
  718. " /../ in its name ($pname)");
  719. }
  720. push (@filesinarchive, $fn);
  721. }
  722. close (CPIO);
  723. $? && subprocerr ("cpio");
  724. &reapgzip;
  725. $/= "\n";
  726. my $tarsubst = quotemeta ($tarprefix);
  727. @filesinarchive = map { s/^$tarsubst/$wpfx/; $_ } @filesinarchive;
  728. return $tarprefix;
  729. }
  730. sub checktarsane {
  731. my ($tarfileread, $wpfx) = @_;
  732. my ($c2);
  733. %dirincluded = ();
  734. %notfileobject = ();
  735. my $tarprefix = &checktarcpio ($tarfileread, $wpfx);
  736. # make <TAR> read from the uncompressed archive file
  737. &forkgzipread ("$tarfileread");
  738. if (! defined ($c2 = open (TAR,"-|"))) { &syserr ("fork for tar -t"); }
  739. if (! $c2) {
  740. $ENV{'LANG'}= 'C';
  741. open (STDIN, "<&GZIP") || &syserr ("reopen gzip for tar -t");
  742. exec ('tar', '-vvtf', '-'); &syserr ("exec tar -vvtf -");
  743. }
  744. close (GZIP);
  745. my $efix= 0;
  746. open (TAR, "<tarlog");
  747. while (<TAR>) {
  748. chomp;
  749. if (! m,^(\S{10})\s,) {
  750. &error("tarfile \`$tarfileread' contains unknown object ".
  751. "listed by tar as \`$_'");
  752. }
  753. my $mode = $1;
  754. $mode =~ s/^([-dpsl])// ||
  755. &error("tarfile \`$tarfileread' contains object \`$fn' with ".
  756. "unknown or forbidden type \`".substr($_,0,1)."'");
  757. my $type = $&;
  758. if ($mode =~ /^l/) { $_ =~ s/ -\> .*//; }
  759. s/ link to .+//;
  760. if (length ($_) <= 48) {
  761. &error ("tarfile \`$tarfileread' contains incomplete entry \`$_'\n");
  762. }
  763. my $tarfn = substr ($_, 48, length ($_) - 48);
  764. $tarfn = deoctify ($tarfn);
  765. # store printable name of file for error messages
  766. my $pname = $tarfn;
  767. $pname =~ y/ -~/?/c;
  768. # fetch name of file as given by cpio
  769. $fn = $filesinarchive[$efix++];
  770. if ($tarfn ne $fn) {
  771. if ((length ($fn) == 99) && (length ($tarfn) >= 99)
  772. && (substr ($fn, 0, 99) eq substr ($tarfn, 0, 99))) {
  773. # this file doesn't match because cpio truncated the name
  774. # to the first 100 characters. let it slide for now.
  775. &warn ("filename \`$pname' was truncated by cpio;" .
  776. " unable to check full pathname");
  777. } else {
  778. &error ("tarfile \`$tarfileread' contains unexpected object".
  779. " listed by tar as \`$_'; expected \`$pname'");
  780. }
  781. }
  782. # if cpio truncated the name above,
  783. # we still can't allow files to expand into /../
  784. # need to check for multiple dots on some operating systems
  785. if ($tarfn =~ m/[.]{2,}/) {
  786. &error ("tarfile \`$tarfileread' contains object with".
  787. "/../ in its name ($pname)");
  788. }
  789. if ($tarfn =~ /\.dpkg-orig$/) {
  790. &error ("tarfile \`$tarfileread' contains file with name ending in .dpkg-orig");
  791. }
  792. if ($mode =~ /[sStT]/ && $type ne 'd') {
  793. &error ("tarfile \`$tarfileread' contains setuid, setgid".
  794. " or sticky object \`$pname'");
  795. }
  796. if ($tarfn eq "$tarprefix/debian" && $type ne 'd') {
  797. &error ("tarfile \`$tarfileread' contains object \`debian'".
  798. " that isn't a directory");
  799. }
  800. if ($type eq 'd') { $tarfn =~ s,/$,,; }
  801. my $dirname = $tarfn;
  802. if (($dirname =~ s,/[^/]+$,,) && (! defined ($dirincluded{$dirname}))) {
  803. &error ("tarfile \`$tarfileread' contains object \`$pname' but its containing ".
  804. "directory \`$dirname' does not precede it");
  805. }
  806. if ($type eq 'd') { $dirincluded{$tarfn} = 1; }
  807. if ($type ne '-') { $notfileobject{$tarfn} = 1; }
  808. }
  809. close (TAR);
  810. #$? && subprocerr ("tar -vvtf");
  811. &reapgzip;
  812. my $tarsubst = quotemeta ($tarprefix);
  813. %dirincluded = map { s/^$tarsubst/$wpfx/; $_=>1 } (keys %dirincluded);
  814. %notfileobject = map { s/^$tarsubst/$wpfx/; $_=>1 } (keys %notfileobject);
  815. }
  816. no strict 'vars';
  817. sub extracttar {
  818. my ($tarfileread,$dirchdir,$newtopdir) = @_;
  819. &forkgzipread("$tarfileread");
  820. defined($c2= fork) || &syserr("fork for tar -xkf -");
  821. if (!$c2) {
  822. open(STDIN,"<&GZIP") || &syserr("reopen gzip for tar -xkf -");
  823. &cpiostderr;
  824. chdir("$dirchdir") || &syserr("cannot chdir to \`$dirchdir' for tar extract");
  825. exec('tar','-xkf','-'); &syserr("exec tar -xkf -");
  826. }
  827. close(GZIP);
  828. $c2 == waitpid($c2,0) || &syserr("wait for tar -xkf -");
  829. $? && subprocerr("tar -xkf -");
  830. &reapgzip;
  831. opendir(D,"$dirchdir") || &syserr("Unable to open dir $dirchdir");
  832. @dirchdirfiles = grep($_ ne "." && $_ ne "..",readdir(D));
  833. closedir(D) || &syserr("Unable to close dir $dirchdir");
  834. if (@dirchdirfiles==1 && -d "$dirchdir/$dirchdirfiles[0]") {
  835. if ("$dirchdir/$dirchdirfiles[0]" ne "$dirchdir/$newtopdir") {
  836. rename("$dirchdir/$dirchdirfiles[0]", "$dirchdir/$newtopdir") ||
  837. &syserr("Unable to rename $dirchdir/$dirchdirfiles[0] to ".
  838. "$dirchdir/$newtopdir");
  839. }
  840. } else {
  841. mkdir("$dirchdir/$newtopdir", 0777) ||
  842. &syserr("Unable to mkdir $dirchdir/$newtopdir");
  843. for (@dirchdirfiles) {
  844. rename("$dirchdir/$_", "$dirchdir/$newtopdir/$_") ||
  845. &syserr("Unable to rename $dirchdir/$_ to ".
  846. "$dirchdir/$newtopdir/$_");
  847. }
  848. }
  849. }
  850. sub cpiostderr {
  851. open(STDERR,"| egrep -v '^[0-9]+ blocks\$' >&2") ||
  852. &syserr("reopen stderr for tar to grep out blocks message");
  853. }
  854. sub setfile {
  855. my ($varref) = @_;
  856. if (defined ($$varref)) {
  857. &error ("repeated file type - files " . $$varref . " and $file");
  858. }
  859. $$varref = $file;
  860. }
  861. sub checktype {
  862. if (!lstat("$origdir/$fn")) {
  863. &unrepdiff2("nonexistent",$type{$fn});
  864. } else {
  865. $v= eval("$_[0] _ ? 2 : 1"); $v || &internerr("checktype $@ ($_[0])");
  866. return 1 if $v == 2;
  867. &unrepdiff2("something else",$type{$fn});
  868. }
  869. return 0;
  870. }
  871. sub setopmode {
  872. defined($opmode) && &usageerr("only one of -x or -b allowed, and only once");
  873. $opmode= $_[0];
  874. }
  875. sub unrepdiff {
  876. print(STDERR "$progname: cannot represent change to $fn: $_[0]\n")
  877. || &syserr("write syserr unrep");
  878. $ur++;
  879. }
  880. sub unrepdiff2 {
  881. print(STDERR "$progname: cannot represent change to $fn:\n".
  882. "$progname: new version is $_[1]\n".
  883. "$progname: old version is $_[0]\n")
  884. || &syserr("write syserr unrep");
  885. $ur++;
  886. }
  887. sub forkgzipwrite {
  888. #print STDERR "forkgzipwrite $_[0]\n";
  889. open(GZIPFILE,"> $_[0]") || &syserr("create file $_[0]");
  890. pipe(GZIPREAD,GZIP) || &syserr("pipe for gzip");
  891. defined($cgz= fork) || &syserr("fork for gzip");
  892. if (!$cgz) {
  893. open(STDIN,"<&GZIPREAD") || &syserr("reopen gzip pipe"); close(GZIPREAD);
  894. close(GZIP); open(STDOUT,">&GZIPFILE") || &syserr("reopen tar.gz");
  895. exec('gzip','-9'); &syserr("exec gzip");
  896. }
  897. close(GZIPREAD);
  898. $gzipsigpipeok= 0;
  899. }
  900. sub forkgzipread {
  901. #print STDERR "forkgzipread $_[0]\n";
  902. open(GZIPFILE,"< $_[0]") || &syserr("read file $_[0]");
  903. pipe(GZIP,GZIPWRITE) || &syserr("pipe for gunzip");
  904. defined($cgz= fork) || &syserr("fork for gunzip");
  905. if (!$cgz) {
  906. open(STDOUT,">&GZIPWRITE") || &syserr("reopen gunzip pipe"); close(GZIPWRITE);
  907. close(GZIP); open(STDIN,"<&GZIPFILE") || &syserr("reopen input file");
  908. exec('gunzip'); &syserr("exec gunzip");
  909. }
  910. close(GZIPWRITE);
  911. $gzipsigpipeok= 1;
  912. }
  913. sub reapgzip {
  914. #print STDERR "reapgzip $_[0]\n";
  915. $cgz == waitpid($cgz,0) || &syserr("wait for gzip");
  916. !$? || ($gzipsigpipeok && WIFSIGNALED($?) && WTERMSIG($?)==SIGPIPE) ||
  917. subprocerr("gzip");
  918. close(GZIPFILE);
  919. }
  920. sub addfile {
  921. my ($filename)= @_;
  922. stat($filename) || &syserr("could not stat output file \`$filename'");
  923. $size= (stat _)[7];
  924. my $md5sum= `md5sum <$filename`;
  925. $? && &subprocerr("md5sum $filename");
  926. $md5sum =~ s/^([0-9a-f]{32})\n$/$1/ || &failure("md5sum gave bogus output \`$_'");
  927. $f{'Files'}.= "\n $md5sum $size $filename";
  928. }
  929. # replace \ddd with their corresponding character, refuse \ddd > \377
  930. # modifies $_ (hs)
  931. {
  932. my $backslash;
  933. sub deoctify {
  934. my $fn= $_[0];
  935. $backslash= sprintf("\\%03o", unpack("C", "\\")) if !$backslash;
  936. s/\\{2}/$backslash/g;
  937. @_= split(/\\/, $fn);
  938. foreach (@_) {
  939. /^(\d{3})/ or next;
  940. &failure("bogus character `\\$1' in `$fn'\n") if oct($1) > 255;
  941. $_= pack("c", oct($1)) . $';
  942. }
  943. return join("", @_);
  944. } }