Leaked source code of windows server 2003
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.

121 lines
2.6 KiB

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