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.

435 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. calbak.c
  5. Abstract:
  6. Callback functions needed by the bsc library.
  7. Author:
  8. Ramon Juan San Andres (ramonsa) 06-Nov-1990
  9. Revision History:
  10. --*/
  11. /**************************************************************************/
  12. #include "stdlib.h"
  13. #include "mbr.h"
  14. typedef char bscbuf[2048];
  15. /**************************************************************************/
  16. LPV
  17. BSC_API
  18. LpvAllocCb (
  19. IN WORD cb
  20. )
  21. /*++
  22. Routine Description:
  23. Allocates block of memory.
  24. Arguments:
  25. cb - Supplies size of block.
  26. Return Value:
  27. Pointer to block of memory of size cb, or NULL
  28. --*/
  29. {
  30. return (LPV)malloc(cb);
  31. }
  32. /**************************************************************************/
  33. VOID
  34. BSC_API
  35. FreeLpv (
  36. IN LPV lpv
  37. )
  38. /*++
  39. Routine Description:
  40. Frees a block of memory.
  41. Arguments:
  42. lpv - Suplies a pointer to the block of memory to free.
  43. Return Value:
  44. None.
  45. --*/
  46. {
  47. free(lpv);
  48. }
  49. /**************************************************************************/
  50. VOID
  51. BSC_API
  52. SeekError (
  53. IN LSZ lszFileName
  54. )
  55. /*++
  56. Routine Description:
  57. Error handling for seek operations.
  58. Arguments:
  59. lszFileName - Supplies the name of the file.
  60. Return Value:
  61. None.
  62. --*/
  63. {
  64. errstat(MBRERR_BSC_SEEK_ERROR, lszFileName);
  65. }
  66. /**************************************************************************/
  67. VOID
  68. BSC_API
  69. ReadError (
  70. IN LSZ lszFileName
  71. )
  72. /*++
  73. Routine Description:
  74. Error handling for read operations.
  75. Arguments:
  76. lszFileName - Supplies the name of the file.
  77. Return Value:
  78. None.
  79. --*/
  80. {
  81. errstat(MBRERR_BSC_READ_ERROR, lszFileName);
  82. }
  83. /**************************************************************************/
  84. VOID
  85. BSC_API
  86. BadBSCVer (
  87. IN LSZ lszFileName
  88. )
  89. /*++
  90. Routine Description:
  91. Error handling for bad version number.
  92. Arguments:
  93. lszFileName - Supplies the name of the file.
  94. .
  95. .
  96. Return Value:
  97. None.
  98. --*/
  99. {
  100. errstat(MBRERR_BAD_BSC_VERSION, lszFileName);
  101. }
  102. /**************************************************************************/
  103. FILEHANDLE
  104. BSC_API
  105. BSCOpen (
  106. IN LSZ lszFileName,
  107. IN FILEMODE mode
  108. )
  109. /*++
  110. Routine Description:
  111. Opens a file.
  112. Arguments:
  113. lszFileName - Supplies the name of the file.
  114. mode - Supplies the mode with which to open the file.
  115. Return Value:
  116. File handle for the opened file. -1 if error.
  117. --*/
  118. {
  119. #if defined (OS2)
  120. bscbuf b;
  121. strcpy(b, lszFileName);
  122. return open(b, mode);
  123. #else
  124. return CreateFile( lszFileName, mode, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
  125. #endif
  126. }
  127. /**************************************************************************/
  128. int
  129. BSC_API
  130. BSCRead (
  131. IN FILEHANDLE handle,
  132. OUT LPCH lpchBuf,
  133. IN WORD cb
  134. )
  135. /*++
  136. Routine Description:
  137. Reads in the specified number of bytes.
  138. Arguments:
  139. handle - Supplies the file handle.
  140. lpchBuf - Supplies pointer to buffer.
  141. cb - Supplies number of bytes to read.
  142. Return Value:
  143. Number of bytes read
  144. --*/
  145. {
  146. #if defined (OS2)
  147. bscbuf b;
  148. while (cb > sizeof(b)) {
  149. if (read(handle, b, sizeof(b)) == -1) {
  150. return -1;
  151. }
  152. memcpy(lpchBuf, b, sizeof(b));
  153. cb -= sizeof(b);
  154. lpchBuf += sizeof(b);
  155. }
  156. if (read(handle, b, cb) == -1) {
  157. return -1;
  158. }
  159. memcpy(lpchBuf, b, cb);
  160. return cb;
  161. #else
  162. DWORD BytesRead;
  163. if ( !ReadFile(handle, lpchBuf, cb, &BytesRead, NULL) ) {
  164. return -1;
  165. } else {
  166. return BytesRead;
  167. }
  168. #endif
  169. }
  170. /**************************************************************************/
  171. int
  172. BSC_API
  173. BSCClose (
  174. IN FILEHANDLE handle
  175. )
  176. /*++
  177. Routine Description:
  178. Closes a handle.
  179. Arguments:
  180. handle - Supplies the handle to be closed.
  181. Return Value:
  182. 0 if the file was successfully closed, -! if error.
  183. --*/
  184. {
  185. #if defined (OS2)
  186. return close(handle);
  187. #else
  188. return !CloseHandle( handle );
  189. #endif
  190. }
  191. /**************************************************************************/
  192. int
  193. BSC_API
  194. BSCSeek (
  195. FILEHANDLE handle,
  196. long lPos,
  197. FILEMODE mode
  198. )
  199. /*++
  200. Routine Description:
  201. Seek (change file pointer).
  202. Arguments:
  203. handle - Supplies the file handle.
  204. lPos - Supplies the offset from the position specified by mode.
  205. mode - Supplies the initial position. Must be one of the SEEK_*
  206. values of the lseek C library function.
  207. Return Value:
  208. 0 if successful, -1 if error.
  209. --*/
  210. {
  211. #if defined (OS2)
  212. if (lseek(handle, lPos, mode) == -1) {
  213. return -1;
  214. } else {
  215. return 0;
  216. }
  217. #else
  218. if (SetFilePointer( handle, lPos, 0L, mode) == -1) {
  219. return -1;
  220. } else {
  221. return 0;
  222. }
  223. #endif
  224. }
  225. /**************************************************************************/
  226. VOID
  227. BSC_API
  228. BSCOutput (
  229. IN LSZ lsz
  230. )
  231. /*++
  232. Routine Description:
  233. Outputs a given string.
  234. Arguments:
  235. lsz - Supplies the string to be output.
  236. Return Value:
  237. None.
  238. --*/
  239. {
  240. // PWND pWinCur;
  241. // winContents wc;
  242. USHORT len; // Length of string
  243. PBYTE p;
  244. PFILE pFile; // Current file
  245. pFile = FileNameToHandle("", NULL);
  246. //GetEditorObject (RQ_WIN_HANDLE, 0, &pWinCur);
  247. //GetEditorObject (RQ_WIN_CONTENTS | 0xff, pWinCur, &wc);
  248. len = strlen(lsz);
  249. while (len) {
  250. //
  251. // We output the string one line at a time.
  252. //
  253. p = lsz;
  254. while (len--) {
  255. if (*lsz != '\n') {
  256. lsz++;
  257. } else {
  258. *lsz++ = '\00';
  259. break;
  260. }
  261. }
  262. // if ((wc.pFile == pBrowse) && BscInUse) {
  263. if ((pFile == pBrowse) && BscInUse) {
  264. //
  265. // Display in Browser window
  266. //
  267. PutLine(BrowseLine++, p, pBrowse);
  268. } else {
  269. //
  270. // Display in status line
  271. //
  272. errstat(p,NULL);
  273. }
  274. }
  275. }
  276. /**************************************************************************/
  277. #ifdef DEBUG
  278. VOID BSC_API
  279. BSCDebugOut(LSZ lsz)
  280. // ignore debug output by default
  281. //
  282. {
  283. // unreferenced lsz
  284. lsz = NULL;
  285. }
  286. #endif