home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / QH.ZIP / QH2.M
Text File  |  1990-04-10  |  3KB  |  141 lines

  1. ;**
  2. ;**        qh.m
  3. ;**
  4. ;**        Interface the MS OS/2 SDK Quick-Help facility to Brief
  5. ;**
  6. ;**            Manuel A. Ulloa
  7. ;**            cserv: 71535,2017
  8. ;**            bix: mulloa
  9. ;**
  10. ;**            Please forward me any relevant changes and/or enhancemets.
  11. ;**
  12. ;**            The macro will us QH.EXE to search for help on the specified
  13. ;**        topic. The topic can be specified by either marking some word
  14. ;**        and invoking qh (by typing Ctrl-Q) or by invoking qh and then
  15. ;**        typing the topic. It depends on QH being correctly installed
  16. ;**        (in the path, etc.) It places the info in a file called B.QH
  17. ;**        placed in the buffer specied in the TMP environment variable.
  18. ;**        Note that QH.EXE can not be invoked in the background as it
  19. ;**        hangs. Furthermore, if the topic is not found QH will put up
  20. ;**        a popup box. Pressing any key makes it go away. A succesful
  21. ;**        match returns 2 for some reason (not 0 as expected).
  22. ;**
  23. ;**        04/05/89        MAU
  24. ;**            First OS/2 Implementation (Brief V2.11)
  25. ;**
  26.  
  27.  
  28. ;**    It needs this function. Found in ARM.M. Uncomment
  29. ;**    to be compiled in diferent files.
  30. ;**
  31. ;**    (extern _armgt        ; from the arm.m file
  32. ;**    )
  33.  
  34.  
  35. ;** (macro qh
  36. ;**        (assign_to_key "<Alt-q>" "do_qh")
  37. ;** )
  38.  
  39.  
  40. (macro do_qh
  41.     (
  42.         (string    _hlptxt
  43.                     tfil
  44.         )
  45.         (int        ret_code
  46.         )
  47.         (global    _hlptxt
  48.         )
  49.  
  50.         (= tfil (inq_environment "TMP"))
  51.  
  52.         ; check if path is the root
  53.         (if (== (substr tfil (strlen tfil) 1) "\\")
  54.             (= tfil (+ tfil "b.qh"))
  55.         ;else
  56.             (= tfil (+ tfil "\\b.qh"))
  57.         )
  58.  
  59.         ; get argumnet for qh
  60.         (if (inq_marked)
  61.             (= _hlptxt (_armgt))
  62.         ;else
  63.             (
  64.                 (if ( ! (get_parm 0 _hlptxt "QH: " NULL _hlptxt) )
  65.                     (return)
  66.                 )
  67.                 ;else
  68.             )
  69.         )
  70.  
  71.  
  72.         (delete_buffer (create_buffer "b.qh" tfil 0))
  73.         (message "Searching for \"%s\"..." _hlptxt)
  74.         (= ret_code (dos (+ "QH " (+ _hlptxt (+ " -p " (+ tfil " -t all >& NUL")))) 0))
  75.         (if (== ret_code 0)        
  76.             (
  77.                 (message "Found \"%s\"." _hlptxt )
  78.                 (edit_file tfil)
  79.             )
  80.         ;else
  81.             (error "Topic not found")            
  82.         )
  83.     )
  84. )
  85.  
  86.  
  87. ;**
  88. ;**    Return marked string
  89. ;**
  90.  
  91. (macro _armgt
  92.     (
  93.         (string    mtxt
  94.         )
  95.         (int        start_line
  96.                     end_line
  97.                     start_col
  98.                     end_col
  99.                     temp_int
  100.         )
  101.  
  102.         (if (inq_marked)
  103.             (
  104.                 (save_position)
  105.                 (inq_position end_line end_col)
  106.                 (swap_anchor)
  107.                 (inq_position start_line start_col)
  108.                 (raise_anchor)
  109.  
  110.                 ;**    If the starting column is greater than the ending
  111.                 ;**    column, swap the variables
  112.  
  113.                 (if (> start_col end_col)
  114.                     (
  115.                         (= temp_int start_col)
  116.                         (= start_col end_col)
  117.                         (= end_col temp_int)
  118.                         (move_abs 0 start_col)
  119.                     )
  120.                     ;else
  121.                 )
  122.  
  123.                 (if (== start_line end_line)
  124.                     (
  125.                         (= temp_int (+ (- end_col start_col) 1) )
  126.                         (= mtxt (read temp_int))
  127.                     )
  128.                     ;else
  129.                     (= mtxt (read))
  130.                 )
  131.  
  132.                 (restore_position)
  133.             )
  134.         ;else
  135.             (= mtxt "")
  136.         )
  137.  
  138.         (returns mtxt)
  139.     )
  140. )
  141.