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.

479 lines
14 KiB

  1. # ---------------------------------------------------------------------------
  2. # Script: A2U
  3. #
  4. # (c) 2000 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: This script is an example of a perl module in the NT postbuild
  7. # environment.
  8. #
  9. # Version: <1.00> (<mm/dd/yyyy>) : (<your alias>) <Purpose>
  10. # <1.01> (<mm/dd/yyyy>) : (<your alias>) <Purpose>
  11. #---------------------------------------------------------------------
  12. # Set Package
  13. # <Set your package name of your perl module>
  14. package A2U;
  15. # Set the script name
  16. # <Set your script name>
  17. $ENV{script_name} = 'A2U.pm';
  18. # Set version
  19. # <Set the version of your script>
  20. $VERSION = '1.00';
  21. # Set required perl version
  22. # <Set the version of perl that your script requires>
  23. require 5.003;
  24. # Use section
  25. use lib $ENV{ "RazzleToolPath" };
  26. use lib $ENV{ "RazzleToolPath" } . "\\PostBuildScripts";
  27. use GetParams;
  28. use LocalEnvEx;
  29. use ParseTable;
  30. use Logmsg;
  31. use strict;
  32. use cklang;
  33. use cksku;
  34. no strict 'vars';
  35. no strict 'refs';
  36. # <Add any perl modules that you will be using for this script>
  37. # Require section
  38. require Exporter;
  39. # <Add any perl pl files that you will be using>
  40. # Global variable section
  41. # <Add any global variables here using my to preserve namespace>
  42. local *CMDOUT;
  43. my (@A2U, $A2UEX, @A2USKUs, $SKU, $pbuildpath, %list, $TempFile, %Codes);
  44. my %RelateSubdir = (
  45. PER => "perinf",
  46. PRO => "\.",
  47. BLA => "blainf",
  48. SBS => "sbsinf",
  49. SRV => "srvinf",
  50. ADS => "entinf",
  51. DTC => "dtcinf",
  52. );
  53. # must match 'ordered links' information in cdimage.cmd
  54. my %SkuSearch = (
  55. PER => [ "PER", "PRO"],
  56. PRO => [ "PRO"],
  57. BLA => [ "BLA", "SRV", "PRO"],
  58. SBS => [ "SBS", "SRV", "PRO"],
  59. SRV => [ "SRV", "PRO"],
  60. ADS => [ "ADS", "SRV", "PRO"],
  61. DTC => ["DTC", "ADS", "SRV", "PRO"],
  62. );
  63. my (@PER, @WKS, @BLA, @SBS, @SRV, @ENT, @DTC);
  64. my (@ruleitems);
  65. sub Main {
  66. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  67. # Begin Main code section
  68. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  69. # Return when you want to exit on error
  70. # <Implement your code here>
  71. return if ($lang=~/(usa)|(psu)|(mir)|(FE)/i);
  72. my $KeyFileName = "cddata.txt.full";
  73. my $TempDir = $ENV{ "TMP" };
  74. my $BinDiffFile = $ENV{_NTPostBld} . "\\build_logs\\bindiff.txt";
  75. my (@files, %BinDiff);
  76. @ruleitems = split(/,/, $ruleitem);
  77. if ((-e "$TempDir\\$KeyFileName") && (!$full)) {
  78. # Put here instead outside of this if-statement is
  79. # because CdDataUpdate calls init itself for compatible with calls from cddata.cmd
  80. &init or return;
  81. logmsg( "Create the A2U list from $TempDir\\$KeyFileName..." );
  82. open(F1, "$TempDir\\$KeyFileName") or do {errmsg( "Can not open cddata file $TempDir\\$KeyFileName." ); return;};
  83. if (-e $BinDiffFile) {
  84. # Create BinDiffFile to the hash for easy to search
  85. open(F, $BinDiffFile) or do {errmsg( "Can not open bindiff file $BinDiffFile." ); return;};
  86. %BinDiff = map({chomp;s/$ENV{_NTPostBld}//; $_ => 1} <F>);
  87. close(F);
  88. # Filter all filename in cddata.txt with is defined in bindiff and Unicode's field is 't' (true)
  89. @files = map({
  90. chomp;
  91. my ($file,$flag)=(split(/ = |:/))[0,7];
  92. ((exists $BinDiff{$file}) && ($flag eq "t"))?$file:()} <F1>);
  93. } else {
  94. # Filter all filename in cddata.txt with Unicode's field is 't' (true)
  95. @files = map({
  96. chomp;
  97. my ($file,$flag)=(split(/ = |:/))[0,7];
  98. ($flag eq "t")?$file:()} <F1>);
  99. }
  100. close(F1);
  101. # Convert the files to unicode.
  102. Convert(\@files);
  103. } else {
  104. # Create its file list if not cddata.txt exists
  105. logmsg( "Create the A2U list from A2U.txt..." );
  106. @files = &CdDataUpdate(@ruleitems);
  107. Convert(\@files);
  108. }
  109. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  110. # End Main code section
  111. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  112. }
  113. # <Implement your subs here>
  114. sub init {
  115. # Read a2u.txt
  116. my @A2UEX;
  117. parse_table_file("$ENV{RazzleToolPath}\\PostbuildScripts\\a2u.txt", \@A2U);
  118. parse_table_file("$ENV{RazzleToolPath}\\codes.txt", \%Codes);
  119. # Read a2uex.txt
  120. # open F, "$ENV{RazzleToolPath}\\PostbuildScripts\\a2uex.txt" or do { errmsg("A2UEX.TXT cannot be open"); return 0;};
  121. # $A2UEX = join(",", map({chomp;(/^\;/ || /^\s*$/)?():$_} <F>));
  122. # close F;
  123. parse_table_file("$ENV{RazzleToolPath}\\PostbuildScripts\\a2uex.txt", \@A2UEX);
  124. $A2UEX = join(",", map {$_->{Exclude}} @A2UEX);
  125. # Get Language's SKUs
  126. @A2USKUs = map({$sku=$_;(cksku::CkSku($sku, $lang, $ENV{_BuildArch}) eq 1)?$sku:()} reverse qw(PRO PER BLA SBS SRV ADS DTC));
  127. $TempFile = $ENV{tmpfile};
  128. $TempFile =~ /(.+)\\[^\\]+/; # Get it's path
  129. $TempFile = `$ENV{RazzleToolPath}\\uniqfile.cmd $1\\$ENV{script_name}_loctmp.tmp`;
  130. chomp $TempFile;
  131. logmsg( "Applicable SKUs: " . join(", ", @A2USKUs) );
  132. return 1;
  133. }
  134. sub CdDataUpdate {
  135. my (@files) = @_;
  136. $lang = $ENV{lang};
  137. return if ($lang=~/(usa)|(psu)|(FE)/i);
  138. &init or return;
  139. # A2U is the list we get from a2u.txt, which contains the rules for convertion.
  140. # Look for each rule to find out the applicable files.
  141. # Locate the files in the tree and store their location in %list.
  142. foreach $hA2U (@A2U) {
  143. if (@files ne 0) {
  144. my $FOUND=0;
  145. for (@files) {
  146. if ($hA2U->{PbuildPath}=~/$_/i) {
  147. $FOUND=1;
  148. last;
  149. }
  150. }
  151. next if (!$FOUND);
  152. }
  153. if (cklang::CkLang(uc$lang, $hA2U->{Languages})) {
  154. $pbuildpath = "$ENV{_NTPostBld}$hA2U->{PbuildPath}";
  155. $hA2U->{Extension} =~s/^-$//;
  156. $hA2U->{FileDir} =~s/^-$//;
  157. &scan_layoutinf($hA2U->{Extension}, $hA2U->{FileDir});
  158. &locate;
  159. }
  160. }
  161. return map({s/\\\.//g;s/^\Q$ENV{_NTPostBld}\E\\*//;$_} keys %list);
  162. }
  163. sub scan_layoutinf {
  164. my($string, $dirnum) = @_;
  165. my($total, $layoutinf, $file)=(0);
  166. my $orgstring = $string;
  167. local *LAYOUT;
  168. logmsg( "Generating file lists..." );
  169. $string =~ s/^\./\\\./;
  170. foreach $SKU (@A2USKUs) {
  171. $layoutinf = "$pbuildpath\\$RelateSubdir{$SKU}\\layout.inf";
  172. if (open(LAYOUT, $layoutinf)) {
  173. while (<LAYOUT>) {
  174. s/;.*$//;
  175. s/^(\S+)\s*=\s*//;
  176. $file = lc $1;
  177. if ($file =~ /$string/i) {
  178. if ($dirnum) {
  179. push @{$SKU}, $file if (split /,/)[7] == $dirnum;
  180. } else {
  181. push @{$SKU}, $file;
  182. }
  183. }
  184. }
  185. close LAYOUT;
  186. #
  187. } elsif ((-e "$pbuildpath\\$string") && (!-d "$pbuildpath\\$string")) {
  188. $total++;
  189. @{$SKU} = ($string);
  190. } else {
  191. errmsg("can't open $layoutinf.");
  192. }
  193. $total += @{$SKU};
  194. }
  195. # errmsg("file that matches '$orgstring' " . ($dirnum ? "and '$dirnum' " : "") . "not found.", 2) unless $total;
  196. }
  197. # locate
  198. # Calls search() with prioritized search place list.
  199. # i.e. &search(@WKS, WKS);
  200. # &search(@SRV, SRV, WKS);
  201. # &search(@ENT, ENT, SRV, WKS); ...
  202. sub locate {
  203. foreach my $index ((0..$#A2USKUs)) {
  204. &search(\@{$A2USKUs[$index]}, @{$SkuSearch{$A2USKUs[$index]}});
  205. @{$A2USKUs[$index]}=();
  206. }
  207. }
  208. # search
  209. # Searches and locates files to be converted.
  210. # Input
  211. # arrayref : reference to file list
  212. # searchlist : list of which type to look for
  213. # Output
  214. # %list (global variable)
  215. # keys are in format of "path/subdir/filename"
  216. sub search {
  217. my($arrayref, @searchlist) = @_;
  218. my $SKU = $searchlist[0];
  219. my ($file, $found);
  220. foreach $file (@$arrayref) {
  221. # Skip files on exclude list
  222. next if ($A2UEX=~/$file/i);
  223. $found = 0;
  224. foreach (@searchlist) {
  225. if (-e "$pbuildpath\\$RelateSubdir{$_}\\$file") {
  226. $list{"$pbuildpath\\$RelateSubdir{$_}\\$file"}++;
  227. $found = 1;
  228. last;
  229. }
  230. }
  231. logmsg("warning: $file for $SKU is not found.") if not $found;
  232. }
  233. }
  234. # Convert
  235. # Converts files to Unicode and copies back.
  236. sub Convert {
  237. my $filesptr = shift;
  238. my ($shortfile, $myfile, $UNICODE, $cmd, $convertctr);
  239. $convertctr=0;
  240. logmsg("Converting $ENV{_NTPostBld} files using codepage and place them into tmp dir $tmp.");
  241. NF: for $shortfile (@$filesptr) {
  242. $myfile = $ENV{_NTPostBld} . "\\" . $shortfile;
  243. $UNICODE = "";
  244. $cmd ="unitext -m -$Codes{uc$lang}->{ACP} -z $myfile $TempFile";
  245. logmsg("$cmd\n");
  246. open UNITEXT, "$cmd |" or do {errmsg("Cannot execute '$cmd'.");next;};
  247. while (<UNITEXT>) {
  248. next if /^Converting /;
  249. if (/^Conversion completed.$/) {
  250. logmsg("$shortfile\t: converted");
  251. $UNICODE = "Y";
  252. $convertctr++;
  253. } elsif (/is probably unicode! Stopping conversion.$/) {
  254. # logmsg("$shortfile\t: already Unicode");
  255. $UNICODE = "N";
  256. next NF;
  257. } else {
  258. logmsg("$shortfile\t: $_");
  259. }
  260. }
  261. close UNITEXT;
  262. logmsg("Copying the Unicode files back to $shortfile");
  263. $cmd = "move /Y $TempFile $myfile";
  264. open MOVECMD, "$cmd |" or errmsg("Cannot execute '$cmd'.");
  265. while (<MOVECMD>) {
  266. logmsg("$_") if /\S/;
  267. }
  268. close MOVECMD;
  269. }
  270. logmsg("Converted $convertctr file(s)");
  271. }
  272. sub ValidateParams {
  273. #<Add your code for validating the parameters here>
  274. }
  275. # <Add your usage here>
  276. sub Usage {
  277. print <<USAGE;
  278. Purpose of program
  279. Usage: $0 [-l lang] [-o ruleitem] [-f]
  280. -l Language
  281. -o ruleitem; such as tsclient
  282. -f fullly run; without reference cddata.txt.full
  283. -? Displays usage
  284. Example:
  285. $0 -l jpn
  286. USAGE
  287. }
  288. sub GetParams {
  289. # Step 1: Call pm getparams with specified arguments
  290. &GetParams::getparams(@_);
  291. # Step 2: Set the language into the enviroment
  292. $ENV{lang}=$lang;
  293. # Step 3: Call the usage if specified by /?
  294. if ($HELP) {
  295. &Usage();
  296. exit 1;
  297. }
  298. }
  299. # Cmd entry point for script.
  300. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pm\$/i")) {
  301. # Step 1: Parse the command line
  302. # <run perl.exe GetParams.pm /? to get the complete usage for GetParams.pm>
  303. &GetParams ('-o', 'l:o:f', '-p', 'lang ruleitem full', @ARGV);
  304. # Include local environment extension s
  305. &LocalEnvEx::localenvex('initialize');
  306. # Set lang from the environment
  307. $lang=$ENV{lang};
  308. # Validate the option given as parameter.
  309. &ValidateParams;
  310. # Step 4: Call the main function
  311. &A2U::Main();
  312. # End local environment extensions.
  313. &LocalEnvEx::localenvex('end');
  314. }
  315. # -------------------------------------------------------------------------------------------
  316. # Script: A2U.pm
  317. # Purpose: ASCII to UniCode
  318. # SD Location: %sdxroot%\tools\postbuildscripts
  319. #
  320. # (1) Code section description:
  321. # CmdMain - Developer code section. This is where your work gets done.
  322. # <Implement your subs here> - Developer subs code section. This is where you write subs.
  323. #
  324. # (2) Reserved Variables -
  325. # $ENV{HELP} - Flag that specifies usage.
  326. # $ENV{lang} - The specified language. Defaults to USA.
  327. # $ENV{logfile} - The path and filename of the logs file.
  328. # $ENV{logfile_bak} - The path and filename of the logfile.
  329. # $ENV{errfile} - The path and filename of the error file.
  330. # $ENV{tmpfile} - The path and filename of the temp file.
  331. # $ENV{errors} - The scripts errorlevel.
  332. # $ENV{script_name} - The script name.
  333. # $ENV{_NTPostBld} - Abstracts the language from the files path that
  334. # postbuild operates on.
  335. # $ENV{_NTPostBld_Bak} - Reserved support var.
  336. # $ENV{_temp_bak} - Reserved support var.
  337. # $ENV{_logs_bak} - Reserved support var.
  338. #
  339. # (3) Reserved Subs -
  340. # Usage - Use this sub to discribe the scripts usage.
  341. # ValidateParams - Use this sub to verify the parameters passed to the script.
  342. #
  343. # (4) Call other executables or command scripts by using:
  344. # system "foo.exe";
  345. # Note that the executable/script you're calling with system must return a
  346. # non-zero value on errors to make the error checking mechanism work.
  347. #
  348. # Example
  349. # if (system("perl.exe foo.pl -l $lang")){
  350. # errmsg("perl.exe foo.pl -l $lang failed.");
  351. # # If you need to terminate function's execution on this error
  352. # goto End;
  353. # }
  354. #
  355. # (5) Log non-error information by using:
  356. # logmsg "<log message>";
  357. # and log error information by using:
  358. # errmsg "<error message>";
  359. #
  360. # (6) Have your changes reviewed by a member of the US build team (ntbusa) and
  361. # by a member of the international build team (ntbintl).
  362. #
  363. # -------------------------------------------------------------------------------------------
  364. =head1 NAME
  365. B<mypackage> - What this package for
  366. =head1 SYNOPSIS
  367. <An code example how to use>
  368. =head1 DESCRIPTION
  369. <Use above example to describe this package>
  370. =head1 INSTANCES
  371. =head2 <myinstances>
  372. <Description of myinstances>
  373. =head1 METHODS
  374. =head2 <mymathods>
  375. <Description of mymathods>
  376. =head1 SEE ALSO
  377. <Some related package or None>
  378. =head1 AUTHOR
  379. <Your Name <your e-mail address>>
  380. =cut
  381. 1;