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.

173 lines
3.3 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1987-1992 **/
  4. /********************************************************************/
  5. /***
  6. * misc.c
  7. * common utility functions used by netcmd
  8. *
  9. * History:
  10. */
  11. /* Include files */
  12. #define INCL_NOCOMMON
  13. #define INCL_DOSMEMMGR
  14. #define INCL_DOSFILEMGR
  15. #define INCL_DOSSIGNALS
  16. #define INCL_ERRORS
  17. #include <os2.h>
  18. #include <lmcons.h>
  19. #include <apperr.h>
  20. #include <apperr2.h>
  21. #include <lmerr.h>
  22. #define INCL_ERROR_H
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <icanon.h>
  26. #include <malloc.h>
  27. #include <netcmds.h>
  28. #include "nettext.h"
  29. #include <tchar.h>
  30. #include <netascii.h>
  31. /***
  32. * Find the first occurrence of a COLON in a string.
  33. * Replace the COLON will a 0, and return the a pointer
  34. * to the WCHAR following the COLON.
  35. *
  36. * Return NULL is there is no COLON in the string.
  37. */
  38. LPWSTR
  39. FindColon(
  40. LPWSTR string
  41. )
  42. {
  43. LPWSTR pos;
  44. if (pos = wcschr(string, COLON))
  45. {
  46. *pos = NULLC;
  47. return (pos + 1);
  48. }
  49. return NULL;
  50. }
  51. /***
  52. * Find the first occurrence of a COMMA in a string.
  53. * Replace the COMMA will a 0, and return the a pointer
  54. * to the WCHAR following the COMMA.
  55. *
  56. * Return NULL is there is no COMMA in the string.
  57. */
  58. LPWSTR
  59. FindComma(
  60. LPWSTR string
  61. )
  62. {
  63. LPWSTR pos;
  64. if (pos = wcschr(string, COMMA))
  65. {
  66. *pos = NULLC;
  67. return (pos + 1);
  68. }
  69. return NULL;
  70. }
  71. /****************** Ascii to Number conversions ***************/
  72. /*
  73. * do an ascii to unsigned int conversion
  74. */
  75. USHORT do_atou(TCHAR *pos, USHORT err, TCHAR *text)
  76. {
  77. USHORT val ;
  78. if ( n_atou(pos,&val) != 0 ) {
  79. ErrorExitInsTxt(err,text) ;
  80. } else {
  81. return(val) ;
  82. }
  83. return 0;
  84. }
  85. /*
  86. * do an ascii to ULONG conversion
  87. */
  88. ULONG do_atoul(TCHAR *pos, USHORT err, TCHAR *text)
  89. {
  90. ULONG val ;
  91. if ( n_atoul(pos,&val) != 0 ) {
  92. ErrorExitInsTxt(err,text) ;
  93. } else {
  94. return(val) ;
  95. }
  96. return 0;
  97. }
  98. /*
  99. *
  100. * Remarks:
  101. * 1) Check if all TCHAR are numeric.
  102. * 2) Check if > 5 TCHAR in string.
  103. * 3) do atol, and see if result > 64K.
  104. */
  105. USHORT n_atou(TCHAR * pos, USHORT * val)
  106. {
  107. LONG tL = 0;
  108. *val = 0 ;
  109. if (!IsNumber(pos))
  110. return(1) ;
  111. if (_tcslen(pos) > ASCII_US_LEN)
  112. return(1) ;
  113. tL = (LONG)_tcstod(pos, NULL);
  114. if (tL > MAX_US_VALUE)
  115. return(1) ;
  116. *val = (USHORT) tL;
  117. return(0) ;
  118. }
  119. /* n_atoul - convert ascii string to ULONG with some verification
  120. *
  121. * Remarks:
  122. * 1) Check if all TCHAR are numeric.
  123. * 2) Check if > 10 TCHAR in string.
  124. * 3) do atol.
  125. */
  126. USHORT n_atoul(TCHAR * pos, ULONG * val)
  127. {
  128. DWORD len;
  129. *val = 0L ;
  130. if (!IsNumber(pos))
  131. return(1) ;
  132. if ( ( len = _tcslen(pos ) ) > ASCII_UL_LEN)
  133. return(1) ;
  134. if (len == ASCII_UL_LEN)
  135. {
  136. if( _tcscmp( pos, ASCII_MAX_UL_VAL ) > 0 )
  137. return(1) ;
  138. }
  139. *val = (ULONG)_tcstod(pos, NULL) ;
  140. return(0) ;
  141. }