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.

184 lines
3.4 KiB

  1. #!perl
  2. use strict;
  3. my $modulebase;
  4. my $module;
  5. my $filename;
  6. my @files;
  7. GetModuleName();
  8. open (OUT,">$modulebase.reg") or die "Can't open $modulebase.reg for output\n";
  9. opendir (DIR, ".");
  10. @files = readdir DIR;
  11. closedir DIR;
  12. foreach $filename (@files)
  13. {
  14. if ($filename =~ /\.rgs/i)
  15. {
  16. makereg ($filename);
  17. }
  18. }
  19. sub makereg()
  20. {
  21. my $infile;
  22. $infile = shift;
  23. print OUT "; -------------------------------------------------------------------------\n";
  24. print OUT "; Automatically generated from $infile using makereg.pl\n";
  25. open (IN,"<$infile") or die "Can't open $infile for input\n";
  26. recurse();
  27. print OUT "; End $infile\n\n";
  28. }
  29. sub GetModuleName()
  30. {
  31. my $targetname;
  32. my $targettype;
  33. my $sg_targettype;
  34. open (F, "sources") or die "SOURCES file does not exist\n";
  35. while (<F>)
  36. {
  37. if (/TARGETNAME=(\S*)/i)
  38. {
  39. $targetname=$1;
  40. }
  41. if (/TARGETTYPE=(\S*)/i)
  42. {
  43. $targettype=$1;
  44. }
  45. if (/SG_TARGETTYPE=(\S*)/i)
  46. {
  47. $sg_targettype=$1;
  48. }
  49. }
  50. if ($targetname && $targettype)
  51. {
  52. if ($targettype =~ /PROGRAM/i)
  53. {
  54. $module="$targetname.exe";
  55. }
  56. elsif ($targettype =~ /DYNLINK/i)
  57. {
  58. $module="$targetname.dll";
  59. }
  60. elsif ( ($targettype =~ /LIBRARY/i) && ($sg_targettype =~ /PROGRAM/i) )
  61. {
  62. $module="$targetname.exe";
  63. }
  64. elsif ( ($targettype =~ /LIBRARY/i) && ($sg_targettype =~ /DYNLINK/i) )
  65. {
  66. $module="$targetname.dll";
  67. }
  68. else
  69. {
  70. die "$targettype is an invalid TARGETTYPE=\n";
  71. }
  72. }
  73. else
  74. {
  75. die "TARGETNAME= and TARGETTYPE= not specified in SOURCES file\n";
  76. }
  77. $modulebase=$targetname;
  78. }
  79. sub recurse
  80. {
  81. my $newp; # new path to pass into recurse
  82. my $p=shift; # p = first parameter
  83. my ($key,$name, $value); # temp local variables.
  84. while (<IN>)
  85. {
  86. s/NoRemove//g; #remove the NoRemove string (isn't it ironic?)
  87. s/ForceRemove//g; #remove the ForceRemove string
  88. s/^\s*//; #remove white space at begining of line
  89. s/\s*$//; #remove white space at end of line.
  90. s/^HKCR/HKEY_CLASSES_ROOT/;
  91. s/^HKLM/HKEY_LOCAL_MACHINE/;
  92. s/^HKCU/HKEY_CURRENT_USER/;
  93. # If line is a {, recurse
  94. if (/^{$/)
  95. {
  96. recurse("$newp");
  97. next;
  98. }
  99. # If line is a }, end recurse.
  100. if (/^}$/)
  101. {
  102. return;
  103. }
  104. # set initial values for temp variables.
  105. $key = undef;
  106. $name = "\@";
  107. $value = undef;
  108. if (/^val /)
  109. {
  110. # if this is a value, save the name. This removes the string before the = so the next if doesn't find a key
  111. s/^val\s+([^=\s]*)//;
  112. $name=$1;
  113. }
  114. if (/=\s*s/)
  115. {
  116. # If line has an "= s" in it, its a string. Set the key and the value
  117. /([^=\s]*)\s*=\s*s\s*(.*)\s*$/;
  118. $key=$1;
  119. $value="$2";
  120. $value =~ s/\\/\\\\/g;
  121. $value =~ s/\"/\\\"/g;
  122. $value = "\"$value\"";
  123. }
  124. elsif (/=\s*d/)
  125. {
  126. # If line has an "= d" in it, its a dword. Set the key and the value
  127. /([^=\s]*)\s*=\s*d\s*(.*)\s*$/;
  128. $key=$1;
  129. $value = sprintf("dword:%x",$2);
  130. }
  131. else
  132. {
  133. # Last case, line is a key name. Save the key
  134. m/^(.*)$/;
  135. $key=$1;
  136. }
  137. # strip single quotes from $key, $name, and $value
  138. $key =~ s/\'//g;
  139. $name =~ s/\'//g;
  140. $value =~ s/\'//g;
  141. $value =~ s/%MODULE%/$module/;
  142. # add quotes to the name
  143. if ($name NE "\@")
  144. {
  145. $name = "\"$name\"";
  146. }
  147. # If we have a new key, set the new path and print it.
  148. if ($key)
  149. {
  150. if ($p)
  151. {
  152. $newp="$p\\$key";
  153. }
  154. else
  155. {
  156. $newp=$key;
  157. }
  158. print OUT "[$newp]\n";
  159. }
  160. #if we have a value, print it.
  161. if ("$value" ne "")
  162. {
  163. print OUT "\t$name=$value\n";
  164. }
  165. }
  166. }