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.

48 lines
1019 B

  1. package InfParse;
  2. use Logmsg;
  3. require Exporter;
  4. @ISA = qw(Exporter);
  5. @EXPORT = qw(parseSect strSub parseStr);
  6. local %strings;
  7. # Parse an inf section.
  8. sub parseSect {
  9. # Go through each line in a section and call the handler.
  10. my $handler = $_[0];
  11. while ( <::INF> ) {
  12. $_ =~ /^\s*([^\";]*(\"[^\"]*\"|[^\";\s]))*\s*(;.*)?$/; # "
  13. $_ = $1;
  14. next if $_ eq "";
  15. return $_ if /^\[/;
  16. &$handler($_);
  17. }
  18. }
  19. # Substitute in stuff from the strings section.
  20. sub strSub {
  21. # Check for strings to substitute into a value.
  22. my ($val) = @_;
  23. while ( $val =~ /%([^%]*)%/ ) {
  24. my $key = lc $1;
  25. my $temp = quotemeta $1;
  26. if ( exists $strings{$key} ) {
  27. $val =~ s/%$temp%/$strings{$key}/g;
  28. } else {
  29. wrnmsg "Unknown string $key.\n";
  30. last;
  31. }
  32. }
  33. return $val;
  34. }
  35. # Parse a line from the Strings section.
  36. sub parseStr {
  37. my ($name, $str) = split(/\s*=\s*/);
  38. $str = $1 if $str=~/^\"([^\"]*)\"$/; # "
  39. $strings{lc $name} = $str;
  40. }
  41. 1;