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.

148 lines
4.6 KiB

  1. //+------------------------------------------------------------------
  2. //
  3. // File: cstrlen.cxx
  4. //
  5. // Contents: implementation for CStrLengthCmdlineObj
  6. //
  7. // Synoposis: Encapsulates a command line switch which takes an
  8. // length restricted string, eg: /password:<value>, where the
  9. // value must be between MINPASSWORD and MAXPASSWORD in
  10. // length
  11. //
  12. // Classes: CStrLengthCmdlineObj
  13. //
  14. // History: 12/27/91 Lizch Created
  15. // 04/17/92 Lizch Converted to NLS_STR
  16. // 09/09/92 Lizch Changed SUCCESS to NO_ERROR
  17. // 09/18/92 Lizch Precompile headers
  18. // 10/18/93 DeanE Converted to WCHAR
  19. //
  20. //-------------------------------------------------------------------
  21. #include <comtpch.hxx>
  22. #pragma hdrstop
  23. #include <cmdlinew.hxx> // public cmdlinew stuff
  24. #include "_clw.hxx" // private cmdlinew stuff
  25. #include <ctype.h> // is functions
  26. LPCNSTR nszCmdlineString = _TEXTN("Takes a string ");
  27. LPCNSTR nszLineArgString = _TEXTN("<string> ");
  28. //+------------------------------------------------------------------
  29. //
  30. // Member: CStrLengthCmdlineObj::SetValue, public
  31. //
  32. // Synoposis: Stores the specified value, eg "lizch" from
  33. // "username:lizch"
  34. //
  35. // Effects: This SetValue simply checks for length within
  36. // specified range, and then calls the base SetValue
  37. //
  38. // Arguments: [nszArg] - the string following the switch on the
  39. // command line. Excludes the equator (eg.
  40. // ':' or '=' ), if any.
  41. //
  42. // Returns: CMDLINE_NO_ERROR or CMDLINE_ERROR_INVALID_VALUE
  43. //
  44. // History: Created 12/27/91 Lizch
  45. // Converted to NLS_STR 04/17/92 Lizch
  46. //-------------------------------------------------------------------
  47. INT CStrLengthCmdlineObj::SetValue(LPCNSTR nszArg)
  48. {
  49. UINT cchArg;
  50. cchArg = _ncslen(nszArg);
  51. if ((cchArg >= _uiMinLength) && (cchArg <= _uiMaxLength))
  52. {
  53. return(CBaseCmdlineObj::SetValue(nszArg));
  54. }
  55. else
  56. {
  57. return(CMDLINE_ERROR_INVALID_VALUE);
  58. }
  59. }
  60. //+-------------------------------------------------------------------
  61. //
  62. // Method: CStrLengthCmdlineObj::QueryCmdlineType, protected, const
  63. //
  64. // Synoposis: returns a character pointer to the cmdline type.
  65. //
  66. // Arguments: None.
  67. //
  68. // Returns: const WCHAR pointer to string.
  69. //
  70. // History: 28-Jul-92 davey Created.
  71. //
  72. //--------------------------------------------------------------------
  73. LPCNSTR CStrLengthCmdlineObj::QueryCmdlineType() const
  74. {
  75. return(nszCmdlineString);
  76. }
  77. //+-------------------------------------------------------------------
  78. //
  79. // Method: CStrLengthCmdlineObj::QueryLineArgType, protected, const
  80. //
  81. // Synoposis: returns a character pointer to the line arg type.
  82. //
  83. // Arguments: None.
  84. //
  85. // Returns: const WCHAR pointer to string.
  86. //
  87. // History: 28-Jul-92 davey Created.
  88. //
  89. //--------------------------------------------------------------------
  90. LPCNSTR CStrLengthCmdlineObj::QueryLineArgType() const
  91. {
  92. // if user has not defined one then give default one
  93. if (_pnszLineArgType == NULL)
  94. {
  95. return(nszLineArgString);
  96. }
  97. else
  98. {
  99. return(_pnszLineArgType);
  100. }
  101. }
  102. //+------------------------------------------------------------------
  103. //
  104. // Member: CStrListCmdlineObj::DisplaySpecialUsage, protected
  105. //
  106. // Synoposis: Prints the switch usage statement according to current
  107. // display method. Generally this will be stdout.
  108. //
  109. // Arguments: [usDisplayWidth] - total possible width available to display
  110. // [usIndent] - amount to indent
  111. // [pusWidth] - space to print on current line
  112. //
  113. // Returns: error code from QueryError,
  114. // error code from DisplayStringByWords
  115. //
  116. // History: 05/14/91 Lizch Created
  117. // 07/29/92 Davey Modified to work with new usage display
  118. //-------------------------------------------------------------------
  119. INT CStrLengthCmdlineObj::DisplaySpecialUsage(
  120. USHORT usDisplayWidth,
  121. USHORT usIndent,
  122. USHORT *pusWidth)
  123. {
  124. NCHAR nszBuf[100];
  125. _sNprintf(nszBuf,
  126. _TEXTN("The string must be between %u and %u characters in length."),
  127. _uiMinLength,
  128. _uiMaxLength);
  129. return(DisplayStringByWords(
  130. nszBuf,
  131. usDisplayWidth,
  132. usIndent,
  133. pusWidth));
  134. }