Added symbol tool.

Pascal J. Bourguignon [2014-03-08 16:10]
Added symbol tool.
Filename
tools/com.informatimago.tools.asd
tools/com.informatimago.tools.symbol.asd
tools/symbol.lisp
diff --git a/tools/com.informatimago.tools.asd b/tools/com.informatimago.tools.asd
new file mode 100644
index 0000000..11309e2
--- /dev/null
+++ b/tools/com.informatimago.tools.asd
@@ -0,0 +1,117 @@
+;;;; -*- mode:lisp;coding:utf-8 -*-
+;;;;**************************************************************************
+;;;;FILE:               com.informatimago.tools.asd
+;;;;LANGUAGE:           Common-Lisp
+;;;;SYSTEM:             Common-Lisp
+;;;;USER-INTERFACE:     NONE
+;;;;DESCRIPTION
+;;;;
+;;;;    ASD file to load the com.informatimago.tools libraries.
+;;;;
+;;;;AUTHORS
+;;;;    <PJB> Pascal J. Bourguignon <pjb@informatimago.com>
+;;;;MODIFICATIONS
+;;;;    2014-03-08 <PJB> Created this .asd file.
+;;;;BUGS
+;;;;LEGAL
+;;;;    AGPL3
+;;;;
+;;;;    Copyright Pascal J. Bourguignon 2014 - 2014
+;;;;
+;;;;    This program is free software: you can redistribute it and/or modify
+;;;;    it under the terms of the GNU Affero General Public License as published by
+;;;;    the Free Software Foundation, either version 3 of the License, or
+;;;;    (at your option) any later version.
+;;;;
+;;;;    This program is distributed in the hope that it will be useful,
+;;;;    but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;;;    GNU Affero General Public License for more details.
+;;;;
+;;;;    You should have received a copy of the GNU Affero General Public License
+;;;;    along with this program.  If not, see http://www.gnu.org/licenses/
+;;;;**************************************************************************
+
+(asdf:defsystem :com.informatimago.tools
+
+  ;; system attributes:
+
+  :description  "This system gathers Informatimago Common Lisp tools."
+
+  :author     "Pascal J. Bourguignon <pjb@informatimago.com>"
+
+  :maintainer "Pascal J. Bourguignon <pjb@informatimago.com>"
+
+  :licence "AGPL3"
+
+
+  ;; component attributes:
+
+  :name "Informatimago Common Lisp Tools Agregate"
+
+  :version "1.0.0"
+
+  :properties ((#:author-email                   . "pjb@informatimago.com")
+               (#:date                           . "Spring 2014")
+               ((#:albert #:output-dir)          . "/tmp/documentation/com.informatimago.tools/")
+               ((#:albert #:formats)             . ("docbook"))
+               ((#:albert #:docbook #:template)  . "book")
+               ((#:albert #:docbook #:bgcolor)   . "white")
+               ((#:albert #:docbook #:textcolor) . "black"))
+
+  #+asdf-unicode :encoding #+asdf-unicode :utf-8
+
+  :depends-on ("com.informatimago.tools.check-asdf"
+               "com.informatimago.tools.make-depends"
+               "com.informatimago.tools.manifest"
+               "com.informatimago.tools.pathname"
+               "com.informatimago.tools.symbol"
+               "com.informatimago.tools.quicklisp"))
+
+
+
+;; (com.informatimago.tools.check-asdf:check-asdf-system-file
+;;  #P"/some/system.asd"  :report output-stream)
+;;
+;; (com.informatimago.common-lisp.tools.make-depends:generate-asd
+;;  system-name sources source-type
+;;  &key description (version "0.0.0")
+;;  author licence license
+;;  (predefined-packages '("COMMON-LISP"))
+;;  (implicit-dependencies '())
+;;  (depends-on '())
+;;  (load-paths (list (make-pathname :directory '(:relative))))
+;;  (vanillap nil))
+;;
+;; (com.informatimago.common-lisp.tools.make-depends:generate-summary
+;;  sources &key (summary-path #p"SUMMARY.HTML")
+;;  (character-set "US-ASCII")
+;;  (source-type "LISP")
+;;  (verbose nil) (repository-url nil))
+;;
+;; (com.informatimago.common-lisp.tools.make-depends:make-depends
+;;  object-files packages translations load-paths
+;;  &key (idf nil) (verbose nil))
+;;
+;; (com.informatimago.tools.manifest:distribution)
+;; (com.informatimago.tools.manifest:print-manifest system)
+;; (com.informatimago.tools.manifest:write-manifest-file program-name system)
+;;
+;; (com.informatimago.tools.pathname:make-pathname …)
+;; (com.informatimago.tools.pathname:user-homedir-pathname)
+;; (com.informatimago.tools.pathname:translate-logical-pathname pathname)
+;;
+;; (com.informatimago.tools.quicklisp:quick-*)
+
+#-(and)
+(defun use-tools ()
+  (use-package :com.informatimago.tools.check-asdf)
+  (use-package :com.informatimago.common-lisp.tools.make-depends)
+  (use-package :com.informatimago.tools.manifest)
+  (shadow '(make-pathname user-homedir-pathname translate-logical-pathname))
+  (use-package :com.informatimago.tools.pathname)
+  (use-package :com.informatimago.tools.symbol)
+  (use-package :com.informatimago.tools.quicklisp)
+  (values))
+
+;;;; THE END ;;;;
diff --git a/tools/com.informatimago.tools.symbol.asd b/tools/com.informatimago.tools.symbol.asd
new file mode 100644
index 0000000..9d052f7
--- /dev/null
+++ b/tools/com.informatimago.tools.symbol.asd
@@ -0,0 +1,44 @@
+;;;; -*- mode:lisp;coding:utf-8 -*-
+;;;;**************************************************************************
+;;;;FILE:               symbol.asd
+;;;;LANGUAGE:           Common-Lisp
+;;;;SYSTEM:             Common-Lisp
+;;;;USER-INTERFACE:     NONE
+;;;;DESCRIPTION
+;;;;
+;;;;    Symbol tools.
+;;;;
+;;;;AUTHORS
+;;;;    <PJB> Pascal J. Bourguignon <pjb@informatimago.com>
+;;;;MODIFICATIONS
+;;;;    2013-12-06 <PJB> Extracted from ~/rc/common.lisp
+;;;;BUGS
+;;;;LEGAL
+;;;;    AGPL3
+;;;;
+;;;;    Copyright Pascal J. Bourguignon 2013 - 2013
+;;;;
+;;;;    This program is free software: you can redistribute it and/or modify
+;;;;    it under the terms of the GNU Affero General Public License as published by
+;;;;    the Free Software Foundation, either version 3 of the License, or
+;;;;    (at your option) any later version.
+;;;;
+;;;;    This program is distributed in the hope that it will be useful,
+;;;;    but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;;;    GNU Affero General Public License for more details.
+;;;;
+;;;;    You should have received a copy of the GNU Affero General Public License
+;;;;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+;;;;**************************************************************************
+
+(asdf:defsystem :com.informatimago.tools.symbol
+    :name "com.informatimago.tools.symbol"
+    :description "Symbol tools."
+    :author "Pascal J. Bourguignon"
+    :version "1.0.0"
+    :license "GPL3"
+    :depends-on ()
+    :components ((:file "symbol")))
+
+;;;; THE END ;;;;
diff --git a/tools/symbol.lisp b/tools/symbol.lisp
new file mode 100644
index 0000000..a741ee0
--- /dev/null
+++ b/tools/symbol.lisp
@@ -0,0 +1,79 @@
+;;;; -*- mode:lisp;coding:utf-8 -*-
+;;;;**************************************************************************
+;;;;FILE:               symbol.lisp
+;;;;LANGUAGE:           Common-Lisp
+;;;;SYSTEM:             Common-Lisp
+;;;;USER-INTERFACE:     NONE
+;;;;DESCRIPTION
+;;;;
+;;;;    A tool to check duplicate/un-exported/imported symbols.
+;;;;
+;;;;AUTHORS
+;;;;    <PJB> Pascal J. Bourguignon <pjb@informatimago.com>
+;;;;MODIFICATIONS
+;;;;    2014-03-08 <PJB> Created.
+;;;;BUGS
+;;;;LEGAL
+;;;;    AGPL3
+;;;;
+;;;;    Copyright Pascal J. Bourguignon 2014 - 2014
+;;;;
+;;;;    This program is free software: you can redistribute it and/or modify
+;;;;    it under the terms of the GNU Affero General Public License as published by
+;;;;    the Free Software Foundation, either version 3 of the License, or
+;;;;    (at your option) any later version.
+;;;;
+;;;;    This program is distributed in the hope that it will be useful,
+;;;;    but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;;;    GNU Affero General Public License for more details.
+;;;;
+;;;;    You should have received a copy of the GNU Affero General Public License
+;;;;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+;;;;**************************************************************************
+
+(defpackage "COM.INFORMATIMAGO.TOOLS.SYMBOL"
+  (:use "COMMON-LISP")
+  (:use "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.PACKAGE")
+  (:export "CHECK-DUPLICATE-SYMBOLS"
+           "DUPLICATE-SYMBOLS")
+  (:documentation "
+A tool to check duplicate/un-exported/imported symbols.
+"))
+(in-package "COM.INFORMATIMAGO.TOOLS.SYMBOL")
+
+
+(defun report-duplicates (symbols &optional (*standard-output* *standard-output*))
+  (let ((*package* (find-package "KEYWORD")))
+    (format t "~&~S~%" symbols)))
+
+(defun duplicate-symbols (&optional (packages (list-all-packages)))
+  "Return: a list of list of symbols that have the same name."
+  (let ((symbols (make-hash-table :test (function equal))) ; maps names to list of unique symbols
+        (duplicates '()))
+    (dolist (p packages)
+      (dolist (s (list-all-symbols p))
+        (pushnew s (gethash (symbol-name s) symbols '()))))
+    (maphash (lambda (name symbols)
+               (declare (ignore name))
+               (when (cdr symbols)
+                 (push symbols duplicates)))
+             symbols)
+    duplicates))
+
+(defun check-duplicate-symbols (&key (packages (list-all-packages)) (exported nil))
+  (report-duplicates (if exported
+                         (remove-if-not (lambda (symbols)
+                                          (some (lambda (symbol)
+                                                  (eq :external
+                                                      (nth-value 1 (find-symbol (symbol-name symbol)
+                                                                                (symbol-package symbol)))))
+                                                symbols))
+                                        (duplicate-symbols packages))
+                         (duplicate-symbols  packages)))
+  (values))
+
+
+
+;;;; THE END ;;;;
+
ViewGit