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.

150 lines
2.8 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. /* Constants */
  32. /* Forward declarations */
  33. /* extern function prototypes */
  34. /***
  35. * Find the first occurrence of a COLON in a string.
  36. * Replace the COLON will a 0, and return the a pointer
  37. * to the TCHAR following the COLON.
  38. *
  39. * Return NULL is there is no COLON in the string.
  40. */
  41. TCHAR *FindColon(TCHAR * string)
  42. {
  43. TCHAR * pos;
  44. if (pos = _tcschr(string, COLON))
  45. {
  46. *pos = NULLC;
  47. return(pos+1);
  48. }
  49. return NULL;
  50. }
  51. /****************** Ascii to Number conversions ***************/
  52. /*
  53. * do an ascii to unsigned int conversion
  54. */
  55. USHORT do_atou(TCHAR *pos, USHORT err, TCHAR *text)
  56. {
  57. USHORT val ;
  58. if ( n_atou(pos,&val) != 0 ) {
  59. ErrorExitInsTxt(err,text) ;
  60. } else {
  61. return(val) ;
  62. }
  63. return 0;
  64. }
  65. /*
  66. * do an ascii to ULONG conversion
  67. */
  68. ULONG do_atoul(TCHAR *pos, USHORT err, TCHAR *text)
  69. {
  70. ULONG val ;
  71. if ( n_atoul(pos,&val) != 0 ) {
  72. ErrorExitInsTxt(err,text) ;
  73. } else {
  74. return(val) ;
  75. }
  76. return 0;
  77. }
  78. /*
  79. *
  80. * Remarks:
  81. * 1) Check if all TCHAR are numeric.
  82. * 2) Check if > 5 TCHAR in string.
  83. * 3) do atol, and see if result > 64K.
  84. */
  85. USHORT n_atou(TCHAR * pos, USHORT * val)
  86. {
  87. LONG tL = 0;
  88. *val = 0 ;
  89. if (!IsNumber(pos))
  90. return(1) ;
  91. if (_tcslen(pos) > ASCII_US_LEN)
  92. return(1) ;
  93. tL = (LONG)_tcstod(pos, NULL);
  94. if (tL > MAX_US_VALUE)
  95. return(1) ;
  96. *val = (USHORT) tL;
  97. return(0) ;
  98. }
  99. /* n_atoul - convert ascii string to ULONG with some verification
  100. *
  101. * Remarks:
  102. * 1) Check if all TCHAR are numeric.
  103. * 2) Check if > 10 TCHAR in string.
  104. * 3) do atol.
  105. */
  106. USHORT n_atoul(TCHAR * pos, ULONG * val)
  107. {
  108. DWORD len;
  109. *val = 0L ;
  110. if (!IsNumber(pos))
  111. return(1) ;
  112. if ( ( len = _tcslen(pos ) ) > ASCII_UL_LEN)
  113. return(1) ;
  114. if (len == ASCII_UL_LEN)
  115. {
  116. if( _tcscmp( pos, ASCII_MAX_UL_VAL ) > 0 )
  117. return(1) ;
  118. }
  119. *val = (ULONG)_tcstod(pos, NULL) ;
  120. return(0) ;
  121. }