home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database / CLIPR503.W96 / DBUHELP.PR_ / DBUHELP.PR
Text File  |  1995-06-26  |  3KB  |  143 lines

  1. /***
  2. *
  3. *  Dbuhelp.prg
  4. *
  5. *  DBU Help Module
  6. *
  7. *  Copyright (c) 1990-1993, Computer Associates International, Inc.
  8. *  All rights reserved.
  9. *
  10. */
  11.  
  12.  
  13. ******
  14. *    syshelp
  15. *
  16. *    Display help screens contained in the file DBU.HLP.
  17. *    The help file can be in one of these places:
  18. *
  19. *        <current directory>
  20. *        \CLIPPER\
  21. *
  22. *    The global variable "helpfile" contains the
  23. *    path\filename, or a null string if not found.
  24. ******
  25. PROCEDURE syshelp
  26. local saveColor
  27. PRIVATE hrow, hcol, hwbuf, htext
  28.  
  29. saveColor := SetColor()
  30.  
  31. IF EMPTY(M->helpfile)
  32.     error_msg("Can't find DBU.HLP")
  33.  
  34. ELSE
  35.     * save current row and column
  36.     hrow = ROW()
  37.     hcol = COL()
  38.  
  39.     * save screen in memvar
  40.     hwbuf = SAVESCREEN(8, 10, 22, 69)
  41.  
  42.     * clear window and draw box
  43.     SetColor(M->color8)
  44.     scroll(8, 10, 22, 69, 0)
  45.     @ 8,10,22,69 BOX M->frame
  46.  
  47.     * display help title
  48.     SetColor(M->color10)
  49.     @ 8,(76 - LEN(help_title[M->help_code])) / 2;
  50.     SAY "  " + help_title[M->help_code] + "  "
  51.  
  52.     * get the help text
  53.     htext = helptext(M->helpfile, M->help_code)
  54.  
  55.     * scroll state makes eliminates the need for a cursor
  56.     SET CURSOR OFF
  57.  
  58.     * use editor in browse only mode
  59.     SetColor(M->color8)
  60.     MEMOEDIT(M->htext, 9, 11, 21, 68, .F.)
  61.  
  62.     * restore window
  63.     RESTSCREEN(8, 10, 22, 69, M->hwbuf)
  64.  
  65.     * restore cursor
  66.     @ M->hrow,M->hcol SAY ""
  67.     IF M->curs_on
  68.         SET CURSOR ON
  69.  
  70.     ENDIF
  71. ENDIF
  72.  
  73. * reset
  74. SetColor(saveColor)
  75. local_func = 0
  76. RETURN
  77.  
  78.  
  79. ******
  80. *    helptext()
  81. *
  82. *    extract help text from a helpfile in the following format:
  83. *
  84. *    o    At the beginning of the help file is a table which contains
  85. *        the offset and length of each block of help text in the file.
  86. *
  87. *    o    A table entry is 4 bytes long and consists of two 16 bit unsigned
  88. *        numbers in binary format.  The first number is the offset within
  89. *        the file where the corresponding help text begins; the second
  90. *        number is the length of the text in bytes.
  91. *
  92. *    o    Table entries and related help text are arranged in numeric order
  93. *        according to the global variable "help_code" which is used to
  94. *        access the correct block of text.
  95. *
  96. *    o    Binary numbers at the beginning of the file are assumed to be
  97. *        in standard Intel format where the Least Significant Byte (LSB)
  98. *        is stored first and the Most Significant Byte (MSB) is second.
  99. ******
  100. FUNCTION helptext
  101.  
  102. PARAMETERS hfile, hnum
  103. PRIVATE htbuf, hoff, hlen, hhandle
  104.  
  105. * open the file and get handle
  106. hhandle = FOPEN(M->hfile)
  107.  
  108. IF FERROR() = 0
  109.     * allocate 512 byte buffer
  110.     htbuf = SPACE(512)
  111.  
  112.     * read the file header into memory
  113.     FREAD(M->hhandle, @htbuf, 512)
  114.  
  115.     * isolate the correct 4 byte table entry
  116.     htbuf = SUBSTR(M->htbuf, (4 * (M->hnum - 1)) + 1, 4)
  117.  
  118.     * convert binary numbers (LSB, MSB) to Clipper numerics
  119.     hoff = ASC(M->htbuf) + (256 * ASC(SUBSTR(M->htbuf, 2)))
  120.     hlen = ASC(SUBSTR(M->htbuf, 3)) + (256 * ASC(SUBSTR(M->htbuf, 4)))
  121.  
  122.     * allocate buffer
  123.     htbuf = SPACE(M->hlen)
  124.  
  125.     * position file to the correct offset
  126.     FSEEK(M->hhandle, M->hoff)
  127.  
  128.     * read text into buffer
  129.     FREAD(M->hhandle, @htbuf, M->hlen)
  130.  
  131. ELSE
  132.     * return null string if error
  133.     htbuf = ""
  134.  
  135. ENDIF
  136.  
  137. * close the file and release the handle
  138. FCLOSE(M->hhandle)
  139. RETURN M->htbuf
  140.  
  141.  
  142. * EOF DBUHELP.PRG
  143.