update-root-xref.pl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/perl
  2. # update-root-xref.pl -- Fixes genxref's paths in case the internal paths change
  3. #
  4. # License: standard mozilla mpl-tri
  5. # orginal author: timeless
  6. ######################################################################
  7. use lib 'lib';
  8. use integer;
  9. use DB_File;
  10. use strict;
  11. use Cwd;
  12. my (%fileidx_in, %fileidx);
  13. my ($realpath, $oldpath, $newpath) = ($ARGV[0], $ARGV[1], $ARGV[2]);
  14. $realpath ||= '.';
  15. $realpath .= '/';
  16. $newpath = '' if $newpath eq "''";
  17. sub rewrite {
  18. my $start = time;
  19. my $fnum = scalar keys %fileidx_in;
  20. my $f;
  21. for (my $curfnum = 1; $curfnum <= $fnum; ++$curfnum) {
  22. $f = $fileidx_in{$curfnum};
  23. $f =~ s{$oldpath}{$newpath};
  24. $fileidx{$curfnum} = $f;
  25. }
  26. print(STDERR
  27. "Completed rewrite ".$fnum." file entries updated.\n\n");
  28. }
  29. chdir($realpath);
  30. tie (%fileidx_in, "DB_File", "fileidx", O_RDONLY, 0660, $DB_HASH)
  31. || die('Could not open "fileidx" for reading');
  32. tie (%fileidx, "DB_File", "fileidx.out.$$", O_RDWR|O_CREAT, 0660, $DB_HASH)
  33. || die("Could not open \"fileidx.out.$$\" for writing");
  34. print(STDERR "Rewriting index in $realpath.\n");
  35. chdir($realpath);
  36. rewrite($oldpath, $newpath);
  37. dbmclose(%fileidx);
  38. dbmclose(%fileidx_in);
  39. rename("fileidx.out.$$", "fileidx")
  40. || die "Couldn't rename fileidx.out.$$ to fileidx";