home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / SUPPORT / APPLOAD.LSP < prev    next >
Encoding:
Lisp/Scheme  |  1995-02-08  |  15.0 KB  |  466 lines

  1. ; Next available MSG number is    22 
  2. ; MODULE_ID APPLOAD_LSP_
  3. ;;;----------------------------------------------------------------------------
  4. ;;;
  5. ;;;    APPLOAD.LSP   Version 0.5
  6. ;;;
  7. ;;;    Copyright (C) 1991, 1992, 1993, 1994 by Autodesk, Inc.
  8. ;;;
  9. ;;;    Permission to use, copy, modify, and distribute this software
  10. ;;;    for any purpose and without fee is hereby granted, provided
  11. ;;;    that the above copyright notice appears in all copies and
  12. ;;;    that both that copyright notice and the limited warranty and
  13. ;;;    restricted rights notice below appear in all supporting
  14. ;;;    documentation.
  15. ;;;
  16. ;;;    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  17. ;;;    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
  18. ;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  19. ;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
  20. ;;;    UNINTERRUPTED OR ERROR FREE.
  21. ;;;
  22. ;;;    Use, duplication, or disclosure by the U.S. Government is subject to
  23. ;;;    restrictions set forth in FAR 52.227-19 (Commercial Computer
  24. ;;;    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  25. ;;;    (Rights in Technical Data and Computer Software), as applicable.
  26. ;;;
  27. ;;;.
  28. ;;;----------------------------------------------------------------------------
  29. ;;;   DESCRIPTION
  30. ;;;
  31. ;;;  An AutoLISP routine with a dialogue interface allowing users select
  32. ;;;  AutoLISP and ADS routines to load or unload.  Frequently used routines
  33. ;;;  can be saved to a file so that subsequent loads or unloads can be 
  34. ;;;  performed quickly and easily from a small list of favorites rather than 
  35. ;;;  scrolling through complete directory listings.
  36. ;;;  
  37. ;;;----------------------------------------------------------------------------
  38. ;;; 
  39. ;;; ===========================================================================
  40. ;;; ===================== load-time error checking ============================
  41. ;;;
  42.   (defun ai_abort (app msg)
  43.      (defun *error* (s)
  44.         (if old_error (setq *error* old_error))
  45.         (princ)
  46.      )
  47.      (if msg
  48.        (alert (strcat " Error en la aplicaci≤n: "
  49.                       app
  50.                       " \n\n  "
  51.                       msg
  52.                       "  \n"
  53.               )
  54.        )
  55.      )
  56.      (exit)
  57.   )
  58.  
  59. ;;; Check to see if AI_UTILS is loaded, If not, try to find it,
  60. ;;; and then try to load it.
  61. ;;;
  62. ;;; If it can't be found or it can't be loaded, then abort the
  63. ;;; loading of this file immediately, preserving the (autoload)
  64. ;;; stub function.
  65.  
  66.   (cond
  67.      (  (and ai_dcl (listp ai_dcl)))          ; it's already loaded.
  68.  
  69.      (  (not (findfile "ai_utils.lsp"))                     ; find it
  70.         (ai_abort "APPLOAD"
  71.                   (strcat "Imposible localizar archivo AI_UTILS.LSP."
  72.                           "\n Compruebe el directorio de soporte.")))
  73.  
  74.      (  (eq "failed" (load "ai_utils" "failed"))            ; load it
  75.         (ai_abort "APPLOAD" "Imposible cargar el archivo AI_UTILS.LSP"))
  76.   )
  77.  
  78.   (if (not (ai_acadapp))               ; defined in AI_UTILS.LSP
  79.       (ai_abort "APPLOAD" nil)         ; a Nil <msg> supresses
  80.   )                                    ; ai_abort's alert box dialog.
  81.  
  82. ;;; ==================== end load-time operations ===========================
  83. ;;;----------------------------------------------------------------------------
  84. ;;; The main fuinction.
  85. ;;;----------------------------------------------------------------------------
  86. (defun c:appload (/ 
  87.                     a             fp_list1      pickf
  88.                     add2lists     from          pickf1        the_list    
  89.                     addfile       globals       pickf_list    ub          
  90.                     appload_err   grey          pickf_no      unloadf     
  91.                     cmd           is_one_ads    pos           updbox      
  92.                     dcl_id        item          read_dfs      what        
  93.                     lb            remfile       what_next     appload_main
  94.                     er            loadf         remove        what_pos    
  95.                     f             make_list     rs_err        yep         
  96.                     filetype      no_load       s             filename
  97.                     fname         no_unload     save_list   
  98.                     fp_list       olderr        save_tog    
  99.                   )
  100.   ;;
  101.   ;; Make a list of all highlighted files for loading or unloading.  Similar
  102.   ;; code to remfile below.  Returns the list.
  103.   ;;
  104.   (defun make_list(/ pickf_no pickf_list fp_list1 n) 
  105.     (setq pickf1 pickf)
  106.     (while (setq pickf_no (read pickf1))
  107.       (setq pickf_list (cons pickf_no pickf_list))
  108.       (setq pickf1 (substr pickf1 (+ 2 (strlen (itoa pickf_no)))))
  109.     )
  110.     (setq n 0)
  111.     (while (< n (length fp_list))
  112.       (if (member n pickf_list)
  113.         (progn 
  114.           (setq fp_list1 (cons (nth n fp_list) fp_list1))
  115.         )
  116.       )
  117.       (setq n (1+ n))
  118.     )
  119.     fp_list1
  120.   )
  121.   ;;
  122.   ;; Load the files.
  123.   ;;
  124.   ;; Updated for Arx applications.
  125.   ;;
  126.   (defun loadf( / n)
  127.     (setq no_load 0)
  128.     (foreach n (setq er (make_list))
  129.       (princ (strcat "\nCargando " n " ..."))
  130.       (cond 
  131.         ((= "lsp" (strcase (substr n (- (strlen n) 2)) T))
  132.           (load n (strcat "Archivo " n " no encontrado."))
  133.         )
  134.         ((or (member (strcase n) (arx)) (member (strcase n) (ads)))
  135.           (princ (strcat "\nAplicaci≤n " n " ya cargada."))
  136.         )
  137.         (T 
  138.           (if (and (= (arxload n "invalid") "invalid")
  139.                    (= (xload n "invalid") "invalid")
  140.               )
  141.               (princ (strcat "\nEl archivo " n " no es vßlido."))
  142.               (princ (strcat "\nEl archivo " n " ha sido cargado."))
  143.           )
  144.         )
  145.       )
  146.     )
  147.   )
  148.   ;;
  149.   ;; Unload the files.
  150.   ;;
  151.   ;; Updated for Arx applications.
  152.   ;;
  153.   (defun unloadf(/ n)
  154.     (setq no_unload 0)
  155.     (foreach n (make_list)
  156.       (princ (strcat "\nDescargando " n " ..."))
  157.       (cond 
  158.         ((= "lsp" (strcase (substr n (- (strlen n) 2)) T))
  159.           (princ (strcat "\nArchivo no vßlido " n 
  160.                          " - Imposible descargar archivos AutoLISP."))
  161.         )
  162.         ((not (or (member (strcase n) (ads)) (member (strcase n) (arx)) ))
  163.           (princ (strcat "\n Archivo no vßlido " n
  164.                          " - La aplicaci≤n no estß cargada."))
  165.         )                           
  166.         ;; Remove Arx apps first as they can appear in (ads).
  167.         ((member (strcase n) (arx))
  168.           (arxunload n)
  169.         )
  170.         ((member (strcase n) (ads))
  171.           (xunload n)
  172.         )
  173.       )
  174.     )
  175.   )      
  176.   ;;
  177.   ;; Check the list to find out whether the load and unload buttons should be
  178.   ;; enabled or not.  Returns a list which consist of two numbers, l and u.
  179.   ;; The buttons are enabled if the corresponding value is greater than 0.
  180.   ;;
  181.   ;; Updated for Arx applications.
  182.   ;;
  183.   (defun is_one_ads(/ yep n)
  184.     (setq lb 0)
  185.     (setq ub 0)
  186.     (foreach n (make_list)
  187. (setq globvar n)
  188.       (if (/= ".lsp" (strcase (substr n (- (strlen n) 3)) T))
  189.         (progn 
  190.           (if (or (member (strcase n) (ads)) (member (strcase n) (arx)) )
  191.             (setq ub (1+ ub))  ; enable unload button
  192.             (setq lb (1+ lb))  ; enable load button
  193.           )
  194.         )
  195.         (setq lb (1+ lb))
  196.       )
  197.     )
  198.     (list lb ub)
  199.   )
  200.   ;;
  201.   ;; Disable the Remove control if no items are highlighted.
  202.   ;;
  203.   (defun grey()
  204.     (if (read (get_tile "fp_list"))
  205.       (progn
  206.         (mode_tile "remove_item" 0)
  207.         (if (< 0 (car (is_one_ads)))
  208.           (mode_tile "load" 0)
  209.           (mode_tile "load" 1)
  210.         )
  211.         (if (< 0 (cadr (is_one_ads)))
  212.           (mode_tile "unload" 0)
  213.           (mode_tile "unload" 1)
  214.         )
  215.       )
  216.       (progn
  217.         ;; Set focus to the File... control so we don't disable a
  218.         ;; a control that has focus.
  219.         (mode_tile "add_to_list" 2)
  220.         (mode_tile "remove_item" 1)
  221.         (mode_tile "load" 1)
  222.         (mode_tile "unload" 1)
  223.       )
  224.     )
  225.   )
  226.   ;;
  227.   ;; Reset the error tile.
  228.   ;;
  229.   (defun rs_err()
  230.     (set_tile "error" "")
  231.   )
  232.   ;;
  233.   ;; Read appload.dfs for defaults.
  234.   ;;
  235.   (defun read_dfs()
  236.     ;; Look for .dfs file in the standard places. 
  237.     (if (not (setq filename (findfile "appload.dfs")))
  238.       (setq filename "appload.dfs")
  239.     )
  240.     (if (setq f (open filename "r"))
  241.       (progn 
  242.         (while (setq a (read-line f))
  243.           (setq fp_list (cons a fp_list))
  244.         )
  245.         (close f)
  246.         (if (and fp_list (>= (getvar "maxsort") (length fp_list)))
  247.           (setq fp_list (acad_strlsort fp_list))
  248.         )
  249.         (updbox)
  250.       )
  251.       (updbox)
  252.     )
  253.   )
  254.   ;;
  255.   ;; Save the current list to file.  Null lists are allowed.
  256.   ;;
  257.   (defun save_list()
  258.     (if (= "1" save_tog)
  259.       (progn 
  260.         ;; Look for .dfs file in the standard places. 
  261.         (if (not (setq filename (findfile "appload.dfs")))
  262.           (setq filename "appload.dfs")
  263.         )
  264.         (if (setq f (open filename "w"))
  265.           (progn
  266.             (if fp_list
  267.               (progn
  268.                 (foreach n fp_list
  269.                   (write-line n f)
  270.                 )
  271.               )
  272.             )
  273.             (close f)
  274.           )
  275.           (alert (strcat "Imposible guardar lista en el directorio actual: \n"
  276.                          " el directorio debe tener permiso de escritura.")
  277.           )
  278.         )
  279.       )  
  280.     )
  281.   )
  282.   ;;
  283.   ;; Add a file to the list, using the File Dialog box
  284.   ;;
  285.   (defun addfile ()
  286.     (setq fname (getfiled "Seleccionar archivo AutoLISP, ADS o ARX" "" filetype 2))
  287.     (if fname
  288.       (progn
  289.         (add2lists fname)
  290.       )
  291.     )
  292.   )
  293.   ;;
  294.   ;; Add a file to the internal lists used for loading
  295.   ;;
  296.   (defun add2lists (fname)
  297.     (if (not (member fname fp_list))
  298.       (progn 
  299.         (setq fp_list (append fp_list (list fname)))            
  300.         (if (and fp_list (>= (getvar "maxsort") (length fp_list)))
  301.           (setq fp_list (acad_strlsort fp_list))
  302.         )
  303.         (updbox)
  304.         (set_tile "fp_list" (itoa (what_pos fname fp_list)))
  305.         (setq pickf (get_tile "fp_list"))
  306.         (grey)
  307.       )
  308.     )
  309.   )
  310.   ;;
  311.   ;; Pass an item and a list and recieve a number showing it's position in  
  312.   ;; the list, nil otherwise.  Item must be in the list, and the list must 
  313.   ;; contain unique names. 0 if first item.                               
  314.   ;;
  315.   (defun what_pos (item the_list / pos)
  316.     (setq pos (- (length the_list)
  317.                  (length (member item the_list)))
  318.     )          
  319.   )
  320.   ;;
  321.   ;;  Remove the currently highlighted selections fp_list
  322.   ;;
  323.   (defun remfile (/ pickf_list pickf_no fp_list1)
  324.     (while (setq pickf_no (read pickf))
  325.       (setq pickf_list (cons pickf_no pickf_list))
  326.       (setq pickf (substr pickf (+ 2 (strlen (itoa pickf_no)))))
  327.     )
  328.     (setq n 0)
  329.     (while (< n (length fp_list))
  330.       (if (not (member n pickf_list))
  331.         (progn 
  332.           (setq fp_list1 (cons (nth n fp_list) fp_list1))
  333.         )
  334.       )
  335.       (setq n (1+ n))
  336.     )
  337.     (setq fp_list (reverse fp_list1))
  338.     (updbox)
  339.     (setq pickf "")
  340.     (grey)
  341.   )
  342.   ;;
  343.   ;;  Remove an item from the list. 
  344.   ;;
  345.   (defun remove (what from)
  346.     (append (reverse (cdr (member what (reverse from))))
  347.             (cdr (member what from))
  348.     )
  349.   )
  350.   ;;
  351.   ;; Build and display a list in the list_box
  352.   ;;
  353.   (defun updbox ()
  354.     (start_list "fp_list")
  355.     (mapcar 'add_list fp_list)
  356.     (end_list)
  357.   )
  358.  
  359.   ;;
  360.   ;; Put up the dialogue.
  361.   ;;
  362.   ;; Updated for Arx apps.
  363.   ;;
  364.   (defun appload_main()
  365.  
  366.     (setq fp_list nil)
  367.     ;; (acad_getfiled) only accpts two file extensions and so all
  368.     ;; platforms must use "*" with the addition of a third filetype
  369.     ;; (.arx).  If the (acad_getfiled) limit is increased from two,
  370.     ;; we can revert to displaying only those files of interest on
  371.     ;; a per platform basis.  In the meantime, that code is commented
  372.     ;; out.
  373.     (cond 
  374.       ((= (getvar "platform") "386 DOS Extender")
  375.        (setq filetype "lsp;exp;arx")
  376.       )
  377.       ;; Only check the initial letters as these extensions are
  378.       ;; good for NT and Windows.
  379.       ((= (substr (getvar "platform") 1 17) "Microsoft Windows")
  380.        (setq filetype "lsp;exe;arx")
  381.       )
  382.       ;;
  383.       ;; The following weird extension "::1" is an
  384.       ;; illegal extension on the mac and is used to
  385.       ;; signal the mac-specific file dialog code
  386.       ;; to filter for the mac file _type_  'libr'.
  387.       ;; I would pass in the 4 char filetype directly,
  388.       ;; but we're trying to enforce a 3 char limit
  389.       ;; in getfiled for cross-platform compatibility.
  390.       ;;
  391.       ((= (getvar "platform") "Apple Macintosh")
  392.        (setq filetype "lsp;::1;arx")
  393.       )
  394.       (t 
  395.          (setq filetype "*")
  396.       )
  397.     )
  398.  
  399.     (if (not (new_dialog "appload" dcl_id)) (exit))
  400.     (read_dfs)
  401.     (if fp_list 
  402.       (progn 
  403.         (set_tile "fp_list" "0")
  404.         (setq pickf "0")
  405.         (grey)
  406.       )
  407.       (progn
  408.         (mode_tile "remove_item" 1)
  409.         (mode_tile "load" 1)
  410.         (mode_tile "unload" 1)
  411.       )
  412.     )
  413.     ;; If a default exists for the save list toggle, use it.  Else set the 
  414.     ;; toggle to 1.
  415.     (if (setq save_tog (cadr (assoc "appload" ai_defaults)))
  416.       (set_tile "save_list" save_tog)
  417.       (set_tile "save_list" (setq save_tog "1"))
  418.     )
  419.     (action_tile "fp_list"      "(rs_err)(setq pickf $value)(grey)" ) 
  420.     (action_tile "add_to_list"  "(rs_err)(addfile)" )
  421.     (action_tile "remove_item"  "(rs_err)(remfile)" )
  422.     (action_tile "save_list"    "(rs_err)(setq save_tog $value)")
  423.     (action_tile "load"         "(save_list)(done_dialog 2)")
  424.     (action_tile "unload"       "(save_list)(done_dialog 3)")
  425.     (action_tile "cancel"       "(save_list)(done_dialog 0)")
  426.     (action_tile "help"         "(help \"\" \"appload\")")
  427.     (setq what_next (start_dialog))
  428.     (cond 
  429.       ((= 2 what_next) (loadf))
  430.       ((= 3 what_next) (unloadf))
  431.     )
  432.     (if (assoc "appload" ai_defaults)
  433.       (setq ai_defaults (subst (list "appload" save_tog) 
  434.                                (assoc "appload" ai_defaults)
  435.                                ai_defaults
  436.                         )
  437.       )
  438.       (setq ai_defaults (cons (list "appload" save_tog) ai_defaults))
  439.     )
  440.   )
  441.  
  442.   ;; Set up error function.
  443.   (setq old_cmd (getvar "cmdecho")    ; save current setting of cmdecho
  444.         old_error  *error*            ; save current error function
  445.         *error* ai_error              ; new error function
  446.   )
  447.  
  448.   (setvar "cmdecho" 0)
  449.  
  450.   (cond
  451.      (  (not (ai_transd)))                       ; transparent OK
  452.      (  (not (ai_acadapp)))                      ; ACADAPP.EXP xloaded?
  453.      (  (not (setq dcl_id (ai_dcl "appload"))))  ; is .DCL file loaded?
  454.      (t (appload_main))                          ; proceed!
  455.   )
  456.  
  457.   (setq *error* old_error) 
  458.   (setvar "cmdecho" old_cmd)
  459.  
  460.   (princ)
  461. )
  462.  
  463. ;;;----------------------------------------------------------------------------
  464. (princ "  APPLOAD cargada.  ")
  465. (princ)
  466.