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.

351 lines
14 KiB

  1. /* standard header for gutils.dll library functions
  2. * include after windows.h
  3. */
  4. #define DimensionOf(x) (sizeof(x) / sizeof(x[0]))
  5. /*--------win-16 win-32 porting macros etc ----------------------------*/
  6. /* win32 msg crackers */
  7. #define GET_WM_COMMAND_ID(w, l) (LOWORD(w))
  8. #define GET_WM_COMMAND_CMD(w, l) (HIWORD(w))
  9. #define GET_WM_COMMAND_HWND(w, l) (l)
  10. #define GET_SCROLL_OPCODE(w, l) (LOWORD(w))
  11. #define GET_SCROLL_POS(w, l) (HIWORD(w))
  12. /* use of WNDPROC and FARPROC don't match up in definitions of
  13. * Win 3.1 functions vs NT functions. WINPROCTYPE matches WNDPROC
  14. * in NT and FARPROC in Win 3.1 so there are no warnings in either.
  15. * Places that use FARPROC in both APIs continue to use FARPROC.
  16. */
  17. #define WINPROCTYPE WNDPROC
  18. // #define DLGPROC WNDPROC Doesn't wash on MIPS!!
  19. /* ------- memory allocator ------------------------------------------*/
  20. /* global heap functions - allocate and free many small
  21. * pieces of memory by calling global alloc for large pieces -
  22. * avoids using too many selectors
  23. *
  24. * DOGMA:
  25. * If you go running things on different threads and then try to EXIT
  26. * and hence gmem_free everything on one thread while still allocating
  27. * and hooking things up on another, things can get a little out of hand!
  28. * In particular, you may traverse a structure and hence try to FREE
  29. * a sub-structure to which there is a pointer, but which itself is not yet
  30. * allocated!
  31. *
  32. * The dogma is that when you allocate a new structure and tie it into a List
  33. * or whatever
  34. * EITHER all pointers within the allocated structure are made NULL
  35. * before it is chained in
  36. * OR the caller of Gmem services undertakes not to try to free any
  37. * garbage pointers that are not yet quite built.
  38. * It is SAFE to attempt to gmem_free a NULL pointer. It's a no-op.
  39. * Note that List_NewXxxx(...) zeros the storage before chaining it in.
  40. * Note that List_AddXxxx(...) obviously doesn't!
  41. */
  42. HANDLE APIENTRY gmem_init(void);
  43. LPSTR APIENTRY gmem_get(HANDLE hHeap, int len);
  44. void APIENTRY gmem_free(HANDLE hHeap, LPSTR ptr, int len);
  45. void APIENTRY gmem_freeall(HANDLE hHeap);
  46. /* return total time consumed doing gmem_get */
  47. LONG APIENTRY gmem_time(void);
  48. /* ---- file open/save common dialogs ---------------------------*/
  49. /*
  50. * these functions now rely on to calls to the common dialog libraries.
  51. *
  52. * parameters:
  53. * prompt - user prompt text (eg for dialog title)
  54. * ext - default extension (eg ".txt")
  55. * spec - default file spec (eg "*.*")
  56. * pszFull - full filename will be copied here.
  57. * cchMax - size of pszFull buffer.
  58. * fn - last component of file name will be copied here.
  59. * returns - TRUE if user selected a file that could be opened for
  60. * reading (gfile_open) or created and opened for writing (gfile_new)
  61. * FALSE if user canceled. if user selects a file that cannot be
  62. * opened, a message box is put up and the dialog re-shown.
  63. */
  64. BOOL APIENTRY gfile_open(HWND hwnd, LPSTR prompt, LPSTR ext, LPSTR spec,
  65. LPSTR pszFull, int cchMax, LPSTR fn);
  66. BOOL APIENTRY gfile_new(LPSTR prompt, LPSTR ext, LPSTR spec,
  67. LPSTR pszFull, int cchMax, LPSTR fn);
  68. /* --------- date conversion functions -----------------------*/
  69. /* days (which is actually days measured from a notional Jan 1st 0000)
  70. is a convenient way to store the date in a single LONG. Use
  71. dmytoday to generate the LONG, use daytodmy to convert back
  72. */
  73. void APIENTRY gdate_daytodmy(LONG days,
  74. int FAR* yrp, int FAR* monthp, int FAR* dayp);
  75. LONG APIENTRY gdate_dmytoday(int yr, int month, int day);
  76. /* number of days in given month (Jan===1) in given year (e.g. 1993) */
  77. int APIENTRY gdate_monthdays(int month, int year);
  78. /* daynr is our standard LONG day number. Returns day of the week.
  79. Weekdays are numbered from 0 to 6, Sunday==0
  80. */
  81. int APIENTRY gdate_weekday(long daynr);
  82. /* --- status line window class ---------------------------------- */
  83. /* The status line is a bar across the top or bottom of the window.
  84. * It can hold a number of fields which can be either static text
  85. * or buttons. The so called "static" text can be changed at any time.
  86. * The fields can be left or right aligned (default is RIGHT).
  87. * If the text is marked as VAR then the screen real estate allocated
  88. * for it will be adjusted whenever the text changes. VAR fields
  89. * can be given minimum or maximum sizes (but not both).
  90. *
  91. * STATIC text fields can be drawn as raised or lowered rectangles (using
  92. * shades of grey), or (default) without a border. BUTTON fields will
  93. * always be drawn as raised rectangles, and will lower when pressed.
  94. *
  95. * Button fields will send WM_COMMAND messages when clicked including the
  96. * field id and the WM_LBUTTONUP notification code. Note that that this
  97. * is not a full implementation of the button class, and no other messages
  98. * will be sent. In general, none of the fields of a status bar are
  99. * implemented as separate windows, so GetDlgItem() and similar calls will not
  100. * work. Buttons only respond to mouse down events, and there is no handling
  101. * of the focus or of keyboard events.
  102. *
  103. * To use:
  104. * call StatusAlloc giving the number of items you are going to add to the
  105. * status bar. This returns a handle to use in subsequent calls.
  106. *
  107. * Then call StatusAddItem to define each item in turn.
  108. * Buttons are placed in order of definition along the bar starting from
  109. * the left (SF_LEFT) and from the right (SF_RIGHT) until the two
  110. * sides meet.
  111. *
  112. * Call StatusHeight to find the expected height of this status bar, and
  113. * set its position within the parent window, then call StatusCreate to
  114. * create the window.
  115. *
  116. * Having created the window, send SM_SETTEXT messages to set the new
  117. * text of a field (static or button), or SM_NEW with a handle (obtained from
  118. * StatusAlloc) to change the contents of the status line.
  119. */
  120. /* values for type argument to StatusAddItem */
  121. #define SF_BUTTON 1
  122. #define SF_STATIC 2
  123. /* bits in flags argument to StatusAddItem */
  124. #define SF_RAISE 1 /* paint static as raised 3D rectangle */
  125. #define SF_LOWER 2 /* paint static as lowered 3D rectangle */
  126. #define SF_LEFT 4 /* align field on left of status bar */
  127. #define SF_RIGHT 8 /* align field on right (DEFAULT) */
  128. #define SF_VAR 0x10 /* size of field depends on actual text extent*/
  129. #define SF_SZMAX 0x20 /* (with SF_VAR): width argument is maximum */
  130. #define SF_SZMIN 0x40 /* (with SF_VAR) width arg is minimum size */
  131. /* interfaces */
  132. HWND APIENTRY StatusCreate(HANDLE hInst, HWND hParent, INT_PTR id,
  133. LPRECT rcp, HANDLE hmem);
  134. /* return the recommended height in device units of the given status bar */
  135. int APIENTRY StatusHeight(HANDLE hmem);
  136. /* alloc the status bar data structures and return handle*/
  137. HANDLE APIENTRY StatusAlloc(int nitems);
  138. /* set the attributes of a field.
  139. *
  140. * hmem obtained from StatusAlloc. itemnr must be less than the nitems
  141. * passed to StatusAlloc.
  142. *
  143. * the width argument is the width of the field in characters (average
  144. * character width).
  145. */
  146. BOOL APIENTRY StatusAddItem(HANDLE hmem, int itemnr, int type, int flags,
  147. int id, int width, LPSTR text);
  148. /* send these window messages to the class */
  149. #define SM_NEW (WM_USER+1) /* wParam handle for new status line */
  150. #define SM_SETTEXT (WM_USER+2) /* wparam: item id, lparam new label*/
  151. /* --- bit-map freelist management functions -------------------------------*/
  152. /* init a pre-allocated array of longs to map nblks - set all to free
  153. you should allocate 1 DWORD in map for every 32 blocks of storage
  154. you wish to control.
  155. */
  156. void APIENTRY gbit_init(DWORD FAR * map, long nblks);
  157. /* mark a range of nblks starting at blknr to be busy */
  158. BOOL APIENTRY gbit_alloc(DWORD FAR * map, long blknr, long nblks);
  159. /* mark a range of nblks starting at blknr to be free */
  160. BOOL APIENTRY gbit_free(DWORD FAR * map, long blknr, long nblks);
  161. /* find a free section nblks long, or the biggest found in the map if all
  162. * are less than nblks long. returns size of region found as return value,
  163. * and sets blknr to the starting blk of region. Region is *not* marked
  164. * busy
  165. */
  166. long APIENTRY gbit_findfree(DWORD FAR* map, long nblks,
  167. long mapsize, long FAR * blknr);
  168. /* ----- buffered line input ----------------------------------*/
  169. /*
  170. * functions for reading a file, one line at a time, with some buffering
  171. * to make the operation reasonably efficient.
  172. *
  173. * call readfile_new to initialise the buffer and give it a handle to
  174. * an open file. Call readfile_next to get a pointer to the next line.
  175. * This discards the previous line and gives you a pointer to the line
  176. * IN THE BUFFER. Make your own copy before calling readfile_next again.
  177. *
  178. * call readfile_delete once you have finished with this file. That will close
  179. * the file and free up any memory.
  180. */
  181. // MAX_LINE_LENGTH is the max number of physical characters we allow in a line
  182. #define MAX_LINE_LENGTH (4096)
  183. // BUFFER_SIZE is expressed in bytes, and is large enough to read in
  184. // MAX_LINE_LENGTH wide chars, and also hold MAX_LINE_LENGTH 5-byte hex code
  185. // representations of the chars.
  186. #define BUFFER_SIZE (MAX_LINE_LENGTH * 5)
  187. /* handle to a file buffer */
  188. typedef struct filebuffer FAR * FILEBUFFER;
  189. /* initialise the buffering for an open file */
  190. FILEBUFFER APIENTRY readfile_new(HANDLE fh, BOOL *pfUnicode);
  191. /* return a pointer to the next line in this file. line must be shorter than
  192. * buffer size (currently 1024 bytes). Line is not null-terminated: *plen
  193. * is set to the length of the line including the \n. This call will
  194. * discard any previous line, so ensure that you have made a copy of one line
  195. * before you call readfile_next again.
  196. * MUST CALL readfile_setdelims FIRST!
  197. */
  198. LPSTR APIENTRY readfile_next(FILEBUFFER fb, int FAR * plen, LPWSTR *ppwz, int *pcwch);
  199. /* set the delimiters to use to break lines. MUST call this to initialise */
  200. void APIENTRY readfile_setdelims(LPBYTE str);
  201. /*
  202. * close the file and discard any associated memory and buffers.
  203. */
  204. void APIENTRY readfile_delete(FILEBUFFER fb);
  205. /* ------ hashing and checksums ------------------------------------------- */
  206. /*
  207. * generate a 32-bit hash code for a null-terminated string of ascii text.
  208. *
  209. * if bIgnoreBlanks is TRUE, we ignore spaces and tabs during the
  210. * hashcode calculation.
  211. */
  212. /* hash codes are unsigned longs */
  213. DWORD APIENTRY hash_string(LPSTR string, BOOL bIgnoreBlanks);
  214. void Format(char * a, char * b);
  215. /* return TRUE iff the string is blank. Blank means the same as
  216. * the characters which are ignored in hash_string when ignore_blanks is set
  217. */
  218. BOOL APIENTRY utils_isblank(LPSTR string);
  219. /*
  220. * Compare two pathnames, and if not equal, decide which should come first.
  221. *
  222. * returns 0 if the same, -1 if left is first, and +1 if right is first.
  223. *
  224. * The comparison is such that all filenames in a directory come before any
  225. * file in a subdirectory of that directory.
  226. *
  227. * To make absolutely certain that you get a canonical sorting, use AnsiLowerBuff
  228. * to convert BOTH to lower case first. You may get a funny effect if one one
  229. * has been converted to lower case and the other not.
  230. */
  231. int APIENTRY
  232. utils_CompPath(LPSTR left, LPSTR right);
  233. /* given an open file handle open for reading, read the file and
  234. * generate a 32-bit checksum for the file
  235. */
  236. /* checksums are unsigned longs */
  237. typedef DWORD CHECKSUM;
  238. /* Open a file, checksum it and close it again. err !=0 iff it failed. */
  239. CHECKSUM APIENTRY checksum_file(LPCSTR fn, LONG FAR * err);
  240. /* --- error message output ----------------------------------------------*/
  241. /*
  242. * reports error in a dialog, returns TRUE for ok, FALSE for cancel.
  243. * if fCancel is FALSE, only the OK button is shown, otherwise both ok
  244. * and cancel. hwnd is the parent window for the dlg. can be null.
  245. */
  246. BOOL APIENTRY Trace_Error(HWND hwnd, LPSTR msg, BOOL fCancel);
  247. /* Write popups to a file until further notice */
  248. void Trace_Unattended(BOOL bUnattended);
  249. /* --- create/write to trace file ----------------------------------------*/
  250. void APIENTRY Trace_File(LPSTR msg);
  251. /* --- close trace file --------------------------------------------------*/
  252. void APIENTRY Trace_Close(void);
  253. /* --- simple input ------------------------------------------------------*/
  254. /*
  255. * input of a single text string, using a simple dialog.
  256. *
  257. * returns TRUE if ok, or FALSE if error or user canceled. If TRUE,
  258. * puts the string entered into result (up to resultsize characters).
  259. *
  260. *
  261. * prompt is used as the prompt string, caption as the dialog caption and
  262. * def_input as the default input. All of these can be null.
  263. */
  264. int APIENTRY StringInput(LPSTR result, int resultsize, LPSTR prompt,
  265. LPSTR caption, LPSTR def_input);
  266. /* --- sockets -----------------------------------------------------------*/
  267. #ifdef SOCKETS
  268. #include <winsock.h>
  269. BOOL SocketConnect( LPSTR pstrServerName, u_short TCPPort, SOCKET *pSocket );
  270. BOOL SocketListen( u_short TCPPort, SOCKET *pSocket );
  271. #endif
  272. // These are for both WINDIFF.EXE and GUTILS.DLL.
  273. //#define strchr My_mbschr
  274. //#define strncpy My_mbsncpy
  275. PUCHAR My_mbspbrk(PUCHAR, PUCHAR);
  276. LPSTR My_mbschr(LPCSTR, unsigned short);
  277. LPSTR My_mbsncpy(LPSTR, LPCSTR, size_t);
  278. // These are for WINDIFF.EXE.
  279. //#define strrchr My_mbsrchr
  280. //#define strncmp My_mbsncmp
  281. LPSTR My_mbsrchr(LPCSTR, unsigned short);
  282. int My_mbsncmp(LPCSTR, LPCSTR, size_t);
  283. LPTSTR APIENTRY LoadRcString(UINT);