dpkg-source.pl 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  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. $dscformat != "1.0" &&
  442. &error("Unsupported format of .dsc file ($dscformat)");
  443. }
  444. $sourcepackage =~ m/[^.0-9]/ &&
  445. &error("dsc format contains illegal character \`$&'");
  446. $sourcepackage= $fi{'S Source'};
  447. $sourcepackage =~ m/[^-+.0-9a-z]/ &&
  448. &error("source package name contains illegal character \`$&'");
  449. $sourcepackage =~ m/^[0-9a-z]./ ||
  450. &error("source package name is too short or starts with non-alphanum");
  451. $version= $fi{'S Version'};
  452. $version =~ m/[^-+:.0-9a-zA-Z]/ &&
  453. &error("version number contains illegal character \`$&'");
  454. $version =~ s/^\d+://;
  455. if ($version =~ m/-([^-]+)$/) {
  456. $baseversion= $`; $revision= $1;
  457. } else {
  458. $baseversion= $version; $revision= '';
  459. }
  460. $files= $fi{'S Files'};
  461. for $file (split(/\n /,$files)) {
  462. next if $file eq '';
  463. $file =~ m/^([0-9a-f]{32})[ \t]+(\d+)[ \t]+([0-9a-zA-Z][-+:.,=0-9a-zA-Z_]+)$/
  464. || &error("Files field contains bad line \`$file'");
  465. ($md5sum{$3},$size{$3},$file) = ($1,$2,$3);
  466. &setfile(\$tarfile) if $file =~ m/\.tar\.gz$/;
  467. &setfile(\$difffile) if $file =~ m/\.diff\.gz$/;
  468. }
  469. $newdirectory= $sourcepackage.'-'.$baseversion;
  470. $expectprefix= $newdirectory; $expectprefix.= '.orig' if length($difffile);
  471. length($tarfile) || &error("no tarfile in Files field");
  472. checkstats($tarfile);
  473. checkstats($difffile) if length($difffile);
  474. checktarsane("$dscdir/$tarfile",$expectprefix);
  475. if (length($difffile)) {
  476. &forkgzipread("$dscdir/$difffile");
  477. $/="\n";
  478. $_ = <GZIP>;
  479. while ($_ || !eof(GZIP)) {
  480. # read file header (---/+++ pair)
  481. s/\n$// or &error("diff is missing trailing newline");
  482. /^--- / or &error("expected ^--- in line $. of diff");
  483. $fn= $';
  484. substr($fn,0,length($expectprefix)+1) eq "$expectprefix/" ||
  485. &error("diff patches file ($fn) not in expected subdirectory");
  486. $fn =~ m/\.dpkg-orig$/ &&
  487. &error("diff patches file with name ending .dpkg-orig");
  488. $dirname= $fn;
  489. if ($dirname =~ s,/[^/]+$,, && !defined($dirincluded{$dirname})) {
  490. $dirtocreate{$dirname} = 1;
  491. }
  492. defined($notfileobject{$fn}) &&
  493. &error("diff patches something which is not a plain file");
  494. $_= <GZIP>; s/\n$// ||
  495. &error("diff finishes in middle of ---/+++ (line $.)");
  496. $_ eq '+++ '.$newdirectory.substr($fn,length($expectprefix)) ||
  497. &error("line after --- for file $fn isn't as expected");
  498. $filepatched{$fn}++ && &error("diff patches file $fn twice");
  499. # read hunks
  500. my $hunk = 0;
  501. while (($_ = <GZIP>) && !/^--- /) {
  502. # read hunk header (@@)
  503. s/\n$// or &error("diff is missing trailing newline");
  504. next if /^\\ No newline/;
  505. /^@@ -\d+(,(\d+))? \+\d+(,(\d+))? @\@$/ or
  506. &error("Expected ^@@ in line $. of diff");
  507. my ($olines, $nlines) = ($1 ? $2 : 1, $3 ? $4 : 1);
  508. ++$hunk;
  509. # read hunk
  510. while ($olines || $nlines) {
  511. $_ = <GZIP> or &error("unexpected end of diff");
  512. s/\n$// or &error("diff is missing trailing newline");
  513. next if /^\\ No newline/;
  514. if (/^ /) { --$olines; --$nlines; }
  515. elsif (/^-/) { --$olines; }
  516. elsif (/^\+/) { --$nlines; }
  517. else { &error("expected [ +-] at start of line $. of diff"); }
  518. }
  519. }
  520. $hunk or &error("expected ^\@\@ at line $. of diff");
  521. }
  522. close(GZIP);
  523. &reapgzip;
  524. }
  525. print("$progname: extracting $sourcepackage in $newdirectory\n")
  526. || &syserr("write extracting message");
  527. &erasedir($newdirectory);
  528. &erasedir("$newdirectory.orig");
  529. mkdir("$expectprefix.tmp-nest",0755)
  530. || &syserr("unable to create \`$expectprefix.tmp-nest'");
  531. system "chmod", "g-s", "$expectprefix.tmp-nest";
  532. extracttar("$dscdir/$tarfile","$expectprefix.tmp-nest","$expectprefix");
  533. rename("$expectprefix.tmp-nest/$expectprefix","$expectprefix")
  534. || &syserr("unable to rename \`$expectprefix.tmp-nest/$expectprefix' "
  535. ."to \`$expectprefix'");
  536. rmdir("$expectprefix.tmp-nest")
  537. || &syserr("unable to remove \`$expectprefix.tmp-nest'");
  538. for $dircreate (keys %dirtocreate) {
  539. $dircreatem= "";
  540. for $dircreatep (split("/",$dirc)) {
  541. $dircreatem.= $dircreatep;
  542. if (!lstat($dircreatem)) {
  543. $! == ENOENT || &syserr("cannot stat $dircreatem");
  544. mkdir($dircreatem,0777)
  545. || &syserr("failed to create $dircreatem subdirectory");
  546. }
  547. else {
  548. -d _ || &error("diff patches file in directory \`$dircreate',"
  549. ." but $dircreatem isn't a directory !");
  550. }
  551. }
  552. }
  553. if (length($difffile)) {
  554. rename($expectprefix,$newdirectory) ||
  555. &syserr("failed to rename newly-extracted $expectprefix to $newdirectory");
  556. if ($sourcestyle =~ m/u/) {
  557. mkdir("$expectprefix.tmp-nest",0755)
  558. || &syserr("unable to create \`$expectprefix.tmp-nest'");
  559. system "chmod", "g-s", "$expectprefix.tmp-nest";
  560. extracttar("$dscdir/$tarfile","$expectprefix.tmp-nest",
  561. "$expectprefix");
  562. rename("$expectprefix.tmp-nest/$expectprefix","$expectprefix")
  563. || &syserr("unable to rename \`$expectprefix.tmp-nest/"
  564. ."$expectprefix' to \`$expectprefix'");
  565. rmdir("$expectprefix.tmp-nest")
  566. || &syserr("unable to remove \`$expectprefix.tmp-nest'");
  567. } elsif ($sourcestyle =~ m/p/) {
  568. stat("$dscdir/$tarfile") ||
  569. &syserr("failed to stat \`$dscdir/$tarfile' to see if need to copy");
  570. ($dsctardev,$dsctarino) = stat _;
  571. $dumptar= $sourcepackage.'_'.$baseversion.'.orig.tar.gz';
  572. if (!stat($dumptar)) {
  573. $! == ENOENT || &syserr("failed to check destination \`$dumptar'".
  574. " to see if need to copy");
  575. } else {
  576. ($dumptardev,$dumptarino) = stat _;
  577. if ($dumptardev == $dsctardev && $dumptarino == $dsctarino) {
  578. $dumptar= '';
  579. }
  580. }
  581. if (length($dumptar)) {
  582. system('cp','--',"$dscdir/$tarfile","$dumptar");
  583. $? && subprocerr("cp $dscdir/$tarfile to $dumptar");
  584. }
  585. }
  586. &forkgzipread("$dscdir/$difffile");
  587. defined($c2= fork) || &syserr("fork for patch");
  588. if (!$c2) {
  589. open(STDIN,"<&GZIP") || &syserr("reopen gzip for patch");
  590. chdir($newdirectory) || &syserr("chdir to $newdirectory for patch");
  591. $ENV{'LANG'}= 'C';
  592. exec('patch','-s','-t','-F','0','-N','-p1','-u',
  593. '-V','never','-g0','-b','-z','.dpkg-orig');
  594. &syserr("exec patch");
  595. }
  596. close(GZIP);
  597. $c2 == waitpid($c2,0) || &syserr("wait for patch");
  598. $? && subprocerr("patch");
  599. &reapgzip;
  600. for $fn (keys %filepatched) {
  601. $ftr= "$newdirectory/".substr($fn,length($expectprefix)+1).".dpkg-orig";
  602. unlink($ftr) || &syserr("remove patch backup file $ftr");
  603. }
  604. if (!(@s= lstat("$newdirectory/debian/rules"))) {
  605. $! == ENOENT || &syserr("cannot stat $newdirectory/debian/rules");
  606. &warn("$newdirectory/debian/rules does not exist");
  607. } elsif (-f _) {
  608. chmod($s[2] | 0111, "$newdirectory/debian/rules") ||
  609. &syserr("cannot make $newdirectory/debian/rules executable");
  610. } else {
  611. &warn("$newdirectory/debian/rules is not a plain file");
  612. }
  613. }
  614. $execmode= 0777 & ~umask;
  615. (@s= stat('.')) || &syserr("cannot stat \`.'");
  616. $dirmode= $execmode | ($s[2] & 02000);
  617. $plainmode= $execmode & ~0111;
  618. $fifomode= ($plainmode & 0222) | (($plainmode & 0222) << 1);
  619. for $fn (@filesinarchive) {
  620. $fn= substr($fn,length($expectprefix)+1);
  621. $fn= "$newdirectory/$fn";
  622. (@s= lstat($fn)) || &syserr("cannot stat extracted object \`$fn'");
  623. $mode= $s[2];
  624. if (-d _) {
  625. $newmode= $dirmode;
  626. } elsif (-f _) {
  627. $newmode= ($mode & 0111) ? $execmode : $plainmode;
  628. } elsif (-p _) {
  629. $newmode= $fifomode;
  630. } elsif (!-l _) {
  631. &internerr("unknown object \`$fn' after extract (mode ".
  632. sprintf("0%o",$mode).")");
  633. } else { next; }
  634. next if ($mode & 07777) == $newmode;
  635. chmod($newmode,$fn) ||
  636. &syserr(sprintf("cannot change mode of \`%s' to 0%o from 0%o",
  637. $fn,$newmode,$mode));
  638. }
  639. exit(0);
  640. }
  641. sub checkstats {
  642. my ($f) = @_;
  643. my @s;
  644. my $m;
  645. open(STDIN,"< $dscdir/$f") || &syserr("cannot read $dscdir/$f");
  646. (@s= stat(STDIN)) || &syserr("cannot fstat $dscdir/$f");
  647. $s[7] == $size{$f} || &error("file $f has size $s[7] instead of expected $size{$f}");
  648. $m= `md5sum`; $? && subprocerr("md5sum $f"); $m =~ s/\n$//;
  649. $m =~ m/^[0-9a-f]{32}$/ || &failure("md5sum of $f gave bad output \`$m'");
  650. $m eq $md5sum{$f} || &error("file $f has md5sum $m instead of expected $md5sum{$f}");
  651. open(STDIN,"</dev/null") || &syserr("reopen stdin from /dev/null");
  652. }
  653. sub erasedir {
  654. my ($dir) = @_;
  655. if (!lstat($dir)) {
  656. $! == ENOENT && return;
  657. &syserr("cannot stat directory $dir (before removal)");
  658. }
  659. system 'rm','-rf','--',$dir;
  660. $? && subprocerr("rm -rf $dir");
  661. if (!stat($dir)) {
  662. $! == ENOENT && return;
  663. &syserr("unable to check for removal of dir \`$dir'");
  664. }
  665. &failure("rm -rf failed to remove \`$dir'");
  666. }
  667. use strict 'vars';
  668. sub checktarcpio {
  669. my ($tarfileread, $wpfx) = @_;
  670. my ($tarprefix, $c2);
  671. @filesinarchive = ();
  672. # make <CPIO> read from the uncompressed archive file
  673. &forkgzipread ("$tarfileread");
  674. if (! defined ($c2 = open (CPIO,"-|"))) { &syserr ("fork for cpio"); }
  675. if (!$c2) {
  676. open (STDIN,"<&GZIP") || &syserr ("reopen gzip for cpio");
  677. &cpiostderr;
  678. exec ('cpio','-0t');
  679. &syserr ("exec cpio");
  680. }
  681. close (GZIP);
  682. $/ = "\0";
  683. open (CPIO, "<cpiolog");
  684. while (defined ($fn = <CPIO>)) {
  685. $fn =~ s/\0$//;
  686. # store printable name of file for error messages
  687. my $pname = $fn;
  688. $pname =~ y/ -~/?/c;
  689. if (! $tarprefix) {
  690. if ($fn =~ m/\n/) {
  691. &error("first output from cpio -0t (from \`$tarfileread') ".
  692. "contains newline - you probably have an out of ".
  693. "date version of cpio. GNU cpio 2.4.2-2 is known to work");
  694. }
  695. $tarprefix = ($fn =~ m,([^/]*)[/],)[0];
  696. # need to check for multiple dots on some operating systems
  697. # empty tarprefix (due to regex failer) will match emptry string
  698. if ($tarprefix =~ /^[.]*$/) {
  699. &error("tarfile \`$tarfileread' does not extract into a ".
  700. "directory off the current directory ($tarprefix from $pname)");
  701. }
  702. }
  703. if ($fn =~ m/\n/) {
  704. &error ("tarfile \`$tarfileread' contains object with".
  705. " newline in its name ($pname)");
  706. }
  707. next if ($fn eq '././@LongLink');
  708. my $fprefix = substr ($fn, 0, length ($tarprefix));
  709. my $slash = substr ($fn, length ($tarprefix), 1);
  710. if ((($slash ne '/') && ($slash ne '')) || ($fprefix ne $tarprefix)) {
  711. &error ("tarfile \`$tarfileread' contains object ($pname) ".
  712. "not in expected directory ($tarprefix)");
  713. }
  714. # need to check for multiple dots on some operating systems
  715. if ($fn =~ m/[.]{2,}/) {
  716. &error ("tarfile \`$tarfileread' contains object with".
  717. " /../ in its name ($pname)");
  718. }
  719. push (@filesinarchive, $fn);
  720. }
  721. close (CPIO);
  722. $? && subprocerr ("cpio");
  723. &reapgzip;
  724. $/= "\n";
  725. my $tarsubst = quotemeta ($tarprefix);
  726. @filesinarchive = map { s/^$tarsubst/$wpfx/; $_ } @filesinarchive;
  727. return $tarprefix;
  728. }
  729. sub checktarsane {
  730. my ($tarfileread, $wpfx) = @_;
  731. my ($c2);
  732. %dirincluded = ();
  733. %notfileobject = ();
  734. my $tarprefix = &checktarcpio ($tarfileread, $wpfx);
  735. # make <TAR> read from the uncompressed archive file
  736. &forkgzipread ("$tarfileread");
  737. if (! defined ($c2 = open (TAR,"-|"))) { &syserr ("fork for tar -t"); }
  738. if (! $c2) {
  739. $ENV{'LANG'}= 'C';
  740. open (STDIN, "<&GZIP") || &syserr ("reopen gzip for tar -t");
  741. exec ('tar', '-vvtf', '-'); &syserr ("exec tar -vvtf -");
  742. }
  743. close (GZIP);
  744. my $efix= 0;
  745. open (TAR, "<tarlog");
  746. while (<TAR>) {
  747. chomp;
  748. if (! m,^(\S{10})\s,) {
  749. &error("tarfile \`$tarfileread' contains unknown object ".
  750. "listed by tar as \`$_'");
  751. }
  752. my $mode = $1;
  753. $mode =~ s/^([-dpsl])// ||
  754. &error("tarfile \`$tarfileread' contains object \`$fn' with ".
  755. "unknown or forbidden type \`".substr($_,0,1)."'");
  756. my $type = $&;
  757. if ($mode =~ /^l/) { $_ =~ s/ -\> .*//; }
  758. s/ link to .+//;
  759. if (length ($_) <= 48) {
  760. &error ("tarfile \`$tarfileread' contains incomplete entry \`$_'\n");
  761. }
  762. my $tarfn = substr ($_, 48, length ($_) - 48);
  763. $tarfn = deoctify ($tarfn);
  764. # store printable name of file for error messages
  765. my $pname = $tarfn;
  766. $pname =~ y/ -~/?/c;
  767. # fetch name of file as given by cpio
  768. $fn = $filesinarchive[$efix++];
  769. if ($tarfn ne $fn) {
  770. if ((length ($fn) == 99) && (length ($tarfn) >= 99)
  771. && (substr ($fn, 0, 99) eq substr ($tarfn, 0, 99))) {
  772. # this file doesn't match because cpio truncated the name
  773. # to the first 100 characters. let it slide for now.
  774. &warn ("filename \`$pname' was truncated by cpio;" .
  775. " unable to check full pathname");
  776. } else {
  777. &error ("tarfile \`$tarfileread' contains unexpected object".
  778. " listed by tar as \`$_'; expected \`$pname'");
  779. }
  780. }
  781. # if cpio truncated the name above,
  782. # we still can't allow files to expand into /../
  783. # need to check for multiple dots on some operating systems
  784. if ($tarfn =~ m/[.]{2,}/) {
  785. &error ("tarfile \`$tarfileread' contains object with".
  786. "/../ in its name ($pname)");
  787. }
  788. if ($tarfn =~ /\.dpkg-orig$/) {
  789. &error ("tarfile \`$tarfileread' contains file with name ending in .dpkg-orig");
  790. }
  791. if ($mode =~ /[sStT]/ && $type ne 'd') {
  792. &error ("tarfile \`$tarfileread' contains setuid, setgid".
  793. " or sticky object \`$pname'");
  794. }
  795. if ($tarfn eq "$tarprefix/debian" && $type ne 'd') {
  796. &error ("tarfile \`$tarfileread' contains object \`debian'".
  797. " that isn't a directory");
  798. }
  799. if ($type eq 'd') { $tarfn =~ s,/$,,; }
  800. my $dirname = $tarfn;
  801. if (($dirname =~ s,/[^/]+$,,) && (! defined ($dirincluded{$dirname}))) {
  802. &error ("tarfile \`$tarfileread' contains object \`$pname' but its containing ".
  803. "directory \`$dirname' does not precede it");
  804. }
  805. if ($type eq 'd') { $dirincluded{$tarfn} = 1; }
  806. if ($type ne '-') { $notfileobject{$tarfn} = 1; }
  807. }
  808. close (TAR);
  809. #$? && subprocerr ("tar -vvtf");
  810. &reapgzip;
  811. my $tarsubst = quotemeta ($tarprefix);
  812. %dirincluded = map { s/^$tarsubst/$wpfx/; $_=>1 } (keys %dirincluded);
  813. %notfileobject = map { s/^$tarsubst/$wpfx/; $_=>1 } (keys %notfileobject);
  814. }
  815. no strict 'vars';
  816. sub extracttar {
  817. my ($tarfileread,$dirchdir,$newtopdir) = @_;
  818. &forkgzipread("$tarfileread");
  819. defined($c2= fork) || &syserr("fork for tar -xkf -");
  820. if (!$c2) {
  821. chdir("$dirchdir") || &syserr("cannot chdir to \`$dirchdir' for tar extract");
  822. open(STDIN,"<&GZIP") || &syserr("reopen gzip for cpio -i");
  823. &cpiostderr;
  824. exec('tar','-xkf','-'); &syserr("exec tar -xkf -");
  825. }
  826. close(GZIP);
  827. $c2 == waitpid($c2,0) || &syserr("wait for tar -xkf -");
  828. $? && subprocerr("tar -xkf -");
  829. &reapgzip;
  830. opendir(D,"$dirchdir") || &syserr("Unable to open dir $dirchdir");
  831. @dirchdirfiles = grep($_ ne "." && $_ ne "..",readdir(D));
  832. closedir(D) || &syserr("Unable to close dir $dirchdir");
  833. if (@dirchdirfiles==1 && -d "$dirchdir/$dirchdirfiles[0]") {
  834. if ("$dirchdir/$dirchdirfiles[0]" ne "$dirchdir/$newtopdir") {
  835. rename("$dirchdir/$dirchdirfiles[0]", "$dirchdir/$newtopdir") ||
  836. &syserr("Unable to rename $dirchdir/$dirchdirfiles[0] to ".
  837. "$dirchdir/$newtopdir");
  838. }
  839. } else {
  840. mkdir("$dirchdir/$newtopdir", 0777) ||
  841. &syserr("Unable to mkdir $dirchdir/$newtopdir");
  842. for (@dirchdirfiles) {
  843. rename("$dirchdir/$_", "$dirchdir/$newtopdir/$_") ||
  844. &syserr("Unable to rename $dirchdir/$_ to ".
  845. "$dirchdir/$newtopdir/$_");
  846. }
  847. }
  848. }
  849. sub cpiostderr {
  850. open(STDERR,"| egrep -v '^[0-9]+ blocks\$' >&2") ||
  851. &syserr("reopen stderr for cpio to grep out blocks message");
  852. }
  853. sub setfile {
  854. my ($varref) = @_;
  855. if (defined ($$varref)) {
  856. &error ("repeated file type - files " . $$varref . " and $file");
  857. }
  858. $$varref = $file;
  859. }
  860. sub checktype {
  861. if (!lstat("$origdir/$fn")) {
  862. &unrepdiff2("nonexistent",$type{$fn});
  863. } else {
  864. $v= eval("$_[0] _ ? 2 : 1"); $v || &internerr("checktype $@ ($_[0])");
  865. return 1 if $v == 2;
  866. &unrepdiff2("something else",$type{$fn});
  867. }
  868. return 0;
  869. }
  870. sub setopmode {
  871. defined($opmode) && &usageerr("only one of -x or -b allowed, and only once");
  872. $opmode= $_[0];
  873. }
  874. sub unrepdiff {
  875. print(STDERR "$progname: cannot represent change to $fn: $_[0]\n")
  876. || &syserr("write syserr unrep");
  877. $ur++;
  878. }
  879. sub unrepdiff2 {
  880. print(STDERR "$progname: cannot represent change to $fn:\n".
  881. "$progname: new version is $_[1]\n".
  882. "$progname: old version is $_[0]\n")
  883. || &syserr("write syserr unrep");
  884. $ur++;
  885. }
  886. sub forkgzipwrite {
  887. #print STDERR "forkgzipwrite $_[0]\n";
  888. open(GZIPFILE,"> $_[0]") || &syserr("create file $_[0]");
  889. pipe(GZIPREAD,GZIP) || &syserr("pipe for gzip");
  890. defined($cgz= fork) || &syserr("fork for gzip");
  891. if (!$cgz) {
  892. open(STDIN,"<&GZIPREAD") || &syserr("reopen gzip pipe"); close(GZIPREAD);
  893. close(GZIP); open(STDOUT,">&GZIPFILE") || &syserr("reopen tar.gz");
  894. exec('gzip','-9'); &syserr("exec gzip");
  895. }
  896. close(GZIPREAD);
  897. $gzipsigpipeok= 0;
  898. }
  899. sub forkgzipread {
  900. #print STDERR "forkgzipread $_[0]\n";
  901. open(GZIPFILE,"< $_[0]") || &syserr("read file $_[0]");
  902. pipe(GZIP,GZIPWRITE) || &syserr("pipe for gunzip");
  903. defined($cgz= fork) || &syserr("fork for gunzip");
  904. if (!$cgz) {
  905. open(STDOUT,">&GZIPWRITE") || &syserr("reopen gunzip pipe"); close(GZIPWRITE);
  906. close(GZIP); open(STDIN,"<&GZIPFILE") || &syserr("reopen input file");
  907. exec('gunzip'); &syserr("exec gunzip");
  908. }
  909. close(GZIPWRITE);
  910. $gzipsigpipeok= 1;
  911. }
  912. sub reapgzip {
  913. #print STDERR "reapgzip $_[0]\n";
  914. $cgz == waitpid($cgz,0) || &syserr("wait for gzip");
  915. !$? || ($gzipsigpipeok && WIFSIGNALED($?) && WTERMSIG($?)==SIGPIPE) ||
  916. subprocerr("gzip");
  917. close(GZIPFILE);
  918. }
  919. sub addfile {
  920. my ($filename)= @_;
  921. stat($filename) || &syserr("could not stat output file \`$filename'");
  922. $size= (stat _)[7];
  923. my $md5sum= `md5sum <$filename`;
  924. $? && &subprocerr("md5sum $filename");
  925. $md5sum =~ s/^([0-9a-f]{32})\n$/$1/ || &failure("md5sum gave bogus output \`$_'");
  926. $f{'Files'}.= "\n $md5sum $size $filename";
  927. }
  928. # replace \ddd with their corresponding character, refuse \ddd > \377
  929. # modifies $_ (hs)
  930. {
  931. my $backslash;
  932. sub deoctify {
  933. my $fn= $_[0];
  934. $backslash= sprintf("\\%03o", unpack("C", "\\")) if !$backslash;
  935. s/\\{2}/$backslash/g;
  936. @_= split(/\\/, $fn);
  937. foreach (@_) {
  938. /^(\d{3})/ or next;
  939. &failure("bogus character `\\$1' in `$fn'\n") if oct($1) > 255;
  940. $_= pack("c", oct($1)) . $';
  941. }
  942. return join("", @_);
  943. } }