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.

233 lines
6.1 KiB

  1. # ---------------------------------------------------------------------------
  2. # Script: splitlist.pl
  3. #
  4. # (c) 2000 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: Splits a text file by lines. It divides the list as the files appear,
  7. # instead of going round-robin. This makes drivercab compress better.
  8. #
  9. # Version: <1.00> (06/28/2000) : (JeremyD) inital version
  10. #---------------------------------------------------------------------
  11. # Set Package
  12. package splitlist;
  13. # Set the script name
  14. $ENV{script_name} = 'splitlist.pl';
  15. # Set version
  16. $VERSION = '1.00';
  17. # Set required perl version
  18. require 5.003;
  19. # Use section
  20. use lib $ENV{RazzleToolPath} . "\\postbuildscripts";
  21. use GetParams;
  22. use LocalEnvEx;
  23. use Logmsg;
  24. use strict;
  25. no strict 'vars';
  26. use IO::File;
  27. # Require section
  28. require Exporter;
  29. # Global variable section
  30. sub Main {
  31. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  32. # Begin Main code section
  33. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  34. # Return when you want to exit on error
  35. if (!-e $srcfile) {
  36. wrnmsg( "Source file $srcfile did not exist" );
  37. return;
  38. }
  39. my $src_fh = new IO::File $srcfile;
  40. if (!defined $src_fh) {
  41. wrnmsg( "Unable to open source file $srcfile: $!" );
  42. return;
  43. }
  44. my @dest_fh;
  45. for (my $i=0; $i<$parts; $i++) {
  46. my $destfile = "$srcfile." . ($i+1);
  47. $dest_fh[$i] = new IO::File (">$destfile");
  48. if (!defined ($dest_fh[$i])) {
  49. wrnmsg( "Unable to open destination file $destfile: $!" );
  50. return;
  51. }
  52. }
  53. # Don't go round-robin, keep the files in order
  54. # and sort them first
  55. my @content=<$src_fh>;
  56. my @sorted_content = sort @content;
  57. my $eachof = @sorted_content / $parts;
  58. for ( my $i=0; $i<$parts; $i++) {
  59. for my $line (@sorted_content[ ($i * $eachof) .. (($i + 1) * $eachof -1) ]) {
  60. $dest_fh[$i]->print($line);
  61. }
  62. }
  63. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  64. # End Main code section
  65. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  66. }
  67. sub ValidateParams {
  68. if (!defined $parts) {
  69. errmsg( "Number of parts must be specified" );
  70. exit(1);
  71. }
  72. if ($parts < 1) {
  73. errmsg( "Invalid number of parts" );
  74. exit(1);
  75. }
  76. if (!defined $srcfile) {
  77. errmsg( "Source file must be specified" );
  78. exit(1);
  79. }
  80. }
  81. # <Add your usage here>
  82. sub Usage {
  83. print <<USAGE;
  84. Split a given file into several pieces. Output files are
  85. named as <inputname>.n starting with n=1.
  86. Usage: $0 -n <number> -f <filename> [-l lang]
  87. -n Number of parts to split input into
  88. -f Source filename
  89. -l Language
  90. -? Displays usage
  91. Example:
  92. $0 -n 4 -f filelist.txt -l jpn
  93. USAGE
  94. }
  95. sub GetParams {
  96. # Step 1: Call pm getparams with specified arguments
  97. &GetParams::getparams(@_);
  98. # Step 2: Set the language into the enviroment
  99. $ENV{lang}=$lang;
  100. # Step 3: Call the usage if specified by /?
  101. if ($HELP) {
  102. &Usage();
  103. exit 1;
  104. }
  105. }
  106. # Cmd entry point for script.
  107. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pl\$/i")) {
  108. # Step 1: Parse the command line
  109. # <run perl.exe GetParams.pm /? to get the complete usage for GetParams.pm>
  110. &GetParams ('-o', 'n:f:l:', '-p', 'parts srcfile lang', @ARGV);
  111. # Include local environment extensions
  112. &LocalEnvEx::localenvex('initialize');
  113. # Set lang from the environment
  114. $lang=$ENV{lang};
  115. # Validate the option given as parameter.
  116. &ValidateParams;
  117. # Step 4: Call the main function
  118. &splitlist::Main();
  119. # End local environment extensions.
  120. &LocalEnvEx::localenvex('end');
  121. }
  122. # -------------------------------------------------------------------------------------------
  123. # Script: template_script.pl
  124. # Purpose: Template perl perl script for the NT postbuild environment
  125. # SD Location: %sdxroot%\tools\postbuildscripts
  126. #
  127. # (1) Code section description:
  128. # CmdMain - Developer code section. This is where your work gets done.
  129. # <Implement your subs here> - Developer subs code section. This is where you write subs.
  130. #
  131. # (2) Reserved Variables -
  132. # $ENV{HELP} - Flag that specifies usage.
  133. # $ENV{lang} - The specified language. Defaults to USA.
  134. # $ENV{logfile} - The path and filename of the logs file.
  135. # $ENV{logfile_bak} - The path and filename of the logfile.
  136. # $ENV{errfile} - The path and filename of the error file.
  137. # $ENV{tmpfile} - The path and filename of the temp file.
  138. # $ENV{errors} - The scripts errorlevel.
  139. # $ENV{script_name} - The script name.
  140. # $ENV{_NTPostBld} - Abstracts the language from the files path that
  141. # postbuild operates on.
  142. # $ENV{_NTPostBld_Bak} - Reserved support var.
  143. # $ENV{_temp_bak} - Reserved support var.
  144. # $ENV{_logs_bak} - Reserved support var.
  145. #
  146. # (3) Reserved Subs -
  147. # Usage - Use this sub to discribe the scripts usage.
  148. # ValidateParams - Use this sub to verify the parameters passed to the script.
  149. #
  150. # (4) Call other executables or command scripts by using:
  151. # system "foo.exe";
  152. # Note that the executable/script you're calling with system must return a
  153. # non-zero value on errors to make the error checking mechanism work.
  154. #
  155. # Example
  156. # if (system("perl.exe foo.pl -l $lang")){
  157. # errmsg("perl.exe foo.pl -l $lang failed.");
  158. # # If you need to terminate function's execution on this error
  159. # goto End;
  160. # }
  161. #
  162. # (5) Log non-error information by using:
  163. # logmsg "<log message>";
  164. # and log error information by using:
  165. # errmsg "<error message>";
  166. #
  167. # (6) Have your changes reviewed by a member of the US build team (ntbusa) and
  168. # by a member of the international build team (ntbintl).
  169. #
  170. # -------------------------------------------------------------------------------------------
  171. =head1 NAME
  172. B<mypackage> - What this package for
  173. =head1 SYNOPSIS
  174. <An code example how to use>
  175. =head1 DESCRIPTION
  176. <Use above example to describe this package>
  177. =head1 INSTANCES
  178. =head2 <myinstances>
  179. <Description of myinstances>
  180. =head1 METHODS
  181. =head2 <mymathods>
  182. <Description of mymathods>
  183. =head1 SEE ALSO
  184. <Some related package or None>
  185. =head1 AUTHOR
  186. <Your Name <your e-mail address>>
  187. =cut
  188. 1;