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.

72 lines
1.7 KiB

  1. #
  2. open(I, "strings.cpp") || die "Can't open strings.cpp ($!)";
  3. open(O, ">strings.new") || die "Can't create strings.new ($!)";
  4. open(H, ">strings.h") || die "Can't create strings.h ($!)";
  5. while (<I>) {
  6. print O;
  7. last if $_ eq "/* DON'T EDIT ANYTHING AFTER THIS POINT; IT WILL BE NUKED BY THE PERL SCRIPT */\n";
  8. if ($incomment) {
  9. $incomment = $_ ne " */\n";
  10. } elsif ($_ eq "/*\n") {
  11. $incomment = 1;
  12. } elsif (/^#/) {
  13. } elsif (/^$/) {
  14. } else {
  15. chop;
  16. ($str, $val) = /(\w+),\s*"(.*)"$/;
  17. $val =~ s/\\\\/\\/g;
  18. $vals{$str} = $val;
  19. push(@names, $str);
  20. }
  21. }
  22. #
  23. # Now study the string list to figure out how things can be combined.
  24. # Sort by length descending.
  25. #
  26. @names = sort { length($vals{$b}) <=> length($vals{$a}) } @names;
  27. print H "/* DON'T EDIT ANYTHING AFTER THIS POINT; IT WILL BE NUKED BY THE PERL SCRIPT */\n";
  28. #
  29. # Emit strings in length descending, coalescing if possible.
  30. # Record previously-seen strings in @seen to see if there's a match.
  31. $ofs = 0;
  32. for (@names) {
  33. $val = $vals{$_};
  34. for $this (keys(%pos)) {
  35. if ($val eq substr($vals{$this}, -length($val)) || $val eq '') {
  36. $pos{$_} = $pos{$this} + length($vals{$this}) - length($val);
  37. $val = '__NOTUSED__';
  38. last;
  39. }
  40. }
  41. if ($val ne '__NOTUSED__') {
  42. push(@out, $val);
  43. $pos{$_} = $ofs;
  44. $ofs += length($val) + 1;
  45. }
  46. print H "#define $_ (c_rgtchCommon + $pos{$_})\n";
  47. }
  48. print H "extern TCHAR c_rgtchCommon[$ofs];\n";
  49. close(H);
  50. print O "#include \"tweakui.h\"\n";
  51. print O "TCHAR c_rgtchCommon[$ofs] = { \n";
  52. $v = 0;
  53. for (@out) {
  54. for (split(//, $_)) {
  55. $v ^= ord($_);
  56. printf O "0x%02x,\n", $v;
  57. }
  58. printf O "0x%02x,\n", $v;
  59. }
  60. print O "};\n";
  61. close(O);
  62. close(I);
  63. unlink("strings.bak");
  64. rename("strings.new", "strings.cpp");