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.

224 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. luiint.c
  5. Abstract:
  6. This module provides routines for setting up search lists of string/value
  7. pairs using messages in the NET.MSG message file, and for traversing
  8. such a search list.
  9. Author:
  10. Dan Hinsley (danhi) 06-Jun-1991
  11. Environment:
  12. User Mode - Win32
  13. Revision History:
  14. 10-Jul-1989 chuckc
  15. Created
  16. 24-Apr-1991 danhi
  17. 32 bit NT version
  18. 06-Jun-1991 Danhi
  19. Sweep to conform to NT coding style
  20. 01-Oct-1992 JohnRo
  21. RAID 3556: Added NetpSystemTimeToGmtTime() for DosPrint APIs.
  22. 20-Feb-1993 YiHsinS
  23. Moved from netcmd\map32\search.c. And added LUI_GetMessageIns.
  24. --*/
  25. //
  26. // INCLUDES
  27. //
  28. #include <windows.h> // IN, LPTSTR, etc.
  29. #include <lmcons.h>
  30. #include <stdio.h>
  31. #include <lmerr.h>
  32. #include <luiint.h>
  33. #include <netlib.h>
  34. /*-- routines proper --*/
  35. /*
  36. * Name: ILUI_setup_list
  37. * Given an array of 'search_list_data' (ie. msgno/value
  38. * pairs), create a string/value pair using the messages
  39. * in the message file.
  40. * Args: char * buffer - for holding the meesages retrieved
  41. * USHORT bufsiz - size of the above buffer
  42. * USHORT offset - the number of items already setup
  43. * in slist, we will offset our retrieved
  44. * string/value pais by this much.
  45. * PUSHORT bytesread - the number of bytes read into buffer
  46. * searchlist_data sdata[] - input array of msgno/value pairs,
  47. * we stop when we hit a message number
  48. * of 0
  49. * searchlist slist[] - will receive the string/value pairs
  50. * (string will be pointers into buffer)
  51. * Returns: 0 if ok, NERR_BufTooSmall otherwise.
  52. * Globals: (none)
  53. * Statics: (none)
  54. * Remarks: WARNING! We assume the caller KNOWs that slist is big enough
  55. * for the pairs to be retrieved. This can be determined statically
  56. * while buffer size cannot. Hence we provide checks for the
  57. * latter.
  58. * Updates: (none)
  59. */
  60. USHORT
  61. ILUI_setup_list(
  62. CHAR *buffer,
  63. USHORT bufsiz,
  64. USHORT offset,
  65. PUSHORT bytesread,
  66. searchlist_data sdata[],
  67. searchlist slist[]
  68. )
  69. {
  70. USHORT err ;
  71. unsigned int msglen ;
  72. int i ;
  73. *bytesread = 0 ;
  74. for ( i=0; sdata[i].msg_no != 0; i++)
  75. {
  76. if (err = LUI_GetMsgIns(NULL,0,buffer,bufsiz,sdata[i].msg_no,
  77. (unsigned far *)&msglen))
  78. return(err) ;
  79. slist[i+offset].s_str = buffer ;
  80. slist[i+offset].val = sdata[i].value ;
  81. buffer += msglen+1 ;
  82. bufsiz -= msglen+1 ;
  83. *bytesread += msglen+1 ;
  84. }
  85. return(0) ;
  86. }
  87. /*
  88. * Name: ILUI_traverse_slist
  89. * traverse a searchlist ('slist') of string/number pairs,
  90. * and return the number matching string 'str'.
  91. * Args: char * pszStr - the string to search for
  92. * searchlist * slist - pointer to head of a searchlist
  93. * int * pusVal - pointer to variable that receives
  94. * the vale retrieved
  95. * Returns: 0 if found, -1 otherwise.
  96. * Globals: (none)
  97. * Statics: (none)
  98. * Remarks: (none)
  99. * Updates: (none)
  100. */
  101. USHORT
  102. ILUI_traverse_slist(
  103. PCHAR pszStr,
  104. searchlist * slist,
  105. SHORT * pusVal
  106. )
  107. {
  108. if (!slist)
  109. return( (USHORT) -1) ;
  110. while (slist->s_str)
  111. {
  112. if (_stricmp(pszStr,slist->s_str) == 0)
  113. {
  114. *pusVal = slist->val ;
  115. return(0) ;
  116. }
  117. ++slist ;
  118. }
  119. return( (USHORT) -1) ;
  120. }
  121. /*
  122. * Name: LUI_GetMsgIns
  123. * This routine is very similar to DOSGETMESSAGE,
  124. * except it:
  125. * 1) looks for messages in specific files
  126. * in a specific order:
  127. * a) MESSAGE_FILE in <lanman_dir>
  128. * b) MESSAGE_FILENAME in DPATH
  129. * c) OS2MSG_FILENAME in DPATH
  130. * 2) guarantees a null terminates string
  131. * 3) will accept NULL for msglen (see below).
  132. * Args: istrings : pointer to table of insert strings
  133. * nstrings : number of insert strings
  134. * msgbuf : buffer to hold message retrieved
  135. * bufsize : size of buffer
  136. * msgno : message number
  137. * msglen : pointer to variable that will receive message length
  138. * Returns: zero if ok, the DOSGETMESSAGE error code otherwise
  139. * Globals: (none)
  140. * Statics: NetMsgFileName, OS2MsgFileName
  141. */
  142. USHORT
  143. LUI_GetMsgIns(
  144. PCHAR *istrings,
  145. USHORT nstrings,
  146. PSZ msgbuf,
  147. USHORT bufsize,
  148. ULONG msgno,
  149. unsigned int *msglen
  150. )
  151. {
  152. USHORT result, tmplen ;
  153. static WCHAR NetMsgFileName[PATHLEN+1] = { 0 };
  154. static WCHAR OS2MsgFileName[PATHLEN+1] = { 0 };
  155. *msgbuf = '\0' ;
  156. /* make a path to the LANMAN message file */
  157. if (NetMsgFileName[0] == '\0') {
  158. wcscpy(NetMsgFileName, MESSAGE_FILENAME);
  159. }
  160. /* make a path to the OS/2 message file */
  161. if (OS2MsgFileName[0] == '\0') {
  162. wcscpy(OS2MsgFileName, OS2MSG_FILENAME);
  163. }
  164. result = DosGetMessage( istrings,
  165. nstrings,
  166. msgbuf,
  167. (USHORT) (bufsize - 1),
  168. (USHORT) msgno,
  169. NetMsgFileName,
  170. &tmplen);
  171. if (result == ERROR_MR_MID_NOT_FOUND) { /* cannot find */
  172. /* try OS2 message file instead */
  173. result = DosGetMessage(istrings,
  174. nstrings,
  175. msgbuf,
  176. (USHORT) (bufsize - 1),
  177. (USHORT) msgno,
  178. OS2MsgFileName,
  179. &tmplen);
  180. }
  181. /*
  182. * in all DosGetMessage above we passed it bufsize-1, so we are
  183. * assure of at least one spare byte for the \0 terminator.
  184. */
  185. msgbuf[tmplen] = '\0' ;
  186. if (msglen != NULL) {
  187. *msglen = tmplen ;
  188. }
  189. return(result) ;
  190. }