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.

165 lines
3.7 KiB

  1. use strict;
  2. use lib $ENV{ "RazzleToolPath" } . "\\PostBuildScripts";
  3. use GetIniSetting;
  4. use Logmsg;
  5. #
  6. # CmdIniSetting
  7. #
  8. # Arguments: -f:fieldname [-l:lang]
  9. #
  10. # Purpose: returns the value for the specified field name to stdout.
  11. # if the field does not exist, nothing is written to stdout.
  12. #
  13. # Returns: 0 if successful, 1 if .ini file is not found, 2 if no
  14. # field is found, 3 if bad usage or otherwise.
  15. #
  16. #
  17. # declare some globals
  18. #
  19. my( @FieldNames ); # stores field name from command line
  20. my( $Language ); # if lang parameter is passed
  21. my( $BuildBranch ) = $ENV{ "_BuildBranch" }; # store build branch
  22. my( $BranchName ); # stores branch to lookup if passed
  23. #
  24. # read command line
  25. #
  26. unless ( &ParseCommandLine( @ARGV ) ) {
  27. # do not log to stdout by design
  28. # errmsg( "Command line not processed correctly!" );
  29. exit( 3 );
  30. }
  31. # at this point, $Language is set if passed on cmd line, and
  32. # @FieldNames is set to the user given flag
  33. #
  34. # we want to set language to usa if not defined on cmd line
  35. if ( ! defined( $Language ) ) { $Language = "usa"; }
  36. # we also want to use the passed branch if there was one
  37. if ( $BranchName ) { $BuildBranch = $BranchName; }
  38. #
  39. # verify existence of ini file
  40. #
  41. unless ( &GetIniSetting::CheckIniFileQuietEx( $BuildBranch, $Language ) ) {
  42. # do not log to stdout by design
  43. # errmsg( "Ini file not found, exiting." );
  44. exit( 1 );
  45. }
  46. #
  47. # verify that the user passed a field to check for
  48. #
  49. unless ( @FieldNames ) {
  50. # do not log to stdout by design
  51. # errmsg( "Bad usage!" );
  52. exit( 3 );
  53. }
  54. #
  55. # get the setting and print to stdout if found
  56. #
  57. my( $Value );
  58. if ( $Value = &GetIniSetting::GetSettingQuietEx( $BuildBranch, $Language,
  59. @FieldNames ) ) {
  60. # setting found for this field
  61. # log to stdout by design
  62. print( "$Value\n" );
  63. exit( 0 );
  64. } else {
  65. # no setting found for this field
  66. # do not log to stdout by design
  67. # errmsg( "No settings found for @FieldNames" );
  68. exit( 2 );
  69. }
  70. #
  71. # we should never get here, just exit with general error level
  72. #
  73. errmsg( "This code should never be run." );
  74. exit( 3 );
  75. #
  76. # ParseCommandLine
  77. #
  78. # Arguments: @ARGV
  79. #
  80. # Purpose: read the -f flag if passed, and -l. if -? is found, go to usage
  81. #
  82. # Returns: true if all args parsed, undef otherwise
  83. #
  84. sub ParseCommandLine
  85. {
  86. # get passed args
  87. my( @Arguments ) = @_;
  88. # declare locals
  89. my( $Argument ); # loop variable
  90. # parse command line
  91. foreach $Argument ( @Arguments ) {
  92. if ( $Argument =~ /^[\/\-]?\?$/ ) { &UsageAndQuit(); }
  93. elsif ( $Argument =~ /^[\/\-][lL]:(.+)$/ ) { $Language = "\L$1"; }
  94. elsif ( $Argument =~ /^[\/\-][bB]:(.+)$/ ) { $BranchName = "\L$1"; }
  95. elsif ( $Argument =~ /^[\/\-][fF]:(.+)$/ ) { @FieldNames = $1; }
  96. else {
  97. # unrecognized argument!
  98. errmsg( "Unrecongized argument \'$Argument\' ..." );
  99. &UsageAndQuit();
  100. }
  101. }
  102. # all args parsed
  103. return( 1 );
  104. }
  105. #
  106. # UsageAndQuit
  107. #
  108. # Arguments: none
  109. #
  110. # Purpose: display usage and error out
  111. #
  112. # Returns: nothing
  113. #
  114. sub UsageAndQuit
  115. {
  116. print( "CmdIniSetting -f:fieldname [-l:lang] [-b:branch]\n" );
  117. print( "\n\t-f:fieldname\tName of field to read\n" );
  118. print( "\t-l:lang\tRead from lang's ini file\n" );
  119. print( "\t-b:branch\tBranch to read .ini file of\n" );
  120. print( "\nCmdIniSetting will read from the appropriate lab and language\n" );
  121. print( "ini file, and return the value for that field to stdout. If the field\n" );
  122. print( "is found and returned to stdout, exit code is zero. Exit code 1\n" );
  123. print( "implies the field was not found. Exit code 2 implies the ini file\n" );
  124. print( "was not found. Exit code 3 is for all other errors.\n" );
  125. exit( 3 );
  126. }