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.

356 lines
7.8 KiB

  1. package GetIniSetting;
  2. #
  3. # GetIniSetting.pm
  4. #
  5. # Just a utility to read the main.usa.ini file (or whatever branch / lang)
  6. # and return the requested information.
  7. #
  8. # Version 1.0 MikeCarl 07/21/00 Write initial module
  9. #
  10. use strict;
  11. use lib $ENV{ "RazzleToolPath" };
  12. use lib $ENV{ "RazzleToolPath" } . "\\PostBuildScripts";
  13. use Logmsg;
  14. #
  15. # CheckIniFile
  16. #
  17. # Arguments: none
  18. #
  19. # Purpose: validates existence of the appropriate ini file
  20. #
  21. # Returns: true if found, undef otherwise
  22. #
  23. sub CheckIniFile
  24. {
  25. # declare locals
  26. my( $BranchName, $Language );
  27. $BranchName = $ENV{ "_BuildBranch" };
  28. $Language = $ENV{ "lang" };
  29. return &CheckIniFileEx( $BranchName, $Language );
  30. }
  31. #
  32. # CheckIniFileEx
  33. #
  34. # Arguments: $BranchName, $Language
  35. #
  36. # Purpose: validates existence of the appropriate ini file using branch and
  37. # language as passed
  38. #
  39. # Returns: true if found, undef otherwise
  40. #
  41. sub CheckIniFileEx
  42. {
  43. # get passed args
  44. my( $BranchName, $Language ) = @_;
  45. # declare locals
  46. my( $IniFileName );
  47. $IniFileName = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" ."$BranchName.$Language.ini";
  48. if ( ! -e $IniFileName ) {
  49. logmsg( "Ini file $IniFileName not found ..." );
  50. return;
  51. }
  52. logmsg( "Ini file $IniFileName found ..." );
  53. return 1;
  54. }
  55. #
  56. # CheckIniFileQuietEx
  57. #
  58. # Arguments: $BranchName, $Language
  59. #
  60. # Purpose: validates existence of the appropriate ini file using branch and
  61. # language as passed. the difference between this and CheckIniFileEx
  62. # is that we do not log to screen or log file.
  63. #
  64. # Returns: true if found, undef otherwise
  65. #
  66. sub CheckIniFileQuietEx
  67. {
  68. # get passed args
  69. my( $BranchName, $Language ) = @_;
  70. # declare locals
  71. my( $IniFileName );
  72. if(lc $BranchName eq "xpsp1" )
  73. {
  74. $IniFileName = "$ENV{ RazzleToolPath }\\sp\\$BranchName.ini";
  75. }
  76. else
  77. {
  78. $IniFileName = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" .
  79. "$BranchName.$Language.ini";
  80. }
  81. if ( ! -e $IniFileName ) { return; }
  82. return 1;
  83. }
  84. #
  85. # GetSetting
  86. #
  87. # Arguments: @FieldNames
  88. #
  89. # Purpose: reads the given field name from the appropriate branch / lang ini
  90. # file. this file is determined through the _BuildBranch and lang
  91. # environment variables. the FieldNames array holds the field and
  92. # subfields to be matched, i.e. ( 'ReleaseServers', 'X86FRE' )
  93. #
  94. # Returns: $FieldValue or undef
  95. #
  96. sub GetSetting
  97. {
  98. # get passed args
  99. my( @FieldNames ) = @_;
  100. # declare locals
  101. my( $BranchName, $Language );
  102. # set up ini file name
  103. $BranchName = $ENV{ "_BuildBranch" };
  104. $Language = $ENV{ "lang" };
  105. # call GetSettingEx with the newly gotten parameters
  106. return &GetSettingEx( $BranchName, $Language, @FieldNames );
  107. }
  108. #
  109. # GetSettingQuietEx
  110. #
  111. # Arguments: @FieldNames, $BranchName, $Language
  112. #
  113. # Purpose: reads the given field name from the appropriate branch / lang ini
  114. # file.
  115. #
  116. # Returns: $FieldValue or undef
  117. #
  118. sub GetSettingQuietEx
  119. {
  120. # get passed args
  121. my( $BranchName, $Language, @FieldNames ) = @_;
  122. # declare locals
  123. my( $IniFileName );
  124. $IniFileName = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" .
  125. "$BranchName.$Language.ini";
  126. # check variables
  127. if ( !$BranchName || !$Language || ( ! -e $IniFileName ) ) {
  128. # error, don't log as we're quiet
  129. return;
  130. }
  131. ParseFileQuiet( $BranchName, $Language, $IniFileName, @FieldNames );
  132. }
  133. sub ParseFileQuiet
  134. {
  135. # get passed args
  136. my( $BranchName, $Language, $IniFileName, @FieldNames ) = @_;
  137. # declare locals
  138. my( @IniFileLines, $Line );
  139. my( $ThisField, $ThisValue );
  140. my( $Item, $LongFieldName );
  141. # get the field names
  142. foreach $Item ( @FieldNames ) {
  143. if ( $LongFieldName ) {
  144. $LongFieldName .= "::$Item";
  145. } else {
  146. $LongFieldName = $Item;
  147. }
  148. }
  149. # open and read the file
  150. unless ( open( INFILE, $IniFileName ) ) {
  151. # error, don't log as we're quiet
  152. return;
  153. }
  154. @IniFileLines = <INFILE>;
  155. close( INFILE );
  156. # parse file for the requested field
  157. foreach $Line ( @IniFileLines ) {
  158. chomp( $Line );
  159. if ( $Line =~ /^\;/ ) { next; }
  160. #
  161. # now we want to see if there is #include statement, and if so
  162. # begin reading the other file
  163. #
  164. if ( $Line =~ /^\#include/i ) {
  165. # get the name of the file to include. by definition, it must be
  166. # in postbuildscripts also
  167. my( $Junk, $IncludeFile );
  168. ( $Junk, $IncludeFile ) = split( /\s+/, $Line, 2 );
  169. $IncludeFile = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" .
  170. $IncludeFile;
  171. # print( "Include file is \'$IncludeFile\'\n" );
  172. my( $ReturnValue ) = &ParseFileQuiet( $BranchName, $Language,
  173. $IncludeFile, @FieldNames );
  174. if ( $ReturnValue ) {
  175. return( $ReturnValue );
  176. }
  177. # if we're here, we didn't find the field in the included file
  178. next;
  179. }
  180. ( $ThisField, $ThisValue ) = split( /\=/, $Line, 2 );
  181. # check if this is the requested field
  182. if ( defined $ThisField && $ThisField =~ /^\Q$LongFieldName\E$/i ) {
  183. # if so, return the associated value
  184. # dbgmsg( "Found value $ThisValue for field $ThisField" );
  185. return( $ThisValue );
  186. }
  187. }
  188. # we didn't find the requested field
  189. # note that we don't want to log an error here, caller can deal with that
  190. return;
  191. }
  192. #
  193. # GetSettingEx
  194. #
  195. # Arguments: @FieldNames, $BranchName, $Language
  196. #
  197. # Purpose: reads the given field name from the appropriate branch / lang ini
  198. # file.
  199. #
  200. # Returns: $FieldValue or undef
  201. #
  202. sub GetSettingEx
  203. {
  204. # get passed args
  205. my( $BranchName, $Language, @FieldNames ) = @_;
  206. # declare locals
  207. my( $IniFileName );
  208. if(lc $BranchName eq "xpsp1" )
  209. {
  210. $IniFileName = "$ENV{ RazzleToolPath }\\sp\\$BranchName.ini";
  211. }
  212. else
  213. {
  214. $IniFileName = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" .
  215. "$BranchName.$Language.ini";
  216. }
  217. # check variables
  218. if ( !$BranchName || !$Language || ( ! -e $IniFileName ) ) {
  219. errmsg( "Failed to see ini file $IniFileName ..." );
  220. return;
  221. }
  222. ParseFile( $BranchName, $Language, $IniFileName, @FieldNames );
  223. }
  224. sub ParseFile
  225. {
  226. # get passed args
  227. my( $BranchName, $Language, $IniFileName, @FieldNames ) = @_;
  228. # declare locals
  229. my( @IniFileLines, $Line );
  230. my( $ThisField, $ThisValue );
  231. my( $Item, $LongFieldName );
  232. # get the field names
  233. foreach $Item ( @FieldNames ) {
  234. if ( $LongFieldName ) {
  235. $LongFieldName .= "::$Item";
  236. } else {
  237. $LongFieldName = $Item;
  238. }
  239. }
  240. # open and read the file
  241. unless ( open( INFILE, $IniFileName ) ) {
  242. errmsg( "Failed to open ini file $IniFileName for read ..." );
  243. return;
  244. }
  245. @IniFileLines = <INFILE>;
  246. close( INFILE );
  247. # parse file for the requested field
  248. foreach $Line ( @IniFileLines ) {
  249. chomp( $Line );
  250. if ( $Line =~ /^\;/ ) { next; }
  251. #
  252. # now we want to see if there is #include statement, and if so
  253. # begin reading the other file
  254. #
  255. if ( $Line =~ /^\#include/i ) {
  256. # get the name of the file to include. by definition, it must be
  257. # in postbuildscripts also
  258. my( $Junk, $IncludeFile );
  259. ( $Junk, $IncludeFile ) = split( /\s+/, $Line, 2 );
  260. $IncludeFile = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" .
  261. $IncludeFile;
  262. # print( "Include file is \'$IncludeFile\'\n" );
  263. my( $ReturnValue ) = &ParseFileQuiet( $BranchName, $Language,
  264. $IncludeFile, @FieldNames );
  265. if ( $ReturnValue ) {
  266. return( $ReturnValue );
  267. }
  268. # if we're here, we didn't find the field in the included file
  269. next;
  270. }
  271. ( $ThisField, $ThisValue ) = split( /\=/, $Line, 2 );
  272. # check if this is the requested field
  273. if ( $ThisField =~ /^\Q$LongFieldName\E$/i ) {
  274. # if so, return the associated value
  275. dbgmsg( "Found value $ThisValue for field $ThisField" );
  276. return( $ThisValue );
  277. }
  278. }
  279. # we didn't find the requested field
  280. # note that we don't want to log an error here, caller can deal with that
  281. return;
  282. }
  283. 1;