home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / GENHELP.ZIP / HELP.PRG < prev    next >
Encoding:
Text File  |  1988-04-23  |  6.0 KB  |  204 lines

  1. * Program Name: help.prg                                   *
  2. * Author: James J. Orlowski, M.D.                          *
  3. * Created: 03/22/1987                                      *
  4. * Revision: 3 Last Revised: 04/23/1988 at 0:00             *
  5. ************************************************************
  6. PARAMETERS call_prg, line_num, input_var
  7. IF call_prg = "HELP" .OR. call_prg = "MEMOEDIT" .OR. call_prg = "GENHELP"
  8.    RETURN
  9. ENDIF
  10.  
  11. * set up help_code
  12. DO CASE
  13.    CASE help_code = 0
  14.       RETURN
  15.    CASE call_prg = "SUBMENUS"
  16.       help_code = menunum
  17. ENDCASE
  18.  
  19. * open all keys so can use MEMOEDIT() within PROCEDURE genhelp 
  20. * below in this help.prg.  These were previously set within 
  21. * PROCEDURES MAIN & SUBMENU within DEMOHELP.PRG
  22. SET KEY 18 TO
  23. SET KEY 3  TO
  24. SET KEY 5  TO
  25. SET KEY 24 TO
  26. SET KEY 1  TO
  27. SET KEY 6  TO
  28. SET KEY 19 TO
  29. SET KEY 4  TO
  30. DO genhelp
  31. * reset menu commands if main.prg or submenus
  32. DO CASE
  33.    CASE call_prg = "DEMOHELP"
  34.       SET KEY 18 TO menu_up     && pg-up arrow
  35.       SET KEY 3  TO menu_dn     && pg-down arrow
  36.       SET KEY 5  TO menu_up     && up arrow
  37.       SET KEY 24 TO menu_dn     && down arrow
  38.    CASE call_prg = "SUBMENUS"
  39.       SET KEY 1   TO menu_home  && home arrow
  40.       SET KEY 6   TO menu_end   && end arrow
  41.       SET KEY 18  TO menu_up    && pg-up arrow
  42.       SET KEY 3   TO menu_dn    && pg-down arrow
  43.       SET KEY 19  TO menu_lft   && left arrow
  44.       SET KEY 4   TO menu_rgt   && right arrow
  45. ENDCASE
  46. RETURN
  47. * EOF regular listing for help.prg
  48.  
  49. ************
  50. *  Procedure..:  GENHELP
  51. *  As modified from:
  52. *  Filename...:  DBUHELP.PRG
  53. *  Author.....:  Dennis L. Dias
  54. *  Date.......:  06/18/86
  55. *  Copyright (c) 1986,1987 Nantucket Corp., All Rights Reserved.
  56. *
  57. *  PROCEDURE genhelp modified by James J. Orlowski, M.D. 
  58. *  to be used independently as a generalized help utility 04/09/88 by:
  59. *  1.) using any help text stored in global variable "helpfile"
  60. *  2.) adds color and other commands spread throughout dbu*.prg files
  61. *      to incorporate all info to allow this file to run independently
  62. *  3.) Also uses global variable help_code as used in original DBUHELP.PRG
  63. *  NOTE: IF YOU HAVE DBU*.OBJ LINKED WITHIN YOUR PROGRAM, 
  64. *  YOU SHOULD DELETE FUNCTION helptext SECTION FROM THIS PROGRAM 
  65. *  SINCE THIS IS AN EXACT DUPLICATE FROM DBUHELP.PRG
  66. *  YOU WOULD ALSO HAVE TO DETERMINE IF DUPLICATE MEMVARS CAUSE
  67. *  PROBLEMS WITH DBU.PRG (i.e. help_code, helpfile)
  68. ************
  69.  
  70. ******
  71. *  genhelp
  72. *
  73. *  Display help screens contained in the 
  74. *  file stored in the global variable "helpfile"
  75. *  The global variable "helpfile" must contain the
  76. *  full path\filename or it will not be found by 
  77. *  IF FILE(helpfile) command
  78. ******
  79. PROCEDURE genhelp
  80.  
  81. PRIVATE hrow, hcol, hwbuf, htext
  82. PRIVATE colorstart, cl_firstcr, cl_helphd
  83. colorstart = SETCOLOR()
  84. IF ISCOLOR()
  85.    color1 = "W+/B,W+/R,B"     && normal
  86.    color2 = "W+/R"            && item hilite
  87.    color3 = "N/GR"            && error or high intensity
  88. ELSE
  89.    color1 = ""
  90.    color2 = "I"
  91.    color3 = "W+"
  92. ENDIF
  93.  
  94. * search for help file
  95. IF .NOT. FILE(helpfile)
  96.    SET COLOR TO &color3
  97.    @ 0,0 SAY "Can't find " + UPPER(helpfile)
  98.    SET COLOR TO &color1
  99. ELSE
  100.    * save current row and column
  101.    hrow = ROW()
  102.    hcol = COL()
  103.  
  104.    * save screen in memvar
  105.    hwbuf = SAVESCREEN(7, 2, 24, 77)
  106.  
  107.    * clear window and draw box
  108.    SET COLOR TO &color1
  109.    scroll(7, 2, 24, 77, 0)
  110.    @ 8,05,22,74 BOX "╒═╕│╛═╘│"
  111.  
  112.    * get the help text
  113.    htext = HELPTEXT(M->helpfile, M->help_code)
  114.  
  115.    * scroll state eliminates the need for a cursor
  116.    SET CURSOR OFF
  117.  
  118.    * display help title
  119.    SET COLOR TO &color2
  120.    cl_firstcr = AT(CHR(13), htext)
  121.    cl_helphd  = SUBSTR(htext, 1, cl_firstcr - 1)
  122.    @ 8,(76 - LEN(cl_helphd)) / 2 SAY "  " + cl_helphd + "  "
  123.    @ 23,09 SAY "Use Cursor Keys To View Help Text; Press ESC Key To Quit Help"
  124.    SET COLOR TO &color1
  125.  
  126.    * use editor in browse only mode
  127.    htext = SUBSTR(htext, cl_firstcr + 2)
  128.    MEMOEDIT(M->htext, 9, 06, 21, 73, .F.)
  129.  
  130.    * restore window
  131.    RESTSCREEN(7, 2, 24, 77, M->hwbuf)
  132.  
  133.    * restore cursor
  134.    @ M->hrow,M->hcol SAY ""
  135.    SET CURSOR ON
  136. ENDIF
  137. SETCOLOR(colorstart)
  138. RETURN
  139. * EOP genhelp
  140.  
  141. ******
  142. *  helptext()
  143. *
  144. *  extract help text from a helpfile in the following format:
  145. *
  146. *  o  At the beginning of the help file is a table which contains
  147. *     the offset and length of each block of help text in the file.
  148. *
  149. *  o  A table entry is 4 bytes long and consists of two 16 bit unsigned
  150. *     numbers in binary format.  The first number is the offset within
  151. *     the file where the corresponding help text begins; the second
  152. *     number is the length of the text in bytes.
  153. *
  154. *  o  Table entries and related help text are arranged in numeric order
  155. *     according to the global variable "help_code" which is used to
  156. *     access the correct block of text.
  157. *
  158. *  o  Binary numbers at the beginning of the file are assumed to be
  159. *     in standard Intel format where the Least Significant Byte (LSB)
  160. *     is stored first and the Most Significant Byte (MSB) is second.
  161. ******
  162. FUNCTION helptext
  163.  
  164. PARAMETERS hfile, hnum
  165. PRIVATE htbuf, hoff, hlen, hhandle
  166.  
  167. * open the file and get handle
  168. hhandle = FOPEN(M->hfile)
  169.  
  170. IF FERROR() = 0
  171.    * allocate 512 byte buffer
  172.    htbuf = SPACE(512)
  173.  
  174.    * read the file header into memory
  175.    FREAD(M->hhandle, @htbuf, 512)
  176.  
  177.    * isolate the correct 4 byte table entry
  178.    htbuf = SUBSTR(M->htbuf, (4 * (M->hnum - 1)) + 1, 4)
  179.  
  180.    * convert binary numbers (LSB, MSB) to Clipper numerics
  181.    hoff = ASC(M->htbuf) + (256 * ASC(SUBSTR(M->htbuf, 2)))
  182.    hlen = ASC(SUBSTR(M->htbuf, 3)) + (256 * ASC(SUBSTR(M->htbuf, 4)))
  183.  
  184.    * allocate buffer
  185.    htbuf = SPACE(M->hlen)
  186.  
  187.    * position file to the correct offset
  188.    FSEEK(M->hhandle, M->hoff)
  189.  
  190.    * read text into buffer
  191.    FREAD(M->hhandle, @htbuf, M->hlen)
  192. ELSE
  193.    * return null string if error
  194.    htbuf = ""
  195. ENDIF
  196.  
  197. * close the file and release the handle
  198. FCLOSE(M->hhandle)
  199. RETURN M->htbuf
  200. * EOFcn helptext()
  201. * EOF help.prg
  202.  
  203.  
  204.