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.

191 lines
3.6 KiB

  1. /*************************************************************************
  2. **
  3. ** helpdll - stubs for call-back routines when used as dll.
  4. **
  5. ** Copyright <C> 1987, Microsoft Corporation
  6. **
  7. ** Purpose:
  8. **
  9. ** Revision History:
  10. **
  11. ** 12-Mar-1990 ln CloseFile -> HelpCloseFile
  12. ** [] 22-Jan-1988 LN Created
  13. **
  14. *************************************************************************/
  15. #include <stdio.h>
  16. #include <malloc.h>
  17. #if defined (OS2)
  18. #define INCL_BASE
  19. #include <os2.h>
  20. #else
  21. #include <windows.h>
  22. #endif
  23. #include "help.h" /* global (help & user) decl */
  24. #include "helpsys.h" /* internal (help sys only) decl*/
  25. #ifdef OS2
  26. int _acrtused; /* define to disable crt0 */
  27. #endif
  28. char far * pascal near hfstrchr(char far *, char);
  29. /************************************************************************
  30. *
  31. * OpenFileOnPath - Open a file located somewhere on the PATH
  32. *
  33. * Purpose:
  34. *
  35. * Entry:
  36. * pszName - far pointer to filename to open
  37. * mode - read/write mode
  38. *
  39. * Exit:
  40. * returns file handle
  41. *
  42. * Exceptions:
  43. * return 0 on error.
  44. *
  45. */
  46. FILE *
  47. pascal
  48. far
  49. OpenFileOnPath(
  50. char far *pszName,
  51. int mode
  52. )
  53. {
  54. FILE *fh;
  55. char szNameFull[260];
  56. char szNameFull1[260];
  57. fh = (FILE *)pathopen(pszName, szNameFull, "rb");
  58. if (!fh) {
  59. char *pszPath;
  60. char *pT;
  61. if (*pszName == '$') {
  62. if (pT = hfstrchr(pszName,':')) { /* if properly terminated */
  63. *pT = 0; /* terminate env variable */
  64. pszPath = pszName+1; /* get path name */
  65. pszName = pT+1; /* and point to filename part */
  66. }
  67. } else {
  68. pszPath = "PATH";
  69. }
  70. sprintf(szNameFull, "$%s:%s", pszPath, pszName);
  71. fh = (FILE *)pathopen(szNameFull, szNameFull1, "rb");
  72. }
  73. return fh;
  74. }
  75. /************************************************************************
  76. *
  77. * HelpCloseFile - Close a file
  78. *
  79. * Purpose:
  80. *
  81. * Entry:
  82. * fh = file handle
  83. *
  84. * Exit:
  85. * none
  86. *
  87. */
  88. void
  89. pascal
  90. far
  91. HelpCloseFile(
  92. FILE* fh
  93. )
  94. {
  95. fclose(fh);
  96. }
  97. /************************************************************************
  98. *
  99. * ReadHelpFile - locate and read data from help file
  100. *
  101. * Purpose:
  102. * reads cb bytes from the file fh, at file position fpos, placing them in
  103. * pdest. Special case of pdest==0, returns file size of fh.
  104. *
  105. * Entry:
  106. * fh = File handle
  107. * fpos = position to seek to first
  108. * pdest = location to place it
  109. * cb = count of bytes to read
  110. *
  111. * Exit:
  112. * returns length of data read
  113. *
  114. * Exceptions:
  115. * returns 0 on errors.
  116. *
  117. */
  118. unsigned long
  119. pascal
  120. far
  121. ReadHelpFile (
  122. FILE *fh,
  123. unsigned long fpos,
  124. char far *pdest,
  125. unsigned short cb
  126. )
  127. {
  128. unsigned long cRet = 0;
  129. if (pdest) {
  130. //
  131. // Read cb bytes
  132. //
  133. if (!fseek(fh, fpos, SEEK_SET)) {
  134. cRet = fread(pdest, 1, cb, fh);
  135. }
  136. } else {
  137. //
  138. // Return size of file (yuck!)
  139. //
  140. if (!fseek(fh, 0, SEEK_END)) {
  141. fgetpos(fh, (fpos_t *) &cRet);
  142. }
  143. }
  144. return cRet;
  145. }
  146. /************************************************************************
  147. **
  148. ** HelpAlloc - Allocate a segment of memory for help
  149. **
  150. ** Purpose:
  151. **
  152. ** Entry:
  153. ** size = size of memory segment desired
  154. **
  155. ** Exit:
  156. ** returns handle on success
  157. **
  158. ** Exceptions:
  159. ** returns NULL on failure
  160. */
  161. mh pascal far HelpAlloc(ushort size)
  162. {
  163. return (mh)malloc(size);
  164. /* end HelpAlloc */}