home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / j / jan93.zip / SEARCH.LSP < prev    next >
Lisp/Scheme  |  1993-02-12  |  6KB  |  238 lines

  1. ;==========================================================
  2. ; SEARCH.LSP Copyright 1992 by Looking Glass Microproducts
  3. ;==========================================================
  4. ; Find text entities on screen.
  5. (setq SEARCH-VERSION "1.00")
  6. ;==========================================================
  7. ; Error Handler
  8. (defun SEARCH-ERROR (S)
  9.    (if BLINKING (redraw BLINKING))
  10.    (if (not
  11.           (member S '("Function cancelled" "console break"))
  12.        )
  13.       (princ S)
  14.    )
  15.    (command "_undo" "end")
  16.    (POPVARS)
  17. )
  18. ;==========================================================
  19. ; Set and Save System Variables
  20. (defun PUSHVARS (VLIST)
  21.    (foreach PAIR VLIST
  22.       (setq
  23.          SYSVARS (cons
  24.                     (cons
  25.                        (strcase (car PAIR))
  26.                        (getvar (car PAIR))
  27.                     )
  28.                     SYSVARS
  29.                  )
  30.       )
  31.       (if (cdr PAIR) (setvar (car PAIR) (cdr PAIR)))
  32.    )
  33.    t
  34. )
  35. ;==========================================================
  36. ; Restore System Variables
  37. (defun POPVARS ()
  38.    (foreach PAIR SYSVARS (setvar (car PAIR) (cdr PAIR)))
  39.    (setq
  40.       *error* OLD-ERROR
  41.    )
  42.    (princ)
  43. )
  44. ;==========================================================
  45. ; Disallow transparent invocation of routine.
  46. (defun NOTRANS ()
  47.    (cond
  48.       ((zerop (logand (getvar "cmdactive") (+ 1 2 4 8))))
  49.       ((alert
  50.           "This command may not be invoked transparently."
  51.        )
  52.       )
  53.    )
  54. )
  55. ;==========================================================
  56. ; Midpoint of Two Points
  57. (defun MIDPOINT (P1 P2)
  58.    (mapcar '(lambda (A B) (* 0.5 (+ A B))) P1 P2)
  59. )
  60. ;==========================================================
  61. ; Middle point of text entity
  62. (defun GET_MIDDLE (/ ICON)
  63.    (setq ICON (getvar "ucsicon"))
  64.    (setvar "ucsicon" 0)
  65.    (command "_ucs" "e" BLINKING)
  66.    (setq
  67.       MIDDLE (trans
  68.                 (apply
  69.                    'MIDPOINT
  70.                    (textbox (entget BLINKING))
  71.                 )
  72.                 1
  73.                 0
  74.              )
  75.    )
  76.    (command "_ucs" "p")
  77.    (setvar "ucsicon" ICON)
  78.    (setq MIDDLE (trans MIDDLE 0 1))
  79. )
  80. ;==========================================================
  81. ; Show prompt
  82. (defun SHOW_PROMPT ()
  83.    (prompt
  84.       (strcat
  85.          "\rMatch "
  86.          (rtos (1+ I) 2 0)
  87.          "/"
  88.          (rtos N 2 0)
  89.          " : Center/Next/Previous/<eXit>:      "
  90.       )
  91.    )
  92. )
  93. ;==========================================================
  94. ; Blink entity until key pressed
  95. (defun GET_ACTION ()
  96.    (while (/= 2 (car (setq ACTION (grread t))))
  97.       (if (> (getvar "date") BLINK)
  98.          (progn
  99.             (setq
  100.                BLINK (+ BLINKRATE (getvar "date"))
  101.                ON    (not ON)
  102.             )
  103.             (redraw BLINKING (if ON 1 2))
  104.          )
  105.       )
  106.    )
  107.    (redraw BLINKING)
  108. )
  109. ;==========================================================
  110. ; Is Point p at center of screen?
  111. (defun CENTERED (P)
  112.    (equal (trans P 1 2) (trans (getvar "viewctr") 1 2) 1E-8)
  113. )
  114. ;==========================================================
  115. ; Is Point p on screen?
  116. (defun ON_SCREEN (P / VIEWCTR VIEWSIZE VSMIN VSMAX ASPECT 
  117.                       VMIN VMAX)
  118.    (setq
  119.       VIEWCTR  (trans (getvar "viewctr") 1 2)
  120.       VIEWSIZE (getvar "viewsize")
  121.       VSMIN    (trans (getvar "vsmin") 1 2)
  122.       VSMAX    (trans (getvar "vsmax") 1 2)
  123.       ASPECT   (mapcar '- VSMAX VSMIN)
  124.       ASPECT   (/ (car ASPECT) (cadr ASPECT))
  125.       VMIN     (mapcar
  126.                   '-
  127.                   VIEWCTR
  128.                   (list
  129.                      (* 0.5 ASPECT VIEWSIZE)
  130.                      (* 0.5 VIEWSIZE)
  131.                   )
  132.                )
  133.       VMAX     (mapcar
  134.                   '+
  135.                   VIEWCTR
  136.                   (list
  137.                      (* 0.5 ASPECT VIEWSIZE)
  138.                      (* 0.5 VIEWSIZE)
  139.                   )
  140.                )
  141.       P        (trans P 1 2)
  142.    )
  143.    (apply 'and (mapcar '<= VMIN P VMAX))
  144. )
  145. ;==========================================================
  146. ; Show ss on screen
  147. (defun SHOW (SS / N I AGAIN ACTION BLINK BLINKING BLINKRATE 
  148.                   ON MIDDLE)
  149.    (setq BLINKRATE (/ 0.5 86400.0)) ; in days 
  150.    (setq N (sslength SS) I 0)
  151.    (prompt "\n")
  152.    (setq AGAIN t)
  153.    (while AGAIN
  154.       (setq
  155.          BLINK    (+ BLINKRATE (getvar "date"))
  156.          BLINKING (ssname SS I)
  157.          ON       t
  158.       )
  159.       (GET_MIDDLE)
  160.       (if (not (ON_SCREEN MIDDLE))
  161.          (command
  162.             "_zoom" "c" MIDDLE ""
  163.          )
  164.       )
  165.       (SHOW_PROMPT)
  166.       (GET_ACTION)
  167.       (cond
  168.          ((member ACTION '((2 67) (2 99)))
  169.             (if (not (CENTERED MIDDLE))
  170.                (command
  171.                   "_zoom" "c" MIDDLE ""
  172.                )
  173.             )
  174.          )
  175.          ((member ACTION '((2 78) (2 110)))
  176.             (setq
  177.                I (if (< I (1- N)) (1+ I) 0)
  178.             )
  179.          )
  180.          ((member ACTION '((2 80) (2 112)))
  181.             (setq
  182.                I (1- (if (> I 0) I N))
  183.             )
  184.          )
  185.          ((member ACTION '((2 13) (2 88) (2 120)))
  186.             (setq
  187.                AGAIN nil
  188.             )
  189.          )
  190.       )
  191.    )
  192. )
  193. ;==========================================================
  194. ; Search main routine
  195. (defun SEARCH (/ PATTERN SS)
  196.    (graphscr)
  197.    (cond
  198.       ((= "" (setq PATTERN (getstring "For pattern: "))))
  199.       ((null
  200.           (setq
  201.              SS (ssget
  202.                    "x"
  203.                    (list (cons 0 "TEXT") (cons 1 PATTERN))
  204.                 )
  205.           )
  206.        )
  207.          (prompt "Not found.")
  208.       )
  209.       (t (SHOW SS))
  210.    )
  211.    (setq SS nil)
  212. )
  213. ;==========================================================
  214. ; Search Command 
  215. (defun C:SEARCH (/ OLD-ERROR SYSVARS)
  216.    (if (NOTRANS)
  217.       (progn
  218.          (setq OLD-ERROR *error* *error* SEARCH-ERROR)
  219.          (PUSHVARS
  220.          '(("cmdecho" . 0) ("blipmode" . 0) ("osmode" . 0))
  221.          )
  222.          (command "_undo" "group")
  223.          (SEARCH)
  224.          (command "_undo" "end")
  225.          (POPVARS)
  226.       )
  227.       (princ)
  228.    )
  229. )
  230. (princ
  231.    (strcat
  232.       "\SEARCH.LSP v"
  233.       SEARCH-VERSION
  234.       " -- Copyright 1992 by Looking Glass Microproducts"
  235.    )
  236. )
  237. (princ)
  238.