home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 5.img / SUPPORT3.LIB / APPLOAD.LSP < prev    next >
Encoding:
Text File  |  1993-01-23  |  11.9 KB  |  405 lines

  1. ;;;----------------------------------------------------------------------------
  2. ;;;
  3. ;;;   APPLOAD.LSP   ¬⌐Ñ╗ 0.5
  4. ;;;
  5. ;;;   ¬⌐┼v (C) 1991-1992  Autodesk ñ╜Ñq
  6. ;;;
  7. ;;;   Ñ╗│n┼ΘºK╢O¿╤▒z╢iªµÑ⌠ª≤Ñ╬│~╗▌¿D¬║½■¿⌐íB¡╫º∩ñ╬╡oªµ, ª²¼O░╚╜╨┐φ┤`ñU¡z
  8. ;;;   ¡∞½h :
  9. ;;;
  10. ;;;   1)  ñWªC¬║¬⌐┼v│qºi░╚╗▌ÑX▓{ªb¿Cñ@Ñ≈½■¿⌐∙╪íC
  11. ;;;   2)  ¼█├÷¬║╗í⌐·ñσÑ≤ñ]Ñ▓╢╖⌐·╕ⁿ¬⌐┼v│qºiñ╬Ñ╗╢╡│\Ñi│qºiíC
  12. ;;;
  13. ;;;   Ñ╗│n┼Θ╢╚┤ú¿╤º@¼░└│Ñ╬ñW¬║░╤ª╥, ª╙Ñ╝┴n⌐·⌐╬┴⌠ºtÑ⌠ª≤½O├╥; ╣∩⌐≤Ñ⌠ª≤»S«φ
  14. ;;;   Ñ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºtÑX¿π¬║½O├╥, ªbª╣ñ@╖ºñ⌐ÑHº_╗{íC
  15. ;;;
  16. ;;;
  17. ;;;----------------------------------------------------------------------------
  18. ;;;   DESCRIPTION
  19. ;;;
  20. ;;;  An AutoLISP routine with a dialogue interface allowing users select
  21. ;;;  AutoLISP and ADS routines to load or unload.  Frequently used routines
  22. ;;;  can be saved to a file so that subsequent loads or unloads can be
  23. ;;;  performed quickly and easily from a small list of favorites rather than
  24. ;;;  scrolling through complete directory listings.
  25. ;;;
  26. ;;;----------------------------------------------------------------------------
  27. ;;;
  28. ;;; ===========================================================================
  29. ;;; ===================== load-time error checking ============================
  30. ;;;
  31.  
  32.   (defun ai_abort (app msg)
  33.      (defun *error* (s)
  34.         (if old_error (setq *error* old_error))
  35.         (princ)
  36.      )
  37.      (if msg
  38.        (alert (strcat " └│Ñ╬╡{ªí┐∙╗~: "
  39.                       app
  40.                       " \n\n  "
  41.                       msg
  42.                       "  \n"
  43.               )
  44.        )
  45.      )
  46.      (exit)
  47.   )
  48.  
  49. ;;; Check to see if AI_UTILS is loaded, If not, try to find it,
  50. ;;; and then try to load it.
  51. ;;;
  52. ;;; If it can't be found or it can't be loaded, then abort the
  53. ;;; loading of this file immediately, preserving the (autoload)
  54. ;;; stub function.
  55.  
  56.   (cond
  57.      (  (and ai_dcl (listp ai_dcl)))          ; it's already loaded.
  58.  
  59.      (  (not (findfile "ai_utils.lsp"))                     ; find it
  60.         (ai_abort "APPLOAD"
  61.                   (strcat "ºΣñú¿∞íuAI_UTILS.LSPív└╔«╫;"
  62.                           "\n  ╜╨└╦¼díusupportívÑ╪┐²íC")))
  63.  
  64.      (  (eq "failed" (load "ai_utils" "failed"))            ; load it
  65.         (ai_abort "APPLOAD" "╡L¬k╕ⁿñJíuAI_UTILS.LSPív└╔«╫"))
  66.   )
  67.  
  68.   (if (not (ai_acadapp))               ; defined in AI_UTILS.LSP
  69.       (ai_abort "APPLOAD" nil)         ; a Nil <msg> supresses
  70.   )                                    ; ai_abort's alert box dialog.
  71.  
  72. ;;; ==================== end load-time operations ===========================
  73. ;;;----------------------------------------------------------------------------
  74. ;;; The main fuinction.
  75. ;;;----------------------------------------------------------------------------
  76. (defun c:appload (/
  77.                     a             fp_list1      pickf
  78.                     add2lists     from          pickf1        the_list
  79.                     addfile       globals       pickf_list    ub
  80.                     appload_err   grey          pickf_no      unloadf
  81.                     cmd           is_one_ads    pos           updbox
  82.                     dcl_id        item          read_dfs      what
  83.                     lb            remfile       what_next     appload_main
  84.                     er            loadf         remove        what_pos
  85.                     f             make_list     rs_err        yep
  86.                     filetype      no_load       s
  87.                     fname         no_unload     save_list
  88.                     fp_list       olderr        save_tog
  89.                   )
  90.   ;;
  91.   ;; Make a list of all highlighted files for loading or unloading.  Similar
  92.   ;; code to remfile below.  Returns the list.
  93.   ;;
  94.   (defun make_list(/ pickf_no pickf_list fp_list1 n)
  95.     (setq pickf1 pickf)
  96.     (while (setq pickf_no (read pickf1))
  97.       (setq pickf_list (cons pickf_no pickf_list))
  98.       (setq pickf1 (substr pickf1 (+ 2 (strlen (itoa pickf_no)))))
  99.     )
  100.     (setq n 0)
  101.     (while (< n (length fp_list))
  102.       (if (member n pickf_list)
  103.         (progn
  104.           (setq fp_list1 (cons (nth n fp_list) fp_list1))
  105.         )
  106.       )
  107.       (setq n (1+ n))
  108.     )
  109.     fp_list1
  110.   )
  111.   ;;
  112.   ;; Load the files.
  113.   ;;
  114.   (defun loadf( / n)
  115.     (setq no_load 0)
  116.     (foreach n (setq er (make_list))
  117.       (princ (strcat "\n╕ⁿñJ " n " ..."))
  118.       (cond
  119.         ((= "lsp" (strcase (substr n (- (strlen n) 2)) T))
  120.           (load n (strcat "ºΣñú¿∞└╔«╫íu" n "ívíC"))
  121.         )
  122.         ((member n (ads))
  123.           (princ (strcat "\n└│Ñ╬╡{ªííu" n "ívñw╕ⁿñJíC"))
  124.         )
  125.         (T
  126.           (if (= (xload n "invalid") "invalid")
  127.               (princ (strcat "\n└╔«╫íu" n "ív╡L«─íC"))
  128.               (princ (strcat "\n└╔«╫íu" n "ívñw╕ⁿñJíC"))
  129.           )
  130.         )
  131.       )
  132.     )
  133.   )
  134.   ;;
  135.   ;; Unload the files.
  136.   ;;
  137.   (defun unloadf(/ n)
  138.     (setq no_unload 0)
  139.     (foreach n (make_list)
  140.       (princ (strcat "\n─└⌐±íu" n "ív..."))
  141.       (cond
  142.         ((= "lsp" (strcase (substr n (- (strlen n) 2)) T))
  143.           (princ (strcat "\níu" n
  144.                          "ív└╔ªW╡L«─ - AutoLISP └╔«╫╡L¬k─└⌐±íC"))
  145.         )
  146.         ((not (member n (ads)))
  147.           (princ (strcat "\níu" n
  148.                          "ív└╔«╫╡L«─ - └│Ñ╬╡{ªíÑ╝╕ⁿñJíC"))
  149.         )
  150.         ((xunload n))
  151.       )
  152.     )
  153.   )
  154.   ;;
  155.   ;; Check the list to find out whether the load and unload buttons should be
  156.   ;; enabled or not.  Returns a list which consist of two numbers, l and u.
  157.   ;; The buttons are enabled if the corresponding value is greater than 0.
  158.   ;;
  159.   (defun is_one_ads(/ yep n)
  160.     (setq lb 0)
  161.     (setq ub 0)
  162.     (foreach n (make_list)
  163.       (if (/= ".lsp" (strcase (substr n (- (strlen n) 3)) T))
  164.         (progn
  165.           (if (member n (ads))
  166.             (setq ub (1+ ub))  ; enable unload button
  167.             (setq lb (1+ lb))  ; enable load button
  168.           )
  169.         )
  170.         (setq lb (1+ lb))
  171.       )
  172.     )
  173.     (list lb ub)
  174.   )
  175.   ;;
  176.   ;; Disable the Remove control if no items are highlighted.
  177.   ;;
  178.   (defun grey()
  179.     (if (read (get_tile "fp_list"))
  180.       (progn
  181.         (mode_tile "remove_item" 0)
  182.         (if (< 0 (car (is_one_ads)))
  183.           (mode_tile "load" 0)
  184.           (mode_tile "load" 1)
  185.         )
  186.         (if (< 0 (cadr (is_one_ads)))
  187.           (mode_tile "unload" 0)
  188.           (mode_tile "unload" 1)
  189.         )
  190.       )
  191.       (progn
  192.         (mode_tile "remove_item" 1)
  193.         (mode_tile "load" 1)
  194.         (mode_tile "unload" 1)
  195.       )
  196.     )
  197.   )
  198.   ;;
  199.   ;; Reset the error tile.
  200.   ;;
  201.   (defun rs_err()
  202.     (set_tile "error" "")
  203.   )
  204.   ;;
  205.   ;; Read appload.dfs for defaults.
  206.   ;;
  207.   (defun read_dfs()
  208.     (if (setq f (open "appload.dfs" "r"))
  209.       (progn
  210.         (while (setq a (read-line f))
  211.           (setq fp_list (cons a fp_list))
  212.         )
  213.         (close f)
  214.         (if (and fp_list (>= (getvar "maxsort") (length fp_list)))
  215.           (setq fp_list (acad_strlsort fp_list))
  216.         )
  217.         (updbox)
  218.       )
  219.     )
  220.   )
  221.   ;;
  222.   ;; Save the current list to file.  Null lists are allowed.
  223.   ;;
  224.   (defun save_list()
  225.     (if (= "1" save_tog)
  226.       (progn
  227.         (if (setq f (open "appload.dfs" "w"))
  228.           (progn
  229.             (if fp_list
  230.               (progn
  231.                 (foreach n fp_list
  232.                   (write-line n f)
  233.                 )
  234.               )
  235.             )
  236.             (close f)
  237.           )
  238.           (alert (strcat "╡L¬k▒Níu▓M│µívªsñJÑ╪½eÑ╪┐²\n"
  239.                          " - Ñ▓╢╖╛╓ª│ª╣Ñ╪┐²¬║íu╝gñJñ╣╖╟ívíC")
  240.           )
  241.         )
  242.       )
  243.     )
  244.   )
  245.   ;;
  246.   ;; Add a file to the list, using the File Dialog box
  247.   ;;
  248.   (defun addfile ()
  249.     (setq fname (getfiled "┐∩╛▄íuLISP/ADSív▒`ªí" "" filetype 2))
  250.     (if fname
  251.       (progn
  252.         (add2lists fname)
  253.       )
  254.     )
  255.   )
  256.   ;;
  257.   ;; Add a file to the internal lists used for loading
  258.   ;;
  259.   (defun add2lists (fname)
  260.     (if (not (member fname fp_list))
  261.       (progn
  262.         (setq fp_list (append fp_list (list fname)))
  263.         (if (and fp_list (>= (getvar "maxsort") (length fp_list)))
  264.           (setq fp_list (acad_strlsort fp_list))
  265.         )
  266.         (updbox)
  267.         (set_tile "fp_list" (itoa (what_pos fname fp_list)))
  268.         (setq pickf (get_tile "fp_list"))
  269.         (grey)
  270.       )
  271.     )
  272.   )
  273.   ;;
  274.   ;; Pass an item and a list and recieve a number showing it's position in
  275.   ;; the list, nil otherwise.  Item must be in the list, and the list must
  276.   ;; contain unique names. 0 if first item.
  277.   ;;
  278.   (defun what_pos (item the_list / pos)
  279.     (setq pos (- (length the_list)
  280.                  (length (member item the_list)))
  281.     )
  282.   )
  283.   ;;
  284.   ;;  Remove the currently highlighted selections fp_list
  285.   ;;
  286.   (defun remfile (/ pickf_list pickf_no fp_list1)
  287.     (while (setq pickf_no (read pickf))
  288.       (setq pickf_list (cons pickf_no pickf_list))
  289.       (setq pickf (substr pickf (+ 2 (strlen (itoa pickf_no)))))
  290.     )
  291.     (setq n 0)
  292.     (while (< n (length fp_list))
  293.       (if (not (member n pickf_list))
  294.         (progn
  295.           (setq fp_list1 (cons (nth n fp_list) fp_list1))
  296.         )
  297.       )
  298.       (setq n (1+ n))
  299.     )
  300.     (setq fp_list (reverse fp_list1))
  301.     (updbox)
  302.     (setq pickf "")
  303.     (grey)
  304.   )
  305.   ;;
  306.   ;;  Remove an item from the list.
  307.   ;;
  308.   (defun remove (what from)
  309.     (append (reverse (cdr (member what (reverse from))))
  310.             (cdr (member what from))
  311.     )
  312.   )
  313.   ;;
  314.   ;; Build and display a list in the list_box
  315.   ;;
  316.   (defun updbox ()
  317.     (start_list "fp_list")
  318.     (mapcar 'add_list fp_list)
  319.     (end_list)
  320.   )
  321.  
  322.   ;;
  323.   ;; Put up the dialogue.
  324.   ;;
  325.   (defun appload_main()
  326.  
  327.     (setq fp_list nil)
  328.     (cond
  329.       ((= (getvar "platform") "386 DOS Extender")
  330.        (setq filetype "lsp;exp")
  331.       )
  332.       ((= (getvar "platform") "Windows")
  333.        (setq filetype "lsp;exe")
  334.       )
  335.       (t (setq filetype "*"))
  336.     )
  337.  
  338.     (if (not (new_dialog "appload" dcl_id)) (exit))
  339.     (read_dfs)
  340.     (if fp_list
  341.       (progn
  342.         (set_tile "fp_list" "0")
  343.         (setq pickf "0")
  344.         (grey)
  345.       )
  346.       (progn
  347.         (mode_tile "remove_item" 1)
  348.         (mode_tile "load" 1)
  349.         (mode_tile "unload" 1)
  350.       )
  351.     )
  352.     ;; If a default exists for the save list toggle, use it.  Else set the
  353.     ;; toggle to 1.
  354.     (if (setq save_tog (cadr (assoc "appload" ai_defaults)))
  355.       (set_tile "save_list" save_tog)
  356.       (set_tile "save_list" (setq save_tog "1"))
  357.     )
  358.     (action_tile "fp_list"      "(rs_err)(setq pickf $value)(grey)" )
  359.     (action_tile "add_to_list"  "(rs_err)(addfile)" )
  360.     (action_tile "remove_item"  "(rs_err)(remfile)" )
  361.     (action_tile "save_list"    "(rs_err)(setq save_tog $value)")
  362.     (action_tile "load"         "(save_list)(done_dialog 2)")
  363.     (action_tile "unload"       "(save_list)(done_dialog 3)")
  364.     (action_tile "cancel"       "(save_list)(done_dialog 0)")
  365.     (action_tile "help"         "(acad_helpdlg \"acad.hlp\" \"appload\")")
  366.     (setq what_next (start_dialog))
  367.     (cond
  368.       ((= 2 what_next) (loadf))
  369.       ((= 3 what_next) (unloadf))
  370.     )
  371.     (if (assoc "appload" ai_defaults)
  372.       (setq ai_defaults (subst (list "appload" save_tog)
  373.                                (assoc "appload" ai_defaults)
  374.                                ai_defaults
  375.                         )
  376.       )
  377.       (setq ai_defaults (cons (list "appload" save_tog) ai_defaults))
  378.     )
  379.   )
  380.  
  381.   ;; Set up error function.
  382.   (setq old_cmd (getvar "cmdecho")    ; save current setting of cmdecho
  383.         old_error  *error*            ; save current error function
  384.         *error* ai_error              ; new error function
  385.   )
  386.  
  387.   (setvar "cmdecho" 0)
  388.  
  389.   (cond
  390.      (  (not (ai_transd)))                       ; transparent OK
  391.      (  (not (ai_acadapp)))                      ; ACADAPP.EXP xloaded?
  392.      (  (not (setq dcl_id (ai_dcl "appload"))))  ; is .DCL file loaded?
  393.      (t (appload_main))                          ; proceed!
  394.   )
  395.  
  396.   (setq *error* old_error)
  397.   (setvar "cmdecho" old_cmd)
  398.  
  399.   (princ)
  400. )
  401.  
  402. ;;;----------------------------------------------------------------------------
  403. (princ "  íuAPPLOADívñw╕ⁿñJíC  ")
  404. (princ)
  405.