;; CADLisp Tools - Purge/Audit Helper
(defun c:CLEANHELP (/ *error* answer undo-started)
  (defun *error* (message)
    (if undo-started (command-s "_.UNDO" "_End"))
    (if (and message (not (wcmatch (strcase message) "*CANCEL*,*QUIT*,*EXIT*")))
      (prompt (strcat "\nCLEANHELP stopped: " message)))
    (princ))
  (initget "Yes No")
  (setq answer (getkword "\nRun AUDIT and all-item PURGE? [Yes/No] <No>: "))
  (if (= answer "Yes")
    (progn
      (if (= 0 (logand 8 (getvar "UNDOCTL")))
        (progn (command-s "_.UNDO" "_Begin") (setq undo-started T)))
      (command-s "_.AUDIT" "_Yes")
      (command-s "_.-PURGE" "_All" "*" "_No")
      (if undo-started (progn (command-s "_.UNDO" "_End") (setq undo-started nil)))
      (prompt "\nAudit and purge commands completed. Review command history."))
    (prompt "\nCleanup cancelled."))
  (princ))
