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.

232 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. PWORD.C
  5. Abstract:
  6. Convert parsing routines for YES/NO and weekday
  7. Author:
  8. Dan Hinsley (danhi) 06-Jun-1991
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. 31-May-1989 chuckc
  13. Created
  14. 24-Apr-1991 danhi
  15. 32 bit NT version
  16. 06-Jun-1991 Danhi
  17. Sweep to conform to NT coding style
  18. 01-Oct-1992 JohnRo
  19. RAID 3556: Added NetpSystemTimeToGmtTime() for DosPrint APIs.
  20. --*/
  21. //
  22. // INCLUDES
  23. //
  24. #include <windows.h> // IN, LPTSTR, etc.
  25. #include <lmcons.h>
  26. #include <lui.h>
  27. #include <stdio.h>
  28. #include <malloc.h>
  29. /*
  30. * Should I put the ID in apperr2.h ?
  31. * but we should sync the .mc file.
  32. */
  33. #include "netmsg.h"
  34. #include <luitext.h>
  35. #include "netascii.h"
  36. #include <tchar.h>
  37. #include <nettext.h> // for swtxt_SW_*
  38. /*-- static data for weeks info --*/
  39. static searchlist_data week_data[] = {
  40. {APE2_GEN_NONLOCALIZED_MONDAY, 0},
  41. {APE2_GEN_NONLOCALIZED_TUESDAY, 1},
  42. {APE2_GEN_NONLOCALIZED_WEDNSDAY, 2},
  43. {APE2_GEN_NONLOCALIZED_THURSDAY, 3},
  44. {APE2_GEN_NONLOCALIZED_FRIDAY, 4},
  45. {APE2_GEN_NONLOCALIZED_SATURDAY, 5},
  46. {APE2_GEN_NONLOCALIZED_SUNDAY, 6},
  47. {APE2_GEN_NONLOCALIZED_MONDAY_ABBREV, 0},
  48. {APE2_GEN_NONLOCALIZED_TUESDAY_ABBREV, 1},
  49. {APE2_GEN_NONLOCALIZED_WEDNSDAY_ABBREV, 2},
  50. {APE2_GEN_NONLOCALIZED_THURSDAY_ABBREV, 3},
  51. {APE2_GEN_NONLOCALIZED_FRIDAY_ABBREV, 4},
  52. {APE2_GEN_NONLOCALIZED_SATURDAY_ABBREV, 5},
  53. {APE2_GEN_NONLOCALIZED_SATURDAY_ABBREV2,5},
  54. {APE2_GEN_NONLOCALIZED_SUNDAY_ABBREV, 6},
  55. {APE2_GEN_MONDAY_ABBREV, 0},
  56. {APE2_GEN_TUESDAY_ABBREV, 1},
  57. {APE2_GEN_WEDNSDAY_ABBREV, 2},
  58. {APE2_GEN_THURSDAY_ABBREV, 3},
  59. {APE2_GEN_FRIDAY_ABBREV, 4},
  60. {APE2_GEN_SATURDAY_ABBREV, 5},
  61. {APE2_TIME_SATURDAY_ABBREV2, 5},
  62. {APE2_GEN_SUNDAY_ABBREV, 6},
  63. {APE2_GEN_MONDAY, 0},
  64. {APE2_GEN_TUESDAY, 1},
  65. {APE2_GEN_WEDNSDAY, 2},
  66. {APE2_GEN_THURSDAY, 3},
  67. {APE2_GEN_FRIDAY, 4},
  68. {APE2_GEN_SATURDAY, 5},
  69. {APE2_GEN_SUNDAY, 6},
  70. {0,0}
  71. } ;
  72. #define DAYS_IN_WEEK (7)
  73. #define NUM_DAYS_LIST (sizeof(week_data)/sizeof(week_data[0])+DAYS_IN_WEEK)
  74. /*
  75. * NOTE - we init the first 7 hardwired days
  76. * and get the rest from the message file
  77. */
  78. static searchlist week_list[NUM_DAYS_LIST + DAYS_IN_WEEK] =
  79. {
  80. {LUI_txt_monday, 0},
  81. {LUI_txt_tuesday, 1},
  82. {LUI_txt_wednesday, 2},
  83. {LUI_txt_thursday, 3},
  84. {LUI_txt_friday, 4},
  85. {LUI_txt_saturday, 5},
  86. {LUI_txt_sunday, 6}
  87. } ;
  88. /*
  89. * Name: ParseWeekDay
  90. * Takes a string and parses it for a week day
  91. * Args: PTCHAR inbuf - string to parse
  92. * PDWORD answer - set to 0-6, if inbuf is a weekday,
  93. * undefined otherwise.
  94. * Returns: 0 if ok,
  95. * ERROR_INVALID_PARAMETER or NERR_InternalError otherwise.
  96. * Globals: (none)
  97. * Statics: (none)
  98. * Remarks:
  99. * Updates: (none)
  100. */
  101. DWORD
  102. ParseWeekDay(
  103. PTCHAR inbuf,
  104. PDWORD answer
  105. )
  106. {
  107. TCHAR buffer[256] ;
  108. DWORD bytesread ;
  109. LONG result ;
  110. if (inbuf == NULL || inbuf[0] == NULLC)
  111. {
  112. return ERROR_INVALID_PARAMETER;
  113. }
  114. if (ILUI_setup_listW(buffer, DIMENSION(buffer), 2, &bytesread,
  115. week_data,week_list))
  116. {
  117. return NERR_InternalError;
  118. }
  119. if (ILUI_traverse_slistW(inbuf, week_list, &result))
  120. {
  121. return ERROR_INVALID_PARAMETER;
  122. }
  123. *answer = result ;
  124. return 0;
  125. }
  126. /*----------- Yes or No ------------*/
  127. static searchlist_data yesno_data[] = {
  128. {APE2_GEN_YES, LUI_YES_VAL},
  129. {APE2_GEN_NO, LUI_NO_VAL},
  130. {APE2_GEN_NLS_YES_CHAR, LUI_YES_VAL},
  131. {APE2_GEN_NLS_NO_CHAR, LUI_NO_VAL},
  132. {0,0}
  133. } ;
  134. #define NUM_YESNO_LIST (sizeof(yesno_data)/sizeof(yesno_data[0])+2)
  135. static searchlist yesno_list[NUM_YESNO_LIST+2] = {
  136. {LUI_txt_yes, LUI_YES_VAL},
  137. {LUI_txt_no, LUI_NO_VAL},
  138. } ;
  139. /*
  140. * Name: LUI_ParseYesNo
  141. * Takes a string and parses it for YES or NO.
  142. * Args: PTCHAR inbuf - string to parse
  143. * PUSHORT answer - set to LUI_YES_VAL or LUI_NO_VAL
  144. * if inbuf matches YES/NO, undefined otherwise.
  145. * Returns: 0 if ok,
  146. * ERROR_INVALID_PARAMETER or NERR_InternalError otherwise.
  147. * Globals: yesno_data, yesno_list
  148. * Statics: (none)
  149. * Remarks:
  150. * Updates: (none)
  151. */
  152. DWORD
  153. LUI_ParseYesNo(
  154. PTCHAR inbuf,
  155. PDWORD answer
  156. )
  157. {
  158. TCHAR buffer[128] ;
  159. DWORD bytesread ;
  160. LONG result ;
  161. DWORD err;
  162. if (inbuf == NULL || inbuf[0] == NULLC)
  163. {
  164. return ERROR_INVALID_PARAMETER;
  165. }
  166. if (err = ILUI_setup_listW(buffer, DIMENSION(buffer), 2,
  167. &bytesread, yesno_data, yesno_list))
  168. {
  169. return err;
  170. }
  171. if (ILUI_traverse_slistW(inbuf, yesno_list, &result))
  172. {
  173. if (!_tcsicmp(inbuf, &swtxt_SW_YES[1]))
  174. {
  175. *answer = LUI_YES_VAL;
  176. return 0;
  177. }
  178. else if (!_tcsicmp(inbuf, &swtxt_SW_NO[1]))
  179. {
  180. *answer = LUI_NO_VAL;
  181. return 0;
  182. }
  183. else
  184. {
  185. return ERROR_INVALID_PARAMETER;
  186. }
  187. }
  188. *answer = result;
  189. return 0;
  190. }