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.

203 lines
4.4 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /*
  4. ** Purpose:
  5. ** Duplicates a zero terminated string into a newly allocated buffer
  6. ** just large enough to hold the source string and its zero terminator.
  7. ** Arguments:
  8. ** sz: non-NULL zero terminated string to duplicate.
  9. ** Returns:
  10. ** NULL if a new buffer to hold the duplicated string cannot be allocated.
  11. ** Pointer to a newly allocated buffer into which sz has been copied with
  12. ** its zero terminator.
  13. **
  14. ***************************************************************************/
  15. SZ APIENTRY SzDupl(sz)
  16. SZ sz;
  17. {
  18. SZ szNew;
  19. AssertDataSeg();
  20. ChkArg(sz != (SZ)NULL, 1, (SZ)NULL);
  21. if ((szNew = (SZ)SAlloc(strlen(sz) + 1)) != (SZ)NULL)
  22. strcpy(szNew, sz);
  23. return(szNew);
  24. }
  25. /*
  26. ** Purpose:
  27. ** Compares two zero terminated strings lexicographically and with
  28. ** case-sensitivity. Comparison depends on the current language
  29. ** selected by the user.
  30. ** Arguments:
  31. ** sz1: non-NULL zero terminated string to compare.
  32. ** sz2: non-NULL zero terminated string to compare.
  33. ** Returns:
  34. ** crcError for errors.
  35. ** crcEqual if the strings are lexicographically equal.
  36. ** crcFirstHigher if sz1 is lexicographically greater than sz2.
  37. ** crcSecondHigher if sz2 is lexicographically greater than sz1.
  38. **
  39. ***************************************************************************/
  40. CRC APIENTRY CrcStringCompare(sz1, sz2)
  41. SZ sz1;
  42. SZ sz2;
  43. {
  44. INT iCmpReturn;
  45. AssertDataSeg();
  46. ChkArg(sz1 != (SZ)NULL, 1, crcError);
  47. ChkArg(sz2 != (SZ)NULL, 2, crcError);
  48. if ((iCmpReturn = lstrcmp((LPSTR)sz1, (LPSTR)sz2)) == 0)
  49. return(crcEqual);
  50. else if (iCmpReturn < 0)
  51. return(crcSecondHigher);
  52. else
  53. return(crcFirstHigher);
  54. }
  55. /*
  56. ** Purpose:
  57. ** Compares two zero terminated strings lexicographically and without
  58. ** case-sensitivity. Comparison depends on the current language
  59. ** selected by the user.
  60. ** Arguments:
  61. ** sz1: non-NULL zero terminated string to compare.
  62. ** sz2: non-NULL zero terminated string to compare.
  63. ** Returns:
  64. ** crcError for errors.
  65. ** crcEqual if the strings are lexicographically equal.
  66. ** crcFirstHigher if sz1 is lexicographically greater than sz2.
  67. ** crcSecondHigher if sz2 is lexicographically greater than sz1.
  68. **
  69. ***************************************************************************/
  70. CRC APIENTRY CrcStringCompareI(sz1, sz2)
  71. SZ sz1;
  72. SZ sz2;
  73. {
  74. INT iCmpReturn;
  75. AssertDataSeg();
  76. ChkArg(sz1 != (SZ)NULL, 1, crcError);
  77. ChkArg(sz2 != (SZ)NULL, 2, crcError);
  78. if ((iCmpReturn = lstrcmpi((LPSTR)sz1, (LPSTR)sz2)) == 0)
  79. return(crcEqual);
  80. else if (iCmpReturn < 0)
  81. return(crcSecondHigher);
  82. else
  83. return(crcFirstHigher);
  84. }
  85. /*
  86. ** Purpose:
  87. ** Finds the last character in a string.
  88. ** Arguments:
  89. ** sz: non-NULL zero terminated string to search for end in.
  90. ** Returns:
  91. ** NULL for an empty string.
  92. ** non-Null string pointer to the last valid character in sz.
  93. **
  94. ***************************************************************************/
  95. SZ APIENTRY SzLastChar(sz)
  96. SZ sz;
  97. {
  98. SZ szCur = (SZ)NULL;
  99. SZ szNext = sz;
  100. AssertDataSeg();
  101. ChkArg(sz != (SZ)NULL, 1, (SZ)NULL);
  102. while (*szNext != '\0')
  103. {
  104. szNext = SzNextChar((szCur = szNext));
  105. Assert(szNext != (SZ)NULL);
  106. }
  107. return(szCur);
  108. }
  109. #define MAX_BUFFER 1024
  110. extern CHAR ReturnTextBuffer[MAX_BUFFER];
  111. /*
  112. ToLower - this function will convert the string to lower case.
  113. Input: Arg[0] - string to be convertd.
  114. Output: lower case string.
  115. */
  116. BOOL
  117. ToLower(
  118. IN DWORD cArgs,
  119. IN LPSTR Args[],
  120. OUT LPSTR *TextOut
  121. )
  122. {
  123. int i; // counter
  124. CHAR *pszTmp = ReturnTextBuffer;
  125. if ( cArgs < 1 )
  126. {
  127. SetErrorText(IDS_ERROR_BADARGS);
  128. return( FALSE );
  129. }
  130. for (i=0;(Args[0][i]!='\0') && (i<MAX_BUFFER);i++,pszTmp++)
  131. {
  132. *pszTmp = (CHAR)tolower(Args[0][i]);
  133. }
  134. *pszTmp='\0';
  135. *TextOut = ReturnTextBuffer;
  136. return TRUE;
  137. }
  138. /*
  139. SetupStrncmp - Similar to c strncmp runtime library
  140. The user must passed 3 arguments to the function.
  141. 1st argument - the first string
  142. 2nd argument - the second string
  143. 3rd argument - number of characters compared
  144. Provide the same function as strncmp
  145. */
  146. BOOL
  147. SetupStrncmp(
  148. IN DWORD cArgs,
  149. IN LPSTR Args[],
  150. OUT LPSTR *TextOut
  151. )
  152. {
  153. if ( cArgs != 3 )
  154. {
  155. SetErrorText(IDS_ERROR_BADARGS);
  156. return( FALSE );
  157. }
  158. wsprintf( ReturnTextBuffer, "%d", strncmp( Args[0], Args[1], atol(Args[2])));
  159. *TextOut = ReturnTextBuffer;
  160. return TRUE;
  161. }