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.

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