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.

174 lines
2.9 KiB

  1. // calback.c
  2. //
  3. // these are the default callbacks for the library
  4. //
  5. #include <string.h>
  6. #include <stdio.h>
  7. #include <malloc.h>
  8. #include <stdlib.h>
  9. #include <io.h>
  10. #if defined(OS2)
  11. #define INCL_NOCOMMON
  12. #define INCL_DOSPROCESS
  13. #define INCL_DOSSEMAPHORES
  14. #define INCL_DOSFILEMGR
  15. #define INCL_DOSERRORS
  16. #define INCL_DOSMISC
  17. #include <os2.h>
  18. #else
  19. #include <windows.h>
  20. #endif
  21. #include <dos.h>
  22. #include "hungary.h"
  23. #include "bsc.h"
  24. typedef char bscbuf[2048];
  25. // you must define the following callbacks for the library to use
  26. LPV BSC_API LpvAllocCb(WORD cb)
  27. // allocate a block of memory
  28. //
  29. {
  30. return malloc(cb);
  31. }
  32. VOID BSC_API FreeLpv(LPV lpv)
  33. // free a block of memory
  34. //
  35. {
  36. free(lpv);
  37. }
  38. VOID BSC_API SeekError(LSZ lszFileName) // do not return!
  39. // error handling
  40. //
  41. {
  42. BSCPrintf("BSC Library: Error seeking in file '%s'\n", lszFileName);
  43. exit(1);
  44. }
  45. VOID BSC_API ReadError(LSZ lszFileName) // do not return!
  46. // error handling
  47. //
  48. {
  49. BSCPrintf("BSC Library: Error reading in file '%s'\n", lszFileName);
  50. exit(1);
  51. }
  52. VOID BSC_API BadBSCVer(LSZ lszFileName) // do not return!
  53. // error handling
  54. //
  55. {
  56. BSCPrintf("BSC Library: '%s' not in current .bsc format\n", lszFileName);
  57. exit(1);
  58. }
  59. FILEHANDLE BSC_API
  60. BSCOpen(LSZ lszFileName, FILEMODE mode)
  61. // open the specified file
  62. //
  63. {
  64. #if defined (OS2)
  65. bscbuf b;
  66. strcpy(b, lszFileName);
  67. return open(b, mode);
  68. #else
  69. return OpenFile( lszFileName, mode, FALSE, FILE_SHARE_READ);
  70. #endif
  71. }
  72. int BSC_API
  73. BSCRead(FILEHANDLE handle, LPCH lpchBuf, WORD cb)
  74. // read in the specified number of bytes
  75. //
  76. {
  77. #if defined (OS2)
  78. bscbuf b;
  79. while (cb > sizeof(b)) {
  80. if (read(handle, b, sizeof(b)) == -1) return -1;
  81. memcpy(lpchBuf, b, sizeof(b));
  82. cb -= sizeof(b);
  83. lpchBuf += sizeof(b);
  84. }
  85. if (read(handle, b, cb) == -1) return -1;
  86. memcpy(lpchBuf, b, cb);
  87. return cb;
  88. #else
  89. return ReadFile(handle, lpchBuf, cb);
  90. #endif
  91. }
  92. int BSC_API
  93. BSCClose(FILEHANDLE handle)
  94. // close the specified handle
  95. //
  96. {
  97. #if defined (OS2)
  98. return close(handle);
  99. #else
  100. return !CloseHandle( handle );
  101. #endif
  102. }
  103. int BSC_API
  104. BSCSeek(FILEHANDLE handle, long lPos, FILEMODE mode)
  105. // seek on the specified handle
  106. //
  107. {
  108. #if defined (OS2)
  109. if (lseek(handle, lPos, mode) == -1)
  110. return -1;
  111. else
  112. return 0;
  113. #else
  114. if (SetFilePointer( handle, lPos, 0L, mode) == -1) {
  115. return -1;
  116. } else {
  117. return 0;
  118. }
  119. #endif
  120. }
  121. VOID BSC_API
  122. BSCOutput(LSZ lsz)
  123. // write the given string to the standard output
  124. //
  125. {
  126. bscbuf b;
  127. int cb;
  128. cb = strlen(lsz);
  129. while (cb > sizeof(b)) {
  130. memcpy(b, lsz, sizeof(b));
  131. if (write(1, b, sizeof(b)) == -1) return;
  132. cb -= sizeof(b);
  133. lsz += sizeof(b);
  134. }
  135. memcpy(b, lsz, cb);
  136. write(1, b, cb);
  137. return;
  138. }
  139. #ifdef DEBUG
  140. VOID BSC_API
  141. BSCDebugOut(LSZ lsz)
  142. // ignore debug output by default
  143. //
  144. {
  145. // unreferenced lsz
  146. lsz = NULL;
  147. }
  148. #endif