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.

86 lines
1.7 KiB

  1. package InfComp;
  2. use strict;
  3. use Carp;
  4. sub new {
  5. my $class = shift;
  6. my $instance = {
  7. DIFF => '',
  8. ERR => ''
  9. };
  10. return bless $instance;
  11. }
  12. sub GetLastError {
  13. my $self = shift;
  14. if (!ref $self) {croak "Invalid object reference"}
  15. return $self->{ERR};
  16. }
  17. sub GetLastDiff {
  18. my $self = shift;
  19. if (!ref $self) {croak "Invalid object reference"}
  20. return $self->{DIFF};
  21. }
  22. #
  23. # 0 - different
  24. # 1 - same
  25. # undefined - error
  26. #
  27. sub compare {
  28. my $self = shift;
  29. my $base = shift;
  30. my $upd = shift;
  31. if (!ref $self) {croak "Invalid object reference"}
  32. if (!$base||!$upd) {croak "Invalid function call -- missing required parameters"}
  33. # Compare the files.
  34. if ( !open FILE1, $base ) {
  35. $self->{ERR} = "Unable to open file: $base";
  36. return;
  37. }
  38. if ( !open FILE2, $upd ) {
  39. close FILE1;
  40. $self->{ERR} = "Unable to open file: $upd";
  41. return;
  42. }
  43. binmode(FILE1);
  44. binmode(FILE2);
  45. my $sect = "";
  46. my $match = 1;
  47. my ($l1,$l2) = ("", "");
  48. do {
  49. # Process the next line in each file.
  50. $l1 = <FILE1>;
  51. $l2 = <FILE2>;
  52. $l1 =~ s/^DriverVer.*//i;
  53. $l2 =~ s/^DriverVer.*//i;
  54. } while ( defined $l1 and defined $l2 and $l1 eq $l2 );
  55. close FILE1;
  56. close FILE2;
  57. if ( !defined $l1 and !defined $l2 ) {
  58. # Files match.
  59. return 1;
  60. }
  61. if ( !defined $l1 ) {
  62. $self->{DIFF} = "$base shorter than $upd.";
  63. }
  64. elsif ( !defined $l2 ) {
  65. $self->{DIFF} = "$upd shorter than $base.";
  66. }
  67. else {
  68. $self->{DIFF} = "\nMismatch: $l1\n$l2\n";
  69. }
  70. return 0;
  71. }
  72. 1;