Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.2 KiB

  1. use strict;
  2. my (%old, %new);
  3. my ($dir, $fname, $size, $dirprinted, $sectionprinted);
  4. if((scalar @ARGV) != 2) {
  5. die "Usage: perl dirdiff <first file> <second file>\n";
  6. }
  7. open(FILE, $ARGV[0]) or die "Failure to open $ARGV[0]: $!";
  8. while(<FILE>) {
  9. chomp;
  10. if( ($dir, $fname, $size) = m/(.*\/)(.*) ([0-9]+$)/ ) {
  11. $old{$dir}{$fname} = $size;
  12. }
  13. }
  14. close(FILE);
  15. open(FILE, $ARGV[1]) or die "Failure to open $ARGV[1]: $!";
  16. while(<FILE>) {
  17. chomp;
  18. if( ($dir, $fname, $size) = m/(.*\/)(.*) ([0-9]+$)/ ) {
  19. $new{$dir}{$fname} = $size;
  20. }
  21. }
  22. close(FILE);
  23. print("Files:\n");
  24. #
  25. # added entries
  26. #
  27. $sectionprinted = 0;
  28. foreach $dir (sort keys %new) {
  29. $dirprinted = 0;
  30. foreach $fname (sort keys %{$new{$dir}}) {
  31. if(!defined($old{$dir}{$fname})) {
  32. if(!$sectionprinted) {
  33. $sectionprinted = 1;
  34. print(" Added:\n");
  35. }
  36. if(!$dirprinted) {
  37. print(" $dir\n");
  38. $dirprinted = 1;
  39. }
  40. print(" $fname\n");
  41. }
  42. }
  43. }
  44. #
  45. # deleted entries
  46. #
  47. $sectionprinted = 0;
  48. foreach $dir (sort keys %old) {
  49. $dirprinted = 0;
  50. foreach $fname (sort keys %{$old{$dir}}) {
  51. if(!defined($new{$dir}{$fname})) {
  52. if(!$sectionprinted) {
  53. $sectionprinted = 1;
  54. print(" Deleted:\n");
  55. }
  56. if(!$dirprinted) {
  57. print(" $dir\n");
  58. $dirprinted = 1;
  59. }
  60. print(" $fname\n");
  61. }
  62. }
  63. }
  64. #
  65. # changed entries
  66. #
  67. $sectionprinted = 0;
  68. foreach $dir (sort keys %old) {
  69. $dirprinted = 0;
  70. foreach $fname (sort keys %{$old{$dir}}) {
  71. if(defined($new{$dir}{$fname})) {
  72. if($new{$dir}{$fname} == $old{$dir}{$fname}) {
  73. next;
  74. }
  75. if(!$sectionprinted) {
  76. $sectionprinted = 1;
  77. print(" Changed:\n");
  78. }
  79. if(!$dirprinted) {
  80. print(" $dir\n");
  81. $dirprinted = 1;
  82. }
  83. print(" $fname\n");
  84. }
  85. }
  86. }