id
int64
0
45.1k
file_name
stringlengths
4
68
file_path
stringlengths
14
193
content
stringlengths
32
9.62M
size
int64
32
9.62M
language
stringclasses
1 value
extension
stringclasses
6 values
total_lines
int64
1
136k
avg_line_length
float64
3
903k
max_line_length
int64
3
4.51M
alphanum_fraction
float64
0
1
repo_name
stringclasses
779 values
repo_stars
int64
0
882
repo_forks
int64
0
108
repo_open_issues
int64
0
90
repo_license
stringclasses
8 values
repo_extraction_date
stringclasses
146 values
sha
stringlengths
64
64
__index_level_0__
int64
0
45.1k
exdup_ids_cmlisp_stkv2
listlengths
1
47
4,926
mcclim.lisp
informatimago_lisp/cl-loaders/mcclim.lisp
;;;; -*- coding:utf-8 -*- (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (ext:without-package-lock ("GRAY" "COMMON-LISP" "CHARSET") (package:add-nickname "CHARSET""EXTERNAL-FORMAT") (asdf:oos 'asdf:load-op :mcclim)) (asdf:operate 'asdf:load-op :clim-listener) (format t "~2%(clim-listener:run-listener)~2%")
365
Common Lisp
.lisp
8
43.625
58
0.704225
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
032caff9dcc561398d1fe0fb6f9aed03bc34480f67feb12d37b94f663ab1748a
4,926
[ -1 ]
4,927
regex.lisp
informatimago_lisp/cl-loaders/regex.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: regex.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Loaded for Michale Parker's REGEX ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2004-11-23 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2004 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (load "loaders:clocc") (let ((sys-path (make-pathname :directory (append (pathname-directory (user-homedir-pathname)) '("src" "lisp" "michael-parker")) :defaults (user-homedir-pathname))) (src-path (make-pathname :directory (append (pathname-directory (user-homedir-pathname)) '("src" "lisp" "michael-parker" "regex")) :defaults (user-homedir-pathname)))) (setf (logical-pathname-translations "REGEX") (list(list "REGEX:SYS;*.*" (make-pathname :name :wild :defaults sys-path)) (list "REGEX:SYS;*.*" (make-pathname :name :wild :type :wild :defaults sys-path)) (list "REGEX:SYS;*.*.*" (make-pathname :name :wild :type :wild :version :wild :defaults sys-path)) (list "REGEX:SRC;*.*" (make-pathname :name :wild :defaults src-path)) (list "REGEX:SRC;*.*" (make-pathname :name :wild :type :wild :defaults src-path)) (list "REGEX:SRC;*.*.*" (make-pathname :name :wild :type :wild :version :wild :defaults src-path)))) (push src-path mk::*central-registry*)) (mk:oos "regex" :load) ;;;; regex.lisp -- -- ;;;;
3,281
Common Lisp
.lisp
68
35.455882
83
0.467581
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
e0b388467576551af108a0a16d5226d8b40d2d6586c64e365962fd4a78210e0b
4,927
[ -1 ]
4,928
clocc.lisp
informatimago_lisp/cl-loaders/clocc.lisp
;;;; -*- coding:utf-8 -*- (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) ;; ---------------------------------------------------------------------- ;; CLOCC -- Compiling the CLOCC -- ;; ------------------------------- (defparameter *clocc-root* (namestring (translate-logical-pathname "PACKAGES:NET;SOURCEFORGE;CLOCC;CLOCC;"))) (load "CLOCC:CLOCC") (load "CLOCC:SRC;DEFSYSTEM;DEFSYSTEM") (load "CLOCC:SRC;CLLIB;BASE") (defun compile-clocc () (load (compile-file "CLOCC:CLOCC")) (load (compile-file "CLOCC:SRC;DEFSYSTEM;DEFSYSTEM")) ;; * compile some systems (setq mk::*central-registry* (nconc ;; select the systems you want to use (mapcar (lambda (syssub) (translate-logical-pathname (concatenate 'string "CLOCC:SRC;" syssub))) '("CLLIB;" "EXT;QUEUES;" "EXT;UNION-FIND;" "GUI;CLX;" "GUI;CLUE;" "F2CL;PACKAGES;" "F2CL;" "PORT;" "PORT;CONFIGURATION;" "PORT;ENVIRONMENT;" "PORT;SHELL;" "TOOLS;METERING;" "TOOLS;CLUNIT;" "SCREAMER;" "SCREAMER;" )) mk::*central-registry*)) (mk:oos "cllib" :compile) (mk:oos "f2cl" :compile));;COMPILE-CLOCC ;; ---------------------------------------------------------------------- ;; -- CLOCC -- FORTRAN to LISP translator -- ;; ----------------------------------------- (defvar *ext* #+clisp ".fas" #+cmucl ".x86f" #+sbcl ".fasl" #+allegro ".fasl" #+vms ".fas" #+lucid ".sbin") (defvar *f2cl_dir* "CLOCC:CLOCC;SRC;F2CL;SRC;") (defun load-f2cl-module (x) (load (concatenate 'string *f2cl_dir* x *ext*) :print nil :verbose nil)) ;;LOAD-F2CL-MODULE (defun load-f2cl () (load-f2cl-module "f2cl0" ) (load-f2cl-module "f2cl1" ) (load-f2cl-module "f2cl2" ) (load-f2cl-module "f2cl3" ) (load-f2cl-module "f2cl4" ) (load-f2cl-module "f2cl5" ) (load-f2cl-module "f2cl6" ) (load-f2cl-module "f2cl7" ) (load-f2cl-module "macros" ) (format t "~&The f2cl software has been loaded.~%"));;LOAD-F2CL (format t "Push on MK::*CENTRAL-REGISTRY* directories where .system files are ~ to be found.~%") (push "clocc:src;port;" mk::*central-registry*) ;;;; clocc.lisp -- -- ;;;;
2,530
Common Lisp
.lisp
68
29.867647
93
0.500815
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
7d8a95b532a54dea05a24c19286bcca28a0bb73726be75ab3470dc434caca449
4,928
[ -1 ]
4,929
norvig-graph.lisp
informatimago_lisp/cl-loaders/norvig-graph.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: norvig-graph.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: clisp ;;;;USER-INTERFACE: clisp ;;;;DESCRIPTION ;;;; ;;;; This file extracts the requires sexps from the norvig sources and ;;;; builds a dependency graph to be displayed by dot(1). ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon ;;;;MODIFICATIONS ;;;; 2003-05-16 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2003 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (load "PACKAGE:COM;INFORMATIMAGO;COMMON-LISP;GRAPH") (load "PACKAGE:COM;INFORMATIMAGO;COMMON-LISP;GRAPH-DOT") (load "PACKAGE:COM;INFORMATIMAGO;COMMON-LISP;LIST") (load "PACKAGE:COM;INFORMATIMAGO;COMMON-LISP;UTILITY") (use-package "COM.INFORMATIMAGO.COMMON-LISP.GRAPH") (use-package "COM.INFORMATIMAGO.COMMON-LISP.GRAPH-DOT") (use-package "COM.INFORMATIMAGO.COMMON-LISP.LIST") (use-package "COM.INFORMATIMAGO.COMMON-LISP.UTILITY") (defvar data) (defvar g) (setq data (mapcan (lambda (file) (let ((requires (with-open-file (in file :direction :input) (let ((*readtable* (copy-readtable nil))) (set-dispatch-macro-character #\# #\. (lambda (&rest args) args)) (do* ((eof (gensym "eof")) (sexp (read in nil eof) (read in nil eof)) (result (list))) ((eq eof sexp) result) (when (and (consp sexp) (eq 'requires (car sexp))) (setq result (nconc (cdr sexp) result )))))) )) (when requires (list (cons (let* ((name (file-namestring file)) (posi (search ".lisp" name))) (if posi (subseq name 0 posi) name)) requires))) )) (directory "NORVIG:*.LISP"))) (setq g (make-instance 'graph-class)) (set-property g :name "NORVIG") (add-nodes g (mapcar (lambda (name) (let ((node (make-instance 'element-class))) (set-property node :name name) node)) (delete-duplicates (flatten data) :test (function string=)))) (mapc (lambda (arcs) (let* ((from (car arcs)) (from-node (car (find-nodes-with-property g :name from)))) (mapc (lambda (to) (let ((to-node (car (find-nodes-with-property g :name to)))) (add-edge-between-nodes g from-node to-node))) (cdr arcs)))) data) (let ((fname "norvig")) (with-open-file (out (format nil "~A.dot" fname) :direction :output :if-exists :supersede :if-does-not-exist :create) (princ (generate-dot g) out)) (ext:shell (format nil "n=~A ; (dot -Tps ${n}.dot -o ${n}.ps;gv ${n}.ps)&" fname)) ;;; (EXT:SHELL (FORMAT NIL "n=~A ; (tred ${n}.dot > ${n}-tred.dot ;~ ;;; dot -Tps ${n}-tred.dot -o ${n}-tred.ps ;~ ;;; gv ${n}-tred.ps) & " FNAME)) ) ;; Give a list of conflicts, symbol defineds in two files. (mapcon (lambda (left-rest) (let ((left (car left-rest))) (mapcan (lambda (right) ;; (FORMAT T "~2%LEFT = ~S~%RIGHT= ~S~%" (CDR LEFT) (CDR RIGHT)) (let ((res (intersection (cdr left) (cdr right) :test (function string-equal)))) (if res (list (cons (car left) (cons (car right) res))) nil))) (cdr left-rest)))) (remove-if (lambda (l) (= 1 (length l))) (mapcar (lambda (file) (cons file (mapcar (lambda (item) (cond ((symbolp (second item)) (second item)) ((and (consp (second item)) (symbolp (car (second item)))) (car (second item))) (t nil))) (with-open-file (in file :direction :input) (let ((*readtable* (copy-readtable nil))) (set-dispatch-macro-character #\# #\. (lambda (&rest args) args)) (do* ((eof (gensym "eof")) (sexp (read in nil eof) (read in nil eof)) (result ())) ((eq eof sexp) result) (when (and (consp sexp) (< 3 (length (string (car sexp)))) (string-equal "DEF" (subseq (string (car sexp)) 0 3))) (push sexp result)))))))) (directory "NORVIG:*.LISP")))) ( ("eliza.lisp" "intro.lisp" mappend) ("eliza.lisp" "eliza1.lisp" *eliza-rules* mappend eliza) ("eliza.lisp" "eliza-pm.lisp" eliza) ("eliza.lisp" "unifgram.lisp" punctuation-p) ("eliza.lisp" "auxfns.lisp" mappend) ("prolog.lisp" "prolog1.lisp" variables-in show-prolog-vars top-level-prove prove prove-all ?- find-anywhere-if unique-find-anywhere-if rename-variables clear-predicate clear-db add-clause <- *db-predicates* predicate get-clauses clause-body clause-head) ("prolog.lisp" "krep2.lisp" show-prolog-vars top-level-prove prove prove-all) ("prolog.lisp" "prologc2.lisp" args) ("prolog.lisp" "prologc1.lisp" args) ("prolog.lisp" "krep.lisp" replace-?-vars) ("prolog.lisp" "prologc.lisp" top-level-prove add-clause <- args) ("prolog.lisp" "compile3.lisp" args) ("intro.lisp" "eliza1.lisp" mappend) ("intro.lisp" "auxfns.lisp" mappend) ("search.lisp" "mycin.lisp" is is) ("search.lisp" "compile3.lisp" is is) ("search.lisp" "gps.lisp" find-path) ("othello2.lisp" "othello.lisp" mobility all-squares) ("othello2.lisp" "overview.lisp" node) ("simple.lisp" "lexicon.lisp" verb noun) ("simple.lisp" "eliza1.lisp" random-elt) ("simple.lisp" "syntax3.lisp" *grammar*) ("simple.lisp" "syntax2.lisp" *grammar*) ("simple.lisp" "syntax1.lisp" *grammar*) ("simple.lisp" "auxfns.lisp" random-elt) ("compopt.lisp" "mycin-r.lisp" nil) ("eliza1.lisp" "eliza-pm.lisp" use-eliza-rules eliza) ("eliza1.lisp" "patmatch.lisp" segment-match segment-match segment-pattern-p pat-match extend-bindings match-variable pat-match extend-bindings lookup binding-val get-binding fail variable-p) ("eliza1.lisp" "auxfns.lisp" random-elt mappend mklist flatten pat-match extend-bindings match-variable pat-match extend-bindings lookup get-binding fail variable-p) ("eliza1.lisp" "cmacsyma.lisp" variable-p) ("eliza1.lisp" "macsyma.lisp" variable-p) ("syntax3.lisp" "syntax2.lisp" integers 10*n+d infix-funcall extend-parse parse terminal-tree-p apply-semantics lexical-rules *open-categories* parser append1 complete-parses first-or-nil rules-starting-with lexical-rules parse-lhs parse use tree rule *grammar*) ("syntax3.lisp" "syntax1.lisp" extend-parse parse lexical-rules *open-categories* parser append1 complete-parses rules-starting-with lexical-rules parse-lhs parse use rule *grammar*) ("syntax3.lisp" "mycin.lisp" rule) ("syntax3.lisp" "loop.lisp" sum repeat) ("syntax3.lisp" "unifgram.lisp" rule) ("syntax3.lisp" "student.lisp" rule) ("syntax3.lisp" "auxfns.lisp" first-or-nil) ("syntax3.lisp" "cmacsyma.lisp" rule) ("syntax3.lisp" "macsyma.lisp" rule) ("syntax3.lisp" "compile3.lisp" arg2) ("syntax3.lisp" "gps.lisp" use) ("syntax2.lisp" "syntax1.lisp" extend-parse parse *open-categories* use parser append1 complete-parses rules-starting-with lexical-rules parse-lhs parse rule *grammar*) ("syntax2.lisp" "mycin.lisp" rule) ("syntax2.lisp" "unifgram.lisp" rule) ("syntax2.lisp" "student.lisp" rule) ("syntax2.lisp" "auxfns.lisp" first-or-nil) ("syntax2.lisp" "cmacsyma.lisp" rule) ("syntax2.lisp" "macsyma.lisp" rule) ("syntax2.lisp" "gps.lisp" use) ("syntax1.lisp" "mycin.lisp" rule) ("syntax1.lisp" "unifgram.lisp" rule) ("syntax1.lisp" "student.lisp" rule) ("syntax1.lisp" "cmacsyma.lisp" rule) ("syntax1.lisp" "macsyma.lisp" rule) ("syntax1.lisp" "gps.lisp" use) ("prolog1.lisp" "krep2.lisp" show-prolog-vars top-level-prove prove-all prove) ("prolog1.lisp" "prologc.lisp" top-level-prove add-clause <-) ("mycin.lisp" "unifgram.lisp" rule) ("mycin.lisp" "overview.lisp" true) ("mycin.lisp" "student.lisp" rule) ("mycin.lisp" "cmacsyma.lisp" rule) ("mycin.lisp" "macsyma.lisp" rule) ("mycin.lisp" "compile3.lisp" is) ("loop.lisp" "overview.lisp" while) ("patmatch.lisp" "auxfns.lisp" match-variable extend-bindings lookup get-binding variable-p fail pat-match) ("patmatch.lisp" "cmacsyma.lisp" variable-p) ("patmatch.lisp" "macsyma.lisp" variable-p) ("unifgram.lisp" "student.lisp" rule) ("unifgram.lisp" "cmacsyma.lisp" rule) ("unifgram.lisp" "macsyma.lisp" rule) ("krep2.lisp" "krep1.lisp" retrieve mapc-retrieve index) ("krep2.lisp" "krep.lisp" add-fact index) ("krep2.lisp" "prologc.lisp" top-level-prove) ("krep1.lisp" "krep.lisp" dtree-index index) ("prologc2.lisp" "prologc1.lisp" compile-clause compile-predicate proper-listp has-variable-p compile-arg compile-unify = def-prolog-compiler-macro prolog-compiler-macro compile-call compile-body make-= make-predicate make-parameters args relation-arity clauses-with-arity prolog-compile var *var-counter* undo-bindings! set-binding! *trail* print-var set-binding! unify! deref bound-p var unbound) ("prologc2.lisp" "prologc.lisp" bind-unbound-vars maybe-add-undo-bindings compile-clause compile-predicate proper-listp has-variable-p compile-arg compile-unify = def-prolog-compiler-macro prolog-compiler-macro compile-call compile-body make-= make-predicate make-parameters args relation-arity clauses-with-arity prolog-compile var *var-counter* undo-bindings! set-binding! *trail* print-var set-binding! unify! deref bound-p var unbound) ("prologc2.lisp" "compile3.lisp" args) ("prologc1.lisp" "prologc.lisp" proper-listp has-variable-p compile-arg compile-unify = def-prolog-compiler-macro prolog-compiler-macro compile-call compile-body make-= compile-clause make-predicate make-parameters compile-predicate args relation-arity clauses-with-arity prolog-compile var *var-counter* undo-bindings! set-binding! *trail* print-var set-binding! unify! deref bound-p var unbound) ("prologc1.lisp" "compile3.lisp" args) ("overview.lisp" "auxfns.lisp" find-all) ("auxmacs.lisp" "macsyma.lisp" find-anywhere) ("auxmacs.lisp" "gps.lisp" starts-with) ("student.lisp" "cmacsyma.lisp" prefix->infix binary-exp-p exp-args exp-p exp rule) ("student.lisp" "macsyma.lisp" prefix->infix binary-exp-p exp-args exp-p exp rule) ("auxfns.lisp" "interp1.lisp" delay delay) ("auxfns.lisp" "cmacsyma.lisp" variable-p) ("auxfns.lisp" "macsyma.lisp" variable-p partition-if) ("auxfns.lisp" "gps.lisp" member-equal) ("prologc.lisp" "compile3.lisp" args) ("gps1.lisp" "gps.lisp" apply-op appropriate-p achieve gps op *ops*) ("interp3.lisp" "interp2.lisp" interp) ("interp3.lisp" "interp1.lisp" init-scheme-proc scheme interp) ("interp3.lisp" "compile3.lisp" scheme) ("interp2.lisp" "interp1.lisp" interp) ("interp1.lisp" "compile3.lisp" scheme) ("interp1.lisp" "compile1.lisp" define) ("cmacsyma.lisp" "macsyma.lisp" prefix->infix *infix->prefix-rules* variable-p infix->prefix binary-exp-p exp-args exp-p exp rule) ("compile3.lisp" "compile2.lisp" *primitive-fns* optymize init-scheme-comp assemble) ("compile3.lisp" "compile1.lisp" show-fn) ("compile2.lisp" "compile1.lisp" comp-lambda gen-set comp-if comp-begin comp) ) ;;;; norvig-graph.lisp -- 2003-05-16 07:11:44 -- pascal ;;;;
12,774
Common Lisp
.lisp
283
39.162544
83
0.634336
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
8846e0a5f047e2b6ca78ce89f90ce65564fd5f60065778ededbd9829c30caaa8
4,929
[ -1 ]
4,930
norvig.lisp
informatimago_lisp/cl-loaders/norvig.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: norvig.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: - ;;;;USER-INTERFACE: - ;;;;DESCRIPTION ;;;; ;;;; Loader for Norvig's code. ;;;; ;;;; ;;;; wget ftp://www.informatimago.com/pub/lisp/norvig-paip-pjb.tar.gz ;;;; tar zxvf norvig-paip-pjb.tar.gz ;;;; wget http://norvig.com/paip/paip.zip ;;;; mkdir norvig ;;;; cd norvig ;;;; unzip -x ../paip.zip ;;;; patch -p1 < ../norvig-paip-pjb.patch ;;;; pwd ;;;; clisp -ansi -q norc ;;;; ;; replace /home/… in the following strings by the current ;;;; ;; directory printed by the above pwd command. ;;;; (setf (logical-pathname-translations "NORVIG") ;;;; `(("NORVIG:**;*.*" "/home/…/norvig/**/*.*") ;;;; ("NORVIG:**;*.*.*" "/home/…/norvig/**/*.*"))) ;;;; (load #P"../norvig-paip-pjb.lisp") ;;;; ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon ;;;;MODIFICATIONS ;;;; 2012-06-20 <PJB> Made some corrections, added instructions. ;;;; 2003-05-14 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2003 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.NORVIG" (:use "COMMON-LISP") (:shadow "EXP")) (in-package "COM.NORVIG") (defparameter configuration '(gps-search elisa-pm prolog-cp krep syntax-3 scheme-3 scheme-c3)) (defmacro exclusive (&rest e-b) (let ((etiquettes (mapcar (function car) e-b)) (rep (gensym "REP"))) `(let ((,rep (intersection configuration ',etiquettes))) (if (= 1 (length ,rep)) (progn (setq ,rep (car ,rep)) (format t "~&CONFIGURED: ~A~%" ,rep)) (setq ,rep (do ((,rep nil)) (,rep ,rep) (format *query-io* "~&Please choose what to load from ~S: " ',etiquettes) (setq ,rep (read *query-io*)) (unless (member ,rep ',etiquettes) (setq ,rep nil))))) (case ,rep ,@e-b)))) (defparameter *paip-source-files* (translate-logical-pathname (make-pathname :host "NORVIG" :directory '(:absolute) :name nil :type "LISP" :case :common)) "The location of the source files for this book. CHANGE IT TO REFLECT THE LOCATION OF THE FILES ON YOUR COMPUTER.") (load "norvig:intro.lisp") ;; A few simple definitions (load "norvig:simple.lisp") ;; Random sentence generator (two versions) (load "norvig:overview.lisp") ;; 14 versions of LENGTH and other examples (load "norvig:auxmacs.lisp") ;; A few macros; load this first. (unless (fboundp 'common-lisp:loop) (load "norvig:loop.lisp")) ;; Load if your Lisp doesn't support ANSI LOOP (load "norvig:auxfns.lisp") ;; Commonly used auxiliary functions. (load "norvig:search.lisp") ;; Search Utility ;; "norvig:search.dat" ;; Test data (examples) for above (exclusive (gps-simple (load "norvig:gps1.lisp") ;; Simple version of General Problem Solver ;; "norvig:gps1.dat" ;; Test data (examples) for above ) (gps (load "norvig:gps1.lisp") ;; Simple version of General Problem Solver (load "norvig:gps.lisp") ;; Final version of General Problem Solver ;; "norvig:gps.dat" ;; Test data (examples) for above ) (gps-search (load "norvig:gps1.lisp") ;; Simple version of General Problem Solver (load "norvig:gps.lisp") ;; Final version of General Problem Solver (load "norvig:gps-srch.lisp") ;; Version of GPS using the search utility ;; "norvig:gps-srch.dat" ;; Test data (examples) for above )) (load "norvig:patmatch.lisp") ;; Pattern Matching Utility ;; "norvig:patmatch.dat" ;; Test data (examples) for above (exclusive (elisa-basic (load "norvig:eliza1.lisp") ;; Basic version of Eliza program ) (elisa (load "norvig:eliza.lisp") ;; Eliza with more rules; different reader ) (elisa-pm (load "norvig:eliza-pm.lisp") ;; Version of Eliza using utilities (load "norvig:cmacsyma.lisp") ;; Efficient Macsyma with canonical form ;; "norvig:cmacsyma.dat" ;; Test data (examples) for above )) (load "norvig:eliza1.lisp") ;; Needed by The Student Program (load "norvig:student.lisp") ;; The Student Program ;; "norvig:student.dat" ;; Test data (examples) for above (load "norvig:macsyma.lisp") ;; The Macsyma Program (load "norvig:macsymar.lisp") ;; Simplification & integration rules for Macsyma ;; "norvig:macsyma.dat" ;; Test data (examples) for above (load "norvig:unify.lisp") ;; Unification functions (exclusive (prolog1 (load "norvig:prolog1.lisp") ;; First version of Prolog interpreter ;; "norvig:prolog1.dat" ;; Test data (examples) for above ) (prolog (load "norvig:prolog.lisp") ;; Final version of Prolog interpreter ;; "norvig:prolog.dat" ;; Test data (examples) for above ) (prolog-c1 (load "norvig:prologc1.lisp") ;; First version of Prolog compiler ;; "norvig:prologc1.dat" ;; Test data (examples) for above ) (prolog-c2 (load "norvig:prologc2.lisp") ;; Second version of Prolog compiler ;; "norvig:prologc2.dat" ;; Test data (examples) for above ) (prolog-c (load "norvig:prologc.lisp") ;; Final version of Prolog compiler ;; "norvig:prologc.dat" ;; Test data (examples) for above ) (prolog-cp ;;(LOAD "norvig:prologcp.lisp") ;; Primitives for Prolog compiler ;;(LOAD "norvig:unifgram.lisp") ;; Unification Parser ;; "norvig:unifgram.dat" ;; Test data (examples) for above ;;(LOAD "norvig:lexicon.lisp") ;; Sample Lexicon of English ;; "norvig:grammar.dat" ;; Test data (examples) for above (load "norvig:grammar.lisp") ;; Comprehensive grammar of English )) (load "norvig:clos.lisp") ;; Some object-oriented and CLOS code ;; "norvig:clos.dat" ;; Test data (examples) for above (exclusive (krep-1 (load "norvig:krep1.lisp") ;; Knowledge Representation code: first version ;; "norvig:krep1.dat" ;; Test data (examples) for above ) (krep-2 (load "norvig:krep2.lisp") ;; Knowledge Representation code w/ conjunctions ) (krep (load "norvig:krep.lisp") ;; Final KR code: worlds and attached functions )) (load "norvig:mycin.lisp") ;; The Emycin expert system shell (load "norvig:mycin-r.lisp") ;; Some rules for a medical application of emycin ;; "norvig:mycin.dat" ;; Test data (examples) for above (load "norvig:waltz.lisp") ;; A Line-Labeling program using Waltz algorithm ;; "norvig:waltz.dat" ;; Test data (examples) for above ;; (LOAD "norvig:othello.lisp") ;; The Othello playing program & strategies ;; "norvig:othello.dat" ;; Test data (examples) for above (load "norvig:othello2.lisp") ;; Additional strategies for Othello (load "norvig:edge-tab.lisp") ;; Edge table for Iago strategy (exclusive (syntax-1 (load "norvig:syntax1.lisp") ;; Syntactic Parser ;; "norvig:syntax1.dat" ;; Test data (examples) for above ) (syntax-2 (load "norvig:syntax2.lisp") ;; Syntactic Parser with semantics ;; "norvig:syntax2.dat" ;; Test data (examples) for above ) (syntax-3 (load "norvig:syntax3.lisp") ;; Syntactic Parser with semantics and pref. ;; "norvig:syntax3.dat" ;; Test data (examples) for above )) (exclusive (scheme-1 (load "norvig:interp1.lisp") ;; Scheme interpreter, incl. version with macros ;; "norvig:interp1.dat" ;; Test data (examples) for above ) (scheme-2 (load "norvig:interp1.lisp") ;; Scheme interpreter, incl. version with macros (load "norvig:interp2.lisp") ;; A tail recurive Scheme interpreter ) (scheme-3 (load "norvig:interp1.lisp") ;; Scheme interpreter, incl. version with macros (load "norvig:interp3.lisp") ;; A Scheme interpreter that handles call/cc ;; "norvig:interp3.dat" ;; Test data (examples) for above )) (exclusive (scheme-c1 (load "norvig:compile1.lisp") ;; Simple Scheme compiler ) (scheme-c2 (load "norvig:compile2.lisp") ;; Compiler with tail recursion and primitives ) (scheme-c3 (load "norvig:compile3.lisp") ;; Compiler with peephole optimizer (load "norvig:compopt.lisp") ;; Peephole optimizers for compile3.lisp ;; "norvig:compile.dat" ;; Test data (examples) for all 3 versions above )) #| 4 gps1.lisp Simple version of General Problem Solver 4 gps1.dat Test data (examples) for above 4 gps.lisp Final version of General Problem Solver 4 gps.dat Test data (examples) for above 5 eliza1.lisp Basic version of Eliza program 5 eliza.lisp Eliza with more rules; different reader 6 patmatch.lisp Pattern Matching Utility 6 patmatch.dat Test data (examples) for above 6 eliza-pm.lisp Version of Eliza using utilities 6 search.lisp Search Utility 6 search.dat Test data (examples) for above 6 gps-srch.lisp Version of GPS using the search utility 6 gps-srch.dat Test data (examples) for above 7 student.lisp The Student Program 7 student.dat Test data (examples) for above 8 macsyma.lisp The Macsyma Program 8 macsymar.lisp Simplification and integration rules for Macsyma 8 macsyma.dat Test data (examples) for above 9-10 <no files; important functions in auxfns.lisp> 11 unify.lisp Unification functions 11 prolog1.lisp First version of Prolog interpreter 11 prolog1.dat Test data (examples) for above 11 prolog.lisp Final version of Prolog interpreter 11 prolog.dat Test data (examples) for above 12 prologc1.lisp First version of Prolog compiler 12 prologc1.dat Test data (examples) for above 12 prologc2.lisp Second version of Prolog compiler 12 prologc2.dat Test data (examples) for above 12 prologc.lisp Final version of Prolog compiler 12 prologc.dat Test data (examples) for above 12 prologcp.lisp Primitives for Prolog compiler 13 clos.lisp Some object-oriented and CLOS code 13 clos.dat Test data (examples) for above 14 krep1.lisp Knowledge Representation code: first version 14 krep1.dat Test data (examples) for above 14 krep2.lisp Knowledge Representation code with conjunctions 14 krep.lisp Final KR code: worlds and attached functions 15 cmacsyma.lisp Efficient Macsyma with canonical form 15 cmacsyma.dat Test data (examples) for above 16 mycin.lisp The Emycin expert system shell 16 mycin-r.lisp Some rules for a medical application of emycin 16 mycin.dat Test data (examples) for above 17 waltz.lisp A Line-Labeling program using the Waltz algorithm 17 waltz.dat Test data (examples) for above 18 othello.lisp The Othello playing program and some strategies 18 othello.dat Test data (examples) for above 18 othello2.lisp Additional strategies for Othello 18 edge-tab.lisp Edge table for Iago strategy 19 syntax1.lisp Syntactic Parser 19 syntax1.dat Test data (examples) for above 19 syntax2.lisp Syntactic Parser with semantics 19 syntax2.dat Test data (examples) for above 19 syntax3.lisp Syntactic Parser with semantics and preferences 19 syntax3.dat Test data (examples) for above 20 unifgram.lisp Unification Parser 20 unifgram.dat Test data (examples) for above 21 grammar.lisp Comprehensive grammar of English 21 lexicon.lisp Sample Lexicon of English 21 grammar.dat Test data (examples) for above 22 interp1.lisp Scheme interpreter, including version with macros 22 interp1.dat Test data (examples) for above 22 interp2.lisp A tail recurive Scheme interpreter 22 interp3.lisp A Scheme interpreter that handles call/cc 22 interp3.dat Test data (examples) for above 23 compile1.lisp Simple Scheme compiler 23 compile2.lisp Compiler with tail recursion and primitives 23 compile3.lisp Compiler with peephole optimizer 23 compopt.lisp Peephole optimizers for compile3.lisp 23 compile.dat Test data (examples) for all 3 versions above |# ;;; (position C-h C-f ;;; Describe function (default position): ;;; (position C-c M-h ;;; --> jumps directly to the Hyperspec page. ;;;; norvig.lisp -- 2003-05-16 07:54:59 -- pascal ;;;;
13,561
Common Lisp
.lisp
298
42.459732
83
0.657466
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
a0af4c8b1813b59df9c6df519d909812c75b6841282a0843f4af4d5c843365e6
4,930
[ -1 ]
4,931
old-asdf.lisp
informatimago_lisp/cl-loaders/old-asdf.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: asdf.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Loads ASDF. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2005-01-21 <PJB> Added scanning of PACKAGES: for ASD files. ;;;; 2003-06-05 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2003 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COMMON-LISP-USER") (load "CCLAN:ASDF;ASDF.LISP") (load "CCLAN:CCLAN-GET;PACKAGE.LISP") (load "CCLAN:CCLAN-GET;CCLAN-GET.ASD") (handler-case (asdf:operate 'asdf:load-op :cclan-get) (error () (asdf:operate 'asdf:compile-op :cclan-get))) (in-package "COM.INFORMATIMAGO.PJB") (defparameter *original-asdf-registry* asdf:*central-registry*) (setf cclan-get::*cclan-tarball-directory* "SHARE-LISP:CCLAN;TARBALL;" cclan-get::*cclan-source-directory* "SHARE-LISP:CCLAN;SOURCE;" cclan-get::*cclan-asdf-registry* "SHARE-LISP:CCLAN;REGISTRY;") (defun asdf-rescan-packages () (format *trace-output* "~&;; Scanning ASDF packages...~%") (prog1 (sort (delete-duplicates (mapcar (lambda (p) (make-pathname :name nil :type nil :version nil :defaults p)) (directory "PACKAGES:**;*.ASD")) :test (function equal)) (lambda (a b) (if (= (length a) (length b)) (string< a b) (< (length a) (length b)))) :key (function namestring)) (format *trace-output* "~&;; Done.~%"))) (defun update-asdf-registry () (setf asdf:*central-registry* (nconc (asdf-rescan-packages) (list cclan-get::*cclan-asdf-registry*) *original-asdf-registry*))) (export 'update-asdf-registry) (update-asdf-registry) (in-package "COMMON-LISP-USER") (asdf:operate 'asdf:load-op :asdf-install) (format t "~2%Push on ASDF:*CENTRAL-REGISTRY* directories where .asd files are ~ to be found.~@ Use: (asdf:operate 'asdf:load-op ,system-name)~@ ~& (asdf-install:install ,system-name)~@ ~2%") ;;;; asdf.lisp -- -- ;;;;
3,204
Common Lisp
.lisp
77
38.064935
83
0.599679
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
943c465e68825f5c311978dfe94de9779456828b92e29128ada0ababa9ae4f35
4,931
[ -1 ]
4,932
hemlock.lisp
informatimago_lisp/cl-loaders/hemlock.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: hemlock.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Loads Portable Hemlock. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2004-07-29 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2004 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (load "loaders:clocc") (pushnew "/local/share/lisp/packages/net/common-lisp/phemlock" ;;"/usr/local/share/lisp/packages/org/dyndns/bauhh/hemlock/hemlock/" mk:*central-registry*) (mk:oos :hemlock :load)
1,644
Common Lisp
.lisp
40
39.55
83
0.599875
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
fa913b511f904878fb53351ece1235e7ebe76dcb2c9ca88958b287032eb9ee66
4,932
[ -1 ]
4,933
portableaserve.lisp
informatimago_lisp/cl-loaders/portableaserve.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: portableaserve.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Loader for portableaserve. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2003-05-30 <PJB> Created. ;; ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2003 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (load "package:portableaserve;logical-hostnames.lisp") (load "package:portableaserve;acl-compat;acl-compat-clisp.system") (def-lp-trans "ACL-COMPAT" +share-lisp+ "portableaserve/acl-compat/") (ext:without-package-lock () (mk:oos "ACL-COMPAT" :load :compile-during-load t)) (load "aserve:aserve.system") (mk:oos "ASERVE" :load :compile-during-load t) (defpackage :aserve-example) (defun aserve-example (&optional (port 2001)) (load "aserve:example.cl") ;; This option enables extended debug message output (net.aserve::debug-on :info) ;; This option enables to enter the debugger if an error ;; occurs. (instead of simply logging and ignoring it) (net.aserve::debug-on :notrap) ;; Start example server on port 2001 (aserve-example::start-simple-server :port port) );;aserve-example ;;;; portableaserve.lisp -- 2003-05-31 04:02:00 -- pascal ;;;;
2,317
Common Lisp
.lisp
55
40.672727
83
0.639221
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
bdf2c5a40b12e7acc9955a6f79ccb3383098865fe3afc56196c483bb4201fd02
4,933
[ -1 ]
4,934
pjb.lisp
informatimago_lisp/cl-loaders/pjb.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: pjb.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Loader for my packages. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2003-06-15 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2003 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (dolist (package '( com.informatimago.common-lisp.compatibility com.informatimago.common-lisp.dfa com.informatimago.common-lisp.dictionary ;; COM.INFORMATIMAGO.COMMON-LISP.GRAPH-DIAGRAM ;; COM.INFORMATIMAGO.COMMON-LISP.GRAPH-DOT com.informatimago.common-lisp.graph ;; collision with MAP: COM.INFORMATIMAGO.COMMON-LISP.HTML com.informatimago.common-lisp.list com.informatimago.common-lisp.make-depends com.informatimago.common-lisp.picture com.informatimago.common-lisp.string com.informatimago.common-lisp.tree-to-diagram com.informatimago.common-lisp.tree-to-ascii com.informatimago.common-lisp.utility )) (in-package "COMMON-LISP-USER") (com.informatimago.common-lisp.package:load-package package) (in-package "COMMON-LISP-USER") ;; (USE-PACKAGE PACKAGE) ) ;;;; pjb.lisp -- 2003-06-15 21:55:45 -- pascal ;;;;
2,390
Common Lisp
.lisp
58
37.844828
83
0.624248
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
0bfdd47da8bb1454a4da6bb483f7f540e38d160ecfa85c96f80c14f12ea38ee0
4,934
[ -1 ]
4,935
asdf.lisp
informatimago_lisp/cl-loaders/asdf.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: asdf.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Loads ASDF. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2005-05-05 <PJB> Merged changes. ;;;; 2005-01-21 <PJB> Added scanning of PACKAGES: for ASD files. ;;;; 2003-06-05 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2003 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COMMON-LISP-USER") ;; (LOAD "CCLAN:ASDF;ASDF.LISP") ;; (LOAD "CCLAN:CCLAN-GET;PACKAGE.LISP") ;; (LOAD "CCLAN:CCLAN-GET;CCLAN-GET.ASD") ;; (handler-case (ASDF:OPERATE 'ASDF:load-OP :CCLAN-GET) ;; (error () (ASDF:OPERATE 'ASDF:compile-OP :CCLAN-GET))) (load "PACKAGES:NET;SOURCEFORGE;CCLAN;ASDF;ASDF.LISP") ;;(LOAD "PACKAGES:NET;SOURCEFORGE;CCLAN;ASDF;ASDF-INSTALL.LISP") (in-package "COM.INFORMATIMAGO.PJB") (defparameter *original-asdf-registry* asdf:*central-registry*) (defun asdf-rescan-packages () (when *load-verbose* (format *trace-output* "~&;; Scanning ASDF packages...~%")) (prog1 (sort (delete-duplicates (mapcar (lambda (p) (make-pathname :name nil :type nil :version nil :defaults p)) (directory "PACKAGES:**;*.ASD")) :test (function equal)) (lambda (a b) (if (= (length a) (length b)) (string< a b) (< (length a) (length b)))) :key (function namestring)) (when *load-verbose* (format *trace-output* "~&;; Done.~%")))) (defun update-asdf-registry () (setf asdf:*central-registry* (nconc (asdf-rescan-packages) ;;(list CCLAN-GET::*CCLAN-ASDF-REGISTRY*) *original-asdf-registry*))) (export 'update-asdf-registry) (update-asdf-registry) (in-package "COMMON-LISP-USER") (asdf:operate 'asdf:load-op :asdf-install) (format t "~2%Push on ASDF:*CENTRAL-REGISTRY* directories where .asd files are ~ to be found.~@ Use: (asdf:operate 'asdf:load-op ,system-name)~@ ~& (asdf-install:install ,system-name)~@ ~2%") ;;;; asdf.lisp -- -- ;;;;
3,220
Common Lisp
.lisp
79
37.35443
83
0.596357
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
31c59ef274693874444a0146ec6370654ecbb41565923b3387632b446ac553ac
4,935
[ -1 ]
4,936
lisa.lisp
informatimago_lisp/cl-loaders/lisa.lisp
;;;; -*- coding:utf-8 -*- (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (unless (find-package "ASDF") (load "LOADER:ASDF")) (pushnew "PACKAGES:NET;SOURCEFORGE;LISA;LISA;" asdf::*central-registry*) (asdf:oos 'asdf:load-op :lisa) ;;;; clocc.lisp -- -- ;;;;
360
Common Lisp
.lisp
7
49.857143
77
0.575499
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
f808739ee16cf35db0b61d41708ea67e7f18fe6a5dc1d12948830b4b093c45c9
4,936
[ -1 ]
4,937
objcl-test.lisp
informatimago_lisp/objcl/objcl-test.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: objcl-test.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Tests the objcl reader macro parser functions. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-12-14 <PJB> Created. ;;;;BUGS ;;;; Should add more tests for error cases. ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST" (:nicknames "COM.INFORMATIMAGO.OBJCL.TEST") (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.SIMPLE-TEST" "COM.INFORMATIMAGO.OBJECTIVE-CL") (:import-from "COM.INFORMATIMAGO.OBJECTIVE-CL" "*OBJC-READTABLE*" "READ-TYPE-SPECIFIER" "READ-METHOD-SIGNATURE" "READ-FINAL-ARGUMENTS" "READ-MESSAGE" "READ-IDENTIFIER" "GENERATE-MESSAGE-SEND" "READ-MESSAGE-SEND") (:export "TEST/ALL")) (in-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST") (eval-when (:compile-toplevel :load-toplevel :execute) (setf *read-default-float-format* 'double-float)) ;; When reading expressions in the tests, we need to set the package ;; to ensure the symbols are read in the expected package. (defmacro with-string-check ((readtable stream string) &body body) `(with-input-from-string (,stream ,string) (let ((*readtable* ,readtable) (*read-default-float-format* 'double-float)) (locally ,@body)))) (define-test test/read-identifier () (let ((*package* (find-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST"))) (check string= (with-string-check (*objc-readtable* stream "hello42World:") (read-identifier stream)) "hello42World"))) (define-test test/read-type-specifier () " type-specifier :='(' type-identifier ')' . " (let ((*package* (find-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST"))) (check equal (with-string-check (*objc-readtable* stream "(int)arg") (read-type-specifier stream)) :int))) (define-test test/read-method-signature () " signature := simple-signature | compound-signature final-signature . simple-signature := objcl-identifier . compound-signature := [objcl-identifier] ':' '(' type-identifier ')' objcl-identifier compound-signature | [objcl-identifier] ':' '(' type-identifier ')' objcl-identifier . " (let ((*package* (find-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST"))) (check equal (with-string-check (*objc-readtable* stream "simpleSelector)") (read-method-signature stream)) '("simpleSelector" nil nil)) (check equal (with-string-check (*objc-readtable* stream "singleArgComplexSelector:(int)arg)") (read-method-signature stream)) '("singleArgComplexSelector:" ((:int arg)) nil)) (check equal (with-string-check (*objc-readtable* stream "multipleArg:(int)arg1 complexSelector:(int)arg2)") (read-method-signature stream)) '("multipleArg:complexSelector:" ((:int arg1) (:int arg2)) nil)) (check equal (with-string-check (*objc-readtable* stream "multipleArgWithEmptyPart:(int)arg1 :(int)arg2)") (read-method-signature stream)) '("multipleArgWithEmptyPart::" ((:int arg1) (:int arg2)) nil)) (check equal (with-string-check (*objc-readtable* stream "singleArgComplexSelector:(int)arg &rest others)") (read-method-signature stream)) '("singleArgComplexSelector:" ((:int arg)) others)) (check equal (with-string-check (*objc-readtable* stream "multipleArg:(int)arg1 complexSelector:(int)arg2 &rest others)") (read-method-signature stream)) '("multipleArg:complexSelector:" ((:int arg1) (:int arg2)) others)) (check equal (with-string-check (*objc-readtable* stream "multipleArgWithEmptyPart:(int)arg1 :(int)arg2 &rest others)") (read-method-signature stream)) '("multipleArgWithEmptyPart::" ((:int arg1) (:int arg2)) others)))) (define-test test/read-final-arguments () " final-arguments := | '(' type-identifier ')' objcl-expression final-arguments . type-identifier := symbol . " (let ((*package* (find-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST"))) (check equal (with-string-check (*objc-readtable* stream "]") (read-final-arguments stream)) '()) (check equal (with-string-check (*objc-readtable* stream "(integer)(+ one 2)]") (read-final-arguments stream)) '((:integer (+ one 2)))) (check equal (with-string-check (*objc-readtable* stream "(integer)(+ 1 2) (float)(+ 1.0 2.0)]") (read-final-arguments stream)) '((:integer (+ 1 2)) (:float (+ 1.0d0 2.0d0)))) (check eql (handler-case (progn (with-string-check (*objc-readtable* stream "(integer)(+ 1 2) (float)]") (read-final-arguments stream)) nil) (error () :success)) :success))) (define-test test/read-message () " message := simple-selector | compound-selector final-arguments . simple-selector := objcl-identifier . compound-selector := [objcl-identifier] ':' objcl-expression compound-selector | [objcl-identifier] ':' objcl-expression . " (let ((*package* (find-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST"))) (check equal (with-string-check (*objc-readtable* stream "simpleSelector]") (read-message stream)) '("simpleSelector" nil nil)) (check equal (with-string-check (*objc-readtable* stream "singleArgComplexSelector:42]") (read-message stream)) '("singleArgComplexSelector:" (42) nil)) (check equal (with-string-check (*objc-readtable* stream "multipleArg:42 complexSelector:24]") (read-message stream)) '("multipleArg:complexSelector:" (42 24) nil)) (check equal (with-string-check (*objc-readtable* stream "multipleArg:(+ 4 2) complexSelector:(* 2 4)]") (read-message stream)) '("multipleArg:complexSelector:" ((+ 4 2) (* 2 4)) nil)) (check equal (with-string-check (*objc-readtable* stream "multipleArg:[self one] complexSelector:[self two]]") (read-message stream)) `("multipleArg:complexSelector:" (,(generate-message-send 'self '"one" 'nil 'nil) ,(generate-message-send 'self '"two" 'nil 'nil)) nil)) (check equal (with-string-check (*objc-readtable* stream "multipleArgWithEmptyPart:42 :24]") (read-message stream)) '("multipleArgWithEmptyPart::" (42 24) nil)) (check equal (with-string-check (*objc-readtable* stream "singleArgComplexSelectorWithFinalArgs:42 (int)1]") (read-message stream)) '("singleArgComplexSelectorWithFinalArgs:" (42) ((:int 1)))) (check equal (with-string-check (*objc-readtable* stream "multipleArg:42 complexSelectorWithFinalArgs:24 (int)1 (float)2.0]") (read-message stream)) '("multipleArg:complexSelectorWithFinalArgs:" (42 24) ((:int 1) (:float 2.0d0)))))) (define-test test/read-message-send () (let ((*package* (find-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST"))) (check equal (with-string-check (*objc-readtable* stream "simpleSelector]") (read-message-send stream 'self (function read-message))) '(self "simpleSelector" nil nil)) (check equal (with-string-check (*objc-readtable* stream "singleArgComplexSelector:42]") (read-message-send stream 'self (function read-message))) '(self "singleArgComplexSelector:" (42) nil)) (check equal (with-string-check (*objc-readtable* stream "multipleArg:42 complexSelector:24]") (read-message-send stream 'self (function read-message))) '(self "multipleArg:complexSelector:" (42 24) nil)) (check equal (with-string-check (*objc-readtable* stream "multipleArg:(+ 4 2) complexSelector:(* 2 4)]") (read-message-send stream 'self (function read-message))) '(self "multipleArg:complexSelector:" ((+ 4 2) (* 2 4)) nil)) (check equal (with-string-check (*objc-readtable* stream "multipleArg:[self one] complexSelector:[self two]]") (read-message-send stream 'self (function read-message))) `(self "multipleArg:complexSelector:" (,(generate-message-send 'self '"one" 'nil 'nil) ,(generate-message-send 'self '"two" 'nil 'nil)) nil)) (check equal (with-string-check (*objc-readtable* stream "multipleArgWithEmptyPart:42 :24]") (read-message-send stream 'self (function read-message))) '(self "multipleArgWithEmptyPart::" (42 24) nil)) (check equal (with-string-check (*objc-readtable* stream "singleArgComplexSelectorWithFinalArgs:42 (int)1]") (read-message-send stream 'self (function read-message))) '(self "singleArgComplexSelectorWithFinalArgs:" (42) ((:int 1)))) (check equal (with-string-check (*objc-readtable* stream "multipleArg:42 complexSelectorWithFinalArgs:24 (int)1 (float)2.0]") (read-message-send stream 'self (function read-message))) '(self "multipleArg:complexSelectorWithFinalArgs:" (42 24) ((:int 1) (:float 2.0d0)))))) (define-test test/message-send () (let ((*package* (find-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST"))) (flet ((gen (args) (apply (function generate-message-send) args))) (declare (inline gen)) (check equal (gen '(self "simpleSelector" nil nil)) '(oclo:send self 'simple-selector)) (check equal (gen '(self "singleArgComplexSelector:" (42) nil)) '(oclo:send self :single-arg-complex-selector 42)) (check equal (gen '(self "multipleArg:complexSelector:" (42 24) nil)) '(oclo:send self :multiple-arg 42 :complex-selector 24)) (check equal (gen '(self "multipleArg:complexSelector:" ((+ 4 2) (* 2 4)) nil)) '(oclo:send self :multiple-arg (+ 4 2) :complex-selector (* 2 4))) (check equal (gen `(self "multipleArg:complexSelector:" (,(generate-message-send 'self '"one" 'nil 'nil) ,(generate-message-send 'self '"two" 'nil 'nil)) nil)) '(oclo:send self :multiple-arg (oclo:send self 'one) :complex-selector (oclo:send self 'two))) (check equal (gen '(self "multipleArgWithEmptyPart::" (42 24) nil)) '(oclo:send self :multiple-arg-with-empty-part 42 :|| 24)) (check equal (gen '(self "singleArgComplexSelectorWithFinalArgs:" (42) ((:int 1)))) '(oclo:send self :single-arg-complex-selector-with-final-args 42 (:int 1))) (check equal (gen '(self "multipleArg:complexSelectorWithFinalArgs:" (42 24) ((:int 1) (:float 2.0d0)))) '(oclo:send self :multiple-arg 42 :complex-selector-with-final-args 24 (:int 1 :float 2.0d0)))))) (define-test test/read-objcl-message-send () (let ((*package* (find-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST"))) (flet ((read-objc (source) (let ((*readtable* *objective-cl-readtable*)) (read-from-string source)))) (declare (inline read-objc)) (check equal (read-objc "[self simpleSelector]") '(oclo:send self 'simple-selector)) (check equal (read-objc "[[NSData alloc] init]") '(oclo:send (oclo:send ns:ns-data 'alloc) 'init)) (check equal (read-objc "[[my-obj doSomething] doSomethingElse]") '(oclo:send (oclo:send my-obj 'do-something) 'do-something-else)) (check equal (read-objc "[self singleArgComplexSelector:42]") '(oclo:send self :single-arg-complex-selector 42)) (check equal (read-objc "[self singleArgComplexSelector:(+ 4 2)]") '(oclo:send self :single-arg-complex-selector (+ 4 2))) (check equal (read-objc "[self singleArgComplexSelector:(+ 4 XYZ)]") '(oclo:send self :single-arg-complex-selector (+ 4 xyz))) (check equal (read-objc "[self singleArgComplexSelector:abc]") '(oclo:send self :single-arg-complex-selector abc)) (check equal (read-objc "[self multipleArg:42 complexSelector:24]") '(oclo:send self :multiple-arg 42 :complex-selector 24)) (check equal (read-objc "[self multipleArg: (+ 4 2) complexSelector: (* 2 4) ]") '(oclo:send self :multiple-arg (+ 4 2) :complex-selector (* 2 4))) (check equal (read-objc "[self multipleArg:[self one]complexSelector:[self two]]") '(oclo:send self :multiple-arg (oclo:send self 'one) :complex-selector (oclo:send self 'two))) (check equal (read-objc "[self multipleArg:[self one] complexSelector:[self two]]") '(oclo:send self :multiple-arg (oclo:send self 'one) :complex-selector (oclo:send self 'two))) (check equal (read-objc "[self multipleArg: [self one] complexSelector: [self two] ]") '(oclo:send self :multiple-arg (oclo:send self 'one) :complex-selector (oclo:send self 'two))) (check equal (read-objc "[self multipleArgWithEmptyPart:42 :24]") '(oclo:send self :multiple-arg-with-empty-part 42 :|| 24)) (check equal (read-objc "[self multipleArgWithEmptyPart:42 : 24 ]") '(oclo:send self :multiple-arg-with-empty-part 42 :|| 24)) (check equal (read-objc "[self multipleArgWithEmptyPart:ABC :DEF]") '(oclo:send self :multiple-arg-with-empty-part abc :|| def)) (check equal (read-objc "[self singleArgComplexSelectorWithFinalArgs:42 (:int)1]") '(oclo:send self :single-arg-complex-selector-with-final-args 42 (:int 1))) (check equal (read-objc "[self singleArgComplexSelectorWithFinalArgs:42(:int) 1 ]") '(oclo:send self :single-arg-complex-selector-with-final-args 42 (:int 1))) (check equal (read-objc "[self multipleArg:42 complexSelectorWithFinalArgs:24 (:int)1 (:float)2.0]") '(oclo:send self :multiple-arg 42 :complex-selector-with-final-args 24 (:int 1 :float 2.0d0))) (check equal (read-objc "(progn [self simpleSelector] [self multipleArg:42 complexSelector:24])") '(progn (oclo:send self 'simple-selector) (oclo:send self :multiple-arg 42 :complex-selector 24)))))) (define-test test/read-objcl-class-definition () (let ((*package* (find-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST"))) (flet ((read-objc (source) (let ((*readtable* *objective-cl-readtable*)) (read-from-string source)))) (declare (inline read-objc)) (check equal (read-objc "@[NSObject subClass:Example slots:( one two three)]") '(defclass example (ns:ns-object) (one two three) (:metaclass ns:+ns-object)))))) (defun equal-modulo-constant-strings (a b) (cond ((typep a 'ns:ns-string) (and (consp b) (eql '\@ (car b)))) ((and (consp a) (consp b)) (and (equal-modulo-constant-strings (car a) (car b)) (equal-modulo-constant-strings (cdr a) (cdr b)))) (t (equal a b)))) (define-test test/read-objcl-class-method-definition () (let ((*package* (find-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST"))) (flet ((read-objc (source) (let ((*readtable* *objective-cl-readtable*)) (read-from-string source)))) (declare (inline read-objc)) (check equal-modulo-constant-strings (read-objc "@[Example classMethod:(multipleArg:(:int)a complexSelector:(:int)b) resultType:(:id) body: (ns-log @\"Example %d %d\" a b) [[NSNumber alloc]initWithInteger:(+ a b)]]") '(oclo:define-objc-class-method ((:id :multiple-arg (:int a) :complex-selector (:int b)) example) (ns-log (\@ "Example %d %d") a b) (oclo:send (oclo:send ns:ns-number 'alloc) :init-with-integer (+ a b))))))) (define-test test/read-objcl-instance-method-definition () (let ((*package* (find-package "COM.INFORMATIMAGO.OBJECTIVE-CL.TEST"))) (flet ((read-objc (source) (let ((*readtable* *objective-cl-readtable*)) (read-from-string source)))) (declare (inline read-objc)) (check equal-modulo-constant-strings (read-objc "@[Example method:(multipleArg:(:int)a complexSelector:(:int)b) resultType:(:id) body: (ns-log @\"Example %d %d\" a b) [[NSNumber alloc]initWithInteger:(+ a b)]]") '(oclo:define-objc-method ((:id :multiple-arg (:int a) :complex-selector (:int b)) example) (ns-log (\@ "Example %d %d") a b) (oclo:send (oclo:send ns:ns-number 'alloc) :init-with-integer (+ a b))))))) (define-test test/all () (test/read-identifier) (test/read-type-specifier) (test/read-method-signature) (test/read-final-arguments) (test/read-message) (test/read-message-send) (test/message-send) (test/read-objcl-class-definition) (test/read-objcl-class-method-definition) (test/read-objcl-instance-method-definition) (test/read-objcl-message-send)) #-(and) (progn '(progn [w alphavalue] [w setalphavalue:0.5] [v mouse:p inrect:r] [[w getframe] mouse:p inrect:r] [nsstring stringwithinteger: (* 42 ten)] [nsstring stringwithformat:@"%f %i %f" (double-float)2 (int)3 (double-float)4] [[nsnumber alloc] initwithint:42] (let ((controller [nswindowcontroller alloc])) [controller initwithwindownibname:@"DataWindow" owner:controller]) [self dosomething] [super dosomething]) (progn (objc:send w 'alpha-value) (objc:send w :set-alpha-value 0.5) (objc:send v :mouse p :in-rect r) (objc:send (objc:send w 'get-frame) :mouse p :in-rect r) (objc:send ns:ns-string :string-with-integer (* 42 ten)) (objc:send ns:ns-string :string-with-format (ccl:@ "%f %i %f") (:double-float 2 :int 3 :double-float 4)) (objc:send (objc:send ns:ns-number 'alloc) :init-with-int 42) (let ((controller (objc:send ns:ns-window-controller 'alloc))) (objc:send controller :init-with-window-nib-name (ccl:@ "DataWindow") :owner controller)) (objc:send self 'do-something) (objc:send-super self 'do-something))) ;;;; THE END ;;;;
21,292
Common Lisp
.lisp
448
37.082589
108
0.57978
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
fb32dd55c9cc24854aa3a9bfc69c22d5af526493e9d7796944fdfe8463a48458
4,937
[ -1 ]
4,938
oclo-ccl.lisp
informatimago_lisp/objcl/oclo-ccl.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: oclo-ccl.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This file defines implementation specific additions to the ;;;; oclo package. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-12-17 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COM.INFORMATIMAGO.OBJECTIVE-C.LOWER") (defun objc-to-lisp-classname-p (str &optional (package *package*)) (let ((name (gethash str ccl::*lisp-classname-table*))) (typecase name (string (setf (gethash str ccl::*lisp-classname-table*) (or (find-symbol name "NS") (intern name package)))) (t name)))) (defun lisp-to-objc-classname-p (sym) (gethash sym ccl::*objc-classname-table*)) (defparameter *null* ccl:+null-ptr+ "A NULL pointer. Don't compare to it to check for a null pointer, but use NULLP instead.") (defun nullp (object) " RETURN: Whether OBJECT is a null pointer. " (ccl::%null-ptr-p object)) (defun selector (name) " NAME: A selector name (string). Example: \"initWithFrame:\" RETURN: The Objective-C selector named NAME. " (ccl::%get-selector (ccl::ensure-objc-selector name))) (in-package "CCL") ;; patch: (defmacro send (o msg &rest args &environment env) (make-optimized-send o msg args env)) (defmacro send/stret (s o msg &rest args &environment env) (make-optimized-send o msg args env s)) (defmacro send-super (o msg &rest args &environment env) (make-optimized-send o msg args env nil t)) (defmacro send-super/stret (s o msg &rest args &environment env) (make-optimized-send o msg args env s t)) ;;;; THE END ;;;;
2,839
Common Lisp
.lisp
71
37.507042
83
0.636463
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
7f97c75191e9c5761203d12251234a7f1bf2842f5264ce56d28622f88330ea39
4,938
[ -1 ]
4,939
objcl.lisp
informatimago_lisp/objcl/objcl.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: objcl.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Objective-CL: Objective-C­like syntax ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-12-17 <PJB> Created. ;;;;BUGS ;;;; Cannot read comments inside [] quite well. ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) #+(and ccl darwin) (setf *readtable* (copy-readtable com.informatimago.objcl.readtable:*cocoa-readtable*)) #-(and ccl darwin) (error "We need a readtable for CCL specific dispatching reader macro #$")) (in-package "COM.INFORMATIMAGO.OBJECTIVE-CL") (define-condition read-error (stream-error) ((control-string :initarg :control-string :initform "Read error" :accessor read-error-control-string) (arguments :initarg :arguments :initform '() :accessor read-error-arguments)) (:report (lambda (condition stream) (format stream "In stream ~S: ~?" (stream-error-stream condition) (read-error-control-string condition) (read-error-arguments condition))))) (defun read-error (stream control-string &rest arguments) (error 'read-error :stream stream :control-string control-string :arguments arguments)) ;; (PROGN (SETF *READTABLE* (COPY-READTABLE NIL NIL)) (SETF (READTABLE-CASE *READTABLE*) :UPCASE)) ;; To reset the reader macro: ;; (if old-definition ;; (set-macro-character char old-definition old-non-term) ;; (set-syntax-from-char char char)) (defparameter *default-readtable* (copy-readtable nil nil) "The default readtable. Used to read @symbols.") (defun set-objc-reader-macros (&optional (*readtable* *readtable*)) (set-syntax-from-char #\[ #\() (set-syntax-from-char #\] #\)) (set-macro-character #\[ 'objcl-expression-reader-macro nil) (set-macro-character #\@ 'objcl-definition-reader-macro t) *readtable*) (defun reset-objc-reader-macros (&optional (*readtable* *readtable*)) (set-syntax-from-char #\[ #\a) (set-syntax-from-char #\] #\a) (set-macro-character #\[ nil t) (set-macro-character #\@ nil t) *readtable*) (defparameter *lisp-readtable* (set-objc-reader-macros (copy-readtable *readtable* nil)) "The lisp readtable, used to read lisp expressions (possibly including Objective-CL forms starting with #\\[ or #\\@).") (defparameter *objc-readtable* (let ((rt (copy-readtable *readtable* nil))) (set-syntax-from-char #\[ #\( rt) (set-syntax-from-char #\] #\) rt) (set-macro-character #\[ 'objcl-expression-reader-macro nil rt) (set-macro-character #\@ 'objcl-definition-reader-macro t rt) (setf (readtable-case rt) :preserve) rt) "The Objective-CL readtable, used to read Objective-CL expressions \(possibly including Objective-CL forms starting with #\\[ or #\\@). Basically the same as *lisp-readtable*, but with readtable-case set to :preserve.") (defun skip-spaces (stream) (peek-char t stream nil nil t)) (defun read-identifier (stream) (let ((buffer (loop :for ch = (peek-char nil stream nil nil t) :while (and ch (or (alphanumericp ch) (find ch "-_<>"))) :collect (read-char stream nil nil t)))) (if buffer (coerce buffer 'string) (error "Expected an identifier, instead got character '~C'" (peek-char nil stream nil nil t))))) (eval-when (:compile-toplevel :load-toplevel :execute) (defun split-string (string &optional (separators " ")) " NOTE: current implementation only accepts as separators a string containing literal characters. " (let ((chunks '()) (position 0) (nextpos 0) (strlen (length string))) (loop :while (< position strlen) :do (loop :while (and (< nextpos strlen) (not (find (aref string nextpos) separators))) :do (incf nextpos)) (push (subseq string position nextpos) chunks) (setf position (incf nextpos))) (nreverse chunks))) (defun objc-to-lisp-classname (identifier &optional (*package* *package*)) (let ((classname (oclo:objc-to-lisp-classname identifier *package*))) (etypecase classname (string (intern classname *package*)) (symbol classname)))) (defun objc-to-lisp-identifier (identifier) (or (oclo:objc-to-lisp-classname-p identifier) (let ((*readtable* *lisp-readtable*)) (read-from-string identifier)))) (defun objc-to-lisp-message (selector) (mapcar (lambda (name) (if (zerop (length name)) :|| (first (oclo:objc-to-lisp-message (concatenate 'string name ":"))))) (split-string selector ":"))) );;eval-when (defun read-type-specifier (stream) (assert (eql #\( (skip-spaces stream))) (let* ((*package* (find-package "KEYWORD")) (*readtable* *lisp-readtable*) (type-specifier (read stream t nil t))) (assert (listp type-specifier)) (assert (= 1 (length type-specifier))) (assert (keywordp (first type-specifier))) (first type-specifier))) (defun read-final-signature (stream) (let ((*readtable* *lisp-readtable*)) (let ((rest (read stream t nil t)) (parameter (read stream t nil t))) (assert (eql '&rest rest)) parameter))) (defun read-method-signature (stream) " RETURN: a list containing the selector, a list of parameters, and the rest parameter. " (let ((simple-selector (and (skip-spaces stream) (read-identifier stream))) (next-char (peek-char nil stream nil nil t)) (selector '()) (parameters '())) (if (eql #\: next-char) (loop :named compound-selector :initially (push simple-selector selector) :while (eql #\: next-char) :do (read-char stream t nil t) ;; (type-identifier) objcl-identifier (let ((next-char (skip-spaces stream))) (cond ((or (null next-char) (eql #\) next-char)) (error "Missing argument after selector part ~A:" (car (last selector 2)))) ((eql #\( next-char) (let ((type-identifier (read-type-specifier stream)) (parameter (let ((*readtable* *lisp-readtable*)) (read stream t nil t)))) (assert (symbolp parameter) (parameter) "The parameter name should be a symbol.") (push (list type-identifier parameter) parameters))) (t (error "Expected a type specifier in parentheses instead of '~C'" next-char)))) ;; objcl-identifier ':' (setf next-char (skip-spaces stream)) (cond ((or (null next-char) (char= #\) next-char)) (return-from compound-selector (list (format nil "~{~A:~}" (nreverse selector)) (nreverse parameters) nil))) ((char= #\& next-char) (return-from compound-selector (list (format nil "~{~A:~}" (nreverse selector)) (nreverse parameters) (read-final-signature stream)))) ((char= #\: next-char) ; empty selector-part (push "" selector)) (t (push (and (skip-spaces stream) (read-identifier stream)) selector) (setf next-char (peek-char nil stream nil nil t)))) :finally (error "~@[Invalid character '~C'. ~]Expected a colon after identifier '~A' in selector '~{~A:~}'." next-char (first selector) (reverse selector))) (list simple-selector nil nil)))) (defun read-final-arguments (stream) (loop :while (eql #\( (skip-spaces stream)) :collect (list (read-type-specifier stream) (let ((*readtable* *lisp-readtable*)) (read stream t nil t))))) (defun read-message (stream) (let ((selector-part (and (skip-spaces stream) (read-identifier stream))) (next-char (peek-char nil stream nil nil t)) (selector '()) (arguments '())) (if (eql #\: next-char) (loop :named compound-selector :initially (push selector-part selector) :while (eql #\: next-char) :do (read-char stream t nil t) ;; objcl-expression (let ((next-char (skip-spaces stream))) (when (or (null next-char) (eql #\] next-char)) (error "Missing argument after selector part ~A:" (car (last selector 2)))) (push (let ((*readtable* *lisp-readtable*)) (read stream t nil t)) arguments)) ;; objcl-identifier ':' (setf next-char (skip-spaces stream)) (cond ((or (null next-char) (char= #\] next-char)) (return-from compound-selector (list (format nil "~{~A:~}" (nreverse selector)) (nreverse arguments) '()))) ((char= #\( next-char) (return-from compound-selector (list (format nil "~{~A:~}" (nreverse selector)) (nreverse arguments) (read-final-arguments stream)))) ((char= #\: next-char) ; empty selector-part (push "" selector)) ;; ((char= #\; next-char) ; comment ;; (read-line stream) ;; (setf next-char (peek-char nil stream nil nil t))) (t (push (and (skip-spaces stream) (read-identifier stream)) selector) (setf next-char (peek-char nil stream nil nil t)))) :finally (error "~@[Invalid character '~C'. ~]Expected a colon after identifier '~A' in selector '~{~A:~}'." next-char (first selector) (reverse selector))) (list selector-part arguments '())))) (defparameter *pseudo-selector-parts* '(("subClass" . objcl-identifier) ("slots" . list) ("method" . signature) ("classMethod" . signature) ("resultType" . type-specifier) ("body" . body))) (defun read-pseudo-message (stream) " Read a pseudo-message. The following selector parts with the indicated following arguments are expected: subClass: objcl-identifier slots: list (sexp) method: '(' signature ')' classMethod: '(' signature ')' resultType: '(' type-identifier ')' body: list... Return a list containing: - the compound selector, - a list of arguments but those of body:, and - a list of the body arguments. " (let ((selector-part (and (skip-spaces stream) (read-identifier stream))) (next-char (peek-char nil stream nil nil t)) (selector '()) (arguments '()) (body '())) (if (eql #\: next-char) (loop :named compound-selector :initially (push selector-part selector) :while (eql #\: next-char) :do (read-char stream t nil t) ; read the colon ;; read argument (let ((next-char (skip-spaces stream))) (when (or (null next-char) (eql #\] next-char)) (error "Missing argument after selector part ~A:" (car (last selector 2)))) (case (cdr (assoc selector-part *pseudo-selector-parts* :test (function string=))) ((objcl-identifier) (push (read-identifier stream) arguments)) ((type-specifier) (push (read-type-specifier stream) arguments)) ((signature) (push (progn (assert (eql #\( (skip-spaces stream))) (read-char stream t nil t) (prog1 (read-method-signature stream) (assert (eql #\) (skip-spaces stream))) (read-char stream t nil t))) arguments)) ((body) (loop :do (push (let ((*readtable* *lisp-readtable*)) (read stream t nil t)) body) :until (or (null (setf next-char (skip-spaces stream))) (eql #\] next-char)))) (otherwise ; same as list (push (let ((*readtable* *lisp-readtable*)) (read stream t nil t)) arguments)))) ;; read selector-part (setf next-char (skip-spaces stream)) (cond ((or (null next-char) (char= #\] next-char)) (return-from compound-selector (list (format nil "~{~A:~}" (nreverse selector)) (nreverse arguments) (nreverse body)))) ((char= #\( next-char) (error "Syntax error in pseudo-message send, expected a selector part, but got an opening parenthesis after reading ~{~A:~}." (reverse selector))) ((char= #\: next-char) ; empty selector-part (push "" selector)) (t (push (setf selector-part (and (skip-spaces stream) (read-identifier stream))) selector) (setf next-char (peek-char nil stream nil nil t)))) :finally (error "~@[Invalid character '~C'. ~]Expected a colon after identifier '~A' in selector '~{~A:~}'." next-char (first selector) (reverse selector))) (list selector-part arguments (nreverse body))))) (defun read-message-send (stream recipient read-message) (let ((next-char (skip-spaces stream))) (cond ((alpha-char-p next-char) (destructuring-bind (selector arguments final-arguments) (funcall read-message stream) (cond ((char= #\] (skip-spaces stream)) (read-char stream)) (t (read-error stream "Syntax error, missing closing bracket after ~A" selector))) (list recipient selector arguments final-arguments))) ((char= #\] next-char) (read-error stream "Syntax error, missing a selector in the brackets, after ~S" recipient)) ((char= #\; next-char) (read-line stream) ; skip comment (read-message-send stream recipient read-message)) (t (read-error stream "Lexical error, unexpected character: ~C, in the brackets, after ~S" next-char recipient))))) #-(and) (defun read-class-definition (stream) (let ((class-name (progn (skip-spaces stream) (read-identifier stream))) (super-class-name (progn (skip-spaces stream) (read-identifier stream))) (slots (let ((*readtable* *lisp-readtable*)) (loop :until (char= #\] (skip-spaces stream)) :collect (read stream t nil t) :finally (read-char stream t nil t))))) (list (oclo:objc-to-lisp-classname class-name) (oclo:objc-to-lisp-classname super-class-name) slots))) #-(and) (defun read-method-definition (stream) (let ((class-name (progn (skip-spaces stream) (read-identifier stream))) (type-specifier (progn (skip-spaces stream) (read-type-specifier stream))) (signature (progn (assert (eql #\( (skip-spaces stream))) (read-char stream) (prog1 (read-method-signature stream) (assert (eql #\) (skip-spaces stream))) (read-char stream)))) (body (let ((*readtable* *lisp-readtable*)) (loop :until (char= #\] (skip-spaces stream)) :collect (read stream t nil t) :finally (read-char stream t nil t))))) (list (oclo:objc-to-lisp-classname class-name) type-specifier signature body))) (defun generate-message-send (recipient selector arguments final-arguments) ;; `(oclo:slet ((,result ;; )) ;; ,result) `(,@(if (and (symbolp recipient) (string-equal "super" recipient)) `(oclo:send-super) `(oclo:send ,recipient)) ,@(if arguments (mapcan (function list) (objc-to-lisp-message selector) arguments) (list `',(intern (symbol-name (first (objc-to-lisp-message selector)))))) ,@(when final-arguments (list (mapcan (function copy-list) final-arguments))))) (defun generate-class-definition (class-name super-class-name slots) `(defclass ,class-name (,super-class-name) ,slots (:metaclass ns:+ns-object)) ;; (progn ;; (eval-when (:execute :compile-toplevel :load-toplevel) ;; (oclo:define-classname-translation ,() ,class-name)) ;; ) ) (defmacro define-objc-method ((selector-arg class-arg) &body body &environment env) (ccl::objc-method-definition-form nil selector-arg class-arg body env)) (defmacro define-objc-class-method ((selector-arg class-arg) &body body &environment env) (ccl::objc-method-definition-form t selector-arg class-arg body env)) (defun generate-method-definition (level class-name result-type signature body) " LEVEL is :+ or :- for class methods or instance methods. " ;; (:ID "multipleArg:complexSelector:" ((:INT A) (:INT B)) NIL) (destructuring-bind (selector fixed-parameters rest-parameter) signature `(,(ecase level ((:-) 'define-objc-method) ((:+) 'define-objc-class-method)) ((,result-type ,@(if fixed-parameters (mapcan (function list) (objc-to-lisp-message selector) fixed-parameters) ;;(list `',(intern (symbol-name (first (objc-to-lisp-message selector))))) (list `,(intern (symbol-name (first (objc-to-lisp-message selector)))))) ,@(when rest-parameter (list rest-parameter))) ,class-name) ,@body))) (defun message-send (stream recipient) " Reads and parse a message sending (recipient is already read), and generate a message sending form. " (apply (function generate-message-send) (read-message-send stream recipient (function read-message)))) ;; (defun class-definition (stream) ;; (apply (function generate-class-definition) (read-class-definition stream))) ;; ;; ;; (defun class-method-definition (stream) ;; (apply (function generate-method-definition) :+ (read-method-definition stream))) ;; ;; ;; (defun instance-method-definition (stream) ;; (apply (function generate-method-definition) :- (read-method-definition stream))) (defun objcl-definition (stream recipient) " Reads and parse a pseudo-message sending (recipient is already read), and generate an Objective-CL definition form. " (destructuring-bind (recipient selector arguments body) (read-message-send stream recipient (function read-pseudo-message)) ;; (print `(:recipient ,recipient :selector ,selector :arguments ,arguments :body ,body)) (cond ((string= selector "subClass:slots:") (generate-class-definition (objc-to-lisp-classname (first arguments)) (objc-to-lisp-classname recipient) (second arguments))) ((string= selector "classMethod:resultType:body:") (generate-method-definition :+ (objc-to-lisp-classname recipient) (second arguments) (first arguments) body)) ((string= selector "method:resultType:body:") (generate-method-definition :- (objc-to-lisp-classname recipient) (second arguments) (first arguments) body)) (t (error "Unknown Objective-CL definition selector ~A" selector))))) (defun read-objcl-expression (stream) "Reads a message sending expressions. The opening bracket has already been read. Returns a message send form." (let ((*readtable* *objc-readtable*) (next-char (skip-spaces stream))) (if (alpha-char-p next-char) (let ((identifier (read-identifier stream))) (cond ((string= identifier "super") (message-send stream :super)) (t (message-send stream (objc-to-lisp-identifier identifier))))) (message-send stream (let ((*readtable* *lisp-readtable*)) (read stream t nil t)))))) (defun read-objcl-definition (stream) "Reads an Objective-CL definition. This can be either a subclass definition, an instance method or a class method definition. In either case, the first token is a class name, followed by a pseudo-message send syntax. The opening bracket has already been read. Returns a defclass, a define-objc-method or a define-objc-class-method form. " (let ((*readtable* *objc-readtable*) (next-char (skip-spaces stream))) (if (alpha-char-p next-char) (let ((identifier (read-identifier stream))) (cond ((string= identifier "super") (error "Cannot send Objective-CL definition message to 'super' in @[...].")) (t (objcl-definition stream identifier)))) ;; (objcl-definition stream (let ((*readtable* *lisp-readtable*)) (read stream t nil t))) ;; This is strange, because low-level Objective-C API allow it without problem, but as documented in ccl: (error "We cannot ensure the right semantics for dynamic Objective-C class and method creation with the current bridge. Please, only use class identifier as recipient to Objective-CL definition messages in @[...].")))) (defun read-suppressed-objcl-expression (stream) " Reads and parses the following syntax: suppressed-objc-expression := '[' { suppressed-expression } ']' . suppressed-expression := sexp | suppressed-objcl-expression . Returns NIL. Assumes the '[' has been read already. " (loop :until (eql #\] (skip-spaces stream)) :do (read stream t nil t) :finally (read-char stream)) nil) (defun objcl-expression-reader-macro (stream ch) (assert (eql #\[ ch)) (if *read-suppress* (read-suppressed-objcl-expression stream) (read-objcl-expression stream))) ;;; ;;; Constants strings in objc-runtime don't support unicode characters. ;;; so we need to redo it here. ;;; http://www.cocoabuilder.com/archive/cocoa/131727-how-to-code-nsstring-literal-with-utf8.html ;; (objc:make-nsstring "été") ;; #<NS-MUTABLE-STRING "été" (#x16038F80)> ;; objc:lisp-string-from-nsstring (defun make-utf8-cstring (lstring) (let* ((lstring (if (typep lstring 'simple-base-string) lstring (copy-seq lstring))) (llen (length lstring)) (clen (ccl::utf-8-octets-in-string lstring 0 llen))) (declare (fixnum llen clen)) (let* ((cstring (ccl::malloc (the fixnum (1+ clen))))) (ccl::utf-8-memory-encode lstring cstring 0 0 llen) (setf (ccl::%get-byte cstring clen) 0) #+testing (print (loop for str = cstring for i from 0 for ch = (ccl:%get-unsigned-byte str i) while (plusp ch) collect ch)) (values cstring clen)))) (defun make-macroman-cstring (lstring) ;; We assume lstring contains only Mac-Roman characters. (let* ((llen (length lstring))) (declare (fixnum llen)) (let* ((cstring (ccl::malloc (the fixnum (1+ llen))))) (ccl::encode-string-to-memory (load-time-value (ccl:lookup-character-encoding :macosroman)) cstring 0 lstring 0 llen) (setf (ccl::%get-byte cstring llen) 0) #+testing (print (loop for str = cstring for i from 0 for ch = (ccl:%get-unsigned-byte str i) while (plusp ch) collect ch)) (values cstring llen)))) (defun %make-constant-nsstring (string) "Make a persistent (heap-allocated) NSConstantString from the argument lisp string." #+apple-objc (if (mac-roman-string-p string) (ccl::make-record :<nsc>onstant<s>tring :isa ccl::*nsconstantstring-class* :bytes (make-macroman-cstring string) :num<b>ytes (length string)) (multiple-value-bind (bytes bytelen) (make-utf8-cstring string) (declare (ignore bytelen)) (oclo:send ns:ns-string :string-with-c-string bytes :encoding #$|NSUTF8StringEncoding|))) #+cocotron-objc (warn "Check the encoding used for NSConstantString in cocotron.") #+cocotron-objc (make-record :<nsc>onstant<s>tring :isa *nsconstantstring-class* :_bytes (make-cstring string) :_length (length string)) #+gnu-objc (warn "Check the encoding used for NSConstantString in GNUstep on this system.") #+gnu-objc (make-record :<nxc>onstant<s>tring :isa *nsconstantstring-class* :c_string (make-cstring string) :len (length string))) (defvar *objc-constant-strings* (make-hash-table :test #'equal)) (eval-when (:execute :compile-toplevel :load-toplevel) (defstruct objc-constant-string string nsstringptr) #-(and) (defclass objc-constant-string () ((string :initarg :string :accessor objc-constant-string-string :initform nil) (nsstringptr :initarg :nsstringptr :accessor objc-constant-string-nsstringptr :initform nil))) );;eval-when (defun ns-constant-string (string) (or (gethash string *objc-constant-strings*) (setf (gethash string *objc-constant-strings*) (make-objc-constant-string :string string :nsstringptr (%make-constant-nsstring string))))) (defun ns-mutable-string (string) (multiple-value-bind (bytes bytelen) (make-utf8-cstring string) (declare (ignore bytelen)) (oclo:send ns:ns-string :string-with-c-string bytes :encoding #$|NSUTF8StringEncoding|))) (defun objcl-string (object) (warn "~S is obsolete, use ~S" 'objcl-string 'objc-string) (objc-string object)) (defun objc-string (object) " RETURN: A NSMutableString instance, containing the character of the OBJECT. If OBJECT is not a string designator, then its PRINC-TO-STRING representation is used. OBJECT: A string designator, or another lisp object. " (ns-mutable-string (typecase object (string object) ((or character symbol) (string object)) (t (princ-to-string object))))) (defun lisp-string (an-objc-string) " RETURN: A Lisp STRING containing the characters of AN-OBJC-STRING. " (unless (oclo:nullp an-objc-string) (typecase an-objc-string (ns:ns-constant-string (objc:lisp-string-from-nsstring an-objc-string)) (ns:ns-mutable-string (objc:lisp-string-from-nsstring an-objc-string)) (ccl::objc-constant-string (ccl::objc-constant-string-string an-objc-string)) (objc-constant-string (objc-constant-string-string an-objc-string)) (t (ccl::%get-utf-8-cstring (oclo:send an-objc-string 'utf8-string)))))) #+testing (print (loop for str = (oclo:send a-nsstring 'utf8-string) for i from 0 for ch = (ccl:%get-unsigned-byte str i) while (plusp ch) collect ch)) (eval-when (:execute :compile-toplevel :load-toplevel) (defmethod make-load-form ((s ns:ns-constant-string) &optional env) (declare (ignore env)) `(ns-constant-string ,(lisp-string s))) (defmethod make-load-form ((s ns:ns-mutable-string) &optional env) (declare (ignore env)) `(ns-mutable-string ,(lisp-string s))) (defmethod make-load-form ((s objc-constant-string) &optional env) (declare (ignore env)) `(ns-constant-string ,(objc-constant-string-string s)))) (defmacro \@ (string) `(objc-constant-string-nsstringptr ,(ns-constant-string string))) (defun objcl-definition-reader-macro (stream ch) (assert (eql #\@ ch)) (if *read-suppress* (read stream t nil t) (let ((next-char (peek-char nil stream t nil t))) (case next-char ((#\[) (read-char stream t nil t) (read-objcl-definition stream)) ((#\") (objc-constant-string-nsstringptr (ns-constant-string (read stream t nil t)))) (otherwise (unread-char ch stream) (let ((*readtable* *default-readtable*)) (read stream t nil t))))))) (defparameter *objective-cl-readtable* *lisp-readtable*) (defmacro enable-objcl-reader-macros () "Sets in the *READTABLE* the reader macros for #\[ and #\@." '(eval-when (:compile-toplevel :load-toplevel :execute) (set-objc-reader-macros))) (defmacro disable-objcl-reader-macros () "Reset in the *READTABLE* the reader macros for #\[ and #\@." '(eval-when (:compile-toplevel :load-toplevel :execute) ;; (reset-objc-reader-macros) (setf *readtable* (copy-readtable nil)))) (defmacro set-objective-cl-syntax () "Sets the *READTABLE* to *OBJECTIVE-CL-READTABLE*. Must be a macro to be taken into account when compiling and loading. DEPRECATED: use (enable-objc-reader-macros)" '(eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* *objective-cl-readtable*))) (defparameter yes #$YES) (defparameter no #$NO) ;;;; THE END ;;;;
31,889
Common Lisp
.lisp
692
36.25578
226
0.580341
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
5b88c92091a39df2ba63c6890767b4374e53a6b3689dfb32216e1bc134cea0ba
4,939
[ -1 ]
4,940
mac-roman.lisp
informatimago_lisp/objcl/mac-roman.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: mac-roman.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This package exports a function to check if a character is in the ;;;; Mac-Roman repertoire. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2011-04-07 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2011 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COM.INFORMATIMAGO.OBJCL.MAC-ROMAN") ;; or we could depend on "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.CHARACTER-SETS" #+(and developing clisp) (defvar *mac-roman-codes* (map 'list 'char-code (sort (ext:convert-string-from-bytes (coerce (set-difference (com.informatimago.common-lisp.cesarum.list:iota 256) '(#xf0)) 'vector) charset:mac-roman) (function char<)))) #+developing (defun segments (list) (loop :while list :collect (loop :with start = (pop list) :with end = start :while (and list (= (1+ end) (car list))) :do (setf end (pop list)) :finally (return (if (= start end) start (cons start end)))))) (defun dichotomy-search (vector value compare &key (start 0) (end (length vector)) (key (function identity))) ;; From com.informatimago.common-lisp.cesarum.utility " PRE: entry is the element to be searched in the table. (<= start end) RETURN: (values found index order) POST: (<= start index end) +-------------------+----------+-------+----------+----------------+ | Case | found | index | order | Error | +-------------------+----------+-------+----------+----------------+ | x < a[min] | FALSE | min | less | 0 | | a[i] < x < a[i+1] | FALSE | i | greater | 0 | | x = a[i] | TRUE | i | equal | 0 | | a[max] < x | FALSE | max | greater | 0 | +-------------------+----------+-------+----------+----------------+ " (let* ((curmin start) (curmax end) (index (truncate (+ curmin curmax) 2)) (order (funcall compare value (funcall key (aref vector index)))) ) (loop :while (and (/= 0 order) (/= curmin index)) :do ;; (FORMAT T "~&min=~S cur=~S max=~S key=~S <~S> [cur]=~S ~%" CURMIN INDEX CURMAX VALUE (FUNCALL COMPARE VALUE (FUNCALL KEY (AREF VECTOR INDEX))) (AREF VECTOR INDEX)) (if (< order 0) (setf curmax index) (setf curmin index)) (setf index (truncate (+ curmin curmax) 2)) (setf order (funcall compare value (funcall key (aref vector index))))) (when (and (< start index) (< order 0)) (setf order 1) (decf index)) #+testing (assert (or (< (funcall compare value (funcall key (aref vector index))) 0) (and (> (funcall compare value (funcall key (aref vector index))) 0) (or (>= (1+ index) end) (< (funcall compare value (funcall key (aref vector (1+ index)))) 0))) (= (funcall compare value (funcall key (aref vector index))) 0))) (values (= order 0) index order))) (defun mac-roman-char-p (ch) "Whether the CH is a Mac-Roman characters." (let ((code (char-code ch))) (or (<= 0 code 127) ; an optimization, 95% of the characters are ASCII. (dichotomy-search ;; Computed as (coerce (segments *mac-roman-codes*)) ;; This vector represents the set of unicodes in the MacRoman character ;; set. It is a sorted vector of segments (min . max) or single codes. #((0 . 127) (160 . 165) (167 . 172) (174 . 177) (180 . 184) (186 . 187) (191 . 207) (209 . 214) (216 . 220) (223 . 239) (241 . 252) 255 305 (338 . 339) 376 402 (710 . 711) (728 . 733) 960 (8211 . 8212) (8216 . 8218) (8220 . 8222) (8224 . 8226) 8230 8240 (8249 . 8250) 8260 8482 8486 8706 8710 8719 8721 8730 8734 8747 8776 8800 (8804 . 8805) 9674 (64257 . 64258)) code (lambda (code segment) (if (consp segment) (cond ((< code (car segment)) -1) ((< (cdr segment) code) +1) (t 0)) (cond ((< code segment) -1) ((< segment code) +1) (t 0)))))))) (defun mac-roman-string-p (string) "Whether the STRING contains only Mac-Roman characters." (every (function mac-roman-char-p) string)) ;;;; THE END ;;;;
5,942
Common Lisp
.lisp
128
38.664063
177
0.510517
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
da79564e732af784e1445c8f41f2bcab12d8db8754be47c7548494b58ab372bd
4,940
[ -1 ]
4,941
scratch.lisp
informatimago_lisp/objcl/scratch.lisp
(eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (push (setf (ccl:current-directory) (setf *default-pathname-defaults* #p"/home/pjb/works/abalone-macosx/objcl/")) asdf:*central-registry*) (cl-user::asdf-load :com.informatimago.objcl) (in-package :cocoa-playground) (objcl:set-objective-cl-syntax) ;; (asdf:oos 'asdf:load-op :com.informatimago.objc) (progn (cl-user::asdf-delete-system :com.informatimago.objcl) (delete-package :com.informatimago.objective-cl) (delete-package :com.informatimago.objective-c.lower) (delete-package :com.informatimago.simple-test) (cl-user::asdf-load :com.informatimago.objcl)) (x86-darwin64::|class_getInstanceMethod| (ccl:with-cstrs ((class-name "NSView")) (x86-darwin64::|objc_lookUpClass| class-name)) (objc:\@selector "initWithFrame:")) #<a foreign pointer #x7fff70e5ae58> (in-package :cl-user) (map nil (function delete-file) (directory #p"~/.cache/common-lisp/galatea.lan.informatimago.com/ccl-1.6-f94-macosx-amd64/home/pjb/src/git/public/lisp/objcl/*.*")) (cd #p"/home/pjb/src/public/lisp/objcl/") (push #p"/home/pjb/src/public/lisp/objcl/" asdf:*central-registry*) (asdf-load :com.informatimago.objcl) (asdf-load :com.informatimago.cocoa-playground) (in-package :cocoa-playground) (objcl:set-objective-cl-syntax) (every (lambda (x) (typep x 'ns:ns-string)) '(@"summer" @"été" @"καλοκαίρι")) '(@"summer" @"été" @"καλοκαίρι") (mapcar (lambda (str) (cons str (com.informatimago.objective-cl:lisp-string str))) '(@"summer" @"été" @"καλοκαίρι"))
1,679
Common Lisp
.lisp
32
47.125
137
0.703565
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
5665e9d7eecf6e3344c7edba011386e8dfbb810ea8834adf7c09707dbc0a60fa
4,941
[ -1 ]
4,942
oclo.lisp
informatimago_lisp/objcl/oclo.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: oclo.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This file defines additions to the oclo package not provided by ;;;; the implementation or implementation specific code. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-12-17 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COM.INFORMATIMAGO.OBJECTIVE-C.LOWER") (defmacro stret (expression &environment env) (let ((result (gensym "structure-result-"))) `(slet ((,result ,(macroexpand expression env))) ,result))) #-(and) (defun needs-stret (o msg args env &optional sclassname) (multiple-value-bind (msg args vargs) (ccl::parse-message (cons msg args)) (let ((message-info (ccl::get-objc-message-info msg))) (unless message-info (error "Unknown message: ~S" msg)) ;; If a vararg exists, make sure that the message can accept it (when (and vargs (not (getf (ccl::objc-message-info-flags message-info) :accepts-varargs))) (error "Message ~S cannot accept a variable number of arguments" msg)) (unless (= (length args) (ccl::objc-message-info-req-args message-info)) (error "Message ~S requires ~a ~d args, but ~d were provided." msg (if vargs "at least" "exactly") (ccl::objc-message-info-req-args message-info) (length args))) (multiple-value-bind (args svarforms sinitforms) (ccl::sletify-message-args args) (let* ((ambiguous (getf (ccl::objc-message-info-flags message-info) :ambiguous)) (methods (ccl::objc-message-info-methods message-info)) (method-info (if ambiguous (let ((class (if sclassname (ccl::find-objc-class sclassname) (ccl::get-objc-class-from-declaration (ccl::declared-type o env))))) (when class (dolist (m methods) (unless (getf (ccl::objc-method-info-flags m) :protocol) (let ((mclass (or (ccl::get-objc-method-info-class m) (error "Can't find ObjC class named ~s" (ccl::objc-method-info-class-name m))))) (when (subtypep class mclass) (return m))))))) (car methods)))) (if method-info (ccl::result-type-requires-structure-return (ccl::objc-method-info-result-type method-info)) (error "Cannot find method result type for message -~A sent to ~S. Try declaring the class of the recipient." (ccl::objc-message-info-message-name message-info) o))))))) #-(and) (defmacro send (&whole w o msg &rest args &environment env) (if (needs-stret o msg args env) `(stret ,w) (ccl::make-optimized-send o msg args env))) #-(and) (defmacro send/stret (&whole w s o msg &rest args &environment env) (if (needs-stret o msg args env) (if s (ccl::make-optimized-send o msg args env s) `(stret (send ,@(cddr w)))) (ccl::make-optimized-send o msg args env))) ;;;; THE END ;;;;
4,643
Common Lisp
.lisp
90
41.155556
124
0.552255
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
eb0fa2d3a8c5da51c435f038e5885fe252216321439273fee68e994954989513
4,942
[ -1 ]
4,943
objc-support.lisp
informatimago_lisp/objcl/objc-support.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: objc-support.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This file loads Objective-C support. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2014-05-02 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2014 - 2016 ;;;; ;;;; 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.OBJECTIVE-CL.READTABLE" (:nicknames "COM.INFORMATIMAGO.OBJCL.READTABLE") (:use "COMMON-LISP") (:export "*CCL-READTABLE*" "*COCOA-READTABLE*")) (in-package "COM.INFORMATIMAGO.OBJECTIVE-CL.READTABLE") #+ccl (defparameter *ccl-readtable* (copy-readtable ccl::%initial-readtable%)) ;; We'll try to catch in this variable the objective-c reader macros ;; installed by ccl require cocoa. (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *cocoa-readtable* nil)) #+(and ccl darwin); for now, not on non-darwin (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* #-(and ccl darwin) (copy-readtable nil) #+(and ccl darwin) ; #+ccl (require :cocoa) needs the botched readtable. (copy-readtable ccl::%initial-readtable%)) ;; When we (require :objc-support) before (require :cocoa), ccl ;; can't find the main bundle. So we must require :cocoa for the ;; applications that need it. #-darwin (require :objc-support) #+darwin (require :cocoa) (defun nsfun-reader-macro (stream subchar numarg) (declare (ignorable subchar numarg)) (let* ((token (make-array 16 :element-type 'character :fill-pointer 0 :adjustable t))) (loop (let* ((char (read-char stream nil nil))) (if (or (eql char #\:) (eql char #\_) (and char (digit-char-p char 36))) (vector-push-extend char token) (progn (when char (unread-char char stream)) (return))))) (unless *read-suppress* (unless (> (length token) 0) (error 'reader-error :stream stream)) ; "Invalid token after #/." #+ccl(ccl::check-objc-message-name token) (intern token "NSFUN")))) (unless *cocoa-readtable* (setf *cocoa-readtable* (copy-readtable *readtable*)) (set-dispatch-macro-character #\# #\/ (function nsfun-reader-macro) *cocoa-readtable*)) (pushnew :objc-support *features*)) ;; ;; ccl::%initial-readtable% CCL readtable ;; com.informatimago.objective-cl.readtable::*ccl-readtable* CCL readtable. ;; com.informatimago.objective-cl.readtable::*cocoa-readtable* cocoa readtable. ;; ;;;; THE END ;;;;
3,657
Common Lisp
.lisp
84
39.428571
91
0.616442
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
283d1459cd6f43c26797701a4615eedb41e8fb11ec9392a178ecf38c1c7ea284
4,943
[ -1 ]
4,944
mac-roman-test.lisp
informatimago_lisp/objcl/mac-roman-test.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: mac-roman-test.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Test mac-roman.lisp ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.OBJCL.MAC-ROMAN.TEST" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.SIMPLE-TEST" "COM.INFORMATIMAGO.OBJCL.MAC-ROMAN") (:export "TEST/ALL")) (in-package "COM.INFORMATIMAGO.OBJCL.MAC-ROMAN.TEST") (defparameter *mac-roman-codes* '(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 160 161 162 163 164 165 167 168 169 170 171 172 174 175 176 177 180 181 182 183 184 186 187 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 209 210 211 212 213 214 216 217 218 219 220 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 241 242 243 244 245 246 247 248 249 250 251 252 255 305 338 339 376 402 710 711 728 729 730 731 732 733 960 8211 8212 8216 8217 8218 8220 8221 8222 8224 8225 8226 8230 8240 8249 8250 8260 8482 8486 8706 8710 8719 8721 8730 8734 8747 8776 8800 8804 8805 9674 64257 64258)) (defun equiv (a b) (eq (not a) (not b))) (defun test/mac-roman-char-p () (assert-true (loop :for code :from 0 :to 65535 :always (equiv (member code *mac-roman-codes*) (mac-roman-char-p (code-char code)))))) (define-test test/all () (test/mac-roman-char-p)) ;;;; THE END ;;;;
3,074
Common Lisp
.lisp
65
43.953846
83
0.629704
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
7fef46ad0f5c81daf81d5f8f6f75596a8bb06f58cc6db63c357229ca45bbc715
4,944
[ -1 ]
4,945
howto.lisp
informatimago_lisp/objcl/howto.lisp
;;; This file contains the equivalent of the "UI Elements HOWTO", ;;; written with the ObjCL reader macros. ;; UI Elements HOWTO ;; ;; This HOWTO shows how you can create Cocoa user-interface elements ;; by making lisp calls to instantiate and initialize Objective-C ;; objects. ;; ;; Cocoa programmers usually create UI elements using Apple's ;; InterfaceBuilder application, and then load those elements from a ;; nibfile, but Cocoa supports creating all the same UI elements by ;; making Objective-C method calls. In fact, that's how it loads ;; nibfiles: by making method calls to instantiate the objects ;; described in them. ;; ;; For Lisp programmers, accustomed to working incrementally and ;; interactively, it may sometimes make more sense to create ;; user-interface elements by making method calls interactively, ;; rather than by constructing a complete user interface in ;; InterfaceBuilder. This HOWTO shows how you can use Objective-C ;; method calls to create and display windows and other UI elements. ;; ;; For more information about how to load nibfiles from Lisp, see the ;; "nib-loading" example. For a complete discussion of how to ;; construct a Cocoa application using nibfiles created with ;; InterfaceBuilder, see the "currency-converter" example. ;; ;; Creating a Window ;; ;; Every user-interface element under Mac OS X appears either in a ;; window or in a menu. We'll begin by exploring how to create and ;; display windows. ;; ;; First, switch to the CCL package, for convenience. Most of Clozure ;; CL's Objective-C utilities are in the CCL package: ;; ;; ? (in-package :ccl) ;; #<Package "CCL"> #| This is bad practice. Instead we will work in our own package, that will use the objcl, oclo and ns packages. |# (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COCOA-HOWTO" (:use "CL")) (in-package "COCOA-HOWTO") (objcl:set-objective-cl-syntax) ;; Creating a Cocoa window follows the common Objective-C pattern of ;; allocating an object and then initializing it with some starting ;; data. To allocate a window, just call the alloc method of the ;; NSWindow class: ;; ;; ? (setf my-window (#/alloc (@class ns-window))) ;; #<NS-WINDOW <NSWindow: 0x13b68580> (#x13B68580)> ;; ;; The above expression creates a new window, but doesn't display it. ;; Before it shows up on the screen we must initialize it with some ;; appropriate values. For that, we'll use the method ;; initWithContentRect:styleMask:backing:defer:. ;; ;; As always in Objective-C, the name of the method reveals something ;; about the arguments it expects. The NSRect that we pass for the ;; initWithContentRect: segment of the method name describes the ;; shape of the window. The mask for styleMask: is a sequence of bits ;; that specify which window features are turned on. The backing: ;; argument is a constant of type NSBackingStoreType that specifies ;; how Cocoa will draw the contents of the window. Finally, the ;; defer: argument is a Boolean that determines whether to display ;; the window as soon as it's created. ;; ;; Next, we'll create data values to pass in these parameters, so ;; that we can display our new window on the screen. We'll build the ;; proper initialization form up piece-by-piece. ;; ;; The first argument, of course, is the window object to be ;; initialized. We pass the window that we created before: ;; ;; (#/initWithContentRect:styleMask:backing:defer: my-window ...) ;; ;; The next argument, the NSRect, is a structure that we need only ;; temporarily. Because NSRect values appear so often in Cocoa code, ;; Clozure CL provides a handy way to allocate them temporarily, ;; disposing of them automatically. The with-ns-rect macro (in the NS ;; package) creates an NSRect value, and then disposes of it when ;; control leaves the scope of the macro; for example: ;; ;; (ns:with-ns-rect (r 100 100 400 300) ;; ...) ;; ;; We can use this rectangle to initialize the shape of our new ;; window: ;; ;; (ns:with-ns-rect (r 100 100 400 300) ;; (#/initWithContentRect:styleMask:backing:defer: ;; my-window ;; r ;; ...)) ;; ;; To specify the window features we want, we must combine several ;; flags to form the proper style mask. Cocoa provides named ;; constants for each of the various window features. To create the ;; syle mask that describes a new window, use inclusive-or to combine ;; the named flags into a style mask: ;; ;; (logior #$NSTitledWindowMask ;; #$NSClosableWindowMask ;; #$NSMiniaturizableWindowMask ;; #$NSResizableWindowMask) ;; ;; You can find definitions for all the window masks in the Apple ;; Developer documentation for NSWindow Constants. ;; ;; Passing the window mask as the next argument gives us this ;; expression: ;; ;; (ns:with-ns-rect (r 100 100 400 300) ;; (#/initWithContentRect:styleMask:backing:defer: ;; my-window ;; r ;; (logior #$NSTitledWindowMask ;; #$NSClosableWindowMask ;; #$NSMiniaturizableWindowMask ;; #$NSResizableWindowMask) ;; ...)) ;; ;; Like the style masks, the NSBackingStoreType value is a named ;; constant that describes which drawing strategy Cocoa should use ;; for the contents of the window. The value can be ;; NSBackingStoreRetained, NSBackingStoreNonretained, or ;; NSBackingStoreBuffered. For this example, we'll use ;; NSBackingStoreBuffered: ;; ;; (ns:with-ns-rect (r 100 100 400 300) ;; (#/initWithContentRect:styleMask:backing:defer: ;; my-window ;; r ;; (logior #$NSTitledWindowMask ;; #$NSClosableWindowMask ;; #$NSMiniaturizableWindowMask ;; #$NSResizableWindowMask) ;; #$NSBackingStoreBuffered ;; ...)) ;; ;; Finally, the defer argument is just a Boolean. If we pass a true ;; value, Cocoa will defer displaying the window until we explicitly ;; tell it to. If we pass a False value, it will instead display the ;; window right away. We can pass the Lisp values T or NIL, and the ;; Objective-C bridge automatically converts them for us, but in the ;; spirit of using Objective-C values for Objective-C operations, ;; let's use the Objective-C constants #$YES and #$NO: ;; ;; (ns:with-ns-rect (r 100 100 400 300) ;; (#/initWithContentRect:styleMask:backing:defer: ;; my-window ;; r ;; (logior #$NSTitledWindowMask ;; #$NSClosableWindowMask ;; #$NSMiniaturizableWindowMask ;; #$NSResizableWindowMask) ;; #$NSBackingStoreBuffered ;; #$NO)) ;; ;; There; the expression to initialize our window object is finally ;; complete. We can evaluate it in the Listener to initialize the ;; window: ;; ;; (ns:with-ns-rect (r 100 100 400 300) ;; (#/initWithContentRect:styleMask:backing:defer: ;; my-window ;; r ;; (logior #$NSTitledWindowMask ;; #$NSClosableWindowMask ;; #$NSMiniaturizableWindowMask ;; #$NSResizableWindowMask) ;; #$NSBackingStoreBuffered ;; #$NO)) #| Just write: |# (defvar *my-window* [[NSWindow alloc] initWithContentRect:(ns:make-ns-rect 100 100 400 300) styleMask:(logior #$NSTitledWindowMask #$NSClosableWindowMask #$NSMiniaturizableWindowMask #$NSResizableWindowMask) backing:#$NSBackingStoreBuffered defer:nil]) [*my-window* setTitle: "Hello World"] ;; Then we can call makeKeyAndOrderFront: to display the window: ;; ;; (#/makeKeyAndOrderFront: my-window nil) [*my-window* makeKeyAndOrderFront:nil] ;; The window, empty, but with the shape and features we specified, ;; appears on the left lower corner of the screen. ;; ;; Adding a Button ;; ;; Once we have a window on the screen, we might like to put ;; something in it. Let's start by adding a button. ;; ;; Creating a button object is as simple as creating a window object; ;; we simply allocate one: ;; ;; (setf my-button (#/alloc ns:ns-button)) ;; #<NS-BUTTON <NSButton: 0x13b7bec0> (#x13B7BEC0)> ;; ;; As with the window, most of the interesting work is in configuring ;; the allocated button after it's allocated. ;; ;; Instances of NSButton include pushbuttons with either text or ;; image labels (or both), checkboxes, and radio buttons. In order to ;; make a text pushbutton, we need to tell our button to use a ;; button-type of NSMomentaryPushInButton, an image position of ;; NSNoImage, and a border style of NSRoundedBezelStyle. These style ;; options are represented by Cocoa constants. ;; ;; We also need to give the button a frame rectangle that defines its ;; size and position. We can once again use ns:with-ns-rect to ;; specify a temporary rectangle for the purpose of initializing our ;; button: ;; ;; (ns:with-ns-rect (frame 10 10 72 32) ;; (#/initWithFrame: my-button frame) ;; (#/setButtonType: my-button #$NSMomentaryPushInButton) ;; (#/setImagePosition: my-button #$NSNoImage) ;; (#/setBezelStyle: my-button #$NSRoundedBezelStyle)) ;; ;Compiler warnings : ;; ; Undeclared free variable MY-BUTTON (4 references), in an anonymous lambda form ;; NIL ;; ;; Now we just need to add the button to the window. This we do by ;; asking the window for its content view, and asking that view to ;; add the button as a subview: ;; ;; (#/addSubview: (#/contentView my-window) my-button) #| Again, it's much simplier to write just: |# (defparameter *my-button* (let ((button [[NSButton alloc] initWithFrame:(ns:make-ns-rect 10 50 72 32)])) [button setButtonType:#$NSMomentaryPushInButton] [button setImagePosition:#$NSNoImage] [button setBezelStyle:#$NSRoundedBezelStyle] [[*my-window* contentView] addSubview:button] button)) ;; The button appears in the window with the rather uninspired title ;; "Button". Clicking it highlights the button but, since we didn't ;; give it any action to perform, does nothing else. ;; ;; We can give the button a more interesting title and, perhaps more ;; importantly, an action to perform, by passing a string and an ;; action to it. First, let's set the button title: ;; ;; (let ((label (%make-nsstring "Hello!"))) ;; (#/setTitle: my-button label) ;; (#/release label)) ;; ;Compiler warnings : ;; ; Undeclared free variable MY-BUTTON, in an anonymous lambda form ;; NIL [*my-button* setTitle:@"Hello!"] ;; The button changes to display the text "Hello!". Notice that we ;; are careful to save a reference to the button text and release it ;; after changing the button title. The normal memory-management ;; policy in Cocoa is that if we allocate an object (like the ;; NSString "Hello!") we are responsible for releasing it. Unlike ;; Lisp, Cocoa does not automatically garbage-collect all allocated ;; objects by default. ;; ;; Giving the button an action is slightly more complicated. Clicking ;; a button causes the button object to send a message to a target ;; object. We haven't given our button a message to send, nor a ;; target object to send it to, so it doesn't do anything. In order ;; to get it do perform some kind of action, we need to give it a ;; target object and a message to send. Then, when we click the ;; button, it will send the message we specify to the target we ;; provide. Naturally, the target object had better be able to ;; respond to the message, or else we'll just see a runtime error. ;; ;; Let's define a class that knows how to respond to a greeting ;; message, and then make an object of that class to serve as our ;; button's target. ;; ;; We can define a subclass of NSObject to handle our button's ;; message: ;; ;; (defclass greeter (ns:ns-object) ;; () ;; (:metaclass ns:+ns-object)) ;; #<OBJC:OBJC-CLASS GREETER (#x13BAF810)> #| To create classes, class method and instance methods, we have pseudo messages that can be sent to the class objects (like in Smalltalk or Ruby). |# @[NSObject subClass:Greeter slots: ()] ;; We'll need to define a method to execute in response to the ;; button's message. Action methods accept one argument (in addition ;; to the receiver): a sender. Normally Cocoa passes the button ;; object itself as the sender argument; the method can do anything ;; it likes (or nothing at all) with the sender. ;; ;; Here's a method that displays an alert dialog: ;; ;; (objc:defmethod #/greet: ((self greeter) (sender :id)) ;; (declare (ignore sender)) ;; (let ((title (%make-nsstring "Hello!")) ;; (msg (%make-nsstring "Hello, World!")) ;; (default-button (%make-nsstring "Hi!")) ;; (alt-button (%make-nsstring "Hello!")) ;; (other-button (%make-nsstring "Go Away"))) ;; (#_NSRunAlertPanel title msg default-button alt-button other-button) ;; (#/release title) ;; (#/release msg) ;; (#/release default-button) ;; (#/release other-button))) @[Greeter method:(greet:(:id)sender) resultType:(:id) body: (declare (ignore sender)) (#_NSRunAlertPanel @"Hello!" @"Hello, World!" @"Hi!" @"Hello!" @"Go Away") oclo:*null*] ;; Now we can create an instance of the Greeter class and use it as ;; the button's target: ;; ;; (setf my-greeter (#/init (#/alloc greeter))) ;; #<GREETER <Greeter: 0x136c58e0> (#x136C58E0)> (defparameter *my-greeter* [[Greeter alloc] init]) ;; (#/setTarget: my-button my-greeter) ;; NIL ;; (#/setAction: my-button (@SELECTOR "greet:")) ;; NIL [*my-button* setTarget:*my-greeter*] [*my-button* setAction:(objc:@selector "greet:")] ;; Now, if you click the button, an Alert panel appears. #| ;;; In summary: (defpackage "COCOA-HOWTO" (:use "CL")) (in-package "COCOA-HOWTO") (objcl:set-objective-cl-syntax) (defvar *my-window* [[NSWindow alloc] initWithContentRect:(ns:make-ns-rect 100 100 400 300) styleMask:(logior #$NSTitledWindowMask #$NSClosableWindowMask #$NSMiniaturizableWindowMask #$NSResizableWindowMask) backing:#$NSBackingStoreBuffered defer:nil]) [*my-window* makeKeyAndOrderFront:nil] (defparameter *my-button* (let ((button [[NSButton alloc] initWithFrame:(ns:make-ns-rect 10 50 72 32)])) [button setButtonType:#$NSMomentaryPushInButton] [button setImagePosition:#$NSNoImage] [button setBezelStyle:#$NSRoundedBezelStyle] [[*my-window* contentView] addSubview:button] button)) [*my-button* setTitle:@"Hello!"] @[NSObject subClass:Greeter slots: ()] @[Greeter method:(greet:(:id)sender) resultType:(:id) body: (declare (ignore sender)) (#_NSRunAlertPanel @"Hello!" @"Hello, World!" @"Hi!" @"Hello!" @"Go Away")] (defparameter *my-greeter* [[Greeter alloc] init]) [*my-button* setTarget:*my-greeter*] [*my-button* setAction:(objc:@selector "greet:")] ;; Notice: classes need to be defined before they can be read in [...] ;; forms. |# ;;;; THE END ;;;;
15,441
Common Lisp
.lisp
373
37.785523
85
0.686318
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
9d85cba9e9c8770fc248908c36d765d3da3bd445298a7c499bb8f0ceba64b8d6
4,945
[ -1 ]
4,946
cocoa.lisp
informatimago_lisp/objcl/cocoa.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: cocoa.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Some fun with Objective-C and Cocoa. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-12-16 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COMMON-LISP-USER") (declaim (declaration also-use-packages)) (declaim (also-use-packages "OBJCL" "OCLO" "NS")) (defpackage "COCOA-PLAYGROUND" (:use "CL" "COM.INFORMATIMAGO.LAYOUT") (:import-from "OBJCL" "@")) (in-package "COCOA-PLAYGROUND") (objcl:set-objective-cl-syntax) (oclo:define-classname-translation "NSApplication" ns:ns-application) ;; (eval-when (:execute :compile-toplevel :load-toplevel) ;; ;; oclo:*COCOA-APPLICATION-FRAMEWORKS* ;; (oclo:load-framework "Cocoa" :cocoa) ;; (oclo:UPDATE-OBJC-METHOD-INFO)) (eval-when (:execute :compile-toplevel :load-toplevel) @[nsview subclass:icals slots: ((stack :initform (make-array 4) :accessor icals-stack))]) @[icals classmethod:(newviewwithframe:(<nsr>ect)frame) resulttype:(:id) body: [[icals alloc] initwithframe:frame]] ;; @[Icals method:(drawRect:(<NSR>ect)rect) resultType:(:void) ;; body: (let ((context [NSGraphicsContext currentContext]) ;; (bounds (oclo:stret [self bounds]))) ;; (unwind-protect ;; (progn ;; [context saveGraphicsState] ;; ;; ) ;; [context restoreGraphicsState]))] ;; For test-window: @[icals method:(greet:(:id)sender) resulttype:(:id) body: (declare (ignore sender)) (#_nsrunalertpanel @"Icals" @"Hello, World!" @"OK" @"Welcome!" @"Go Away")] @[icals method:(initwithframe:(<nsr>ect)frame) resulttype:(:id) body: (when (setf self [super initwithframe:frame]) (create-interface self) self)] @[icals method:(setstackfield:(:id #|NSTextField*|#)field atindex:(:int)index) resulttype:(:void) body: (when (<= 0 index 3) (setf (aref (icals-stack self) index) field))] @[icals method:(pressdigit:(:id)sender) resulttype:(:id) body: (let ((acc (aref (icals-stack self) 0))) [acc setintvalue:(+ [sender intvalue] (* 10 [acc intvalue]))])] @[icals method: (reporterror:(:id #|<NSS>tring|#)text) resulttype:(:id) body: nslog(@"Icals error: %@" text)] @[icals method:(pressenter:(:id)sender) resulttype:(:id) body: (declare (ignore sender)) (loop :for i :from 3 :above 0 :do [(aref (icals-stack self) i) setintvalue:[(aref (icals-stack self) (1- i)) intvalue]] :finally [(aref (icals-stack self) 0) setintvalue:0])] @[icals method:(presspop:(:id)sender) resulttype:(:id) body: (declare (ignore sender)) (loop :for i :from 0 :below 3 :do [(aref (icals-stack self) i) setintvalue:[(aref (icals-stack self) (1+ i)) intvalue]])] @[icals method:(pressoperation:(:id)sender) resulttype:(:id) body: (let ((right (aref (icals-stack self) 0)) (left (aref (icals-stack self) 1)) (op (cdr (assoc (objc:lisp-string-from-nsstring [sender stringvalue]) '(("+" . +) ("-" . -) ("*" . *) ("/" . /)) :test (function string=))))) (if op (progn [self presspop:sender] [(aref (icals-stack self) 0) setdoublevalue:(or (ignore-errors (funcall op left right)) 0)]) [self reporterror:@"Invalid Operation Button"]))] (defun create-interface (ical) ;; 7 8 9 / [ ] ;; 4 5 6 * [ ] ;; 1 2 3 - [ ] ;; P 0 E + [ ] (let ((size (make-rect))) (flet ((make-button (title action) (let ((button (make-push-button :title title :action action :target ical))) [button sizetofit] (oclo:slet ((frame [button frame])) (setf size (rect-union size frame)) (cons button frame)))) (make-field (value) (let ((field (make-text-field :frame (make-rect :x 0 :y 0 :width 120 :height 32)))) [field setstringvalue:value] (oclo:slet ((frame [field frame])) (cons field frame))))) (let ((digits (loop :for i :from 0 :to 9 :collect (make-button (objc:make-nsstring (princ-to-string i)) (objc:@selector "pressDigit:")))) (ops (loop :for op :in '("+" "-" "*" "/") :collect (make-button (objc:make-nsstring op) (objc:@selector "pressOperation:")))) (pop (make-button @"P" (objc:@selector "pressPop:"))) (enter (make-button @"E" (objc:@selector "pressEnter:"))) (fields (loop :repeat 4 :collect (make-field @"0")))) (loop :for (object . frame) :in (list* enter pop (append ops digits)) :do (setf (rect-size frame) (rect-size size))) (setf (rect-origin (cdr pop)) (make-point :x 20 :y 20)) (stack-up (mapcar (function cdr) (list pop (elt digits 1) (elt digits 4) (elt digits 7))) :align :center :spacing 6) (place (elt digits 0) (right-of pop 6)) (stack-up (mapcar (function cdr) (list (elt digits 0) (elt digits 2) (elt digits 5) (elt digits 8))) :align :center :spacing 6) (place enter (right-of (elt digits 0) 6)) (stack-up (mapcar (function cdr) (list enter (elt digits 3) (elt digits 6) (elt digits 9))) :align :center :spacing 6) (place (first ops) (right-of enter 6)) (stack-up (mapcar (function cdr) ops) :align :center :spacing 6) (place (first fields) (right-of (first ops) 12)) (stack-up (mapcar (function cdr) fields) :align :center :spacing 6) (loop :for (object . frame) :in (list* enter pop (append ops digits fields)) :do (progn [object setframe:frame] [ical addsubview:object])) (loop :for i :from 0 :for (field . frame) :in fields :do [ical setstackfield:field atindex:i]))))) (defconstant yes 1) (defconstant no 0) (defconstant +default-autoresizing-mask+ (logior #$nsviewminxmargin #$nsviewwidthsizable #$nsviewminymargin #$nsviewheightsizable)) (defun make-window (&key (title @"Untitled") (frame (ns:make-ns-rect 0 0 200 100)) (style-mask (logior #$nstitledwindowmask #$nsresizablewindowmask)) (order-front nil)) (let ((window [[nswindow alloc] initwithcontentrect:frame stylemask:style-mask backing:#$nsbackingstorebuffered defer:nil])) [window settitle:title] [window setautodisplay:t] [window setviewsneeddisplay:yes] [window flushwindowifneeded] (when order-front [window orderfront:nil]) window)) (defun close-window (window) [window close] [window dealloc]) (defun make-text-field (&key (frame (ns:make-ns-rect 20 50 120 32)) (title @"Field") (autoresizing-mask +default-autoresizing-mask+) target action (editable t) (selectable t)) (let ((field [[nstextfield alloc] initwithframe:frame])) [field setimageposition:#$nsnoimage] [field settitle:title] [field setautoresizingmask:autoresizing-mask] [field setenabled:yes] [field seteditable:editable] [field setselectable:selectable] (when target [field settarget:target]) (when action [field setaction:action]) field)) (defun make-push-button (&key (frame (ns:make-ns-rect 20 50 120 32)) (title @"Button") (autoresizing-mask +default-autoresizing-mask+) target action) (let ((button [[nsbutton alloc] initwithframe:frame])) [button setbuttontype:#$nsmomentarypushinbutton] [button setimageposition:#$nsnoimage] [button setbezelstyle:#$nsroundedbezelstyle] [button settitle:title] [button setautoresizingmask:autoresizing-mask] [button setenabled:yes] (when target [button settarget:target]) (when action [button setaction:action]) button)) (defun make-text-field (&key (frame (ns:make-ns-rect 20 50 120 32)) value)) (defun make-icals-window (&key (title @"Untitled") (frame (ns:make-ns-rect 0 0 200 100)) (style-mask (logior #$nstitledwindowmask #$nsresizablewindowmask)) (order-front nil)) (let ((window (make-window :title title :frame frame :style-mask style-mask :order-front order-front)) (view [icals newviewwithframe:frame])) [window setcontentview:view] [view addsubview: (make-push-button :title @"Hello" :target view :action (objc:@selector "greet:"))] window)) (defvar *window* nil) (defun make-test-window () (close-test-window) (setf *window* (make-icals-window :frame (ns:make-ns-rect 0 0 200 100) :title @"Test Window" :order-front t))) (defun close-test-window () (when *window* (close-window *window*)) (setf *window* nil)) (defun print-sorted-hash-table-keys (table) (let ((keys (make-array (hash-table-count table) :fill-pointer 0)) (klen 0)) (maphash (lambda (k v) (let ((key (prin1-to-string k))) (vector-push (cons key (prin1-to-string v)) keys) (setf klen (max klen (length key))))) table) (loop :for line :across (sort keys (function string<) :key (function car)) :do (format t "~VA ~A~%" klen (car line) (cdr line))))) #-(and) (progn (print-sorted-hash-table-keys (ccl::objc-class-map)) (print-sorted-hash-table-keys ccl::*lisp-classname-table*) (print-sorted-hash-table-keys ccl::*objc-classname-table*)) ;; [*window* setFrame:(NS:MAKE-NS-RECT 0 80 400 200) display:t animate:t] ;; ;; (defun update () ;; [[*window* contentView] setNeedsDisplay:YES] ;; [*window* setViewsNeedDisplay:YES] ;; [*window* display] ;; [*window* update] ;; [*window* flushWindowIfNeeded] ;; [[NSApplication sharedApplication] updateWindows]) ;; [NSApplication sharedApplication] ;; [[NSApplication sharedApplication] updateWindows] ;; [[NSApplication sharedApplication] currentEvent] ;; [[NSApplication sharedApplication] currentSystemPresentationOptions] ;;;; THE END ;;;;
12,684
Common Lisp
.lisp
287
34.264808
108
0.55178
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
39b363dea71a6ec3d38d50740ba4c750fa549ef8cfd7b52abeded7d10231a2ec
4,946
[ -1 ]
4,947
packages.lisp
informatimago_lisp/objcl/packages.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: packages.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Defines the packages. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-12-14 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2017 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COMMON-LISP-USER") ;; #+(and ccl ccl-1.9) ;; (let ((initialized nil)) ;; (defun ccl::open-main-bundle () ;; (if initialized ;; (#/mainBundle ns:ns-bundle) ;; (let ((mainBundle (#/mainBundle ns:ns-bundle))) ;; (#/initWithPath: mainBundle (namestring (truename ccl::*cocoa-ide-path*))))))) ;; #+(and ccl darwin) (defpackage "COM.INFORMATIMAGO.OBJECTIVE-CL.MAC-ROMAN" (:nicknames "COM.INFORMATIMAGO.OBJCL.MAC-ROMAN") (:use "COMMON-LISP") (:export "MAC-ROMAN-CHAR-P" "MAC-ROMAN-STRING-P") (:documentation " This package exports a function to check if a character is in the Mac-Roman repertoire. Copyright Pascal J. Bourguignon 2011 - 2017 This package is licensed under the GPL. See source file for details. ")) (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter *oclo-symbol-names* '("*OBJC-DESCRIPTION-MAX-LENGTH*" "@CLASS" "@SELECTOR" "DEFINE-OBJC-CLASS-METHOD" "DEFINE-OBJC-METHOD" "DEFMETHOD" "LISP-STRING-FROM-NSSTRING" "LOAD-FRAMEWORK" "MAKE-NSSTRING" "MAKE-OBJC-INSTANCE" "OBJC-CLASS" "OBJC-CLASS-OBJECT" "OBJC-MESSAGE-SEND" "OBJC-MESSAGE-SEND-STRET" "OBJC-MESSAGE-SEND-SUPER" "OBJC-MESSAGE-SEND-SUPER-STRET" "OBJC-METACLASS" "OBJC-OBJECT" "REMOVE-LISP-SLOTS" "RETURNING-FOREIGN-STRUCT" "SEND-SUPER" "SEND-SUPER/STRET" "SEND" "SEND/STRET" "WITH-AUTORELEASE-POOL" "WITH-AUTORELEASED-NSSTRINGS" #-ccl-1.9 "*COCOA-APPLICATION-FRAMEWORKS*" "@" "DEFINE-CLASSNAME-TRANSLATION" "LISP-TO-OBJC-CLASSNAME" "LISP-TO-OBJC-MESSAGE" "OBJC-TO-LISP-CLASSNAME" "OBJC-TO-LISP-MESSAGE" "SLET" "UPDATE-OBJC-METHOD-INFO")) (defparameter *oclo-ccl-symbol-names* '("UPDATE-OBJC-METHOD-INFO" "SLET" "OBJC-TO-LISP-MESSAGE" "OBJC-TO-LISP-CLASSNAME" "LISP-TO-OBJC-MESSAGE" "LISP-TO-OBJC-CLASSNAME" "DEFINE-CLASSNAME-TRANSLATION" "@" "WITH-AUTORELEASED-NSSTRINGS" "WITH-AUTORELEASE-POOL" "SEND/STRET" "SEND" "SEND-SUPER/STRET" "SEND-SUPER" "OBJC-MESSAGE-SEND-SUPER-STRET" "OBJC-MESSAGE-SEND-SUPER" "OBJC-MESSAGE-SEND-STRET" "OBJC-MESSAGE-SEND" "MAKE-OBJC-INSTANCE" "LISP-STRING-FROM-NSSTRING" "DEFMETHOD" "DEFINE-OBJC-METHOD" "DEFINE-OBJC-CLASS-METHOD" "@SELECTOR" "@CLASS" "*OBJC-DESCRIPTION-MAX-LENGTH*")) (defparameter *oclo-objc-symbol-names* '("RETURNING-FOREIGN-STRUCT" "REMOVE-LISP-SLOTS" "OBJC-OBJECT" "OBJC-METACLASS" "OBJC-CLASS-OBJECT" "OBJC-CLASS" "MAKE-NSSTRING" "LOAD-FRAMEWORK")) #-(and) (dolist (s *oclo-symbol-names*) (cond ((find-symbol s "CCL") (push s *oclo-ccl-symbol-names*)) ((find-symbol s "OBJC") (push s *oclo-objc-symbol-names*)) (t (error "~A is not found in OBJC or CCL" s)))) ) ;;eval-when (defpackage "COM.INFORMATIMAGO.OBJECTIVE-C.LOWER" (:nicknames "COM.INFORMATIMAGO.OCLO" "OCLO") (:use "CL") #+(and ccl objc-support) (:shadowing-import-from "OBJC" . #.*oclo-objc-symbol-names*) #+(and ccl objc-support) (:shadowing-import-from "CCL" . #.*oclo-ccl-symbol-names*) (:export . #.*oclo-symbol-names*) (:export "SELF" "SUPER" ;; implemented in oclo.lisp: "STRET" ;; implemented in oclo-<implementation>.lisp: "LISP-TO-OBJC-CLASSNAME-P" "OBJC-TO-LISP-CLASSNAME-P" "*NULL*" "NULLP" "SELECTOR") (:documentation " This package exports low level Objective-C stuff, basically the ccl Objective-C bridge, in a nifty single package exporting all these symbols. ")) (defpackage "COM.INFORMATIMAGO.OBJECTIVE-CL" (:nicknames "COM.INFORMATIMAGO.OBJCL" "OBJCL") (:use "COMMON-LISP" "COM.INFORMATIMAGO.OBJCL.MAC-ROMAN") ;; also use "COM.INFORMATIMAGO.OBJECTIVE-C.LOWER" as "OCLO". (:export "*OBJECTIVE-CL-READTABLE*" "*OBJC-READTABLE*" "DISABLE-OBJCL-READER-MACROS" "ENABLE-OBJCL-READER-MACROS" "SET-OBJECTIVE-CL-SYNTAX" ; deprecated; use (enable-objc-reader-macros). "READ-ERROR" "READ-ERROR-CONTROL-STRING" "READ-ERROR-ARGUMENTS" "OBJC-DEFINITION-READER-MACRO" ; #\@ "OBJC-EXPRESSION-READER-MACRO" ; #\[ "@" ; macro to make NSString literals with unicode. "OBJC-STRING" "LISP-STRING" #|deprecated:|# "OBJCL-STRING" "YES" "NO") (:documentation " This package exports a readtable with a couple of reader macros to read Objective-C bracketed expressions, and @\"\" strings. ")) ;;;; THE END ;;;;
5,984
Common Lisp
.lisp
160
33.36875
90
0.643005
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
4e1431a0d21f33600758293b89927dfaa0151d001eee7fde28ee3557fe222640
4,947
[ -1 ]
4,948
test.lisp
informatimago_lisp/objcl/test.lisp
;; -*- mode:lisp; coding:utf-8 -*- (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (eval-when (:compile-toplevel) (print @"ASCII test string.") (print @"ISO-8859-1 test string, c'est bientôt l'été.") (print @"Unicodde test string, λαμβδα!") (print (class-of @"ASCII test string.")) (print (class-of @"ISO-8859-1 test string, c'est bientôt l'été.")) (print (class-of @"Unicodde test string, λαμβδα!")) (print (find-method (function make-load-form) nil (list (class-of @"ASCII test string.")) nil)) (print (find-method (function make-load-form) nil (list (class-of @"ISO-8859-1 test string, c'est bientôt l'été.")) nil)) (print (find-method (function make-load-form) nil (list (class-of @"Unicode test string, λαμβδα!")) nil)) (terpri)) (defvar *test-1* @"ASCII test string.") (defvar *test-2* @"ISO-8859-1 test string, c'est bientôt l'été.") (defvar *test-3* @"Unicodde test string, λαμβδα!")
1,003
Common Lisp
.lisp
17
54.294118
123
0.68254
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
b54d8e8bdf634d73ffc73484d39ca6344d6159669a9d78658f150eca5b816d58
4,948
[ -1 ]
4,949
objc.lisp
informatimago_lisp/objcl/gnu/objc.lisp
(eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COM.INFORMATIMAGO.OBJC.GNU") ;;; This file was automatically generated by SWIG (http://www.swig.org). ;;; Version 2.0.7 ;;; ;;; Do not make changes to this file unless you know what you are doing--modify ;;; the SWIG interface file instead. ;;;SWIG wrapper code starts here (cl:defmacro defanonenum (cl:&body enums) "Converts anonymous enums to defconstants." `(cl:progn ,@(cl:loop for value in enums for index = 0 then (cl:1+ index) when (cl:listp value) do (cl:setf index (cl:second value) value (cl:first value)) collect `(cl:defconstant ,value ,index)))) (cl:eval-when (:compile-toplevel :load-toplevel) (cl:unless (cl:fboundp 'swig-lispify) (cl:defun swig-lispify (name flag cl:&optional (package cl:*package*)) (cl:labels ((helper (lst last rest cl:&aux (c (cl:car lst))) (cl:cond ((cl:null lst) rest) ((cl:upper-case-p c) (helper (cl:cdr lst) 'upper (cl:case last ((lower digit) (cl:list* c #\- rest)) (cl:t (cl:cons c rest))))) ((cl:lower-case-p c) (helper (cl:cdr lst) 'lower (cl:cons (cl:char-upcase c) rest))) ((cl:digit-char-p c) (helper (cl:cdr lst) 'digit (cl:case last ((upper lower) (cl:list* c #\- rest)) (cl:t (cl:cons c rest))))) ((cl:char-equal c #\_) (helper (cl:cdr lst) '_ (cl:cons #\- rest))) (cl:t (cl:error "Invalid character: ~A" c))))) (cl:let ((fix (cl:case flag ((constant enumvalue) "+") (variable "*") (cl:t "")))) (cl:intern (cl:concatenate 'cl:string fix (cl:nreverse (helper (cl:concatenate 'cl:list name) cl:nil cl:nil)) fix) package)))))) ;;;SWIG wrapper code ends here (cffi:defcfun ("objc_msg_lookup" objc_msg_lookup) :pointer (receiver :pointer) (op :pointer)) (cffi:defcstruct objc_super (self :pointer) (super_class :pointer)) (cffi:defcfun ("objc_msg_lookup_super" objc_msg_lookup_super) :pointer (super :pointer) (sel :pointer)) (cffi:defcvar ("__objc_msg_forward" __objc_msg_forward) :pointer) (cffi:defcvar ("__objc_msg_forward2" __objc_msg_forward2) :pointer) (cffi:defcfun ("objc_exception_throw" objc_exception_throw) :void (exception :pointer)) (cffi:defctype objc_exception_matcher :pointer) (cffi:defcfun ("objc_setExceptionMatcher" objc_setExceptionMatcher) :pointer (new_matcher :pointer)) (cffi:defctype objc_uncaught_exception_handler :pointer) (cffi:defcfun ("objc_setUncaughtExceptionHandler" objc_setUncaughtExceptionHandler) :pointer (new_handler :pointer)) (cffi:defcfun ("objc_sync_enter" objc_sync_enter) :int (object :pointer)) (cffi:defcfun ("objc_sync_exit" objc_sync_exit) :int (object :pointer)) (defanonenum (OBJC_SYNC_SUCCESS #.0) (OBJC_SYNC_NOT_OWNING_THREAD_ERROR #.-1) (OBJC_SYNC_TIMED_OUT #.-2) (OBJC_SYNC_NOT_INITIALIZED #.-3)) (cl:defconstant __GNU_LIBOBJC__ 20110608) (cffi:defctype BOOL :unsigned-char) (cffi:defctype SEL :pointer) (cffi:defctype Class :pointer) (cffi:defcstruct objc_object (class_pointer :pointer)) (cffi:defctype id :pointer) (cffi:defctype IMP :pointer) (cffi:defctype Protocol (:struct objc_object)) (cffi:defctype Ivar :pointer) (cffi:defctype Property :pointer) (cffi:defctype objc_property_t :pointer) (cffi:defctype Method :pointer) (cffi:defctype Category :pointer) (cffi:defcstruct objc_method_description (name :pointer) (types :string)) (cl:defconstant _F_CONST #x01) (cl:defconstant _F_IN #x01) (cl:defconstant _F_OUT #x02) (cl:defconstant _F_INOUT #x03) (cl:defconstant _F_BYCOPY #x04) (cl:defconstant _F_BYREF #x08) (cl:defconstant _F_ONEWAY #x10) (cl:defconstant _F_GCINVISIBLE #x20) (cffi:defcfun ("object_getClass" object_getClass) :pointer (object :pointer)) (cffi:defcfun ("sel_getName" sel_getName) :string (selector :pointer)) (cffi:defcfun ("sel_getTypeEncoding" sel_getTypeEncoding) :string (selector :pointer)) (cffi:defcfun ("sel_getUid" sel_getUid) :pointer (name :string)) (cffi:defcfun ("sel_registerName" sel_registerName) :pointer (name :string)) (cffi:defcfun ("sel_registerTypedName" sel_registerTypedName) :pointer (name :string) (type :string)) (cffi:defcfun ("sel_isEqual" sel_isEqual) :unsigned-char (first_selector :pointer) (second_selector :pointer)) (cffi:defcfun ("sel_copyTypedSelectorList" sel_copyTypedSelectorList) :pointer (name :string) (numberOfReturnedSelectors :pointer)) (cffi:defcfun ("sel_getTypedSelector" sel_getTypedSelector) :pointer (name :string)) (cffi:defcfun ("class_createInstance" class_createInstance) :pointer (class_ :pointer) (extraBytes :pointer)) (cffi:defcfun ("object_copy" object_copy) :pointer (object :pointer) (extraBytes :pointer)) (cffi:defcfun ("object_dispose" object_dispose) :pointer (object :pointer)) (cffi:defcfun ("object_getClassName" object_getClassName) :string (object :pointer)) (cffi:defcfun ("object_setClass" object_setClass) :pointer (object :pointer) (class_ :pointer)) (cffi:defcfun ("class_getInstanceVariable" class_getInstanceVariable) :pointer (class_ :pointer) (name :string)) (cffi:defcfun ("class_getClassVariable" class_getClassVariable) :pointer (class_ :pointer) (name :string)) (cffi:defcfun ("object_getIndexedIvars" object_getIndexedIvars) :pointer (object :pointer)) (cffi:defcfun ("object_getInstanceVariable" object_getInstanceVariable) :pointer (object :pointer) (name :string) (returnValue :pointer)) (cffi:defcfun ("object_setInstanceVariable" object_setInstanceVariable) :pointer (object :pointer) (name :string) (newValue :pointer)) (cffi:defcfun ("object_getIvar" object_getIvar) :pointer (object :pointer) (variable :pointer)) (cffi:defcfun ("object_setIvar" object_setIvar) :void (object :pointer) (variable :pointer) (value :pointer)) (cffi:defcfun ("ivar_getName" ivar_getName) :string (variable :pointer)) (cffi:defcfun ("ivar_getOffset" ivar_getOffset) :pointer (variable :pointer)) (cffi:defcfun ("ivar_getTypeEncoding" ivar_getTypeEncoding) :string (variable :pointer)) (cffi:defcfun ("class_copyIvarList" class_copyIvarList) :pointer (class_ :pointer) (numberOfReturnedIvars :pointer)) (cffi:defcfun ("class_addIvar" class_addIvar) :unsigned-char (class_ :pointer) (ivar_name :string) (size :pointer) (log_2_of_alignment :unsigned-char) (type :string)) (cffi:defcfun ("property_getName" property_getName) :string (property :pointer)) (cffi:defcfun ("property_getAttributes" property_getAttributes) :string (property :pointer)) (cffi:defcfun ("class_getProperty" class_getProperty) :pointer (class_ :pointer) (propertyName :string)) (cffi:defcfun ("class_copyPropertyList" class_copyPropertyList) :pointer (class_ :pointer) (numberOfReturnedProperties :pointer)) (cffi:defcfun ("class_getIvarLayout" class_getIvarLayout) :string (class_ :pointer)) (cffi:defcfun ("class_getWeakIvarLayout" class_getWeakIvarLayout) :string (class_ :pointer)) (cffi:defcfun ("class_setIvarLayout" class_setIvarLayout) :void (class_ :pointer) (layout :string)) (cffi:defcfun ("class_setWeakIvarLayout" class_setWeakIvarLayout) :void (class_ :pointer) (layout :string)) (cffi:defctype objc_get_unknown_class_handler :pointer) (cffi:defcfun ("objc_setGetUnknownClassHandler" objc_setGetUnknownClassHandler) :pointer (new_handler :pointer)) (cffi:defcfun ("objc_getClass" objc_getClass) :pointer (name :string)) (cffi:defcfun ("objc_lookUpClass" objc_lookUpClass) :pointer (name :string)) (cffi:defcfun ("objc_getMetaClass" objc_getMetaClass) :pointer (name :string)) (cffi:defcfun ("objc_getRequiredClass" objc_getRequiredClass) :pointer (name :string)) (cffi:defcfun ("objc_getClassList" objc_getClassList) :int (returnValue :pointer) (maxNumberOfClassesToReturn :int)) (cffi:defcfun ("class_getName" class_getName) :string (class_ :pointer)) (cffi:defcfun ("class_isMetaClass" class_isMetaClass) :unsigned-char (class_ :pointer)) (cffi:defcfun ("class_getSuperclass" class_getSuperclass) :pointer (class_ :pointer)) (cffi:defcfun ("class_getVersion" class_getVersion) :int (class_ :pointer)) (cffi:defcfun ("class_setVersion" class_setVersion) :void (class_ :pointer) (version :int)) (cffi:defcfun ("class_getInstanceSize" class_getInstanceSize) :pointer (class_ :pointer)) (cffi:defcfun ("method_setImplementation" method_setImplementation) :pointer (method :pointer) (implementation :pointer)) (cffi:defcfun ("method_exchangeImplementations" method_exchangeImplementations) :void (method_a :pointer) (method_b :pointer)) (cffi:defcfun ("objc_allocateClassPair" objc_allocateClassPair) :pointer (super_class :pointer) (class_name :string) (extraBytes :int)) (cffi:defcfun ("objc_registerClassPair" objc_registerClassPair) :void (class_ :pointer)) (cffi:defcfun ("objc_disposeClassPair" objc_disposeClassPair) :void (class_ :pointer)) (cffi:defcfun ("class_getInstanceMethod" class_getInstanceMethod) :pointer (class_ :pointer) (selector :pointer)) (cffi:defcfun ("class_getClassMethod" class_getClassMethod) :pointer (class_ :pointer) (selector :pointer)) (cffi:defcfun ("class_getMethodImplementation" class_getMethodImplementation) :pointer (class_ :pointer) (selector :pointer)) (cffi:defcfun ("class_respondsToSelector" class_respondsToSelector) :unsigned-char (class_ :pointer) (selector :pointer)) (cffi:defcfun ("class_addMethod" class_addMethod) :unsigned-char (class_ :pointer) (selector :pointer) (implementation :pointer) (method_types :string)) (cffi:defcfun ("class_replaceMethod" class_replaceMethod) :pointer (class_ :pointer) (selector :pointer) (implementation :pointer) (method_types :string)) (cffi:defcfun ("method_getName" method_getName) :pointer (method :pointer)) (cffi:defcfun ("method_getImplementation" method_getImplementation) :pointer (method :pointer)) (cffi:defcfun ("method_getTypeEncoding" method_getTypeEncoding) :string (method :pointer)) (cffi:defcfun ("method_getDescription" method_getDescription) :pointer (method :pointer)) (cffi:defcfun ("class_copyMethodList" class_copyMethodList) :pointer (class_ :pointer) (numberOfReturnedMethods :pointer)) (cffi:defcfun ("method_getNumberOfArguments" method_getNumberOfArguments) :unsigned-int (method :pointer)) (cffi:defcfun ("method_copyReturnType" method_copyReturnType) :string (method :pointer)) (cffi:defcfun ("method_copyArgumentType" method_copyArgumentType) :string (method :pointer) (argumentNumber :unsigned-int)) (cffi:defcfun ("method_getReturnType" method_getReturnType) :void (method :pointer) (returnValue :string) (returnValueSize :pointer)) (cffi:defcfun ("method_getArgumentType" method_getArgumentType) :void (method :pointer) (argumentNumber :unsigned-int) (returnValue :string) (returnValueSize :pointer)) (cffi:defcfun ("objc_getProtocol" objc_getProtocol) :pointer (name :string)) (cffi:defcfun ("objc_copyProtocolList" objc_copyProtocolList) :pointer (numberOfReturnedProtocols :pointer)) (cffi:defcfun ("class_addProtocol" class_addProtocol) :unsigned-char (class_ :pointer) (protocol :pointer)) (cffi:defcfun ("class_conformsToProtocol" class_conformsToProtocol) :unsigned-char (class_ :pointer) (protocol :pointer)) (cffi:defcfun ("class_copyProtocolList" class_copyProtocolList) :pointer (class_ :pointer) (numberOfReturnedProtocols :pointer)) (cffi:defcfun ("protocol_conformsToProtocol" protocol_conformsToProtocol) :unsigned-char (protocol :pointer) (anotherProtocol :pointer)) (cffi:defcfun ("protocol_isEqual" protocol_isEqual) :unsigned-char (protocol :pointer) (anotherProtocol :pointer)) (cffi:defcfun ("protocol_getName" protocol_getName) :string (protocol :pointer)) (cffi:defcfun ("protocol_getMethodDescription" protocol_getMethodDescription) (:pointer (:struct objc_method_description)) (protocol :pointer) (selector :pointer) (requiredMethod :unsigned-char) (instanceMethod :unsigned-char)) (cffi:defcfun ("protocol_copyMethodDescriptionList" protocol_copyMethodDescriptionList) :pointer (protocol :pointer) (requiredMethod :unsigned-char) (instanceMethod :unsigned-char) (numberOfReturnedMethods :pointer)) (cffi:defcfun ("protocol_getProperty" protocol_getProperty) :pointer (protocol :pointer) (propertyName :string) (requiredProperty :unsigned-char) (instanceProperty :unsigned-char)) (cffi:defcfun ("protocol_copyPropertyList" protocol_copyPropertyList) :pointer (protocol :pointer) (numberOfReturnedProperties :pointer)) (cffi:defcfun ("protocol_copyProtocolList" protocol_copyProtocolList) :pointer (protocol :pointer) (numberOfReturnedProtocols :pointer)) (cffi:defcvar ("_objc_load_callback" _objc_load_callback) :pointer) (cffi:defcfun ("objc_enumerationMutation" objc_enumerationMutation) :void (collection :pointer)) (cffi:defcfun ("objc_setEnumerationMutationHandler" objc_setEnumerationMutationHandler) :void (handler :pointer)) (cffi:defcfun ("objc_malloc" objc_malloc) :pointer (size :pointer)) (cffi:defcfun ("objc_atomic_malloc" objc_atomic_malloc) :pointer (size :pointer)) (cffi:defcfun ("objc_realloc" objc_realloc) :pointer (mem :pointer) (size :pointer)) (cffi:defcfun ("objc_calloc" objc_calloc) :pointer (nelem :pointer) (size :pointer)) (cffi:defcfun ("objc_free" objc_free) :void (mem :pointer)) (cffi:defcfun ("class_ivar_set_gcinvisible" class_ivar_set_gcinvisible) :void (_class :pointer) (ivarname :string) (gcInvisible :unsigned-char)) (cffi:defcfun ("objc_sizeof_type" objc_sizeof_type) :int (type :string)) (cffi:defcfun ("objc_alignof_type" objc_alignof_type) :int (type :string)) (cffi:defcfun ("objc_aligned_size" objc_aligned_size) :int (type :string)) (cffi:defcfun ("objc_promoted_size" objc_promoted_size) :int (type :string)) (cffi:defcfun ("objc_skip_type_qualifiers" objc_skip_type_qualifiers) :string (type :string)) (cffi:defcfun ("objc_skip_typespec" objc_skip_typespec) :string (type :string)) (cffi:defcfun ("objc_skip_offset" objc_skip_offset) :string (type :string)) (cffi:defcfun ("objc_skip_argspec" objc_skip_argspec) :string (type :string)) (cffi:defcfun ("objc_get_type_qualifiers" objc_get_type_qualifiers) :unsigned-int (type :string)) (cffi:defcstruct objc_struct_layout (original_type :string) (type :string) (prev_type :string) (record_size :unsigned-int) (record_align :unsigned-int)) (cffi:defcfun ("objc_layout_structure" objc_layout_structure) :void (type :string) (layout :pointer)) (cffi:defcfun ("objc_layout_structure_next_member" objc_layout_structure_next_member) :unsigned-char (layout :pointer)) (cffi:defcfun ("objc_layout_finish_structure" objc_layout_finish_structure) :void (layout :pointer) (size :pointer) (align :pointer)) (cffi:defcfun ("objc_layout_structure_get_info" objc_layout_structure_get_info) :void (layout :pointer) (offset :pointer) (align :pointer) (type :pointer)) (cffi:defcvar ("__objc_thread_exit_status" __objc_thread_exit_status) :int) (cl:defconstant OBJC_THREAD_INTERACTIVE_PRIORITY 2) (cl:defconstant OBJC_THREAD_BACKGROUND_PRIORITY 1) (cl:defconstant OBJC_THREAD_LOW_PRIORITY 0) (cffi:defctype objc_thread_t :pointer) (cffi:defcstruct objc_mutex (owner :pointer) (depth :int) (backend :pointer)) (cffi:defctype objc_mutex_t :pointer) (cffi:defcstruct objc_condition (backend :pointer)) (cffi:defctype objc_condition_t :pointer) (cffi:defcfun ("objc_mutex_allocate" objc_mutex_allocate) :pointer) (cffi:defcfun ("objc_mutex_deallocate" objc_mutex_deallocate) :int (mutex :pointer)) (cffi:defcfun ("objc_mutex_lock" objc_mutex_lock) :int (mutex :pointer)) (cffi:defcfun ("objc_mutex_unlock" objc_mutex_unlock) :int (mutex :pointer)) (cffi:defcfun ("objc_mutex_trylock" objc_mutex_trylock) :int (mutex :pointer)) (cffi:defcfun ("objc_condition_allocate" objc_condition_allocate) :pointer) (cffi:defcfun ("objc_condition_deallocate" objc_condition_deallocate) :int (condition :pointer)) (cffi:defcfun ("objc_condition_wait" objc_condition_wait) :int (condition :pointer) (mutex :pointer)) (cffi:defcfun ("objc_condition_signal" objc_condition_signal) :int (condition :pointer)) (cffi:defcfun ("objc_condition_broadcast" objc_condition_broadcast) :int (condition :pointer)) (cffi:defcfun ("objc_thread_detach" objc_thread_detach) :pointer (selector :pointer) (object :pointer) (argument :pointer)) (cffi:defcfun ("objc_thread_yield" objc_thread_yield) :void) (cffi:defcfun ("objc_thread_exit" objc_thread_exit) :int) (cffi:defcfun ("objc_thread_set_priority" objc_thread_set_priority) :int (priority :int)) (cffi:defcfun ("objc_thread_get_priority" objc_thread_get_priority) :int) (cffi:defcfun ("objc_thread_get_data" objc_thread_get_data) :pointer) (cffi:defcfun ("objc_thread_set_data" objc_thread_set_data) :int (value :pointer)) (cffi:defcfun ("objc_thread_id" objc_thread_id) :pointer) (cffi:defcfun ("objc_thread_add" objc_thread_add) :void) (cffi:defcfun ("objc_thread_remove" objc_thread_remove) :void) (cffi:defctype objc_thread_callback :pointer) (cffi:defcfun ("objc_set_thread_callback" objc_set_thread_callback) :pointer (func :pointer)) (cffi:defcfun ("__objc_init_thread_system" __objc_init_thread_system) :int) (cl:defconstant _C_ID #\@) (cl:defconstant _C_CLASS #\#) (cl:defconstant _C_SEL #\:) (cl:defconstant _C_CHR #\c) (cl:defconstant _C_UCHR #\C) (cl:defconstant _C_SHT #\s) (cl:defconstant _C_USHT #\S) (cl:defconstant _C_INT #\i) (cl:defconstant _C_UINT #\I) (cl:defconstant _C_LNG #\l) (cl:defconstant _C_ULNG #\L) (cl:defconstant _C_LNG_LNG #\q) (cl:defconstant _C_ULNG_LNG #\Q) (cl:defconstant _C_FLT #\f) (cl:defconstant _C_DBL #\d) (cl:defconstant _C_LNG_DBL #\D) (cl:defconstant _C_BFLD #\b) (cl:defconstant _C_BOOL #\B) (cl:defconstant _C_VOID #\v) (cl:defconstant _C_UNDEF #\?) (cl:defconstant _C_PTR #\^) (cl:defconstant _C_CHARPTR #\*) (cl:defconstant _C_ARY_B #\[) (cl:defconstant _C_ARY_E #\]) (cl:defconstant _C_UNION_B #\() (cl:defconstant _C_UNION_E #\)) (cl:defconstant _C_STRUCT_B #\{) (cl:defconstant _C_STRUCT_E #\}) (cl:defconstant _C_VECTOR #\!) (cl:defconstant _C_COMPLEX #\j) (cl:defconstant _C_ATOM #\%) (cl:defconstant _C_CONST #\r) (cl:defconstant _C_IN #\n) (cl:defconstant _C_INOUT #\N) (cl:defconstant _C_BYCOPY #\O) (cl:defconstant _C_BYREF #\R) (cl:defconstant _C_ONEWAY #\V) (cl:defconstant _C_GCINVISIBLE #\|)
19,257
Common Lisp
.lisp
481
36.035343
100
0.72066
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
ac62da705d6b1a999fb80309954d220526e45d8d1673f015623a0eb403117e94
4,949
[ -1 ]
4,950
gnu.lisp
informatimago_lisp/objcl/gnu/gnu.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: gnu.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; CFFI interface to GNU libobjc. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2013-12-31 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2013 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.OBJC.GNU" (:use) (:export "BACKEND" "BOOL" "CATEGORY" "CLASS" "CLASS_ADDIVAR" "CLASS_ADDMETHOD" "CLASS_ADDPROTOCOL" "CLASS_CONFORMSTOPROTOCOL" "CLASS_COPYIVARLIST" "CLASS_COPYMETHODLIST" "CLASS_COPYPROPERTYLIST" "CLASS_COPYPROTOCOLLIST" "CLASS_CREATEINSTANCE" "CLASS_GETCLASSMETHOD" "CLASS_GETCLASSVARIABLE" "CLASS_GETINSTANCEMETHOD" "CLASS_GETINSTANCESIZE" "CLASS_GETINSTANCEVARIABLE" "CLASS_GETIVARLAYOUT" "CLASS_GETMETHODIMPLEMENTATION" "CLASS_GETNAME" "CLASS_GETPROPERTY" "CLASS_GETSUPERCLASS" "CLASS_GETVERSION" "CLASS_GETWEAKIVARLAYOUT" "CLASS_ISMETACLASS" "CLASS_IVAR_SET_GCINVISIBLE" "CLASS_POINTER" "CLASS_REPLACEMETHOD" "CLASS_RESPONDSTOSELECTOR" "CLASS_SETIVARLAYOUT" "CLASS_SETVERSION" "CLASS_SETWEAKIVARLAYOUT" "DEPTH" "ID" "IMP" "IVAR" "IVAR_GETNAME" "IVAR_GETOFFSET" "IVAR_GETTYPEENCODING" "METHOD" "METHOD_COPYARGUMENTTYPE" "METHOD_COPYRETURNTYPE" "METHOD_EXCHANGEIMPLEMENTATIONS" "METHOD_GETARGUMENTTYPE" "METHOD_GETDESCRIPTION" "METHOD_GETIMPLEMENTATION" "METHOD_GETNAME" "METHOD_GETNUMBEROFARGUMENTS" "METHOD_GETRETURNTYPE" "METHOD_GETTYPEENCODING" "METHOD_SETIMPLEMENTATION" "NAME" "OBJC_ALIGNED_SIZE" "OBJC_ALIGNOF_TYPE" "OBJC_ALLOCATECLASSPAIR" "OBJC_ATOMIC_MALLOC" "OBJC_CALLOC" "OBJC_CONDITION" "OBJC_CONDITION_ALLOCATE" "OBJC_CONDITION_BROADCAST" "OBJC_CONDITION_DEALLOCATE" "OBJC_CONDITION_SIGNAL" "OBJC_CONDITION_T" "OBJC_CONDITION_WAIT" "OBJC_COPYPROTOCOLLIST" "OBJC_DISPOSECLASSPAIR" "OBJC_ENUMERATIONMUTATION" "OBJC_EXCEPTION_MATCHER" "OBJC_EXCEPTION_THROW" "OBJC_FREE" "OBJC_GETCLASS" "OBJC_GETCLASSLIST" "OBJC_GETMETACLASS" "OBJC_GETPROTOCOL" "OBJC_GETREQUIREDCLASS" "OBJC_GET_TYPE_QUALIFIERS" "OBJC_GET_UNKNOWN_CLASS_HANDLER" "OBJC_LAYOUT_FINISH_STRUCTURE" "OBJC_LAYOUT_STRUCTURE" "OBJC_LAYOUT_STRUCTURE_GET_INFO" "OBJC_LAYOUT_STRUCTURE_NEXT_MEMBER" "OBJC_LOOKUPCLASS" "OBJC_MALLOC" "OBJC_METHOD_DESCRIPTION" "OBJC_MSG_LOOKUP" "OBJC_MSG_LOOKUP_SUPER" "OBJC_MUTEX" "OBJC_MUTEX_ALLOCATE" "OBJC_MUTEX_DEALLOCATE" "OBJC_MUTEX_LOCK" "OBJC_MUTEX_T" "OBJC_MUTEX_TRYLOCK" "OBJC_MUTEX_UNLOCK" "OBJC_OBJECT" "OBJC_PROMOTED_SIZE" "OBJC_PROPERTY_T" "OBJC_REALLOC" "OBJC_REGISTERCLASSPAIR" "OBJC_SETENUMERATIONMUTATIONHANDLER" "OBJC_SETEXCEPTIONMATCHER" "OBJC_SETGETUNKNOWNCLASSHANDLER" "OBJC_SETUNCAUGHTEXCEPTIONHANDLER" "OBJC_SET_THREAD_CALLBACK" "OBJC_SIZEOF_TYPE" "OBJC_SKIP_ARGSPEC" "OBJC_SKIP_OFFSET" "OBJC_SKIP_TYPESPEC" "OBJC_SKIP_TYPE_QUALIFIERS" "OBJC_STRUCT_LAYOUT" "OBJC_SUPER" "OBJC_SYNC_ENTER" "OBJC_SYNC_EXIT" "OBJC_SYNC_NOT_INITIALIZED" "OBJC_SYNC_NOT_OWNING_THREAD_ERROR" "OBJC_SYNC_SUCCESS" "OBJC_SYNC_TIMED_OUT" "OBJC_THREAD_ADD" "OBJC_THREAD_BACKGROUND_PRIORITY" "OBJC_THREAD_CALLBACK" "OBJC_THREAD_DETACH" "OBJC_THREAD_EXIT" "OBJC_THREAD_GET_DATA" "OBJC_THREAD_GET_PRIORITY" "OBJC_THREAD_ID" "OBJC_THREAD_INTERACTIVE_PRIORITY" "OBJC_THREAD_LOW_PRIORITY" "OBJC_THREAD_REMOVE" "OBJC_THREAD_SET_DATA" "OBJC_THREAD_SET_PRIORITY" "OBJC_THREAD_T" "OBJC_THREAD_YIELD" "OBJC_UNCAUGHT_EXCEPTION_HANDLER" "OBJECT_COPY" "OBJECT_DISPOSE" "OBJECT_GETCLASS" "OBJECT_GETCLASSNAME" "OBJECT_GETINDEXEDIVARS" "OBJECT_GETINSTANCEVARIABLE" "OBJECT_GETIVAR" "OBJECT_SETCLASS" "OBJECT_SETINSTANCEVARIABLE" "OBJECT_SETIVAR" "ORIGINAL_TYPE" "OWNER" "PREV_TYPE" "PROPERTY" "PROPERTY_GETATTRIBUTES" "PROPERTY_GETNAME" "PROTOCOL" "PROTOCOL_CONFORMSTOPROTOCOL" "PROTOCOL_COPYMETHODDESCRIPTIONLIST" "PROTOCOL_COPYPROPERTYLIST" "PROTOCOL_COPYPROTOCOLLIST" "PROTOCOL_GETMETHODDESCRIPTION" "PROTOCOL_GETNAME" "PROTOCOL_GETPROPERTY" "PROTOCOL_ISEQUAL" "RECORD_ALIGN" "RECORD_SIZE" "SEL" "SELF" "SEL_COPYTYPEDSELECTORLIST" "SEL_GETNAME" "SEL_GETTYPEDSELECTOR" "SEL_GETTYPEENCODING" "SEL_GETUID" "SEL_ISEQUAL" "SEL_REGISTERNAME" "SEL_REGISTERTYPEDNAME" "SUPER_CLASS" "TYPE" "TYPES" "_C_ARY_B" "_C_ARY_E" "_C_ATOM" "_C_BFLD" "_C_BOOL" "_C_BYCOPY" "_C_BYREF" "_C_CHARPTR" "_C_CHR" "_C_CLASS" "_C_COMPLEX" "_C_CONST" "_C_DBL" "_C_FLT" "_C_GCINVISIBLE" "_C_ID" "_C_IN" "_C_INOUT" "_C_INT" "_C_LNG" "_C_LNG_DBL" "_C_LNG_LNG" "_C_ONEWAY" "_C_PTR" "_C_SEL" "_C_SHT" "_C_STRUCT_B" "_C_STRUCT_E" "_C_UCHR" "_C_UINT" "_C_ULNG" "_C_ULNG_LNG" "_C_UNDEF" "_C_UNION_B" "_C_UNION_E" "_C_USHT" "_C_VECTOR" "_C_VOID" "_F_BYCOPY" "_F_BYREF" "_F_CONST" "_F_GCINVISIBLE" "_F_IN" "_F_INOUT" "_F_ONEWAY" "_F_OUT" "_OBJC_LOAD_CALLBACK" "__GNU_LIBOBJC__" "__OBJC_INIT_THREAD_SYSTEM" "__OBJC_MSG_FORWARD" "__OBJC_MSG_FORWARD2" "__OBJC_THREAD_EXIT_STATUS")) (defpackage "COM.INFORMATIMAGO.OBJC" (:use "COMMON-LISP" "COM.INFORMATIMAGO.OBJC.GNU") (:shadowing-import-from "COM.INFORMATIMAGO.OBJC.GNU" "CLASS" "METHOD" "TYPE") (:export)) (in-package "COM.INFORMATIMAGO.OBJC") (ql:quickload :cffi) (pushnew #P"/usr/lib/gcc/x86_64-linux-gnu/4.7/" cffi:*foreign-library-directories* :test (function equalp)) (cffi:use-foreign-library "libobjc.so") (load "objc.lisp") (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter *type-map* '((:id . :pointer) (:class . :pointer) (:sel . :pointer) (:imp . :pointer))) (defun objc-to-cffi-type (type) (or (cdr (assoc type *type-map*)) type)) (deftype name () '(or string symbol)) (defun namep (name) (typecase name (string name) (symbol (symbol-name name)) (otherwise nil))) (defun lisp-to-objc-classname (name) (namep name)) );eval-when (defmacro define-objc-class (name superclass ivars &rest options) (declare (ignore options)) (check-type name name) (check-type superclass name) `(create-objc-class ,(namep name) ,(namep superclass) ',(mapcar (lambda (ivar) (etypecase ivar (name (list (namep ivar) :pointer)) (cons (check-type (first ivar) name) (check-type (second ivar) (or keyword cons)) (list (namep (first ivar)) (objc-to-cffi-type (second ivar)))))) ivars))) ;; (macroexpand '(define-objc-class |Test| "Object" ;; ((i :int) ;; (name :string)))) ;; (create-objc-class "Test" "Object" '(("I" :int) ("NAME" :string))) ;; (cffi:foreign-type-size :id) (defparameter *nil* (cffi-sys:null-pointer)) (defun get-class-names () (let ((max (* 128 1024))) (cffi:with-foreign-objects ((classes 'com.informatimago.objc.gnu:class max)) (let ((nclasses (com.informatimago.objc.gnu:objc_getclasslist classes max))) (loop :for i :below (min max nclasses) :collect (com.informatimago.objc.gnu:class_getname (cffi:mem-aref classes 'com.informatimago.objc.gnu:class i))))))) (defun get-class (name) (com.informatimago.objc.gnu:objc_getclass name)) (let ((test1 (com.informatimago.objc.gnu:objc_allocateclasspair *nil* "Test1" 0))) (com.informatimago.objc.gnu:objc_registerclasspair test1) test1) (get-class "Test1") ;; (get-class "Object") ; #<A Foreign Pointer #x7F1C270E0DC0> ;; (get-class-names) ; ("NXConstantString" "Object" "Protocol") ;; (objc_allocateClassPair) #-(and) (let ((exports '())) (dolist (form (com.informatimago.common-lisp.cesarum.file:sexp-list-file-contents #P"~/src/public/lisp/objcl/gnu/objc.lisp")) (case (first form) ((in-package defmacro eval-when)) ((cffi:defcfun) (destructuring-bind (d (cn ln) &rest r) form (declare (ignore d cn r)) (push (symbol-name ln) exports))) ((cffi:defcvar) (destructuring-bind (d (cn ln) &rest r) form (declare (ignore d cn r)) (push (symbol-name ln) exports))) ((cffi:defcstruct) (destructuring-bind (d n &rest slots) form (declare (ignore d)) (push (symbol-name n) exports) (loop :for (n type) :in slots :do (push (symbol-name n) exports)))) ((defconstant cffi:defctype) (push (symbol-name (second form)) exports)) (otherwise (if (string= 'defanonenum (first form)) (loop :for value :in (rest form) :do (push (symbol-name (if (listp value) (first value) value)) exports)) (print form))))) (sort (remove-duplicates exports :test (function string=)) (function string<))) ;; (find-package "COM.INFORMATIMAGO.OBJC.GNU") #|| (cffi:foreign-library-name *libobjc*) (dolist (dir cffi:*FOREIGN-LIBRARY-DIRECTORIES*) (print (merge-pathnames (cffi:foreign-library-pathname *libobjc*) dir))) (truename (cffi:foreign-library-pathname *libobjc*)) (dolist (lib (cffi:list-foreign-libraries)) (princ-to-string lib)) (length "LIBOBJC\\.SO.4-8900") ||#
10,445
Common Lisp
.lisp
220
41.668182
107
0.653476
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
b3d78cefc42ca01722e72b6eea3184a66d63cbee1d260147dc0cc1a8daa6742f
4,950
[ -1 ]
4,951
susv3.lisp
informatimago_lisp/cl-posix/susv3.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: susv3.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: CLISP ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This packages exports SUSV3 functions. ;;;; This is the CLISP specific implementation of the SUSV3 API. ;;;; ;;;; ;;;; The Open Group Base Specifications Issue 6 ;;;; IEEE Std 1003.1, 2003 Edition ;;;; ;;;; http://www.opengroup.org/onlinepubs/007904975/index.html ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon ;;;;MODIFICATIONS ;;;; 2003-06-13 <PJB> Added dirent stuff. ;;;; 2003-05-13 <PJB> Created ;;;;BUGS ;;;; ;;;; Check if the name is correct: there is a hierarchy of specifications ;;;; in sus3. I want to avoid using #+XSI, but rather have different ;;;; interfaces: (:USE SUSV3) (:USE SUSV3-XSI). ;;;; ;;;; ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2003 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.CLISP.SUSV3" (:documentation "This packages exports SUSV3 functions. This is the CLISP specific implementation of the SUSV3 API.") (:use "COMMON-LISP" "EXT" "LINUX") (:export ;; NOT IN SUSV3 API (Lisp/C support stuff): "BOUND-STRING" ;; type (BOUND-STRING min max) "SUSV3-ERROR" ;; (SIGNAL 'SUSV3-ERROR errno) ;; "GETENV" ;; sys/types.h "INO-T" ;; sys/stat.h ;; limits.h "+NAME-MAX+" ;; dirent.h "DIR" "DIRENT" "OPENDIR" "READDIR" "REWINDDIR" "CLOSEDIR" ;; readdir_r ;; TSF ;; not implemented, do we need it? "SEEKDIR" "TELLDIR" ;; XSI ;; NOT IN SUSV3 API (TEST FUNCTIONS): "DIRENT-TEST")) (in-package "COM.INFORMATIMAGO.CLISP.SUSV3") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Lisp/C support stuff (deftype bound-string (min max) "A TYPE REPRESENTING STRINGS OF MINIMUM SIZE MIN AND MAXIMUM SIZE MAX." (if (= (eval min) (eval max)) `(string ,(eval min)) `string) ;; TODO: (OR (STRING MIN) (STRING (1+ MIN)) ... (STRING MAX)) );;BOUND-STRING (define-condition susv3-error () ( (errno :initarg :errno :accessor errno :type (signed-byte 32)) ));;SUSV3-ERROR (defmacro check-errno (&body body) `(progn (setq linux:|errno| 0) (let ((result (progn ,@body))) (if (/= 0 linux:|errno|) (signal (make-condition 'susv3-error :errno linux:|errno|)) result))) );;CHECK-ERRNO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ??? (declare (ftype (function (string) (or null string)) getenv)) (defun getenv (name) " URL: <http://www.opengroup.org/onlinepubs/007904975/functions/getenv.html> RETURN: NIL or the value of the environment variable named NAME. " (ext:getenv name) );;GETENV ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; sys/types.h (deftype ino-t () "The type of file serial numbers." `(unsigned-byte 32) );;INO-T (deftype dev-t () "Device ID." `(unsigned-byte 32) );;DEV-T (deftype mode-t () "Mode of file." `(unsigned-byte 32) );;MODE-T (deftype nlink-t () "Number of hard links to the file." `(unsigned-byte 32) );;NLINK-T (deftype uid-t () "User ID." `(unsigned-byte 32) );;UID-T (deftype gid-t () "Group ID." `(unsigned-byte 32) );;GID-T (deftype time-t () "Time in seconds since epoch." `(unsigned-byte 32) );;TIME-T ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; sys/stat.h (deftype blksize-t "" `(unsigned-byte 32) );;BLKSIZE-T (deftype blkcnt-t "" `(unsigned-byte 32) );;BLKCNT-T (defstruct stat (dev 0 :type dev-t) ;; Device ID of device containing file. (ino 0 :type ino-t) ;; File serial number. (mode 0 :type mode-t) ;; Mode of file (see below). (nlink 0 :type nlink-t) ;; Number of hard links to the file. (uid 0 :type uid-t) ;; User ID of file. (gid 0 :type gid-t) ;; Group ID of file. (rdev 0 :type dev-t) ;; XSI: Device ID (if file is char or block special). (size 0 :type off-t) ;; For regular files, the file size in bytes. ;; For symbolic links, the length in bytes of the ;; pathname contained in the symbolic link. ;; SHM: For a shared memory object, the length in bytes. ;; TYM: For a typed memory object, the length in bytes. ;; For other file types, the use of this field is ;; unspecified. (atime 0 :type time-t) ;; Time of last access. (mtime 0 :type time-t) ;; Time of last data modification. (ctime 0 :type time-t) ;; Time of last status change. (blksize 0 :type blksize-t) ;; XSI: A file system-specific preferred I/O ;; block size for this object. In some file system ;; types, this may vary from file to file. (blocks 0 :type blkcnt-t) ;; XSI: Num. of blocks allocated for this object. );;STAT ;; The st_ino and st_dev fields taken together uniquely identify the ;; file within the system. The blkcnt_t, blksize_t, dev_t, ino_t, ;; mode_t, nlink_t, uid_t, gid_t, off_t, and time_t types shall be ;; defined as described in <sys/types.h> . Times shall be given in ;; seconds since the Epoch. ;; Unless otherwise specified, the structure members st_mode, st_ino, ;; st_dev, st_uid, st_gid, st_atime, st_ctime, and st_mtime shall have ;; meaningful values for all file types defined in IEEE Std ;; 1003.1-2001. ;; For symbolic links, the st_mode member shall contain meaningful ;; information, which can be used with the file type macros described ;; below, that take a mode argument. The st_size member shall contain ;; the length, in bytes, of the pathname contained in the symbolic ;; link. File mode bits and the contents of the remaining members of ;; the stat structure are unspecified. The value returned in the ;; st_size field shall be the length of the contents of the symbolic ;; link, and shall not count a trailing null if one is present. ;; The following symbolic names for the values of type mode_t shall ;; also be defined. ;; File type: ;; ;; S_IFMT ;; [XSI] [Option Start] Type of file. ;; ;; S_IFBLK ;; Block special.S_IFCHR ;; Character special.S_IFIFO ;; FIFO special.S_IFREG ;; Regular.S_IFDIR ;; Directory.S_IFLNK ;; Symbolic link.S_IFSOCK ;; Socket. [Option End] (defconstant s-ifmt #o0170000) (defconstant s-ifdir #o040000) (defconstant s-ifchr #o020000) (defconstant s-ifblk #o060000) (defconstant s-ifreg #o100000) (defconstant s-ififo #o010000) (defconstant s-iflnk #o120000) (defconstant s-ifsock #o140000) ;; File mode bits: ;; ;; S_IRWXU ;; Read, write, execute/search by owner. ;; ;; S_IRUSR ;; Read permission, owner.S_IWUSR ;; Write permission, owner.S_IXUSR ;; Execute/search permission, owner. ;; S_IRWXG ;; Read, write, execute/search by group. ;; ;; S_IRGRP ;; Read permission, group.S_IWGRP ;; Write permission, group.S_IXGRP ;; Execute/search permission, group. ;; S_IRWXO ;; Read, write, execute/search by others. ;; ;; S_IROTH ;; Read permission, others.S_IWOTH ;; Write permission, others.S_IXOTH ;; Execute/search permission, others. ;; S_ISUID ;; Set-user-ID on execution.S_ISGID ;; Set-group-ID on execution.S_ISVTX ;; [XSI] [Option Start] On directories, restricted deletion flag. [Option End] ;; The bits defined by S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP, ;; S_IXGRP, S_IROTH, S_IWOTH, S_IXOTH, S_ISUID, S_ISGID, [XSI] [Option ;; Start] and S_ISVTX [Option End] shall be unique. ;; S_IRWXU is the bitwise-inclusive OR of S_IRUSR, S_IWUSR, and S_IXUSR. ;; ;; S_IRWXG is the bitwise-inclusive OR of S_IRGRP, S_IWGRP, and S_IXGRP. ;; ;; S_IRWXO is the bitwise-inclusive OR of S_IROTH, S_IWOTH, and S_IXOTH. ;; Implementations may OR other implementation-defined bits into ;; S_IRWXU, S_IRWXG, and S_IRWXO, but they shall not overlap any of ;; the other bits defined in this volume of IEEE Std 1003.1-2001. The ;; file permission bits are defined to be those corresponding to the ;; bitwise-inclusive OR of S_IRWXU, S_IRWXG, and S_IRWXO. (defconstant s-isuid #o004000) (defconstant s-isgid #o002000) (defconstant s-isvtx #o001000) (define-symbol-macro s-iread s-irusr) (define-symbol-macro s-iwrite s-iwusr) (define-symbol-macro s-iexec s-ixusr) (defconstant s-irusr #o000400) (defconstant s-iwusr #o000200) (defconstant s-ixusr #o000100) (defconstant s-irwxu (logior s-irusr s-iwusr s-ixusr)) (defconstant s-irgrp #o000040) (defconstant s-iwgrp #o000020) (defconstant s-ixgrp #o000010) (defconstant s-irwxg (logior s-irgrp s-iwgrp s-ixgrp)) (defconstant s-iroth #o000004) (defconstant s-iwoth #o000002) (defconstant s-ixoth #o000001) (defconstant s-irwxo (logior s-iroth s-iwoth s-ixoth)) ;; The following macros shall be provided to test whether a file is of ;; the specified type. The value m supplied to the macros is the value ;; of st_mode from a stat structure. The macro shall evaluate to a ;; non-zero value if the test is true; 0 if the test is false. ;; S_ISBLK(m) ;; ;; Test for a block special file.S_ISCHR(m) ;; Test for a character special file.S_ISDIR(m) ;; Test for a directory.S_ISFIFO(m) ;; Test for a pipe or FIFO special file.S_ISREG(m) ;; Test for a regular file.S_ISLNK(m) ;; Test for a symbolic link.S_ISSOCK(m) ;; Test for a socket. (defmacro s-isdir (m) `(= (logand ,m s-ifmt) s-ifdir)) (defmacro s-ischr (m) `(= (logand ,m s-ifmt) s-ifchr)) (defmacro s-isblk (m) `(= (logand ,m s-ifmt) s-ifblk)) (defmacro s-isreg (m) `(= (logand ,m s-ifmt) s-ifreg)) (defmacro s-isfifo (m) `(= (logand ,m s-ifmt) s-iffifo)) (defmacro s-islnk (m) `(= (logand ,m s-ifmt) s-iflnk)) (defmacro s-issock (m) `(= (logand ,m s-ifmt) s-ifsock)) ;; The implementation may implement message queues, semaphores, or ;; shared memory objects as distinct file types. The following macros ;; shall be provided to test whether a file is of the specified ;; type. The value of the buf argument supplied to the macros is a ;; pointer to a stat structure. The macro shall evaluate to a non-zero ;; value if the specified object is implemented as a distinct file ;; type and the specified file type is contained in the stat structure ;; referenced by buf. Otherwise, the macro shall evaluate to zero. ;; S_TYPEISMQ(buf) ;; Test for a message queue.S_TYPEISSEM(buf) ;; Test for a semaphore.S_TYPEISSHM(buf) ;; Test for a shared memory object. ;; [TYM] [Option Start] The implementation may implement typed memory ;; objects as distinct file types, and the following macro shall test ;; whether a file is of the specified type. The value of the buf ;; argument supplied to the macros is a pointer to a stat ;; structure. The macro shall evaluate to a non-zero value if the ;; specified object is implemented as a distinct file type and the ;; specified file type is contained in the stat structure referenced ;; by buf. Otherwise, the macro shall evaluate to zero. ;; S_TYPEISTMO(buf) ;; Test macro for a typed memory object. ;; [Option End] ;; The following shall be declared as functions and may also be ;; defined as macros. Function prototypes shall be provided. ;; int chmod(const char *, mode_t); ;; int fchmod(int, mode_t); ;; int fstat(int, struct stat *); ;; int lstat(const char *restrict, struct stat *restrict); ;; int mkdir(const char *, mode_t); ;; int mkfifo(const char *, mode_t); ;; [XSI][Option Start] ;; int mknod(const char *, mode_t, dev_t); ;; [Option End] ;; int stat(const char *restrict, struct stat *restrict); ;; mode_t umask(mode_t); (declare (ftype (function (string mode-t) nil) chmod) (ftype (function (integer mode-t) nil) fchmod) (ftype (function (integer) stat) fstat) (ftype (function (string) stat) lstat) (ftype (function (string) stat) stat) (ftype (function (string mode-t) nil) mkdir) (ftype (function (string mode-t) nil) mkfifo) (ftype (function (mode-t) mode-t) umask) ) (declare ;; XSI (ftype (function (string mode-t dev-t) nil) mknod) ) (defun chmod (path mode) (check-errno (linux:|chmod| path mode)) (values) );;CHMOD (defun fchmod (fd mode) (check-errno (linux:|fchmod| fd mode)) (values) );;FCHMOD (defmacro linux-stat->susv3-stat (sb) " PRIVATE " `(make-stat :dev (linux:|stat-st_dev| ,sb) :ino (linux:|stat-st_ino| ,sb) :mode (linux:|stat-st_mode| ,sb) :nlink (linux:|stat-st_nlink| ,sb) :uid (linux:|stat-st_uid| ,sb) :gid (linux:|stat-st_gid| ,sb) :rdev (linux:|stat-st_rdev| ,sb) :size (linux:|stat-st_size| ,sb) :atime (linux:|stat-st_atime| ,sb) :mtime (linux:|stat-st_mtime| ,sb) :ctime (linux:|stat-st_ctime| ,sb) :blksize (linux:|stat-st_blksize| ,sb) :blocks (linux:|stat-st_blocks| ,sb)) );;LINUX-STAT->SUSV3-STAT (defun stat (path) (linux-stat->susv3-stat (check-errno (linux:|stat| path))) );;STAT (defun lstat (path) (linux-stat->susv3-stat (check-errno (linux:|lstat| path))) );;LSTAT (defun fstat (fd) (linux-stat->susv3-stat (check-errno (linux:|fstat| fd))) );;FSTAT (defun mkdir (path mode) (check-errno (linux:|mkdir| path mode)) (values) );;MKDIR (defun mkfifo (path mode) (check-errno (linux:|mkfifo| path mode)) (values) );;MKFIFO (defun umask (mode) (linux:|umask| mode) );;UMASK ;;XSI (defun mknod (path mode device) (check-errno (linux:|mknod| path mode device)) (values) );;MKNOD ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; dirent.h (defconstant +name-max+ 255) (deftype dir () "A type representing a directory stream." `t );;DIR (defstruct dirent (ino 0 :type ino-t) ;; File serial number (name "" :type (bound-string 0 +name-max+)) ;; Name of entry );;DIRENT (declaim (ftype (function (dir) integer) closedir) (ftype (function (string) (or null dir)) opendir) (ftype (function (dir) (or null dirent)) readdir) (ftype (function (dir) nil) rewinddir) ) (declaim ;; XSI (ftype (function (dir integer) nil) seekdir) (ftype (function (dir) integer) telldir) ) (defun opendir (path) (check-errno (linux:|opendir| path)) );;OPENDIR (defun closedir (dir-stream) (check-errno (linux:|closedir| dir-stream)) );;CLOSEDIR (defun readdir (dir-stream) (let ((c-dirent (check-errno (linux:|readdir| dir-stream)))) (and c-dirent (make-dirent :ino (linux::|dirent-d_ino| c-dirent) :name (linux::|dirent-d_name| c-dirent)))) );;READDIR (defun rewinddir (dir-stream) (check-errno (linux:|rewinddir| dir-stream)) (values) );;REWINDDIR (defun seekdir (dir-stream position) (check-errno (linux:|seekdir| dir-stream position)) (values) );;SEEKDIR (defun telldir (dir-stream) (check-errno (linux:|telldir| dir-stream)) );;TELLDIR (defun dirent-test () (do* ((dir-stream (opendir "/tmp")) (entry (readdir dir-stream) (readdir dir-stream))) ((null entry)) (format t "entry: ~8D ~S~%" (dirent-ino entry) (dirent-name entry))) );;DIRENT-TEST ;;;; THE END ;;;;
16,247
Common Lisp
.lisp
438
34.678082
83
0.649566
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
1c2a061a65510279d0e09349b4e3f95faceef6446dd945f9a1401dbbff7dcd81
4,951
[ -1 ]
4,952
gen-lib-graph.lisp
informatimago_lisp/common-lisp/gen-lib-graph.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: gen-lib-graph.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This file scans all the .asd files in this library and ;;;; generates a GrafViz .dot files showing their dependencies. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-11-01 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COMMON-LISP-USER") (require 'asdf) (setf asdf:*central-registry* (append (remove-duplicates (mapcar (lambda (path) (make-pathname :name nil :type nil :version nil :defaults path)) (directory "**/*.asd")) :test (function equalp)) asdf:*central-registry*)) (asdf:oos 'asdf:load-op :com.informatimago.common-lisp.graphviz) (defpackage "COM.INFORMATIMAGO.TOOLS.GEN-LIB-GRAPH" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.GRAPH" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.SEQUENCE" "COM.INFORMATIMAGO.COMMON-LISP.GRAPHVIZ.GRAPH-DOT")) (in-package "COM.INFORMATIMAGO.TOOLS.GEN-LIB-GRAPH") (defparameter *asd-files* (directory "*/*.asd")) (defun read-asd-file (path) (let ((*package* *package*) (result '())) (labels ((collect (sexp) (push sexp result)) (process (sexp) (cond ((atom sexp)) ((eql 'eval-when (first sexp)) (when (intersection '(:load-toplevel :execute load eval) (second sexp)) (dolist (sexp (cddr sexp)) (process sexp)))) ((eql 'progn (first sexp)) (dolist (sexp (cdr sexp)) (process sexp))) ((eql 'in-package (first sexp)) (eval sexp)) ((eql 'asdf:defsystem (first sexp)) (collect sexp))))) (with-open-file (asd path) (loop :for sexp := (ignore-errors (read asd nil asd)) :until (eql sexp asd) :do (process sexp)))) (nreverse result))) (defun asd-name (asd) (string-downcase (second asd))) (defun asd-depends-on (asd) (mapcar (function string-downcase) (getf (cddr asd) :depends-on))) (defmethod dot-label ((element element-class)) (getf (properties element) :dot-label)) (defun make-system-graph (asd-files graph-path &key test) (let* ((asds (let ((asds (mapcan (function read-asd-file) asd-files))) (if test (remove-if-not test asds) asds))) (nodes (mapcar (lambda (asd) (format *trace-output* ";; read ~A~%" (asd-name asd)) (force-output *trace-output*) (make-instance 'element-class :ident (asd-name asd) :properties (list :asd asd :dot-label (subseq (string (asd-name asd)) (length "com.informatimago.common-lisp."))))) asds)) (g (make-instance 'graph-class :edge-class 'directed-edge-class))) (add-nodes g nodes) (loop :for node :in nodes :for dependencies = (mapcar (lambda (asd-name) (find asd-name nodes :test (function equal) :key (lambda (node) (asd-name (get-property node :asd))))) (asd-depends-on (get-property node :asd))) :do (loop :for dependency :in dependencies :when dependency :do (format *trace-output* "~A -> ~A~%" (dot-label node) (dot-label dependency)) (add-edge-between-nodes g node dependency))) (set-property g :dot-rankdir "LR") (set-property g :dot-concentrate t) (with-open-file (out graph-path :direction :output :if-does-not-exist :create :if-exists :supersede) (princ (generate-dot g) out)))) (make-system-graph *asd-files* "system-graph.dot" :test (lambda (asd) (not (suffixp ".test" (asd-name asd))))) ;;;; THE END ;;;;
5,599
Common Lisp
.lisp
124
33.879032
123
0.52346
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
e3c88dc0b7e51a006e7ae9dcd84be2d64aa923c7a6fad84032dd38ae89c9b03b
4,952
[ -1 ]
4,953
compile-with-asdf.lisp
informatimago_lisp/common-lisp/compile-with-asdf.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: compile-with-asdf.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Compile the com.informatimago.common-lisp libraries with ASDF. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-11-01 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COMMON-LISP-USER") (defvar *asdf-source* #p"/data/lisp/packages/net/common-lisp/projects/asdf/asdf/asdf.lisp") (defvar *asdf-binary-locations-directory* #p"/data/lisp/packages/net/common-lisp/projects/asdf-binary-locations/asdf-binary-locations/") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ASDF ;;; (unless (find-package :asdf) (handler-case (require :asdf) (error () (load (compile-file *asdf-source*))))) (defun push-asdf-repository (path) (pushnew path asdf:*central-registry* :test #'equal)) (defun asdf-load (&rest systems) (mapcar (lambda (system) (asdf:operate 'asdf:load-op system)) systems)) (defun asdf-delete-system (&rest systems) (mapc (lambda (system) (remhash (string-downcase system) asdf::*defined-systems*)) systems) (values)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ASDF-BINARY-LOCATIONS ;;; (defun hostname () (let ((outpath (format nil "/tmp/hostname-~8,'0X.txt" (random #x100000000)))) (asdf:run-shell-command "( hostname --fqdn 2>/dev/null || hostname --long 2>/dev/null || hostname ) > ~A" outpath) (prog1 (with-open-file (hostname outpath) (read-line hostname)) (delete-file outpath)))) (let ((sym (find-symbol "ENABLE-ASDF-BINARY-LOCATIONS-COMPATIBILITY" "ASDF"))) (when (and sym (fboundp sym)) (push :has-asdf-enable-asdf-binary-locations-compatibility *features*))) #+has-asdf-enable-asdf-binary-locations-compatibility (progn (format *trace-output* "enable-asdf-binary-locations-compatibility ~%") (asdf:enable-asdf-binary-locations-compatibility :centralize-lisp-binaries t :default-toplevel-directory (merge-pathnames (format nil ".cache/common-lisp/~A/" (hostname)) (user-homedir-pathname) nil) :include-per-user-information nil :map-all-source-files t :source-to-target-mappings nil)) #-has-asdf-enable-asdf-binary-locations-compatibility (progn (push-asdf-repository *asdf-binary-locations-directory*) (asdf-load :asdf-binary-locations)) #-has-asdf-enable-asdf-binary-locations-compatibility (progn (format *trace-output* "enable-asdf-binary-locations-compatibility ~%") (setf asdf:*centralize-lisp-binaries* t asdf:*include-per-user-information* nil asdf:*default-toplevel-directory* (merge-pathnames (format nil ".cache/common-lisp/~A/" (hostname)) (user-homedir-pathname) nil) asdf:*source-to-target-mappings* '())) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Compiling com.informatimago.common-lisp ;;; (setf asdf:*central-registry* (append (remove-duplicates (mapcar (lambda (path) (make-pathname :name nil :type nil :version nil :defaults path)) (directory "**/*.asd")) :test (function equalp)) asdf:*central-registry*)) (asdf-load :com.informatimago.common-lisp) ;;;; THE END ;;;;
4,481
Common Lisp
.lisp
107
37.747664
98
0.626379
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
e916ccd0678dd3110cf72369a6b8b1b573efc8766e3872389002c4a71498543a
4,953
[ -1 ]
4,954
com.informatimago.common-lisp.asd
informatimago_lisp/common-lisp/com.informatimago.common-lisp.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp libraries. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp" ;; system attributes: :description "Informatimago Common Lisp Systems Agregate" :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.6.0" :properties ((#:author-email . "[email protected]") (#:date . "Autumn 2010") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp/") ((#: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.common-lisp.lisp-sexp" "com.informatimago.common-lisp.lisp-text" "com.informatimago.common-lisp.lisp-reader" ;; not yet "com.informatimago.common-lisp.lisp" "com.informatimago.common-lisp.cesarum" "com.informatimago.common-lisp.picture" "com.informatimago.common-lisp.arithmetic" "com.informatimago.common-lisp.data-encoding" "com.informatimago.common-lisp.heap" "com.informatimago.common-lisp.html-base" "com.informatimago.common-lisp.html-generator" "com.informatimago.common-lisp.html-parser" "com.informatimago.common-lisp.http" "com.informatimago.common-lisp.bank" "com.informatimago.common-lisp.csv" "com.informatimago.common-lisp.diagram" "com.informatimago.common-lisp.regexp" "com.informatimago.common-lisp.ed" "com.informatimago.common-lisp.graphviz" "com.informatimago.common-lisp.invoice" "com.informatimago.common-lisp.interactive" "com.informatimago.common-lisp.parser" "com.informatimago.common-lisp.rfc2822" "com.informatimago.common-lisp.rfc3548" ;; not yet "com.informatimago.common-lisp.telnet" "com.informatimago.common-lisp.unix" "com.informatimago.common-lisp.data") #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.test")))) ;;;; THE END ;;;;
3,902
Common Lisp
.lisp
78
42.487179
103
0.59434
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
751014d3751d65f7851704c6ab3a354709aa166544f4c4030ed8ff1afcc80834
4,954
[ -1 ]
4,955
com.informatimago.common-lisp.test.asd
informatimago_lisp/common-lisp/com.informatimago.common-lisp.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.test system. ;;;; Tests the com.informatimago.common-lisp system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp") :components () #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.lisp-sexp") (asdf:test-op "com.informatimago.common-lisp.lisp-reader") (asdf:test-op "com.informatimago.common-lisp.lisp-text") (asdf:test-op "com.informatimago.common-lisp.cesarum") (asdf:test-op "com.informatimago.common-lisp.picture") (asdf:test-op "com.informatimago.common-lisp.arithmetic") (asdf:test-op "com.informatimago.common-lisp.data-encoding") (asdf:test-op "com.informatimago.common-lisp.heap") (asdf:test-op "com.informatimago.common-lisp.html-base") (asdf:test-op "com.informatimago.common-lisp.html-generator") (asdf:test-op "com.informatimago.common-lisp.html-parser") (asdf:test-op "com.informatimago.common-lisp.http") (asdf:test-op "com.informatimago.common-lisp.bank") (asdf:test-op "com.informatimago.common-lisp.csv") (asdf:test-op "com.informatimago.common-lisp.diagram") (asdf:test-op "com.informatimago.common-lisp.regexp") (asdf:test-op "com.informatimago.common-lisp.ed") (asdf:test-op "com.informatimago.common-lisp.graphviz") (asdf:test-op "com.informatimago.common-lisp.invoice") (asdf:test-op "com.informatimago.common-lisp.interactive") (asdf:test-op "com.informatimago.common-lisp.parser") (asdf:test-op "com.informatimago.common-lisp.rfc2822") (asdf:test-op "com.informatimago.common-lisp.rfc3548") ;; not yet (asdf:test-op "com.informatimago.common-lisp.telnet") (asdf:test-op "com.informatimago.common-lisp.unix")))) ;;;; THE END ;;;;
4,386
Common Lisp
.lisp
86
42.976744
83
0.587715
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
dbb76f9755323891678bfceb2bde4ba4bc096bf15a8882d24de640c745f2f67a
4,955
[ -1 ]
4,956
init.lisp
informatimago_lisp/common-lisp/init.lisp
;;;; -*- coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: init.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Initialization for common-lisp packages. ;;;; ;;;; This files remove some specificities from the lisp environment ;;;; (to make it more Common-Lisp), ;;;; loads the package COM.INFORMATIMAGO.COMMON-LISP.PACKAGE, ;;;; and add logical pathname translations to help find then other packages. ;;;; ;;;; Since we're generating an image, it should be useful only ;;;; at compilation-time, so any path present here should not be needed ;;;; at run-time. (But we don't clear them from the translations...). ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2004-01-20 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2004 - 2016 ;;;; ;;;; 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/> ;;;;*************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (setq *load-verbose* t) #+clisp (setq custom:*load-echo* nil) ;; clean the imported packages: (mapc (lambda (used) (unuse-package used "COMMON-LISP-USER")) (remove (find-package "COMMON-LISP") (copy-seq (package-use-list "COMMON-LISP-USER")))) (progn (defvar *directories* '()) (defun get-directory (key &optional (subpath "")) (unless *directories* (with-open-file (dirs (make-pathname :name "DIRECTORIES" :type "TXT" :version nil :case :common :defaults (user-homedir-pathname))) (loop :for k = (read dirs nil dirs) :until (eq k dirs) :do (push (string-trim " " (read-line dirs)) *directories*) :do (push (intern (substitute #\- #\_ (string k)) "KEYWORD") *directories*)))) (unless (getf *directories* key) (error "~S: No directory keyed ~S" 'get-directory key)) (merge-pathnames subpath (getf *directories* key) nil))) #+clisp (when (string= (lisp-implementation-version) "2.33.83" :end1 (min (length (lisp-implementation-version)) 7)) (ext:without-package-lock ("COMMON-LISP") (let ((oldload (function cl:load))) (fmakunbound 'cl:load) (defun cl:load (filespec &key (verbose *load-verbose*) (print *load-print*) (if-does-not-exist t) (external-format :default)) (handler-case (funcall oldload filespec :verbose verbose :print print :if-does-not-exist if-does-not-exist :external-format external-format) (system::simple-parse-error () (funcall oldload (translate-logical-pathname filespec) :verbose verbose :print print :if-does-not-exist if-does-not-exist :external-format external-format))))))) ;; (DEFUN SCONC (&REST ARGS) ;; (apply (function CONCATENATE) ;; 'string ;; (mapcar (lambda (item) (typecase item ;; (pathname (namestring item)) ;; (otherwise (string item)))) ARGS)));;SCONC ;; COM.INFORMATIMAGO.COMMON-LISP packages depends only on themselves, ;; from the current directory. ;; Load COM.INFORMATIMAGO.COMMON-LISP.PACKAGE: (handler-case (load "package") (t () (load "package.lisp"))) ;; Import DEFINE-PACKAGE, and add translations: (import 'package:define-package) (setf (logical-pathname-translations "PACKAGES") (handler-case (logical-pathname-translations "PACKAGES") (error nil))) (package:add-translations (list (make-pathname :host "PACKAGES" :directory '(:absolute "COM" "INFORMATIMAGO" #-cmu"COMMON-LISP" :wild-inferiors) :name :wild :type :wild :version :wild) (merge-pathnames (make-pathname :directory '(:relative :wild-inferiors) :name :wild :type :wild :version :wild) #-cmu *load-pathname* #+(and cmu unix) (let ((dir (pathname-directory *load-pathname*))) (if (and dir (eq :absolute (first dir))) *load-pathname* (merge-pathnames *load-pathname* (nth-value 1 (unix:unix-current-directory)) nil))) #+(and cmu (not unix)) (error "Cannot compile here.") nil)) (list (make-pathname :host "PACKAGES" :directory '(:absolute :wild-inferiors) :name :wild :type :wild :version :wild) (get-directory :share-lisp "packages/**/*.*"))) ;; #+sbcl (setf (logical-pathname-translations "PACKAGES") ;; (sort (copy-seq (logical-pathname-translations "PACKAGES")) ;; (lambda (a b) (< (length (second a)) (length (second b)))))) ;;;; init.lisp -- -- ;;;;
5,907
Common Lisp
.lisp
131
38.312977
83
0.577157
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
d089bd462efe3f5a14911e342954d67ed4f4261e25f7dfacf17b6c20ab56fc82
4,956
[ -1 ]
4,957
com.informatimago.common-lisp.lisp.stepper.test.asd
informatimago_lisp/common-lisp/lisp/com.informatimago.common-lisp.lisp.stepper.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.lisp.stepper.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.lisp.stepper.test system. ;;;; Tests the com.informatimago.common-lisp.lisp.stepper system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.lisp.stepper.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.lisp.stepper system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.lisp.stepper.test/") ((#: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.common-lisp.lisp.stepper" "com.informatimago.common-lisp.cesarum") :components () #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) ;; (let ((*package* (find-package "TESTED-PACKAGE"))) ;; (uiop:symbol-call "TESTED-PACKAGE" ;; "TEST/ALL")) )) ;;;; THE END ;;;;
3,011
Common Lisp
.lisp
67
38.761194
92
0.553025
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
7912455e91148d52cb3305b3211a2e80158ca2a40c6d9c40b732e030ea8e572f
4,957
[ -1 ]
4,958
cl-definition.lisp
informatimago_lisp/common-lisp/lisp/cl-definition.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: cl-definition.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This file gives a description of all the standard symbols in ;;;; the CL package. These descriptions can be used to generate ;;;; automatically various things. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2012-07-12 <PJB> Created. ;;;; 2014-08-30 <PJB> Added handling of parameters in define-declare-macro. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2012 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.CL-DEFINITIONS" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.LISP-SEXP.SOURCE-FORM") (:export "SYMBOL-TYPE-OF-DECLARATIONS" "SYMBOL-DECLARATION-INFOS" "SYMBOL-INFO" "MAP-SYMBOL-INFOS" "*SYMBOL-CATEGORIES*") (:documentation " This file gives a description of all the standard symbols in the CL package. These descriptions can be used to generate automatically various things. Copyright Pascal J. Bourguignon 2012 - 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. ")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.CL-DEFINITIONS") (defvar *declarations* (make-hash-table) "Maps symbols to a-list (type-of-declaration) of p-lists (parameter).") (defun enter (symbol type-of-declaration parameters) (let ((sym (gethash symbol *declarations*))) (let ((entry (assoc type-of-declaration sym))) (if entry (setf (cdr entry) parameters) (push (cons type-of-declaration parameters) sym))) (setf (gethash symbol *declarations*) sym))) (defun symbol-type-of-declarations (symbol) " SYMBOL: A symbol exported from the COMMON-LISP package. RETURN: a list of keywords denoting the type of declarations the symbol has. " (mapcar (function car) (gethash symbol *declarations*))) (defun symbol-declaration-infos (symbol type-of-declaration) " SYMBOL: A symbol exported from the COMMON-LISP package. TYPE-OF-DECLARATION: A keyword denoting the type of declaration wanted. RETURN: A p-list containing the parameters of the TYPE-OF-DECLARATION declaration of the SYMBOL. " (cdr (assoc type-of-declaration (gethash symbol *declarations*)))) (defun symbol-info (symbol) " SYMBOL: A symbol exported from the COMMON-LISP package. RETURN: an a-list (type-of-declaration) of p-lists (parameter) describing the specifications of the given CL SYMBOL. " (gethash symbol *declarations*)) (defun map-symbol-infos (fun) " DO: Calls the function FUN on each symbol exported from the COMMON-LISP package, unordered. FUN: A function taking a symbol and an a-list (type-of-declaration) of p-lists (parameter) describing the specifications of the given CL SYMBOL. " (maphash fun *declarations*)) ;; (enter 'vector :compound-type-specifier '((:lambda-list . (element-type &optional size)) (:compound-type-kind . :specializing))) ;; (enter 'vector :system-class '(:superclasses (array sequence))) ;; (com.informatimago.common-lisp.cesarum.utility:print-hashtable *declarations*) ;; (symbol-type-of-declarations 'vector)(:system-class :compound-type-specifier) ;; (symbol-declaration-infos 'vector :system-class) (lambda-list-parameters (parse-lambda-list '(name declaration-lambda-list &key documentation) :macro)) ;; (#<&mandatory name #x3020022DE0FD> #<&mandatory declaration-lambda-list #x3020022DE0AD> #<&key documentation #x3020022DE03D>) (make-lambda-list (parse-lambda-list '(name declaration-lambda-list &key documentation) :macro)) ;; (name declaration-lambda-list &key documentation) (make-argument-list-form (parse-lambda-list '(name declaration-lambda-list &key documentation) :macro)) ;;(append (list name declaration-lambda-list) (list :documentation documentation)) (make-argument-list (parse-lambda-list '(name declaration-lambda-list &key documentation) :macro)) ;; (name declaration-lambda-list :documentation documentation nil) (make-help (parse-lambda-list '(name declaration-lambda-list &key documentation) :macro)) ;; ((:mandatory . "name") (:mandatory . "declaration-lambda-list") (:key . "documentation")) (defmacro define-declare-macro (type-of-declaration parameter-lambda-list) (let* ((ll (parse-lambda-list parameter-lambda-list :macro)) (parameters (mapcan (lambda (parameter) (list (intern (string (parameter-name parameter)) :keyword) (list 'list ''quote (parameter-name parameter)))) (lambda-list-parameters ll)))) (print parameters) `(defmacro ,(intern (concatenate 'string "DECLARE-" (string type-of-declaration))) ,parameter-lambda-list `(enter ',,(first parameter-lambda-list) ,,(intern (string type-of-declaration) :keyword) (list ,,@parameters))))) (define-declare-macro declaration (name declaration-lambda-list &key documentation)) (define-declare-macro compound-type-specifier (name type-lambda-list kind &key documentation)) (define-declare-macro type (name supertype &key documentation definition)) (define-declare-macro class (name superclasses &key documentation (slots ()))) (define-declare-macro system-class (name superclasses &key documentation (slots ()))) (define-declare-macro condition-type (name superclasses &key documentation (slots ()))) (define-declare-macro symbol (name &key documentation)) (define-declare-macro lambda-list-keyword (name &key documentation)) (define-declare-macro variable (name &key documentation)) (define-declare-macro constant-variable (name &key documentation)) (define-declare-macro generic-function (name generic-lambda-list &key documentation (signals :unspecified) (result-type t))) (define-declare-macro standard-generic-function (name generic-lambda-list &key documentation (signals :unspecified) (result-type t))) (define-declare-macro accessor (name accessor-lambda-list &key documentation (signals :unspecified) (result-type t))) (define-declare-macro function (name function-lambda-list &key documentation (signals :unspecified) (result-type t))) (define-declare-macro macro (name macro-lambda-list &key documentation (signals :unspecified))) (define-declare-macro local-function (name function-lambda-list &key documentation (signals :unspecified) context (result-type t))) (define-declare-macro local-macro (name macro-lambda-list &key documentation (signals :unspecified) context)) (define-declare-macro restart (name restart-lambda-list &key documentation)) (define-declare-macro special-operator (name macro-lambda-list &key documentation (signals :unspecified) context)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; COMMON-LISP description. ;;; (defparameter *symbol-categories* '( (declarations DECLARATION DYNAMIC-EXTENT FTYPE IGNORABLE IGNORE INLINE NOTINLINE OPTIMIZE SPECIAL TYPE) (compound-type-specifier and or not eql member array simple-array vector simple-vector bit-vector simple-bit-vector string base-string simple-string simple-base-string real complex float short-float single-float double-float long-float rational integer signed-byte unsigned-byte mod function cons values satisfies) (type EXTENDED-CHAR BASE-CHAR STANDARD-CHAR BASE-STRING SIMPLE-STRING SIMPLE-BASE-STRING FIXNUM BIGNUM SIGNED-BYTE UNSIGNED-BYTE BIT SHORT-FLOAT SINGLE-FLOAT DOUBLE-FLOAT LONG-FLOAT COMPILED-FUNCTION SIMPLE-ARRAY SIMPLE-VECTOR SIMPLE-BIT-VECTOR NIL) (class STANDARD-OBJECT STRUCTURE-OBJECT) (system-class t array method number stream symbol package restart function pathname sequence character readtable hash-table random-state method-combination vector string bit-vector list cons built-in-class standard-class structure-class generic-function standard-generic-function standard-method real complex float rational ratio integer logical-pathname class echo-stream file-stream string-stream synonym-stream two-way-stream broadcast-stream concatenated-stream null) (condition-type condition serious-condition simple-condition warning storage-condition error arithmetic-error cell-error control-error file-error package-error parse-error print-not-readable program-error stream-error type-error division-by-zero floating-point-inexact floating-point-invalid-operation floating-point-overflow floating-point-underflow unbound-slot unbound-variable undefined-function reader-error simple-error simple-type-error simple-warning end-of-file style-warning) (symbol declare lambda) (lambda-list-keyword &optional &rest &aux &key &allow-other-keys &body &environment &whole) (variable *break-on-signals* *compile-file-pathname* *compile-file-truename* *compile-print* *compile-verbose* *debugger-hook* *debug-io* *default-pathname-defaults* *error-output* *features* *gensym-counter* *load-pathname* *load-print* *load-truename* *load-verbose* *macroexpand-hook* *modules* *package* *print-array* *print-base* *print-case* *print-circle* *print-escape* *print-gensym* *print-length* *print-level* *print-lines* *print-miser-width* *print-pprint-dispatch* *print-pretty* *print-radix* *print-readably* *print-right-margin* *query-io* *random-state* *read-base* *read-default-float-format* *read-eval* *read-suppress* *readtable* *standard-input* *standard-output* *terminal-io* *trace-output* - / // /// * ** *** + ++ +++ ) (constant-variable nil t pi array-dimension-limit array-rank-limit array-total-size-limit boole-1 boole-2 boole-andc1 boole-andc2 boole-and boole-c1 boole-c2 boole-clr boole-eqv boole-ior boole-nand boole-nor boole-orc1 boole-orc2 boole-set boole-xor call-arguments-limit char-code-limit double-float-epsilon double-float-negative-epsilon internal-time-units-per-second lambda-list-keywords lambda-parameters-limit least-negative-double-float least-negative-long-float least-negative-normalized-double-float least-negative-normalized-long-float least-negative-normalized-short-float least-negative-normalized-single-float least-negative-short-float least-negative-single-float least-positive-double-float least-positive-long-float least-positive-normalized-double-float least-positive-normalized-long-float least-positive-normalized-short-float least-positive-normalized-single-float least-positive-short-float least-positive-single-float long-float-epsilon long-float-negative-epsilon most-negative-double-float most-negative-fixnum most-negative-long-float most-negative-short-float most-negative-single-float most-positive-double-float most-positive-fixnum most-positive-long-float most-positive-short-float most-positive-single-float multiple-values-limit short-float-epsilon short-float-negative-epsilon single-float-epsilon single-float-negative-epsilon) (accessor caaaar caaadr caaar caadar caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr cadr car cdaaar cdaadr cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr cddr cdr first second third fourth fifth sixth seventh eighth ninth tenth rest nth elt subseq aref row-major-aref bit sbit svref char schar fill-pointer get getf gethash ldb mask-field compiler-macro-function macro-function fdefinition find-class logical-pathname-translations readtable-case symbol-function symbol-plist symbol-value values) (function 1- 1+ abort abs acons acos acosh adjoin adjustable-array-p adjust-array alpha-char-p alphanumericp append apply apropos apropos-list arithmetic-error-operands arithmetic-error-operation array-dimension array-dimensions array-displacement array-element-type array-has-fill-pointer-p array-in-bounds-p arrayp array-rank array-row-major-index array-total-size ash asin asinh assoc assoc-if assoc-if-not atan atanh atom bit-andc1 bit-andc2 bit-and bit-eqv bit-ior bit-nand bit-nor bit-not bit-orc1 bit-orc2 bit-vector-p bit-xor boole both-case-p boundp break broadcast-stream-streams butlast byte byte-position byte-size ceiling cell-error-name cerror character characterp char-code char-downcase char-equal char<= char< char= char>= char> char/= char-greaterp char-int char-lessp char-name char-not-equal char-not-greaterp char-not-lessp char-upcase cis class-of clear-input clear-output close clrhash code-char coerce compiled-function-p compile-file compile-file-pathname compile complement complex complexp compute-restarts concatenated-stream-streams concatenate conjugate cons consp constantly constantp continue copy-alist copy-list copy-pprint-dispatch copy-readtable copy-seq copy-structure copy-symbol copy-tree cos cosh count count-if count-if-not decode-float decode-universal-time delete-duplicates delete-file delete delete-if delete-if-not delete-package denominator deposit-field describe digit-char digit-char-p directory directory-namestring disassemble dpb dribble echo-stream-input-stream echo-stream-output-stream ed endp enough-namestring ensure-directories-exist ensure-generic-function eq eql equal equalp error eval evenp every exp export expt fboundp fceiling ffloor file-author file-error-pathname file-length file-namestring file-position file-string-length file-write-date fill find-all-symbols find find-if find-if-not find-package find-restart find-symbol finish-output float-digits float floatp float-precision float-radix float-sign floor fmakunbound force-output format fresh-line fround ftruncate funcall <= < = >= > - /= / * + function-lambda-expression functionp gcd gensym gentemp get-decoded-time get-dispatch-macro-character get-internal-real-time get-internal-run-time get-macro-character get-output-stream-string get-properties get-setf-expansion get-universal-time graphic-char-p hash-table-count hash-table-p hash-table-rehash-size hash-table-rehash-threshold hash-table-size hash-table-test host-namestring identity imagpart import input-stream-p inspect integer-decode-float integer-length integerp interactive-stream-p intern intersection invalid-method-error invoke-debugger invoke-restart invoke-restart-interactively isqrt keywordp last lcm ldb-test ldiff length lisp-implementation-type lisp-implementation-version list-all-packages listen list list* list-length listp load load-logical-pathname-translations logandc1 logandc2 logand logbitp logcount logeqv log logical-pathname logior lognand lognor lognot logorc1 logorc2 logtest logxor long-site-name lower-case-p machine-instance machine-type machine-version macroexpand-1 macroexpand make-array make-broadcast-stream make-concatenated-stream make-condition make-dispatch-macro-character make-echo-stream make-hash-table make-list make-load-form-saving-slots make-package make-pathname make-random-state make-sequence make-string make-string-input-stream make-string-output-stream make-symbol make-synonym-stream make-two-way-stream makunbound mapcan mapcar mapc mapcon map maphash map-into mapl maplist max member member-if member-if-not merge merge-pathnames method-combination-error min minusp mismatch mod muffle-warning name-char namestring nbutlast nconc nintersection notany notevery not nreconc nreverse nset-difference nset-exclusive-or nstring-capitalize nstring-downcase nstring-upcase nsublis nsubst nsubst-if nsubst-if-not nsubstitute nsubstitute-if nsubstitute-if-not nthcdr null numberp numerator nunion oddp open open-stream-p output-stream-p package-error-package package-name package-nicknames packagep package-shadowing-symbols package-used-by-list package-use-list pairlis parse-integer parse-namestring pathname-device pathname-directory pathname pathname-host pathname-match-p pathname-name pathnamep pathname-type pathname-version peek-char phase plusp position position-if position-if-not pprint-dispatch pprint-fill pprint pprint-indent pprint-linear pprint-newline pprint-tab pprint-tabular prin1 prin1-to-string princ princ-to-string print print-not-readable-object probe-file proclaim provide random random-state-p rassoc rassoc-if rassoc-if-not rational rationalize rationalp read-byte read-char read-char-no-hang read-delimited-list read-from-string read read-line read-preserving-whitespace read-sequence readtablep realpart realp reduce rem remhash remove-duplicates remove remove-if remove-if-not remprop rename-file rename-package replace require restart-name revappend reverse room round rplaca rplacd scale-float search set-difference set-dispatch-macro-character set-exclusive-or set set-macro-character set-pprint-dispatch set-syntax-from-char shadow shadowing-import short-site-name signal signum simple-bit-vector-p simple-condition-format-arguments simple-condition-format-control simple-string-p simple-vector-p sin sinh sleep slot-boundp slot-exists-p slot-makunbound slot-value software-type software-version some sort special-operator-p sqrt stable-sort standard-char-p store-value stream-element-type stream-error-stream stream-external-format streamp string-capitalize string-downcase string-equal string<= string< string= string>= string> string string/= string-greaterp string-left-trim string-lessp string-not-equal string-not-greaterp string-not-lessp stringp string-right-trim string-trim string-upcase sublis subsetp subst subst-if subst-if-not substitute substitute-if substitute-if-not subtypep sxhash symbol-name symbol-package symbolp synonym-stream-symbol tailp tan tanh terpri translate-logical-pathname translate-pathname tree-equal truename truncate two-way-stream-input-stream two-way-stream-output-stream type-error-datum type-error-expected-type type-of typep unbound-slot-instance unexport unintern union unread-char unuse-package upgraded-array-element-type upgraded-complex-part-type upper-case-p use-package user-homedir-pathname use-value values-list vector vectorp vector-pop vector-push-extend vector-push warn wild-pathname-p write-byte write-char write write-line write-sequence write-string write-to-string yes-or-no-p y-or-n-p zerop) (local-function CALL-NEXT-METHOD NEXT-METHOD-P) (local-macro CALL-METHOD LOOP-FINISH MAKE-METHOD PPRINT-EXIT-IF-LIST-EXHAUSTED PPRINT-POP) (macro and assert case ccase check-type cond ctypecase decf declaim defclass defconstant defgeneric define-compiler-macro define-condition define-method-combination define-modify-macro define-setf-expander define-symbol-macro defmacro defmethod defpackage defparameter defsetf defstruct deftype defun defvar destructuring-bind do-all-symbols do-external-symbols dolist do do* do-symbols dotimes ecase etypecase formatter handler-bind handler-case ignore-errors incf in-package lambda loop multiple-value-bind multiple-value-list multiple-value-setq nth-value or pop pprint-logical-block print-unreadable-object prog1 prog2 prog prog* psetf psetq push pushnew remf restart-bind restart-case return rotatef setf shiftf step time trace typecase unless untrace when with-accessors with-compilation-unit with-condition-restarts with-hash-table-iterator with-input-from-string with-open-stream with-output-to-string with-package-iterator with-simple-restart with-slots with-standard-io-syntax) (restart ABORT CONTINUE MUFFLE-WARNING STORE-VALUE USE-VALUE) (special-operator block catch eval-when flet function go if labels let let* load-time-value locally macrolet multiple-value-call multiple-value-prog1 progn progv quote return-from setq symbol-macrolet tagbody the throw unwind-protect) (standard-generic-fucntion add-method allocate-instance change-class class-name compute-applicable-methods describe-object documentation find-method function-keywords initialize-instance make-instances-obsolete make-instance make-load-form method-qualifiers no-applicable-method no-next-method print-object reinitialize-instance remove-method shared-initialize slot-missing slot-unbound update-instance-for-different-class update-instance-for-redefined-class))) (declare-declaration DECLARATION (&rest names)) (declare-declaration DYNAMIC-EXTENT (&rest var-or-functions)) (declare-declaration FTYPE (type &rest function-names)) (declare-declaration IGNORABLE (&rest var-or-functions)) (declare-declaration IGNORE (&rest var-or-functions)) (declare-declaration INLINE (&rest function-names)) (declare-declaration NOTINLINE (&rest function-names)) (declare-declaration OPTIMIZE (&rest qualities)) (declare-declaration SPECIAL (&rest vars)) (declare-declaration TYPE (type &rest vars)) (declare-compound-type-specifier AND (&rest typespecs) :combining) (declare-compound-type-specifier OR (&rest typespecs) :combining) (declare-compound-type-specifier NOT (typespec) :combining) (declare-compound-type-specifier EQL (object) :combining) (declare-compound-type-specifier MEMBER (&rest objects) :combining) (declare-compound-type-specifier array (element-type &optional dimension-spec) :specializing) (declare-compound-type-specifier simple-array (element-type &optional dimension-spec) :specializing) (declare-compound-type-specifier vector (element-type &optional size) :specializing) (declare-compound-type-specifier simple-vector (&optional size) :specializing) (declare-compound-type-specifier bit-vector (&optional size) :abbreviating) (declare-compound-type-specifier simple-bit-vector (&optional size) :abbreviating) (declare-compound-type-specifier string (&optional size) :abbreviating) (declare-compound-type-specifier base-string (&optional size) :abbreviating) (declare-compound-type-specifier simple-string (&optional size) :abbreviating) (declare-compound-type-specifier simple-base-string (&optional size) :abbreviating) (declare-compound-type-specifier real (&optional lower-limit upper-limit) :abbreviating) (declare-compound-type-specifier complex (&optional typespec) :specializing) (declare-compound-type-specifier float (&optional lower-limit upper-limit) :abbreviating) (declare-compound-type-specifier short-float (&optional lower-limit upper-limit) :abbreviating) (declare-compound-type-specifier single-float (&optional lower-limit upper-limit) :abbreviating) (declare-compound-type-specifier double-float (&optional lower-limit upper-limit) :abbreviating) (declare-compound-type-specifier long-float (&optional lower-limit upper-limit) :abbreviating) (declare-compound-type-specifier rational (&optional lower-limit upper-limit) :abbreviating) (declare-compound-type-specifier integer (&optional lower-limit upper-limit) :abbreviating) (declare-compound-type-specifier signed-byte (&optional size) :abbreviating) (declare-compound-type-specifier unsigned-byte (&optional size) :abbreviating) (declare-compound-type-specifier mod (n) :abbreviating) (declare-compound-type-specifier function (&optional arg-typespec value-typespec) :specializing) (declare-compound-type-specifier cons (&optional car-typespec cdr-typespec) :specializing) (declare-compound-type-specifier values (&rest value-typespecs) :specializing) (declare-compound-type-specifier satisfies (predicate-name) :predicating) (declare-type ATOM (t)) (declare-type BOOLEAN (symbol) :definition (member t nil)) (declare-type KEYWORD (symbol) :documentation " Note: we cannot say :definition (satisfies keywordp) because keywordp is whether (symbol-package k) = (find-package :keyword) while KEYWORD includes all symbols interned in the :keyword package. ") (declare-type EXTENDED-CHAR (character)) (declare-type BASE-CHAR (character)) (declare-type STANDARD-CHAR (base-char)) (declare-type BASE-STRING (string)) (declare-type SIMPLE-STRING (string)) (declare-type SIMPLE-BASE-STRING (base-string simple-string)) (declare-type FIXNUM (integer)) (declare-type BIGNUM (integer) :definition (and integer (not fixnum))) (declare-type SIGNED-BYTE (integer)) (declare-type UNSIGNED-BYTE (signed-byte)) (declare-type BIT (unsigned-byte) :definition (unsigned-byte 0 1)) (declare-type SHORT-FLOAT (float)) (declare-type SINGLE-FLOAT (float)) (declare-type DOUBLE-FLOAT (float)) (declare-type LONG-FLOAT (float)) (declare-type COMPILED-FUNCTION (function)) (declare-type SIMPLE-ARRAY (array)) (declare-type SIMPLE-VECTOR (vector)) (declare-type SIMPLE-BIT-VECTOR (bit-vector simple-vector)) (declare-type NIL :all-types) (declare-class STANDARD-OBJECT (t)) (declare-class STRUCTURE-OBJECT (t)) (declare-system-class T ()) (declare-system-class ARRAY (t)) (declare-system-class METHOD (t)) (declare-system-class NUMBER (t)) (declare-system-class STREAM (t)) (declare-system-class SYMBOL (t)) (declare-system-class PACKAGE (t)) (declare-system-class RESTART (t)) (declare-system-class FUNCTION (t)) (declare-system-class PATHNAME (t)) (declare-system-class SEQUENCE (t)) (declare-system-class CHARACTER (t)) (declare-system-class READTABLE (t)) (declare-system-class HASH-TABLE (t)) (declare-system-class RANDOM-STATE (t)) (declare-system-class METHOD-COMBINATION (t)) (declare-system-class VECTOR (array sequence)) (declare-system-class STRING (vector)) (declare-system-class BIT-VECTOR (vector)) (declare-system-class LIST (sequence)) (declare-system-class CONS (list)) (declare-system-class BUILT-IN-CLASS (class)) (declare-system-class STANDARD-CLASS (class)) (declare-system-class STRUCTURE-CLASS (class)) (declare-system-class GENERIC-FUNCTION (function)) (declare-system-class STANDARD-GENERIC-FUNCTION (generic-function)) (declare-system-class STANDARD-METHOD (method)) (declare-system-class REAL (number)) (declare-system-class COMPLEX (number)) (declare-system-class FLOAT (real)) (declare-system-class RATIONAL (real)) (declare-system-class RATIO (rational)) (declare-system-class INTEGER (rational)) (declare-system-class LOGICAL-PATHNAME (pathname)) (declare-system-class CLASS (standard-object)) (declare-system-class ECHO-STREAM (stream)) (declare-system-class FILE-STREAM (stream)) (declare-system-class STRING-STREAM (stream)) (declare-system-class SYNONYM-STREAM (stream)) (declare-system-class TWO-WAY-STREAM (stream)) (declare-system-class BROADCAST-STREAM (stream)) (declare-system-class CONCATENATED-STREAM (stream)) (declare-system-class NULL (symbol)) (declare-condition-type CONDITION (t)) (declare-condition-type SERIOUS-CONDITION (condition)) (declare-condition-type SIMPLE-CONDITION (condition)) (declare-condition-type WARNING (condition)) (declare-condition-type STORAGE-CONDITION (serious-condition)) (declare-condition-type ERROR (serious-condition)) (declare-condition-type ARITHMETIC-ERROR (error)) (declare-condition-type CELL-ERROR (error)) (declare-condition-type CONTROL-ERROR (error)) (declare-condition-type FILE-ERROR (error)) (declare-condition-type PACKAGE-ERROR (error)) (declare-condition-type PARSE-ERROR (error)) (declare-condition-type PRINT-NOT-READABLE (error)) (declare-condition-type PROGRAM-ERROR (error)) (declare-condition-type STREAM-ERROR (error)) (declare-condition-type TYPE-ERROR (error)) (declare-condition-type DIVISION-BY-ZERO (arithmetic-error)) (declare-condition-type FLOATING-POINT-INEXACT (arithmetic-error)) (declare-condition-type FLOATING-POINT-INVALID-OPERATION (arithmetic-error)) (declare-condition-type FLOATING-POINT-OVERFLOW (arithmetic-error)) (declare-condition-type FLOATING-POINT-UNDERFLOW (arithmetic-error)) (declare-condition-type UNBOUND-SLOT (cell-error)) (declare-condition-type UNBOUND-VARIABLE (cell-error)) (declare-condition-type UNDEFINED-FUNCTION (cell-error)) (declare-condition-type READER-ERROR (parse-error)) (declare-condition-type SIMPLE-ERROR (simple-condition error)) (declare-condition-type SIMPLE-TYPE-ERROR (simple-condition type-error)) (declare-condition-type SIMPLE-WARNING (simple-condition warning)) (declare-condition-type END-OF-FILE (stream-error)) (declare-condition-type STYLE-WARNING (warning)) (declare-symbol DECLARE) (declare-symbol LAMBDA) (declare-lambda-list-keyword &OPTIONAL) (declare-lambda-list-keyword &REST) (declare-lambda-list-keyword &AUX) (declare-lambda-list-keyword &KEY) (declare-lambda-list-keyword &ALLOW-OTHER-KEYS) (declare-lambda-list-keyword &BODY) (declare-lambda-list-keyword &ENVIRONMENT) (declare-lambda-list-keyword &WHOLE) (declare-variable *BREAK-ON-SIGNALS*) (declare-variable *COMPILE-FILE-PATHNAME*) (declare-variable *COMPILE-FILE-TRUENAME*) (declare-variable *COMPILE-PRINT*) (declare-variable *COMPILE-VERBOSE*) (declare-variable *DEBUGGER-HOOK*) (declare-variable *DEBUG-IO*) (declare-variable *DEFAULT-PATHNAME-DEFAULTS*) (declare-variable *ERROR-OUTPUT*) (declare-variable *FEATURES*) (declare-variable *GENSYM-COUNTER*) (declare-variable *LOAD-PATHNAME*) (declare-variable *LOAD-PRINT*) (declare-variable *LOAD-TRUENAME*) (declare-variable *LOAD-VERBOSE*) (declare-variable *MACROEXPAND-HOOK*) (declare-variable *MODULES*) (declare-variable *PACKAGE*) (declare-variable *PRINT-ARRAY*) (declare-variable *PRINT-BASE*) (declare-variable *PRINT-CASE*) (declare-variable *PRINT-CIRCLE*) (declare-variable *PRINT-ESCAPE*) (declare-variable *PRINT-GENSYM*) (declare-variable *PRINT-LENGTH*) (declare-variable *PRINT-LEVEL*) (declare-variable *PRINT-LINES*) (declare-variable *PRINT-MISER-WIDTH*) (declare-variable *PRINT-PPRINT-DISPATCH*) (declare-variable *PRINT-PRETTY*) (declare-variable *PRINT-RADIX*) (declare-variable *PRINT-READABLY*) (declare-variable *PRINT-RIGHT-MARGIN*) (declare-variable *QUERY-IO*) (declare-variable *RANDOM-STATE*) (declare-variable *READ-BASE*) (declare-variable *READ-DEFAULT-FLOAT-FORMAT*) (declare-variable *READ-EVAL*) (declare-variable *READ-SUPPRESS*) (declare-variable *READTABLE*) (declare-variable *STANDARD-INPUT*) (declare-variable *STANDARD-OUTPUT*) (declare-variable *TERMINAL-IO*) (declare-variable *TRACE-OUTPUT*) (declare-variable -) (declare-variable /) (declare-variable //) (declare-variable ///) (declare-variable *) (declare-variable **) (declare-variable ***) (declare-variable +) (declare-variable ++) (declare-variable +++) (declare-constant-variable NIL) (declare-constant-variable T) (declare-constant-variable PI) (declare-constant-variable ARRAY-DIMENSION-LIMIT) (declare-constant-variable ARRAY-RANK-LIMIT) (declare-constant-variable ARRAY-TOTAL-SIZE-LIMIT) (declare-constant-variable BOOLE-1) (declare-constant-variable BOOLE-2) (declare-constant-variable BOOLE-ANDC1) (declare-constant-variable BOOLE-ANDC2) (declare-constant-variable BOOLE-AND) (declare-constant-variable BOOLE-C1) (declare-constant-variable BOOLE-C2) (declare-constant-variable BOOLE-CLR) (declare-constant-variable BOOLE-EQV) (declare-constant-variable BOOLE-IOR) (declare-constant-variable BOOLE-NAND) (declare-constant-variable BOOLE-NOR) (declare-constant-variable BOOLE-ORC1) (declare-constant-variable BOOLE-ORC2) (declare-constant-variable BOOLE-SET) (declare-constant-variable BOOLE-XOR) (declare-constant-variable CALL-ARGUMENTS-LIMIT) (declare-constant-variable CHAR-CODE-LIMIT) (declare-constant-variable DOUBLE-FLOAT-EPSILON) (declare-constant-variable DOUBLE-FLOAT-NEGATIVE-EPSILON) (declare-constant-variable INTERNAL-TIME-UNITS-PER-SECOND) (declare-constant-variable LAMBDA-LIST-KEYWORDS) (declare-constant-variable LAMBDA-PARAMETERS-LIMIT) (declare-constant-variable LEAST-NEGATIVE-DOUBLE-FLOAT) (declare-constant-variable LEAST-NEGATIVE-LONG-FLOAT) (declare-constant-variable LEAST-NEGATIVE-NORMALIZED-DOUBLE-FLOAT) (declare-constant-variable LEAST-NEGATIVE-NORMALIZED-LONG-FLOAT) (declare-constant-variable LEAST-NEGATIVE-NORMALIZED-SHORT-FLOAT) (declare-constant-variable LEAST-NEGATIVE-NORMALIZED-SINGLE-FLOAT) (declare-constant-variable LEAST-NEGATIVE-SHORT-FLOAT) (declare-constant-variable LEAST-NEGATIVE-SINGLE-FLOAT) (declare-constant-variable LEAST-POSITIVE-DOUBLE-FLOAT) (declare-constant-variable LEAST-POSITIVE-LONG-FLOAT) (declare-constant-variable LEAST-POSITIVE-NORMALIZED-DOUBLE-FLOAT) (declare-constant-variable LEAST-POSITIVE-NORMALIZED-LONG-FLOAT) (declare-constant-variable LEAST-POSITIVE-NORMALIZED-SHORT-FLOAT) (declare-constant-variable LEAST-POSITIVE-NORMALIZED-SINGLE-FLOAT) (declare-constant-variable LEAST-POSITIVE-SHORT-FLOAT) (declare-constant-variable LEAST-POSITIVE-SINGLE-FLOAT) (declare-constant-variable LONG-FLOAT-EPSILON) (declare-constant-variable LONG-FLOAT-NEGATIVE-EPSILON) (declare-constant-variable MOST-NEGATIVE-DOUBLE-FLOAT) (declare-constant-variable MOST-NEGATIVE-FIXNUM) (declare-constant-variable MOST-NEGATIVE-LONG-FLOAT) (declare-constant-variable MOST-NEGATIVE-SHORT-FLOAT) (declare-constant-variable MOST-NEGATIVE-SINGLE-FLOAT) (declare-constant-variable MOST-POSITIVE-DOUBLE-FLOAT) (declare-constant-variable MOST-POSITIVE-FIXNUM) (declare-constant-variable MOST-POSITIVE-LONG-FLOAT) (declare-constant-variable MOST-POSITIVE-SHORT-FLOAT) (declare-constant-variable MOST-POSITIVE-SINGLE-FLOAT) (declare-constant-variable MULTIPLE-VALUES-LIMIT) (declare-constant-variable SHORT-FLOAT-EPSILON) (declare-constant-variable SHORT-FLOAT-NEGATIVE-EPSILON) (declare-constant-variable SINGLE-FLOAT-EPSILON) (declare-constant-variable SINGLE-FLOAT-NEGATIVE-EPSILON) (declare-accessor CAAAAR (list)) (declare-accessor CAAADR (list)) (declare-accessor CAAAR (list)) (declare-accessor CAADAR (list)) (declare-accessor CAADDR (list)) (declare-accessor CAADR (list)) (declare-accessor CAAR (list)) (declare-accessor CADAAR (list)) (declare-accessor CADADR (list)) (declare-accessor CADAR (list)) (declare-accessor CADDAR (list)) (declare-accessor CADDDR (list)) (declare-accessor CADDR (list)) (declare-accessor CADR (list)) (declare-accessor CAR (list)) (declare-accessor CDAAAR (list)) (declare-accessor CDAADR (list)) (declare-accessor CDAAR (list)) (declare-accessor CDADAR (list)) (declare-accessor CDADDR (list)) (declare-accessor CDADR (list)) (declare-accessor CDAR (list)) (declare-accessor CDDAAR (list)) (declare-accessor CDDADR (list)) (declare-accessor CDDAR (list)) (declare-accessor CDDDAR (list)) (declare-accessor CDDDDR (list)) (declare-accessor CDDDR (list)) (declare-accessor CDDR (list)) (declare-accessor CDR (list)) (declare-accessor FIRST (list)) (declare-accessor SECOND (list)) (declare-accessor THIRD (list)) (declare-accessor FOURTH (list)) (declare-accessor FIFTH (list)) (declare-accessor SIXTH (list)) (declare-accessor SEVENTH (list)) (declare-accessor EIGHTH (list)) (declare-accessor NINTH (list)) (declare-accessor TENTH (list)) (declare-accessor REST (list)) (declare-accessor NTH (index list)) (declare-accessor ELT (sequence index)) (declare-accessor SUBSEQ (sequence start &optional end)) (declare-accessor AREF (array &rest subscripts)) (declare-accessor ROW-MAJOR-AREF (array index)) (declare-accessor BIT (bit-array &rest subscripts)) (declare-accessor SBIT (bit-array &rest subscripts)) (declare-accessor SVREF (simple-vector index)) (declare-accessor CHAR (string index)) (declare-accessor SCHAR (string index)) (declare-accessor FILL-POINTER (vector)) (declare-accessor GET (symbol indicator &optional default)) (declare-accessor GETF (plist indicator &optional default)) (declare-accessor GETHASH (key hash-table &optional default) :result-type (values t t)) (declare-accessor LDB (ldb bytespec integer) :result-type byte) (declare-accessor MASK-FIELD (bytespec integer)) (declare-accessor COMPILER-MACRO-FUNCTION (function-name &optional environment) :result-type (or function null)) (declare-accessor MACRO-FUNCTION (symbol &optional environment) :result-type (or function null)) (declare-accessor FDEFINITION (function-name) :result-type function :signals (type-error)) (declare-accessor FIND-CLASS (symbol &optional errorp environment) :result-type (or class null)) (declare-accessor LOGICAL-PATHNAME-TRANSLATIONS (host) :result-type list) (declare-accessor READTABLE-CASE (readtable)) (declare-accessor SYMBOL-FUNCTION (symbol)) (declare-accessor SYMBOL-PLIST (symbol)) (declare-accessor SYMBOL-VALUE (symbol)) (declare-accessor VALUES (&rest object)) ;;; functions -- 3. Evaluation and Compilation (declare-function COMPILE (name/function-name-or-nil &optional definition/lambda-expression-or-function) :result-type (values (or function-name compiled-function) t t)) (declare-function EVAL ()) (declare-function MACROEXPAND-1 ()) (declare-function MACROEXPAND ()) (declare-function PROCLAIM ()) (declare-function SPECIAL-OPERATOR-P ()) (declare-function CONSTANTP ()) ;;; functions -- 4. Types and Classes ;;; functions -- 5. Data and Control Flow ;;; functions -- 6. Iteration ;;; functions -- 7. Objects ;;; functions -- 8. Structures ;;; functions -- 9. Conditions ;;; functions -- 10. Symbols ;;; functions -- 11. Packages ;;; functions -- 12. Numbers ;;; functions -- 13. Characters ;;; functions -- 14. Conses ;;; functions -- 15. Arrays ;;; functions -- 16. Strings ;;; functions -- 17. Sequences ;;; functions -- 18. Hash Tables ;;; functions -- 19. Filenames ;;; functions -- 20. Files ;;; functions -- 21. Streams ;;; functions -- 22. Printer ;;; functions -- 23. Reader ;;; functions -- 24. System Construction ;;; functions -- 25. Environment (declare-function 1- (argument/number) :result-type number :signals (type-error arithmetic-error) :documentation "1- returns a number that is one less than its argument number.") (declare-function 1+ (argument/number) :result-type number :signals (type-error arithmetic-error) :documentation "1+ returns a number that is one more than its argument number.") (declare-function ABORT (&optional condition/condition) :result-type (values) :signals (control-error) :documentation " Transfers control to the most recently established applicable restart named ABORT. If no such restart exists, signals an error of type CONTROL-ERROR. When CONDITION is non-nil, only those restarts are considered that are either explicitly associated with that condition, or not associated with any condition; that is, the excluded restarts are those that are associated with a non-empty set of conditions of which the given condition is not an element. If CONDITION is nil, all restarts are considered. ") (declare-function MUFFLE-WARNING (&optional condition/condition) :result-type (values) :documentation " Transfers control to the most recently established applicable restart named MUFFLE-WARNING. If no such restart exists, signals an error of type CONTROL-ERROR. When CONDITION is non-nil, only those restarts are considered that are either explicitly associated with that condition, or not associated with any condition; that is, the excluded restarts are those that are associated with a non-empty set of conditions of which the given condition is not an element. If CONDITION is nil, all restarts are considered. ") (declare-function CONTINUE (&optional condition/condition) :result-type null :documentation " Transfers control to the most recently established applicable restart named CONTINUE. If no such restart exists, returns NIL. When CONDITION is non-nil, only those restarts are considered that are either explicitly associated with that condition, or not associated with any condition; that is, the excluded restarts are those that are associated with a non-empty set of conditions of which the given condition is not an element. If CONDITION is nil, all restarts are considered. ") (declare-function STORE-VALUE (value &optional condition/condition) :result-type null :documentation " Transfers control to the most recently established applicable restart named STORE-VALUE. If no such restart exists, returns NIL. When CONDITION is non-nil, only those restarts are considered that are either explicitly associated with that condition, or not associated with any condition; that is, the excluded restarts are those that are associated with a non-empty set of conditions of which the given condition is not an element. If CONDITION is nil, all restarts are considered. ") (declare-function USE-VALUE (value &optional condition/condition) :result-type null :documentation " Transfers control to the most recently established applicable restart named USE-VALUE. If no such restart exists, returns NIL. When CONDITION is non-nil, only those restarts are considered that are either explicitly associated with that condition, or not associated with any condition; that is, the excluded restarts are those that are associated with a non-empty set of conditions of which the given condition is not an element. If CONDITION is nil, all restarts are considered. ") (declare-function ABS (number) :result-type real :signals (type-error)) (declare-function ACONS (key datum alist) :result-type list) (declare-function ACOS (number) :result-type real) (declare-function ACOSH (number) :result-type number) (declare-function ADJOIN (item list &key (key (function identity)) (test (function eql)) test-not) :result-type list) (declare-function ADJUSTABLE-ARRAY-P (array) :result-type generalized-boolean) (declare-function ADJUST-ARRAY (array new-dimensions &key element-type initial-element initial-contents fill-pointer displaced-to displaced-index-offset) :result-type array) (declare-function ALPHA-CHAR-P (character) :result-type generalized-boolean :signals (type-error)) (declare-function ALPHANUMERICP (character) :result-type generalized-boolean :signals (type-error)) (declare-function APPEND (&rest lists) :result-type lists :signals ()) (declare-function APPLY (function &rest args+)) (declare-function APROPOS (string &optional package) :result-type (values)) (declare-function APROPOS-LIST (string &optional package) :result-type list) (declare-function ARITHMETIC-ERROR-OPERANDS ()) (declare-function ARITHMETIC-ERROR-OPERATION ()) (declare-function ARRAY-DIMENSION (array integer) :result-type (integer 0)) (declare-function ARRAY-DIMENSIONS (array) :result-type (list (integer 0))) (declare-function ARRAY-DISPLACEMENT ()) (declare-function ARRAY-ELEMENT-TYPE ()) (declare-function ARRAY-HAS-FILL-POINTER-P ()) (declare-function ARRAY-IN-BOUNDS-P ()) (declare-function ARRAYP ()) (declare-function ARRAY-RANK ()) (declare-function ARRAY-ROW-MAJOR-INDEX ()) (declare-function ARRAY-TOTAL-SIZE ()) (declare-function ASH ()) (declare-function ASIN (number) :result-type real) (declare-function ASINH (number) :result-type number) (declare-function ASSOC ()) (declare-function ASSOC-IF ()) (declare-function ASSOC-IF-NOT ()) (declare-function ATAN (number1 &optional number2) :result-type real) (declare-function ATANH (number) :result-type number) (declare-function ATOM ()) (declare-function BIT-ANDC1 ()) (declare-function BIT-ANDC2 ()) (declare-function BIT-AND ()) (declare-function BIT-EQV ()) (declare-function BIT-IOR ()) (declare-function BIT-NAND ()) (declare-function BIT-NOR ()) (declare-function BIT-NOT ()) (declare-function BIT-ORC1 ()) (declare-function BIT-ORC2 ()) (declare-function BIT-VECTOR-P ()) (declare-function BIT-XOR ()) (declare-function BOOLE ()) (declare-function BOTH-CASE-P ()) (declare-function BOUNDP ()) (declare-function BREAK ()) (declare-function BROADCAST-STREAM-STREAMS ()) (declare-function BUTLAST ()) (declare-function BYTE ()) (declare-function BYTE-POSITION ()) (declare-function BYTE-SIZE ()) (declare-function CEILING ()) (declare-function CELL-ERROR-NAME ()) (declare-function CERROR ()) (declare-function CHARACTER ()) (declare-function CHARACTERP ()) (declare-function CHAR-CODE ()) (declare-function CHAR-DOWNCASE ()) (declare-function CHAR-EQUAL ()) (declare-function CHAR<= ()) (declare-function CHAR< ()) (declare-function CHAR= ()) (declare-function CHAR>= ()) (declare-function CHAR> ()) (declare-function CHAR/= ()) (declare-function CHAR-GREATERP ()) (declare-function CHAR-INT ()) (declare-function CHAR-LESSP ()) (declare-function CHAR-NAME ()) (declare-function CHAR-NOT-EQUAL ()) (declare-function CHAR-NOT-GREATERP ()) (declare-function CHAR-NOT-LESSP ()) (declare-function CHAR-UPCASE ()) (declare-function CIS ()) (declare-function CLASS-OF ()) (declare-function CLEAR-INPUT ()) (declare-function CLEAR-OUTPUT ()) (declare-function CLOSE ()) (declare-function CLRHASH ()) (declare-function CODE-CHAR ()) (declare-function COERCE ()) (declare-function COMPILED-FUNCTION-P ()) (declare-function COMPILE-FILE ()) (declare-function COMPILE-FILE-PATHNAME ()) (declare-function COMPLEMENT ()) (declare-function COMPLEX ()) (declare-function COMPLEXP ()) (declare-function COMPUTE-RESTARTS ()) (declare-function CONCATENATED-STREAM-STREAMS ()) (declare-function CONCATENATE ()) (declare-function CONJUGATE ()) (declare-function CONS ()) (declare-function CONSP ()) (declare-function CONSTANTLY ()) (declare-function COPY-ALIST ()) (declare-function COPY-LIST ()) (declare-function COPY-PPRINT-DISPATCH ()) (declare-function COPY-READTABLE ()) (declare-function COPY-SEQ ()) (declare-function COPY-STRUCTURE ()) (declare-function COPY-SYMBOL ()) (declare-function COPY-TREE ()) (declare-function COS (number) :result-type number) (declare-function COSH (number) :result-type number) (declare-function COUNT ()) (declare-function COUNT-IF ()) (declare-function COUNT-IF-NOT ()) (declare-function DECODE-FLOAT ()) (declare-function DECODE-UNIVERSAL-TIME ()) (declare-function DELETE-DUPLICATES ()) (declare-function DELETE-FILE ()) (declare-function DELETE ()) (declare-function DELETE-IF ()) (declare-function DELETE-IF-NOT ()) (declare-function DELETE-PACKAGE ()) (declare-function DENOMINATOR ()) (declare-function DEPOSIT-FIELD ()) (declare-function DESCRIBE ()) (declare-function DIGIT-CHAR ()) (declare-function DIGIT-CHAR-P ()) (declare-function DIRECTORY ()) (declare-function DIRECTORY-NAMESTRING ()) (declare-function DISASSEMBLE ()) (declare-function DPB ()) (declare-function DRIBBLE ()) (declare-function ECHO-STREAM-INPUT-STREAM ()) (declare-function ECHO-STREAM-OUTPUT-STREAM ()) (declare-function ED ()) (declare-function ENDP ()) (declare-function ENOUGH-NAMESTRING ()) (declare-function ENSURE-DIRECTORIES-EXIST ()) (declare-function ENSURE-GENERIC-FUNCTION ()) (declare-function EQ ()) (declare-function EQL ()) (declare-function EQUAL ()) (declare-function EQUALP ()) (declare-function ERROR ()) (declare-function EVENP ()) (declare-function EVERY ()) (declare-function EXP ()) (declare-function EXPORT ()) (declare-function EXPT ()) (declare-function FBOUNDP ()) (declare-function FCEILING ()) (declare-function FFLOOR ()) (declare-function FILE-AUTHOR ()) (declare-function FILE-ERROR-PATHNAME ()) (declare-function FILE-LENGTH ()) (declare-function FILE-NAMESTRING ()) (declare-function FILE-POSITION ()) (declare-function FILE-STRING-LENGTH ()) (declare-function FILE-WRITE-DATE ()) (declare-function FILL ()) (declare-function FIND-ALL-SYMBOLS ()) (declare-function FIND ()) (declare-function FIND-IF ()) (declare-function FIND-IF-NOT ()) (declare-function FIND-PACKAGE ()) (declare-function FIND-RESTART ()) (declare-function FIND-SYMBOL ()) (declare-function FINISH-OUTPUT ()) (declare-function FLOAT-DIGITS ()) (declare-function FLOAT ()) (declare-function FLOATP ()) (declare-function FLOAT-PRECISION ()) (declare-function FLOAT-RADIX ()) (declare-function FLOAT-SIGN ()) (declare-function FLOOR ()) (declare-function FMAKUNBOUND ()) (declare-function FORCE-OUTPUT ()) (declare-function FORMAT ()) (declare-function FRESH-LINE ()) (declare-function FROUND ()) (declare-function FTRUNCATE ()) (declare-function FUNCALL ()) (declare-function <= ()) (declare-function < ()) (declare-function = ()) (declare-function >= ()) (declare-function > ()) (declare-function - ()) (declare-function /= ()) (declare-function / ()) (declare-function * ()) (declare-function + ()) (declare-function FUNCTION-LAMBDA-EXPRESSION ()) (declare-function FUNCTIONP ()) (declare-function GCD ()) (declare-function GENSYM ()) (declare-function GENTEMP ()) (declare-function GET-DECODED-TIME ()) (declare-function GET-DISPATCH-MACRO-CHARACTER ()) (declare-function GET-INTERNAL-REAL-TIME ()) (declare-function GET-INTERNAL-RUN-TIME ()) (declare-function GET-MACRO-CHARACTER ()) (declare-function GET-OUTPUT-STREAM-STRING ()) (declare-function GET-PROPERTIES ()) (declare-function GET-SETF-EXPANSION ()) (declare-function GET-UNIVERSAL-TIME ()) (declare-function GRAPHIC-CHAR-P ()) (declare-function HASH-TABLE-COUNT ()) (declare-function HASH-TABLE-P ()) (declare-function HASH-TABLE-REHASH-SIZE ()) (declare-function HASH-TABLE-REHASH-THRESHOLD ()) (declare-function HASH-TABLE-SIZE ()) (declare-function HASH-TABLE-TEST ()) (declare-function HOST-NAMESTRING ()) (declare-function IDENTITY ()) (declare-function IMAGPART ()) (declare-function IMPORT ()) (declare-function INPUT-STREAM-P ()) (declare-function INSPECT ()) (declare-function INTEGER-DECODE-FLOAT ()) (declare-function INTEGER-LENGTH ()) (declare-function INTEGERP ()) (declare-function INTERACTIVE-STREAM-P ()) (declare-function INTERN ()) (declare-function INTERSECTION ()) (declare-function INVALID-METHOD-ERROR ()) (declare-function INVOKE-DEBUGGER ()) (declare-function INVOKE-RESTART ()) (declare-function INVOKE-RESTART-INTERACTIVELY ()) (declare-function ISQRT ()) (declare-function KEYWORDP ()) (declare-function LAST ()) (declare-function LCM ()) (declare-function LDB-TEST ()) (declare-function LDIFF ()) (declare-function LENGTH ()) (declare-function LISP-IMPLEMENTATION-TYPE ()) (declare-function LISP-IMPLEMENTATION-VERSION ()) (declare-function LIST-ALL-PACKAGES ()) (declare-function LISTEN ()) (declare-function LIST ()) (declare-function LIST* ()) (declare-function LIST-LENGTH ()) (declare-function LISTP ()) (declare-function LOAD ()) (declare-function LOAD-LOGICAL-PATHNAME-TRANSLATIONS ()) (declare-function LOGANDC1 ()) (declare-function LOGANDC2 ()) (declare-function LOGAND ()) (declare-function LOGBITP ()) (declare-function LOGCOUNT ()) (declare-function LOGEQV ()) (declare-function LOG ()) (declare-function LOGICAL-PATHNAME ()) (declare-function LOGIOR ()) (declare-function LOGNAND ()) (declare-function LOGNOR ()) (declare-function LOGNOT ()) (declare-function LOGORC1 ()) (declare-function LOGORC2 ()) (declare-function LOGTEST ()) (declare-function LOGXOR ()) (declare-function LONG-SITE-NAME ()) (declare-function LOWER-CASE-P ()) (declare-function MACHINE-INSTANCE ()) (declare-function MACHINE-TYPE ()) (declare-function MACHINE-VERSION ()) (declare-function MAKE-ARRAY ()) (declare-function MAKE-BROADCAST-STREAM ()) (declare-function MAKE-CONCATENATED-STREAM ()) (declare-function MAKE-CONDITION ()) (declare-function MAKE-DISPATCH-MACRO-CHARACTER ()) (declare-function MAKE-ECHO-STREAM ()) (declare-function MAKE-HASH-TABLE ()) (declare-function MAKE-LIST ()) (declare-function MAKE-LOAD-FORM-SAVING-SLOTS ()) (declare-function MAKE-PACKAGE ()) (declare-function MAKE-PATHNAME ()) (declare-function MAKE-RANDOM-STATE ()) (declare-function MAKE-SEQUENCE ()) (declare-function MAKE-STRING ()) (declare-function MAKE-STRING-INPUT-STREAM ()) (declare-function MAKE-STRING-OUTPUT-STREAM ()) (declare-function MAKE-SYMBOL ()) (declare-function MAKE-SYNONYM-STREAM ()) (declare-function MAKE-TWO-WAY-STREAM ()) (declare-function MAKUNBOUND ()) (declare-function MAPCAN ()) (declare-function MAPCAR ()) (declare-function MAPC ()) (declare-function MAPCON ()) (declare-function MAP ()) (declare-function MAPHASH ()) (declare-function MAP-INTO ()) (declare-function MAPL ()) (declare-function MAPLIST ()) (declare-function MAX ()) (declare-function MEMBER ()) (declare-function MEMBER-IF ()) (declare-function MEMBER-IF-NOT ()) (declare-function MERGE ()) (declare-function MERGE-PATHNAMES ()) (declare-function METHOD-COMBINATION-ERROR ()) (declare-function MIN ()) (declare-function MINUSP ()) (declare-function MISMATCH ()) (declare-function MOD ()) (declare-function NAME-CHAR ()) (declare-function NAMESTRING ()) (declare-function NBUTLAST ()) (declare-function NCONC ()) (declare-function NINTERSECTION ()) (declare-function NOTANY ()) (declare-function NOTEVERY ()) (declare-function NOT ()) (declare-function NRECONC ()) (declare-function NREVERSE ()) (declare-function NSET-DIFFERENCE ()) (declare-function NSET-EXCLUSIVE-OR ()) (declare-function NSTRING-CAPITALIZE ()) (declare-function NSTRING-DOWNCASE ()) (declare-function NSTRING-UPCASE ()) (declare-function NSUBLIS ()) (declare-function NSUBST ()) (declare-function NSUBST-IF ()) (declare-function NSUBST-IF-NOT ()) (declare-function NSUBSTITUTE ()) (declare-function NSUBSTITUTE-IF ()) (declare-function NSUBSTITUTE-IF-NOT ()) (declare-function NTHCDR ()) (declare-function NULL ()) (declare-function NUMBERP ()) (declare-function NUMERATOR ()) (declare-function NUNION ()) (declare-function ODDP ()) (declare-function OPEN ()) (declare-function OPEN-STREAM-P ()) (declare-function OUTPUT-STREAM-P ()) (declare-function PACKAGE-ERROR-PACKAGE ()) (declare-function PACKAGE-NAME ()) (declare-function PACKAGE-NICKNAMES ()) (declare-function PACKAGEP ()) (declare-function PACKAGE-SHADOWING-SYMBOLS ()) (declare-function PACKAGE-USED-BY-LIST ()) (declare-function PACKAGE-USE-LIST ()) (declare-function PAIRLIS ()) (declare-function PARSE-INTEGER ()) (declare-function PARSE-NAMESTRING ()) (declare-function PATHNAME-DEVICE ()) (declare-function PATHNAME-DIRECTORY ()) (declare-function PATHNAME ()) (declare-function PATHNAME-HOST ()) (declare-function PATHNAME-MATCH-P ()) (declare-function PATHNAME-NAME ()) (declare-function PATHNAMEP ()) (declare-function PATHNAME-TYPE ()) (declare-function PATHNAME-VERSION ()) (declare-function PEEK-CHAR ()) (declare-function PHASE ()) (declare-function PLUSP ()) (declare-function POSITION ()) (declare-function POSITION-IF ()) (declare-function POSITION-IF-NOT ()) (declare-function PPRINT-DISPATCH ()) (declare-function PPRINT-FILL ()) (declare-function PPRINT ()) (declare-function PPRINT-INDENT ()) (declare-function PPRINT-LINEAR ()) (declare-function PPRINT-NEWLINE ()) (declare-function PPRINT-TAB ()) (declare-function PPRINT-TABULAR ()) (declare-function PRIN1 ()) (declare-function PRIN1-TO-STRING ()) (declare-function PRINC ()) (declare-function PRINC-TO-STRING ()) (declare-function PRINT ()) (declare-function PRINT-NOT-READABLE-OBJECT ()) (declare-function PROBE-FILE ()) (declare-function PROVIDE ()) (declare-function RANDOM ()) (declare-function RANDOM-STATE-P ()) (declare-function RASSOC ()) (declare-function RASSOC-IF ()) (declare-function RASSOC-IF-NOT ()) (declare-function RATIONAL ()) (declare-function RATIONALIZE ()) (declare-function RATIONALP ()) (declare-function READ-BYTE ()) (declare-function READ-CHAR ()) (declare-function READ-CHAR-NO-HANG ()) (declare-function READ-DELIMITED-LIST ()) (declare-function READ-FROM-STRING ()) (declare-function READ ()) (declare-function READ-LINE ()) (declare-function READ-PRESERVING-WHITESPACE ()) (declare-function READ-SEQUENCE ()) (declare-function READTABLEP ()) (declare-function REALPART ()) (declare-function REALP ()) (declare-function REDUCE ()) (declare-function REM ()) (declare-function REMHASH ()) (declare-function REMOVE-DUPLICATES ()) (declare-function REMOVE ()) (declare-function REMOVE-IF ()) (declare-function REMOVE-IF-NOT ()) (declare-function REMPROP ()) (declare-function RENAME-FILE ()) (declare-function RENAME-PACKAGE ()) (declare-function REPLACE ()) (declare-function REQUIRE ()) (declare-function RESTART-NAME ()) (declare-function REVAPPEND ()) (declare-function REVERSE ()) (declare-function ROOM ()) (declare-function ROUND ()) (declare-function RPLACA ()) (declare-function RPLACD ()) (declare-function SCALE-FLOAT ()) (declare-function SEARCH ()) (declare-function SET-DIFFERENCE ()) (declare-function SET-DISPATCH-MACRO-CHARACTER ()) (declare-function SET-EXCLUSIVE-OR ()) (declare-function SET ()) (declare-function SET-MACRO-CHARACTER ()) (declare-function SET-PPRINT-DISPATCH ()) (declare-function SET-SYNTAX-FROM-CHAR ()) (declare-function SHADOW ()) (declare-function SHADOWING-IMPORT ()) (declare-function SHORT-SITE-NAME ()) (declare-function SIGNAL ()) (declare-function SIGNUM ()) (declare-function SIMPLE-BIT-VECTOR-P ()) (declare-function SIMPLE-CONDITION-FORMAT-ARGUMENTS ()) (declare-function SIMPLE-CONDITION-FORMAT-CONTROL ()) (declare-function SIMPLE-STRING-P ()) (declare-function SIMPLE-VECTOR-P ()) (declare-function SIN (number) :result-type number) (declare-function SINH (number) :result-type number) (declare-function SLEEP ()) (declare-function SLOT-BOUNDP ()) (declare-function SLOT-EXISTS-P ()) (declare-function SLOT-MAKUNBOUND ()) (declare-function SLOT-VALUE ()) (declare-function SOFTWARE-TYPE ()) (declare-function SOFTWARE-VERSION ()) (declare-function SOME ()) (declare-function SORT ()) (declare-function SQRT ()) (declare-function STABLE-SORT ()) (declare-function STANDARD-CHAR-P ()) (declare-function STREAM-ELEMENT-TYPE ()) (declare-function STREAM-ERROR-STREAM ()) (declare-function STREAM-EXTERNAL-FORMAT ()) (declare-function STREAMP ()) (declare-function STRING-CAPITALIZE ()) (declare-function STRING-DOWNCASE ()) (declare-function STRING-EQUAL ()) (declare-function STRING<= ()) (declare-function STRING< ()) (declare-function STRING= ()) (declare-function STRING>= ()) (declare-function STRING> ()) (declare-function STRING ()) (declare-function STRING/= ()) (declare-function STRING-GREATERP ()) (declare-function STRING-LEFT-TRIM ()) (declare-function STRING-LESSP ()) (declare-function STRING-NOT-EQUAL ()) (declare-function STRING-NOT-GREATERP ()) (declare-function STRING-NOT-LESSP ()) (declare-function STRINGP ()) (declare-function STRING-RIGHT-TRIM ()) (declare-function STRING-TRIM ()) (declare-function STRING-UPCASE ()) (declare-function SUBLIS ()) (declare-function SUBSETP ()) (declare-function SUBST ()) (declare-function SUBST-IF ()) (declare-function SUBST-IF-NOT ()) (declare-function SUBSTITUTE ()) (declare-function SUBSTITUTE-IF ()) (declare-function SUBSTITUTE-IF-NOT ()) (declare-function SUBTYPEP ()) (declare-function SXHASH ()) (declare-function SYMBOL-NAME ()) (declare-function SYMBOL-PACKAGE ()) (declare-function SYMBOLP ()) (declare-function SYNONYM-STREAM-SYMBOL ()) (declare-function TAILP ()) (declare-function TAN (number) :result-type number) (declare-function TANH (number) :result-type number) (declare-function TERPRI ()) (declare-function TRANSLATE-LOGICAL-PATHNAME ()) (declare-function TRANSLATE-PATHNAME ()) (declare-function TREE-EQUAL ()) (declare-function TRUENAME ()) (declare-function TRUNCATE ()) (declare-function TWO-WAY-STREAM-INPUT-STREAM ()) (declare-function TWO-WAY-STREAM-OUTPUT-STREAM ()) (declare-function TYPE-ERROR-DATUM ()) (declare-function TYPE-ERROR-EXPECTED-TYPE ()) (declare-function TYPE-OF ()) (declare-function TYPEP ()) (declare-function UNBOUND-SLOT-INSTANCE ()) (declare-function UNEXPORT ()) (declare-function UNINTERN ()) (declare-function UNION ()) (declare-function UNREAD-CHAR ()) (declare-function UNUSE-PACKAGE ()) (declare-function UPGRADED-ARRAY-ELEMENT-TYPE ()) (declare-function UPGRADED-COMPLEX-PART-TYPE ()) (declare-function UPPER-CASE-P ()) (declare-function USE-PACKAGE ()) (declare-function USER-HOMEDIR-PATHNAME ()) (declare-function VALUES-LIST ()) (declare-function VECTOR ()) (declare-function VECTORP ()) (declare-function VECTOR-POP ()) (declare-function VECTOR-PUSH-EXTEND ()) (declare-function VECTOR-PUSH ()) (declare-function WARN ()) (declare-function WILD-PATHNAME-P ()) (declare-function WRITE-BYTE ()) (declare-function WRITE-CHAR ()) (declare-function WRITE ()) (declare-function WRITE-LINE ()) (declare-function WRITE-SEQUENCE ()) (declare-function WRITE-STRING ()) (declare-function WRITE-TO-STRING ()) (declare-function YES-OR-NO-P ()) (declare-function Y-OR-N-P ()) (declare-function ZEROP ()) (declare-local-function CALL-NEXT-METHOD (&rest arguments)) (declare-local-function NEXT-METHOD-P ()) (declare-local-macro CALL-METHOD ()) (declare-local-macro LOOP-FINISH ()) (declare-local-macro MAKE-METHOD ()) (declare-local-macro PPRINT-EXIT-IF-LIST-EXHAUSTED ()) (declare-local-macro PPRINT-POP ()) ;;; macros -- 3. Evaluation and Compilation ;;; macros -- 4. Types and Classes ;;; macros -- 5. Data and Control Flow ;;; macros -- 6. Iteration ;;; macros -- 7. Objects ;;; macros -- 8. Structures ;;; macros -- 9. Conditions ;;; macros -- 10. Symbols ;;; macros -- 11. Packages ;;; macros -- 12. Numbers ;;; macros -- 13. Characters ;;; macros -- 14. Conses ;;; macros -- 15. Arrays ;;; macros -- 16. Strings ;;; macros -- 17. Sequences ;;; macros -- 18. Hash Tables ;;; macros -- 19. Filenames ;;; macros -- 20. Files ;;; macros -- 21. Streams ;;; macros -- 22. Printer ;;; macros -- 23. Reader ;;; macros -- 24. System Construction ;;; macros -- 25. Environment (declare-macro AND ()) (declare-macro ASSERT ()) (declare-macro CASE ()) (declare-macro CCASE ()) (declare-macro CHECK-TYPE ()) (declare-macro COND ()) (declare-macro CTYPECASE ()) (declare-macro DECF ()) (declare-macro DECLAIM ()) (declare-macro DEFCLASS ()) (declare-macro DEFCONSTANT ()) (declare-macro DEFGENERIC ()) (declare-macro DEFINE-COMPILER-MACRO ()) (declare-macro DEFINE-CONDITION ()) (declare-macro DEFINE-METHOD-COMBINATION ()) (declare-macro DEFINE-MODIFY-MACRO ()) (declare-macro DEFINE-SETF-EXPANDER ()) (declare-macro DEFINE-SYMBOL-MACRO ()) (declare-macro DEFMACRO ()) (declare-macro DEFMETHOD ()) (declare-macro DEFPACKAGE ()) (declare-macro DEFPARAMETER ()) (declare-macro DEFSETF ()) (declare-macro DEFSTRUCT ()) (declare-macro DEFTYPE ()) (declare-macro DEFUN ()) (declare-macro DEFVAR ()) (declare-macro DESTRUCTURING-BIND ()) (declare-macro DO-ALL-SYMBOLS ()) (declare-macro DO-EXTERNAL-SYMBOLS ()) (declare-macro DOLIST ()) (declare-macro DO ()) (declare-macro DO* ()) (declare-macro DO-SYMBOLS ()) (declare-macro DOTIMES ()) (declare-macro ECASE ()) (declare-macro ETYPECASE ()) (declare-macro FORMATTER ()) (declare-macro HANDLER-BIND ()) (declare-macro HANDLER-CASE ()) (declare-macro IGNORE-ERRORS ()) (declare-macro INCF ()) (declare-macro IN-PACKAGE ()) (declare-macro LAMBDA ()) (declare-macro LOOP ()) (declare-macro MULTIPLE-VALUE-BIND ()) (declare-macro MULTIPLE-VALUE-LIST ()) (declare-macro MULTIPLE-VALUE-SETQ ()) (declare-macro NTH-VALUE ()) (declare-macro OR ()) (declare-macro POP ()) (declare-macro PPRINT-LOGICAL-BLOCK ()) (declare-macro PRINT-UNREADABLE-OBJECT ()) (declare-macro PROG1 ()) (declare-macro PROG2 ()) (declare-macro PROG ()) (declare-macro PROG* ()) (declare-macro PSETF ()) (declare-macro PSETQ ()) (declare-macro PUSH ()) (declare-macro PUSHNEW ()) (declare-macro REMF ()) (declare-macro RESTART-BIND ()) (declare-macro RESTART-CASE ()) (declare-macro RETURN ()) (declare-macro ROTATEF ()) (declare-macro SETF ()) (declare-macro SHIFTF ()) (declare-macro STEP ()) (declare-macro TIME ()) (declare-macro TRACE ()) (declare-macro TYPECASE ()) (declare-macro UNLESS ()) (declare-macro UNTRACE ()) (declare-macro WHEN ()) (declare-macro WITH-ACCESSORS ()) (declare-macro WITH-COMPILATION-UNIT ()) (declare-macro WITH-CONDITION-RESTARTS ()) (declare-macro WITH-HASH-TABLE-ITERATOR ()) (declare-macro WITH-INPUT-FROM-STRING ()) (declare-macro WITH-OPEN-STREAM ()) (declare-macro WITH-OUTPUT-TO-STRING ()) (declare-macro WITH-PACKAGE-ITERATOR ()) (declare-macro WITH-SIMPLE-RESTART ()) (declare-macro WITH-SLOTS ()) (declare-macro WITH-STANDARD-IO-SYNTAX ()) (declare-restart ABORT ()) (declare-restart CONTINUE ()) (declare-restart MUFFLE-WARNING ()) (declare-restart STORE-VALUE ()) (declare-restart USE-VALUE ()) ;;; special operators -- 3. Evaluation and Compilation ;;; special operators -- 4. Types and Classes ;;; special operators -- 5. Data and Control Flow ;;; special operators -- 6. Iteration ;;; special operators -- 7. Objects ;;; special operators -- 8. Structures ;;; special operators -- 9. Conditions ;;; special operators -- 10. Symbols ;;; special operators -- 11. Packages ;;; special operators -- 12. Numbers ;;; special operators -- 13. Characters ;;; special operators -- 14. Conses ;;; special operators -- 15. Arrays ;;; special operators -- 16. Strings ;;; special operators -- 17. Sequences ;;; special operators -- 18. Hash Tables ;;; special operators -- 19. Filenames ;;; special operators -- 20. Files ;;; special operators -- 21. Streams ;;; special operators -- 22. Printer ;;; special operators -- 23. Reader ;;; special operators -- 24. System Construction ;;; special operators -- 25. Environment (declare-special-operator BLOCK ()) (declare-special-operator CATCH ()) (declare-special-operator EVAL-WHEN ()) (declare-special-operator FLET ()) (declare-special-operator FUNCTION ()) (declare-special-operator GO ()) (declare-special-operator IF ()) (declare-special-operator LABELS ()) (declare-special-operator LET ()) (declare-special-operator LET* ()) (declare-special-operator LOAD-TIME-VALUE ()) (declare-special-operator LOCALLY ()) (declare-special-operator MACROLET ()) (declare-special-operator MULTIPLE-VALUE-CALL ()) (declare-special-operator MULTIPLE-VALUE-PROG1 ()) (declare-special-operator PROGN ()) (declare-special-operator PROGV ()) (declare-special-operator QUOTE ()) (declare-special-operator RETURN-FROM ()) (declare-special-operator SETQ ()) (declare-special-operator SYMBOL-MACROLET ()) (declare-special-operator TAGBODY ()) (declare-special-operator THE ()) (declare-special-operator THROW ()) (declare-special-operator UNWIND-PROTECT ()) ;;; generic functions -- 3. Evaluation and Compilation ;;; generic functions -- 4. Types and Classes ;;; generic functions -- 5. Data and Control Flow ;;; generic functions -- 6. Iteration ;;; generic functions -- 7. Objects ;;; generic functions -- 8. Structures ;;; generic functions -- 9. Conditions ;;; generic functions -- 10. Symbols ;;; generic functions -- 11. Packages ;;; generic functions -- 12. Numbers ;;; generic functions -- 13. Characters ;;; generic functions -- 14. Conses ;;; generic functions -- 15. Arrays ;;; generic functions -- 16. Strings ;;; generic functions -- 17. Sequences ;;; generic functions -- 18. Hash Tables ;;; generic functions -- 19. Filenames ;;; generic functions -- 20. Files ;;; generic functions -- 21. Streams ;;; generic functions -- 22. Printer ;;; generic functions -- 23. Reader ;;; generic functions -- 24. System Construction ;;; generic functions -- 25. Environment (declare-standard-generic-function ADD-METHOD ()) (declare-standard-generic-function ALLOCATE-INSTANCE ()) (declare-standard-generic-function CHANGE-CLASS ()) (declare-standard-generic-function CLASS-NAME ()) (declare-standard-generic-function COMPUTE-APPLICABLE-METHODS ()) (declare-standard-generic-function DESCRIBE-OBJECT ()) (declare-standard-generic-function DOCUMENTATION ()) (declare-standard-generic-function FIND-METHOD ()) (declare-standard-generic-function FUNCTION-KEYWORDS ()) (declare-standard-generic-function INITIALIZE-INSTANCE ()) (declare-standard-generic-function MAKE-INSTANCES-OBSOLETE ()) (declare-standard-generic-function MAKE-INSTANCE ()) (declare-standard-generic-function MAKE-LOAD-FORM ()) (declare-standard-generic-function METHOD-QUALIFIERS ()) (declare-standard-generic-function NO-APPLICABLE-METHOD ()) (declare-standard-generic-function NO-NEXT-METHOD ()) (declare-standard-generic-function PRINT-OBJECT ()) (declare-standard-generic-function REINITIALIZE-INSTANCE ()) (declare-standard-generic-function REMOVE-METHOD ()) (declare-standard-generic-function SHARED-INITIALIZE ()) (declare-standard-generic-function SLOT-MISSING ()) (declare-standard-generic-function SLOT-UNBOUND ()) (declare-standard-generic-function UPDATE-INSTANCE-FOR-DIFFERENT-CLASS ()) (declare-standard-generic-function UPDATE-INSTANCE-FOR-REDEFINED-CLASS ()) ;;;; THE END ;;;;
77,095
Common Lisp
.lisp
1,616
44.581064
173
0.692043
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
745d803e21cdb4d7bb37612b1ff87648657d90a1f85eabc1f6d49f9971ea6547
4,958
[ -1 ]
4,959
relative-package.lisp
informatimago_lisp/common-lisp/lisp/relative-package.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: relative-package.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Implements Allegro CL-like relative packages. ;;;; http://franz.com/support/documentation/8.1/doc/packages.htm#relative-2 ;;;; ;;;; Note: |..foo| won't be read as a relative package name. ;;;; .|.foo| will be read as the relative package name ..|foo|. ;;;; ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-11-01 <PJB> Created. ;;;;BUGS ;;;; ;;;; Doesn't handle escapes in dotted package names! ;;;; .|.foo|:x ..f\o\o:x ..f\:\o:x ..|f:o|:x ..f\ \o:x ..|f o|:x are broken. ;;;; ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.STRING") (:import-from "COM.INFORMATIMAGO.COMMON-LISP.LISP-READER.READER" "READTABLE-PARSE-TOKEN" "SYMBOL-IN-MISSING-PACKAGE-ERROR" "SYMBOL-MISSING-IN-PACKAGE-ERROR" "UNEXPORTED-SYMBOL-ERROR" ;; temporarily: (will have to export our own restart symbols). "INTERN-HERE" "RETURN-UNINTERNED" "INVALID-SYMBOL-COMPONENT-LIST" "INTERNAL-SYMBOL" "MISSING-SYMBOL" "MISSING-PACKAGE" "MAKE-SYMBOL-PARSER-FUNCTION" "MAKE-TOKEN-PARSER") (:shadow . #1=("FIND-PACKAGE" "MAKE-PACKAGE" "DELETE-PACKAGE" "FIND-SYMBOL" "IMPORT" "INTERN" "SHADOW" "SHADOWING-IMPORT" "EXPORT" "UNEXPORT" "UNINTERN" "USE-PACKAGE" "UNUSE-PACKAGE" "PACKAGE-NAME" "PACKAGE-NICKNAMES" "PACKAGE-USE-LIST" "PACKAGE-USED-BY-LIST" "PACKAGE-SHADOWING-SYMBOLS" "RENAME-PACKAGE" "WITH-PACKAGE-ITERATOR" "DO-SYMBOLS" "DO-EXTERNAL-SYMBOLS" "DEFPACKAGE" "IN-PACKAGE")) (:export "ENABLE-RELATIVE-PACKAGE-NAMES" "DISABLE-RELATIVE-PACKAGE-NAMES" "PACKAGE-DESIGNATOR" "PACKAGE-PARENT" "PACKAGE-CHILDREN" "*DISABLE-USELESS-PARENT-PACKAGE-CHECK*" . #1#)) (defpackage "COMMON-LISP-WITH-RELATIVE-PACKAGE" (:nicknames "CL-RP") (:documentation "This is a package like COMMON-LISP, but with relative package names.") (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE") (:shadowing-import-from "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE" . #1=("FIND-PACKAGE" "MAKE-PACKAGE" "DELETE-PACKAGE" "FIND-SYMBOL" "IMPORT" "INTERN" "SHADOW" "SHADOWING-IMPORT" "EXPORT" "UNEXPORT" "UNINTERN" "USE-PACKAGE" "UNUSE-PACKAGE" "PACKAGE-NAME" "PACKAGE-NICKNAMES" "PACKAGE-USE-LIST" "PACKAGE-USED-BY-LIST" "PACKAGE-SHADOWING-SYMBOLS" "RENAME-PACKAGE" "WITH-PACKAGE-ITERATOR" "DO-SYMBOLS" "DO-EXTERNAL-SYMBOLS" "DEFPACKAGE" "IN-PACKAGE")) (:export . #.(let ((names '())) (do-external-symbols (s "COMMON-LISP" names) (push (symbol-name s) names)))) (:export "ENABLE-RELATIVE-PACKAGE-NAMES" "DISABLE-RELATIVE-PACKAGE-NAMES" "PACKAGE-DESIGNATOR" "PACKAGE-PARENT" "PACKAGE-CHILDREN" "*DISABLE-USELESS-PARENT-PACKAGE-CHECK*")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE") #| Notes ================================================== Package structure vs. name structure -------------------------------------------------- cf. `<http://franz.com/support/documentation/8.1/doc/packages.htm#relative-2>`_ The hierarchial packages as implemented by Allegro CL, introduce an inconsistency in the children-parent relationship between PACKAGEs. On one one hand, RELATIVE-PACKAGE-NAME-TO-PACKAGE and PACKAGE-PARENT enforce that the parent of a package be an existing package, and therefore when we have two packages: "R.A1.A2.A3.X" and "R.B1.B2.B3.Y", then cannot refer one to the other using the relative package NAME ....B1.B2.B3.Y or ....A1.A2.A3.X if there are no package named "R.A1.A2.A3" "R.A1.A2" "R.A1" or "R.B1.B2.B3" "R.B1.B2" "R.B1". On the other hand, PACKAGE-CHILDREN :RECURSE T will gladly return in its result, packages selected on the only basis of their package NAME having a given prefix, regardless whether THEY have a parent. So with only the two packages "R.A1.A2.A3.X" and "R.B1.B2.B3.Y", (package-children "R") will return (#<package "R.A1.A2.A3.X"> #<package "R.B1.B2.B3.Y">), but (mapcar 'package-parent (package-children "R")) will signal an error. Furthermore, if packages where "hierarchical", and really "have" children, shouldn't DELETE-PACKAGE also delete the children of a package bar leaving them parentless? A parent-children relationship would be a run-time entity, while refering to another package using a relative NAME would be a read-time operation. Do we need the former? This package implements "bug-for-bug" Allegro's "hierarchical" packages, but IMO, it would be better to base the operations on package NAMES rather than on an implied or effective parent-children relationship between PACKAGES. For example, in Allegro's reference implementation it's indicated that relative-package-name-to-package should be fast because used at read-time. Well, it would be faster if we didn't tested for the existence of all the intermediary parent packages! Another advantage of basing a design of relative package names only on NAMES, is that it would be a smaller extension on the CL standard, and therefore risking fewer unseen consequences (such as DELETE-PACKAGE having to delete the children packages). On the other hand, one advantage on insisting on the existence of intermediary packages, is that it allows to create a border around relative package pathnames, to effectively prevent refering packages outside of a sub-hierarchy (cf. in relative-package-test.lisp how it's done by avoiding the creating the ".TEST.NONE" package). Relative package names are insufficient -------------------------------------------------- Relative packages are useful to provide short names to packages that are related. However, when using library packages with structured names, they are not useful, since we are actually crossing to other package name trees: :: (in-package :com.ogamita.nasium-lse.os) (com.informatimago.common-lisp.cesarum.string:prefixp "Insu" "Insufficient!") For this, we need local nicknames. Local nicknames can be compiled with relative package names to imply local nicknames for all children and grand children of the local nicknamed packages. :: (in-package :com.ogamita.nasium-lse.os) (add-local-nickname :com.informatimago.common-lisp.cesarum :cesarum) (cesarum.string:prefixp "Su" "Sufficient!") |# (deftype package-designator () '(or package string-designator)) (defun package-name-to-package (name) (cl:find-package name)) (defconstant +package-separator+ #\:) (defconstant +relative-prefix+ #\.) (defconstant +component-separator+ #\.) (defparameter *relative-prefix* (string +relative-prefix+)) (defparameter *component-separator* (string +component-separator+)) (defvar *disable-useless-parent-package-check* nil) ;; (setf *disable-useless-parent-package-check* t) (defun resolve-relative-package-name (name &optional (*package* *package*)) (if (and (plusp (length name)) (char= (aref name 0) +relative-prefix+)) (let ((base (nreverse (split-string (package-name *package*) *component-separator*)))) (loop :for i :from 1 :below (length name) :while (char= (aref name i) +relative-prefix+) :do (pop base) :do (unless *disable-useless-parent-package-check* ;; bug-for-bug simile of Allegro's. (let ((parent (unsplit-string (reverse base) +component-separator+))) (unless (package-name-to-package parent) (error "The parent package ~S does not exist." parent)))) :finally (return (let ((parent (unsplit-string (nreverse base) +component-separator+))) (if (< i (length name)) (concatenate 'string parent *component-separator* (subseq name i)) parent))))) name)) (defun relative-package-name-to-package (name &optional (*package* *package*)) (when (and (plusp (length name)) (char= (aref name 0) +relative-prefix+)) (package-name-to-package (resolve-relative-package-name name *package*)))) (defgeneric find-package (package-designator) (:documentation " PACKAGE-DESIGNATOR: a package designator. RETURN: the designated package, or NIL. DO: When a string designator is given, then if there is a package with the same *name* or *nickname*, it's designated, else if there is a package *named* by the combination of the designator and the current *PACKAGE* *name*, it's designated. Otherwise NIL is returned. ") (:method ((designator t)) (check-type designator package-designator "A package designator is expected") (find-package designator)) (:method ((package package)) package) (:method ((designator symbol)) (find-package (symbol-name designator))) (:method ((designator character)) (find-package (string designator))) (:method ((name string)) (or (package-name-to-package name) (relative-package-name-to-package name)))) (defgeneric package-parent (package-designator) (:documentation " SIGNAL: an ERROR if there's no direct parent package. RETURN: the parent package of the package designated by PACKAGE-DESIGNATOR. NOTE: if *DISABLE-USELESS-PARENT-PACKAGE-CHECK* is true then return the name of the missing parent package instead of signaling an error. ") (:method ((designator t)) (check-type designator package-designator "A package designator is expected") (package-parent designator)) (:method ((package package)) (package-parent (package-name package))) (:method ((designator symbol)) (package-parent (symbol-name designator))) (:method ((designator character)) (package-parent (string designator))) (:method ((name string)) (let ((pos (position +component-separator+ name :from-end t))) (if pos (let ((parent (subseq name 0 pos))) (or (package-name-to-package parent) (if *disable-useless-parent-package-check* parent (error "The parent of ~a does not exist." name)))) (error "There is no parent of ~a." name))))) (defgeneric package-children (package-specifier &key recurse) (:documentation " RETURN: A list of all the child packages of the package designated by PACKAGE-DESIGNATOR. If RECURSE is NIL, then only the direct children are listed. NOTE: The current implementation uses a prefix filter on the name of packages, so with RECURSE set, we return grandchildren even if there's no intermediary package. ") (:method ((designator t) &key (recurse t)) (check-type designator package-designator "A package designator is expected") (package-children designator :recurse recurse)) (:method ((package package) &key (recurse t)) (package-children (package-name package) :recurse recurse)) (:method ((designator symbol) &key (recurse t)) (package-children (symbol-name designator) :recurse recurse)) (:method ((designator character) &key (recurse t)) (package-children (string designator) :recurse recurse)) (:method ((name string) &key (recurse t)) (let ((prefix (concatenate 'string name *component-separator*))) (remove-if-not (lambda (package) (let ((pname (package-name package))) (and (prefixp prefix pname) (or recurse (not (position +component-separator+ pname :start (length prefix))))))) (list-all-packages))))) (defun normalize-designator (designator) (if (typep designator 'string-designator) (resolve-relative-package-name (string designator)) designator)) (defmacro define-normalize-and-forward-package-methods (name &key (type-error nil)) (let ((cl-name (cl:intern (string name) (load-time-value (cl:find-package "COMMON-LISP"))))) `(progn (defgeneric ,name (name)) ,@ (if type-error `((defmethod ,name ((name t)) (error 'simple-type-error :datum name :expected-type 'package-designator :format-control "~S called with a non ~S: ~S" :format-arguments (list ',name 'package-designator name))) (defmethod ,name ((name package)) (,cl-name name))) `((defmethod ,name (name) (,cl-name name)))) (defmethod ,name ((name character)) (,name (string name))) (defmethod ,name ((name symbol)) (,name (string name))) (defmethod ,name ((name string)) ;; We don't have here the same sophisticated normalize ;; function as in ;; "COM.INFORMATIMAGO.COMMON-LISP.LISP-READER.PACKAGE" so we ;; defer handling wrong package names to the CL function. (,cl-name (normalize-designator name)))))) (define-normalize-and-forward-package-methods delete-package) (define-normalize-and-forward-package-methods package-name) (define-normalize-and-forward-package-methods package-nicknames) (define-normalize-and-forward-package-methods package-use-list) (define-normalize-and-forward-package-methods package-used-by-list) (define-normalize-and-forward-package-methods package-shadowing-symbols) (defgeneric make-package (pack-name &key nicknames use) (:method ((pack-name character) &key (nicknames '()) (use '())) (make-package (string pack-name) :nicknames nicknames :use use)) (:method ((pack-name symbol) &key (nicknames '()) (use '())) (make-package (string pack-name) :nicknames nicknames :use use)) (:method ((pack-name string) &key (nicknames '()) (use '())) (cl:make-package (resolve-relative-package-name pack-name) :nicknames nicknames :use (mapcar (function normalize-designator) use)))) (defgeneric rename-package (package new-name &optional new-nicknames) (:method (package new-name &optional new-nicknames) (cl:rename-package package new-name new-nicknames)) (:method ((pack-name character) new-name &optional new-nicknames) (rename-package (string pack-name) new-name new-nicknames)) (:method ((pack-name symbol) new-name &optional new-nicknames) (rename-package (string pack-name) new-name new-nicknames)) (:method ((pack-name string) new-name &optional new-nicknames) (cl:rename-package (normalize-designator pack-name) new-name new-nicknames))) ;; Using normalize-designator in the following functions defer ;; handling the undefined packages to the CL functions: (defgeneric find-symbol (sym-name &optional pack) (:method (sym-name &optional (pack *package*)) (cl:find-symbol sym-name (normalize-designator pack)))) (defgeneric intern (sym-name &optional pack) (:method (sym-name &optional (pack *package*)) (cl:intern sym-name (normalize-designator pack)))) (defgeneric unintern (symbol &optional pack) (:method (symbol &optional (pack *package*)) (cl:unintern symbol (normalize-designator pack)))) (defgeneric import (symbols &optional pack) (:method (symbols &optional (pack *package*)) (cl:import symbols (normalize-designator pack)))) (defgeneric export (symbols &optional pack) (:method (symbols &optional (pack *package*)) (cl:export symbols (normalize-designator pack)))) (defgeneric unexport (symbols &optional pack) (:method (symbols &optional (pack *package*)) (cl:unexport symbols (normalize-designator pack)))) (defgeneric shadow (symbols &optional pack) (:method (symbols &optional (pack *package*)) (cl:shadow symbols (normalize-designator pack)))) (defgeneric shadowing-import (symbols &optional pack) (:method (symbols &optional (pack *package*)) (cl:shadowing-import symbols (normalize-designator pack)))) (defgeneric use-package (packs &optional using-pack) (:method (packs &optional (using-pack *package*)) (cl:use-package (mapcar (function normalize-designator) packs) (normalize-designator using-pack)))) (defgeneric unuse-package (packs &optional using-pack) (:method (packs &optional (using-pack *package*)) (cl:unuse-package (mapcar (function normalize-designator) packs) (normalize-designator using-pack)))) ;;; Macros: (defmacro in-package (name) (if (typep name 'string-designator) `(cl:in-package ,(normalize-designator name)) `(cl:in-package ,name))) (defmacro with-package-iterator ((name package-list-form &rest symbol-types) &body declarations-body) `(cl:with-package-iterator (,name (mapcar (function normalize-designator) ,package-list-form) ,@symbol-types) ,@declarations-body)) (defmacro do-symbols ((var &optional package result-form) &body body) `(cl:do-symbols (,var ,(if package `((normalize-designator ,package)) '*package*) ,result-form) ,@body)) (defmacro do-external-symbols ((var &optional package result-form) &body body) `(cl:do-external-symbols (,var ,(if package `((normalize-designator ,package)) '*package*) ,result-form) ,@body)) (defmacro defpackage (defined-package-name &rest options) " DO: Like CL:DEFPACKAGE, but pre-processes the package names in those clauses: (:use package-name*)* | (:shadowing-import-from package-name {symbol-name}*)* | (:import-from package-name {symbol-name}*)* | NOTE: Since relative package names in those closes are resolved at macro-expansion time, the refered relative packages and all the parents in their path must exist at macro-expansion-time. " `(cl:defpackage ,defined-package-name ,@(mapcar (lambda (option) (if (atom option) option (case (first option) (:use `(:use ,@(mapcar (function normalize-designator) (rest option)))) ((:shadowing-import-from :import-from) `(,(first option) ,(normalize-designator (second option)) ,@(cddr option))) (otherwise option)))) options))) ;;; Dot reader macro. (defun symbol-from-split-token (components) " DO: Same as .READER:SYMBOL-FROM-SPLIT-TOKEN, but use relative package functions instead of CL ones. COMPONENTS: a list of strings separated by integers specifying the number of colons. EXAMPLES: X (\"X\") :Y (1 \"Y\") X:Y (\"X\" 1 \"Y\") X::Y (\"X\" 2 \"Y\") X:::Y (\"X\" 3 \"Y\") X:: (\"X\" 2) X:Y:Z (\"X\" 1 \"Y\" 1 \"Z\") RETURN: A symbol designated by the components, or signal an error. NOTE: This function implements the standard semantics, where only one occurence of : or :: is allowed, and depending on : or ::, an exported symbol is expected or not. " (values (case (length components) (1 (if (stringp (first components)) (intern (first components) *package*) (invalid-symbol-component-list components))) (2 (case (first components) ((1 2) (intern (second components) (load-time-value (find-package "KEYWORD")))) (otherwise (invalid-symbol-component-list components)))) (3 (destructuring-bind (pname colons sname) components (assert (stringp pname) (pname) "Symbol component was expected to be a string.") (assert (stringp sname) (sname) "Symbol component was expected to be a string.") (let ((package (find-package pname))) ; *** this is the critical call for relative packages. (if package (case colons (1 (multiple-value-bind (sym where) (find-symbol sname package) (case where ((nil) (missing-symbol package sname)) ((:internal) (internal-symbol package sname sym)) ((:external) sym)))) (2 (intern sname package)) (otherwise (invalid-symbol-component-list components))) (missing-package pname sname))))) (otherwise (invalid-symbol-component-list components))))) (defparameter *dot-reader-readtable* (let ((rt (com.informatimago.common-lisp.lisp-reader.reader:copy-readtable nil))) (setf (readtable-parse-token rt) (make-token-parser :parse-symbol-token (make-symbol-parser-function (function symbol-from-split-token)))) rt) " Note: a COM.INFORMATIMAGO.COMMON-LISP.LISP-READER.READER:READTABLE, not a CL:READTABLE. ") (declaim (inline terminating-macro-character-p whitespacep)) (defun terminating-macro-character-p (char &optional (*readtable* *readtable*)) (multiple-value-bind (fun non-terminating-p) (get-macro-character char *readtable*) (and fun (not non-terminating-p)))) (defun whitespacep (char &optional (*readtable* *readtable*)) ;; Hard to cache since the whitespace[2] status of a character can ;; be changed at any time in a readtable with SET-SYNTAX-FROM-CHAR. (and (not (get-macro-character char *readtable*)) (equal '(:x :x) (ignore-errors (let ((*package* (load-time-value (find-package "KEYWORD")))) (read-from-string (format nil "(X~CX)" char) nil nil)))))) #-(and) (loop for c below char-code-limit for ch = (code-char c) when (and ch (whitespacep ch)) collect ch) (defun dot-reader-macro (stream dot) (let ((buffer (make-array 64 :element-type 'character :fill-pointer 0 :adjustable t))) ;; . -> ? ;; .. -> Illegal symbol syntax in "..". ;; .x -> symbol in *package* ;; .x::y -> symbol in relative package ;; ...:y -> symbol in relative package ;; .42 -> float ;; .42:y -> symbol in relative package ;; TODO: we'd have to implement the whole lisp reader algorithm, ;; notably to handle escape sequences. Perhaps we could ;; export from our lisp reader the core returning a token, ;; before parsing it. Then we could do simply: ;; (funcall (..reader:readtable-parse-token rt) ;; (..reader:read-token stream rt)) ;; ;; Alternatively, see if we couldn't transfer the reader macros ;; from the host readtable to our reader readtable, so that we ;; may just use (..reader:read stream). ;; ;; Also broken: single dot in dotted lists cannot be read ;; anymore, once we have a reader macro on #\. We deal with ;; it in LIST-READER-MACRO, but this could be avoided if we ;; didn't have to write a reader macro for #\. (vector-push-extend dot buffer) (loop :for ch := (read-char stream nil nil) :until (or (null ch) (whitespacep ch) (terminating-macro-character-p ch)) :do (vector-push-extend ch buffer) :finally (unread-char ch stream)) (let ((com.informatimago.common-lisp.lisp-reader.reader:*readtable* *dot-reader-readtable*)) (values (com.informatimago.common-lisp.lisp-reader.reader:read-from-string buffer))))) #-(and) (progn (let ((token "...string:prefixp")) (check eql (with-input-from-string (in token) (dot-reader-macro in (read-char in))) 'prefixp)) (mapcar (lambda (token) (with-input-from-string (in token) (dot-reader-macro in (read-char in)))) '("...string:prefixp" ".X" ".TEST::HOO" "..:ADD-NICKNAME" ".42" "..relative:enable-relative-package-names")) (dolist (token '(" " "...")) (expect-condition 'error (with-input-from-string (in token) (dot-reader-macro in (read-char in)))))) (defun list-reader-macro (stream open) (declare (ignore open)) (loop :with result := (cons nil nil) :with tail := result :for ch := (peek-char t stream t nil t) ; skip spaces. :do (case ch ((#\)) (read-char stream t nil t) (return-from list-reader-macro (cdr result))) ((#\.) (read-char stream t nil t) (if (let ((next (peek-char nil stream nil nil t))) (or (null next) (whitespacep next) (terminating-macro-character-p next))) (progn ; dot (setf (cdr tail) (read stream t nil t)) (let ((final (peek-char t stream t nil t))) (unless (eql final #\)) (error "Invalid syntax after dot in dotted list ~S; found ~C" (cdr result) final)) (read-char stream t nil t)) (return-from list-reader-macro (cdr result))) (progn (unread-char ch stream) (setf (cdr tail) (cons (read stream t nil t) nil) tail (cdr tail))))) (otherwise (let ((mac (get-macro-character ch))) (if mac ;; When we have a reader macro, we must call it ourselves, ;; to check whether it reads an object or not, so we may ;; try again. (let ((item (multiple-value-list (funcall mac stream (read-char stream t nil t))))) (unless (null item) (setf (cdr tail) (cons (first item) nil) tail (cdr tail)))) ;; if not a reader macro, we can use read to proceed: (setf (cdr tail) (cons (read stream t nil t) nil) tail (cdr tail)))))))) (defmacro enable-relative-package-names () `(eval-when (:compile-toplevel :load-toplevel :execute) (set-macro-character +relative-prefix+ (function dot-reader-macro) t *readtable*) (when (char= +relative-prefix+ #\. ) (set-macro-character #\( (function list-reader-macro) nil *readtable*)))) (defmacro disable-relative-package-names () `(eval-when (:compile-toplevel :load-toplevel :execute) (set-macro-character +relative-prefix+ nil t *readtable*))) ;;;; THE END ;;;; #| 1- The aforementioned package-inferred-system extension to ASDF, which is standard since ASDF 3.1 (from May 2014, now included with all modern maintained CL implementations, which includes ABCL, Allegro, CCL, CMUCL, ECL, LispWorks, MKCL, SBCL, but not the also supported CLISP, CormanCL, GCL, Genera, MCL, MOCL, SCL, XCL). https://common-lisp.net/project/asdf/asdf/The-package_002dinferred_002dsystem-extension.html#The-package_002dinferred_002dsystem-extension It works well, is actually used in production by several systems, and does actually provide a more maintainable package discipline than the traditional "everything in one big package". 2- My experimental system package-renaming, which allows you to portably rename packages around some files, though it comes with some practical limitations. https://git.common-lisp.net/frideau/package-renaming I haven't actually used it, but it can portably implement local package nicknames, if you really want them. |#
30,085
Common Lisp
.lisp
590
41.972881
138
0.619519
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
b04485e22e3a23b5c7733568322c3d2ca4dfa7b2c8a810c3e70c50c80b487d21
4,959
[ -1 ]
4,960
com.informatimago.common-lisp.lisp.relative-package.asd
informatimago_lisp/common-lisp/lisp/com.informatimago.common-lisp.lisp.relative-package.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.lisp.relative-package.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.lisp.relative-package library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-11-02 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.lisp.relative-package" ;; system attributes: :description "A Allegro CL relative package implementation." :long-description " This system loads the relative-package package which implements Allegro CL relative packages. " :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Automn 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.lisp.relative-package/") ((#: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.common-lisp.lisp-reader" "com.informatimago.common-lisp.cesarum") :components ((:file "relative-package" :depends-on ())) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:load-op "com.informatimago.common-lisp.lisp.relative-package.test"))) #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) (asdf:oos 'asdf:test-op "com.informatimago.common-lisp.lisp.relative-package.test"))) ;;;; THE END ;;;;
3,085
Common Lisp
.lisp
63
43.936508
125
0.59609
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
724a948b032c55191bda3fe583b0f6e85826f27bafc6f2313e33c83b4719f2dc
4,960
[ -1 ]
4,961
stepper-test.lisp
informatimago_lisp/common-lisp/lisp/stepper-test.lisp
(defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER.TEST" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.SIMPLE-TEST")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER.TEST") ;;; ;;; Unit tests: ;;; (define-test test/step-atom () (check equal (cl-stepper::step-atom 42) '(com.informatimago.common-lisp.lisp.stepper.internal::call-step-atom '42 (lambda nil 42)))) (define-test test/step-simple-form () (check equal (cl-stepper::step-simple-form '(function sin)) '(com.informatimago.common-lisp.lisp.stepper.internal::call-step-atom '#'sin (lambda nil #'sin))) (check equal (cl-stepper::step-simple-form '(quote 33)) '(com.informatimago.common-lisp.lisp.stepper.internal::call-step-atom ''33 (lambda nil '33))) (check equal (cl-stepper::step-simple-form '(cl-stepper:function sin)) '(com.informatimago.common-lisp.lisp.stepper.internal::call-step-atom '(com.informatimago.common-lisp.lisp.stepper:function sin) (lambda nil (com.informatimago.common-lisp.lisp.stepper:function sin)))) (check equal (cl-stepper::step-simple-form '(cl-stepper:quote 33)) '(com.informatimago.common-lisp.lisp.stepper.internal::call-step-atom '(com.informatimago.common-lisp.lisp.stepper:quote 33) (lambda nil (com.informatimago.common-lisp.lisp.stepper:quote 33))))) (define-test test/simple-step () (check equal (cl-stepper::simple-step '(print 1)) '(com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (print 1)) '(print 1)))) (define-test test/step-body () (check equal (cl-stepper::step-body :locally '((print 1) (print 2) (print 3)) nil) '((progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (print (com.informatimago.common-lisp.lisp.stepper.internal::self-evaluating 1))) '(print 1))) (progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (print (com.informatimago.common-lisp.lisp.stepper.internal::self-evaluating 2))) '(print 2))) (progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (print (com.informatimago.common-lisp.lisp.stepper.internal::self-evaluating 3))) '(print 3)))))) (define-test test/step-function-call () (check equal (com.informatimago.common-lisp.lisp.stepper.internal::step-function-call '(print 1) nil) '(progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (print (com.informatimago.common-lisp.lisp.stepper.internal::self-evaluating 1))) '(print 1)))) (check equal (com.informatimago.common-lisp.lisp.stepper.internal::step-function-call '((lambda (x) (print x) 42)) nil) '(progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil ((lambda (x) (com.informatimago.common-lisp.lisp.stepper.internal::call-step-function 'nil 'nil '(x) (list x) (lambda nil (progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (print (com.informatimago.common-lisp.lisp.stepper.internal::symbol-reference x))) '(print x))) (com.informatimago.common-lisp.lisp.stepper.internal::self-evaluating 42)))))) '((lambda (x) (print x) 42))))) (check equal (com.informatimago.common-lisp.lisp.stepper.internal::step-function-call '((cl-stepper:lambda (x) (print x) 42)) nil) '(progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil ((lambda (x) (com.informatimago.common-lisp.lisp.stepper.internal::call-step-function 'nil 'nil '(x) (list x) (lambda nil (progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (print (com.informatimago.common-lisp.lisp.stepper.internal::symbol-reference x))) '(print x))) (com.informatimago.common-lisp.lisp.stepper.internal::self-evaluating 42)))))) '((com.informatimago.common-lisp.lisp.stepper:lambda (x) (print x) 42)))))) (define-test test/step-expression () (check equal (cl-stepper::step-expression '(cl-stepper:progn (print 1) (print 2)) nil) '(com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (progn (progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (print (com.informatimago.common-lisp.lisp.stepper.internal::self-evaluating 1))) '(print 1))) (progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (print (com.informatimago.common-lisp.lisp.stepper.internal::self-evaluating 2))) '(print 2))))) '(progn (progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (print (com.informatimago.common-lisp.lisp.stepper.internal::self-evaluating 1))) '(print 1))) (progn (com.informatimago.common-lisp.lisp.stepper.internal::call-simple-step (lambda nil (print (com.informatimago.common-lisp.lisp.stepper.internal::self-evaluating 2))) '(print 2))))))) ;;; ;;; Integration tests: ;;; (define-test test/step-abort () (handler-case #1=(with-input-from-string (in (format nil "a~%")) (with-output-to-string (out) (let* ((*query-io* (make-two-way-stream in out)) (cl-stepper:*step-trace-output* *query-io*)) (cl-stepper:step (cl-stepper:progn (print 1) (print 2)))))) (:no-error (&rest ignored) (declare (ignore ignored)) (progress-success)) (control-error (err) (progress-failure-message '#1# "Aborting the stepping signals ~A" err)))) (define-test test/all () (test/step-atom) (test/step-simple-form) (test/simple-step) (test/step-body) (test/step-function-call) (test/step-expression) (test/step-abort)) ;; (test/all)
7,118
Common Lisp
.lisp
136
38.786765
126
0.581455
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
0c0be9d119ea9de55e8ef06e8a1f7675531945b7eecdbd0dc1faacd82c17f284
4,961
[ -1 ]
4,962
com.informatimago.common-lisp.lisp.relative-package.test.asd
informatimago_lisp/common-lisp/lisp/com.informatimago.common-lisp.lisp.relative-package.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.lisp.relative-package.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.lisp.relative-package.test system. ;;;; Tests the com.informatimago.common-lisp.lisp.relative-package system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-11-02 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.lisp.relative-package.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.lisp.relative-package system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Automn 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.lisp.relative-package.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.lisp.relative-package") :components ((:file "relative-package-test" :depends-on ())) #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) (let ((*package* (find-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST"))) (uiop:symbol-call "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST" "TEST/ALL")))) ;;;; THE END ;;;;
3,157
Common Lisp
.lisp
66
41.666667
120
0.578504
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
150a7349d44602d02dc0c55dd25820bf899bb5bdc5a886179f5fa5addb5ddd22
4,962
[ -1 ]
4,963
cl-saving-defines.lisp
informatimago_lisp/common-lisp/lisp/cl-saving-defines.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: cl-saving-defines.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; See :documentation of package below. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2012-08-07 <PJB> Extracted from ibcl.lisp and restructured. ;;;; 2006-07-01 <PJB> Added deftype, defclass. ;;;; 2006-05-04 <PJB> Added this header. Augmented. ;;;;BUGS ;;;; ;;;; Since we collect only the whole forms of some specific macros, ;;;; we don't save closure, or eval-when, progn, etc. ;;;; ;;;; (let ((x 42)) ;;;; (defun g () x) ;;;; (defun s (z) (setf x z))) ;;;; (source 'g 'function) ;;;; --> (defun g nil x) ; instead of (let …) ;;;; (source 's 'function) ;;;; --> (defun s (z) (setf x z)) ; instead of (let …) ;;;; ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2012 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.CL-SAVING-DEFINES" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE" "COM.INFORMATIMAGO.COMMON-LISP.LISP-SEXP.SOURCE-FORM") (:shadow "DEFPACKAGE" "DEFINE-COMPILER-MACRO" "DEFINE-MODIFY-MACRO" "DEFINE-SETF-EXPANDER" "DEFMACRO" "DEFSETF" "DEFVAR" "DEFPARAMETER" "DEFCONSTANT" "DEFINE-SYMBOL-MACRO" "DEFSTRUCT" "DEFCLASS" "DEFTYPE" "DEFINE-CONDITION" "DEFINE-METHOD-COMBINATION" "DEFGENERIC" "DEFMETHOD" "DEFUN") (:export "DEFPACKAGE" "DEFINE-COMPILER-MACRO" "DEFINE-MODIFY-MACRO" "DEFINE-SETF-EXPANDER" "DEFMACRO" "DEFSETF" "DEFVAR" "DEFPARAMETER" "DEFCONSTANT" "DEFINE-SYMBOL-MACRO" "DEFSTRUCT" "DEFCLASS" "DEFTYPE" "DEFINE-CONDITION" "DEFINE-METHOD-COMBINATION" "DEFGENERIC" "DEFMETHOD" "DEFUN") (:documentation " This package exports macros wrapping the CL def* macros that save the source form. Copyright Pascal J. Bourguignon 2006 - 2012 This package is provided under the Afero General Public License 3. See the source file for details. ")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.CL-SAVING-DEFINES") (cl:defmacro define-wrapper-macro (defname (name &rest lambda-list) source-type) (let ((source (gensym))) `(cl:defmacro ,defname ,(list* '&whole source (cons name lambda-list)) (declare (ignorable ,@(mapcar (function parameter-name) (lambda-list-parameters (parse-lambda-list (cons name lambda-list) :macro))))) `(progn (setf (source ',,name ',,source-type) ',,source) ,(cons (intern (string (first ,source)) "COMMON-LISP") (rest ,source)))))) (define-wrapper-macro defpackage (name &rest options) :package) (define-wrapper-macro defvar (name &optional value docstring) :variable) (define-wrapper-macro defparameter (name value &optional docstring) :variable) (define-wrapper-macro defconstant (name value &optional docstring) :variable) (define-wrapper-macro define-symbol-macro (name expansion) :variable) (cl:defmacro defstruct (&whole form name-and-options &rest fields) (declare (ignorable fields)) `(progn (setf (source ',(if (consp name-and-options) (car name-and-options) name-and-options) :type) ',form) ,(cons 'cl:defstruct (rest form)))) (define-wrapper-macro deftype (name lambda-list &body body) :type) (define-wrapper-macro defclass (name parents slots &rest options) :type) (define-wrapper-macro define-condition (name parents slots &rest options) :type) (define-wrapper-macro define-compiler-macro (name lambda-list &body body) :compiler-macro) (define-wrapper-macro define-modify-macro (name lambda-list fun &optional docstring) :function) (define-wrapper-macro define-setf-expander (name lambda-list &body body) :function) (define-wrapper-macro defsetf (name lambda-list &body body) :function) (define-wrapper-macro defmacro (name lambda-list &body body) :function) (define-wrapper-macro defun (name lambda-list &body body) :function) (define-wrapper-macro defgeneric (name lambda-list &rest options) :function) (define-wrapper-macro define-method-combination (name &rest options) :method-combination) (cl:defmacro defmethod (&whole form name &rest arguments) (let ((qualifiers (loop :while (atom (first arguments)) :collect (pop arguments)))) (destructuring-bind (lambda-list &body body) arguments (declare (ignorable body)) (let ((specializers (mapcar (lambda (parameter) (if (parameter-specializer-p parameter) (parameter-specializer parameter) 't)) (lambda-list-mandatory-parameters (parse-lambda-list lambda-list :specialized))))) `(progn (setf (source '(,name ,qualifiers ,specializers) :method) ',form) ,(cons 'cl:defmethod (rest form))))))) ;;;; THE END ;;;;
6,703
Common Lisp
.lisp
129
45.496124
97
0.584251
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
d9aeb4bde3979d488daf4c1fb2ff866a5657581b43981fbcc21463f1166a0b30
4,963
[ -1 ]
4,964
stepper.lisp
informatimago_lisp/common-lisp/lisp/stepper.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: stepper.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Implements a Common Lisp stepper. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2012-08-03 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2012 - 2022 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER") ;;;---------------------------------------------------------------------- ;;; ;;; Special operators ;;; (cl:defmacro define-special-operator ((name &rest lambda-list) prefix &body body) `(cl:defmacro ,name ,(append prefix lambda-list) ,@body)) (deftype function (&rest args) (cl:if args `(cl:function ,@args) 'cl:function)) (define-special-operator (function name) (&whole form &environment env) (cl:if (and (consp name) (eq 'lambda (first name))) (step-simple-form (step-expression name env) form) (step-simple-form `(cl:function ,name) form))) (define-special-operator (quote literal) (&whole form) (step-simple-form `(cl:quote ,literal) form)) (define-special-operator (if test then &optional (else nil)) (&whole form &environment env) (simple-step `(cl:if ,(step-expression test env) ,(step-expression then env) ,(step-expression else env)) form)) (define-special-operator (block name &body body) (&whole form &environment env) (simple-step `(cl:block ,name ,@(step-body :progn body env)) form)) (define-special-operator (return-from name &optional result) (&whole form &environment env) (simple-step `(cl:return-from ,name ,(step-expression result env)) form)) (define-special-operator (catch object &body body) (&whole form &environment env) (simple-step `(cl:catch ,(step-expression object env) ,@(step-body :progn body env)) form)) (define-special-operator (throw object result) (&whole form &environment env) (simple-step `(cl:throw ,(step-expression object env) ,(step-expression result env)) form)) (define-special-operator (unwind-protect protected &body cleanup) (&whole form &environment env) (simple-step `(cl:unwind-protect ,(step-expression protected env) ,@(step-body :progn cleanup env)) form)) (define-special-operator (tagbody &body body) (&whole form &environment env) (simple-step `(cl:tagbody ,@(mapcan (cl:lambda (form) (cl:if (or (symbolp form) (integerp form)) (list form `(did-tag ',form)) (list (step-expression form env)))) body)) form)) (define-special-operator (go tag) (&whole form) (simple-step `(cl:go ,tag) form)) (cl:eval-when (:compile-toplevel :load-toplevel :execute) (cl:defun generate-processing-stepper-declarations (body form instrumented-form &optional (preserve-toplevelness-p nil)) (multiple-value-bind (ds declarations real-body) (parse-body :locally body) (declare (ignore ds real-body)) (cl:cond ((stepper-declaration-p declarations 'disable) (step-disabled form)) ((stepper-declaration-p declarations 'trace) (cl:if preserve-toplevelness-p instrumented-form ;; TODO: perhaps wrap the body in the LET? `(cl:let ((*step-mode* :trace)) ,(simple-step instrumented-form form)))) (t (cl:if preserve-toplevelness-p instrumented-form (simple-step instrumented-form form))))))) (define-special-operator (flet (&rest bindings) &body body) (&whole form &environment env) (generate-processing-stepper-declarations body form `(cl:flet ,(mapcar (cl:lambda (fun) (destructuring-bind (name lambda-list &body body) fun `(,name ,lambda-list ,@(step-function :ordinary name lambda-list body env)))) bindings) ,@(step-body :locally body env)))) (define-special-operator (labels (&rest bindings) &body body) (&whole form &environment env) (generate-processing-stepper-declarations body form `(cl:labels ,(mapcar (cl:lambda (fun) (destructuring-bind (name lambda-list &body body) fun `(,name ,lambda-list ,@(step-function :ordinary name lambda-list body env)))) bindings) ,@(step-body :locally body env)))) (define-special-operator (setq var val &rest pairs) (&environment env) (cond ((null pairs) (cl:if (eql var (macroexpand var env)) (simple-step `(cl:setq ,var ,(step-expression val env)) `(setq ,var ,val)) (simple-step (macroexpand `(setf ,var ,val) env) `(setq ,var ,val)))) ((oddp (length pairs)) (error "An odd number of arguments given to SETQ in ~S" `(setq ,var ,val ,pairs))) (t `(cl:progn ,(macroexpand `(setq ,var ,val) env) ,@(loop :for (var val) :on pairs :by (function cddr) :collect (macroexpand `(setq ,var ,val) env)))))) (define-special-operator (let (&rest bindings) &body body) (&whole form &environment env) (generate-processing-stepper-declarations body form (multiple-value-bind (ds declarations real-body) (parse-body :locally body) (declare (ignore ds)) `(cl:let ,(step-bindings :parallel bindings form env) ;; NOTE: When we did-bind the variable, they should not be ;; declared ignore so replace those declarations by ;; ignorable. We must also put the all the declarations ;; before the calls to did-bind. ,@(substitute-ignorable declarations) (unless (eq *step-mode* :run) ,@(mapcar (cl:lambda (binding) (cl:let ((var (cl:if (atom binding) binding (first binding)))) `(did-bind ',var ,var))) bindings)) ,@(step-body :progn real-body env))))) (define-special-operator (let* (&rest bindings) &body body) (&whole form &environment env) (generate-processing-stepper-declarations body form `(cl:let* ,(step-bindings :sequential bindings form env) ,@(step-body :locally body env)))) (define-special-operator (multiple-value-call function-form &rest arguments) (&whole form &environment env) (simple-step `(apply ,(step-expression function-form env) (append ,@(mapcar (cl:lambda (argument) `(cl:multiple-value-list ,(step-expression argument env))) arguments))) form)) (define-special-operator (multiple-value-prog1 result-form &body body) (&whole form &environment env) (cl:let ((result (gensym))) (simple-step `(cl:let ((,result (cl:multiple-value-list ,(step-expression result-form env)))) ,@(step-body :progn body env) (values-list ,result)) form))) (define-special-operator (progn &body body) (&environment env) ;; We must preserve toplevelness. `(cl:progn ,@(step-body :progn body env))) (define-special-operator (progv symbols values &body body) (&whole form &environment env) (cl:let ((vsym (gensym)) (vval (gensym))) (simple-step `(cl:let ((,vsym ,(step-expression symbols env)) (,vval ,(step-expression values env))) (cl:progv ,vsym ,vval (mapc (cl:function did-bind) ,vsym ,vval) ,@(step-body :progn body env))) form))) (define-special-operator (locally &body body) (&whole form &environment env) (generate-processing-stepper-declarations body form `(cl:locally ,@(step-body :locally body env)) :preserve-toplevelness)) (define-special-operator (the value-type expression) (&environment env) ;; TODO: Check the semantics of (the (values t) (values 1 2 3)) ;; --> It seems (values t) == (VALUES INTEGER &REST T) ;; TODO: Handle (values &rest) in value-type. (cl:let ((results (gensym)) (temp (gensym))) (simple-step `(cl:let ((,results (cl:multiple-value-list ,(step-expression expression env)))) ,(cl:if (and (listp value-type) (eq 'values (first value-type))) `(cl:let ((,temp ,results)) ,@(mapcar (cl:lambda (value-type) `(check-type (pop ,temp) ,value-type)) (rest value-type))) `(check-type ,(first results) ,value-type)) (cl:the ,value-type (values-list ,results))) `(the ,value-type ,expression)))) (define-special-operator (eval-when (&rest situations) &body body) (&environment env) ;; We must preserve toplevelness. `(cl:eval-when (,@situations) ,@(step-body :progn body env))) (define-special-operator (symbol-macrolet (&rest bindings) &body body) (&whole form &environment env) (generate-processing-stepper-declarations body form `(cl:symbol-macrolet ,bindings ,@(step-body :locally body env)))) (define-special-operator (macrolet (&rest bindings) &body body) (&whole form &environment env) (generate-processing-stepper-declarations body form `(cl:macrolet ,bindings ,@(step-body :locally body env)))) (define-special-operator (load-time-value expression &optional read-only-p) (&whole form &environment env) (simple-step `(cl:load-time-value ,(step-expression expression env) ,read-only-p) form)) ;;;---------------------------------------------------------------------- ;;; ;;; Macros ;;; (cl:defmacro defun (name lambda-list &body body &environment env) `(cl:defun ,name ,lambda-list ,@(step-function :ordinary name lambda-list body env))) (cl:defmacro defgeneric (name lambda-list &rest options &environment env) `(cl:defgeneric ,name ,lambda-list ,@(mapcar (cl:lambda (option) (cl:if (and (consp option) (eq :method (car option))) (cl:let* ((arguments (rest option)) (qualifiers (loop :while (not (listp (first arguments))) :collect (pop arguments)))) (destructuring-bind (lambda-list &body body) arguments `(:method ,@qualifiers ,lambda-list ,@(step-function :specialized name lambda-list body env)))) option)) options))) (cl:defmacro defmethod (name &rest arguments &environment env) (cl:let ((qualifiers (loop :while (not (listp (first arguments))) :collect (pop arguments)))) (destructuring-bind (lambda-list &body body) arguments `(cl:defmethod ,name ,@qualifiers ,lambda-list ,@(step-function :specialized name lambda-list body env))))) (cl:defmacro lambda (&whole form &environment env lambda-list &body body) (declare (ignorable lambda-list body)) `(cl:function ,(step-lambda form :environment env)) ;; `(cl:progn ;; (print '(1) *step-trace-output* ) ;; ,(simple-step `(cl:function ,(step-lambda form :environment env)) ;; form)) ) (cl:defmacro define-condition (&whole form &environment env name parent slots &rest options) (simple-step `(cl:define-condition ,name ,parent ,slots ,@(mapcar (cl:lambda (option) (cl:if (and (consp option) (eq :report (first option)) (consp (second option)) (eq 'lambda (first (second option)))) `(:report ,(step-lambda (second option) :environment env)) option)) options)) form)) ;;;---------------------------------------------------------------------- ;;; ;;; Stepper ;;; (cl:defmacro step (form &optional (mode :step) &environment env) `(cl:catch 'abort-stepping (cl:let ((*step-mode* ,mode) (*step-package* *package*)) ,(step-expression form env)))) ;; ;; Let's forward the class: ;; ;; (defclass function (cl:function) ;; ()) ;; ;; Doesn't work because of missing built-in meta-class. ;; And subclassing a built-in class is not conforming. ;;;; the END ;;;;
13,870
Common Lisp
.lisp
291
38.298969
122
0.580624
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
b380039a6bdf149c8f82601455cc3e1e43f47821bc1267ca2ea6c910f539c9e1
4,964
[ -1 ]
4,965
com.informatimago.common-lisp.lisp.ibcl.asd
informatimago_lisp/common-lisp/lisp/com.informatimago.common-lisp.lisp.ibcl.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.lisp.ibcl.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.lisp.ibcl library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.lisp.ibcl" ;; system attributes: :description "Informatimago Image Based Common Lisp Utility." :long-description " This system provides three packages: COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE keep sources sexps. COM.INFORMATIMAGO.COMMON-LISP.LISP.CL-SAVING-DEFINES def* macro saving sources. COM.INFORMATIMAGO.COMMON-LISP.LISP.IBCL IBCL package. " :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Summer 2012") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.lisp.ibcl/") ((#: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.common-lisp.lisp-sexp") :components ((:file "source" :depends-on ()) (:file "cl-saving-defines" :depends-on ("source")) (:file "ibcl" :depends-on ("source" "cl-saving-defines"))) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.lisp.ibcl.test")))) ;;;; THE END ;;;;
2,993
Common Lisp
.lisp
61
45.590164
113
0.598223
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
cf8018115c07f1b0e26585aa2068cb591ebbd5422294c9f30fc0daf80244089f
4,965
[ -1 ]
4,966
old-stepper.lisp
informatimago_lisp/common-lisp/lisp/old-stepper.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: stepper.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Implements a Common Lisp stepper. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2012-08-03 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2012 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.LISP-SEXP.SOURCE-FORM" "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE") (:nicknames "STEPPER") (:shadow "FUNCTION-LAMBDA-EXPRESSION" "MACRO-FUNCTION" "COMPILER-MACRO-FUNCTION") (:shadow "STEP") (:export "STEP") (:documentation " Implements a Common Lisp stepper. ")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER") #|Random notes. Terminology =========== The term "to trace" here doen't mean CL:TRACE, but executing forms while printing each subexpressions before evaluating them and printing their results once they return (or informing of a non-local exit). The same printing is done while stepping, but interrupted by user interaction to let him decide what to do next (step into, step over, trace or "run"). The terms "to run" here means to evaluate the form (or the remaining of the evaluation of the form) without printing any trace. Whenever breakpoints are implemented however, tracing and running would stop at the next breakpoint encountered. Principle of operation ====================== Since we don't have yet the infrastructure to manage editing units (text source along with sexp source, etc), we'll take a few shortcuts. The main problem is to get at the source sexp for the functions and methods to be stepped and traced. For this, we cannot count on ``function-lambda-expression``, and it would be largely insufficient anyways: we want to implement the CL:STEP API allowing to step into a toplevel or stand-alone form, and we may want to trace or step into the loading of a lisp file too. Eager Option ------------ In the eager option, we instrument all the toplevel forms we read as soon as we read them. - we need to implement a LOAD function. - difficulties with ASDF which tries to compile everything first, so: - we need to implement a COMPILE-FILE function too. - and of course, we may want to provide a REPL (⚠ slime). Lazy Option ----------- In the lazy option, we only instrument the forms and the functions or methods needed to perform he stepping or tracing. This require keeping around the source forms. Note this means definiting reader macros (to keep text source) or macros (as done by IBCL). Macro Option ------------ IBCL only keeps the source of predefined macros (a subset of the CL def* macros), so we may miss user defined macros (define-such-and-such…), unless they expand to CL def* macros. With a macro that would expand to something like: :: (progn (setf (gethash 'some-key *some-hash*) (some-object (lambda () 'some-code))) (defun something () 'some-code)) we would instrument the function ``something``, but not the anonymous function or code possibly returned by the ``some-object`` function. But we can define alternate special operators as macro too. The big advantage of this solution is that it allows to capture closures without effort: :: (shadow '(let defun)) (defmacro let (bindings &body body) `(cl:let ,(generate-stepping-bindings bindings) ,@(generate-stepping-body body))) (defmacro defun (name lambda-list &body body) `(cl:defun ,name ,lambda-list ,@(generate-stepping-function name lambda-list body))) (let ((x 42)) (defun g () x) (defun s (z) (setf x z))) (and assert case ccase check-type cond ctypecase decf declaim defclass defconstant defgeneric define-compiler-macro define-condition define-method-combination define-modify-macro define-setf-expander define-symbol-macro defmacro defmethod defpackage defparameter defsetf defstruct deftype defun defvar destructuring-bind do do* do-all-symbols do-external-symbols do-symbols dolist dotimes ecase etypecase formatter handler-bind handler-case ignore-errors in-package incf lambda loop loop-finish multiple-value-bind multiple-value-list multiple-value-setq nth-value or pop pprint-logical-block print-unreadable-object prog prog* prog1 prog2 psetf psetq push pushnew remf restart-bind restart-case return rotatef setf shiftf step time trace typecase unless untrace when with-accessors with-compilation-unit with-condition-restarts with-hash-table-iterator with-input-from-string with-open-file with-open-stream with-output-to-string with-package-iterator with-simple-restart with-slots with-standard-io-syntax) Note ---------- In ccl, a macro like cl:defmethod expands to implementation specific special operators (ccl:nfunction) or even, to calls to internal functions passing lambda expressions or other code chunks as data. This would prevent their instrumenting by IBCL-like macros. Operation ------------- We should detect closure functions, by searching for undefined free variables, and avoid redefining them. |# ;;;---------------------------------------------------------------------- ;;; ;;; Environment ;;; ;; variable symbol-macro constant ;; function macro special-operator compiler-macro ;; declare ;; block ;; tag (defclass binding () ((name :initarg :name :accessor binding-name :documentation "A name. Usually a symbol or a list (SETF name). Binding names are compared with EQUAL."))) (defclass var-space-binding (binding) ()) (defclass variable-binding (var-space-binding) ((value :initarg :value :accessor variable-value) (specialp :initarg :special :initform nil :reader variable-special-p))) (defclass constant-binding (variable-binding) ()) (defclass symbol-macro-binding (var-space-binding) ((expansion :initarg :expansion :accessor symbol-macro-expansion))) (defclass fun-space-binding (binding) ()) (defclass function-binding (fun-space-binding) ((lambda-expression :initarg :lambda-expression :accessor function-lambda-expression))) (defclass macro-binding (fun-space-binding) ((function :initarg :function :accessor macro-function))) (defclass compiler-macro-binding (fun-space-binding) ((function :initarg :function :accessor compiler-macro-function))) (defclass special-operator (fun-space-binding) ()) (defclass tag-binding (binding) () (:documentation "This binds a go tag (symbol or integer).")) (defclass block-binding (binding) () (:documentation "This binds a symbol to a block.")) (defclass environment () ((next :initform nil :accessor environment-next :initarg :next) (var-space :initform '() :accessor environment-var-space) (fun-space :initform '() :accessor environment-fun-space) (tag-space :initform '() :accessor environment-tag-space) (block-space :initform '() :accessor environment-block-space))) (defgeneric environment-depth (environment) (:method ((env null)) 0) (:method ((env environment)) (1+ (environment-depth (environment-next env))))) (defmethod print-object ((self binding) stream) (print-unreadable-object (self stream :type t :identity t) (format stream "~{~S~^ ~}" (list :name (binding-name self)))) self) (defmethod print-object ((self variable-binding) stream) (print-unreadable-object (self stream :type t :identity t) (format stream "~{~S~^ ~}" (list :name (binding-name self) :value (if (slot-boundp self 'value) (variable-value self) :#<UNBOUND>) :specialp (variable-special-p self)))) self) (defmethod print-object ((self symbol-macro-binding) stream) (print-unreadable-object (self stream :type t :identity t) (format stream "~{~S~^ ~}" (list :name (binding-name self) :expansion (symbol-macro-expansion self)))) self) (defmethod print-object ((self environment) stream) (print-unreadable-object (self stream :type t :identity t) (format stream "~{~S~^ ~}" (list :depth (environment-depth self) :var-space-count (length (environment-var-space self)) :fun-space-count (length (environment-fun-space self)) :tag-space-count (length (environment-tag-space self)) :block-space-count (length (environment-block-space self))))) self) (defparameter *global-environment* (make-instance 'environment)) (define-condition duplicate-binding-error (error) ((space :initarg :space :reader duplicate-binding-space) (old-binding :initarg :old-binding :reader duplicate-binding-old-binding) (new-binding :initarg :new-binding :reader duplicate-binding-new-binding)) (:report (lambda (condition stream) (format stream "Duplicate ~(~A~) binding: old = ~S ; new = ~S" (duplicate-binding-space condition) (duplicate-binding-old-binding condition) (duplicate-binding-new-binding condition))))) (defun %add-binding (new env space old-bindings adder) (let ((old (find (binding-name new) old-bindings :key (function binding-name) :test (function equal)))) (if old (error 'duplicate-binding-error :space space :old-binding old :new-binding new) (funcall adder))) env) (defgeneric add-binding (binding environment) (:documentation " BINDING: An instance of BINDING. ENVIRONMENT: An instance of ENVIRONMENT or NIL (denoting *GLOBAL-ENVIRONMENT*). DO: Adds the BINDING in the corresponding name space of ENVIRONMENT. If there is already a binding with the same name in the same name space, then a DUPLICATE-BINDING-ERROR is signaled. RETURN: The environment denoted by ENVIRONMENT. ") (:method (binding (env null)) (declare (ignorable env)) (add-binding binding *global-environment*)) (:method ((binding var-space-binding) (env environment)) (%add-binding binding env :variable (environment-var-space env) (lambda () (push binding (environment-var-space env))))) (:method ((binding fun-space-binding) (env environment)) (%add-binding binding env :function (environment-fun-space env) (lambda () (push binding (environment-fun-space env))))) (:method ((binding tag-binding) (env environment)) (%add-binding binding env :tag (environment-tag-space env) (lambda () (push binding (environment-tag-space env))))) (:method ((binding block-binding) (env environment)) (%add-binding binding env :block (environment-block-space env) (lambda () (push binding (environment-block-space env)))))) (defgeneric find-binding-1 (space name environment) (:documentation " SPACE: One of: :VAR-SPACE :FUN-SPACE, or :VARIABLE :CONSTANT :SYMBOL-MACRO :FUNCTION :MACRO :COMPILER-MACRO :SPECIAL-OPERATOR. NAME: A binding name. ENVIRONMENT: An instance of ENVIRONMENT or NIL (denoting *GLOBAL-ENVIRONMENT*). DO: Finds in the ENVIRONMENT (not the next ones) a binding with the same NAME in the name space indicated by SPACE. If SPACE is not :VAR-SPACE or :FUN-SPACE then the type of the binding found is checked before returning the binding. RETURN: A binding named NAME in the name space SPACE of the ENVIRONMENT, or NIL if none is found. ") (:method (space name (env null)) (find-binding-1 space name *global-environment*)) (:method (space name (env environment)) (let ((binding (find name (ecase space ((:var-space :variable :constant :symbol-macro) (environment-var-space env)) ((:fun-space :function :macro :compiler-macro :special-operator) (environment-fun-space env)) ((:tag-space :tag) (environment-tag-space env)) ((:block-space :block) (environment-block-space env))) :key (function binding-name) :test (function equal)))) (when binding (case space ((:variable) (check-type binding variable-binding)) ((:constant) (check-type binding constant-binding)) ((:symbol-macro) (check-type binding symbol-macro-binding)) ((:function) (check-type binding function-binding)) ((:macro) (check-type binding macro-binding)) ((:compiler-macro) (check-type binding compiler-macro-binding)) ((:special-operator) (check-type binding special-operator-binding)) ((:block) (check-type binding block-binding)) ((:tag) (check-type binding tag-binding))) binding)))) (defgeneric find-binding (space name environment) (:documentation " SPACE: One of: :VAR-SPACE :FUN-SPACE :TAG-SPACE :BLOCK-SPACE or one of :VARIABLE :CONSTANT :SYMBOL-MACRO :FUNCTION :MACRO :COMPILER-MACRO :SPECIAL-OPERATOR :TAG :BLOCK. NAME: A binding name. ENVIRONMENT: An instance of ENVIRONMENT or NIL (denoting *GLOBAL-ENVIRONMENT*). DO: Finds in the ENVIRONMENT or the next ones, a binding with the same NAME in the name space indicated by SPACE. If SPACE is not :VAR-SPACE or :FUN-SPACE then the type of the binding found is checked before returning the binding. RETURN: A binding named NAME in the name space SPACE, or NIL if none is found. ") (:method (space name (env null)) (find-binding-1 space name *global-environment*)) (:method (space name (env environment)) (or (find-binding-1 space name env) (find-binding space name (environment-next env))))) #|| (add-binding (make-instance 'variable-binding :name 'x :value 42) nil) (add-binding (make-instance 'variable-binding :name 'z :value #c(15 3)) nil) (add-binding (make-instance 'macro-binding :name 'm :function (lambda (whole environment) (declare (ignorable environment)) (block m (destructuring-bind (macro-name &rest args) whole (declare (ignorable macro-name)) `(progn ,@args))))) nil) (let ((env (make-instance 'environment))) (add-binding (make-instance 'function-binding :name 'm :lambda-expression '(lambda (x) (block 'm (list 'm x 'm)))) env) (list *global-environment* (find-binding :fun-space 'm nil) (find-binding :fun-space 'm env) (find-binding-1 :var-space 'x nil) (find-binding-1 :var-space 'x env) (find-binding :var-space 'x env))) (#<environment :depth 1 :var-space-count 2 :fun-space-count 1 #x302001DF04BD> #<macro-binding :name m #x302001E2E0BD> #<function-binding :name m #x30200204F0CD> #1=#<variable-binding :name x :value 42 :specialp nil #x302001E2F8CD> nil #1#) ||# (defun extend-environment (environment &key var-space fun-space tag-space block-space) (let ((env (make-instance 'environment :next environment))) (dolist (var var-space) (add-binding var env)) (dolist (fun fun-space) (add-binding fun env)) (dolist (tag tag-space) (add-binding tag env)) (dolist (block block-space) (add-binding block env)) env)) (defgeneric uncompile-global (object) (:method ((self variable-binding)) (if (variable-special-p self) (if (slot-boundp self 'value) `(defparameter ,(binding-name self) ,(list 'quote (variable-value self))) `(defvar ,(binding-name self))) `(deflexical ,(binding-name self) ,@(if (slot-boundp self 'value) (list (list 'quote (variable-value self))))))) (:method ((self constant-binding)) `(defconstant ,(binding-name self) ,(list 'quote (selfiable-value self)))) (:method ((self symbol-macro-binding)) `(define-symbol-macro ,(binding-name self) ,(symbol-macro-expansion self))) (:method ((self function-binding)) (destructuring-bind (lambada lambda-list (blog name &body body)) (function-lambda-expression self) (declare (ignore lambada blog name)) `(defun ,(binding-name self) ,lambda-list ,@body))) (:method ((self macro-binding)) (destructuring-bind (lambada lambda-list (blog name &body body)) (function-lambda-expression self) (declare (ignore lambada blog name)) `(defun ,(binding-name self) ,lambda-list ,@body))) ) ;; (uncompile-global (find-binding :var-space 'x nil)) ;; (deflexical x '42) (defgeneric uncompile-environment (enviroment) (:method ((env null)) () (uncompile-environment *global-environment*)) (:method ((env environment)) () )) ;; (find-binding :fun-space 'm ;; (extend-environment ;; (extend-environment ;; (extend-environment ;; nil ;; :fun-space (list ;; (make-instance 'function-binding ;; :name 'f ;; :lambda-expression '(lambda () (block f :outer))) ;; (make-instance 'function-binding ;; :name 'g ;; :lambda-expression '(lambda () (block g :outer))) ;; (make-instance 'function-binding ;; :name 'm ;; :lambda-expression '(lambda () (block m :outer))))) ;; :fun-space (list ;; (make-instance 'macro-binding ;; :name 'm ;; :function (cl:macro-function (defmacro m (&args) ;; `(progn ,args)))))) ;; :fun-space (list ;; (make-instance 'function-binding ;; :name 'g ;; :lambda-expression '(lambda () (block g :inner)))))) (defun macro-function-p (name env) (let* ((env (or env *global-environment*)) (binding (find-binding :fun-space name env))) (cond ((null binding) (cl:macro-function name)) ((typep binding 'macro-binding) binding)))) ;;;---------------------------------------------------------------------- ;;; ;;; Stepping & Tracing ;;; (defvar *eval-step-mode* :trace "May be :run, :trace or :step. :run don't print anything, just evaluate the forms. :trace just prints the forms and their results as they are evaluted. :step prints the form, then ask the user what to do (step over, step into, trace, run). When break-points are implemented, :run and :trace will run until a break-point is reached. ") (defvar *eval-step-level* 0 "The level.") (defun eval-will-step (form) (format *trace-output* "~&~V<~>Will evaluate ~S~%" *eval-step-level* form)) (defun eval-print-results (results) (when results (let ((start "-->")) (dolist (result results) (format *trace-output* "~V<~>~A ~S~%" *eval-step-level* start result) (setf start " "))))) (defun eval-did-step (form results) (format *trace-output* "~&~V<~>Evaluation of ~S returned ~:[no result~;~R result~:P~]~%" *eval-step-level* form results (length results)) (eval-print-results results)) (defun eval-choice (&optional thunk) (when thunk (funcall thunk)) (format *query-io* "~V<~>Step Into (s, si, RET), Step over (so), Trace (t), Run (r), Abort (a, q)? " *eval-step-level*) (let ((answer (string-trim " " (read-line *query-io*)))) (cond ((member answer '("" "s" "si") :test (function string-equal)) :step-into) ((string-equal answer "so") :step-over) ((string-equal answer "t") :trace) ((string-equal answer "r") :run) ((member answer '("a" "q") :test (function string-equal)) :abort) (t (eval-choice form))))) (defun call-eval-atom (thunk display-form) (flet ((do-step () (eval-will-step display-form) (let ((results (multiple-value-list (funcall thunk)))) (eval-did-step display-form results) (values-list results)))) (case *eval-step-mode* (:run (funcall thunk)) (:trace (do-step)) (:step (ecase (eval-choice (lambda () (eval-will-step display-form))) (:abort (throw 'abort-stepping nil)) (:run (setf *eval-step-mode* :run) (funcall thunk)) (:trace (setf *eval-step-mode* :trace) (do-step)) (:step-into (do-step)) (:step-over (do-step))))))) (defun eval-atom (atom &optional (display-atom atom)) `(call-eval-atom (lambda () ,atom) ',display-atom)) (defun call-eval-step (thunk display-form) (flet ((do-step () (eval-will-step display-form) (let ((results (let ((*eval-step-level* (1+ *eval-step-level*))) (multiple-value-list (funcall thunk))))) (eval-did-step display-form results) (values-list results)))) (case *eval-step-mode* (:run (funcall thunk)) (:trace (do-step)) (:step (ecase (eval-choice (lambda () (eval-will-step display-form))) (:abort (throw 'abort-stepping nil)) (:run (setf *eval-step-mode* :run) (funcall thunk)) (:trace (setf *eval-step-mode* :trace) (do-step)) (:step-into (do-step)) (:step-over (let ((*eval-step-mode* :run)) (do-step)))))))) (defun eval-step (form &optional (display-form form)) (if (atom form) `(call-eval-atom (lambda () ,form) ',display-form) `(call-eval-step (lambda () ,form) ',display-form))) (defun call-eval-step-function (name pnames pvals thunk) (labels ((report-enter (out) (format out "~&~V<~>Entering ~:[anonymous ~;~]function ~:*~:[~;~:*~S~]~%" *eval-step-level* name) (loop :for pname :in pnames :for pval :in pvals :do (format out "~V<~> ~16A = ~S~%" *eval-step-level* pname pval))) (report-exit (non-local-exit results) (format *trace-output* "~&~V<~>Exiting ~:[anonymous ~;~]function ~:*~:[~;~S ~]~ ~:[returned ~:[no result~;~R result~:P~]~;by non-local exit.~]~%" *eval-step-level* name non-local-exit results (length results)) (eval-print-results results)) (do-step () (let ((non-local-exit t) (results '())) (unwind-protect (progn (setf results (let ((*eval-step-level* (1+ *eval-step-level*))) (multiple-value-list (funcall thunk))) non-local-exit nil)) (report-exit non-local-exit results)) (values-list results)))) (case *eval-step-mode* (:run (funcall thunk)) (:trace (report-enter *trace-output*) (do-step)) (:step (ecase (eval-choice (lambda () (report-enter *query-io*))) (:abort (throw 'abort-stepping nil)) (:run (setf *eval-step-mode* :run) (funcall thunk)) (:trace (setf *eval-step-mode* :trace) (do-step)) (:step-into (do-step)) (:step-over (let ((*eval-step-mode* :run)) (do-step)))))))) (defun eval-step-lambda (env lambda-form &key (kind :ordinary) name) " ENV: An environment. LAMBDA-FORM: A lambda form. KIND: A lambda-list kind (:ordinary for functions, :generic for generic functions, :specialized for methods, :destructuring for macros, etc). NAME: The name of the defined function or macro. RETURN: A stepping lambda-form from the LAMBDA-FORM. " (destructuring-bind (lambda lambda-list &body body) lambda-form (let* ((parameters (mapcar (function parameter-name) (lambda-list-parameters (parse-lambda-list lambda-list kind)))) (env (extend-environment env :var-space (mapcar (lambda (pname) (make-instance 'variable-binding :name pname)) parameters))) (non-local-exit (gensym))) `(lambda ,lambda-list (call-eval-step-function ',name ',parameters (list ,@parameters) (lambda () ,@(eval-step-body env body))))))) (defun eval-step-body (env body) (mapcar (lambda (form) (eval-expression env form)) body)) ;;;---------------------------------------------------------------------- ;;; ;;; Special operators ;;; (defparameter *special-operators* (make-hash-table)) (defmacro define-special-operator ((name &rest destructuring-lambda-list) (env) &body body) (let ((vform (gensym))) `(setf (gethash ',name *special-operators*) (lambda (,env ,vform) (declare (ignorable ,env)) (block ,name (destructuring-bind (,name ,@destructuring-lambda-list) ,vform (declare (ignorable ,name)) ,@body)))))) (defun call-special-operator (op env form) (let ((fun (gethash op *special-operators*))) (unless fun (error "No such special operator ~S for form ~S" op form)) (funcall fun env form))) (define-special-operator (function funame) (env) (eval-step `(cl:function ,funame) `(function ,funame))) (define-special-operator (quote literal) (env) (eval-step `(cl:quote ,literal) `(quote ,literal))) (define-special-operator (if test then &optional (else nil elsep)) (env) (eval-step `(cl:if ,(eval-expression env test) ,(eval-expression env then) ,(eval-expression env else)) `(if ,test ,then ,@(when elsep (list else))))) (define-special-operator (block name &body body) (env) (let ((env (extend-environment env :block-space (list (make-instance 'block-binding :name name))))) (eval-step `(cl:block ,name ,@(eval-step-body env body)) `(block ,name ,@body)))) (define-special-operator (return-from name &optional result) (env) (if (find-binding :block name env) (eval-step `(cl:return-from ,name ,(eval-expression env result)) `(return-from ,name ,result)) (error "~S but there's no block ~S in scope." `(return-from ,name ,result) name))) (define-special-operator (catch object &body body) (env) (eval-step `(cl:catch ,(eval-expression env object) ,@(eval-step-body env body)) `(catch ,object ,@body))) (define-special-operator (throw object result) (env) (eval-step `(cl:throw ,(eval-expression env object) ,(eval-expression env result)) `(throw ,object ,result))) (define-special-operator (unwind-protect protected &body cleanup) (env) (eval-step `(cl:unwind-protect ,(eval-expression env protected) ,@(eval-step-body env cleanup)) `(unwind-protect ,protected ,@cleanup))) (define-special-operator (tagbody &body body) (env) (let* ((tags (remove-if-not (lambda (item) (or (symbolp item) (integerp item))) body)) (env (extend-environment env :tag-space (mapcar (lambda (tag) (make-instance 'tag-binding :name tag)) tags)))) (eval-step `(cl:tagbody ,@(mapcan (lambda (form) (if (or (symbolp form) (integerp form)) `(,form (trace-step "Passed tag ~S" ',form)) (list (eval-expression env form)))) body)) `(tagbody ,@body)))) (define-special-operator (go tag) (env) (if (find-binding :tag tag env) (eval-step `(cl:go ,tag) `(go ,tag)) (error "~S but there's no tag ~S in scope." `(go ,tag) tag))) (define-special-operator (flet (&rest bindings) &body body) (env) ;; TODO: (let* ((funs (mapcar (lambda (fun) (make-instance 'function-binding :name (first fun) :lambda-expression `(lambda (second fun) ;; get docstring and declarations from body here. (block ,(first fun) ;; body: ,@(rest (rest fun)))))) bindings)) (env (extend-environment env :fun-space funs))) (eval-step `(cl:flet ,bindings ,@(eval-step-body env body)) `(flet ,bindings ,@body)))) (define-special-operator (labels (&rest bindings) &body body) (env) ;; TODO: (eval-step `(cl:labels ,bindings ,@(eval-step-body env body)) `(labels ,bindings ,@body))) (define-special-operator (setq var val &rest pairs) (env) (cond ((null pairs) (let ((sm (find-binding :var-space var env))) (if (typep sm 'symbol-macro-binding) (call-special-operator 'setf env `(setf ,(symbol-macro-expansion sm) ,val)) (eval-step `(cl:setq ,var ,(eval-expression env val)) `(setq ,var ,val))))) ((oddp (length pairs)) (error "An odd number of arguments given to SETQ in ~S" `(setq ,var ,val ,pairs))) (t `(cl:progn ,(call-special-operator 'setq env `(setq ,var ,val)) ,@(loop :for (var val) :on pairs :by (function cddr) :collect (call-special-operator 'setq env `(setq ,var ,val))))))) (define-special-operator (let (&rest bindings) &body body) (env) (if (null bindings) (call-special-operator 'locally env `(locally ,@body)) (let* ((vars (mapcar (lambda (binding) (make-instance 'variable-binding :name (cond ((symbolp binding) binding) ((atom binding) (error "Invalid atom ~S in binding list of ~S" binding `(let ,bindings ,@body))) ((/= 2 (length bindings)) (error "Invalid binding ~S in binding list of ~S" binding `(let ,bindings ,@body))) (t (first binding))))) bindings)) (new-env (extend-environment env :var-space vars))) (eval-step `(cl:let ,(mapcar (lambda (binding) (if (symbolp binding) binding `(,(first binding) ,(eval-step (second binding))))) bindings) ,@(eval-step-body new-env body)) `(cl:let ,bindings ,@body))))) (define-special-operator (let* (&rest bindings) &body body) (env) (if (null bindings) (call-special-operator 'locally env `(locally ,@body)) (call-special-operator 'let env `(let (,(first bindings)) (let* (,(rest bindings)) ,@body))))) (define-special-operator (multiple-value-call function-form &rest arguments) (env) (eval-step `(apply ,(eval-expression env function-form) (append ,@(mapcar (lambda (argument) `(multiple-value-list ,(eval-expression env argument))) arguments))) `(multiple-value-call ,function-form ,@arguments))) (define-special-operator (multiple-value-prog1 result-form &body body) (env) (let ((result (gensym))) (eval-step `(let ((,result (multiple-value-list ,(eval-expression env result-form)))) ,@(eval-step-body body) (values-list ,result)) `(multiple-value-prog1 ,result-form ,@body)))) (define-special-operator (progn &body body) (env) (eval-step `(cl:progn ,@(eval-step-body env body)) `(progn ,@body))) (define-special-operator (progv symbols values &body body) (env) ) (define-special-operator (locally &body body) (env) (eval-step `(cl:locally ;; TODO: deal with declarations ,@(eval-step-body env body)) `(locally ,@body))) (define-special-operator (the value-type expression) (env) ;; TODO: Check the semantics of (the (values t) (values 1 2 3)) ;; --> It seems (values t) == (VALUES INTEGER &REST T) ;; TODO: Handle (values &rest) in value-type. (let ((results (gensym)) (temp (gensym))) (eval-step `(cl:let ((results (cl:multiple-value-list ,(eval-expression env expression)))) ,(if (and (listp value-type) (eq 'values (first value-type))) `(let ((,temp ,results)) ,@(mapcar (lambda (value-type) `(check-type (pop ,temp) ,value-type)) (rest value-type))) `(check-type ,(first result) ,value-type)) (cl:the ,value-type (values-list ,results))) `(the ,value-type ,expression)))) (define-special-operator (eval-when (&rest situations) &body body) (env) (eval-step `(cl:eval-when (,@situations) ,@(eval-step-body env body)) `(eval-when (,@situations) ,@body))) (define-special-operator (symbol-macrolet (&rest bindings) &body body) (env)) (define-special-operator (macrolet (&rest bindings) &body body) (env)) (define-special-operator (load-time-value expression &optional read-only-p) (env)) (define-special-operator (symbol-reference symbol) (env) (declare (ignore env)) ; for now (let ((binding (find-binding :var-space symbol env))) (etypecase binding ((or null variable-binding) (eval-atom symbol)) (symbol-macro-binding (eval-atom symbol) ; for now. ;; TODO: ;; (eval-expression env expansion) )))) (define-special-operator (self-evaluating object) (env) (declare (ignore env)) (eval-atom object)) (define-special-operator (macro-call (macro-name &rest arguments)) (env) ;; find macro function ;; macroexpand ) (define-special-operator (function-call (&whole form function-name &rest arguments)) (env) (if (consp function-name) (if (eq 'lambda (first function-name)) (eval-step `(,(eval-step-lambda env function-name) ,@(mapcar (lambda (argument) (eval-expression env argument)) arguments)) form) (error "Invalid object used as function name ~S in function call ~S" function-name form)) (let ((binding (find-binding :fun-space function-name env))) (etypecase binding ((or null function-binding) (eval-step `(,function-name ,@(mapcar (lambda (argument) (eval-expression env argument)) arguments)) form)))))) #+ccl (define-special-operator (ccl:compiler-let (&rest bindings) &body body) (env) (call-special-operator 'let env `(let ,bindings ,@body))) (defun eval-expression (env form) (cond ((symbolp form) (call-special-operator 'symbol-reference env `(symbol-reference ,form))) ;; The other atoms are unchanged: ((atom form) (call-special-operator 'self-evaluating env `(self-evaluating ,form))) ;; Now we have a list. (t (case (first form) ;; First we check the special operators: ((block catch eval-when flet function go if labels let let* load-time-value locally macrolet multiple-value-call multiple-value-prog1 progn progv quote return-from setq symbol-macrolet tagbody the throw unwind-protect) (call-special-operator (first form) env form)) (otherwise (if (macro-function-p (first form) env) (call-special-operator 'macro-call env `(macro-call ,form)) (call-special-operator 'function-call env `(function-call ,form)))))))) ;;;---------------------------------------------------------------------- ;;; ;;; Stepper ;;; (defmacro step (form) `(catch 'abort-stepping ,(eval-expression nil `(progn ,form)))) ;; (setf *print-circle* nil) ;; (eval-step-lambda nil '(lambda (a b &optional o &rest r &key k1 k2 ((kk3 k3) nil k3p) &aux a1 a2))) ;; (lambda (a b &optional o &rest r &key k1 k2 ((kk3 k3) nil k3p) &aux a1 a2) ;; (call-eval-step-function 'nil '#1=(a b o r k1 k2 k3 a1 a2) (list . #1#) (lambda nil))) ;; ;; (pprint (eval-step-lambda ;; nil ;; '(lambda (a b &optional o &rest r &key k1 k2 ((kk3 k3) nil k3p) &aux a1 a2) ;; (let ((c 1) (b 2)) (if (< a b) (+ (* b 3) (truncate 10 3)) (print 'hello)))))) ;; ;; ;; (lambda (a b &optional o &rest r &key k1 k2 ((kk3 k3) nil k3p) &aux a1 a2) ;; (call-eval-step-function ;; 'nil ;; '(a b o r k1 k2 k3 a1 a2) ;; (list a b o r k1 k2 k3 a1 a2) ;; (lambda nil ;; (call-eval-step ;; (lambda nil ;; (let ((c (call-eval-atom (lambda nil 1) '1)) (b (call-eval-atom (lambda nil 2) '2))) ;; (call-eval-step ;; (lambda nil ;; (if (call-eval-step ;; (lambda nil ;; (< (call-eval-atom (lambda nil a) 'a) (call-eval-atom (lambda nil b) 'b))) ;; '(< a b)) ;; (call-eval-step ;; (lambda nil ;; (+ (call-eval-step ;; (lambda nil ;; (* (call-eval-atom (lambda nil b) 'b) ;; (call-eval-atom (lambda nil 3) '3))) ;; '(* b 3)) ;; (call-eval-step ;; (lambda nil ;; (truncate (call-eval-atom (lambda nil 10) '10) ;; (call-eval-atom (lambda nil 3) '3))) ;; '(truncate 10 3)))) ;; '(+ (* b 3) (truncate 10 3))) ;; (call-eval-step ;; (lambda nil (print (call-eval-step (lambda nil 'hello) ''hello))) ;; '(print 'hello)))) ;; '(if (< a b) (+ (* b 3) (truncate 10 3)) (print 'hello))))) ;; '(let ((c 1) (b 2)) (if (< a b) (+ (* b 3) (truncate 10 3)) (print 'hello))))))) ;;;; THE END ;;;;
41,241
Common Lisp
.lisp
885
38.183051
107
0.57652
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
2df72b3cb145a3046b63cd83acd5beb704215966c53ab92a9682e7df1417f94f
4,966
[ -1 ]
4,967
source-test.lisp
informatimago_lisp/common-lisp/lisp/source-test.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: source-test.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Test source.lisp. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-02-25 <PJB> Extracted from source.lisp. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE.TEST" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.SIMPLE-TEST" "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE") (:import-from "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE" "NORMALIZE-OBJECT-AND-SOURCE-TYPE") (:export "TEST/ALL")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE.TEST") (defun test/normalize-object-and-source-type () (assert-true (equal (list (multiple-value-list (normalize-object-and-source-type 'f 'function)) (multiple-value-list (normalize-object-and-source-type '(setf f) 'function)) (multiple-value-list (normalize-object-and-source-type 'f 'setf-function)) (ignore-errors (multiple-value-list (normalize-object-and-source-type '(setf f) 'setf-function)))) '((f :function) (f :setf-function) (f :setf-function) nil))) (assert-true (equal (list (multiple-value-list (normalize-object-and-source-type '(m () (t t)) :method)) (multiple-value-list (normalize-object-and-source-type '((setf m) () (t t)) ':method)) (multiple-value-list (normalize-object-and-source-type '(m () (t t)) 'setf-method)) (ignore-errors (multiple-value-list (normalize-object-and-source-type '((setf m) () (t t)) :setf-method)))) '((m :method (() (t t))) (m :setf-method (() (t t))) (m :setf-method (() (t t))) nil)))) (define-test test/all () (test/normalize-object-and-source-type)) ;;;; THE END ;;;;
3,477
Common Lisp
.lisp
75
36.493333
96
0.530468
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
0c1e326fcb7df6f1a521edf6ef149db0c33bd7d7e382894d444af3ab61f47b38
4,967
[ -1 ]
4,968
ibcl.lisp
informatimago_lisp/common-lisp/lisp/ibcl.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: ibcl.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; See :documentation of package below. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2012-08-07 <PJB> Restructured. ;;;; 2006-07-01 <PJB> Added deftype, defclass. ;;;; 2006-05-04 <PJB> Added this header. Augmented. ;;;;BUGS ;;;; Missing some def* macros, like define-symbol-macro, ;;;; defconditions, defmethod, defgeneric, etc. ;;;; Missing some functions, like make-package, rename-package, etc. ;;;; See also MOP functions. ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2006 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (cl:defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.IMAGE-BASED-COMMON-LISP" (:nicknames "COM.INFORMATIMAGO.COMMON-LISP.LISP.IBCL" "IMAGE-BASED-COMMON-LISP" "IBCL") (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE") (:shadowing-import-from "COM.INFORMATIMAGO.COMMON-LISP.LISP.CL-SAVING-DEFINES" ;; Not defpackage we provide our own wrapping. "DEFINE-COMPILER-MACRO" "DEFINE-MODIFY-MACRO" "DEFINE-SETF-EXPANDER" "DEFMACRO" "DEFSETF" "DEFVAR" "DEFPARAMETER" "DEFCONSTANT" "DEFINE-SYMBOL-MACRO" "DEFSTRUCT" "DEFCLASS" "DEFTYPE" "DEFINE-CONDITION" "DEFINE-METHOD-COMBINATION" "DEFGENERIC" "DEFMETHOD" "DEFUN") (:shadow "FIND-SYMBOL" "FIND-PACKAGE" "IMPORT" "SHADOW" "SHADOWING-IMPORT" "DELETE-PACKAGE" "MAKE-PACKAGE" "WITH-PACKAGE-ITERATOR" "UNEXPORT" "IN-PACKAGE" "UNUSE-PACKAGE" "USE-PACKAGE" "DEFPACKAGE" "DO-SYMBOLS" "DO-EXTERNAL-SYMBOLS" "FIND-SYMBOL") (:export . #.(let ((symbols '())) (do-external-symbols (sym "COMMON-LISP") (push (string sym) symbols)) (do-external-symbols (sym "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE") (push (string sym) symbols)) symbols)) (:documentation " The package IBCL exports the same symbols as COMMON-LISP, but for some of the functions of macros modified to track of the source of the definitions and to be able to edit them from the image, and to save them in files. The package IBCL-USER is a virgin package using IBCL instead of CL. One can work at the REPL, define variables with DEFCONSTANT, DEFVAR, DEFPARAMETER, macros with DEFMACRO, and functions with DEFUN, edit macro and function definitions with ED. The function LIST-PACKAGES-WITH-SOURCES returns a list of packages where some of these variables or functions are defined. The function SOURCE returns the source form of the given symbol or package. The function SAVE-SOURCES saves the definitions in a package, or all the definitions to a file or stream. The IBCL package provides some shadowed CL functions to substittute sneakily IBCL for CL. When defpackage is ibcl:defpackage, as long as CL package operators are not qualified, (cl:defpackage …) vs. (defpackage …), the IBCL package will be used instead of the CL package. This should allow loading libraries using IBCL instead of CL. (in-package :ibcl-user) (asdf-load-source :some-system) (source 'some-system:some-function :function) --> (defun some-system:some-function …) Copyright Pascal J. Bourguignon 2006 - 2012 This package is provided under the Afero General Public License 3. See the source file for details. ")) (cl:defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.IMAGE-BASED-COMMON-LISP-USER" (:nicknames "COM.INFORMATIMAGO.COMMON-LISP.LISP.IBCL-USER" "IMAGE-BASED-COMMON-LISP-USER" "IBCL-USER") (:use "COM.INFORMATIMAGO.COMMON-LISP.LISP.IMAGE-BASED-COMMON-LISP") (:documentation " The package IBCL-USER is a virgin package using IBCL instead of CL. Copyright Pascal J. Bourguignon 2006 - 2012 This package is provided under the Afero General Public License 3. See the source file for details. ")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.IMAGE-BASED-COMMON-LISP") (define-condition simple-package-error (package-error simple-error) ()) (defun normalize-package-designator (package) (let ((pack (cl:find-package package))) (if pack (package-name pack) (error 'simple-package-error :package package :format-control "No such package ~S" :format-arguments (list package))))) (defun substitute-package-designator (new old sequence) (substitute (normalize-package-designator new) (normalize-package-designator old) sequence :key (function normalize-package-designator) :test (function equal))) (defun substitute-packages (new-old-a-list sequence) (loop :for (new . old) :in new-old-a-list :do (setf sequence (substitute-package-designator new old sequence)) :finally (return sequence))) (defun substitute-one-package (new-old-a-list package) (let ((package (normalize-package-designator package))) (or (car (rassoc package new-old-a-list :key (function normalize-package-designator) :test (function equal))) package))) (defvar *package-map* '(("IBCL-USER" . "COMMON-LISP-USER") ("IBCL" . "COMMON-LISP")) "An A-list mapping new packages for old packages.") (defun ensure-list (object) (if (listp object) object (list object))) (defun find-symbol (string &optional (package *package*)) (cl:find-symbol string (substitute-one-package *package-map* package))) (defun find-package (designator) (let ((found (cl:find-package designator))) (when found (cl:find-package (substitute-one-package *package-map* found))))) (defun import (symbols &optional (package *package*)) (cl:import symbols (substitute-one-package *package-map* package))) (defun shadow (symbol-names &optional (package *package*)) (cl:shadow symbol-names (substitute-one-package *package-map* package))) (defun shadowing-import (symbols &optional (package *package*)) (cl:shadowing-import symbols (substitute-one-package *package-map* package))) (defun delete-package (package-designator) (prog1 (cl:delete-package package-designator) (remhash (find-package package-designator) com.informatimago.common-lisp.lisp.source::*sources*))) (defun make-package (package &key nicknames uses) (cl:make-package package :nicknames nicknames :use (substitute-packages *package-map* uses))) (defmacro with-package-iterator ((name package-list-form &rest symbol-types) &body body) `(cl:with-package-iterator (,name (substitute-packages *package-map* (ensure-list ,package-list-form)) ,@symbol-types) ,@body)) (defun unexport (symbols &optional (package *package*)) (cl:unexport symbols (substitute-one-package *package-map* package))) (defmacro in-package (designator) `(cl:in-package ,(substitute-one-package *package-map* designator))) (defun unuse-package (packages-to-unuse &optional (designator *package*)) (cl:unuse-package (substitute-packages *package-map* (ensure-list packages-to-unuse)) (substitute-one-package *package-map* designator))) (defun use-package (packages-to-use &optional (designator *package*)) (cl:use-package (substitute-packages *package-map* (ensure-list packages-to-use)) (substitute-one-package *package-map* designator))) (defmacro defpackage (name &rest options) " DO: Same as CL:DEFPACKAGE, but substitute the packages specified by *PACKAGE-MAP*, and record the defpackage form in the sources. RETURN: The package name. " `(com.informatimago.common-lisp.lisp.cl-saving-defines:defpackage ,name ,@(mapcar (lambda (option) (if (consp option) (case (first option) ((:use) (cons :use (substitute-packages *package-map* (rest option)))) ((:shadowing-import-from :import-from) (list* (first option) (substitute-one-package *package-map* (second option)) (cddr option))) (otherwise option)) option)) options))) (cl:defmacro do-symbols ((var &optional (package *package*) result-form) &body body) `(cl:do-symbols (,var (substitute-one-package *package-map* ,package) ,result-form) ,@body)) (defmacro do-external-symbols ((var &optional (package *package*) result-form) &body body) `(cl:do-external-symbols (,var (substitute-one-package *package-map* ,package) ,result-form) ,@body)) ;;;; THE END ;;;;
10,285
Common Lisp
.lisp
211
41.563981
98
0.6418
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
751bf9d7715187960612cc44621f209b62c1f713d42902d7ae14b33d011607b9
4,968
[ -1 ]
4,969
stepper-functions.lisp
informatimago_lisp/common-lisp/lisp/stepper-functions.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: stepper-functions.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; An internal package of the Common Lisp stepper. ;;;; This package exports the stepper generator functions ;;;; and defines the stepper interactive functions. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2021-11-05 <PJB> Added stepping macroexpansions. ;;;; 2014-10-08 <PJB> Corrected step-{break,unbreak}-{entry,exit}. ;;;; 2012-08-09 <PJB> Extracted from stepper.lisp ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2012 - 2022 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) ;; Only the step-disabled function is read in the cl-stepper package; ;; the rest of the file is read in the .stepper.internal package. (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER") ;; When instrumenting is disabled with a declaration, all the forms and ;; subforms in the scope must use the CL operators instead of the stepper ;; macros. Since subforms and their expansions may use those stepper ;; macros, we would need a code walker to process them. A simpler and ;; more portable solution is to use macrolet and to shadow all those ;; stepper macros. (cl:defun com.informatimago.common-lisp.lisp.stepper.internal:step-disabled (form) " RETURN: A form where FORM is evaluated in an environment where all the stepper special operator macros expand to CL special operators. " `(cl:macrolet ((function (name) (cl:if (and (consp name) (eq 'lambda (first name))) `(cl:function (cl:lambda ,@(rest (first name)))) `(cl:function ,name))) (quote (literal) `(cl:quote ,literal)) (if (&whole form test then &optional else) (declare (ignorable test then else)) `(cl:if ,@(rest form))) (block (&whole form name &body body) (declare (ignorable name body)) `(cl:block ,@(rest form))) (return-from (&whole form name &optional result) (declare (ignorable name result)) `(cl:return-from ,@(rest form))) (catch (&whole form object &body body) (declare (ignorable object body)) `(cl:catch ,@(rest form))) (throw (&whole form object result) (declare (ignorable object result)) `(cl:throw ,@(rest form))) (unwind-protect (&whole form protected &body cleanup) (declare (ignorable protected cleanup)) `(cl:unwind-protect ,@(rest form))) (tagbody (&whole form &body body) (declare (ignorable body)) `(cl:tagbody ,@(rest form))) (go (tag) `(cl:go ,tag)) (flet (&whole form (&rest bindings) &body body) (declare (ignorable bindings body)) `(cl:flet ,@(rest form))) (labels (&whole form (&rest bindings) &body body) (declare (ignorable bindings body)) `(cl:labels ,@(rest form))) (macrolet (&whole form (&rest bindings) &body body) (declare (ignorable bindings body)) `(cl:macrolet ,@(rest form))) (symbol-macrolet (&whole form (&rest bindings) &body body) (declare (ignorable bindings body)) `(cl:symbol-macrolet ,@(rest form))) (let (&whole form (&rest bindings) &body body) (declare (ignorable bindings body)) `(cl:let ,@(rest form))) (let* (&whole form (&rest bindings) &body body) (declare (ignorable bindings body)) `(cl:let* ,@(rest form))) (setq (&whole form var val &rest pairs) (declare (ignorable var val pairs)) `(cl:setq ,@(rest form))) (multiple-value-call (&whole form function-form &rest arguments) (declare (ignore function-form arguments)) `(cl:multiple-value-call ,@(rest form))) (multiple-value-prog1 (&whole form result-form &body body) (declare (ignore result-form body)) `(cl:multiple-value-prog1 ,@(rest form))) (locally (&whole form &body body) (declare (ignore body)) `(cl:locally ,@(rest form))) (progn (&whole form &body body) (declare (ignore body)) `(cl:progn ,@(rest form))) (progv (&whole form symbols values &body body) (declare (ignore symbols values body)) `(cl:progv ,@(rest form))) (the (&whole form value-type expression) (declare (ignore value-type expression)) `(cl:the ,@(rest form))) (eval-when (&whole form (&rest situations) &body body) (declare (ignore situations body)) `(cl:eval-when ,@(rest form))) (load-time-value (&whole form expression &optional read-only-p) (declare (ignore expression read-only-p)) `(cl:load-time-value ,@(rest form)))) ,form)) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER.INTERNAL") (defvar *step-mode* :run " May be :run, :function :trace or :step. :run don't print anything, just evaluate the forms. :function just prints the function calls and their results. :trace just prints the forms and their results as they are evaluted. :step prints the form, then ask the user what to do (step over, step into, trace, run). When break-points are implemented, :run, :function and :trace will run until a break-point is reached. ") (defvar *step-max-trace-depth* nil "The maximum depth of function calls that should be traced. When more than that depth of calls occur, the *step-mode* switches to :run.") (defvar *step-current-trace-depth* 0 "The current depth of instrumented function calls.") ;; (STEP-TRACE f) T T F F ;; (STEP-NOTRACE f) T F T F ;; *STEP-MODE* :r :t :s :r :t :s :r :t :s :r :t :s ;; ---------------------------------------------------------------- ;; Action: r r s t t s r r s r t s ;; r = run, t = trace, s = step (in or over). (defvar *trace-functions* '() "A list of function names that we must trace with the stepper. SEE: STEP-TRACE, STEP-UNTRACE.") (defvar *break-functions-entry* '() "A list of function names that we must break into the stepper upon entry. SEE: STEP-BREAK-ENTRY, STEP-UNBREAK-ENTRY.") (defvar *break-functions-exit* '() "A list of function names that we must break into the stepper upon exit. SEE: STEP-BREAK-EXIT, STEP-UNBREAK-EXIT.") (defmacro step-trace-function (&rest fnames) " DO: Enable tracing of functions named by FNAMES. FNAMES: A list of function names. NOTE: The functions must have been compiled with the operators from the CL-STEPPER package not the CL package. RETURN: The list of function names added. " ;; We use :test 'equal for (setf fname). `(setf *trace-functions* (delete-duplicates (union *trace-functions* ',fnames :test (function equal)) :test (function equal)))) (defmacro step-untrace-function (&rest fnames) " DO: Disable tracing of functions named by FNAMES. FNAMES: A list of function names. NOTE: The functions must have been compiled with the operators from the CL-STEPPER package not the CL package. RETURN: The list of step-traced functions remaining. " `(setf *trace-functions* (set-difference *trace-functions* ',fnames :test (function equal)))) (defmacro step-break-entry (&rest fnames) " DO: Enable breaking on entry of functions named by FNAMES. FNAMES: A list of function names. NOTE: The functions must have been compiled with the operators from the CL-STEPPER package not the CL package. RETURN: The list of function names added. " `(setf *break-functions-entry* (delete-duplicates (union *break-functions-entry* ',fnames :test (function equal)) :test (function equal)))) (defmacro step-unbreak-entry (&rest fnames) " DO: Disable breaking on entry of functions named by FNAMES. FNAMES: A list of function names. NOTE: The functions must have been compiled with the operators from the CL-STEPPER package not the CL package. RETURN: The list of step-break-entry functions remaining. " `(setf *break-functions-entry* (set-difference *break-functions-entry* ',fnames :test (function equal)))) (defmacro step-break-exit (&rest fnames) " DO: Enable breaking on exit of functions named by FNAMES. FNAMES: A list of function names. NOTE: The functions must have been compiled with the operators from the CL-STEPPER package not the CL package. RETURN: The list of function names added. " `(setf *break-functions-exit* (delete-duplicates (union *break-functions-exit* ',fnames :test (function equal)) :test (function equal)))) (defmacro step-unbreak-exit (&rest fnames) " DO: Disable breaking on exit of functions named by FNAMES. FNAMES: A list of function names. NOTE: The functions must have been compiled with the operators from the CL-STEPPER package not the CL package. RETURN: The list of step-break-entry functions remaining. " `(setf *break-functions-exit* (set-difference *break-functions-exit* ',fnames :test (function equal)))) (defvar *step-level* 0 "The level.") (defvar *step-package* (find-package :cl-user) "The package bound to *PACKAGE* while printing tracing logs.") (defvar *step-print-readably* nil "The value bound to *PRINT-READABLY* while printing tracing logs.") (defvar *step-print-length* 10 "The value bound to *PRINT-LENGTH* while printing tracing logs.") (defvar *step-print-level* 3 "The value bound to *PRINT-LEVEl* while printing tracing logs.") (defvar *step-print-case* :downcase "The value bound to *PRINT-CASE* while printing tracing logs.") (defvar *step-trace-output* (make-synonym-stream '*trace-output*) "The stream where the stepper traces are written to.") (defmacro with-step-printing (&body body) `(let ((*print-length* *step-print-length*) (*print-level* *step-print-level*) (*print-readably* *step-print-readably*) (*print-case* *step-print-case*) (*package* *step-package*) (*step-mode* :run)) ,@body)) ;; Tracing steps: (defmacro with-parens (stream &body body) (let ((vstream (gensym))) `(let ((,vstream ,stream)) (unwind-protect (progn (format ,vstream "~&~V<~>(" *step-level*) ,@body) (format ,vstream ")"))))) (defun will-step (form &optional (stream *step-trace-output*)) (with-step-printing (format stream "Will evaluate ~S" form))) (defun did-bind (variable value &optional (stream *step-trace-output*)) " RETURN: VALUE " (unless (eq :run *step-mode*) (with-step-printing (format stream "~&~V<~> (Bind ~16A to ~S)" *step-level* variable value))) value) (defun print-step-results (results &optional (stream *step-trace-output*)) (when results (with-step-printing (let ((start "==>")) (dolist (result results) (format stream "~%~V<~>~A ~S" *step-level* start result) (setf start " ")))))) (defun did-step (form results &optional (stream *step-trace-output*)) (with-step-printing (format stream "~&~V<~> Evaluation of ~S returned ~:[no result~;~R result~:P~]" *step-level* form results (length results))) (if (= 1 (length results)) (format stream " ==> ~S" (first results)) (print-step-results results stream))) (defun did-tag (tag &optional (stream *step-trace-output*)) (unless (eq :run *step-mode*) (with-step-printing (format stream "~&~V<~> (Passed tag ~S)" *step-level* tag)))) ;; Interactive stepping: (define-condition step-condition (condition) ((message :initarg :message :initform "Step" :reader step-message)) (:report (lambda (condition stream) (format stream "~A" (step-message condition))))) (defun step-choice (&optional thunk) (when thunk (funcall thunk *step-trace-output*)) (with-step-printing (format *query-io* "~&~V<~> ~{~A~^, ~}?" *step-level* '("Step Into (s, si, RET)" "Step over (so)" "Trace (t)" "Function (f)" "Run (r)" "List (l)" "Eval (e)" "Debugger (d)" "Abort (a, q)"))) (let ((answer (string-trim " " (progn (finish-output *query-io*) (read-line *query-io*))))) (cond ((member answer '("" "s" "si") :test (function string-equal)) :step-into) ((string-equal answer "so") :step-over) ((string-equal answer "f") :function) ((string-equal answer "t") :trace) ((string-equal answer "r") :run) ((string-equal answer "l") :list) ((string-equal answer "e") :eval) ((string-equal answer "d") (restart-case (progn (invoke-debugger (make-condition 'step-condition :message (if thunk (with-output-to-string (out) (funcall thunk out)) "Step"))) :step-into) (step-into () :report "Step Into" (progn :step-into)) (step-over () :report "Step Over" (progn :step-over)) (step-trace () :report "Trace" (progn :trace)) (step-function () :report "Function" (progn :function)) (step-run () :report "Run" (progn :run)) (abort () :Report "Abort Stepping" (progn :abort)))) ((member answer '("a" "q") :test (function string-equal)) :abort) (t (step-choice thunk))))) ;; Instrumentation: ;; The step-* functions are called by macros to generate the stepping ;; code. Usually, calling a call-step-* function that does the actual ;; work. (defun substitute-ignorable (declarations) (mapcar (lambda (declaration) (destructuring-bind (declare &rest items) declaration `(,declare ,@(mapcar (lambda (item) (if (consp item) (destructuring-bind (op &rest args) item (if (eq 'ignore op) `(ignorable ,@args) item)) item)) items)))) declarations)) (assert (equalp (substitute-ignorable '((declare (type q x) (ignore x)) (declare (ignore z)) (declare (type p z)) (declare thing))) '((declare (type q x) (ignorable x)) (declare (ignorable z)) (declare (type p z)) (declare thing)))) (defun trivial-atom-p (atom) "Trivial atoms are either (quote something) forms, or atoms that are self-evaluating." (typecase atom (keyword t) ; self evaluating ((member nil t) t) ; self evaluating (symbol nil) ; variable or symbol-macro (cons (eq 'cl:quote (car atom))) (t t))) ; self evaluating (defun print-form (label form) (handler-case (let ((*print-pretty* t)) (format *step-trace-output* "~&~S~2%" form)) (error (err) (format *step-trace-output* "~&Cannot print the ~A for ~A~%" label err)))) (defvar *rep-history* 0) (defparameter *rep-eof* (gensym "EOF")) (defun read-eval-print () " DO: Implements a minimalist CL Read-Eval-Print body. " (catch 'repl (finish-output *standard-output*) (finish-output *trace-output*) (finish-output *error-output*) (finish-output *debug-io*) (format *debug-io* "~%~A[~D]> " (package-name *package*) (incf *rep-history*)) (finish-output *debug-io*) (handling-errors (setf - (read *debug-io* nil *rep-eof*)) (when (or (eq - *rep-eof*) (and (listp -) (null (rest -)) (member (first -) '(quit exit continue) :test (function string-equal)))) (return-from read-eval-print)) (let ((results (multiple-value-list (eval -)))) (setf +++ ++ ++ + + - /// // // / / results *** ** ** * * (first /))) (finish-output *standard-output*) (finish-output *trace-output*) (finish-output *error-output*) (format *debug-io* "~& --> ~{~S~^ ;~% ~}~%" /)) (format *debug-io* "~%") (finish-output *debug-io*))) (defmacro doagain (&body body) (let ((again (gensym "again"))) `(values-list (block ,again (tagbody ,again (return-from ,again (multiple-value-list (macrolet ((again () `(go ,',again))) ,@body)))))))) (defun call-step-atom (atom thunk) (case *step-mode* ((:run :function) (funcall thunk)) (:trace (let ((results (let ((*step-level* (1+ *step-level*))) (multiple-value-list (funcall thunk))))) (if (= 1 (length results)) (unless (trivial-atom-p atom) (with-parens *step-trace-output* (with-step-printing (format *step-trace-output* "~S ==> ~S" atom (first results))))) (with-parens *step-trace-output* (with-step-printing (did-step atom results)))) (values-list results))) (:step (flet ((do-step () (let ((results (let ((*step-level* (1+ *step-level*))) (multiple-value-list (funcall thunk))))) (with-step-printing (if (= 1 (length results)) (if (trivial-atom-p atom) (format *step-trace-output* "~&~V<~> (--> ~S)" *step-level* atom) (format *step-trace-output* "~&~V<~> (~S ==> ~S)" *step-level* atom (first results))) ;; (will-step display-form) (did-step atom results))) (values-list results)))) (with-parens *step-trace-output* (doagain (ecase (step-choice (lambda (out) (will-step atom out))) (:abort (throw 'abort-stepping nil)) (:eval (read-eval-print) (again)) (:list (print-form "atom" atom) (again)) (:run (setf *step-mode* :run) (funcall thunk)) (:function (setf *step-mode* :function) (funcall thunk)) (:trace (setf *step-mode* :trace) (do-step)) (:step-over (let ((*step-mode* :run)) (do-step))) (:step-into (do-step))))))))) (defun step-atom (object) `(call-step-atom ',object (lambda () ,object))) (defun step-simple-form (actual &optional (form actual)) `(call-step-atom ',form (lambda () ,actual))) (defun call-simple-step (thunk display-form) (flet ((do-step () (will-step display-form) (let ((results (let ((*step-level* (1+ *step-level*))) (multiple-value-list (funcall thunk))))) (did-step display-form results) (values-list results)))) (case *step-mode* ((:run :function) (funcall thunk)) (:trace (with-parens *step-trace-output* (do-step))) (:step (with-parens *step-trace-output* (doagain (ecase (step-choice (lambda (out) (will-step display-form out))) (:abort (throw 'abort-stepping nil)) (:eval (read-eval-print) (again)) (:list (print-form "form" display-form) (again)) (:run (setf *step-mode* :run) (funcall thunk)) (:function (setf *step-mode* :function) (do-step)) (:trace (setf *step-mode* :trace) (do-step)) (:step-over (let ((*step-mode* :run)) (do-step))) (:step-into (do-step))))))))) (defun simple-step (form &optional (display-form form)) `(call-simple-step (lambda () ,form) ',display-form)) (defun step-body (where body env) (multiple-value-bind (docstring declarations body) (parse-body where body) (append docstring (substitute-ignorable declarations) (mapcar (lambda (form) (step-expression form env)) body)))) (defun call-step-function (name specializers pnames pvals thunk) (labels ((report-enter (out) (with-step-printing (format out "Entering ~:[anonymous ~;~]function ~:*~:[~;~:*~S~]" (if specializers (cons name specializers) name))) (let ((*step-level* (1+ *step-level*))) (mapc (function did-bind) pnames pvals))) (report-exit (non-local-exit results out) (with-step-printing (format out "~&~V<~> Exiting ~:[anonymous ~;~]function ~:*~:[~;~:*~S ~]~ ~:[returned ~:[no result~;~R result~:P~]~;by non-local exit.~]" *step-level* (if specializers (cons name specializers) name) non-local-exit results (length results))) (if (= 1 (length results)) (format out " ==> ~S" (first results)) (print-step-results results out))) (do-step () (let ((results '()) (non-local-exit t)) (unwind-protect (setf results (let ((*step-level* (1+ *step-level*))) (multiple-value-list (funcall thunk))) non-local-exit nil) (unless (eq *step-mode* :run) (report-exit non-local-exit results *step-trace-output*)) (when (member name *break-functions-exit* :test (function equal)) (doagain (ecase (step-choice (lambda (out) (declare (ignore out)))) (:abort (throw 'abort-stepping nil)) (:eval (read-eval-print) (again)) (:list (print-form "function call" (cons name (mapcar (lambda (val) `(quote ,val)) pvals))) (again)) (:run (setf *step-mode* :run)) (:function (setf *step-mode* :function)) (:trace (setf *step-mode* :trace)) (:step-over (setf *step-mode* :step)) (:step-into (setf *step-mode* :step)))))) (values-list results))) (choice (report) (doagain (ecase (step-choice report) (:abort (throw 'abort-stepping nil)) (:eval (read-eval-print) (again)) (:list (print-form "function call" (cons name (mapcar (lambda (val) `(quote ,val)) pvals))) (again)) (:run (setf *step-mode* :run) (do-step)) (:function (setf *step-mode* :function) (do-step)) (:trace (setf *step-mode* :trace) (do-step)) (:step-over (let ((*step-mode* :run)) (do-step))) (:step-into (do-step)))))) (let ((*step-current-trace-depth* (1+ *step-current-trace-depth*))) (if (member name *break-functions-entry* :test (function equal)) (with-parens *step-trace-output* (choice (function report-enter))) (case *step-mode* ((:run) ;; (print (list (not (not (member name *trace-functions* :test (function equal)))) name *trace-functions*)) (if (member name *trace-functions* :test (function equal)) (let ((*step-mode* :trace) (*step-current-trace-depth* 0)) ; reset it (with-parens *step-trace-output* (report-enter *step-trace-output*) (do-step))) (do-step))) ((:function :trace) (if (and *step-max-trace-depth* (< *step-max-trace-depth* *step-current-trace-depth*)) (let ((*step-mode* :run)) (do-step)) (with-parens *step-trace-output* (report-enter *step-trace-output*) (do-step)))) ((:step) (with-parens *step-trace-output* (choice (function report-enter))))))))) (declaim (declaration stepper)) (pushnew :com.informatimago.common-lisp.lisp.cl-stepper *features*) (defun stepper-declaration-p (declarations keyword) (let ((result (dolist (declaration declarations) (let ((decl (and (consp declaration) (eq 'declare (first declaration)) (find-if (lambda (specifier) (and (consp specifier) (eq 'stepper (first specifier)) (member keyword (rest specifier)))) (rest declaration))))) (when decl (return decl)))))) ;; (format *step-trace-output* "~&(~S ~S ~S) --> ~S~%" ;; 'stepper-declaration-p declarations keyword result) result)) ;; (stepper-declaration-p '((declare (ignorable object) (stepper disable))) 'disable) ;; (stepper-declaration-p '((declare (type integer x)) (declare (stepper trace))) 'trace) (defun step-function (kind name lambda-list body env) " KIND: A lambda-list kind (:ordinary for functions, :specialized for methods, :destructuring for macros). NAME: The name of the defined function or macro. LAMBDA-FORM: A lambda form. BODY: A list of forms, the body of the function. RETURN: A stepping body. " (let* ((lambda-list (parse-lambda-list lambda-list kind)) (parameters (mapcar (function parameter-name) (lambda-list-parameters lambda-list))) (specializers (when (eq kind :specialized) (mapcar (lambda (parameter) (when (parameter-specializer-p parameter) (parameter-specializer parameter))) (lambda-list-parameters lambda-list))))) (multiple-value-bind (docstring declarations real-body) (parse-body :lambda body) (if (stepper-declaration-p declarations 'disable) (append docstring declarations (list (step-disabled `(progn ,@real-body)))) (append docstring (substitute-ignorable declarations) (let ((form `(call-step-function ',name ',specializers ',parameters (list ,@parameters) (lambda () ,@(if name `((block ,(if (consp name) (second name) name) ;; inner block for non-local exit. ,@(step-body :progn real-body env))) (step-body :progn real-body env)))))) (list (if (stepper-declaration-p declarations 'trace) `(let ((*step-mode* :trace)) ,form) form)))))))) (defun step-lambda (lambda-form &key (kind :ordinary) name environment) " ENV: An environment. LAMBDA-FORM: A lambda form. KIND: A lambda-list kind (:ordinary for functions, :generic for generic functions, :specialized for methods, :destructuring for macros, etc). NAME: The name of the defined function or macro. RETURN: A stepping lambda-form from the LAMBDA-FORM. " (destructuring-bind (lambda lambda-list &body body) lambda-form (declare (ignore lambda)) `(lambda ,lambda-list ,@(step-function kind name lambda-list body environment)))) (defun step-bindings (mode bindings form env) (flet ((binding-step (var expr) (if (eq :sequential mode) `(,var (did-bind ',var ,(step-expression expr env))) `(,var ,(step-expression expr env))))) (mapcar (lambda (binding) (cond ((symbolp binding) (binding-step binding 'nil)) ((atom binding) (error "Invalid atom ~S in binding list of ~S" binding form)) ((< 2 (length binding)) (error "Invalid binding ~S in binding list of ~S" binding form)) (t (binding-step (first binding) (second binding))))) bindings))) (defmacro symbol-reference (symbol &environment env) (let ((expansion (macroexpand symbol env))) (if (eq symbol expansion) (step-atom symbol) (step-expression expansion env)))) (defmacro self-evaluating (object) (step-atom object)) (defun step-function-call (form env) (destructuring-bind (function-name &rest arguments) form (if (consp function-name) (if (member (first function-name) '(com.informatimago.common-lisp.lisp.stepper:lambda lambda)) `(progn ,(simple-step `(,(step-lambda function-name :environment env) ,@(mapcar (lambda (argument) (step-expression argument env)) arguments)) `,form)) (error "Invalid object used as function name ~S in function call ~S" function-name form)) `(progn ,(simple-step `(,function-name ,@(mapcar (lambda (argument) (step-expression argument env)) arguments)) form))))) (defvar *implementation-specific-special-operators* '() "An a-list mapping symbols to macro-functions expanding an implementation specific special-operator.") #+ccl (push (cons 'ccl:compiler-let (lambda (whole environment) (declare (ignore environment)) (destructuring-bind (clet (&rest bindings) &body body) whole (declare (ignore clet bindings)) `(progn ,@body)))) *implementation-specific-special-operators*) (defun step-expression (form env) ;; Operators in CL-STEPPER are macros, so they're taken care of ;; automatically. (cond ((symbolp form) `(symbol-reference ,form)) ;; The other atoms are unchanged: ((atom form) `(self-evaluating ,form)) ;; Now we have a list. ((and (listp (first form)) (eq 'cl:lambda (first (first form)))) ;; ((cl:lambda …) …) (step-function-call form env)) ((and (listp (first form)) (eq 'lambda (first (first form)))) ;; ((lambda …) …) (step-function-call form env)) ((let ((somf (assoc (first form) *implementation-specific-special-operators*))) (and somf (progn (step-expression (funcall (cdr somf) form env) env) t)))) (t (case (first form) ;; First we check the real CL special operators: ;; We map them to cl-stepper operators and step the mapped version. ((function quote) (step-simple-form form)) ((eval-when locally progn) (simple-step form)) ((block catch flet go if labels let let* load-time-value macrolet multiple-value-call multiple-value-prog1 progv return-from setq symbol-macrolet tagbody the throw unwind-protect) (step-expression (cons (case (first form) ((block) 'com.informatimago.common-lisp.lisp.stepper:block) ((catch) 'com.informatimago.common-lisp.lisp.stepper:catch) ((flet) 'com.informatimago.common-lisp.lisp.stepper:flet) ((go) 'com.informatimago.common-lisp.lisp.stepper:go) ((if) 'com.informatimago.common-lisp.lisp.stepper:if) ((labels) 'com.informatimago.common-lisp.lisp.stepper:labels) ((let) 'com.informatimago.common-lisp.lisp.stepper:let) ((let*) 'com.informatimago.common-lisp.lisp.stepper:let*) ((load-time-value) 'com.informatimago.common-lisp.lisp.stepper:load-time-value) ((macrolet) 'com.informatimago.common-lisp.lisp.stepper:macrolet) ((multiple-value-call) 'com.informatimago.common-lisp.lisp.stepper:multiple-value-call) ((multiple-value-prog1) 'com.informatimago.common-lisp.lisp.stepper:multiple-value-prog1) ((progv) 'com.informatimago.common-lisp.lisp.stepper:progv) ((return-from) 'com.informatimago.common-lisp.lisp.stepper:return-from) ((setq) 'com.informatimago.common-lisp.lisp.stepper:setq) ((symbol-macrolet) 'com.informatimago.common-lisp.lisp.stepper:symbol-macrolet) ((tagbody) 'com.informatimago.common-lisp.lisp.stepper:tagbody) ((the) 'com.informatimago.common-lisp.lisp.stepper:the) ((throw) 'com.informatimago.common-lisp.lisp.stepper:throw) ((unwind-protect) 'com.informatimago.common-lisp.lisp.stepper:unwind-protect)) (rest form)) env)) ;; Next we check for the stepper macros. Since they already ;; expand to simple-step, we just use them as is, unless ;; they're toplevelness protected forms: ((com.informatimago.common-lisp.lisp.stepper:function com.informatimago.common-lisp.lisp.stepper:quote) (step-simple-form form)) ((com.informatimago.common-lisp.lisp.stepper:block com.informatimago.common-lisp.lisp.stepper:catch ;; com.informatimago.common-lisp.lisp.stepper:eval-when com.informatimago.common-lisp.lisp.stepper:flet com.informatimago.common-lisp.lisp.stepper:go com.informatimago.common-lisp.lisp.stepper:if com.informatimago.common-lisp.lisp.stepper:labels com.informatimago.common-lisp.lisp.stepper:let com.informatimago.common-lisp.lisp.stepper:let* com.informatimago.common-lisp.lisp.stepper:load-time-value ;; com.informatimago.common-lisp.lisp.stepper:locally com.informatimago.common-lisp.lisp.stepper:macrolet com.informatimago.common-lisp.lisp.stepper:multiple-value-call com.informatimago.common-lisp.lisp.stepper:multiple-value-prog1 ;; com.informatimago.common-lisp.lisp.stepper:progn com.informatimago.common-lisp.lisp.stepper:progv com.informatimago.common-lisp.lisp.stepper:return-from com.informatimago.common-lisp.lisp.stepper:setq com.informatimago.common-lisp.lisp.stepper:symbol-macrolet com.informatimago.common-lisp.lisp.stepper:tagbody com.informatimago.common-lisp.lisp.stepper:the com.informatimago.common-lisp.lisp.stepper:throw com.informatimago.common-lisp.lisp.stepper:unwind-protect) form) (otherwise (if (macro-function (first form) env) ;; For a macro, we expand it, and step the expansion; ;; most probably the expansion will contain CL operator, ;; they're mapped above. (step-expression (macroexpand form env) env) ;; For a function, we step the arguments: (step-function-call form env))))))) ;;;; THE END ;;;;
38,438
Common Lisp
.lisp
773
38.003881
122
0.550003
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
ec4f3cd462f31230de9f53e2c5795f54738401b556a06f957124896199ccdda8
4,969
[ -1 ]
4,970
generic-cl.lisp
informatimago_lisp/common-lisp/lisp/generic-cl.lisp
;;;; -*- coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: generic-cl.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; See :documentation of package below. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2006-05-27 <PJB> Created ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2006 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.GENERIC-COMMON-LISP" (:nicknames "GENERIC-COMMON-LISP" "GENERIC-CL") (:use "COMMON-LISP") (:documentation " This package exports generic functions that forward to the COMMON-LISP package when there's no specialization. Copyright Pascal J. Bourguignon 2006 - 2006 This package is provided under the Afero General Public License 3. See the source file for details. ") ;; export the same symbols as CL: (:export . #.(let ((symbols '())) (do-external-symbols (sym "COMMON-LISP") (push (string sym) symbols)) symbols))) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.GENERIC-COMMON-LISP") ;; export at the end. (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter *not-implemented-yet* (make-hash-table :test (function equal)))) (defmacro not-implemented-yet (what) (unless (gethash what *not-implemented-yet*) (setf (gethash what *not-implemented-yet*) t) (warn "~S not implemented yet." what)) `(progn (unless (gethash ',what *not-implemented-yet*) (setf (gethash ',what *not-implemented-yet*) t) (warn "~S not implemented yet." ',what)) nil)) (defmacro define-forward (name arguments) ;; (let* ((lambda-list (parse-lambda-list arguments :ordinary)) ;; (m-name (intern (format nil "%~A" name))) ;; (cl-name (intern (string (if (consp name) ;; (second name) ;; name)) ;; "COMMON-LISP"))) ;; ;; When a keyword or optional argument has no initform ;; ;; then add one to the method and use APPLY. ;; `(progn ;; (shadow '(,m-name)) ;; (defgeneric ,m-name ,(mapcar (lambda (arg) ;; (if (consp arg) ;; (if (consp (first arg)) ;; (second (first arg)) ;; (first arg)) ;; arg)) ;; arguments) ;; (:method ,arguments ;; ,(if (consp name) ;; `(setf (,cl-name ,@(cdr arguments)) ,(car arguments)) ;; `(,cl-name ,@arguments)))))) (declare (ignore name arguments)) (not-implemented-yet define-forward)) (defmacro defmethod-and-forward (name fname arguments) (declare (ignore name fname arguments)) (not-implemented-yet defmethod-and-forward)) (defmacro define-method (name qualifiers-or-lambda-list &body body) (declare (ignore name qualifiers-or-lambda-list body)) (not-implemented-yet define-method)) ;; t ;; sequence ;; vector ;; list ;; null ;; cons ;; user-sequence ;; direct-access-sequence ;; sequential-access-sequence ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; After these define-foward, these functions become generic functions, ;;; with a default method that calls the corresponding function in CL. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Forwarding 14. Conses ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-forward rplaca (cons object)) (define-forward rplacd (cons object)) (dolist (name '(car cdr caar cadr cdar cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr first second third fourth fifth sixth seventh eighth ninth tenth )) (eval `(define-forward ,name (cons))) (eval `(define-forward (setf ,name) (value cons)))) (define-forward copy-tree (tree)) (dolist (name '(sublis nsublis)) (eval `(define-forward ,name (alist tree &key (key nil) (test (function eql)) test-not)))) (dolist (name '(subst nsubst)) (eval `(define-forward ,name (new old tree &key (key nil) (test (function eql)) test-not)))) (dolist (name '(subst nsubst)) (eval `(define-forward ,name (new old tree &key (key nil) (test (function eql)) test-not)))) (dolist (name '(subst-if subst-if-not nsubst-if nsubst-if-not)) (eval `(define-forward ,name (new predicate tree &key (key nil) (test (function eql)) test-not)))) (define-forward tree-equal (tree-1 tree-2 &key (test (function eql)) test-not)) (define-forward copy-list (list)) (define-forward endp (list)) (define-forward nth (n list)) (define-forward (setf nth) (value n list)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Forwarding 17. Sequences ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-forward copy-seq (sequence)) (define-forward elt (sequence index)) (define-forward (setf elt) (value sequence index)) (define-forward fill (sequence item &key (start 0) (end nil))) (define-forward make-sequence (result-type size &key initial-element)) (define-forward subseq (sequence start &optional (end nil))) (define-forward (setf subseq) (value sequence start &optional (end nil))) (define-forward map (result-type function sequence &rest sequences)) (define-forward map-into (result-sequence function &rest sequences)) (define-forward length (sequence)) (define-forward reverse (sequence)) (define-forward nreverse (sequence)) (define-forward sort (sequence predicate &key (key nil))) (define-forward stable-sort (sequence predicate &key (key nil))) (define-forward concatenate (result-type &rest sequences)) (define-forward merge (result-type sequence-1 sequence-2 predicate &key (key nil))) (dolist (name '(remove-duplicates delete-duplicates)) (eval `(define-forward ,name (sequence &key (key nil) (from-end nil) (start 0) (end nil) (test (function eql)) test-not)))) (dolist (name '(count find position)) (eval `(define-forward ,name (item sequence &key (key nil) (from-end nil) (start 0) (end nil) (test (function eql)) test-not)))) (dolist (name '(count-if count-if-not find-if find-if-not position-if position-if-not)) (eval `(define-forward ,name (predicate sequence &key (key nil) (from-end nil) (start 0) (end nil))))) (define-forward reduce (function sequence &key (key nil) (from-end nil) (start 0) (end nil) initial-value)) (dolist (name '(search mismatch)) (eval `(define-forward ,name (sequence-1 sequence-2 &key (key nil) (from-end nil) (start1 0) (end1 nil)(start2 0) (end2 nil) (test (function eql)) test-not)))) (define-forward replace (sequence-1 sequence-2 &key (start1 0) (end1 nil) (start2 0) (end2 nil))) (defmethod-and-forward substitute nsubstitute (newitem olditem (self sequential-access-sequence) &key (from-end nil) (test (function eql)) test-not (start 0) (end nil) (count nil) (key nil))) (defmethod-and-forward substitute-if nsubstitute-if (newitem olditem (self sequential-access-sequence) &key (from-end nil) (test (function eql)) test-not (start 0) (end nil) (count nil) (key nil))) (defmethod-and-forward substitute-if-not nsubstitute-if-not (newitem olditem (self sequential-access-sequence) &key (from-end nil) (test (function eql)) test-not (start 0) (end nil) (count nil) (key nil)) ) (dolist (name '(remove delete)) (eval `(define-forward ,name (item sequence &key (from-end nil) (test (function eql)) test-not (start 0) (end nil) (count nil) (key nil))))) (dolist (name '(remove-if remove-if-not delete-if delete-if-not)) (eval `(define-forward ,name (test sequence &key (from-end nil) (start 0) (end nil) (count nil) (key nil))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;--------------------------------------------------------------------- ;;; So now, we can define our own subclasses of sequences. ;;;--------------------------------------------------------------------- ;; (define-method closer-mop:validate-superclass :before ((c class) (s class)) ;; (call-next-method)) ;; (remove-method (function closer-mop:validate-superclass) ;; (find-method (function closer-mop:validate-superclass) ;; ':before ;; '(class class))) ;;; this doesn't work on ccl for built-in-class vs stanard-class ;;; and not on clisp for find-class can't find the class pased in arguments. ;; (define-method closer-mop:validate-superclass :before ;; ((class class) (superclass class)) ;; (warn "~S check again this implementation!"'(closer-mop:validate-superclass :before ;; ((class class) (superclass class)))) ;; (print class) ;; (print (list class (eql class (find-class 'user-sequence)) ;; superclass (eql superclass (load-time-value (find-class 'sequence))))) ;; (print (or (and #-clisp (eql class (find-class 'user-sequence)) ;; #+clisp (eq 'user-sequence (class-name class)) ;; (eql superclass (load-time-value (find-class 'sequence)))) ;; (call-next-method)))) (warn "TODO: implement user-sequence as subclass of sequence") (defclass user-sequence (#+not-yet sequence) () (:documentation "Our own abstract sequence class.")) ;;;--------------------------------------------------------------------- ;;; Abstract direct access sequence ;;;--------------------------------------------------------------------- (defclass direct-access-sequence (user-sequence) ((length #+not-yet :reader #+not-yet length)) (:documentation "A class of vector-like sequences with direct access.")) (define-method copy-seq ((self direct-access-sequence)) (let ((copy (make-instance (class-of self) :size (length self)))) (loop :for i :from 0 :below (length self) :do (setf (elt copy i) (elt self i)) :finally (return copy)))) ;;; primitives: ;;; (define-method elt ((self direct-access-sequence) index) ) ;;; (define-method (setf elt) (value (self direct-access-sequence) index) value) ;;;--------------------------------------------------------------------- ;;; Abstract sequential access sequence ;;;--------------------------------------------------------------------- (defclass sequential-access-sequence (user-sequence) () (:documentation "A class of list-like sequences with sequential access.")) (defgeneric sas-head (self) (:documentation "RETURN: A cursor at the head of the sequence.")) (defclass sas-cursor () ((sas :reader cursor-sas :initarg :sequence)) (:documentation "A cursor on a sequential access sequence.")) (defgeneric sas-cursor-copy (self) (:documentation "RETURN: a copy of the cursor. Calling (sas-cursor-next self) won't change the copy.")) (defgeneric sas-cursor-next (self) (:documentation "RETURN: the next cursor. May modify self, or may return a new object.")) (defgeneric sas-cursor-end-p (self) (:documentation "RETURN: whether the cursor has reached the end of the sequence.")) (defgeneric sas-cursor-value (self) (:documentation "PRE: (not (sas-cursor-end-p self)) RETURN: the value at the cursor position in the sequence.")) (defgeneric (setf sas-cursor-value) (value self) (:documentation "DO: Sets the value at the cursor position in the sequence. If the cursor is at the end, then append then new value. POST: (not (sas-cursor-end-p self))")) (define-method length ((self sequential-access-sequence)) (loop :for cursor = (sas-head self) :then (sas-cursor-next cursor) :for length :from 0 :until (sas-cursor-end-p cursor) :finally (return length))) (define-method copy-seq ((self sequential-access-sequence)) (let ((copy (make-instance (class-of self)))) (loop :for src = (sas-head self) :then (sas-cursor-next src) :for dst = (sas-head self) :then (sas-cursor-next dst) :until (sas-cursor-end-p src) :do (setf (sas-cursor-value dst) (sas-cursor-value src)) :finally (return copy)))) (define-method elt ((self sequential-access-sequence) index) (check-type index (integer 0)) (loop :for cursor = (sas-head self) :then (sas-cursor-next cursor) :for length :from 0 :below index :do (if (sas-cursor-end-p cursor) (check-type index `(integer 0 ,length)) (return (sas-cursor-value cursor))))) (define-method (setf elt) (value (self sequential-access-sequence) index) (check-type index (integer 0)) (loop :for cursor = (sas-head self) :then (sas-cursor-next cursor) :for length :from 0 :below index :do (if (sas-cursor-end-p cursor) (check-type index `(integer 0 ,length)) (return (setf (sas-cursor-value cursor) value))))) (define-method fill ((self sequential-access-sequence) item &key (start 0) (end nil)) (loop :for cursor = (sas-head self) :then (sas-cursor-next cursor) :for index :from start :below end :do (cond ((sas-cursor-end-p cursor) (return self)) ((< index start)) ((and end (<= end index)) (return self)) (t (setf (sas-cursor-value cursor) item))))) (define-method subseq ((self sequential-access-sequence) start &optional (end nil)) (loop :with sub = (make-instance (class-of self)) :with dst = (sas-head sub) :for src = (sas-head self) :then (sas-cursor-next src) :for index :from start :do (cond ((sas-cursor-end-p src) (return sub)) ((< index start)) ((and end (<= end index)) (return sub)) (t (setf (sas-cursor-value dst) (sas-cursor-value src)))))) (define-method (setf subseq) (value sequence start &optional (end nil)) (declare (ignore value sequence start end)) (not-implemented-yet (setf subseq))) (define-forward map (result-type function sequence &rest sequences)) (define-forward map-into (result-sequence function &rest sequences)) (define-forward length (sequence)) (define-forward nreverse (sequence)) (define-forward sort (sequence predicate &key (key nil))) (define-forward stable-sort (sequence predicate &key (key nil))) (define-forward concatenate (result-type &rest sequences)) (define-forward merge (result-type sequence-1 sequence-2 predicate &key (key nil))) (define-method make-sequence ((result-type sequence) size &key initial-element) (declare (ignore result-type size initial-element)) (not-implemented-yet make-sequence)) (dolist (name '(remove delete)) (eval `(define-forward ,name (item sequence &key (from-end nil) (test (function eql)) test-not (start 0) (end nil) (count nil) (key nil))))) (dolist (name '(remove-if remove-if-not delete-if delete-if-not)) (eval `(define-forward ,name (test sequence &key (from-end nil) (start 0) (end nil) (count nil) (key nil))))) (dolist (name '(remove-duplicates delete-duplicates)) (eval `(define-forward ,name (sequence &key (key nil) (from-end nil) (start 0) (end nil) (test (function eql)) test-not)))) (dolist (name '(count find position)) (eval `(define-forward ,name (item sequence &key (key nil) (from-end nil) (start 0) (end nil) (test (function eql)) test-not)))) (dolist (name '(count-if count-if-not find-if find-if-not position-if position-if-not)) (eval `(define-forward ,name (predicate sequence &key (key nil) (from-end nil) (start 0) (end nil))))) (define-forward reduce (function sequence &key (key nil) (from-end nil) (start 0) (end nil) initial-value)) (dolist (name '(search mismatch)) (eval `(define-forward ,name (sequence-1 sequence-2 &key (key nil) (from-end nil) (start1 0) (end1 nil)(start2 0) (end2 nil) (test (function eql)) test-not)))) (define-forward replace (sequence-1 sequence-2 &key (start1 0) (end1 nil)(start2 0) (end2 nil))) (defmethod-and-forward substitute nsubstitute (newitem olditem (self sequential-access-sequence) &key (from-end nil) (test (function eql)) test-not (start 0) (end nil) (count nil) (key nil)) ) (defmethod-and-forward substitute-if nsubstitute-if (newitem olditem (self sequential-access-sequence) &key (from-end nil) (test (function eql)) test-not (start 0) (end nil) (count nil) (key nil)) ) (defmethod-and-forward substitute-if-not nsubstitute-if-not (newitem olditem (self sequential-access-sequence) &key (from-end nil) (test (function eql)) test-not (start 0) (end nil) (count nil) (key nil)) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; THE END ;;;;
19,151
Common Lisp
.lisp
395
43.308861
89
0.584915
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
248e6b3cfd9d83911a6be48fdfcb516e7f45106c0cc96ae09a22d132183a6b41
4,970
[ -1 ]
4,971
stepper-packages.lisp
informatimago_lisp/common-lisp/lisp/stepper-packages.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: stepper-packages.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Defines the Common Lisp Stepper packages. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2022-07-14 <PJB> Corrected bug with ABORT-STEPPING. ;;;; 2012-08-09 <PJB> Extracted from stepper.lisp ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2012 - 2022 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) ;; We define an internal package that uses COMMON-LISP to easily ;; define functions and macros, since the CL-STEPPER package shadows ;; all the special operators and defun, defgeneric and defmacro ;; macros. ;; ;; The CL-STEPPER package only contains those shadowed macro ;; definitions. (defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER.INTERNAL" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.LISP-SEXP.SOURCE-FORM" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.UTILITY") #+mocl (:shadowing-import-from "COM.INFORMATIMAGO.MOCL.KLUDGES.MISSING" "*TRACE-OUTPUT*" "ARRAY-DISPLACEMENT" "CHANGE-CLASS" "COMPILE" "COMPLEX" "ENSURE-DIRECTORIES-EXIST" "FILE-WRITE-DATE" "INVOKE-DEBUGGER" "*DEBUGGER-HOOK*" "LOAD" "LOGICAL-PATHNAME-TRANSLATIONS" "MACHINE-INSTANCE" "MACHINE-VERSION" "NSET-DIFFERENCE" "RENAME-FILE" "SUBSTITUTE-IF" "TRANSLATE-LOGICAL-PATHNAME") (:export "*STEP-PACKAGE*" "*STEP-PRINT-READABLY*" "*STEP-PRINT-LENGTH*" "*STEP-PRINT-LEVEL*" "*STEP-PRINT-CASE*" "*STEP-TRACE-OUTPUT*" "*STEP-MAX-TRACE-DEPTH*" "STEP-TRACE-FUNCTION" "STEP-UNTRACE-FUNCTION" "STEP-BREAK-ENTRY" "STEP-UNBREAK-ENTRY" "STEP-BREAK-EXIT" "STEP-UNBREAK-EXIT" "*STEP-MODE*" "*STEP-LEVEL*" "WILL-STEP" "DID-BIND" "PRINT-STEP-RESULTS" "DID-STEP" "DID-TAG" "STEP-CONDITION" "STEP-MESSAGE" "STEP-CHOICE" "ABORT-STEPPING" "STEPPER" "DISABLE" "STEPPER-DECLARATION-P" "STEP-DISABLED" "SUBSTITUTE-IGNORABLE" "SIMPLE-STEP" "STEP-SIMPLE-FORM" "STEP-ATOM" "STEP-EXPRESSION" "STEP-BODY" "STEP-FUNCTION" "STEP-LAMBDA" "STEP-BINDINGS") (:documentation " This is an internal package of the Common Lisp stepper. This package exports the stepper generator functions, and defines stepper interactive functions (not exported). See the documentation of the package COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER. BUGS: we should probably design it with hooks so that clients may define the stepping/tracing user interface. Copyright Pascal J. Bourguignon 2012 - 2022 This package is provided under the Afero General Public License 3. See the source file for details. ")) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER" (:nicknames "COMMON-LISP-STEPPER" "CL-STEPPER" #-lispworks "STEPPER") (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.LISP-SEXP.SOURCE-FORM" "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER.INTERNAL") #+mocl (:shadowing-import-from "COM.INFORMATIMAGO.MOCL.KLUDGES.MISSING" "*TRACE-OUTPUT*" "ARRAY-DISPLACEMENT" "CHANGE-CLASS" "COMPILE" "COMPLEX" "ENSURE-DIRECTORIES-EXIST" "FILE-WRITE-DATE" "INVOKE-DEBUGGER" "*DEBUGGER-HOOK*" "LOAD" "LOGICAL-PATHNAME-TRANSLATIONS" "MACHINE-INSTANCE" "MACHINE-VERSION" "NSET-DIFFERENCE" "RENAME-FILE" "SUBSTITUTE-IF" "TRANSLATE-LOGICAL-PATHNAME") (:shadow ;; macros "DEFUN" "DEFGENERIC" "DEFMETHOD" "LAMBDA" "DEFINE-CONDITION" "STEP") (:shadow ;; special operators "BLOCK" "CATCH" "EVAL-WHEN" "FLET" "FUNCTION" "GO" "IF" "LABELS" "LET" "LET*" "LOAD-TIME-VALUE" "LOCALLY" "MACROLET" "MULTIPLE-VALUE-CALL" "MULTIPLE-VALUE-PROG1" "PROGN" "PROGV" "QUOTE" "RETURN-FROM" "SETQ" "SYMBOL-MACROLET" "TAGBODY" "THE" "THROW" "UNWIND-PROTECT") (:export ;; everything from COMMON-LISP . #.(cl:let ((e '())) (cl:do-external-symbols (s "COMMON-LISP" e) (push (string s) e)))) (:export "*STEP-MODE*" "*STEP-PRINT-LENGTH*" "*STEP-PRINT-LEVEL*" "*STEP-PRINT-CASE*" "*STEP-PACKAGE*" "*STEP-TRACE-OUTPUT*" "*STEP-MAX-TRACE-DEPTH*" "STEP-TRACE-FUNCTION" "STEP-UNTRACE-FUNCTION" "STEP-BREAK-ENTRY" "STEP-UNBREAK-ENTRY" "STEP-BREAK-EXIT" "STEP-UNBREAK-EXIT" "STEPPER" "DISABLE" #| "TRACE" already exported as CL symbol |# ;; (declare (stepper disable)) ; to prevent instrumentation of the ;; enclosing sexp and sub expressions. ) (:documentation " Implements a Portable Common Lisp Stepper. This package should be used instead of COMMON-LISP, and the code recompiled or reloaded. This will instrumentalize the functions so that tracing and stepping is available. To start running some code step-by-step, you can use: (step (some-expression)) ; note: it's cl-stepper:step, not cl:step. Or you may use STEP-TRACE-FUNCTION, to activate tracing of some functions (that must have been compiled with CL-STEPPER), or STEP-BREAK-ENTRY or STEP-BREAK-EXIT to enter the stepper upon entry or exit of the named functions. It is also possible to run the tracer on all the code that has been compiled with CL-STEPPER, with: (setf *step-mode* :trace) Reset it with: (setf *step-mode* :run) If you load a lot of packages with CL-STEPPER, you may want to set *STEP-MAX-CALL-DEPTH* to a small integer when using *STEP-MODE* :trace, to avoid very big output. You may also redirect the tracing output to a different stream setting *STEP-TRACE-OUTPUT*. Note: when tracing a function with (step-trace-function fun), the depth is reset while tracing that function (*step-max-call-depth* still applies for the call tree starting from that function). The stepper menu is: Step Into (s, si, RET), Step over (so), Trace (t), Run (r), Debugger (d), Abort (a, q)? Step Into: Continue evaluating each forms and subforms step by step. Step Over: Evaluate the current form in one step. Trace: The code is executed, and all the instrumented code produces traces. Run: The code is executed silently. Debugger: The debugger is invoked with a STEP-CONDITION. There are restarts installed to invoke all the stepper menu commands. Abort: The evaluation of the STEP form is aborted. With the Step Over, Trace, and Run commands, if a function with a break-point or an active trace is reached, it will still enter the stepper menu again, or trace it. To disable instrumentation of a form, you can insert (stepper disable) declarations in the places where declarations are allowed. (declaim (declaration stepper)) ; for when CL-STEPPER is not used. (… (declare (stepper disable)) …) declarations. Use (locally (declare (stepper disable)) …) to disable in random places. Similarly, to force tracing a function or a form, use the (declare (stepper trace)) declaration. \(stepper disable) has priority over (stepper trace). Copyright Pascal J. Bourguignon 2012 - 2022 This package is provided under the Afero General Public License 3. See the source file for details. ")) ;;;; THE END ;;;;
9,125
Common Lisp
.lisp
211
35.421801
83
0.62599
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
b4034d0c104f7612d1cab83ff32307e4fa163c1426849e1d2c51f816575e504e
4,971
[ -1 ]
4,972
com.informatimago.common-lisp.lisp.asd
informatimago_lisp/common-lisp/lisp/com.informatimago.common-lisp.lisp.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.lisp.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.lisp library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.lisp" ;; system attributes: :description "Informatimago Common Lisp Lisp Language Utility and Extensions" :long-description " Currently we provide a GENERIC-CL package exporting generic functions that forward to the COMMON-LISP package when there's no specialization. " :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes :version "1.4.0" :properties ((#:author-email . "[email protected]") (#:date . "Autumn 2010") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.lisp/") ((#:albert #:formats) . ("docbook")) ((#:albert #:docbook #:template) . "book") ((#:albert #:docbook #:bgcolor) . "white") ((#:albert #:docbook #:textcolor) . "black")) #+asdf-unicode :encoding #+asdf-unicode :utf-8 :depends-on ("closer-mop" "com.informatimago.common-lisp.lisp.ibcl" "com.informatimago.common-lisp.lisp.stepper" "com.informatimago.common-lisp.lisp.relative-package") :components ((:file "generic-cl" :depends-on ())) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.lisp.ibcl.test") (asdf:test-op "com.informatimago.common-lisp.lisp.stepper.test") (asdf:test-op "com.informatimago.common-lisp.lisp.relative-package.test") (asdf:test-op "com.informatimago.common-lisp.lisp.test")))) ;;;; THE END ;;;;
3,129
Common Lisp
.lisp
65
43.553846
108
0.604902
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
be95d3de2cd7fb5c74c1587289a138345bcaa49882fdcff8baeae34a3384874b
4,972
[ -1 ]
4,973
com.informatimago.common-lisp.lisp.test.asd
informatimago_lisp/common-lisp/lisp/com.informatimago.common-lisp.lisp.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.lisp.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.lisp.test system. ;;;; Tests the com.informatimago.common-lisp.lisp system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.lisp.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.lisp system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.lisp.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.lisp") :components ((:file "source-test") (:file "stepper-test")) #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) (let ((*package* (find-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE.TEST"))) (uiop:symbol-call "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE.TEST" "TEST/ALL")) (let ((*package* (find-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER.TEST"))) (uiop:symbol-call "COM.INFORMATIMAGO.COMMON-LISP.LISP.STEPPER.TEST" "TEST/ALL")))) ;;;; THE END ;;;;
3,307
Common Lisp
.lisp
70
39.585714
111
0.551777
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
7ad6ffbe75fc4177b18ef4f9d0904536d6dbf74a47a9fe01f5a6c9923f1e6c2b
4,973
[ -1 ]
4,974
cl-symbols-by-chapter.lisp
informatimago_lisp/common-lisp/lisp/cl-symbols-by-chapter.lisp
(defparameter *cl-symbols-by-chapter* '(((3 "Evaluation and Compilation") (:symbol lambda) (:macro lambda) (:function compile) (:function eval) (:special-operator eval-when) (:special-operator load-time-value) (:special-operator quote) (:accessor compiler-macro-function) (:macro define-compiler-macro) (:macro defmacro) (:accessor macro-function) (:function macroexpand) (:function macroexpand-1) (:macro define-symbol-macro) (:special-operator symbol-macrolet) (:variable *macroexpand-hook*) (:function proclaim) (:macro declaim) (:symbol declare) (:declaration ignore) (:declaration ignorable) (:declaration dynamic-extent) (:declaration type) (:declaration inline) (:declaration notinline) (:declaration ftype) (:declaration declaration) (:declaration optimize) (:declaration special) (:special-operator locally) (:special-operator the) (:function special-operator-p) (:function constantp)) ((4 "Types and Classes") (:type nil) (:type boolean) (:system-class function) (:type compiled-function) (:system-class generic-function) (:system-class standard-generic-function) (:system-class class) (:system-class built-in-class) (:system-class structure-class) (:system-class standard-class) (:system-class method) (:system-class standard-method) (:class structure-object) (:class standard-object) (:system-class method-combination) (:system-class t) (:type-specifier satisfies) (:type-specifier member) (:type-specifier not) (:type-specifier and) (:type-specifier or) (:type-specifier values) (:type-specifier eql) (:function coerce) (:macro deftype) (:function subtypep) (:function type-of) (:function typep) (:condition-type type-error) (:function type-error-datum) (:function type-error-expected-type) (:condition-type simple-type-error)) ((5 "Data and Control Flow") (:function apply) (:macro defun) (:accessor fdefinition) (:function fboundp) (:function fmakunbound) (:special-operator flet) (:special-operator labels) (:special-operator macrolet) (:function funcall) (:special-operator function) (:function function-lambda-expression) (:function functionp) (:function compiled-function-p) (:constant-variable call-arguments-limit) (:constant-variable lambda-list-keywords) (:constant-variable lambda-parameters-limit) (:macro defconstant) (:macro defparameter) (:macro defvar) (:macro destructuring-bind) (:special-operator let) (:special-operator let*) (:special-operator progv) (:special-form setq) (:macro psetq) (:special-operator block) (:special-operator catch) (:special-operator go) (:special-operator return-from) (:macro return) (:special-operator tagbody) (:special-operator throw) (:special-operator unwind-protect) (:constant-variable nil) (:function not) (:constant-variable t) (:function eq) (:function eql) (:function equal) (:function equalp) (:function identity) (:function complement) (:function constantly) (:function every) (:function some) (:function notevery) (:function notany) (:macro and) (:macro cond) (:special-operator if) (:macro or) (:macro when) (:macro unless) (:macro case) (:macro ccase) (:macro ecase) (:macro typecase) (:macro ctypecase) (:macro etypecase) (:macro multiple-value-bind) (:special-operator multiple-value-call) (:macro multiple-value-list) (:special-operator multiple-value-prog1) (:macro multiple-value-setq) (:accessor values) (:function values-list) (:constant-variable multiple-values-limit) (:macro nth-value) (:macro prog) (:macro prog*) (:macro prog1) (:macro prog2) (:special-operator progn) (:macro define-modify-macro) (:macro defsetf) (:macro define-setf-expander) (:function get-setf-expansion) (:macro setf) (:macro psetf) (:macro shiftf) (:macro rotatef) (:condition-type control-error) (:condition-type program-error) (:condition-type undefined-function)) ((6 "Iteration") (:macro do) (:macro do*) (:macro dotimes) (:macro dolist) (:macro loop) (:local-macro loop-finish)) ((7 "Objects") (:standard-generic-function function-keywords) (:function ensure-generic-function) (:standard-generic-function allocate-instance) (:standard-generic-function reinitialize-instance) (:standard-generic-function shared-initialize) (:standard-generic-function update-instance-for-different-class) (:standard-generic-function update-instance-for-redefined-class) (:standard-generic-function change-class) (:function slot-boundp) (:function slot-exists-p) (:function slot-makunbound) (:standard-generic-function slot-missing) (:standard-generic-function slot-unbound) (:function slot-value) (:standard-generic-function method-qualifiers) (:standard-generic-function no-applicable-method) (:standard-generic-function no-next-method) (:standard-generic-function remove-method) (:standard-generic-function make-instance) (:standard-generic-function make-instances-obsolete) (:standard-generic-function make-load-form) (:function make-load-form-saving-slots) (:macro with-accessors) (:macro with-slots) (:macro defclass) (:macro defgeneric) (:macro defmethod) (:accessor find-class) (:local-function next-method-p) (:local-macro call-method) (:local-macro make-method) (:local-function call-next-method) (:standard-generic-function compute-applicable-methods) (:macro define-method-combination) (:standard-generic-function find-method) (:standard-generic-function add-method) (:standard-generic-function initialize-instance) (:standard-generic-function class-name) (:standard-generic-function (setf class-name)) (:function class-of) (:condition-type unbound-slot) (:function unbound-slot-instance)) ((8 "Structures") (:macro defstruct) (:function copy-structure)) ((9 "Conditions") (:condition-type condition) (:condition-type warning) (:condition-type style-warning) (:condition-type serious-condition) (:condition-type error) (:condition-type cell-error) (:function cell-error-name) (:condition-type parse-error) (:condition-type storage-condition) (:macro assert) (:function error) (:function cerror) (:macro check-type) (:condition-type simple-error) (:function invalid-method-error) (:function method-combination-error) (:function signal) (:condition-type simple-condition) (:function simple-condition-format-control) (:function simple-condition-format-arguments) (:function warn) (:condition-type simple-warning) (:function invoke-debugger) (:function break) (:variable *debugger-hook*) (:variable *break-on-signals*) (:macro handler-bind) (:macro handler-case) (:macro ignore-errors) (:macro define-condition) (:function make-condition) (:system-class restart) (:function compute-restarts) (:function find-restart) (:function invoke-restart) (:function invoke-restart-interactively) (:macro restart-bind) (:macro restart-case) (:function restart-name) (:macro with-condition-restarts) (:macro with-simple-restart) (:restart abort) (:restart continue) (:restart muffle-warning) (:restart store-value) (:restart use-value) (:function abort) (:function continue) (:function muffle-warning) (:function store-value) (:function use-value)) ((10 "Symbols") (:system-class symbol) (:type keyword) (:function symbolp) (:function keywordp) (:function make-symbol) (:function copy-symbol) (:function gensym) (:variable *gensym-counter*) (:function gentemp) (:accessor symbol-function) (:function symbol-name) (:function symbol-package) (:accessor symbol-plist) (:accessor symbol-value) (:accessor get) (:function remprop) (:function boundp) (:function makunbound) (:function set) (:condition-type unbound-variable)) ((11 "Packages") (:system-class package) (:function export) (:function find-symbol) (:function find-package) (:function find-all-symbols) (:function import) (:function list-all-packages) (:function rename-package) (:function shadow) (:function shadowing-import) (:function delete-package) (:function make-package) (:macro with-package-iterator) (:function unexport) (:function unintern) (:macro in-package) (:function unuse-package) (:function use-package) (:macro defpackage) (:macro do-symbols) (:macro do-external-symbols) (:macro do-all-symbols) (:function intern) (:function package-name) (:function package-nicknames) (:function package-shadowing-symbols) (:function package-use-list) (:function package-used-by-list) (:function packagep) (:variable *package*) (:condition-type package-error) (:function package-error-package)) ((12 "Numbers") (:system-class number) (:system-class complex) (:system-class real) (:system-class float) (:type short-float) (:type single-float) (:type double-float) (:type long-float) (:system-class rational) (:system-class ratio) (:system-class integer) (:type signed-byte) (:type unsigned-byte) (:type-specifier mod) (:type bit) (:type fixnum) (:type bignum) (:function =) (:function /=) (:function <) (:function >) (:function <=) (:function >=) (:function max) (:function min) (:function minusp) (:function plusp) (:function zerop) (:function floor) (:function ffloor) (:function ceiling) (:function fceiling) (:function truncate) (:function ftruncate) (:function round) (:function fround) (:function sin) (:function cos) (:function tan) (:function asin) (:function acos) (:function atan) (:constant-variable pi) (:function sinh) (:function cosh) (:function tanh) (:function asinh) (:function acosh) (:function atanh) (:function *) (:function +) (:function -) (:function /) (:function 1+) (:function 1-) (:function abs) (:function evenp) (:function oddp) (:function exp) (:function expt) (:function gcd) (:macro incf) (:macro decf) (:function lcm) (:function log) (:function mod) (:function rem) (:function signum) (:function sqrt) (:function isqrt) (:system-class random-state) (:function make-random-state) (:function random) (:function random-state-p) (:variable *random-state*) (:function numberp) (:function cis) (:function complex) (:function complexp) (:function conjugate) (:function phase) (:function realpart) (:function imagpart) (:function upgraded-complex-part-type) (:function realp) (:function numerator) (:function denominator) (:function rational) (:function rationalize) (:function rationalp) (:function ash) (:function integer-length) (:function integerp) (:function parse-integer) (:function boole) (:constant-variable boole-1) (:constant-variable boole-2) (:constant-variable boole-and) (:constant-variable boole-andc1) (:constant-variable boole-andc2) (:constant-variable boole-c1) (:constant-variable boole-c2) (:constant-variable boole-clr) (:constant-variable boole-eqv) (:constant-variable boole-ior) (:constant-variable boole-nand) (:constant-variable boole-nor) (:constant-variable boole-orc1) (:constant-variable boole-orc2) (:constant-variable boole-set) (:constant-variable boole-xor) (:function logand) (:function logandc1) (:function logandc2) (:function logeqv) (:function logior) (:function lognand) (:function lognor) (:function lognot) (:function logorc1) (:function logorc2) (:function logxor) (:function logbitp) (:function logcount) (:function logtest) (:function byte) (:function byte-size) (:function byte-position) (:function deposit-field) (:function dpb) (:accessor ldb) (:function ldb-test) (:accessor mask-field) (:constant-variable most-positive-fixnum) (:constant-variable most-negative-fixnum) (:function decode-float) (:function scale-float) (:function float-radix) (:function float-sign) (:function float-digits) (:function float-precision) (:function integer-decode-float) (:function float) (:function floatp) (:constant-variable most-positive-short-float) (:constant-variable least-positive-short-float) (:constant-variable least-positive-normalized-short-float) (:constant-variable most-positive-double-float) (:constant-variable least-positive-double-float) (:constant-variable least-positive-normalized-double-float) (:constant-variable most-positive-long-float) (:constant-variable least-positive-long-float) (:constant-variable least-positive-normalized-long-float) (:constant-variable most-positive-single-float) (:constant-variable least-positive-single-float) (:constant-variable least-positive-normalized-single-float) (:constant-variable most-negative-short-float) (:constant-variable least-negative-short-float) (:constant-variable least-negative-normalized-short-float) (:constant-variable most-negative-single-float) (:constant-variable least-negative-single-float) (:constant-variable least-negative-normalized-single-float) (:constant-variable most-negative-double-float) (:constant-variable least-negative-double-float) (:constant-variable least-negative-normalized-double-float) (:constant-variable most-negative-long-float) (:constant-variable least-negative-long-float) (:constant-variable least-negative-normalized-long-float) (:constant-variable short-float-epsilon) (:constant-variable short-float-negative-epsilon) (:constant-variable single-float-epsilon) (:constant-variable single-float-negative-epsilon) (:constant-variable double-float-epsilon) (:constant-variable double-float-negative-epsilon) (:constant-variable long-float-epsilon) (:constant-variable long-float-negative-epsilon) (:condition-type arithmetic-error) (:function arithmetic-error-operands) (:function arithmetic-error-operation) (:condition-type division-by-zero) (:condition-type floating-point-invalid-operation) (:condition-type floating-point-inexact) (:condition-type floating-point-overflow) (:condition-type floating-point-underflow)) ((13 "Characters") (:system-class character) (:type base-char) (:type standard-char) (:type extended-char) (:function char=) (:function char/=) (:function char<) (:function char>) (:function char<=) (:function char>=) (:function char-equal) (:function char-not-equal) (:function char-lessp) (:function char-greaterp) (:function char-not-greaterp) (:function char-not-lessp) (:function character) (:function characterp) (:function alpha-char-p) (:function alphanumericp) (:function digit-char) (:function digit-char-p) (:function graphic-char-p) (:function standard-char-p) (:function char-upcase) (:function char-downcase) (:function upper-case-p) (:function lower-case-p) (:function both-case-p) (:function char-code) (:function char-int) (:function code-char) (:constant-variable char-code-limit) (:function char-name) (:function name-char)) ((14 "Conses") (:system-class list) (:system-class null) (:system-class cons) (:type atom) (:function cons) (:function consp) (:function atom) (:function rplaca) (:function rplacd) (:accessor car) (:accessor cdr) (:accessor caar) (:accessor cadr) (:accessor cdar) (:accessor cddr) (:accessor caaar) (:accessor caadr) (:accessor cadar) (:accessor caddr) (:accessor cdaar) (:accessor cdadr) (:accessor cddar) (:accessor cdddr) (:accessor caaaar) (:accessor caaadr) (:accessor caadar) (:accessor caaddr) (:accessor cadaar) (:accessor cadadr) (:accessor caddar) (:accessor cadddr) (:accessor cdaaar) (:accessor cdaadr) (:accessor cdadar) (:accessor cdaddr) (:accessor cddaar) (:accessor cddadr) (:accessor cdddar) (:accessor cddddr) (:function copy-tree) (:function sublis) (:function nsublis) (:function subst) (:function subst-if) (:function subst-if-not) (:function nsubst) (:function nsubst-if) (:function nsubst-if-not) (:function tree-equal) (:function copy-list) (:function list) (:function list*) (:function list-length) (:function listp) (:function make-list) (:macro push) (:macro pop) (:accessor first) (:accessor second) (:accessor third) (:accessor fourth) (:accessor fifth) (:accessor sixth) (:accessor seventh) (:accessor eighth) (:accessor ninth) (:accessor tenth) (:accessor nth) (:function endp) (:function null) (:function nconc) (:function append) (:function revappend) (:function nreconc) (:function butlast) (:function nbutlast) (:function last) (:function ldiff) (:function tailp) (:function nthcdr) (:accessor rest) (:function member) (:function member-if) (:function member-if-not) (:function mapc) (:function mapcar) (:function mapcan) (:function mapl) (:function maplist) (:function mapcon) (:function acons) (:function assoc) (:function assoc-if) (:function assoc-if-not) (:function copy-alist) (:function pairlis) (:function rassoc) (:function rassoc-if) (:function rassoc-if-not) (:function get-properties) (:accessor getf) (:macro remf) (:function intersection) (:function nintersection) (:function adjoin) (:macro pushnew) (:function set-difference) (:function nset-difference) (:function set-exclusive-or) (:function nset-exclusive-or) (:function subsetp) (:function union) (:function nunion)) ((15 "Arrays") (:system-class array) (:type simple-array) (:system-class vector) (:type simple-vector) (:system-class bit-vector) (:type simple-bit-vector) (:function make-array) (:function adjust-array) (:function adjustable-array-p) (:accessor aref) (:function array-dimension) (:function array-dimensions) (:function array-element-type) (:function array-has-fill-pointer-p) (:function array-displacement) (:function array-in-bounds-p) (:function array-rank) (:function array-row-major-index) (:function array-total-size) (:function arrayp) (:accessor fill-pointer) (:accessor row-major-aref) (:function upgraded-array-element-type) (:constant-variable array-dimension-limit) (:constant-variable array-rank-limit) (:constant-variable array-total-size-limit) (:function simple-vector-p) (:accessor svref) (:function vector) (:function vector-pop) (:function vector-push) (:function vector-push-extend) (:function vectorp) (:accessor bit) (:accessor sbit) (:function bit-and) (:function bit-andc1) (:function bit-andc2) (:function bit-eqv) (:function bit-ior) (:function bit-nand) (:function bit-nor) (:function bit-not) (:function bit-orc1) (:function bit-orc2) (:function bit-xor) (:function bit-vector-p) (:function simple-bit-vector-p)) ((16 "Strings") (:system-class string) (:type base-string) (:type simple-string) (:type simple-base-string) (:function simple-string-p) (:accessor char) (:accessor schar) (:function string) (:function string-upcase) (:function string-downcase) (:function string-capitalize) (:function nstring-upcase) (:function nstring-downcase) (:function nstring-capitalize) (:function string-trim) (:function string-left-trim) (:function string-right-trim) (:function string=) (:function string/=) (:function string<) (:function string>) (:function string<=) (:function string>=) (:function string-equal) (:function string-not-equal) (:function string-lessp) (:function string-greaterp) (:function string-not-greaterp) (:function string-not-lessp) (:function stringp) (:function make-string)) ((17 "Sequences") (:system-class sequence) (:function copy-seq) (:accessor elt) (:function fill) (:function make-sequence) (:accessor subseq) (:function map) (:function map-into) (:function reduce) (:function count) (:function count-if) (:function count-if-not) (:function length) (:function reverse) (:function nreverse) (:function sort) (:function stable-sort) (:function find) (:function find-if) (:function find-if-not) (:function position) (:function position-if) (:function position-if-not) (:function search) (:function mismatch) (:function replace) (:function substitute) (:function substitute-if) (:function substitute-if-not) (:function nsubstitute) (:function nsubstitute-if) (:function nsubstitute-if-not) (:function concatenate) (:function merge) (:function remove) (:function remove-if) (:function remove-if-not) (:function delete) (:function delete-if) (:function delete-if-not) (:function remove-duplicates) (:function delete-duplicates)) ((18 "Hash Tables") (:system-class hash-table) (:function make-hash-table) (:function hash-table-p) (:function hash-table-count) (:function hash-table-rehash-size) (:function hash-table-rehash-threshold) (:function hash-table-size) (:function hash-table-test) (:accessor gethash) (:function remhash) (:function maphash) (:macro with-hash-table-iterator) (:function clrhash) (:function sxhash)) ((19 "Filenames") (:system-class pathname) (:system-class logical-pathname) (:function pathname) (:function make-pathname) (:function pathnamep) (:function pathname-host) (:function pathname-device) (:function pathname-directory) (:function pathname-name) (:function pathname-type) (:function pathname-version) (:function load-logical-pathname-translations) (:accessor logical-pathname-translations) (:function logical-pathname) (:variable *default-pathname-defaults*) (:function namestring) (:function file-namestring) (:function directory-namestring) (:function host-namestring) (:function enough-namestring) (:function parse-namestring) (:function wild-pathname-p) (:function pathname-match-p) (:function translate-logical-pathname) (:function translate-pathname) (:function merge-pathnames)) ((20 "Files") (:function directory) (:function probe-file) (:function ensure-directories-exist) (:function truename) (:function file-author) (:function file-write-date) (:function rename-file) (:function delete-file) (:condition-type file-error) (:function file-error-pathname)) ((21 "Streams") (:system-class stream) (:system-class broadcast-stream) (:system-class concatenated-stream) (:system-class echo-stream) (:system-class file-stream) (:system-class string-stream) (:system-class synonym-stream) (:system-class two-way-stream) (:function input-stream-p) (:function output-stream-p) (:function interactive-stream-p) (:function open-stream-p) (:function stream-element-type) (:function streamp) (:function read-byte) (:function write-byte) (:function peek-char) (:function read-char) (:function read-char-no-hang) (:function terpri) (:function fresh-line) (:function unread-char) (:function write-char) (:function read-line) (:function write-string) (:function write-line) (:function read-sequence) (:function write-sequence) (:function file-length) (:function file-position) (:function file-string-length) (:function open) (:function stream-external-format) (:macro with-open-file) (:function close) (:macro with-open-stream) (:function listen) (:function clear-input) (:function finish-output) (:function force-output) (:function clear-output) (:function y-or-n-p) (:function yes-or-no-p) (:function make-synonym-stream) (:function synonym-stream-symbol) (:function broadcast-stream-streams) (:function make-broadcast-stream) (:function make-two-way-stream) (:function two-way-stream-input-stream) (:function two-way-stream-output-stream) (:function echo-stream-input-stream) (:function echo-stream-output-stream) (:function make-echo-stream) (:function concatenated-stream-streams) (:function make-concatenated-stream) (:function get-output-stream-string) (:function make-string-input-stream) (:function make-string-output-stream) (:macro with-input-from-string) (:macro with-output-to-string) (:variable *debug-io*) (:variable *error-output*) (:variable *query-io*) (:variable *standard-input*) (:variable *standard-output*) (:variable *trace-output*) (:variable *terminal-io*) (:condition-type stream-error) (:function stream-error-stream) (:condition-type end-of-file)) ((22 "Printer") (:function copy-pprint-dispatch) (:macro formatter) (:function pprint-dispatch) (:local-macro pprint-exit-if-list-exhausted) (:function pprint-fill) (:function pprint-linear) (:function pprint-tabular) (:function pprint-indent) (:macro pprint-logical-block) (:function pprint-newline) (:local-macro pprint-pop) (:function pprint-tab) (:standard-generic-function print-object) (:macro print-unreadable-object) (:function set-pprint-dispatch) (:function write) (:function prin1) (:function print) (:function pprint) (:function princ) (:function write-to-string) (:function prin1-to-string) (:function princ-to-string) (:variable *print-array*) (:variable *print-base*) (:variable *print-radix*) (:variable *print-case*) (:variable *print-circle*) (:variable *print-escape*) (:variable *print-gensym*) (:variable *print-level*) (:variable *print-length*) (:variable *print-lines*) (:variable *print-miser-width*) (:variable *print-pprint-dispatch*) (:variable *print-pretty*) (:variable *print-readably*) (:variable *print-right-margin*) (:condition-type print-not-readable) (:function print-not-readable-object) (:function format)) ((23 "Reader") (:system-class readtable) (:function copy-readtable) (:function make-dispatch-macro-character) (:function read) (:function read-preserving-whitespace) (:function read-delimited-list) (:function read-from-string) (:accessor readtable-case) (:function readtablep) (:function set-dispatch-macro-character) (:function get-dispatch-macro-character) (:function set-macro-character) (:function get-macro-character) (:function set-syntax-from-char) (:macro with-standard-io-syntax) (:variable *read-base*) (:variable *read-default-float-format*) (:variable *read-eval*) (:variable *read-suppress*) (:variable *readtable*) (:condition-type reader-error)) ((24 "System Construction") (:function compile-file) (:function compile-file-pathname) (:function load) (:macro with-compilation-unit) (:variable *features*) (:variable *compile-file-pathname*) (:variable *compile-file-truename*) (:variable *load-pathname*) (:variable *load-truename*) (:variable *compile-print*) (:variable *compile-verbose*) (:variable *load-print*) (:variable *load-verbose*) (:variable *modules*) (:function provide) (:function require)) ((25 "Environment") (:function decode-universal-time) (:function encode-universal-time) (:function get-universal-time) (:function get-decoded-time) (:function sleep) (:function apropos) (:function apropos-list) (:function describe) (:standard-generic-function describe-object) (:macro trace) (:macro untrace) (:macro step) (:macro time) (:constant-variable internal-time-units-per-second) (:function get-internal-real-time) (:function get-internal-run-time) (:function disassemble) (:standard-generic-function documentation) (:standard-generic-function (setf documentation)) (:function room) (:function ed) (:function inspect) (:function dribble) (:variable -) (:variable +) (:variable ++) (:variable +++) (:variable *) (:variable **) (:variable ***) (:variable /) (:variable //) (:variable ///) (:function lisp-implementation-type) (:function lisp-implementation-version) (:function short-site-name) (:function long-site-name) (:function machine-instance) (:function machine-type) (:function machine-version) (:function software-type) (:function software-version) (:function user-homedir-pathname))))
31,224
Common Lisp
.lisp
1,020
24.641176
70
0.650278
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
00f8d3e105ae33eba1bf9e99176cbb040c68a9c9344eb073259b118d8501657a
4,974
[ -1 ]
4,975
com.informatimago.common-lisp.lisp.stepper.asd
informatimago_lisp/common-lisp/lisp/com.informatimago.common-lisp.lisp.stepper.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.lisp.stepper.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.lisp.stepper library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.lisp.stepper" ;; system attributes: :description "Informatimago Common Lisp Stepper." :long-description " This system implements a portable stepper. " :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Summer 2012") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.lisp.stepper/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.lisp-sexp") :components ((:file "stepper-packages") (:file "stepper-functions" :depends-on ("stepper-packages")) (:file "stepper" :depends-on ("stepper-packages" "stepper-functions"))) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.lisp.stepper.test")))) ;;;; THE END ;;;;
2,889
Common Lisp
.lisp
60
43.483333
116
0.585487
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
4b37cc7f5b23b324373215db82f44f20f34bcf6d4040b4c11eedbb83be562217
4,975
[ -1 ]
4,976
ibcl-bootstrap.lisp
informatimago_lisp/common-lisp/lisp/ibcl-bootstrap.lisp
;;;;************************************************************************** ;;;;FILE: ibcl-bootstrap.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This script generates an executable saved image environment using ;;;; IMAGE-BASED-COMMON-LISP instead of COMMON-LISP. ;;;; ;;;; IBCL Bootstrap ;;;; ;;;; To create the executable image: ;;;; ;;;; clisp -ansi -norc -i ibcl-bootstrap.lisp -p "IBCL" ;;;; sbcl --userinit /dev/null --load ibcl-bootstrap.lisp ;;;; ;;;; Then, to launch it, use: ;;;; ;;;; ./ibcl ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2006-07-01 <PJB> Added support to SBCL. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2006 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COMMON-LISP-USER") (load (merge-pathnames #p"ibcl.lisp" *load-pathname*)) (in-package "COMMON-LISP") (rename-package (find-package "COMMON-LISP-USER") "OLD-CL-USER") (defpackage "COMMON-LISP-USER" (:nicknames "CL-USER") (:use "IBCL")) (in-package "IMAGE-BASED-COMMON-LISP-USER") #+sbcl (require :sb-posix) (cl:defun save-image (&rest args) #+clisp (labels ((key-present-p (key plist) (and (not (null plist)) (or (eq key (car plist)) (key-present-p key (cddr plist)))))) (let* ((keys (rest args))) (unless (key-present-p :start-package keys) (setf (getf keys :start-package) (find-package "IBCL-USER"))) (unless (key-present-p :norc keys) (setf (getf keys :norc) t)) (apply (function ext:saveinitmem) (first args) keys))) #+sbcl (when (zerop (sb-posix:fork)) (apply (function sb-ext:save-lisp-and-die) args)) #-(or clisp sbcl) (error "I don't know how to save an image in ~A" (lisp-implementation-type)) (values)) #+clisp (ext:saveinitmem "ibcl" :executable t) #+sbcl (sb-ext:save-lisp-and-die "ibcl" :executable t :toplevel (lambda () (setf *package* (find-package "COMMON-LISP-USER")) (delete-package (find-package "OLD-CL-USER")) (sb-posix:putenv (format nil "SBCL_HOME=~A" (namestring (user-homedir-pathname)))) (sb-impl::toplevel-repl nil) (sb-ext:quit 0))) #-(or clisp sbcl) (error "How do we save an image in ~A" (lisp-implementation-type)) #+clisp (ext:quit) #+sbcl (sb-ext:quit) #-(or clisp sbcl) (error "How do we quit from ~A" (lisp-implementation-type))
3,636
Common Lisp
.lisp
90
35.5
83
0.57865
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
f45f94599de0961c4c984921612cabfa764d5efd194624038803ff625991b05d
4,976
[ -1 ]
4,977
com.informatimago.common-lisp.lisp.ibcl.test.asd
informatimago_lisp/common-lisp/lisp/com.informatimago.common-lisp.lisp.ibcl.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.lisp.ibcl.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.lisp.ibcl.test system. ;;;; Tests the com.informatimago.common-lisp.lisp.ibcl system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.lisp.ibcl.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.lisp.ibcl system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.lisp.ibcl.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.lisp.ibcl") :components ((:file "source-test" :depends-on nil)) #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) (let ((*package* (find-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE.TEST"))) (uiop:symbol-call "COM.INFORMATIMAGO.COMMON-LISP.LISP.SOURCE.TEST" "TEST/ALL")))) ;;;; THE END ;;;;
3,053
Common Lisp
.lisp
66
39.969697
110
0.564824
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
53dc50b9b3596bd52f52314262617917c88a4bd0385ff53109f739d7a251881d
4,977
[ -1 ]
4,978
relative-package-test.lisp
informatimago_lisp/common-lisp/lisp/relative-package-test.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: relative-package-test.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Tests the relative-package. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-11-02 <PJB> Adapted from http://franz.com/support/documentation/8.1/doc/packages.htm#relative-2 ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.SIMPLE-TEST" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE") (:shadowing-import-from "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE" . #1=("FIND-PACKAGE" "MAKE-PACKAGE" "DELETE-PACKAGE" "FIND-SYMBOL" "IMPORT" "INTERN" "SHADOW" "SHADOWING-IMPORT" "EXPORT" "UNEXPORT" "UNINTERN" "USE-PACKAGE" "UNUSE-PACKAGE" "PACKAGE-NAME" "PACKAGE-NICKNAMES" "PACKAGE-USE-LIST" "PACKAGE-USED-BY-LIST" "PACKAGE-SHADOWING-SYMBOLS" "RENAME-PACKAGE" "WITH-PACKAGE-ITERATOR" "DO-SYMBOLS" "DO-EXTERNAL-SYMBOLS" "DEFPACKAGE" "IN-PACKAGE")) (:import-from "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE" "SYMBOL-FROM-SPLIT-TOKEN") (:import-from "COM.INFORMATIMAGO.COMMON-LISP.LISP-READER.READER" "SYMBOL-IN-MISSING-PACKAGE-ERROR" "SYMBOL-MISSING-IN-PACKAGE-ERROR" "UNEXPORTED-SYMBOL-ERROR")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST") ;; There should be no package named ;; :com.informatimago.common-lisp.lisp.relative-package.test.none ;; so that an error is signaled when we try to access it. (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d.e) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d.f) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.e) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.f) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.d) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.e) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.c) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.d) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.b) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.c) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test.d) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test-foo.bar.baz) (defpackage :com.informatimago.common-lisp.lisp.relative-package.test.none.test-foo.bar.baz.wham) (define-test test/package-children () (let ((*disable-useless-parent-package-check* nil)) (check equal (sort (mapcar #'package-name (package-children :com.informatimago.common-lisp.lisp.relative-package.test.none.test :recurse nil)) #'string<) '("COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.B" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.C" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.D")) (check equal (sort (mapcar #'package-name (package-children :com.informatimago.common-lisp.lisp.relative-package.test.none.test)) #'string<) '("COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.D" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.D.E" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.D.F" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.E" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.F" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.D" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.E" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.C" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.D" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.B" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.C" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.D")) (check equal (sort (mapcar #'package-name (package-children :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c)) #'string<) '("COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.D" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.D.E" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.D.F" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.E" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.F")) (check equal (sort (mapcar #'package-name (package-children :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c :recurse nil)) #'string<) '("COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.D" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.E" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.F")) (check equal (sort (mapcar #'package-name (package-children :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d)) #'string<) '("COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.D.E" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.D.F")) (check equal (sort (mapcar #'package-name (package-children :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d :recurse nil)) #'string<) '("COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.D.E" "COM.INFORMATIMAGO.COMMON-LISP.LISP.RELATIVE-PACKAGE.TEST.NONE.TEST.A.B.C.D.F")) (check equal (package-children :com.informatimago.common-lisp.lisp.relative-package.test.none.test.b) '()) (check equal (package-children :com.informatimago.common-lisp.lisp.relative-package.test.none.test.c) '()) (check equal (package-children :com.informatimago.common-lisp.lisp.relative-package.test.none.test.d) '()))) (define-test test/package-parent () (let ((*disable-useless-parent-package-check* nil)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d.e) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d.f) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.e) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.f) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.d) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.e) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.c) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.d) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.b) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.c) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test)) (check eql (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test.d) (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test)) (expect-condition 'error (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test)) (expect-condition 'error (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test-foo.bar.baz)) (expect-condition 'error (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test-foo.bar)) (expect-condition 'error (package-parent :com.informatimago.common-lisp.lisp.relative-package.test.none.test-foo)))) (define-test test/find-package () (let ((*disable-useless-parent-package-check* nil)) (dolist (item '((:com.informatimago.common-lisp.lisp.relative-package.test.none.test.a :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a ".") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a "..") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test.b :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a "..B") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test.c :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a "..C") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test.d :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a "..D") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b :com.informatimago.common-lisp.lisp.relative-package.test.none.test.b "..A.B") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b "...") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test.b :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b "...B") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d.f :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d "...C.D.F") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d ".....") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test.b :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d ".....B") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c.d ".") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b.c ".") (:com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b :com.informatimago.common-lisp.lisp.relative-package.test.none.test.a.b "."))) (check string= (let ((*package* (find-package (second item))) ) (package-name (find-package (third item)))) (symbol-name (first item)) ((second item) (third item)))) (let ((*package* (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test))) (expect-condition 'error (find-package "..")) (expect-condition 'error (find-package "...")) (expect-condition 'error (find-package "....")) (expect-condition 'error (find-package "....FOO"))) (let ((*package* (find-package :com.informatimago.common-lisp.lisp.relative-package.test.none.test.b))) (expect-condition 'error (find-package "..."))))) (define-test test/symbol-from-split-token () (expect-condition 'error (symbol-from-split-token '())) (expect-condition 'error (symbol-from-split-token '(1))) (expect-condition 'error (symbol-from-split-token '(2))) (expect-condition 'error (symbol-from-split-token '("FROOS" 2 "PPO" 2))) (expect-condition 'error (symbol-from-split-token '(3 "PPO"))) (expect-condition 'symbol-in-missing-package-error (symbol-from-split-token '("FROOS" 1 "PPO"))) (expect-condition 'symbol-in-missing-package-error (symbol-from-split-token '("FROOS" 2 "PPO"))) (check eq :foo (symbol-from-split-token '(1 "FOO"))) (expect-condition 'unexported-symbol-error (symbol-from-split-token '("CL-USER" 1 "KAZOO"))) (check eq 'cl-user::kazoo (symbol-from-split-token '("CL-USER" 2 "KAZOO"))) (check eq 'cl:sin (symbol-from-split-token '("CL" 1 "SIN"))) (check eq 'cl:sin (symbol-from-split-token '("CL" 2 "SIN")))) (define-test test/all () (test/package-children) (test/package-parent) (test/find-package) (test/symbol-from-split-token)) ;;;; THE END ;;;;
17,468
Common Lisp
.lisp
256
58.335938
135
0.668856
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
7ac3777a3ddd3edb693ab8d54f0a18f2a64d51787b6a2857fbc5572bd9b910d5
4,978
[ -1 ]
4,979
com.informatimago.common-lisp.data.asd
informatimago_lisp/common-lisp/data/com.informatimago.common-lisp.data.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.data.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.data library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-09-05 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.data" ;; system attributes: :description "Informatimago Common Lisp DATA File Format" :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Summer 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.data/") ((#:albert #:formats) . ("docbook")) ((#:albert #:docbook #:template) . "book") ((#:albert #:docbook #:bgcolor) . "white") ((#:albert #:docbook #:textcolor) . "black")) :depends-on () :components ((:file "constants" :depends-on ())) ;; #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.data.test"))) #+asdf-unicode :encoding #+asdf-unicode :utf-8) ;;;; THE END ;;;;
2,477
Common Lisp
.lisp
53
43.54717
108
0.584641
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
63906887ef6174549576ef77f0362a46b4ce0e687fe1b2cb3991d3a75e40cbe5
4,979
[ -1 ]
4,980
constants.lisp
informatimago_lisp/common-lisp/data/constants.lisp
;;;; -*- mode:common-lisp;coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: constantes.lisp ;;;;LANGUAGE: Common Lisp ;;;;SYSTEM: POSIX ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Defines constants of physics. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-08-03 <PJB> Converted to Common Lisp from emacs lisp. ;;;; 2003-12-04 <PJB> Added this header. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal Bourguignon 2003 - 2016 ;;;; ;;;; 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/>. ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.DATA.CONSTANT" (:use "COMMON-LISP") (:export "DEF-PHYS-CONST" "PHYSICAL-CONSTANT-P" "UNIT" "N" "H_0" "V_0" "T_0" "N_0" "R" "G" "E" "C" "K" "H" "M_P" "M_N" "M_E" "MU_0" "EPSILON_0" "G_N" "SUN-MASS" "SUN-EQUATORIAL-RADIUS" "SUN-LUMINOSITY" "SUN-MEAN-SURFACE-TEMPERATURE" "EARTH-MASS" "EARTH-VOLUME" "EARTH-RADIUS-EQUATORIAL" "EARTH-RADIUS-POLAR" "EARTH-RADIUS-MEAN" "EARTH-CORE-RADIUS" "EARTH-ELLIPTICITY" "EARTH-DENSITY" "EARTH-GM" "EARTH-ALBEDO-BOND" "EARTH-ALBEDO-VISUAL-GEOMETRIC" "EARTH-VISUAL-MAGNITUDE" "EARTH-PERIHELION" "EARTH-APHELION" "EARTH-MASS" "EARTH-VOLUME" "EARTH-EQUATORIAL-RADIUS" "EARTH-POLAR-RADIUS" "EARTH-VOLUMETRIC-MEAN-RADIUS" "EARTH-CORE-RADIUS" "EARTH-ELLIPTICITY" "EARTH-MEAN-DENSITY" "EARTH-SURFACE-GRAVITY" "EARTH-ESCAPE-VELOCITY" "EARTH-GM" "EARTH-BOND-ALBEDO" "EARTH-VISUAL-GEOMETRIC-ALBEDO" "EARTH-ALBEDO-VISUAL-MAGNITUDE" "EARTH-SOLAR-IRRADIANCE" "EARTH-BLACK-BODY-TEMPERATURE" "EARTH-MOMENT-OF-INERTIA" "EARTH-J2" "EARTH-TOPOGRAPHIC-RANGE" "EARTH-SEMIMAJOR-AXIS" "EARTH-SIDEREAL-ORBIT-PERIOD" "EARTH-TROPICAL-ORBIT-PERIOD" "EARTH-PERICENTER" "EARTH-APOCENTER" "EARTH-MEAN-ORBITAL-VELOCITY" "EARTH-MAXIMUM-ORBITAL-VELOCITY" "EARTH-MINIMUM-ORBITAL-VELOCITY" "EARTH-SIDEREAL-ROTATION-PERIOD" "EARTH-LENGTH-OF-DAY" "EARTH-OBLIQUITY-TO-ORBIT" "EARTH-ORBITAL-ECCENTRICITY" "EARTH-ORBITAL-INCLINATION" "EARTH-LONGITUDE-OF-ASCENDING-NODE" "EARTH-LONGITUDE-OF-PERICENTER" "EARTH-MEAN-LONGITUDE" "EARTH-DIPOLE-FIELD-STRENGTH" "EARTH-LATITUDE-OF-DIPOLE-NORTH" "EARTH-LONGITUDE-OF-DIPOLE-NORTH" "EARTH-DIPOLE-OFFSET-DISTANCE" "EARTH-LATITUDE-OF-OFFSET-VECTOR" "EARTH-LONGITUDE-OF-OFFSET-VECTOR" "RE" "EARTH-SURFACE-PRESSURE" "EARTH-SURFACE-DENSITY" "EARTH-SCALE-HEIGHT" "EARTH-AVERAGE-TEMPERATURE" "EARTH-DIURNAL-TEMPERATURE-MINIMUM" "EARTH-DIURNAL-TEMPERATURE-MAXIMUM" "EARTH-SURFACE-WIND-SPEEDS-MINIMUM" "EARTH-SURFACE-WIND-SPEEDS-MAXIMUM" "EARTH-MEAN-MOLECULAR-WEIGHT" "EARTH-NITROGEN-N2" "EARTH-OXYGEN-O2" "EARTH-WATER-H2O" "EARTH-ARGON-AR" "EARTH-CARBON" "EARTH-NEON-NE" "EARTH-HELIUM-HE" "EARTH-CH4" "EARTH-KRYPTON-KR" "EARTH-HYDROGEN-H2" "MOON-MASS" "MOON-VOLUME" "MOON-RADIUS-EQUATORIAL" "MOON-POLAR-RADIUS" "MOON-VOLUMETRIC-MEAN-RADIUS" "MOON-ELLIPTICITY" "MOON-DENSITY" "MOON-SURFACE-GRAVITY" "MOON-ESCAPE-VELOCITY" "MOON-GM" "MOON-ALBEDO-BIND" "MOON-ALBEDO-VISUAL-GEOMETRIC" "MOON-ALBEDO-VISUAL-MAGNITUDE" "MOON-SOLAR-IRRADIANCE" "MOON-BLACK-BODY-TEMPERATURE" "MOON-MOMENT-OF-INERTIA" "MOON-TOPOGRAPHIC-RANGE" "MOON-SEMIMAJOR-AXIS" "MOON-PERICENTER" "MOON-APOCENTER" "MOON-REVOLUTION-PERIOD" "MOON-SYNODIC-PERIOD" "MOON-MEAN-ORBITAL-VELOCITY" "MOON-ORBITAL-INCLINATION" "MOON-ORBITAL-EXCENTRICITY" "MOON-SIDEREAL-ROTATION-PERIOD" "MOON-EQUATORIAL-INCLINATION" "MOON-RECESSION-RATE-FROM-EARTH" "MARS-APHELION" "MARS-ARGON-AR" "MARS-AVERAGE-TEMPERATURE" "MARS-BLACK-BODY-TEMPERATURE" "MARS-BOND-ALBEDO" "MARS-CARBON-DIOXIDE-CO2" "MARS-CARBON-MONOXIDE-CO" "MARS-CORE-RADIUS" "MARS-ELLIPTICITY" "MARS-EQUATORIAL-RADIUS" "MARS-ESCAPE-VELOCITY" "MARS-GM" "MARS-KRYPTON-KR" "MARS-MASS" "MARS-MEAN-DENSITY" "MARS-MEAN-MOLECULAR-WEIGHT" "MARS-MEAN-ORBITAL-VELOCITY" "MARS-MOMENT-OF-INERTIA" "MARS-NEON-NE" "MARS-NITROGEN-N2" "MARS-OBLIQUITY-TO-ORBIT" "MARS-ORBITAL-ECCENTRICITY" "MARS-ORBITAL-INCLINATION" "MARS-OXYGEN-O2" "MARS-PERIHELION" "MARS-POLAR-RADIUS" "MARS-SCALE-HEIGHT" "MARS-SEMIMAJOR-AXIS" "MARS-SIDEREAL-ORBIT-PERIOD" "MARS-SIDEREAL-ROTATION-PERIOD" "MARS-SOLAR-IRRADIANCE" "MARS-SURFACE-DENSITY" "MARS-SURFACE-GRAVITY" "MARS-SURFACE-PRESSURE" "MARS-SURFACE-WIND-SPEEDS-RANGE-AUTUMN" "MARS-SURFACE-WIND-SPEEDS-RANGE-DUST-STORM" "MARS-SURFACE-WIND-SPEEDS-RANGE-SUMMER" "MARS-SYNODIC-PERIOD" "MARS-TOPOGRAPHIC-RANGE" "MARS-TROPICAL-ORBIT-PERIOD" "MARS-VISUAL-GEOMETRIC-ALBEDO" "MARS-VOLUME" "MARS-VOLUMETRIC-MEAN-RADIUS" "MARS-WATER-H2O" "MARS-APPARENT-MAGNITUDE-NEAR-OPPOSITION" "MARS-DIURNAL-TEMPERATUNRE-MINIMUM" "MARS-HEAVY-WATER-HDO" "MARS-APPARENT-DIAMETER-FROM-EARTH-MAXIMUM" "MARS-DISTANCE-FROM-EARTH-MAXIMUM" "MARS-APPARENT-DIAMETER-FROM-EARTH-MINIMUM" "MARS-DISTANCE-FROM-EARTH-MINIMUM" "MARS-NITROGEN-OXIDE-NO" "MARS-VISUAL-MAGNITUDE" "MARS-XENON-XE" "YEAR" "LIGHT-YEAR" "SQUARE" "LORENTZ" "LORENTZ" ;; units: "CM" "YEAR" "F" "E" "ARC-SECOND" "G" "W" "MBAR" "H" "MBARS" "°" "I" "MR" "%" "KG" "C" "S" "DAY" "N" "GAUSS" "KM" "M" "RE" "J" "K" "^" "MOL" "PPM")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.DATA.CONSTANT") #-(and) (let ((us)) (do-external-symbols (s "COM.INFORMATIMAGO.COMMON-LISP.DATA.CONSTANT" (mapcar 'string (remove-duplicates us))) (let ((u (ignore-errors (unit s)))) (com.informatimago.common-lisp.cesarum.list:appendf us (com.informatimago.common-lisp.cesarum.list:flatten u))))) ;; http://lx50.fmridc.org/dmt/units_j.dat (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *constantes* '() "List of constantes definies par def-phys-const.")) (defmacro def-phys-const (name value unit &optional doc-string) (pushnew name *constantes*) `(progn (pushnew ',name *constantes*) (defparameter ,name ,value ,@(when doc-string (list doc-string))) (setf (get ',name 'physical-constant) t (get ',name 'unit) ',unit) ',name)) (defun physical-constant-p (name) (get name 'physical-constant)) (defun unit (name) (if (physical-constant-p name) (get name 'unit) (error "~S is not a physical constant registered to package ~S" name "COM.INFORMATIMAGO.COMMON-LISP.DATA.CONSTANT"))) ;; (get 'c 'unit) (def-phys-const N 6.022098e23 (^ mol -1) "Avogadro's number") ;;N (def-phys-const H_0 1.01325e5 (* kg (^ m -1) (^ s -2)) "pression atmosphérique normale") ;;H_0 (def-phys-const V_0 22.414e-3 (* (^ m 3) (^ mol -1)) "volume molaire du gaz parfait (CN)") ;;V_0 (def-phys-const T_0 273.15 K "zéro de l'échelle Celsius") ;;T_0 (def-phys-const n_0 (/ N V_0) (^ m -3) "Loschmidt's number") ;;n_0 (def-phys-const R 8.3143 (* J (^ K -1) (^ mol -1)) "constante des gaz parfaits") ;;R (def-phys-const G 6.672e-11 (* (^ kg -1) (^ m 3) (^ s -2)) "constante de la gravitation") ;;G (def-phys-const e 1.602189e-19 C "charge élémentaire") ;;e (def-phys-const c 299792458.0 (* m (^ s -1)) "célérité de la lumière") ;;c (def-phys-const k 1.38066e-23 (* J (^ K -1)) "Boltzmann's constant") ;;k (def-phys-const h 6.626176e-34 (* J s) "Planck's constant") ;;h (def-phys-const m_p 1.67265e-27 kg "Mass of proton") ;;m_p (def-phys-const m_n 1.67496e-27 kg "Mass of neutron") ;;m_n (def-phys-const m_e 9.10953e-31 kg "Mass of electron") ;;m_e (def-phys-const mu_0 (* 16e-7 (atan 1)) (* H (^ m -1)) "perméabilité du vide") ;;mu_0 (def-phys-const epsilon_0 (/ 1 (* mu_0 c c)) (* F (^ m -1)) "permittivité du vide") ;;epsilon_0 (def-phys-const g_n 9.80665 (* m (^ s -2)) "pesanteur normale") ;;g_n ;;---------------------------------------------------------------------- ;; Solar System ;;---------------------------------------------------------------------- ;; Sun (def-phys-const sun-mass 1.989e+30 kg "Mass of Sun") ;;sun-mass (def-phys-const sun-equatorial-radius 695e6 m "Equatorial Radius of Sun") (def-phys-const sun-luminosity 3.827e26 (* j (^ s -1))) (def-phys-const sun-mean-surface-temperature 6274 K) ;; Earth (def-phys-const earth-mass 5.9736e24 kg "Mass of Earth") ;;earth-mass (def-phys-const earth-volume 108.321e19 (^ m 3) "Volume of Earth") ;;earth-volume (def-phys-const earth-radius-equatorial 6378.1e3 m "Equatorial radius of Earth") ;;earth-radius-equatorial (def-phys-const earth-radius-polar 6356.8e3 m "Polar radius of Earth") ;;earth-radius-polar (def-phys-const earth-radius-mean 6371.0e3 m "Volumetric Mean Radius of Earth") ;;earth-radius-mean (def-phys-const earth-core-radius 3485e3 m "Radius of core of Earth") ;;earth-core-radius (def-phys-const earth-ellipticity 0.00335 1 "Ellipticity of Earth") ;;earth-ellipticity (def-phys-const earth-density 5515 (* kg (^ m -3)) "Ellipticity of Earth") ;;earth-density (def-phys-const earth-GM .3986e15 (* (^ m 3) (^ s -2)) "G × Mass of Earth") ;;earth-GM (def-phys-const earth-albedo-bond 0.306 1 "Bond Albedo of Earth") ;;earth-albedo-bond (def-phys-const earth-albedo-visual-geometric 0.367 1 "Visual Geometric Albedo of Earth") ;;earth-albedo-visual-geometric (def-phys-const earth-visual-magnitude -3.86 1 "Visual Magnitude (V(1,0)) of Earth") ;;earth-visual-magnitude ;;; Solar Irradiance 1367.6 W m-2 ;;; Black-Body Temperature 254.3 K ;;; Moment of Inertia 0.3308 I MR-2 ;;; J2 1082.63 × 10-6 ;;; Topographic Range 20 km ;;;; Orbital Parameters ;;;; Semimajor Axis 149.60 × 106 km ;;;; Sidereal Orbit Period 365.256 day ;;;; Tropical Orbit Period 365.242 day (def-phys-const earth-perihelion 147.09e9 m "Perihelion of Earth") ;;earth-perihelion (def-phys-const earth-aphelion 152.10e9 m "Aphelion of Earth") ;;earth-aphelion (def-phys-const earth-mass 5.9736e24 kg) (def-phys-const earth-volume 108.321e10 (^ km 3)) (def-phys-const earth-equatorial-radius 6378.1 km) (def-phys-const earth-polar-radius 6356.8 km) (def-phys-const earth-volumetric-mean-radius 6371.0 km) (def-phys-const earth-core-radius 3485 km) (def-phys-const earth-ellipticity 0.00335 1) (def-phys-const earth-mean-density 5515 (* kg (^ m -3))) (def-phys-const earth-surface-gravity 9.78 (* m (^ s -2))) (def-phys-const earth-escape-velocity 11.186 (* km (^ s -1))) (def-phys-const earth-gm 0.3986e6 (* (^ km 3) (^ s -2))) (def-phys-const earth-bond-albedo 0.306 1) (def-phys-const earth-visual-geometric-albedo 0.367 1) (def-phys-const earth-albedo-visual-magnitude -3.86 1) (def-phys-const earth-solar-irradiance 1367.6 (* W (^ m -2))) (def-phys-const earth-black-body-temperature 254.3 K) (def-phys-const earth-moment-of-inertia 0.3308 (* I (^ MR -2))) (def-phys-const earth-j2 1082.63e-6 1) (def-phys-const earth-topographic-range 20 km) (def-phys-const earth-semimajor-axis 149.60e6 km) (def-phys-const earth-sidereal-orbit-period 365.256 day) (def-phys-const earth-tropical-orbit-period 365.242 day) (def-phys-const earth-pericenter 147.09e6 km) (def-phys-const earth-apocenter 152.10e6 km) (def-phys-const earth-mean-orbital-velocity 29.78 (* km (^ s -1))) (def-phys-const earth-maximum-orbital-velocity 30.29 (* km (^ s -1))) (def-phys-const earth-minimum-orbital-velocity 29.29 (* km (^ s -1))) (def-phys-const earth-sidereal-rotation-period (* 23.9345 60 60) s) (def-phys-const earth-length-of-day (* 24.0000 60 60) s) (def-phys-const earth-obliquity-to-orbit 23.45 1) (def-phys-const earth-orbital-eccentricity 0.01671022 1) (def-phys-const earth-orbital-inclination 0.00005 °) (def-phys-const earth-longitude-of-ascending-node -11.26064 °) (def-phys-const earth-longitude-of-pericenter 102.94719 °) (def-phys-const earth-mean-longitude 100.46435 °) (def-phys-const earth-dipole-field-strength 0.3076 (* gauss (^ Re 3))) (def-phys-const earth-latitude-of-dipole-north 78.6 N) (def-phys-const earth-longitude-of-dipole-north 70.1 W) (def-phys-const earth-dipole-offset-distance 0.0725 Re) (def-phys-const earth-latitude-of-offset-vector 18.3 N) (def-phys-const earth-longitude-of-offset-vector 147.8 E) (def-phys-const Re 6378.1 km "Earth Radii") (def-phys-const earth-surface-pressure 1014 mbar) (def-phys-const earth-surface-density 1.217 (* kg (^ m -3))) (def-phys-const earth-scale-height 8.5 km) (def-phys-const earth-average-temperature 288 K) (def-phys-const earth-diurnal-temperature-minimum 283 K) (def-phys-const earth-diurnal-temperature-maximum 293 K) (def-phys-const earth-surface-wind-speeds-minimum 0 (* m (^ s -1))) (def-phys-const earth-surface-wind-speeds-maximum 100 (* m (^ s -1))) (def-phys-const earth-mean-molecular-weight 28.97 (* g (^ mol -1))) (def-phys-const earth-nitrogen-n2 0.78084 1) (def-phys-const earth-oxygen-o2 0.20946 1) (def-phys-const earth-water-h2o 0.01 1) (def-phys-const earth-argon-ar 0.00934 1) (def-phys-const earth-carbon 0.00035 1) (def-phys-const earth-neon-ne 0.00001818 1) (def-phys-const earth-helium-he 0.00000524 1) (def-phys-const earth-ch4 0.0000017 1) (def-phys-const earth-krypton-kr 0.00000114 1) (def-phys-const earth-hydrogen-h2 0.00000055 1) (def-phys-const moon-mass 0.07349e24 kg) (def-phys-const moon-volume 2.1973e10 (^ km 3)) (def-phys-const moon-radius-equatorial 1738 km) (def-phys-const moon-polar-radius 1735 km) (def-phys-const moon-volumetric-mean-radius 1737.5 1) (def-phys-const moon-ellipticity 0.002 1) (def-phys-const moon-density 3340 (* kg (^ m -3))) (def-phys-const moon-surface-gravity 1.62 (* m (^ s -2))) (def-phys-const moon-escape-velocity 2.38 (* km (^ s -1))) (def-phys-const moon-gm 0.0049e6 (* (^ km 3) (^ s -2))) (def-phys-const moon-albedo-bind 0.067 1) (def-phys-const moon-albedo-visual-geometric 0.12 1) (def-phys-const moon-albedo-visual-magnitude +0.21 1) (def-phys-const moon-solar-irradiance 1380 (* W (^ m -2))) (def-phys-const moon-black-body-temperature 274.5 K) (def-phys-const moon-moment-of-inertia 0.394 (* I (^ MR -2))) (def-phys-const moon-topographic-range 16 km) (def-phys-const moon-semimajor-axis 0.3844e6 km) (def-phys-const moon-pericenter 0.3633e6 km) (def-phys-const moon-apocenter 0.4055e6 km) (def-phys-const moon-revolution-period 27.322 day) (def-phys-const moon-synodic-period 29.53 day) (def-phys-const moon-mean-orbital-velocity 1.023 (* km (^ s -1))) (def-phys-const moon-orbital-inclination 5.145 °) (def-phys-const moon-orbital-excentricity 0.0549 1) (def-phys-const moon-sidereal-rotation-period (* 655.728 60 60) s) (def-phys-const moon-equatorial-inclination 6.68 °) (def-phys-const moon-recession-rate-from-earth 3.8 (* cm (^ year -1))) (def-phys-const mars-aphelion 249.3e6 km) (def-phys-const mars-argon-ar 1.6 %) (def-phys-const mars-average-temperature 210 K) (def-phys-const mars-black-body-temperature 216.6 K) (def-phys-const mars-bond-albedo 0.16 1) (def-phys-const mars-carbon-dioxide-co2 95.32 %) (def-phys-const mars-carbon-monoxide-co 0.08 %) (def-phys-const mars-core-radius 1700 km) (def-phys-const mars-ellipticity 0.0065 1) (def-phys-const mars-equatorial-radius 3397 km) (def-phys-const mars-escape-velocity 5.03 (* km (^ s -1))) (def-phys-const mars-gm 0.04283e6 (* (^ km 3) (^ s -2))) (def-phys-const mars-krypton-kr 0.3 ppm) (def-phys-const mars-mass 0.6419e24 kg) (def-phys-const mars-mean-density 3933 (* kg (^ m -3))) (def-phys-const mars-mean-molecular-weight 43.34 (* g (^ mol -1))) (def-phys-const mars-mean-orbital-velocity 24.13 (* km (^ s -1))) (def-phys-const mars-moment-of-inertia 0.366 (* I (^ MR -2))) (def-phys-const mars-neon-ne 2.5 ppm) (def-phys-const mars-nitrogen-n2 2.7 %) (def-phys-const mars-obliquity-to-orbit 25.19 °) (def-phys-const mars-orbital-eccentricity 0.0934 1) (def-phys-const mars-orbital-inclination 1.85 °) (def-phys-const mars-oxygen-o2 0.13 %) (def-phys-const mars-perihelion 206.6e6 km) (def-phys-const mars-polar-radius 3375 km) (def-phys-const mars-scale-height 11.1 km) (def-phys-const mars-semimajor-axis 227.9e6 km) (def-phys-const mars-sidereal-orbit-period 686.980 day) (def-phys-const mars-sidereal-rotation-period (* 24.6229 60 60) s) (def-phys-const mars-solar-irradiance 595 (* W (^ m -2))) (def-phys-const mars-surface-density 0.020 (* kg (^ m -3))) (def-phys-const mars-surface-gravity 3.69 (* m (^ s -2))) (def-phys-const mars-surface-pressure-minimum 6.9 mbar) (def-phys-const mars-surface-pressure-maximum 9.0 mbar) (def-phys-const mars-surface-wind-speeds-range-autumn '(2 4) (* m (^ s -1))) (def-phys-const mars-surface-wind-speeds-range-dust-storm '(17 30) (* m (^ s -1))) (def-phys-const mars-surface-wind-speeds-range-summer '(5 10) (* m (^ s -1))) (def-phys-const mars-synodic-period 779.94 day) (def-phys-const mars-topographic-range 36 km) (def-phys-const mars-tropical-orbit-period 686.930 day) (def-phys-const mars-visual-geometric-albedo 0.150 1) (def-phys-const mars-volume 16.318e10 (^ km 3)) (def-phys-const mars-volumetric-mean-radius 3390 km) (def-phys-const mars-water-h2o 210 ppm) (def-phys-const mars-apparent-magnitude-near-opposition -2.0 1) (def-phys-const mars-diurnal-temperatunre-minimum 184 (* K to 242 K)) (def-phys-const mars-heavy-water-hdo 0.85 ppm) (def-phys-const mars-apparent-diameter-from-earth-maximum 25.7 arc-second) (def-phys-const mars-distance-from-earth-maximum 401.3e6 km) (def-phys-const mars-apparent-diameter-from-earth-minimum 3.5 arc-second) (def-phys-const mars-distance-from-earth-minimum 54.5e6 km) (def-phys-const mars-nitrogen-oxide-no 100 ppm) (def-phys-const mars-visual-magnitude -1.52 1) (def-phys-const mars-xenon-xe 0.08 ppm) (defparameter year (* 365 24 60 60) "Value of a year in second.") (defparameter light-year (* c year) "Value of a light-year in meter.") (defun square (x) (* x x)) (defun lorentz ( x t_ v ) " RETURN: x' ; t' ; dx' ; dt' such as gamma = sqrt( 1 - ( v / c ) ^ 2 ) x' = ( x + v t ) / gamma t' = ( t + x v / c ^ 2 ) / gamma dx' = x / gamma dt' = t / gamma " (let ((gamma (/ 1.0 (sqrt (- 1.0 (square (/ v c))))))) (values gamma (/ (- x (* v t_)) gamma) (/ (- t_ (/ (* x v) (* c c))) gamma) (/ x gamma) (/ t_ gamma)))) ;;; (setq d (* 4.3 light-year)) ;;; (setq v (* 0.90 c)) ;;; (setq t_ (/ d v)) ;;; (setq gamma (car (lorentz d t_ v))) ;; Luego, por efecto de la compresión del tiempo cuando se viaja a ;; velocidades cerca de c, la sonda no tarda tanto tiempo en llegar, y, ;; por lo contrario, la gente que se queda en la Tierra debe esparar más ;; tiempo en antes de saber que la sonda a llegado. ;; ;; Cómo se podra verificar en cualquier página web sobre el tema (para ;; decir que ¡esta clase de información esta a accesible por todo con un ;; par de clics!): ;; ;; Aplicando las transformadas de Lorentz: ;; ;; gamma = 1 / sqrt( 1 - ( v / c ) ^ 2 ) ;; x' = ( x + v t ) * gamma ;; t' = ( t + x v / c ^ 2 ) * gamma ;; ;; que dan las coordenadas (x',t') dentro de un referencial que se mueve ;; a la velocidad v con respecto a un referencial fijo, dadas la ;; coordenadas (x,t) dentro del referencial fijo, se puede deducir ;; facilmente la dilatación y la contracción de la longitud y de la ;; duración: ;; ;; l' = l / gamma ;; d' = d / gamma ;; ;; (o si se es vago, se puede tanbien buscar en el web con un par de clic ;; de más). ;; ;; ;; Así que, por ejemplo, si la sonda viaja a v/c = 0.90 or 90% de la ;; velocidad de la luz, a una distancia de 4.3 años-luz, lo hara en un ;; tiempo superior a 4.3 años (visto desde el referencial fijo, es decir, ;; desde la Tierra porque va siempre a una velocidad menor que c: ;; ;; d = 4.3 * año * c ;; v = 0.9 * c ;; t = d / v ;; ;; t = ( 4.3 * año * c ) / ( 0.9 * c ) ;; = ( 4.3 / 0.9 ) * año ;; = 4.777 año ;; ;; Pero, visto de la sonda, la duración del viaje es: ;; ;; d' = d / gamma ;; con: ;; gamma = 1 / sqrt( 1 - ( v / c ) ^ 2 ) ;; gamma = 1 / sqrt( 1 - 0.9^2 ) ;; gamma = 2.294 ;; ;; asi que: ;; ;; d' = 4.777 año / 2.294 ;; d' = 2.082 año ;; ;; ;; En el caso que la sonda viaje a 99% de la velocidad de la luz, ;; obtendremos: ;; ;; gamma = 1 / sqrt( 1 - 0.99^2 ) ;; gamma = 7.089 ;; y: ;; d' = 4.777 año / 7.089 ;; d' = 0.673 año, o 8 meses, ;; ;; ¡a comparar con los 3 meses que Cristobal Colomb tomó para ir a America! ;; ;; (Esto para decir que se podria salir a explorar las estrellas con la ;; tecnologia que tenemos desde hace 50 años : los reactores nucleares, ;; salvo que los que se quedan atras no verian volver a los astronautas ;; que van más lejos). ;; ;; ;; ;; ;; (En el caso del photon que viaja a la velocidad de la luz, él toca los ;; dos puntos al mismo tiempo, de su punto de vista. Cuando quita un ;; electron y cuando llega a un otro electro, que sea dentro de la misma ;; molecula o al otro lado de la galaxia o del universo, para él es al ;; mismo tiempo. Las interacciónes electro-magneticas son efectivamente ;; instantaneas, para los photones). ;; ;; ;; ;; http://scienceworld.wolfram.com/physics/TimeDilation.html ;; http://www.geocities.com/angelto.geo/bhole/lorentz.html ;; y miles de páginas sobre el tema... ;; ;;;; THE END ;;;;
25,482
Common Lisp
.lisp
500
45.978
83
0.592657
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
3a568973ab532939fdf274795be1a01bc9e4e6c1ddc02421073e1f00ff26a6fd
4,980
[ -1 ]
4,981
rfc3548.lisp
informatimago_lisp/common-lisp/rfc3548/rfc3548.lisp
;;;; -*- mode:lisp; coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: rfc3548.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; See package docstring. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2012-04-13 <PJB> Removed dependency on external data files for tests. ;;;; Ran around a bug in ccl-1.5. ;;;; 2004-08-18 <PJB> Added base16, base32 and filebase64. ;;;; 2004-08-17 <PJB> Created (extracted from antispam.lisp). ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2004 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.RFC3548.RFC3548" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.STREAM") (:export "BASE16-DECODE-BYTES" "BASE16-ENCODE-BYTES" "BASE32-DECODE-BYTES" "BASE32-ENCODE-BYTES" "FILEBASE64-DECODE-BYTES" "FILEBASE64-ENCODE-BYTES" "BASE64-DECODE-BYTES" "BASE64-ENCODE-BYTES" "BASE16-DECODE" "BASE16-ENCODE" "BASE32-DECODE" "BASE32-ENCODE" "FILEBASE64-DECODE" "FILEBASE64-ENCODE" "BASE64-DECODE" "BASE64-ENCODE") (:import-from "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.STREAM" "BVSTREAM-WRITE-BYTE" "BVSTREAM-READ-BYTE" "WITH-INPUT-FROM-BYTE-VECTOR" "WITH-OUTPUT-TO-BYTE-VECTOR") (:documentation " This packages exports functions to encode an decode text blocks according to the encoding described in: RFC3548: The Base16, Base32, and Base64 Data Encodings base64-encode (read-byte write-char) base64-decode (read-char write-byte &key (ignore-invalid-input nil)) filebase64-encode (read-byte write-char) filebase64-decode (read-char write-byte &key (ignore-invalid-input nil)) base32-encode (read-byte write-char) base32-decode (read-char write-byte &key (ignore-invalid-input nil)) base16-encode (read-byte write-char) base16-decode (read-char write-byte &key (ignore-invalid-input nil)) READ-BYTE: A function taking no argument and returning a byte (integer 0 255) or nil for eof. It may be called several times after eof and should keep returning nil. WRITE-BYTE: A function taking one byte (integer 0 255) argument used to collect decoded bytes. READ-CHAR: A function taking no argument and returning a character or nil for eof. It may be called several times after eof and should keep returning nil. Only characters whose code is between 0 and 255 should be returned. WRITE-CHAR: A function taking one character argument, used to collect encoded bytes. IGNORE-INVALID-INPUT: When true, any invalid character or padding is ignored and processing continues as if it did not occur. When nil, such an occurence would raise an error. base64-encode-bytes (bytes &key line-width (new-line +new-line+)) base64-decode-bytes (encoded &key ignore-crlf ignore-invalid-input) filebase64-encode-bytes (bytes &key line-width (new-line +new-line+)) filebase64-decode-bytes (encoded &key ignore-crlf ignore-invalid-input) base32-encode-bytes (bytes &key line-width (new-line +new-line+)) base32-decode-bytes (encoded &key ignore-crlf ignore-invalid-input) base16-encode-bytes (bytes &key line-width (new-line +new-line+)) base16-decode-bytes (encoded &key ignore-crlf ignore-invalid-input) BYTES: A vector of (unsigned-byte 8). ENCODED: A string. LINE-WIDTH: NIL or an integer indicating the line width. the string new-line will be inserted after that many characters have been written on a given line. NEW-LINE: A string contaiing the new-line character or characters. the default +new-line+ is (format nil \"~%\"). IGNORE-CRLF: When true, ASCII characters LF and CR are not passed to the decoding function. When NIL, they're passed, and if invalid input is not ignored, an error would be raised. IGNORE-INVALID-INPUT: Passed to the decoding function. See above. The encoding functions take a vector of bytes and return an encoded string. The decoding functions take an encoded string and return a vector of bytes. To encode a string, characters must be converted to bytes, and to decode a string, bytes must be converted to characters. This must be done accordingly to the characeter set encoding. License: AGPL3 Copyright Pascal J. Bourguignon 2004 - 2012 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/> ")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.RFC3548.RFC3548") (defun make-decode-table (code &key (case-sensitive t)) " CODE: A string of length (1+ (expt 2 n)). RETURN: An array A:[0..255] --> [-1..(expt 2 n)] character-code --> encoding-value " (do* ((table (make-array '(256) :element-type ;; There's a bug in ccl-1.5 :-( #+(and ccl (not ccl-1.6)) t #-(and ccl (not ccl-1.6)) `(integer -1 ,(1- (length code))) :initial-element -1)) (index 0 (1+ index)) (char (aref code index) (aref code index))) ((<= (1- (length code)) index) table) (if case-sensitive (setf (aref table (char-code char)) index) (setf (aref table (char-code (char-downcase char))) index (aref table (char-code (char-upcase char))) index)))) (defparameter +base64-encode+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" "An array A[0..64] --> character giving the character used to encode the values from 0 to 63, and the padding character in slot 64.") (defparameter +base64-decode+ (make-decode-table +base64-encode+) "An array A:[0..255] |--> [-1..63] character-code ---> encoding-value") (defparameter +filebase64-encode+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=" "An array A[0..64] --> character giving the character used to encode the values from 0 to 63, and the padding character in slot 64.") (defparameter +filebase64-decode+ (make-decode-table +filebase64-encode+) "An array A:[0..255] |--> [-1..63] character-code ---> encoding-value") (defparameter +base32-encode+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=" "An array A[0..32] --> character giving the character used to encode the values from 0 to 31, and the padding character in slot 32.") (defparameter +base32-decode+ (make-decode-table +base32-encode+ :case-sensitive nil) "An array A:[0..255] |--> [-1..31] character-code ---> encoding-value") (defun padding-code (code) "The position of the padding character in code (the last one)." (1- (length code))) ;; encode: ;; base64: 3*8 --> 4*6 ;; base32: 5*8 --> 8*5 ;; base16: 1*8 --> 2*4 (defun encode64 (encode read-byte write-char) (macrolet ((out (code) `(funcall write-char (aref encode ,code)))) (do ((i1 (funcall read-byte) (funcall read-byte)) (i2 (funcall read-byte) (funcall read-byte)) (i3 (funcall read-byte) (funcall read-byte)) (padding (padding-code encode))) ((null i3) (cond ((null i1)) ((null i2) (out (ldb (byte 6 2) i1)) (out (dpb (ldb (byte 2 0) i1) (byte 2 4) 0)) (out padding) (out padding)) (t (out (ldb (byte 6 2) i1)) (out (dpb (ldb (byte 2 0) i1) (byte 2 4) (ldb (byte 4 4) i2))) (out (dpb (ldb (byte 4 0) i2) (byte 4 2) 0)) (out padding))) (values)) ;; aaaaaaaa bbbbbbbb cccccccc ;; aaaaaa aabbbb bbbbcc cccccc (out (ldb (byte 6 2) i1)) (out (dpb (ldb (byte 2 0) i1) (byte 2 4) (ldb (byte 4 4) i2))) (out (dpb (ldb (byte 4 0) i2) (byte 4 2) (ldb (byte 2 6) i3))) (out (ldb (byte 6 0) i3))))) (defun encode32 (encode read-byte write-char) (macrolet ((out (code) `(funcall write-char (aref encode ,code)))) (do ((i1 (funcall read-byte) (funcall read-byte)) (i2 (funcall read-byte) (funcall read-byte)) (i3 (funcall read-byte) (funcall read-byte)) (i4 (funcall read-byte) (funcall read-byte)) (i5 (funcall read-byte) (funcall read-byte)) (padding (padding-code encode))) ((null i5) (cond ((null i1)) ((null i2) (out (ldb (byte 5 3) i1)) (out (dpb (ldb (byte 3 0) i1) (byte 3 2) 0)) (out padding) (out padding) (out padding) (out padding) (out padding) (out padding)) ((null i3) (out (ldb (byte 5 3) i1)) (out (dpb (ldb (byte 3 0) i1) (byte 3 2) (ldb (byte 2 6) i2))) (out (ldb (byte 5 1) i2)) (out (dpb (ldb (byte 1 0) i2) (byte 1 4) 0)) (out padding) (out padding) (out padding) (out padding)) ((null i4) (out (ldb (byte 5 3) i1)) (out (dpb (ldb (byte 3 0) i1) (byte 3 2) (ldb (byte 2 6) i2))) (out (ldb (byte 5 1) i2)) (out (dpb (ldb (byte 1 0) i2) (byte 1 4) (ldb (byte 4 4) i3))) (out (dpb (ldb (byte 4 0) i3) (byte 4 1) 0)) (out padding) (out padding) (out padding)) (t (out (ldb (byte 5 3) i1)) (out (dpb (ldb (byte 3 0) i1) (byte 3 2) (ldb (byte 2 6) i2))) (out (ldb (byte 5 1) i2)) (out (dpb (ldb (byte 1 0) i2) (byte 1 4) (ldb (byte 4 4) i3))) (out (dpb (ldb (byte 4 0) i3) (byte 4 1) (ldb (byte 1 7) i4))) (out (ldb (byte 5 2) i4)) (out (dpb (ldb (byte 2 0) i4) (byte 2 3) 0)) (out padding))) (values)) ;; aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ;; aaaaa aaabb bbbbb bcccc ccccd ddddd ddeee eeeee (out (ldb (byte 5 3) i1)) (out (dpb (ldb (byte 3 0) i1) (byte 3 2) (ldb (byte 2 6) i2))) (out (ldb (byte 5 1) i2)) (out (dpb (ldb (byte 1 0) i2) (byte 1 4) (ldb (byte 4 4) i3))) (out (dpb (ldb (byte 4 0) i3) (byte 4 1) (ldb (byte 1 7) i4))) (out (ldb (byte 5 2) i4)) (out (dpb (ldb (byte 2 0) i4) (byte 2 3) (ldb (byte 3 5) i5))) (out (ldb (byte 5 0) i5))))) ;; decode: ;; base64: 3*8 <-- 4*6 ;; base32: 5*8 <-- 8*5 ;; base16: 1*8 <-- 2*4 (defmacro with-io ((in out) (decode padchar padcode read-char write-byte ignore-invalid-input) &body body) `(let ((state 0)) (flet ((,in () (case state ((0) (do* ((ch (funcall ,read-char) (funcall ,read-char)) (code (when ch (aref ,decode (char-code ch))) (when ch (aref ,decode (char-code ch))))) ((or (null ch) (char= ,padchar ch) (<= 0 code)) (cond ((null ch) (setf state 2) ,padcode) ((char= ,padchar ch) (setf state 1) ,padcode) (t code))) (unless ,ignore-invalid-input (error "RFC3548::DECODE got an invalid input ~ character: ~C" ch)))) ((1) (do* ((ch (funcall ,read-char) (funcall ,read-char))) ((or (null ch) (char= ,padchar ch)) (when (null ch) (setf state 2)) ,padcode) (unless ,ignore-invalid-input (error "RFC3548::DECODE got an invalid input ~ character: ~C, after ,pad character." ch)))) ((2) ,padcode))) (,out (code) (funcall ,write-byte code))) ,@body))) (defun decode64 (decode padchar padcode read-char write-byte ignore-invalid-input) (with-io (in out) (decode padchar padcode read-char write-byte ignore-invalid-input) (do ((i1 (in) (in)) (i2 (in) (in)) (i3 (in) (in)) (i4 (in) (in))) ((= i4 padcode) (cond ((= i1 padcode)) ((= i2 padcode) ;; should not occur (unless ignore-invalid-input (error "DECODE64 got an invalid padcode sequence.")) (out (dpb (ldb (byte 6 0) i1) (byte 6 2) 0))) ((= i3 padcode) (out (dpb (ldb (byte 6 0) i1) (byte 6 2) (ldb (byte 2 4) i2)))) (t (out (dpb (ldb (byte 6 0) i1) (byte 6 2) (ldb (byte 2 4) i2))) (out (dpb (ldb (byte 4 0) i2) (byte 4 4) (ldb (byte 4 2) i3))))) (values)) ;; aaaaaa aabbbb bbbbcc cccccc ;; aaaaaaaa bbbbbbbb cccccccc (out (dpb (ldb (byte 6 0) i1) (byte 6 2) (ldb (byte 2 4) i2))) (out (dpb (ldb (byte 4 0) i2) (byte 4 4) (ldb (byte 4 2) i3))) (out (dpb (ldb (byte 2 0) i3) (byte 2 6) (ldb (byte 6 0) i4)))))) (defun decode32 (decode padchar padcode read-char write-byte ignore-invalid-input) (with-io (in out) (decode padchar padcode read-char write-byte ignore-invalid-input) (do ((i1 (in) (in)) (i2 (in) (in)) (i3 (in) (in)) (i4 (in) (in)) (i5 (in) (in)) (i6 (in) (in)) (i7 (in) (in)) (i8 (in) (in))) ((= i8 padcode) (cond ((= i1 padcode)) ((= i3 padcode) (out (dpb (ldb (byte 5 0) i1) (byte 5 3) (ldb (byte 3 2) i2)))) ((= i5 padcode) (out (dpb (ldb (byte 5 0) i1) (byte 5 3) (ldb (byte 3 2) i2))) (out (dpb (ldb (byte 2 0) i2) (byte 2 6) (dpb (ldb (byte 5 0) i3) (byte 5 1) (ldb (byte 1 4) i4))))) ((= i6 padcode) (out (dpb (ldb (byte 5 0) i1) (byte 5 3) (ldb (byte 3 2) i2))) (out (dpb (ldb (byte 2 0) i2) (byte 2 6) (dpb (ldb (byte 5 0) i3) (byte 5 1) (ldb (byte 1 4) i4)))) (out (dpb (ldb (byte 4 0) i4) (byte 4 4) (ldb (byte 4 1) i5)))) (t (out (dpb (ldb (byte 5 0) i1) (byte 5 3) (ldb (byte 3 2) i2))) (out (dpb (ldb (byte 2 0) i2) (byte 2 6) (dpb (ldb (byte 5 0) i3) (byte 5 1) (ldb (byte 1 4) i4)))) (out (dpb (ldb (byte 4 0) i4) (byte 4 4) (ldb (byte 4 1) i5))) (out (dpb (ldb (byte 1 0) i5) (byte 1 7) (dpb (ldb (byte 5 0) i6) (byte 5 2) (ldb (byte 2 3) i7)))))) (values)) ;; aaaaa aaabb bbbbb bcccc ccccd ddddd ddeee eeeee ;; aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee (out (dpb (ldb (byte 5 0) i1) (byte 5 3) (ldb (byte 3 2) i2))) (out (dpb (ldb (byte 2 0) i2) (byte 2 6) (dpb (ldb (byte 5 0) i3) (byte 5 1) (ldb (byte 1 4) i4)))) (out (dpb (ldb (byte 4 0) i4) (byte 4 4) (ldb (byte 4 1) i5))) (out (dpb (ldb (byte 1 0) i5) (byte 1 7) (dpb (ldb (byte 5 0) i6) (byte 5 2) (ldb (byte 2 3) i7)))) (out (dpb (ldb (byte 3 0) i7) (byte 3 5) (ldb (byte 5 0) i8)))))) (defun base64-encode (read-byte write-char) " DO: Encode the stream read with the READ-BYTE closure in BASE64 text written with WRITE-CHAR closure. READ-BYTE: A function taking no argument and returning a byte (integer 0 255) or nil for eof. It may be called several times after eof and should keep returning nil. WRITE-CHAR: A function taking one character argument, used to collect encoded bytes. " (encode64 +base64-encode+ read-byte write-char)) (defun base64-decode (read-char write-byte &key (ignore-invalid-input nil)) " DO: Decode the BASE64 text stream read with the READ-CHAR closure into a binary stream written with WRITE-BYTE closure. READ-CHAR: A function taking no argument and returning a character or nil for eof. It may be called several times after eof and should keep returning nil. Only characters whose code is between 0 and 255 should be returned. WRITE-BYTE: A function taking one byte (integer 0 255) argument used to collect decoded bytes. IGNORE-INVALID-INPUT: When true, any invalid character or padding is ignored and processing continues as if it did not occur. When nil, such an occurence would raise an error. " (decode64 +base64-decode+ (aref +base64-encode+ (padding-code +base64-encode+)) (padding-code +base64-encode+) read-char write-byte ignore-invalid-input)) (defun filebase64-encode (read-byte write-char) " DO: Encode the stream read with the READ-BYTE closure in FILEBASE64 text written with WRITE-CHAR closure. NOTE: It's the same encoding as BASE64, but the 62nd and 63rd characters are - and _ instead of + and /, thus making it usable for file names and URLs. READ-BYTE: A function taking no argument and returning a byte (integer 0 255) or nil for eof. It may be called several times after eof and should keep returning nil. WRITE-CHAR: A function taking one character argument, used to collect encoded bytes. " (encode64 +filebase64-encode+ read-byte write-char)) (defun filebase64-decode (read-char write-byte &key (ignore-invalid-input nil)) " DO: Decode the FILEBASE64 text stream read with the READ-CHAR closure into a binary stream written with WRITE-BYTE closure. NOTE: It's the same encoding as BASE64, but the 62nd and 63rd characters are - and _ instead of + and /, thus making it usable for file names and URLs. READ-CHAR: A function taking no argument and returning a character or nil for eof. It may be called several times after eof and should keep returning nil. Only characters whose code is between 0 and 255 should be returned. WRITE-BYTE: A function taking one byte (integer 0 255) argument used to collect decoded bytes. IGNORE-INVALID-INPUT: When true, any invalid character or padding is ignored and processing continues as if it did not occur. When nil, such an occurence would raise an error. " (decode64 +filebase64-decode+ (aref +filebase64-encode+ (padding-code +filebase64-encode+)) (padding-code +filebase64-encode+) read-char write-byte ignore-invalid-input)) (defun base32-encode (read-byte write-char) " DO: Encode the stream read with the READ-BYTE closure in BASE32 text written with WRITE-CHAR closure. READ-BYTE: A function taking no argument and returning a byte (integer 0 255) or nil for eof. It may be called several times after eof and should keep returning nil. WRITE-CHAR: A function taking one character argument, used to collect encoded bytes. " (encode32 +base32-encode+ read-byte write-char)) (defun base32-decode (read-char write-byte &key (ignore-invalid-input nil)) " DO: Decode the BASE32 text stream read with the READ-CHAR closure into a binary stream written with WRITE-BYTE closure. READ-CHAR: A function taking no argument and returning a character or nil for eof. It may be called several times after eof and should keep returning nil. Only characters whose code is between 0 and 255 should be returned. WRITE-BYTE: A function taking one byte (integer 0 255) argument used to collect decoded bytes. IGNORE-INVALID-INPUT: When true, any invalid character or padding is ignored and processing continues as if it did not occur. When nil, such an occurence would raise an error. " (decode32 +base32-decode+ (aref +base32-encode+ (padding-code +base32-encode+)) (padding-code +base32-encode+) read-char write-byte ignore-invalid-input)) (defun base16-encode (read-byte write-char) " DO: Encode the stream read with the READ-BYTE closure in BASE16 text written with WRITE-CHAR closure. READ-BYTE: A function taking no argument and returning a byte (integer 0 255) or nil for eof. It may be called several times after eof and should keep returning nil. WRITE-CHAR: A function taking one character argument, used to collect encoded bytes. " (loop :for byte = (funcall read-byte) :while byte :do (progn (funcall write-char (aref "0123456789ABCDEF" (ldb (byte 4 4) byte))) (funcall write-char (aref "0123456789ABCDEF" (ldb (byte 4 0) byte)))))) (defun base16-decode (read-char write-byte &key (ignore-invalid-input nil)) " DO: Decode the BASE16 text stream read with the READ-CHAR closure into a binary stream written with WRITE-BYTE closure. READ-CHAR: A function taking no argument and returning a character or nil for eof. It may be called several times after eof and should keep returning nil. Only characters whose code is between 0 and 255 should be returned. WRITE-BYTE: A function taking one byte (integer 0 255) argument used to collect decoded bytes. IGNORE-INVALID-INPUT: When true, any invalid character or padding is ignored and processing continues as if it did not occur. When nil, such an occurence would raise an error. " (loop :with high = nil :for ch = (funcall read-char) :while ch :do (let ((low (position ch "0123456789ABCDEF" :test (function char-equal)))) (if low (if high (progn (funcall write-byte (dpb high (byte 4 4) low)) (setf high nil)) (setf high low)) (unless ignore-invalid-input (error "BASE16-DECODE got an invalid input character: ~C" ch)))) :finally (when (and high (not ignore-invalid-input)) (error "BASE16-DECODE got an odd byte number.")))) (defmacro encode-bytes (encode bytes line-width new-line) `(with-output-to-string (out) (with-input-from-byte-vector (in ,bytes) (let ((column 0)) (,encode ;; read-byte: (lambda () (let ((byte (bvstream-read-byte in))) (if (eq :eof byte) nil byte))) ;; write-char (if ,line-width (lambda (ch) (write-char ch out) (incf column) (when (<= ,line-width column) (setf column 0) (princ ,new-line out))) (lambda (ch) (write-char ch out)))) (when (and ,line-width (/= 0 column)) (princ ,new-line out)))))) (defmacro decode-bytes (decode encoded ignore-crlf ignore-invalid-input) `(with-output-to-byte-vector (out) (with-input-from-string (in ,encoded) (,decode ;; read-char (if ,ignore-crlf (lambda () (do ((ch (read-char in nil nil)(read-char in nil nil))) ((or (null ch) (not (member (char-code ch) '(10 13)))) ch))) (lambda () (read-char in nil nil))) ;; write-byte (lambda (byte) (bvstream-write-byte out byte)) :ignore-invalid-input ,ignore-invalid-input)))) (defparameter +new-line+ (format nil "~%")) (defun base64-encode-bytes (bytes &key line-width (new-line +new-line+)) " DO: Encode the BYTES in BASE64 text. RETURN: An encoded string. BYTES: A vector of (unsigned-byte 8). LINE-WIDTH: NIL or an integer indicating the line width. the string new-line will be inserted after that many characters have been written on a given line. NEW-LINE: A string contaiing the new-line character or characters. the default +new-line+ is (format nil \"~%\"). " (encode-bytes base64-encode bytes line-width new-line)) (defun base64-decode-bytes (encoded &key ignore-crlf ignore-invalid-input) " DO: Decode the BASE64 encoded string ENCODED. RETURN: A decoded vector of (unsigned-byte 8). ENCODED: A string. IGNORE-CRLF: When true, ASCII characters LF and CR are not passed to the decoding function. When NIL, they're passed, and if invalid input is not ignored, an error would be raised. IGNORE-INVALID-INPUT: Passed to the decoding function. See above. " (decode-bytes base64-decode encoded ignore-crlf ignore-invalid-input)) (defun filebase64-encode-bytes (bytes &key line-width (new-line +new-line+)) " DO: Encode the BYTES in FILEBASE64 text. RETURN: An encoded string. BYTES: A vector of (unsigned-byte 8). LINE-WIDTH: NIL or an integer indicating the line width. the string new-line will be inserted after that many characters have been written on a given line. NEW-LINE: A string contaiing the new-line character or characters. the default +new-line+ is (format nil \"~%\"). " (encode-bytes filebase64-encode bytes line-width new-line)) (defun filebase64-decode-bytes (encoded &key ignore-crlf ignore-invalid-input) " DO: Decode the FILEBASE64 encoded string ENCODED. RETURN: A decoded vector of (unsigned-byte 8). ENCODED: A string. IGNORE-CRLF: When true, ASCII characters LF and CR are not passed to the decoding function. When NIL, they're passed, and if invalid input is not ignored, an error would be raised. IGNORE-INVALID-INPUT: Passed to the decoding function. See above. " (decode-bytes filebase64-decode encoded ignore-crlf ignore-invalid-input)) (defun base32-encode-bytes (bytes &key line-width (new-line +new-line+)) " DO: Encode the BYTES in BASE32 text. RETURN: An encoded string. BYTES: A vector of (unsigned-byte 8). LINE-WIDTH: NIL or an integer indicating the line width. the string new-line will be inserted after that many characters have been written on a given line. NEW-LINE: A string contaiing the new-line character or characters. the default +new-line+ is (format nil \"~%\"). " (encode-bytes base32-encode bytes line-width new-line)) (defun base32-decode-bytes (encoded &key ignore-crlf ignore-invalid-input) " DO: Decode the BASE32 encoded string ENCODED. RETURN: A decoded vector of (unsigned-byte 8). ENCODED: A string. IGNORE-CRLF: When true, ASCII characters LF and CR are not passed to the decoding function. When NIL, they're passed, and if invalid input is not ignored, an error would be raised. IGNORE-INVALID-INPUT: Passed to the decoding function. See above. " (decode-bytes base32-decode encoded ignore-crlf ignore-invalid-input)) (defun base16-encode-bytes (bytes &key line-width (new-line +new-line+)) " DO: Encode the BYTES in BASE16 text. RETURN: An encoded string. BYTES: A vector of (unsigned-byte 8). LINE-WIDTH: NIL or an integer indicating the line width. the string new-line will be inserted after that many characters have been written on a given line. NEW-LINE: A string contaiing the new-line character or characters. the default +new-line+ is (format nil \"~%\"). " (encode-bytes base16-encode bytes line-width new-line)) (defun base16-decode-bytes (encoded &key ignore-crlf ignore-invalid-input) " DO: Decode the BASE16 encoded string ENCODED. RETURN: A decoded vector of (unsigned-byte 8). ENCODED: A string. IGNORE-CRLF: When true, ASCII characters LF and CR are not passed to the decoding function. When NIL, they're passed, and if invalid input is not ignored, an error would be raised. IGNORE-INVALID-INPUT: Passed to the decoding function. See above. " (decode-bytes base16-decode encoded ignore-crlf ignore-invalid-input)) ;;;; THE END ;;;;
30,439
Common Lisp
.lisp
647
38.485317
86
0.600965
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
93b15bcf6cc081230db422add83d76a1a1667da1289b8bdb6ec886d1ddba62e3
4,981
[ -1 ]
4,982
com.informatimago.common-lisp.rfc3548.test.asd
informatimago_lisp/common-lisp/rfc3548/com.informatimago.common-lisp.rfc3548.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.rfc3548.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.rfc3548.test system. ;;;; Tests the com.informatimago.common-lisp.rfc3548 system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.rfc3548.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.rfc3548 system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.rfc3548.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.rfc3548") :components ((:file "rfc3548-test" :depends-on nil)) #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) (let ((*package* (find-package "COM.INFORMATIMAGO.COMMON-LISP.RFC3548.RFC3548.TEST"))) (uiop:symbol-call "COM.INFORMATIMAGO.COMMON-LISP.RFC3548.RFC3548.TEST" "TEST/ALL")))) ;;;; THE END ;;;;
3,048
Common Lisp
.lisp
66
39.893939
114
0.566443
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
dd8c62477a3583263ac17a76bd6559821e7eb87710f8ff93938be2f6963f776c
4,982
[ -1 ]
4,983
com.informatimago.common-lisp.rfc3548.asd
informatimago_lisp/common-lisp/rfc3548/com.informatimago.common-lisp.rfc3548.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.rfc3548.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.rfc3548 library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.rfc3548" ;; system attributes: :description "Informatimago Common Lisp RFC3548 Implementation: Base16, Base32, and Base64." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.4.0" :properties ((#:author-email . "[email protected]") (#:date . "Autumn 2010") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.rfc3548/") ((#: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.common-lisp.cesarum") :components ((:file "rfc3548" :depends-on ())) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.rfc3548.test")))) ;;;; THE END ;;;;
2,562
Common Lisp
.lisp
53
45.132075
111
0.594573
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
6f9e04e84cf32a804af9cac0302dd8a9a9cdb5fe02dbec21d82f95cd5c3ce831
4,983
[ -1 ]
4,984
rfc3548-test.lisp
informatimago_lisp/common-lisp/rfc3548/rfc3548-test.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: rfc3548-test.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Tests rfc3548.lisp. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-02-25 <PJB> Extracted from rfc3548.lisp ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.RFC3548.RFC3548.TEST" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.SIMPLE-TEST" "COM.INFORMATIMAGO.COMMON-LISP.RFC3548.RFC3548") (:export "TEST/ALL") (:import-from "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.STREAM" "BVSTREAM-WRITE-BYTE" "BVSTREAM-READ-BYTE" "WITH-INPUT-FROM-BYTE-VECTOR" "WITH-OUTPUT-TO-BYTE-VECTOR")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.RFC3548.RFC3548.TEST") (define-test test/encoding (encoding &key line-width ignore-crlf) (let ((data (map 'vector (function char-code) #-(and) (with-open-file (in "/home/pascal/tmp/misc/wang.accented" :direction :input :if-does-not-exist :error) (loop :for ch = (read-char in nil nil) :while ch :collect ch into result :finally (return result))) " Hao Wang, logicien americain. L'algorithme en question a été publié en 1960 dans l'IBM Journal, article intitule \"Toward Mechanical Mathematics\", avec des variantes et une extension au calcul des prédicats. Il s'agit ici du \"premier programme\" de Wang, systeme \"P\". L'article a été écrit en 1958, et les expériences effectuées sur IBM 704 ­ machine à lampes, 32 k mots de 36 bits, celle­là même qui vit naître LISP à la même époque. Le programme a été écrit en assembleur (Fortran existait, mais il ne s'était pas encore imposé) et l'auteur estime que \"there is very little in the program that is not straightforward\". Il observe que les preuves engendrées sont \"essentiellement des arbres\", et annonce que la machine a démontre 220 théorèmes du calcul des propositions (tautologies) en 3 minutes. Il en tire argument pour la supériorité d'une approche algorithmique par rapport à une approche heuristique comme celle du \"Logic Theorist\" de Newell, Shaw et Simon (à partir de 1956 sur la machine JOHNNIAC de la Rand Corporation): un débat qui dure encore... Cet algorithme a été popularisé par J. McCarthy, comme exemple­fanion d'application de LISP. Il figure dans le manuel de la première version de LISP (LISP 1, sur IBM 704 justement, le manuel est daté de Mars 1960), et il a été repris dans le celebre \"LISP 1.5 Programmer's Manual\" publié en 1962 par MIT Press, un des maîtres­livres de l'Informatique. " )) enc dec encoded decoded) (case encoding ((:base16) (setf enc (function base16-encode-bytes) dec (function base16-decode-bytes))) ((:base32) (setf enc (function base32-encode-bytes) dec (function base32-decode-bytes))) ((:base64) (setf enc (function base64-encode-bytes) dec (function base64-decode-bytes))) ((:filebase64) (setf enc (function filebase64-encode-bytes) dec (function filebase64-decode-bytes))) (:otherwise (error "Unknown encoding ~S~%" encoding))) (dotimes (i 8) (setf encoded (funcall enc data :line-width line-width)) ;; (print encoded) (setf decoded (funcall dec encoded :ignore-crlf ignore-crlf)) (assert-true (equalp data decoded)) (setf data (subseq data 0 (1- (length data))))))) (define-test test/all-encodings () (dolist (enc '(:base16 :base32 :base64 :filebase64)) (dolist (line '(nil t)) (test/encoding enc :line-width (when line 40) :ignore-crlf line)))) (defun interactive-test/base16-encode () (base16-encode (lambda () (let ((ch (read-char))) (if (char= #\newline ch) nil (char-code ch)))) (function write-char))) (defun interactive-test/base16-decode () (base16-decode (lambda () (let ((ch (read-char))) (if (char= #\newline ch) nil ch))) (lambda (byte) (write-char (code-char byte))))) (define-test test/all () (test/all-encodings)) ;;;; THE END ;;;;
5,547
Common Lisp
.lisp
112
43.5
84
0.636296
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
89d3522b791a7de8e2db2b2dfaf992a88f728164557a6a0cb6d741764b8ca2ae
4,984
[ -1 ]
4,985
com.informatimago.common-lisp.graphviz.test.asd
informatimago_lisp/common-lisp/graphviz/com.informatimago.common-lisp.graphviz.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.graphviz.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.graphviz.test system. ;;;; Tests the com.informatimago.common-lisp.graphviz system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.graphviz.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.graphviz system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.graphviz.test/") ((#: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.common-lisp.graphviz" "com.informatimago.common-lisp.cesarum") :components () #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) ;; (let ((*package* (find-package "TESTED-PACKAGE"))) ;; (uiop:symbol-call "TESTED-PACKAGE" ;; "TEST/ALL")) )) ;;;; THE END ;;;;
2,983
Common Lisp
.lisp
67
38.343284
88
0.551132
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
89da1fdf7d899fab87f11f22548f12bd57a3d2317447581d478e2ce572307cb8
4,985
[ -1 ]
4,986
graph-dot.lisp
informatimago_lisp/common-lisp/graphviz/graph-dot.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: graph-dot.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Generate dot files from graphs (graph-class). ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2004-08-06 <PJB> Added defgeneric. ;;;; 2003-05-16 <PJB> Converted from emacs lisp. ;;;; 2003-05-14 <PJB> Extracted from pjb-cvs. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2003 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.GRAPHVIZ.GRAPH-DOT" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.LIST" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.STRING" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.GRAPH") (:export "GENERATE-DOT") (:documentation " This package exports methods for GRAPH to generate dot(1) files. License: AGPL3 Copyright Pascal J. Bourguignon 2003 - 2012 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/> ")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.GRAPHVIZ.GRAPH-DOT") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Generating dot files (defun dot-ident (ident) " RETURN: A string containing the ident with the dash removed. " (remove (character "-") (string ident))) (defgeneric generate-dot (graph) (:documentation "RETURN: a string containing the dot file contents for the GRAPH.")) (defmethod generate-dot ((self element-class)) " RETURN: A string containing the dot file data for this ELEMENT-CLASS node. " (let ((style (or (get-property self :dot-style) "filled")) (color (or (get-property self :dot-color) "black")) (fillcolor (or (get-property self :dot-fill-color) "LightYellow")) (label (or (get-property self :dot-label) (let ((pnames (property-names self))) (cond ((null pnames) nil) ((= 1 (length pnames)) (format nil "~A" (get-property self (car pnames)))) (t (unsplit-string (mapcar (lambda (prop-name) (if (let ((name (symbol-name prop-name))) (and (< 4 (length name) ) (string-equal "DOT-" (subseq (symbol-name prop-name) 0 4)))) "" (format nil "~A = ~A" prop-name (get-property self prop-name)))) pnames) #\Newline)))) (dot-ident (ident self))))) (format nil "~A [ style=~A color=~A fillcolor=~A label=\"~A\" ];~%" (dot-ident (ident self)) style color fillcolor label))) (defmethod generate-dot ((self edge-class)) " RETURN: A string containing the dot file data for this edge. " (format nil "~A -> ~A ;~%" (dot-ident (ident (car (nodes self)))) (dot-ident (ident (cdr (nodes self)))))) (defmethod generate-dot ((self directed-edge-class)) " RETURN: A string containing the dot file data for this edge. " (format nil "~A -> ~A ;~%" (dot-ident (ident (from self))) (dot-ident (ident (to self))))) (defmethod generate-dot ((self weighted-directed-edge-class)) " RETURN: A string containing the dot file data for this edge. " (format nil "~A -> ~A [ weight=~D, style=~A, color=~A ];~%" (dot-ident (ident (from self))) (dot-ident (ident (to self))) (weight self) (cond ((< (weight self) 3) "dotted") ((< (weight self) 10) "dashed") ((< (weight self) 15) "solid") (t "bold")) "black")) ;;; (DESCRIPTION (car (element-list (NODES g)))) ;;; (MAP-ELEMENTS (NODES g) (lambda (elem) (ident elem))) ;;; (car (element-list (NODES g))) (defmethod generate-dot ((self graph-class)) " RETURN: A string containing the dot file data for this graph. NOTE: dot graphs are directed. " (apply (function concatenate) 'string (flatten (list (format nil "digraph ~A~%" (or (get-property self :name) "Untitled")) (format nil (concatenate 'string "{~%" (format nil "rankdir=~A;~%" (or (get-property self :dot-rankdir) "TB")) (format nil "concentrate=~:[false~;true~];~%" (get-property self :dot-concentrate)) "// attributes of graph:~%" "// page=8,11.4; // page size (NeXTprinter:A4).~%" "// size=30,8; // graph size (please edit to fit).~%" "// rotate=90; // graph orientation (please edit to fit).~%" "page=300;~%" "size=300;~%" "rotate=90;~%" "// ratio=fill; // fill the size (or compress, auto, aspect/ratio).~%" "nodesep=0.3;~%" "ranksep=0.3;~%" "center=1;~%" "splines=true;~%" "// common attributes of NODES:~%" "node [height=0.2 width=0.5 shape=box fontsize=8 fontname=Futura] ;~%")) (map-elements 'list (nodes self) (lambda (node) (generate-dot node))) (format nil "// common attributes of edges:~%edge [style=solid];~%") (map-elements 'list (edges self) (lambda (edge) (generate-dot edge))) (format nil "}~%"))))) ;;;; THE END ;;;;
7,308
Common Lisp
.lisp
167
35.437126
92
0.556588
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
9b59fc181c11248a4c7fd44db8b23f5fd27c5e4da51d759f2aef16ab982e6a37
4,986
[ -1 ]
4,987
com.informatimago.common-lisp.graphviz.asd
informatimago_lisp/common-lisp/graphviz/com.informatimago.common-lisp.graphviz.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.graphviz.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.graphviz library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.graphviz" ;; system attributes: :description "Informatimago Common Lisp Grapviz Graph Generation Methods" :long-description "Methods on the GRAPH class to generate GraphViz dot(1) files." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.4.0" :properties ((#:author-email . "[email protected]") (#:date . "Autumn 2010") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.graphviz/") ((#: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.common-lisp.cesarum") :components ((:file "graph-dot" :depends-on ())) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.graphviz.test")))) ;;;; THE END ;;;;
2,633
Common Lisp
.lisp
54
45.574074
112
0.60031
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
36712abb95a5ec26e387a337e7e4aaa699192a892667fe45c183e6da0d071057
4,987
[ -1 ]
4,988
com.informatimago.common-lisp.html-parser.test.asd
informatimago_lisp/common-lisp/html-parser/com.informatimago.common-lisp.html-parser.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.html-parser.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.html-parser.test system. ;;;; Tests the com.informatimago.common-lisp.html-parser system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.html-parser.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.html-parser system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.html-parser.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.html-parser") :components () #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) ;; (let ((*package* (find-package "TESTED-PACKAGE"))) ;; (uiop:symbol-call "TESTED-PACKAGE" ;; "TEST/ALL")) )) ;;;; THE END ;;;;
3,004
Common Lisp
.lisp
67
38.656716
91
0.551959
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
15b20021f0c380a5b0129470892d030ceaa5fd960e88867d6266e7de8f4dbc76
4,988
[ -1 ]
4,989
parse-html.lisp
informatimago_lisp/common-lisp/html-parser/parse-html.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: parse-html.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; A Simple HTML parser. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-10-20 <PJB> Added PARSE-HTML-STREAM. ;;;; 2012-03-13 <PJB> Renamed package to match its position in the hierarchy. ;;;; 2005-02-22 <PJB> Optimized WALK for HTML-SEQ. ;;;; 2003-11-12 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2003 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.HTML-PARSER.PARSE-HTML" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.UTILITY" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.LIST" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.STRING" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.PEEK-STREAM" "COM.INFORMATIMAGO.COMMON-LISP.HTML-GENERATOR.HTML-ENTITIES" "COM.INFORMATIMAGO.COMMON-LISP.HTML-BASE.ML-SEXP") #+mocl (:shadowing-import-from "COM.INFORMATIMAGO.MOCL.KLUDGES.MISSING" "*TRACE-OUTPUT*" "*LOAD-VERBOSE*" "*LOAD-PRINT*" "ARRAY-DISPLACEMENT" "CHANGE-CLASS" "COMPILE" "COMPLEX" "ENSURE-DIRECTORIES-EXIST" "FILE-WRITE-DATE" "INVOKE-DEBUGGER" "*DEBUGGER-HOOK*" "LOAD" "LOGICAL-PATHNAME-TRANSLATIONS" "MACHINE-INSTANCE" "MACHINE-VERSION" "NSET-DIFFERENCE" "RENAME-FILE" "SUBSTITUTE-IF" "TRANSLATE-LOGICAL-PATHNAME" "PRINT-NOT-READABLE" "PRINT-NOT-READABLE-OBJECT") (:import-from "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.STRING" "UNSPLIT-STRING" "SPLIT-STRING" "STRING-REPLACE") (:export "UNPARSE-HTML" "WRITE-HTML-TEXT" "PARSE-HTML-STREAM" "PARSE-HTML-STRING" "PARSE-HTML-FILE") (:documentation " This package implements a simple HTML parser. Example: (parse-html-string \"&lt;html&gt;&lt;head&gt;&lt;title&gt;Test&lt;/title&gt;&lt;/head&gt; &lt;body&gt;&lt;h1&gt;Little Test&lt;/h1&gt; &lt;p&gt;How dy? &lt;a href=\\\"/check.html\\\"&gt;Check this&lt;/a&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;one&lt;li&gt;two&lt;li&gt;three&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;\") --> ((:html nil (:head nil (:title nil \"Test\")) \" \" (:body nil (:h1 nil \"Little Test\") \" \" (:p nil \"How dy? \" (:a (:href \"/check.html\") \"Check this\")) \" \" (:ul nil (:li nil \"one\" (:li nil \"two\" (:li nil \"three\"))))))) Sexp html format: element ::= (tag (&rest attributes) &rest contents) . tag ::= (or symbol string) . -- usually a keyword attributes ::= list of (name value) . contents ::= list of element | string . name ::= (or symbol string) . -- usually a keyword. value ::= string . License: AGPL3 Copyright Pascal J. Bourguignon 2003 - 2015 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/> ")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.HTML-PARSER.PARSE-HTML") (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *tag-package* (load-time-value (find-package "KEYWORD")))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Scanner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defstruct (html-scanner (:constructor %make-html-scanner)) (state :normal :type symbol) (next-state nil :type symbol) (source (make-instance 'peek-stream :stream *standard-input*) :type peek-stream)) (defun make-html-scanner (&key (source *standard-input*) (state :normal)) (%make-html-scanner :source (make-instance 'peek-stream :stream source) :state state)) (defmacro defcharset (name characters &key complement) (let ((characters (eval characters)) (table (make-array '(256) :element-type 'bit :initial-element (if complement 1 0)))) (dotimes (i (length characters)) (setf (aref table (char-code (aref characters i))) (if complement 0 1))) `(let ((table ,table)) (defun ,name (ch) (let ((code (char-code ch))) (if (<= 0 code 255) (/= 0 (aref table code)) ,complement)))))) (defcharset cs-space-p (format nil "~{~C~}" (mapcar (function code-char) '(32 10 13 9 11 12)))) (defcharset cs-crlf-p (format nil "~{~C~}" (mapcar (function code-char) '(10 13)))) (defcharset cs-string-d-char-p (format nil "\"~{~C~}" (mapcar (function code-char) '(10 13))) :complement t) (defcharset cs-string-s-char-p (format nil "'~{~C~}" (mapcar (function code-char) '(10 13))) :complement t) (defcharset cs-string-n-char-p (format nil "~{~C~}\"'=>" (mapcar (function code-char) '(32 10 13 9 11 12))) :complement t) ;; "-+,./0123456789:?ABCDEFGHIJKLMNOPQRSTUVWXYZZ_abcdefghijklmnopqrstuvwxyzz" (defcharset cs-alpha-char-p "ABCDEFGHIJKLMNOPQRSTUVWXYZZabcdefghijklmnopqrstuvwxyz") (defcharset cs-ident-char-p "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZZ_abcdefghijklmnopqrstuvwxyz:") ;; xmlns:rdf (defparameter +crlf+ (format nil "~C~C" (code-char 10) (code-char 13))) ;; <td width=\"180\" align=\"rig valign=bottom nowrap><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"140\" height=\"29\"><param name=\"movie\" value=\"/images/pest_tiendas.swf\"><param name=\"quality\" value=\"high\"> ;; <input type="hidden" name="dire" value="Pol. Industrial, 2 "E""> ;; :: if in tag and close-" ;; :: then look ahead while closed and not '>' and not '=' and not '/' for xml '/>'. (defun heuristic-quote-in-string (string start end-of-string) "( *[a-z]+ *= *{string})/?>" (let* ((next-quote (position end-of-string string :start (1+ start))) (equal-sign (position (character "=") string :start (1+ start) :end next-quote))) ;; (format t "next-quote=~S equal-sign=~S~%" next-quote equal-sign) (if next-quote (if (and equal-sign (< equal-sign next-quote)) (values start nil) ; sss"xxx=xxx" (values (1+ next-quote) t)) ; ssss"ssss"xx (values start nil)))) ; sss"xxx=xxx> (defun get-token (scanner) (let ((value (make-array '(16) :fill-pointer 0 :adjustable t :element-type 'character))) (labels ((get-char-and-keep () "Get the next character from the source, advance, and append it to value." (let ((ch (getchar (html-scanner-source scanner)))) (when ch (vector-push-extend ch value)) ch)) (eat-char () "Get the next character from the source, and advance." (getchar (html-scanner-source scanner))) (unget-char (ch) "Remove the character ch from the value, and put it back to the source." (ungetchar (html-scanner-source scanner) ch) (vector-pop value)) (next-char () "Peek the next character from the source. (eql (get-char-and-keep) (next-char)) --> true (eql (next-char) (get-char-and-keep)) --> true or false! Same with eat-char." (nextchar (html-scanner-source scanner))) ;; (has-char () ;; "Whether value is not empty." ;; (plusp (fill-pointer value))) ;; (last-char () ;; "Return the last character in value." ;; (aref value (1- (fill-pointer value)))) ) (declare (inline get-char-and-keep eat-char unget-char next-char)) (case (html-scanner-state scanner) ((:normal) (let ((ch (get-char-and-keep))) (cond ;; eof ((null ch) (return-from get-token (values :eof nil))) ;; open a tag ((char= ch (character "<")) (setf ch (get-char-and-keep)) (cond ;; eof ((null ch) (return-from get-token (values :pcdata value))) ;; <? ((char= ch (character "?")) (loop :named :foreign :with state = :foreign :for ch = (get-char-and-keep) :while ch :do (ecase state ((:foreign) (when (char= ch (character "?")) (setf state :end))) ((:end) (if (char= ch (character ">")) (return-from :foreign (values :foreign value)) (setf state :foreign)))))) ;; <! ((char= ch (character "!")) (setf ch (get-char-and-keep)) (cond ;; eof ((null ch) (return-from get-token (values :pcdata value))) ;; <!- comment ((char= ch (character "-")) (loop named :comment with state = :comment for ch = (get-char-and-keep) while ch do (case state ((:comment) (when (char= ch (character "-")) (setf state :dash))) ((:dash) (if (char= ch (character "-")) (setf state :dash-dash) (setf state :comment))) ((:dash-dash) (cond ((char= ch (character " "))) ((char= ch (character ">")) (return-from :comment (values :comment value))) (t (setf state :comment))))))) ;; <! open definition (t (unget-char ch) (setf (html-scanner-state scanner) :tag) (values :open-def value)))) ;; </ open close tag ((char= ch (character "/")) (setf (html-scanner-state scanner) :tag) (values :close-tag value)) ;; < open open tag (t (unget-char ch) (setf (html-scanner-state scanner) :tag-ident) (values :open-tag value)))) ;; outside of a tag: pcdata (t (loop for ch = (get-char-and-keep) while (and ch (char/= ch (character "<"))) finally (when ch (unget-char ch))) (values :pcdata value))))) ((:script :style) (setf (html-scanner-state scanner) :normal) (values :cdata (loop :for ch = (get-char-and-keep) :for nc = (next-char) :while (and ch nc (or (char/= ch (character "<")) (char/= nc (character "/")))) :finally (progn (unget-char ch) (return value))))) ((:tag-ident :tag) (let ((ch (loop :for ch = (eat-char) :while (and ch (cs-space-p ch)) :finally (progn (when ch (vector-push-extend ch value)) (return ch))))) (cond ;; eof ((null ch) (return-from get-token (values :eof nil))) ;; /> close close tag ((and (char= ch (character "/")) (char= (next-char) (character ">"))) (get-char-and-keep) (setf (html-scanner-state scanner) :normal) (values :close-end-tag value)) ;; > close close tag ((char= ch (character ">")) (setf (html-scanner-state scanner) (if (html-scanner-next-state scanner) (prog1 (html-scanner-next-state scanner) (setf (html-scanner-next-state scanner) nil)) :normal)) (values :end-tag value)) ;; identifier ((cs-alpha-char-p ch) ;;ident (loop for ch = (get-char-and-keep) while (and ch (cs-ident-char-p ch)) finally (when ch (unget-char ch))) (when (eq (html-scanner-state scanner) :tag-ident) (setf (html-scanner-state scanner) :tag) (cond ((string-equal "script" value) (setf (html-scanner-next-state scanner) :script)) ((string-equal "style" value) (setf (html-scanner-next-state scanner) :style)))) (values :identifier value)) ;; "string" or 'string' ((or (char= ch (character "\"")) ;; string-d (char= ch (character "'"))) ;; string-n (let ((char-set (if (char= ch (character "\"")) (function cs-string-d-char-p) (function cs-string-s-char-p))) (end-of-string ch)) (vector-pop value) ; remove the string openining character (tagbody :go-on (loop :for ch = (get-char-and-keep) :while (and ch (or (funcall char-set ch) (find ch +crlf+))) :when (find ch +crlf+) :do (warn "Newline inside a string: ~S" value) :finally (if (or (null ch) (char/= ch end-of-string)) (error "Newline inside a string: ~S" value) (vector-pop value))) ; remove the string closing character ;; There are two common syntax error found in web pages ;; (both hand-written and generated automatically): ;; 1- A closing attribute double quote is duplicated at ;; the end of the tag: <tag attrib="xyz""> ;; 2- Double-quotes are used inside the attribute to quote: ;; <tag attrib="Jojo "The Beef" Steack"> ;; Notice that the end of the tag could be ">" or " />" ;; (cond ;; ((char= (next-char) end-of-string) ;; ;; let's handle a syntax error: <tag attrib="xyz""> ;; (let ((ch (eat-char))) ;; (when (find (next-char) "/>") ;; (unget-char ch)))) ;; ;; ((and (has-char) (char= (last-char) #\space) ;; (not (find (next-char) " />"))) ;; ;; let's handle a syntax error: ;; ;; <tag attrib="Jojo "The Beef" Steack"> ;; (let ((start (length value))) ;; (vector-push-extend end-of-string value) ;; (loop ; collect all chars till the next #\> ;; :for ch = (get-char-and-keep) ;; :while (and ch (not (find ch ">")))) ;; (multiple-value-bind (end go-on) ;; (heuristic-quote-in-string value start end-of-string) ;; (loop ; put back characters after the string ;; :while (< end (length value)) ;; :do (unget-char (last-char))) ;; (when go-on (go :go-on)))))) )) (values :string value)) ;; unquoted attribute: cdata ((cs-string-n-char-p ch) ;; string-n (loop for ch = (get-char-and-keep) while (and ch (cs-string-n-char-p ch)) finally (unget-char ch)) (values :string value)) ((char= ch (character "=")) (values :equal value)) (t (error "Invalid character '~C' in tag." ch))))) (otherwise (error "Invalid state ~S" (html-scanner-state scanner))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Parser ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Keep these structures disjoint types for the walk methods below. (defstruct html-seq first rest) (defstruct comment data) (defstruct foreign data) (defstruct pattribute name value) (defstruct definition name attributes) (defstruct open-tag name attributes closed) (defstruct close-tag name attributes) (defun normalize-tag (tag) (intern (string-upcase tag) *tag-package*)) (defstruct html-parser scanner token value next-token next-value) (defun advance (parser) (multiple-value-bind (tok val) (get-token (html-parser-scanner parser)) (setf (html-parser-token parser) (html-parser-next-token parser) (html-parser-value parser) (html-parser-next-value parser) (html-parser-next-token parser) tok (html-parser-next-value parser) val))) ;; Productions (defun report-error (parser message) (error "~A; (~S ~S) (~S ~S)" message (html-parser-token parser) (html-parser-value parser) (html-parser-next-token parser) (html-parser-next-value parser))) (defun parse-file (parser) ;; file --> tag { html-seq: [(first tag) (rest nil) ] } ;; | data { html-seq: [(first data) (rest nil) ] } ;; | tag file { html-seq: [(first tag) (rest file)] } ;; | data file { html-seq: [(first data) (rest file)] } ; (loop :for synthetic = (case (html-parser-token parser) ((:eof) nil) ((:pcdata) (prog1 (html-parser-value parser) (advance parser))) ((:cdata) (prog1 (html-parser-value parser) (advance parser))) ((:open-def) (parse-definition parser)) ((:foreign) (prog1 (make-foreign :data (html-parser-value parser)) (advance parser))) ((:comment) (prog1 (make-comment :data (let ((text (html-parser-value parser))) (subseq text 4 (- (length text) 3)))) (advance parser))) ((:open-tag) (parse-open-tag parser)) ((:close-tag) (parse-close-tag parser)) (otherwise (report-error parser "Unexpected token"))) :while synthetic :collect synthetic)) (defun parse-definition (parser) ;; tag --> "<!" ident ">" ;; { definition: [(name ident) ] } ;; | "<!" ident aivs ">" ;; { definition: [(name ident) (pattributes aivs)] } (advance parser) (unless (eq :identifier (html-parser-token parser)) (report-error parser "Expected an identifier")) (let ((ident (normalize-tag (html-parser-value parser)))) (advance parser) (if (eq :end-tag (html-parser-token parser)) (progn (advance parser) (make-definition :name ident :attributes nil)) (let ((pattributes (loop :while (member (html-parser-token parser) '(:string :identifier)) :collect (html-parser-value parser) :do (advance parser)))) (if (eq :end-tag (html-parser-token parser)) (advance parser) (report-error parser "Expected a \">\"")) (make-definition :name ident :attributes pattributes))))) (defun parse-open-tag (parser) ;; | "<" ident ">" ;; { open-tag: [(name ident) ] } ;; | "<" ident pattributes ">" ;; { open-tag: [(name ident) (pattributes pattributes)] } (advance parser) (unless (eq :identifier (html-parser-token parser)) (report-error parser "Expected a tag identifier")) (let ((tag (prog1 (make-open-tag :name (prog1 (normalize-tag (html-parser-value parser)) (advance parser)) :attributes (parse-attributes parser) :closed (eq (html-parser-token parser) :close-end-tag)) (unless (member (html-parser-token parser) '(:end-tag :close-end-tag)) (report-error parser "Expected a \">\"")) (advance parser)))) tag)) (defun parse-close-tag (parser) ;; Same as open-tag, but for the make-close-tag. (advance parser) (unless (eq :identifier (html-parser-token parser)) (report-error parser "Expected a tag identifier")) (prog1 (make-close-tag :name (prog1 (normalize-tag (html-parser-value parser)) (advance parser)) :attributes (parse-attributes parser)) (unless (eq :end-tag (html-parser-token parser)) (report-error parser "Expected a \">\"")) (advance parser))) (defun parse-attributes (parser) ;; attributes --> attribute ;; { html-seq: [(first attribute) (rest nil) ] } ;; | attribute attributes ;; { html-seq: [(first attribute) (rest attributes)] }; (loop :while (member (html-parser-token parser) '(:identifier :string)) :collect (parse-attribute parser))) (defun parse-attribute (parser) ;; attribute --> ident ;; { attribute: [(name ident) (value nil) ] } ;; | ident "=" value ;; { attribute: [(name ident) (value value)] } ; (unless (member (html-parser-token parser) '(:identifier :string)) (report-error parser "Expected an attribute identifier or a string.")) (make-pattribute :name (prog1 (normalize-tag (html-parser-value parser)) (advance parser)) :value (clean-attribute (if (eq :equal (html-parser-token parser)) (progn (advance parser) (unless (member (html-parser-token parser) '(:string :identifier)) (report-error parser "Expected an attribute value")) (prog1 (string (html-parser-value parser)) (advance parser))) (html-parser-value parser))))) (defun clean-attribute (attr) "If the attribute name is quoted or double-quoted, then remove those quotes." (cond ((not (stringp attr)) attr) ((or (and (<= 2 (length attr)) (char= (character "'") (char attr 0)) (char= (character "'") (char attr (1- (length attr))))) (and (<= 2 (length attr)) (char= (character "\"") (char attr 0)) (char= (character "\"") (char attr (1- (length attr)))))) (subseq attr 1 (- (length attr) 1))) (t attr))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (defstruct comment data) ;; (defstruct foreign data) ;; (defstruct pattribute name value) ;; (defstruct definition name pattributes) ;; (defstruct open-tag name pattributes closed) ;; (defstruct close-tag name pattributes) (defstruct pelement name attributes contents closed) (defparameter *newline* (string #\newline) "A string containing only a newline.") (defgeneric unwrap-pattribute (pattribute) (:method ((pattribute pattribute)) (make-attribute (pattribute-name pattribute) (pattribute-value pattribute)))) (defgeneric unwrap-element (element) (:method ((element t)) element) (:method ((element foreign)) (make-element :foreign '() (list (foreign-data element)))) (:method ((element comment)) (make-element :comment '() (list (comment-data element)))) (:method ((element definition)) (make-element :definition '() (definition-attributes element))) (:method ((element pelement)) (make-element (pelement-name element) (mapcan (function unwrap-pattribute) (pelement-attributes element)) (remove *newline* (mapcar (function unwrap-element) (pelement-contents element)) :test (function equal))))) (defun encase (tok-list) " Transform a list of tokens and content strings, into a :document sexp tree structured according to the OPEN-TAG and (optional) CLOSE-TAG tokens. " (loop :with stack := (list (make-pelement :name :document)) :for tok :in tok-list :do (etypecase tok ((or string comment foreign definition) (push tok (pelement-contents (car stack)))) (open-tag (let ((pelement (make-pelement :name (open-tag-name tok) :attributes (open-tag-attributes tok) :closed (open-tag-closed tok)))) (if (pelement-closed pelement) (push pelement (pelement-contents (car stack))) (push pelement stack)))) (close-tag (if (position (close-tag-name tok) stack :key (function pelement-name)) (loop :for top := (pop stack) :do (setf (pelement-closed top) t (pelement-contents top) (nreverse (pelement-contents top))) (push top (pelement-contents (car stack))) :until (eq (close-tag-name tok) (pelement-name top))) #|else ignore the unbalanced close tag|#))) :finally (return (loop :for top := (pop stack) :do (setf (pelement-closed top) t (pelement-contents top) (nreverse (pelement-contents top))) :while stack :do (push top (pelement-contents (car stack))) :finally (return top))))) (defun parse-html-stream (stream &key (verbose nil)) " DO: Parse the HTML stream STREAM. VERBOSE: When true, writes some information in the *TRACE-OUTPUT*. RETURN: A list of html elements. SEE ALSO: ELEMENT-TAG, ELEMENT-ATTRIBUTES, ATTRIBUTE-NAMED, ELEMENT-CHILDREN. " (let ((name (or (ignore-errors (namestring stream)) (princ-to-string stream))) synthetic encased) (when verbose (format *trace-output* "~&starting parsing of file ~S~%" name)) (setf synthetic (let ((parser (make-html-parser :scanner (make-html-scanner :source stream)))) (advance parser) (advance parser) (parse-file parser))) (when verbose (format *trace-output* "~&file ~S parsed~%" name)) (setf encased (unwrap-element (encase synthetic))) (when verbose (format *trace-output* "~&file ~S encased -- done.~%" name)) encased)) (defun parse-html-file (pathname &key (verbose nil) (external-format :default)) " DO: Parse the HTML file PATHNAME. VERBOSE: When true, writes some information in the *TRACE-OUTPUT*. EXTERNAL-FORMAT: The external-format to use to open the HTML file. RETURN: A list of html elements. SEE ALSO: ELEMENT-TAG, ELEMENT-ATTRIBUTES, ATTRIBUTE-NAMED, ELEMENT-CHILDREN. " (with-open-file (src pathname :direction :input :if-does-not-exist :error :external-format external-format) (parse-html-stream src :verbose verbose))) (defun parse-html-string (string &key (start 0) (end (length string)) (verbose nil)) " DO: Parse the HTML in the STRING (between START and END) VERBOSE: When true, writes some information in the *TRACE-OUTPUT*. RETURN: A list of html elements. SEE ALSO: ELEMENT-TAG, ELEMENT-ATTRIBUTES, ATTRIBUTE-NAMED, ELEMENT-CHILDREN. " (when verbose (format *trace-output* "~&starting string parsing from ~D~%" start)) (with-input-from-string (src string :start start :end end) (parse-html-stream src :verbose verbose))) (defparameter *nl* (make-hash-table) " This hash-table maps tag symbols (interned in *TAG-PACKAGE*) to a list of two elements: - a list of keywords indicating the newlines that should be written around the element when writing HTML: :bo before open tag. :ao after open tag. :bc before close tag. :ac after open tag. - a function taking the element as parameted (named SELF), used to format the element as (reStructured)text. ") (defun element-key (html) (intern (string (element-tag html)) *tag-package*)) (defun must-new-line (html where) (member where (first (gethash (element-key html) *nl*)))) (defun write-text (element) (typecase element (string (princ (melt-entities element))) (atom (princ element)) (otherwise (flet ((write-it () (let ((entry (gethash (element-tag element) *nl*))) (if (second entry) (funcall (second entry) element) (progn (when (intersection '(:bo :ao) (first entry)) (terpri)) (print element *trace-output*) (princ element) (when (intersection '(:bc :ac) (first entry)) (terpri))))))) (cond ((member (element-tag element) '(:foreign :definition :comment) :test (function string-equal)) #|ignore|#) ((member (element-tag element) '(:pre :quote :address) :test (function string-equal)) (let ((*pre* t)) (write-it))) (t (write-it))))))) (defun write-children-text (self) (dolist (child (element-children self)) (write-text child))) (defun write-nothing (self) (declare (ignore self)) (values)) (defun write-title (self line-char &optional abovep) (let* ((title (remove #\newline (with-output-to-string (*standard-output*) (write-children-text self)))) (line (make-string (length title) :initial-element line-char))) (terpri) (terpri) (when abovep (princ line) (terpri)) (princ title) (terpri) (princ line) (terpri) (terpri))) (defun write-indented-children (self) (dolist (line (split-string (with-output-to-string (*standard-output*) (write-children-text self)) #(#\newline))) (princ " ") (princ line) (terpri))) (defun write-parenthesized-children (self left right) (princ left) (write-children-text self) (princ right)) (defmacro define-element-writer (tag nls &body body) `(progn (setf (gethash (intern (string-upcase ,(symbol-name tag)) *tag-package*) *nl*) (list ',nls ,(case (first body) ((:children) `(function write-children-text)) ((:skip) `(function write-nothing)) (otherwise `(lambda (self) (block ,tag ,@body)))))) ',tag)) ;; ^ <a>^ x^ </a>^ ;; :bo :ao :bc :ac (define-element-writer a () :children) (define-element-writer abbr () :children) (define-element-writer acronym () :children) (define-element-writer address (:bo :ac) :children) (define-element-writer applet (:bo :ao :bc :ac) :skip) (define-element-writer area (:bo :ac) :children) (define-element-writer b () (write-parenthesized-children self "**" "**")) (define-element-writer base () :children) (define-element-writer basefont () :children) (define-element-writer bdo () :children) (define-element-writer big () :children) (define-element-writer blockquote (:bo :ao :bc :ac) (write-indented-children self)) (define-element-writer body (:bo :ao :bc :ac) :children) (define-element-writer br (:bo :ac) (terpri) (write-children-text self)) (define-element-writer button (:bo :ac) :children) (define-element-writer center (:bo :ac) :children) (define-element-writer cite () :children) (define-element-writer code () (write-parenthesized-children self "`" "`")) (define-element-writer del () :children) (define-element-writer dfn () :children) (define-element-writer dir () :children) (define-element-writer div (:bo :ac) :children) (define-element-writer em () (write-parenthesized-children self "*" "*")) (define-element-writer fieldset () :children) (define-element-writer font () :children) (define-element-writer form (:bo :ao :bc :ac) :children) (define-element-writer frame (:bo :ao :bc :ac) :children) (define-element-writer frameset (:bo :ao :bc :ac) :children) (define-element-writer h1 (:bo :ac) (write-title self #\#)) (define-element-writer h2 (:bo :ac) (write-title self #\*)) (define-element-writer h3 (:bo :ac) (write-title self #\=)) (define-element-writer h4 (:bo :ac) (write-title self #\-)) (define-element-writer h5 (:bo :ac) (write-title self #\^)) (define-element-writer h6 (:bo :ac) (write-title self #\.)) (define-element-writer head (:bo :ao :bc :ac) :children) (define-element-writer hr (:bo :ac) (terpri) (princ (make-string 78 :initial-element #\-)) (terpri) (write-children-text self)) (define-element-writer html (:bo :ao :bc :ac) :children) (define-element-writer i () (write-parenthesized-children self "/" "/")) (define-element-writer iframe (:bo :ao :bc :ac) :children) (define-element-writer img (:bo :ac) (let ((alt (attribute-named self :alt))) (when alt (princ alt)))) (define-element-writer input (:bo :ac) :children) (define-element-writer ins () :children) (define-element-writer isindex () :children) (define-element-writer kbd () (write-parenthesized-children self "[" "]")) (define-element-writer label () :children) (define-element-writer legend () :children) (define-element-writer link (:bo :ac) :children) (define-element-writer map (:bo :ao :bc :ac) :children) (define-element-writer menu (:bo :ao :bc :ac) :children) (define-element-writer meta (:bo :ac) :children) (define-element-writer noframes (:bo :ao :bc :ac) :children) (define-element-writer noscript (:bo :ao :bc :ac) :children) (define-element-writer object (:bo :ao :bc :ac) :children) (define-element-writer optgroup (:bo :ao :bc :ac) :children) (define-element-writer option (:bo :ac) :children) (define-element-writer p (:bo :ac) (terpri) (terpri) (write-children-text self)) (define-element-writer param (:bo :ac) :children) (define-element-writer pre (:bo :ac) (terpri) (princ "::") (terpri) (terpri) (write-indented-children self) (terpri) (terpri)) (define-element-writer q () :children) (define-element-writer s () :children) (define-element-writer samp () :children) (define-element-writer script (:bo :ao :bc :ac) :skip) (define-element-writer select (:bo :ao :bc :ac) :children) (define-element-writer small () :children) (define-element-writer span () :children) (define-element-writer strike () :children) (define-element-writer strong () (write-parenthesized-children self "**" "**")) (define-element-writer style (:bo :ac) :children) (define-element-writer sub () :children) (define-element-writer sup () :children) (define-element-writer textarea (:bo :ac) :children) (define-element-writer title (:bo :ac) (write-title self #\# t)) (define-element-writer tt () (write-parenthesized-children self "`" "`")) (define-element-writer u () :children) (define-element-writer var () :children) (defvar *ol-index* nil) (defvar *ol-stack* '()) (define-element-writer dl (:bo :ac) (push *ol-index* *ol-stack*) (setf *ol-index* nil) (terpri) (write-children-text self) ) (define-element-writer dt (:bo) (terpri) (write-children-text self)) (define-element-writer dd (:bo) (terpri) (write-indented-children self)) (define-element-writer ol (:bo :ao :bc :ac) (push *ol-index* *ol-stack*) (setf *ol-index* 0) (terpri) (write-children-text self) ) (define-element-writer ul (:bo :ao :bc :ac) (push *ol-index* *ol-stack*) (setf *ol-index* nil) (terpri) (write-children-text self)) (define-element-writer li (:bo :ac) (if (integerp *ol-index*) (format t "~%~D. " (incf *ol-index*)) (format t "~%- ")) (write-indented-children self)) (defvar *row-kind* :body) (defstruct row kind tag attributes cells) (defstruct cell attributes lines) (defun collect-table-cells (element) (when (listp element) (case (element-tag element) ((:table) (let ((*row-kind* :body) (rows '())) (dolist (child (element-children element) rows) (when (listp child) (case (element-tag child) ((:thead :tbody) (appendf rows (collect-table-cells child))) ((:th :tr) (appendf rows (list (collect-table-cells child)))) ((:caption :col :colgroup) #| ignore for now |#) (otherwise (warn "Stray element in table: ~S" element))))))) ((:thead) (let ((*row-kind* :head)) (collect-table-cells element))) ((:tbody) (let ((*row-kind* :body)) (collect-table-cells element))) ((:th :tr) (make-row :kind *row-kind* :tag (element-tag element) :attributes (element-attributes element) :cells (mapcar (function collect-table-cells) (remove-if-not (lambda (element) (and (listp element) (eql :td (element-tag element)))) (element-children element))))) ((:td) (make-cell :attributes (element-attributes element) :lines (split-string (with-output-to-string (*standard-output*) (write-children-text element)) #(#\newline)))) (otherwise (warn "Stray element in table: ~S" element) nil)))) (defun compute-max-widths (rows) (reduce (lambda (widths cells) (loop :for width :in widths :for current-cells = cells :then (cdr current-cells) :for cell = (car current-cells) :collect (if cell (reduce (function max) (mapcar (function length) (cell-lines cell)) :initial-value width) width))) rows :key (function row-cells) :initial-value (make-list (reduce (function max) (mapcar (compose length row-cells) rows)) :initial-element 0))) (defun generate-line (widths) (with-output-to-string (*standard-output*) (princ "+") (dolist (width widths) (princ (make-string (+ 2 width) :initial-element #\-)) (princ "+")) (terpri))) (defun generate-control-string (widths) (format nil "~~{|~:{ ~~:[~A~~;~~:*~~~DA~~] |~}~~%~~}" (mapcar (lambda (width) (list (make-string width :initial-element #\space) width)) widths))) (define-element-writer table (:bo :ao :bc :ac) ;; TODO: deal with colspan, rowspan. (let* ((*row-kind* :table) (rows (collect-table-cells self)) (widths (compute-max-widths rows)) (line (generate-line widths)) (cstr (generate-control-string widths))) (terpri) (princ line) (loop :for cells :in (mapcar (lambda (row) (mapcar (function cell-lines) (row-cells row))) rows) :unless (null cells) :do (loop :for data = (loop :for current :on cells :collect (pop (car current))) :do (format t cstr data) :while (some (function identity) cells) :finally (princ line))))) (define-element-writer caption () :children) (define-element-writer colgroup () :children) (define-element-writer col () :children) (define-element-writer thead (:bo :ao :bc :ac) :children) (define-element-writer tfoot (:bo :ao :bc :ac) :children) (define-element-writer tbody (:bo :ao :bc :ac) :children) (define-element-writer tr (:bo :ac) :children) (define-element-writer th (:bo :ac) :children) (define-element-writer td (:bo :ac) :children) (defun write-html-text (html &optional (stream *standard-output*)) "Writes on STREAM a textual rendering of the HTML. Some reStructuredText formating is used. Simple tables are rendered, but colspan and rowspan are ignored. " (let ((*standard-output* stream)) (if (string-equal (element-tag html) :document) (dolist (child (element-children html)) (write-text child)) (write-text html)))) (defun tag-case (tag) (let ((stag (string tag))) (if (every (lambda (ch) (if (alpha-char-p ch) (upper-case-p ch) t)) stag) (string-downcase stag) stag))) (defun unparse-html (html &optional (stream *standard-output*)) "Writes back on STREAM the reconstituted HTML source." (let ((package *package*)) (with-standard-io-syntax (let ((*package* package)) (cond ((atom html) (format stream "~A" html)) ((string-equal (element-tag html) :document) ;; (:document nil …) (dolist (child (element-children html)) (unparse-html child stream))) ((string-equal (element-tag html) :foreign) ;; (:foreign nil "<?xml version=\"1.0\" encoding=\"utf-8\" ?>") (format stream "~&~{~A~}~%" (element-children html))) ((string-equal (element-tag html) :comment) ;; (:foreign nil "<?xml version=\"1.0\" encoding=\"utf-8\" ?>") (format stream "~&<!--~{~A~}-->~%" (element-children html))) ((string-equal (element-tag html) :definition) ;; (:definition () :doctype "html" "PUBLIC" "-//W3C//DTD XHTML 1.0 Transitional//EN" ;; "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd") (format stream "~&<!~{~A~^ ~}>~%" (cddr html))) (t (let ((nl (first (gethash (element-key html) *nl*)))) (format stream "~:[~;~&~]<~A~{ ~A=~S~}>~:[~;~&~]" (member :bo nl) (tag-case (element-tag html)) (loop :for (attr val) :on (element-attributes html) :by (function cddr) :nconc (list (tag-case attr) val)) (member :ao nl)) (dolist (child (element-children html)) (unparse-html child stream)) (format stream "~:[~;~&~]</~A>~:[~;~&~]" (member :bc nl) (tag-case (element-tag html)) (member :ac nl))))))))) ;;;; THE END ;;;;
47,981
Common Lisp
.lisp
958
38.72547
340
0.51347
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
1f1b8580fe6e8ee86f8752b6f2bac807e90cfa76606bb8db581f3c8dc2c3ce7c
4,989
[ -1 ]
4,990
com.informatimago.common-lisp.html-parser.asd
informatimago_lisp/common-lisp/html-parser/com.informatimago.common-lisp.html-parser.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.html-parser.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.html-parser library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.html-parser" ;; system attributes: :description "Informatimago Common Lisp HTML 4.01 Parser" :long-description " A simple HTML 4.01 parser. " :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.4.0" :properties ((#:author-email . "[email protected]") (#:date . "Autumn 2010") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.html-parser/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.html-base") :components ((:file "parse-html" :depends-on ())) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.html-parser.test")))) ;;;; THE END ;;;;
2,659
Common Lisp
.lisp
57
43.280702
115
0.595458
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
f1178a153687bff371ee2f78ee757b7021814a1fd90d731d9dc7be7051ae937d
4,990
[ -1 ]
4,991
apple-file.lisp
informatimago_lisp/common-lisp/apple-file/apple-file.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: apple-file.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Implements a codecs for AppleSingle and AppleDouble file formats. ;;;; http://kaiser-edv.de/documents/AppleSingle_AppleDouble.pdf ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2013-05-08 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2013 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.APPLE-FILE.APPLE-FILE" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.UTILITY" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.INDEX-SET") (:shadowing-import-from "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.INDEX-SET" "INCLUDE""MERGE""UNION""INTERSECTION") (:export "APPLE-FILE-REAL-NAME" "APPLE-FILE-COMMENT" "APPLE-FILE-ICON-B&W" "APPLE-FILE-ICON-COLOR" "APPLE-FILE-CREATION-DATE" "APPLE-FILE-MODIFICATION-DATE" "APPLE-FILE-BACKUP-DATE" "APPLE-FILE-ACCESS-DATE" "APPLE-FILE-FINDER-CREATOR" "APPLE-FILE-FINDER-TYPE" "APPLE-FILE-FINDER-LOCATION" "APPLE-FILE-FINDER-ICON-ID" "APPLE-FILE-FINDER-FOLDER" "APPLE-FILE-FINDER-PUT-AWAY-FOLDER" "APPLE-FILE-MACINTOSH-PROTECTED" "APPLE-FILE-MACINTOSH-LOCKED" "APPLE-FILE-PRODOS-ACCESS" "APPLE-FILE-PRODOS-TYPE" "APPLE-FILE-PRODOS-AUXILIARY-TYPE" "APPLE-FILE-MSDOS-ATTRIBUTES" "APPLE-FILE-AFP-BACKUP-NEEDED" "APPLE-FILE-AFP-SYSTEM" "APPLE-FILE-AFP-MULTI-USER" "APPLE-FILE-AFP-INVISIBLE" "APPLE-FILE-AFP-DIRECTORY-ID")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.APPLE-FILE.APPLE-FILE") (deftype octet () '(unsigned-byte 8)) (defun equal-type (a b) (and (subtypep a b) (subtypep b a))) ;;---------------------------------------------------------------------- ;; Apple Single & Apple Double File Format ;;---------------------------------------------------------------------- (defconstant +apple-format-version+ #x00020000) (defconstant +apple-single-magic-number+ #x00051600) (defconstant +apple-double-magic-number+ #x00051607) (defenum predefined-entry-id (data-fork-id 1) resource-fork-id real-name comment icon-b&w icon-color (file-dates-info 8) finder-info macintosh-file-info prodos-file-info msdos-file-info short-name afp-file-info directory-id) (defparameter *symbolic-entry-ids* #(nil :data-fork-id :resource-fork-id :real-name :comment :icon-b&w :icon-color nil :file-dates-info :finder-info :macintosh-file-info :prodos-file-info :msdos-file-info :short-name :afp-file-info :directory-id)) (defun symbolicate-entry-id (entry-id) (when (<= 0 entry-id (1- (length *symbolic-entry-ids*))) (aref *symbolic-entry-ids* entry-id))) (defclass apple-file () ((kind :initform :apple-single :initarg :kind :accessor header-kind :reader apple-file-header-kind :type (member :apple-single :apple-double :apple-triple)) (magic :initform 0 :initarg :magic :accessor header-magic :reader apple-file-header-magic) (version :initform 0 :initarg :version :accessor header-version :reader apple-file-header-version) (entries :initform '() :initarg :entries :accessor header-entries :reader apple-file-header-entries) (info-stream :initform nil :initarg :info-stream :accessor header-info-stream :reader apple-file-info-stream) (direction :initform :input :initarg :direction :reader apple-file-direction))) (defstruct entry kind id offset length decoded) (defstruct (file-dates-info (:conc-name file-)) creation-date modification-date backup-date access-date) (defstruct finder-info type creator flags location.y location.x folder icon-id script xflags comment-id put-away-folder) (defstruct (macintosh-file-info (:conc-name file-)) protected locked) (defstruct (prodos-file-info (:conc-name file-)) access type auxiliary-type) (defstruct (msdos-file-info (:conc-name file-)) msdos-attributes) (defstruct (afp-file-info (:conc-name file-)) backup-needed system multi-user invisible directory-id) (defun get-ubyte (bytes offset) (aref bytes offset)) (defun get-ushort (bytes offset) (let ((hi (aref bytes offset)) (lo (aref bytes (1+ offset)))) (+ (ash hi 8) lo))) (defun get-u3bytes (bytes offset) (let ((hi (aref bytes offset)) (mi (aref bytes (+ 1 offset))) (lo (aref bytes (+ 2 offset)))) (+ (ash (+ (ash hi 8) mi) 8) lo))) (defun get-ulong (bytes offset) (let ((hi (get-ushort bytes offset)) (lo (get-ushort bytes (+ offset 2)))) (+ (ash hi 16) lo))) (defun get-byte (bytes offset) (let ((ubyte (get-ubyte bytes offset))) (if (< ubyte #x80) ubyte (- ubyte #x100)))) (defun get-short (bytes offset) (let ((ushort (get-ushort bytes offset))) (if (< ushort #x8000) ushort (- ushort #x10000)))) (defun get-long (bytes offset) (let ((ulong (get-ulong bytes offset))) (if (< ulong #x80000000) ulong (- ulong #x100000000)))) (defun read-ushort (stream) (let ((hi (read-byte stream)) (lo (read-byte stream))) (+ (ash hi 8) lo))) (defun read-ulong (stream) (let ((hi (read-ushort stream)) (lo (read-ushort stream))) (+ (ash hi 16) lo))) (defgeneric decode-entry-data (kind data)) (defun check-ranges (header) (let ((file-set (make-instance 'index-set)) (entry-set (make-instance 'index-set))) (dolist (entry (header-entries header)) (assign-empty entry-set) (include entry-set (make-range :start (entry-offset entry) :count (entry-length entry))) (if (emptyp (intersection 'index-set file-set entry-set)) (merge file-set entry-set) (report-collision header entry))))) (defun report-collision (header entry) (declare (ignore entry)) ;; TODO: (error "Some entries collide in ~S." header)) (defun read-header (stream kind) (check-type stream file-stream) (assert (equal-type 'octet (stream-element-type stream))) (let ((magic (read-ulong stream)) (expected-magic (ecase kind (:apple-single +apple-single-magic-number+) (:apple-double +apple-double-magic-number+)))) (assert (= magic expected-magic)) (let ((version (read-ulong stream))) (assert (= version +apple-format-version+))) (loop :repeat 16 :do (read-byte stream)) (let* ((entry-count (read-ushort stream)) (header (make-instance 'apple-file :kind kind :magic magic :version +apple-format-version+ :entries (loop :repeat entry-count :collect (let* ((entry-id (read-ulong stream)) (offset (read-ulong stream)) (length (read-ulong stream)) (kind (symbolicate-entry-id entry-id)) (entry (make-entry :kind kind :id entry-id :offset offset :length length))) entry)) :info-stream stream))) (dolist (entry (header-entries header)) (when (entry-kind entry) (setf (entry-decoded entry) (decode-entry-data (entry-kind entry) (read-entry-data stream entry))))) header))) (defun read-entry-data (stream entry) (file-position stream (entry-offset entry)) (let ((data (make-array (entry-length entry) :element-type 'octet))) (let ((read-size (read-sequence data stream))) (assert (= (entry-length entry) read-size) () "entry-length=~A read-size=~A" (entry-length entry) read-size) data))) (defmethod decode-entry-data ((kind (eql :data-fork-id)) data) data) (defmethod decode-entry-data ((kind (eql :resource-fork-id)) data) (warn "TBD decode-entry-data :resource-fork-id") data) (defmethod decode-entry-data ((kind (eql :real-name)) data) (map 'string (function code-char) data)) (defmethod decode-entry-data ((kind (eql :short-name)) data) (map 'string (function code-char) data)) (defmethod decode-entry-data ((kind (eql :comment)) data) (map 'string (function code-char) data)) (defmethod decode-entry-data ((kind (eql :icon-b&w)) data) data) (defmethod decode-entry-data ((kind (eql :icon-color)) data) data) (defun to-lisp-date (macdate) (+ macdate (load-time-value (encode-universal-time 0 0 0 1 1 2000 0)))) (defun to-mac-date (universal-time) (- universal-time (load-time-value (encode-universal-time 0 0 0 1 1 2000 0)))) (defmethod decode-entry-data ((kind (eql :file-dates-info)) data) (make-file-dates-info :creation-date (to-lisp-date (get-long data 0)) :modification-date (to-lisp-date (get-long data 4)) :backup-date (to-lisp-date (get-long data 8)) :access-date (to-lisp-date (get-long data 12)))) (defun decode-fdflag (word) (append (loop :for (key flag) :in '((:is-alias 15) (:is-invisible 14) (:has-bundle 13) (:name-locked 12) (:is-stationery 11) (:has-custom-icon 10) (:has-been-inited 8) (:has-no-inits 7) (:is-shared 6)) :when (logbitp flag word) :collect key :when (logbitp flag word) :collect t) (list :label (case (ldb (byte 3 1) word) (0 nil) (1 :red) (2 :orange) (3 :yellow) (4 :green) (5 :blue) (6 :violet) (7 :gray))))) (defmethod decode-entry-data ((kind (eql :finder-info)) data) (let ((fdtype (get-ulong data 0)) (fdcreator (get-ulong data 4)) (fdflags (decode-fdflag (get-ushort data 8))) (fdlocation.y (get-short data 10)) (fdlocation.x (get-short data 12)) (fdfolder (get-short data 14)) (fdiconid (get-short data 16)) (fdscript (get-byte data 24)) (fdxflags (get-byte data 25)) (fdcomment (get-short data 26)) (fdputaway (get-long data 28))) (make-finder-info :type fdtype :creator fdcreator :flags fdflags :location.y fdlocation.y :location.x fdlocation.x :folder fdfolder :icon-id fdiconid :script fdscript :xflags fdxflags :comment-id fdcomment :put-away-folder fdputaway))) (defmethod decode-entry-data ((kind (eql :macintosh-file-info)) data) (let ((flag (get-ulong data 0))) (make-macintosh-file-info :protected (logbitp 1 flag) :locked (logbitp 0 flag)))) (defmethod decode-entry-data ((kind (eql :prodos-file-info)) data) (make-prodos-file-info :access (get-ushort data 0) :type (get-ushort data 2) :auxiliary-type (get-ulong data 4))) (defmethod decode-entry-data ((kind (eql :msdos-file-info)) data) (make-msdos-file-info :msdos-attributes (get-ushort data 0))) (defmethod decode-entry-data ((kind (eql :afp-file-info)) data) (let ((flag (get-ulong data 0))) (make-afp-file-info :backup-needed (logbitp 6 flag) :system (logbitp 2 flag) :multi-user (logbitp 1 flag) :invisible (logbitp 0 flag)))) (defmethod decode-entry-data ((kind (eql :directory-id)) data) (get-ulong data 0)) ;;---------------------------------------------------------------------- ;; Resources ;;---------------------------------------------------------------------- (defenum system-resource-type-id DRVR-id WDEF-id MDEF-id CDEF-id PDEF-id PACK-id reserved-6-id reserved-7-id) (defun make-owned-system-resource-id (resource-type-id owner-id sub-id) (dpb sub-id (byte 5 0) (dpb owner-id (byte 6 5) (dpb resource-type-id (byte 3 11) #xc000)))) (defun owned-system-resource-id-p (id) (= (ldb (byte 2 14) id) 3)) (defun owned-system-resource-type-id (id) (ldb (byte 3 11) id)) (defun owned-system-resource-owner-id (id) (ldb (byte 6 5) id)) (defun owned-system-resource-sub-id (id) (ldb (byte 5 0) id)) ;; (owned-system-resource-id-p #xd182) ;; (owned-system-resource-sub-id #xd182) ;; (owned-system-resource-owner-id #xd182) ;; (owned-system-resource-type-id #xd182) (defenum resource-attributes (res-sys-heap 64) (res-purgeable 32) (res-locked 16) (res-protected 8) (res-preload 4) (res-changed 2)) (defun decode-resource-attributes (attributes) (loop :for key :in '(:changed :preload :protected :locked :purgeable :system-heap) :for bit = 2 :then (* 2 bit) :unless (zerop (logand bit attributes)) :collect key)) ;; header 16 byte ;; resreved 112 bytes ;; application data 128 bytes ;; resource data ;; resource map (defstruct resource-header data-offset map-offset data-length map-length resource) (defun resource-header (resource-data) (make-resource-header :resource resource-data :data-offset (get-ulong resource-data 0) :map-offset (get-ulong resource-data 4) :data-length (get-ulong resource-data 8) :map-length (get-ulong resource-data 12))) (defun resource-application-data (resource-header) (subseq (resource-header-resource resource-header) 128 256)) ;; (defun resource-list (resource-header) ;; (let* ((start (resource-header-data-offset resource-header)) ;; (end (+ start (resource-header-data-length resource-header))) ;; (resource (resource-header-resource resource-header))) ;; (loop ;; :while (< start end) ;; :for resource-length = (get-ulong resource start) ;; :collect (subseq resource (+ 4 start) (+ 4 start resource-length))))) (defstruct resource-map file-attributes type-list-offset ; offsets from start of resource-header name-list-offset) (defstruct resource type id name attributes data) (defun get-resource-name (resource name-list-offset offset) (when (/= -1 offset) (loop :with len = (aref resource (+ name-list-offset offset)) :with name = (make-array len :element-type 'character) :for i :below len :for ch = (code-char (aref resource (+ name-list-offset offset i 1))) :do (setf (aref name i) ch) :finally (return name)))) (defun get-resource-data (resource start) (let ((len (get-ulong resource start))) (subseq resource (+ start 4) (+ start 4 len)))) (defun resources (resource-header) (assert (<= 28 (resource-header-map-length resource-header))) (let* ((start (resource-header-map-offset resource-header)) (end (+ start (resource-header-map-length resource-header))) (resource (resource-header-resource resource-header)) ;; (file-attributes (get-ushort resource (+ start 22))) (type-list-offset (+ start (get-short resource (+ start 24)))) (name-list-offset (+ start (get-short resource (+ start 26)))) (data-offset (resource-header-data-offset resource-header))) (loop :repeat (1+ (get-ushort resource type-list-offset)) :for type-offset :from (+ type-list-offset 2) :by 8 :while (< type-offset end) :collect (let ((resource-type (get-ulong resource type-offset)) (resource-count (1+ (get-ushort resource (+ type-offset 4)))) (resource-offset (+ type-list-offset (get-short resource (+ type-offset 6))))) (loop :repeat resource-count :for reference-offset :from resource-offset :by 12 :collect (make-resource :type resource-type :id (get-ushort resource reference-offset) :name (get-resource-name resource name-list-offset (get-short resource (+ reference-offset 2))) :attributes (decode-resource-attributes (aref resource (+ reference-offset 4))) :data (get-resource-data resource (+ data-offset (get-u3bytes resource (+ reference-offset 5)))))))))) ;; (defvar resource-file #(0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 30 84 104 105 115 32 114 101 115 111 117 114 99 101 32 102 111 114 107 32 105 110 116 101 110 116 105 111 110 97 108 108 121 32 108 101 102 116 32 98 108 97 110 107 32 32 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 30 0 0 0 0 0 0 0 0 0 28 0 30 255 255)) ;; (resource-header resource-file) ;; (resource-list (resource-header resource-file)) ;; (resources (resource-header resource-file)) ;; (resources (resource-header (header-) resource-file)) ;; (let ((resources (resources (resource-header (entry-decoded ;; (find :resource-fork-id ;; (header-entries (with-open-file (stream (first (directory #P"/home/pjb/works/patchwork/examples/B/._*.*")) ;; :element-type 'octet) ;; (read-header stream :apple-double))) ;; ;; :key (function entry-kind))))))) ;; (mapcar (lambda (resources) ;; (mapcar (lambda (resource) ;; (format-signature (resource-type resource))) ;; resources)) ;; resources)) ;; (("FRED" "FRED") ("MPSR")) ;; ((#S(resource :type 1179796804 :id 2 :name nil :attributes nil :data #(0 1 0 4 9 0 1 0 0 0)) ;; #S(resource :type 1179796804 :id 3 :name nil :attributes nil :data #(0 0 6 77 111 110 97 99 111))) ;; (#S(resource :type 1297109842 :id 1005 :name nil :attributes nil :data #(0 9 77 111 110 97 99 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 8 0 44 0 6 1 240 2 168 0 44 0 6 1 240 2 168 0 0 0 0 0 0 0 188 0 0 0 188 0 0 0 0 1 0)))) ;; ;; (map 'string 'code-char #(0 0 6 77 111 110 97 99 111)) ;;---------------------------------------------------------------------- ;; APPLE-FILE ;;---------------------------------------------------------------------- (define-condition file-type-error (simple-error) ()) (defgeneric apple-file-fork-pathname (path format fork) (:documentation " RETURN: the pathname of the specified FORK of the file at PATH, assuming a file in FORMAT. PATH: A pathname designator. FORMAT: (member :apple-single :apple-double :apple-triple) FORK: (member :info :data :resource) ") (:method ((apple-file apple-file) format fork) (apple-file-fork-pathname (apple-file-info-stream apple-file) format fork)) (:method ((stream file-stream) format fork) (apple-file-fork-pathname (pathname stream) format fork)) (:method ((path string) format fork) (apple-file-fork-pathname (pathname path) format fork)) (:method ((info-path pathname) (format (eql :apple-single)) fork) (declare (ignore fork)) info-path) (:method ((info-path pathname) (format (eql :apple-double)) fork) (let ((name (pathname-name info-path))) (ecase fork ((:info :resource) (if (string= "._" name :end2 (min 2 (length name))) info-path (make-pathname :name (format nil "._~A" name) :defaults info-path))) ((:data) (if (string= "._" name :end2 (min 2 (length name))) (make-pathname :name (subseq name 2) :defaults info-path) info-path))))) (:method ((info-path pathname) (format (eql :apple-triple)) fork) (make-pathname :type (ecase fork ((:info) "info") ((:data) "data") ((:resource) "rsrc")) :case :local :defaults info-path))) (defun tree-structure-and-leaf-difference (a b &key (test (function eql))) (cond ((and (null a) (null b)) '=) ((or (null a) (null b)) `(/= ,a ,b)) ((and (atom a) (atom b)) (if (funcall test a b) '= `(/= ,a ,b))) ((or (atom a) (atom b)) `(/= ,a ,b)) (t (cons (tree-structure-and-leaf-difference (car a) (car b) :test test) (tree-structure-and-leaf-difference (cdr a) (cdr b) :test test))))) ;; (open-apple-file pathname) --> apple-file ;; (close-apple-file apple-file) ;; (apple-file-data-fork-stream apple-file :direction :external-format :element-type :if-does-not-exist :if-exists) --> stream ;; (apple-file-resource-fork-stream apple-file :direction :if-does-not-exist :if-exists) --> stream ;; (apple-file-resources apple-file) --> resources (defun open-apple-file (pathname &key (direction :input) (if-does-not-exist :error)) (assert (eq direction :input) () "non :input direction not supported yet.") (flet ((get-header (info-path format) (let* ((stream (open info-path :direction :input :if-does-not-exist nil :element-type 'octet)) (header (when stream (file-position stream 0) (ignore-errors (read-header stream format))))) (when header (setf (header-info-stream header) stream)) header))) (let ((header (or (get-header (apple-file-fork-pathname pathname :apple-single :info) :apple-single) (get-header (apple-file-fork-pathname pathname :apple-double :info) :apple-double) (get-header (apple-file-fork-pathname pathname :apple-triple :info) :apple-triple)))) (if header (make-instance 'apple-file :header header :info-stream (header-info-stream header) :direction direction) (case if-does-not-exist (:error (error 'file-error :pathname pathname)) (otherwise if-does-not-exist)))))) (defgeneric close-apple-file (apple-file) (:method ((apple-file apple-file)) (close (header-info-stream apple-file)))) (defun apple-file-data-fork (apple-file &key (direction :input) (external-format :default) (element-type 'character) (if-does-not-exist :error) if-exists) (let ((data-path (apple-file-fork-pathname apple-file (apple-file-header-kind apple-file) :data)) (info-path (apple-file-fork-pathname apple-file (apple-file-header-kind apple-file) :info))) (if (equalp data-path info-path) (error "~S not implemented for apple-triple files yet." 'apple-file-data-fork) (open data-path :direction direction :external-format external-format :element-type element-type :if-does-not-exist if-does-not-exist :if-exists if-exists)))) (defun apple-file-resource-fork (apple-file) (declare (ignore apple-file)) (error "~S not implemented yet" 'apple-file-resource-fork)) ;;---------------------------------------------------------------------- ;; APPLE-FILE attributes ;;---------------------------------------------------------------------- (defmacro define-attribute (name entry-key docstring &rest readers) (labels ((wrap-readers (readers form) (if (null readers) form (wrap-readers (rest readers) `(,(first readers) ,form))))) `(defun ,name (apple-file) ,docstring (let ((entry (find ,entry-key (header-entries apple-file) :key (function entry-kind)))) (when entry ,(wrap-readers readers '(entry-decoded entry))))))) (defun format-signature (signature) (format nil "~C~C~C~C" (code-char (ldb (byte 8 24) signature)) (code-char (ldb (byte 8 16) signature)) (code-char (ldb (byte 8 8) signature)) (code-char (ldb (byte 8 0) signature)))) (defun and-format-signature (creator) (values creator (format-signature creator))) (defun location-x-y (finfo) (cons (finder-info-location.x finfo) (finder-info-location.y finfo))) (define-attribute apple-file-real-name :real-name "RETURN: NIL or the real name string in the APPLE-FILE.") (define-attribute apple-file-comment :comment "RETURN: NIL or the comment string in the APPLE-FILE.") (define-attribute apple-file-icon-b&w :icon-b&w "RETURN: NIL or the black & white icon data (byte vector) in the APPLE-FILE.") (define-attribute apple-file-icon-color :icon-color "RETURN: NIL or the color icon data (byte vector) in the APPLE-FILE.") (define-attribute apple-file-creation-date :file-dates-info "RETURN: NIL or the creation date (lisp universal-time) in the APPLE-FILE." file-creation-date) (define-attribute apple-file-modification-date :file-dates-info "RETURN: NIL or the modification date (lisp universal-time) in the APPLE-FILE." file-modification-date) (define-attribute apple-file-backup-date :file-dates-info "RETURN: NIL or the backup date (lisp universal-time) in the APPLE-FILE." file-backup-date) (define-attribute apple-file-access-date :file-dates-info "RETURN: NIL or the access date (lisp universal-time) in the APPLE-FILE." file-access-date) (define-attribute apple-file-finder-creator :finder-info "RETURN: NIL or the creator (as integer and as string) of the APPLE-FILE." finder-info-creator and-format-signature) (define-attribute apple-file-finder-type :finder-info "RETURN: NIL or the type (as integer and as string) of the APPLE-FILE." finder-info-type and-format-signature) (define-attribute apple-file-finder-location :finder-info "RETURN: NIL or the X, Y coordinates of the icon of the APPLE-FILE." location-x-y) (define-attribute apple-file-finder-icon-id :finder-info "RETURN: NIL or the icon ID of the APPLE-FILE." finder-info-icon-id) (define-attribute apple-file-finder-folder :finder-info "RETURN: NIL or the folder ID of the APPLE-FILE." finder-info-folder) (define-attribute apple-file-finder-put-away-folder :finder-info "RETURN: NIL or the put away folder ID of the APPLE-FILE." finder-info-put-away-folder) (define-attribute apple-file-macintosh-protected :macintosh-file-info "RETURN: NIL or the protected flag of the APPLE-FILE." file-protected) (define-attribute apple-file-macintosh-locked :macintosh-file-info "RETURN: NIL or the locked flag of the APPLE-FILE." file-locked) (define-attribute apple-file-prodos-access :prodos-file-info "RETURN: NIL or the PRODOS access code of the APPLE-FILE." file-access) (define-attribute apple-file-prodos-type :prodos-file-info "RETURN: NIL or the PRODOS type code of the APPLE-FILE." file-type) (define-attribute apple-file-prodos-auxiliary-type :prodos-file-info "RETURN: NIL or the PRODOS auxiliary type code of the APPLE-FILE." file-auxiliary-type) (define-attribute apple-file-msdos-attributes :msdos-file-info "RETURN: NIL or the MSDOS attributes of the APPLE-FILE." file-msdos-attributes) (define-attribute apple-file-afp-backup-needed :afp-file-info "RETURN: NIL or the AFP backup needed flag of the APPLE-FILE." file-backup-needed) (define-attribute apple-file-afp-system :afp-file-info "RETURN: NIL or the AFP system flag of the APPLE-FILE." file-system) (define-attribute apple-file-afp-multi-user :afp-file-info "RETURN: NIL or the AFP multi-user flag of the APPLE-FILE." file-multi-user) (define-attribute apple-file-afp-invisible :afp-file-info "RETURN: NIL or the AFP invisible flag of the APPLE-FILE." file-invisible) (define-attribute apple-file-afp-directory-id :afp-file-info "RETURN: NIL or the AFP directory ID of the APPLE-FILE." file-directory-id) ;;---------------------------------------------------------------------- ;; ;;---------------------------------------------------------------------- (defun lsattr (path) (format t "~A attributes:~%" path) (with-open-file (stream path :element-type 'octet) (let ((header (read-header stream :apple-double))) (dolist (attribute '(apple-file-real-name apple-file-comment apple-file-icon-b&w apple-file-icon-color apple-file-creation-date apple-file-modification-date apple-file-backup-date apple-file-access-date apple-file-finder-creator apple-file-finder-type apple-file-finder-location apple-file-finder-icon-id apple-file-finder-folder apple-file-finder-put-away-folder apple-file-macintosh-protected apple-file-macintosh-locked apple-file-prodos-access apple-file-prodos-type apple-file-prodos-auxiliary-type apple-file-msdos-attributes apple-file-afp-backup-needed apple-file-afp-system apple-file-afp-multi-user apple-file-afp-invisible apple-file-afp-directory-id)) (let ((name (subseq (string-downcase attribute) #.(length "apple-file-"))) (values (multiple-value-list (funcall attribute header)))) (when (first values) (format t "~30A ~{~A~^ ~}~%" name values)))) (let ((resources (resources (resource-header (entry-decoded (find :resource-fork-id (header-entries header) :key (function entry-kind))))))) (dolist (resources resources) (format t "Resource type: ~A" (format-signature (resource-type (first resources)))) (if (string= "STR " (format-signature (resource-type (first resources)))) (dolist (resource resources) (format t "~& ~A[~A]~@[(~A)~]: ~S~%" (resource-id resource) (length (resource-data resource)) (resource-name resource) (map 'string 'code-char (subseq (resource-data resource) 1)))) (dolist (resource resources) (format t " ~A[~A]~@[(~A)~]" (resource-id resource) (length (resource-data resource)) (resource-name resource)))) (terpri))))) (values)) ;; (dolist (path (directory #P"/home/pjb/works/patchwork/examples/B/._*.*")) ;; (lsattr path) ;; (terpri)) ;; (defun make-apple-double-pathname (pathname) ;; (apple-file-fork-pathname pathname :apple-double :info)) ;; (make-apple-double-pathname "toto") ;; ;; (first (directory #P"/home/pjb/works/patchwork/examples/B/._*.*")) ;; #P"/home/pjb/works/patchwork/examples/B/\\._ ''PW-functionals.lib copie" ;; ;; (remove-if-not (function probe-file) ;; ;; (directory #P"/home/pjb/works/patchwork/examples/B/*.*") ;; ;; :key (function make-apple-double-pathname)) ;; (with-open-file (stream #P"/home/pjb/works/patchwork/examples/B/._%désordre" ;; :element-type 'octet) ;; (let ((header (read-header stream :apple-double))) ;; (dolist (entry (header-entries header)) ;; (print (entry-kind entry)) ;; (print (read-entry-data stream entry))))) ;; ;; (with-open-file (stream #P"/home/pjb/works/patchwork/examples/B/._%désordre" ;; :element-type 'octet) ;; (read-header stream :apple-double)) ;; ;; ;; (format-signature 1413830740) ;; ;; "TEXT" ;; ;; (format-signature 1128483890) ;; ;; "CCL2" ;; ;; ;; #S(header :kind :apple-double :magic 333319 :version 131072 ;; :entries (#S(entry :kind :finder-info :id 9 :offset 50 :length 3760 ;; :decoded #S(finder-info :type 1413830740 :creator 1128483890 :flags (:has-been-inited t :label nil) :location.y -1 :location.x -1 :folder 0 :icon-id 0 :script 0 :xflags 0 :comment-id 0 :put-away-folder 23779)) ;; ;; #S(entry :kind :resource-fork-id :id 2 :offset 3810 :length 286 ;; :decoded #(0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 30 84 104 105 115 32 114 101 115 111 117 114 99 101 32 102 111 114 107 32 105 110 116 101 110 116 105 111 110 97 108 108 121 32 108 101 102 116 32 98 108 97 110 107 32 32 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 30 0 0 0 0 0 0 0 0 0 28 0 30 255 255)))) ;;;; THE END ;;;;
36,510
Common Lisp
.lisp
732
41.288251
707
0.570555
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
e2fb76537a5b9f6b1be64c9015c6bdb4e92c323d64cd3ca5d7fe94561bbddda5
4,991
[ -1 ]
4,992
com.informatimago.common-lisp.apple-file.test.asd
informatimago_lisp/common-lisp/apple-file/com.informatimago.common-lisp.apple-file.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.apple-file.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.apple-file.test system. ;;;; Tests the com.informatimago.common-lisp.apple-file system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.apple-file.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.apple-file system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.apple-file.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.apple-file") :components ((:file "apple-file-test" :depends-on nil)) #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) (dolist (p '("COM.INFORMATIMAGO.COMMON-LISP.APPLE-FILE.APPLE-FILE.TEST")) (let ((*package* (find-package p))) (uiop:symbol-call p "TEST/ALL"))))) ;;;; THE END ;;;;
3,021
Common Lisp
.lisp
66
39.848485
101
0.566542
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
01477cf75d12e40e51916dd348d6f87ed4fb659773822b1dbdcb2acea208a62e
4,992
[ -1 ]
4,993
apple-file-test.lisp
informatimago_lisp/common-lisp/apple-file/apple-file-test.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: apple-file-test.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Tests apple-file.lisp. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-02-25 <PJB> Extracted from apple-file.lisp. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.APPLE-FILE.APPLE-FILE.TEST" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.SIMPLE-TEST" "COM.INFORMATIMAGO.COMMON-LISP.APPLE-FILE.APPLE-FILE") (:import-from "COM.INFORMATIMAGO.COMMON-LISP.APPLE-FILE.APPLE-FILE" "APPLE-FILE-FORK-PATHNAME" "TREE-STRUCTURE-AND-LEAF-DIFFERENCE") (:export "TEST/ALL")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.APPLE-FILE.APPLE-FILE.TEST") (define-test test/apple-file-fork-pathname () #+unix (let ((*default-pathname-defaults* #P"/")) (assert-true (tree-structure-and-leaf-difference (mapcar (lambda (format) (mapcar (lambda (fork) (apple-file-fork-pathname (make-pathname :name "test" :type "single" :case :local) format fork)) '(:info :data :resource))) '(:apple-single :apple-double :apple-triple)) (list (list (make-pathname :name "test" :type "single" :case :local) (make-pathname :name "test" :type "single" :case :local) (make-pathname :name "test" :type "single" :case :local)) (list (make-pathname :name "._test" :type "single" :case :local) (make-pathname :name "test" :type "single" :case :local) (make-pathname :name "._test" :type "single" :case :local)) (list (make-pathname :name "test" :type "info" :case :local) (make-pathname :name "test" :type "data" :case :local) (make-pathname :name "test" :type "rsrc" :case :local))) :test 'pathname-match-p)))) (define-test test/all () (test/apple-file-fork-pathname)) ;;;; THE END ;;;;
3,247
Common Lisp
.lisp
68
41.455882
108
0.586066
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
8d2f51c01b115516a8d0f0159d49fd6aa46beeabc94074cf874fb300f75a24a5
4,993
[ -1 ]
4,994
com.informatimago.common-lisp.apple-file.asd
informatimago_lisp/common-lisp/apple-file/com.informatimago.common-lisp.apple-file.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.apple-file.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.apple-file library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2013-05-26 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2013 - 2016 ;;;; ;;;; 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.common-lisp.apple-file" ;; system attributes: :description "Apple-Single and Apple-Double File Formats." :long-description " Read Apple-Single and Apple-Double file formats. " :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Spring 2013") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.apple-file/") ((#: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.common-lisp.cesarum") :components ((:file "apple-file" :depends-on ())) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.apple-file.test")))) ;;;; THE END ;;;;
2,620
Common Lisp
.lisp
56
43.642857
114
0.596875
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
3f0c63e8bea0db3a21e310a2b613c8ed01ec3f9c9573b7e9ee9643713792a790
4,994
[ -1 ]
4,995
com.informatimago.common-lisp.interactive.asd
informatimago_lisp/common-lisp/interactive/com.informatimago.common-lisp.interactive.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.interactive.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.interactive library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.interactive" ;; system attributes: :description "Informatimago Common Lisp Interactive Commands" :long-description " Various interactive commands intended to be used at the REPL, including a file browser, a few unix-like commands (ls, cat, more), CL specific commands such as: mkupack, lspack, pushp, popp, etc. " :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.4.0" :properties ((#:author-email . "[email protected]") (#:date . "Autumn 2010") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.interactive/") ((#: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.common-lisp.cesarum") :components ((:file "browser" :depends-on ()) (:file "interactive" :depends-on ("browser"))) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.interactive.test")))) ;;;; THE END ;;;;
2,836
Common Lisp
.lisp
59
44.779661
115
0.606924
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
cf696d997f2579241d1fd49c904ddeaccf5609fb955d9e875e0e65b37c2b5e54
4,995
[ -1 ]
4,996
browser.lisp
informatimago_lisp/common-lisp/interactive/browser.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: browser.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; See defpackage documentation string. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2021-06-14 <PJB> Added SELECT-WORKING-DIRECTORY. ;;;; 2017-05-27 <PJB> All commands are functions, not macros anymore. ;;;; Renamed DEFCOMMAND -> DEFINE-EXTERNAL-COMMAND. ;;;; 2015-10-10 <PJB> CAT/MORE/LESS can process *STANDARD-INPUT*. ;;;; 2004-11-23 <PJB> Generalized ls formating. ;;;; 2004-09-24 <PJB> Added ls. ;;;; 2004-08-07 <PJB> Added cat, more, and less. ;;;; 2004-06-19 <PJB> Created. ;;;;BUGS ;;;; The syntax of paths given by users is not specified. ;;;; Both logical pathnames and physical pathnames are possible and wackily ;;;; processed... ;;;; ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2004 - 2021 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.INTERACTIVE.BROWSER" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.STRING") #+mocl (:shadowing-import-from "COM.INFORMATIMAGO.MOCL.KLUDGES.MISSING" "*TRACE-OUTPUT*" "*LOAD-VERBOSE*" "*LOAD-PRINT*" "ARRAY-DISPLACEMENT" "CHANGE-CLASS" "COMPILE" "COMPLEX" "ENSURE-DIRECTORIES-EXIST" "FILE-WRITE-DATE" "INVOKE-DEBUGGER" "*DEBUGGER-HOOK*" "LOAD" "LOGICAL-PATHNAME-TRANSLATIONS" "MACHINE-INSTANCE" "MACHINE-VERSION" "NSET-DIFFERENCE" "RENAME-FILE" "SUBSTITUTE-IF" "TRANSLATE-LOGICAL-PATHNAME" "PRINT-NOT-READABLE" "PRINT-NOT-READABLE-OBJECT") (:export "MAKE" "MV" "CP" "RM" "DEFINE-EXTERNAL-COMMAND" "*SHELL*" "LESS" "MORE" "CAT" "LS" "GREP" "MKDIR" "POPD" "PUSHD" "PWD" "CD" "BROWSE" "*TERMINAL-HEIGHT*" "*DIRECTORY-HISTORY*" "CHANGE-WORKING-DIRECTORY" "SELECT-WORKING-DIRECTORY" "WORKING-DIRECTORY" "*CHANGE-DIRECTORY-HOOK*" "*KEEP-DOT-FILES*") (:documentation " This package exports a function to browse the directory hierarchy and load lisp files, and a few interactive commands: CD, PWD, PUSHD, POPD, MKDIR, LS, CAT, MORE, CP, MV, MAKE, GREP. License: AGPL3 Copyright Pascal J. Bourguignon 2002 - 2021 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/> ")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.INTERACTIVE.BROWSER") ;;;--------------------------------------------------------------------- ;;; Dates ;;;--------------------------------------------------------------------- (defun now () (get-universal-time)) (defun current-year () (nth-value 5 (decode-universal-time (get-universal-time)))) (defvar *today* (now) "Used as a reference to determine which short form a date must be formated as. Client code can rebind it to another universal date or set it to (now).") (defvar *short-month-names* #("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec")) (defun parse-short-month (short-month-name) (let ((pos (position short-month-name *short-month-names* :test (function string-equal)))) (and pos (1+ pos)))) (defun parse-ls-date (string) (let* ((month (parse-short-month (subseq string 0 3))) (day (parse-integer string :start 4 :end 6)) (colon (position #\: string :start 7)) (year (if colon (current-year) (parse-integer string :start 8))) (hour (if colon (parse-integer string :start 7 :end 9) 12)) (minute (if colon (parse-integer string :start (1+ colon)) 0))) (encode-universal-time 0 minute hour day month year 0))) (defun format-ls-date (stream date colon at &rest arguments) (declare (ignore at arguments)) (multiple-value-bind (se mi ho da mo ye) (decode-universal-time date) (if colon (cond ((< (- *today* date) (* 24 60 60)) (format stream "~2,'0D:~2,'0D:~2,'0D " ho mi se)) ((< (- *today* date) (* 6 30 24 60 60)) (format stream "~2,'0D-~2,'0D ~2,'0D:~2,'0D" mo da ho mi)) (t (format stream "~4,'0D-~2,'0D-~2,'0D " ye mo da))) (cond ((< (- *today* date) (* 6 30 24 60 60)) (format stream "~3A ~2D ~2,'0D:~2,'0D" (aref *short-month-names* (1- mo)) da ho mi)) (t (format stream "~3A ~2D ~5D" (aref *short-month-names* (1- mo)) da ye)))))) (defun shorter-date (universal-time) (format nil "~/COM.INFORMATIMAGO.COMMON-LISP.INTERACTIVE.BROWSER::FORMAT-LS-DATE/" universal-time)) ;;;--------------------------------------------------------------------- (defvar *shell* nil "A function of one string argument executing it as a shell command.") (defvar *verbose* nil "Makes some functions output information on *trace-output*.") (defun runcommand (name args) (if *shell* (funcall *shell* (funcall (if *verbose* (lambda (x) (format *trace-output* "~&~A~%" x) x) (function identity)) (format nil "~{~A~^ ~}" (mapcar (lambda (item) (typecase item (symbol (string-downcase item)) (otherwise item))) (cons name args))))) (error "Please assign a shell function to ~S" '*shell*))) (defmacro define-external-command (name &optional docstring) "Define a macro named NAME taking any number of arguments, and calling the external program of same name thru the shell." `(defun ,name (&rest args) ,(or docstring (format nil "COMMAND~%Runs the ~A command." name)) (runcommand ',name args))) (define-external-command rm) (define-external-command cp) (define-external-command mv) (define-external-command make) (define-external-command grep) (defvar *keep-dot-files* nil "Whether dot-files should be shown.") (defun update-default-pathname-default (working-directory) (setf *default-pathname-defaults* (merge-pathnames working-directory *default-pathname-defaults* nil))) (defvar *change-directory-hook* (list 'update-default-pathname-default) "A list of unary functions called with the path of the new current working directory. The default list contains a hook to set the *DEFAULT-PATHNAME-DEFAULTS*. A common usage is to set the unix current working directory to the same directory, so that the *default-pathname-defaults*, the *working-directory* and the unix current working directory are all three synchronized. ") (defvar *directory-stack* nil) (defvar *directory-history* nil) (defvar *working-directory* (user-homedir-pathname) "The current working directory") (defun working-directory () "RETURN: The working directory." *working-directory*) (defun check-directories-exist (path) "Return: whether all the directories in PATH exist; the path to the first directory that doesn't exist." (let* ((non-existent (find-if-not (lambda (dir) ;; We cannot use directory to check whether a directory ;; exists. So we try a file pattern, and if not found ;; but no error is signaled, assume the directory exists. ;; Of course, this doesn't work on some implementations ;; such as ccl. ;; On ccl, if we try to create a file in an inexistant ;; directory, it will create it!!! But we can use ;; probe-file to test directories in ccl… (let ((probe-dirpath (make-pathname :name nil :type nil :version nil :directory dir :defaults path))) #+ccl (probe-file probe-dirpath) #-ccl (ignore-errors (or (directory (merge-pathnames "PROBE.FILE" probe-dirpath nil)) t)))) (nreverse (loop :for dir :on (reverse (pathname-directory path)) :collect (reverse dir)))))) (values (not non-existent) (merge-pathnames (make-pathname :directory non-existent :defaults path) path nil)))) (defun change-working-directory (path) " DO: Sets *WORKING-DIRECTORY* to the new PATH, if it exists and is a directory path. Runs the hooks on *CHANGE-DIRECTORY-HOOK*. RETURN: *WORKING-DIRECTORY* " (multiple-value-bind (exists-p dirpath) (check-directories-exist path) (if exists-p (progn ;; (print (list path dirpath (truename dirpath))) (setf *working-directory* (truename dirpath)) (dolist (hook *change-directory-hook*) (let ((*working-directory* *working-directory*)) (funcall hook *working-directory*))) (pushnew *working-directory* *directory-history* :test (function equal))) (error "nonexistent directory: ~S" dirpath))) *working-directory*) (defun select-working-directory () (when *directory-history* (setf *directory-history* (sort *directory-history* (function string<) :key (function namestring))) (loop (loop :for index :from 1 :for dir :in *directory-history* :do (format *query-io* "~4D) ~A~%" index dir) :finally (format *query-io* "~4D) ~A~%" 0 "Cancel.")) (finish-output *query-io*) (let ((selection (read *query-io*))) (when (and (integerp selection)) (cond ((zerop selection) (return-from select-working-directory)) ((plusp selection) (let ((dir (nth (1- selection) *directory-history* ))) (when dir (change-working-directory dir) (return-from select-working-directory)))))))))) (defun parent-directory (dirpath) (make-pathname :directory (let ((dir (pathname-directory dirpath))) (cons (car dir) (butlast (cdr dir)))) :defaults dirpath)) (defun subdirectories (dirpath) (directory (merge-pathnames (make-pathname :directory '(:relative :wild)) dirpath))) (defun filter-out-dots (list) (delete-if (lambda (path) (char= (character ".") (aref (or (pathname-name path) (car (last (pathname-directory path)))) 0))) list)) (defun subdirectories-names (dirpath &key (keep-dot-files *keep-dot-files*)) (let ((subs (subdirectories dirpath))) (unless keep-dot-files (setf subs (filter-out-dots subs))) (mapcar (lambda (path) (car (last (pathname-directory path)))) subs))) (defun child-directory (dirpath child) (merge-pathnames (make-pathname :directory (list :relative child)) dirpath)) (defun files (dirpath &key (type :wild) (keep-dot-files *keep-dot-files*)) (let ((files (directory (make-pathname :name :wild :type type :defaults dirpath)))) (unless keep-dot-files (setf files (filter-out-dots files))) (mapcar (lambda (path) (cons (pathname-name path) path)) files))) (defparameter *screen-width* 80) (defun print-list (stream list offset &key (index-width 2)) (let* ((item-width (reduce (function max) list :key (function length))) (max-width (+ index-width 3 item-width)) (col-count (truncate *screen-width* max-width)) (row-count (truncate (+ (length list) col-count -1) col-count)) (table (make-array (list col-count row-count) :initial-element "")) (x 0) (y 0)) (dolist (item list) (setf (aref table x y) (format nil "~V,D) ~V,A" index-width offset item-width item)) (incf offset) (incf y) (if (<= row-count y) (setf x (1+ x) y 0))) (dotimes (y row-count) (dotimes (x (1- col-count)) (princ (aref table x y) stream) (princ " " stream)) (princ (aref table (1- col-count) y) stream) (terpri stream)))) (defun browse () "COMMAND DO: Displays the contents of the working directory and allows the user to navigate in the directory tree and to load files. " (loop (let* ((subdirs (sort (subdirectories-names (working-directory)) (function string<))) (files (sort (files (working-directory) :type "lisp") (lambda (a b) (string< (car a) (car b))))) (item-count (+ (length subdirs) (length files))) (count-width (if (= 0 item-count) 1 (ceiling (log item-count 10))))) (format t "~&") (format t "--- current directory ----------------------------~%") (format t "~V,A ~A~%" count-width "" (working-directory)) (format t "--- parent directory ----------------------------~%") (format t "~V,D) ~A~%" count-width 0 (parent-directory (working-directory))) (when subdirs (format t "--- subdirectories -------------------------------~%") (print-list t subdirs 1 :index-width count-width)) (when files (format t "--- files ----------------------------------------~%") (print-list t (mapcar (function car) files) (1+ (length subdirs)) :index-width count-width)) (format t "--------------------------------------------------~%") (let ((answer (block :answer (loop (format t "~&Change directory number, ~ load file number, or -1 to quit: ") (finish-output) (let ((answer (read t nil nil))) (typecase answer (integer (if (<= -1 answer item-count) (return-from :answer answer) (format t "~&Input out of range.~%"))) (otherwise (format t "~&Bad input type.~%")))))))) (cond ((= -1 answer) (return)) ((= 0 answer) (change-working-directory (parent-directory (working-directory)))) ((<= answer (length subdirs)) (change-working-directory (child-directory (working-directory) (elt subdirs (1- answer))))) (t (load (cdr (elt files (- answer (length subdirs) 1))) :verbose t))))))) (defun resolve (path &key (directory nil)) (setf path (typecase path (string (namestring (pathname path))) (pathname (namestring path)) (symbol (namestring (pathname (string-downcase path)))) (character (string path)) (number (format nil "~A" path)) (list (cond ((eq :absolute (car path)) (format nil "/~{~A~^/~}" (cdr path))) ((eq :relative (car path)) (format nil "~{~A~^/~}" (cdr path))) (t (format nil "~{~A~^/~}" path)))) (otherwise (error "Bad path ~S" path)))) (merge-pathnames (if directory (make-pathname :directory (cons (if (char= (character "/") (char path 0)) :absolute :relative) (substitute :up ".." (delete-if (lambda (item) (member item '("" ".") :test (function string=))) (split-string path "/")) :test (function string=)))) path) (working-directory))) (defun split-options (args) " ARGS: A list of strings containing options. RETURN: A list of options; a list of arguments both in the order found in ARGS, and converted to string. " (do ((options '()) (arguments '()) (args args (cdr args))) ((null args) (values (nreverse options) (nreverse arguments))) (let ((current (typecase (car args) (string (car args)) (keyword (format nil "-~(~A~)" (car args))) (symbol (string-downcase (car args))) (character (string (car args))) (list (car args)) (otherwise (format nil "~A" (car args)))))) (if (and (< 0 (length current)) (char= (character "-") (char current 0))) (push current options) (push current arguments))))) (defun relativize (path default) (let ((dp (pathname-directory path)) (dd (pathname-directory default))) (if (and (>= (length dp) (length dd)) (equal (subseq dp 0 (length dd)) dd)) (make-pathname :directory (cons :relative (subseq dp (length dd))) :defaults path) path))) (defun wilder-path (path) (cond ((string= "" path) (list (make-pathname :name :wild) (make-pathname :directory '(:relative :wild)))) ((intersection '(:wild :wild-inferior) (list* (pathname-name path) (pathname-type path) (pathname-version path) (pathname-host path) (pathname-device path) (pathname-directory path))) (list path)) (t (let* ((dp (pathname-directory path)) (dk (car dp)) (dr (if (pathname-name path) (cdr dp) (butlast (cdr dp)))) (li (or (pathname-name path) (car (last (cdr dp)))))) ;; (print `(dp ,dp dk ,dk dr ,dr li ,li)) ;; "" --> * */ ;; /a/b/c --> /a/b/c /a/b/c/ /a/b/c/* /a/b/c/*/ ;; /a/b/c/ --> /a/b/c /a/b/c/ /a/b/c/* /a/b/c/*/ ;; /a/b/f --> /a/b/f /a/b/f/ /a/b/f/* (append (list ;; /a/b/c/* (make-pathname :directory (delete nil (cons dk (append dr (list li :wild)))) :name nil :defaults path) ;; /a/b/c/* (make-pathname :directory (delete nil (cons dk (append dr (list li)))) :name :wild :defaults path)) (when (stringp li) (list ;; /a/b/c (make-pathname :directory (delete nil (cons dk dr)) :name li :defaults path))) (when (and (null (pathname-type path)) (or (null (pathname-version path)) (eq :newest (pathname-version path)))) (list ;; /a/b/c/ (make-pathname :directory (delete nil (cons dk (append dr (list li)))) :name nil :defaults path)))))))) (defun mkdir (dir &rest other-dirs) "COMMAND DO: Create the directories. ARGUMENTS: A list of paths. If name or type is not nil, then the file name is taken as the last item in the directory path. " (dolist (path (cons dir other-dirs)) (ensure-directories-exist (resolve (if (or (pathname-name path) (pathname-type path)) (make-pathname :directory (append (or (pathname-directory path) '(:relative)) (list (file-namestring path))) :name nil :type nil :defaults path) path) :directory t)))) (defun ls (&rest args) "COMMAND DO: List the files or directories. OPTIONS: -L long listing: item kind, size, date, name; otherwise only name. -A all entries: list also entries whose name starts with a dot or ends with a tilde. ARGUMENTS: A list of paths possibly containing wildcards. If none is given, then \"*\" is used. " (setf *today* (get-universal-time)) (multiple-value-bind (opts args) (split-options args) (let ((opt-long nil) (opt-all nil)) (dolist (opt opts) (cond ((or (eq :l opt) (string-equal "-l" opt)) (setf opt-long t)) ((or (eq :a opt) (string-equal "-a" opt)) (setf opt-all t)) (t (error "Invalid option ~S" opt)))) (dolist (entry (sort (delete-duplicates ;; SBCL RETURNS DIRECTORIES FOR "*" AS WELL AS FOR "*/". (mapcan (lambda (path) (handler-case (directory path) (error () nil))) (mapcar (lambda (path) (resolve path :directory nil)) (or (delete-duplicates (mapcan (function wilder-path) args) :key (function namestring) :test (function string=)) '("*/" "*" "*.*")))) :key (function namestring) :test (function string=)) (function string<) :key (function namestring))) (when (or opt-all (let* ((fns (file-namestring entry)) (name (if (string/= "" fns) fns (first (last (pathname-directory entry)))))) (not (or (prefixp "." name) #+ccl (prefixp "\\." name) (suffixp "~" name))))) (if opt-long (format t "~1A ~10A ~11A ~A~%" (if (pathname-name entry) "-" "d") (handler-case (with-open-file (file entry :direction :input) (format nil "~10D" (file-length file))) (error () "")) (handler-case (shorter-date (file-write-date entry)) (error () "")) (namestring (relativize entry (working-directory)))) (format t "~A~%" (namestring (relativize entry (working-directory))))))))) (values)) (defvar *terminal-height* 50 "The number of line displayed on the terminal. Used by functions like MORE.") (defun more-stream (page *standard-input* *standard-output*) (do* ((+eof+ (list '+eof+)) (lnum 0 (1+ lnum)) (line (read-line *standard-input* nil +eof+) (read-line *standard-input* nil +eof+))) ((eq line +eof+)) (write-line line *standard-output*) (when (and page (>= lnum page)) (setf lnum 0) (princ "Type RETURN for next page:" *query-io*) (finish-output *query-io*) (clear-input *query-io*) (read-line *query-io* nil)))) (defun more (&rest args) "COMMAND DO: concatenate and paginate a list of files. ARGUMENTS: If the first argument is :PAGE, then the second arguments is either an integer giving the page height, or NIL indicating that no pagination must be done; else the page height is *TERMINAL-HEGIHT*. The other arguments are paths of files to be dumped on *STANDARD-OUTPUT*; a string-designator for \"-\" represents *STANDARD-INPUT*. If no path is given, only *STANDARD-INPUT* is processed. " (let (page paths) (if (eq :page (first args)) (setf page (second args) paths (cddr args)) (setf page *terminal-height* paths args)) (if paths (dolist (path paths) (if (and (typep path 'string-designator) (string= path "-")) (more-stream page *standard-input* *standard-output*) (with-open-file (in (resolve path :directory nil) :direction :input :if-does-not-exist :error) (more-stream page in *standard-output*)))) (more-stream page *standard-input* *standard-output*))) (values)) (defun less (&rest args) "COMMAND SEE: MORE " (apply (function more) args)) (defun cat (&rest paths) "COMMAND SEE: MORE DO: Same as more, but force no pagination. " (apply (function more) :page nil paths)) (defun cd (&optional path) "COMMAND DO: Change the working directory. ARGUMENTS: The path of the new working directory. If not given, then change to the user home directory. " (change-working-directory (if path (resolve path :directory t) (user-homedir-pathname)))) (defun pwd () "COMMAND DO: Returns the current working directory. " (working-directory)) (defun popd () "COMMAND DO: Unstack the working directory from the stack. " (if *directory-stack* (cons (change-working-directory (pop *directory-stack*)) *directory-stack*) (list (working-directory)))) (defun pushd (&optional path) "COMMAND DO: Push the current working directory onto the stack, and change the working directory to the path (or home directory). SEE; POPD, CD. " (if path (progn (push (working-directory) *directory-stack*) (cons (cd path) *directory-stack*)) (let ((top (pop *directory-stack*))) (push (working-directory) *directory-stack*) (cons (cd top) *directory-stack*)))) ;;;; THE END ;;;;
27,632
Common Lisp
.lisp
609
34.512315
110
0.539579
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
dbbaab4e8affb90f931059e01924cfdc48dcfec871a1581079b84eb24b4829f9
4,996
[ -1 ]
4,997
com.informatimago.common-lisp.interactive.test.asd
informatimago_lisp/common-lisp/interactive/com.informatimago.common-lisp.interactive.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.interactive.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.interactive.test system. ;;;; Tests the com.informatimago.common-lisp.interactive system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.interactive.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.interactive system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.interactive.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.interactive") :components () #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) ;; (let ((*package* (find-package "TESTED-PACKAGE"))) ;; (uiop:symbol-call "TESTED-PACKAGE" ;; "TEST/ALL")) )) ;;;; THE END ;;;;
3,004
Common Lisp
.lisp
67
38.656716
91
0.554344
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
6959e7a3db12dfe0bb7181320f00bd6215aeca24a7be76f533943f17a9a5f987
4,997
[ -1 ]
4,998
com.informatimago.common-lisp.csv.asd
informatimago_lisp/common-lisp/csv/com.informatimago.common-lisp.csv.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.csv.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.csv library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.csv" ;; system attributes: :description "Informatimago Common Lisp CSV File Format" :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.4.0" :properties ((#:author-email . "[email protected]") (#:date . "Autumn 2010") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.csv/") ((#: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.common-lisp.cesarum") :components ((:file "csv" :depends-on ())) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.csv.test")))) ;;;; THE END ;;;;
2,501
Common Lisp
.lisp
53
44
107
0.58749
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
2df30c9548268cb29b2ef25c1e49dcbdd1012b0af872235bc186d072a1a8272b
4,998
[ -1 ]
4,999
com.informatimago.common-lisp.csv.test.asd
informatimago_lisp/common-lisp/csv/com.informatimago.common-lisp.csv.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.csv.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.csv.test system. ;;;; Tests the com.informatimago.common-lisp.csv system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.csv.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.csv system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.csv.test/") ((#: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.common-lisp.csv" "com.informatimago.common-lisp.cesarum") :components () #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) ;; (let ((*package* (find-package "TESTED-PACKAGE"))) ;; (uiop:symbol-call "TESTED-PACKAGE" ;; "TEST/ALL")) )) ;;;; THE END ;;;;
2,948
Common Lisp
.lisp
67
37.820896
83
0.545676
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
f77035589a9fae53b212f8d57befd1c6f49a9df17256cab58232ca2fdca72f3c
4,999
[ -1 ]
5,000
ed.lisp
informatimago_lisp/common-lisp/ed/ed.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: ed.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; See defpackage documentation string. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2012-03-31 <PJB> Made a few corrections. ;;;; 2003-12-19 <PJB> Created. ;;;;BUGS ;;;; ;;;; Not complete. ;;;; (Still waiting on regexp package...). ;;;; ;;;; In: 1,20!(do-something-with *input*) ;;;; *input* is not bound to the 20 lines, and the output is not ;;;; *inserted in the buffer. ;;;; ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2003 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.ED.ED" (:use "COMMON-LISP") #+mocl (:shadowing-import-from "COM.INFORMATIMAGO.MOCL.KLUDGES.MISSING" "*TRACE-OUTPUT*" "*LOAD-VERBOSE*" "*LOAD-PRINT*" "ARRAY-DISPLACEMENT" "CHANGE-CLASS" "COMPILE" "COMPLEX" "ENSURE-DIRECTORIES-EXIST" "FILE-WRITE-DATE" "INVOKE-DEBUGGER" "*DEBUGGER-HOOK*" "LOAD" "LOGICAL-PATHNAME-TRANSLATIONS" "MACHINE-INSTANCE" "MACHINE-VERSION" "NSET-DIFFERENCE" "RENAME-FILE" "SUBSTITUTE-IF" "TRANSLATE-LOGICAL-PATHNAME" "PRINT-NOT-READABLE" "PRINT-NOT-READABLE-OBJECT") (:shadow "ED") (:export "ED") (:documentation " This package exports an implementation of the COMMON-LISP ED function following the user manual of ed(1). ed(1) in COMMON-LISP. Real men do it with magnets. ed is for girly men. This is a clone of the unix ed(1) editor written in pure Common-Lisp. Since Common-Lisp does not define any process management functions, all !command forms are taken as Lisp forms instead of sh(1) commands. These forms are executed within a (LAMBDA (*INPUT*) command) with the *INPUT* argument bound to a mutable list of inmutable input strings, one per line. The result of the returning form in command must be a list of string, the list of resulting lines to be inserted into the buffer or to be printed on the terminal. For the rest, the aim is to be 100% user-interface compatible with ed(1). Ed, man! !man ed: <http://www.gnu.org/fun/jokes/ed.msg.html> Can you imagine that some Common-Lisp implementations DON'T provide any editor (in conformity with the Common-Lisp specifications)? Not complete (waiting for a REGEXP package). But otherwise functional enough. License: AGPL3 Copyright Pascal J. Bourguignon 2003 - 2015 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/> ")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.ED.ED") (eval-when (:compile-toplevel :load-toplevel :execute) (defconstant +debug+ t) (defparameter *show-debug* nil)) (defmacro dbg (&body body) (when +debug+ `(when *show-debug* (let ((*standard-output* *trace-output*)) ,@body)))) ;;(WHEN +DEBUG+ ;;(shadow 'handler-case) ;;(defmacro handler-case (form &rest args) form)) ;;-------- ;; buffer: ;;-------- (defstruct buffer (path nil) (lines '(0)) ; (index-of-current-line . lines) (marks '( )) ; ((ch . linum) ...) (old-lines '(0)) ; (index-of-current-line . lines) (old-marks '( )) ; ((ch . linum) ...) (cut-lines '( )) ; (lines ...) (show-errors nil) (got-error nil) (last-error "") (show-prompt nil) (prompt-string "") (command nil) (modified nil) (print nil) (quit nil)) ;; (setq b (buffer-read "~/test.txt")) (defmacro toggle (place &environment env) (multiple-value-bind (vars vals stores setter getter) (get-setf-expansion place env) `(let* (,@(mapcar (function list) vars vals) (,(car stores) ,getter)) (prog1 (setq ,(car stores) (not ,(car stores))) ,setter)))) ;;------- ;; lines: ;;------- (defun (setf buffer-current-linum) (new-linum buffer) (setf (car (buffer-lines buffer)) new-linum)) (defun buffer-current-linum (buffer) (car (buffer-lines buffer))) (defun buffer-length (buffer) (length (cdr (buffer-lines buffer)))) (defun buffer-nth-line (buffer linum) (car (buffer-line-cons buffer linum))) (defun buffer-line-cons (buffer linum) "Return the cons cells where the line LINUM of the BUFFER is stored." (if (< linum 0) nil (nthcdr linum (buffer-lines buffer)))) ;;------- ;; marks: ;;------- (defun buffer-set-mark (buffer ch linum) (let ((ass (assoc ch (buffer-marks buffer)))) (if ass (setf (cdr ass) linum) (push (cons ch linum) (buffer-marks buffer)))) (values)) (defun buffer-get-mark (buffer ch) (cdr (assoc ch (buffer-marks buffer)))) (defun buffer-offset-marks (buffer from offset) (if (< offset 0) (let ((mindel (+ from offset))) (setf (buffer-marks buffer) (mapcan (lambda (ass) (cond ((< (cdr ass) mindel) (list ass)) ((< (cdr ass) from) nil) (t (incf (cdr ass) offset) (list ass)))) (buffer-marks buffer)))) (map nil (lambda (ass) (when (<= from (cdr ass)) (incf (cdr ass) offset))) (buffer-marks buffer)))) (defun copy-marks (marks) (mapcar (lambda (ass) (cons (car ass) (cdr ass))) marks)) ;;---------------- ;; error messages: ;;---------------- (defun buffer-clear-error (buffer) (setf (buffer-got-error buffer) nil)) (defun buffer-set-error (buffer message) (setf (buffer-last-error buffer) message (buffer-got-error buffer) t)) ;;------------- ;; undo buffer: ;;------------- (defun buffer-save-undo (buffer) (setf (buffer-modified buffer) t) (setf (buffer-old-marks buffer) (copy-marks (buffer-marks buffer)) (buffer-old-lines buffer) (copy-seq (buffer-lines buffer)))) (defun buffer-swap-undo (buffer) (psetf (buffer-old-marks buffer) (buffer-marks buffer) (buffer-marks buffer) (buffer-old-marks buffer) (buffer-old-lines buffer) (buffer-lines buffer) (buffer-lines buffer) (buffer-old-lines buffer))) (defun buffer-erase (buffer) ;; no undo! (setf (buffer-lines buffer) '(0) (buffer-marks buffer) nil (buffer-old-lines buffer) '(0) (buffer-old-marks buffer) nil (buffer-cut-lines buffer) nil (buffer-modified buffer) t)) (defun buffer-read (path) (let ((buffer (make-buffer :path path))) (do-read buffer path 0) buffer)) (defun buffer-from-string (text) (let ((buffer(make-buffer))) (do-paste buffer 0 (do ((newline (format nil "~%")) (lines ()) (position 0) (nextpos 0)) ((>= nextpos (length text)) (nreverse lines)) (setq position (search newline text :start2 nextpos)) (if position (progn (push (subseq text nextpos position) lines) (setq nextpos (+ position (length newline)))) (progn (push (subseq text nextpos) lines) (setq nextpos (length text)))))) buffer)) (defun limit (value min max) (if (<= min value max) value nil)) (defun address->linum (buffer address &optional (min 1)) (cond ((null address) nil) ((eq address :curr) (buffer-current-linum buffer)) ((eq address :first) 1) ((eq address :last) (buffer-length buffer)) ((eq address :next) (limit (1+ (buffer-current-linum buffer)) 1 (buffer-length buffer))) ((eq address :prev) (limit (1- (buffer-current-linum buffer)) min (buffer-length buffer))) ((not (consp address)) nil) ((eq (car address) :next) (limit (+ (buffer-current-linum buffer) (cdr address)) 1 (buffer-length buffer))) ((eq (car address) :prev) (limit (- (buffer-current-linum buffer) (cdr address)) min (buffer-length buffer))) ((eq (car address) :linum) (limit (cdr address) min (buffer-length buffer))) ((eq (car address) :mark) (limit (buffer-get-mark buffer (cdr address)) 1 (buffer-length buffer))) ((eq (car address) :regexp) ;; TODO: regexp not implemented yet. (format *terminal-io* "REGEXP NOT IMPLEMENTED YET.~%")))) (defmacro with-addresses ((buffer . addresses) &body body) `(let ,(mapcar (lambda (vam) `(,(first vam) (address->linum ,buffer ,(second vam) ,(third vam)))) addresses) (if (or ,@(mapcar (lambda (vam) `(null ,(first vam))) addresses) ,@(when (<= 2 (length addresses)) `((< ,(first (second addresses)) ,(first (first addresses)))))) (buffer-set-error ,buffer "Invalid address") (progn ,@body)))) (defmacro unless-modified (buffer &body body) `(if (buffer-modified ,buffer) (progn (setf (buffer-modified ,buffer) nil) (buffer-set-error ,buffer "Warning: file modified")) (progn ,@body))) ;; (progn (PJB-CL+INDENT with-addresses 1)(PJB-CL+INDENT unless-modified 1)) (defun do-insert (buffer linum) (dbg (format t "DO-INSERT(~S ~S) ~%" "buffer" linum)) (do ((place (buffer-line-cons buffer linum) (cdr place)) (line (read-line *terminal-io* nil ".") (read-line *terminal-io* nil ".")) (curr linum (1+ curr))) ((string= line ".") (progn (setf (buffer-current-linum buffer) curr) (buffer-offset-marks buffer linum (- curr linum)))) (setf (cdr place) (cons line (cdr place))))) (defun do-paste (buffer linum new-lines) (dbg (format t "DO-PASTE(~S ~S [~D lines]) ~%" "buffer" linum (length new-lines))) (let* ((insert-point (buffer-line-cons buffer linum)) (after (cdr insert-point))) (setf (buffer-current-linum buffer) (+ linum (length new-lines))) (setf (cdr insert-point) new-lines) (setf (cdr (last new-lines)) after))) (defun do-cut (buffer from last) " RETURN: The list of cut lines. " (dbg (format t "DO-CUT(~S ~S ~S) ~%" "buffer" from last)) (let* ((delete-point (buffer-line-cons buffer (1- from))) (after-point (buffer-line-cons buffer last)) (result (cdr delete-point))) (setf (buffer-current-linum buffer) (if (null (cdr after-point)) from (1+ from))) (setf (cdr delete-point) (cdr after-point) (cdr after-point) nil) (buffer-offset-marks buffer from (- last from -1)) result)) (defun do-print-lines (buffer curr last func) (dbg (format t " DO-PRINT-LINES(~S ~S ~S [a function]) ~%" "buffer" curr last)) (setf (buffer-print buffer) nil) (do* ((curr curr (1+ curr)) (lines (buffer-line-cons buffer curr) (cdr lines))) ((> curr last) (setf (buffer-current-linum buffer) last)) (funcall func curr (car lines)))) (defun do-write (buffer path mode from last) (dbg (format t "DO-WRITE(~S ~S ~S ~S ~S) ~%" "buffer" path mode from last)) (handler-case (with-open-file (output path :direction :output :if-exists mode :if-does-not-exist :create) (do ((line (buffer-line-cons buffer from) (cdr line)) (curr from (1+ curr))) ((> curr last)) (format output "~A~%" (car line)))) (error (err) (buffer-set-error buffer (format nil "~S" err))))) (defun do-read (buffer path linum) (dbg (format t "DO-READ(~S ~S ~S) ~%" "buffer" path linum)) (handler-case (do-paste buffer linum (with-open-file (input path :direction :input :if-does-not-exist :error) (do ((lines '() (cons line lines)) (line t)) ((null line) (nreverse (cdr lines))) (setf line (read-line input nil nil))))) (error (err) (buffer-set-error buffer (format nil "~S" err))))) (defun filter-command-output (output) (if (and (listp output) (every (function stringp) output)) output (list (format nil "~S" output)))) ;; (defmacro hc (form &rest rest) form) (defun do-command (buffer &key (input nil) (output :print)) (dbg (format t "DO-COMMAND(~S ~S ~S) ~%" "buffer" input output)) (if (buffer-command buffer) (handler-case (progn (format *terminal-io* "~A~%" (buffer-command buffer)) (let* ((*package* (find-package "COM.INFORMATIMAGO.COMMON-LISP.ED.ED")) (results (eval `((lambda (*input*) (declare (ignorable *input*)) ,(read-from-string (format nil "(progn ~A)" (buffer-command buffer)))) (list ,@input))))) (case output ((:print) (map nil (lambda (line) (format *terminal-io* "~A~%" line)) (filter-command-output results)) (format *terminal-io* "!~%") (values)) ((:result) (format *terminal-io* "!~%") results) (otherwise (buffer-set-error buffer "Internal error: DO-COMMAND") (values))))) (error (err) (buffer-set-error buffer (format nil "~S" err)) (values))) (progn (buffer-set-error buffer "No previous command") (values)))) (defun cmd-comment (buffer from to arg) (declare (ignore from to arg)) (dbg (format t "CMD-COMMENT: ~%")) ;; (.,.)# Begins a comment; the rest of the line, up to a newline, ;; is ignored. If a line address followed by a semicolon is ;; given, then the current address is set to that address. ;; Otherwise, the current address is unchanged. (setf (buffer-print buffer) nil)) (defun cmd-append (buffer from to arg) (declare (ignore from arg)) (dbg (format t "CMD-APPEND: ~%")) ;; (.)a Appends text to the buffer after the addressed line, ;; which may be the address 0 (zero). Text is entered in ;; input mode. The current address is set to last line ;; entered. (with-addresses (buffer (linum to 0)) (buffer-save-undo buffer) (do-insert buffer linum))) (defun cmd-insert (buffer from to arg) (declare (ignore from arg)) (dbg (format t "CMD-INSERT: ~%")) ;; (.)i Inserts text in the buffer before the current line. Text ;; is entered in input mode. The current address is set to ;; the last line entered. (with-addresses (buffer (linum to 1)) (buffer-save-undo buffer) (do-insert buffer (max 0 (1- linum))))) (defun cmd-delete-lines (buffer from to arg) (declare (ignore arg)) (dbg (format t "CMD-DELETE-LINES: ~%")) ;; (.,.)d Deletes the addressed lines from the buffer. If there is ;; a line after the deleted range, then the current address ;; is set to this line. Otherwise the current address is set ;; to the line before the deleted range. (with-addresses (buffer (curr from 1) (last to 1)) (buffer-save-undo buffer) (setf (buffer-cut-lines buffer) (do-cut buffer curr last)))) (defun cmd-copy (buffer from to arg) (declare (ignore arg)) (dbg (format t "CMD-COPY: ~%")) ;; (.,.)y Copies (yanks) the addressed lines to the cut buffer. ;; The cut buffer is overwritten by subsequent `y', `s', ;; `j', `d', or `c' commands. The current address is ;; unchanged. ;; no undo (with-addresses (buffer (curr from 1) (last to 1)) ;; We don't need to make copies of the line string ;; because they're considered immutable. ;; When edited (changed, substituted), ;; a new copy replaces the old one. (setf (buffer-cut-lines buffer) (subseq (buffer-lines buffer) curr (1+ last))))) (defun cmd-paste (buffer from to arg) (declare (ignore from arg)) (dbg (format t "CMD-PASTE: ~%")) ;; (.)x Copies (puts) the contents of the cut buffer to after the ;; addressed line. The current address is set to the last ;; line copied. (with-addresses (buffer (curr to 0)) (buffer-save-undo buffer) (do-paste buffer curr (copy-seq (buffer-cut-lines buffer))))) (defun cmd-undo (buffer from to arg) (declare (ignore from to arg)) (dbg (format t "CMD-UNDO: ~%")) ;; u Undoes the last command and restores the current address ;; to what it was before the command. The global commands ;; `g', `G', `v', and `V'. are treated as a single command ;; by undo. `u' is its own inverse. (buffer-swap-undo buffer)) (defun cmd-copy-lines (buffer from to arg) (dbg (format t "CMD-COPY-LINES: ~%")) ;; (.,.)t(.) ;; Copies (i.e., transfers) the addressed lines to after the ;; right-hand destination address, which may be the address ;; 0 (zero). The current address is set to the last line ;; copied. (with-addresses (buffer (curr from 1) (last to 1) (target arg 0)) (buffer-save-undo buffer) (do-paste buffer arg (subseq (buffer-lines buffer) curr (1+ last))))) (defun cmd-move-lines (buffer from to arg) (dbg (format t "CMD-MOVE-LINES: ~%")) ;; (.,.)m(.) ;; Moves lines in the buffer. The addressed lines are moved ;; to after the right-hand destination address, which may be ;; the address 0 (zero). The current address is set to the ;; last line moved. (with-addresses (buffer (curr from 1) (last to 1) (target arg 0)) (buffer-save-undo buffer) (do-paste buffer arg (do-cut buffer curr last)))) (defun cmd-change-lines (buffer from to arg) (dbg (format t "CMD-CHANGE-LINES: ~%")) ;; (.,.)c Changes lines in the buffer. The addressed lines are ;; deleted from the buffer, and text is appended in their ;; place. Text is entered in input mode. The current ;; address is set to last line entered. (with-addresses (buffer (curr from 1) (last to 1) (target arg 0)) (buffer-save-undo buffer) (setf (buffer-cut-lines buffer) (do-cut buffer curr last)) (do-insert buffer curr))) (defun cmd-join-lines (buffer from to arg) (declare (ignore arg)) (dbg (format t "CMD-JOIN-LINES: ~%")) ;; (.,.+1)j ;; Joins the addressed lines. The addressed lines are ;; deleted from the buffer and replaced by a single line ;; containing their joined text. The current address is set ;; to the resultant line. (with-addresses (buffer (curr from 1) (last to 1)) (buffer-save-undo buffer) (setf (buffer-cut-lines buffer) (do-cut buffer curr last)) (do-paste buffer (max 0 (1- curr)) (apply (function concatenate) 'string (buffer-cut-lines buffer))))) (defun cmd-mark (buffer from to arg) (declare (ignore from)) (dbg (format t "CMD-MARK: ~%")) ;; (.)klc Marks a line with a lower case letter lc. The line can ;; then be addressed as 'lc (i.e., a single quote followed ;; by lc ) in subsequent commands. The mark is not cleared ;; until the line is deleted or otherwise modified. (with-addresses (buffer (curr to 1)) (buffer-set-mark buffer arg curr))) (defun cmd-print-line-number (buffer from to arg) (declare (ignore from arg)) (dbg (format t "CMD-PRINT-LINE-NUMBER: ~%")) ;; ($)= Prints the line number of the addressed line. (with-addresses (buffer (curr to 1)) (format *terminal-io* "~D~%" curr))) (defun cmd-scroll-lines (buffer from to arg) (declare (ignore from arg)) (dbg (format t "CMD-SCROLL-LINES: ~%")) ;; (.+1)zn Scrolls n lines at a time starting at addressed line. If ;; n is not specified, then the current window size is used. ;; The current address is set to the last line printed. (with-addresses (buffer (curr to 1)) ;; TODO: IMPLEMENT SCROLL! (do-print-lines buffer curr (buffer-length buffer) (lambda (linum line) (declare (ignore linum)) (format *terminal-io* "~A~%" line))) )) (defun cmd-print-lines (buffer from to arg) (declare (ignore arg)) (dbg (format t "CMD-PRINT-LINES: ~%")) ;; (.+1)newline ;; Prints the addressed line, and sets the current address ;; to that line. ;; (.,.)p Prints the addressed lines. If invoked from a termi- ;; nal, ed pauses at the end of each page until a newline is ;; entered. The current address is set to the last line ;; printed. (with-addresses (buffer (curr from 1) (last to 1)) (do-print-lines buffer curr last (lambda (linum line) (declare (ignore linum)) (format *terminal-io* "~A~%" line))))) (defun cmd-print-lines-and-numbers (buffer from to arg) (declare (ignore arg)) (dbg (format t "CMD-PRINT-LINES-AND-NUMBERS: ~%")) ;; (.,.)n Prints the addressed lines along with their line numbers. ;; The current address is set to the last line printed. ;; (with-addresses (buffer (curr from 1) (last to 1)) (do-print-lines buffer curr last (lambda (linum line) (format *terminal-io* "~6D ~A~%" linum line))))) (defun cmd-print-lines-unambiguously (buffer from to arg) (declare (ignore arg)) (dbg (format t "CMD-PRINT-LINES-UNAMBIGUOUSLY: ~%")) ;; (.,.)l Prints the addressed lines unambiguously. If invoked ;; from a terminal, ed pauses at the end of each page until ;; a newline is entered. The current address is set to the ;; last line printed. (with-addresses (buffer (curr from 1) (last to 1)) (do-print-lines buffer curr last (lambda (linum line) (declare (ignore linum)) (do ((i 0 (1+ i)) (ch)) ((>= i (length line)) (format *terminal-io* "$~%")) (setq ch (char line i)) (if (graphic-char-p ch) (format *terminal-io* "~C" ch) (let ((ass (assoc (char-code ch) '((7 . "a") (8 . "b") (9 . "t") (10 . "l") (11 . "v") (12 . "f") (13 . "r"))))) (if ass (format *terminal-io* "\\~A" (cdr ass)) (format *terminal-io* "\\~3,'0O" (char-code ch)))))))))) (defun cmd-substitute (buffer from to arg) (declare (ignore buffer from to arg)) ;; TODO: implement this function. (dbg (format t "CMD-SUBSTITUTE: ~%")) ;; (.,.)s/re/replacement/ ;; (.,.)s/re/replacement/g ;; (.,.)s/re/replacement/n ;; Replaces text in the addressed lines matching a regular ;; expression re with replacement. By default, only the ;; first match in each line is replaced. If the `g' ;; (global) suffix is given, then every match to be ;; replaced. The `n' suffix, where n is a postive number, ;; causes only the nth match to be replaced. It is an error ;; if no substitutions are performed on any of the addressed ;; lines. The current address is set the last line ;; affected. ;; ;; re and replacement may be delimited by any character ;; other than space and newline (see the `s' command below). ;; If one or two of the last delimiters is omitted, then the ;; last line affected is printed as though the print suffix ;; `p' were specified. ;; ;; An unescaped `&' in replacement is replaced by the cur- ;; rently matched text. The character sequence `\m', where ;; m is a number in the range [1,9], is replaced by the mth ;; backreference expression of the matched text. If ;; replacement consists of a single `%', then replacement ;; from the last substitution is used. Newlines may be ;; embedded in replacement if they are escaped with a back- ;; slash (\). ;; ;; (.,.)s Repeats the last substitution. This form of the `s' com- ;; mand accepts a count suffix `n', or any combination of ;; the characters `r', `g', and `p'. If a count suffix `n' ;; is given, then only the nth match is replaced. The `r' ;; suffix causes the regular expression of the last search ;; to be used instead of the that of the last substitution. ;; The `g' suffix toggles the global suffix of the last sub- ;; stitution. The `p' suffix toggles the print suffix of ;; the last substitution The current address is set to the ;; last line affected. (format *terminal-io* "NOT IMPLEMENTED YET.~%")) (defun cmd-edit-matching (buffer from to arg) (declare (ignore buffer from to arg)) ;; TODO: implement this function. (dbg (format t "CMD-EDIT-MATCHING: ~%")) ;; (1,$)g/re/command-list ;; Applies command-list to each of the addressed lines ;; matching a regular expression re. The current address is ;; set to the line currently matched before command-list is ;; executed. At the end of the `g' command, the current ;; address is set to the last line affected by command-list. ;; ;; Each command in command-list must be on a separate line, ;; and every line except for the last must be terminated by ;; a backslash (\). Any commands are allowed, except for ;; `g', `G', `v', and `V'. A newline alone in command-list ;; is equivalent to a `p' command. ;; (format *terminal-io* "NOT IMPLEMENTED YET.~%")) (defun cmd-edit-not-matching (buffer from to arg) (declare (ignore buffer from to arg)) ;; TODO: implement this function. (dbg (format t "CMD-EDIT-NOT-MATCHING: ~%")) ;; (1,$)v/re/command-list ;; Applies command-list to each of the addressed lines not ;; matching a regular expression re. This is similar to the ;; `g' command. ;; (format *terminal-io* "NOT IMPLEMENTED YET.~%")) (defun cmd-user-edit-matching (buffer from to arg) (declare (ignore buffer from to arg)) ;; TODO: implement this function. (dbg (format t "CMD-USER-EDIT-MATCHING: ~%")) ;; (1,$)G/re/ ;; Interactively edits the addressed lines matching a regu- ;; lar expression re. For each matching line, the line is ;; printed, the current address is set, and the user is ;; prompted to enter a command-list. At the end of the `G' ;; command, the current address is set to the last line ;; affected by (the last) command-list. ;; ;; The format of command-list is the same as that of the `g' ;; command. A newline alone acts as a null command list. A ;; single `&' repeats the last non-null command list. (format *terminal-io* "NOT IMPLEMENTED YET.~%")) (defun cmd-user-edit-not-matching (buffer from to arg) (declare (ignore buffer from to arg)) ;; TODO: implement this function. (dbg (format t "CMD-USER-EDIT-NOT-MATCHING: ~%")) ;; (1,$)V/re/ ;; Interactively edits the addressed lines not matching a ;; regular expression re. This is similar to the `G' com- ;; mand. (format *terminal-io* "NOT IMPLEMENTED YET.~%")) (defun file-or-command-arg (arg) " --> :empty --> :path ; path ; exists (t/nil) --> :command ; command --> :command-append ; command --> :invalid ; error-message " (if (string= "" arg) (values :empty) (progn (let ((pos (skip-spaces arg))) (when (and pos (< 0 pos)) (setq arg (subseq arg pos)))) (cond ((or (string= "" arg) (handler-case (prog1 nil (probe-file arg)) (error nil t))) (values :invalid "Invalid filename")) ((and (<= 2 (length arg)) (string= "!!" arg :end2 2)) (values :command-append (subseq arg 2))) ((and (<= 1 (length arg)) (string= "!" arg :end2 1)) (values :command (subseq arg 1))) (t (values :path arg (probe-file arg))))))) (defun cmd-write-or-append (buffer from to arg mode) (with-addresses (buffer (curr from 1) (last to 1)) (multiple-value-bind (kind path exists) (file-or-command-arg arg) (declare (ignore exists)) (case kind ((:empty) (if (buffer-path buffer) (do-write buffer (buffer-path buffer) mode curr last) (buffer-set-error buffer "No current filename"))) ((:path) (unless (buffer-path buffer) (setf (buffer-path buffer) path)) (do-write buffer path mode curr last)) ((:comand) (setf (buffer-command buffer) path) (do-command buffer :input (subseq (buffer-lines buffer) curr (1+ last)))) ((:comand-append) (setf (buffer-command buffer) (concatenate 'string (buffer-command buffer) path)) (do-command buffer :input (subseq (buffer-lines buffer) curr (1+ last)))) ((:invalid) (buffer-set-error buffer path)) (otherwise (buffer-set-error buffer "Internal error: FILE-OR-COMMAND-ARG")))))) (defun cmd-append-file (buffer from to arg) (dbg (format t "CMD-APPEND-FILE: ~%")) ;; (1,$)W file ;; Appends the addressed lines to the end of file. This is ;; similar to the `w' command, expect that the previous con- ;; tents of file is not clobbered. The current address is ;; unchanged. (cmd-write-or-append buffer from to arg :append)) (defun cmd-write-file (buffer from to arg) (dbg (format t "CMD-WRITE-FILE: ~%")) ;; (1,$)w file ;; Writes the addressed lines to file. Any previous con- ;; tents of file is lost without warning. If there is no ;; default filename, then the default filename is set to ;; file, otherwise it is unchanged. If no filename is spec- ;; ified, then the default filename is used. The current ;; address is unchanged. ;; ;; (1,$)w !command ;; Writes the addressed lines to the standard input of ;; `!command', (see the !command below). The default file- ;; name and current address are unchanged. (cmd-write-or-append buffer from to arg :supersede)) (defun cmd-write-file-quit (buffer from to arg) (dbg (format t "CMD-WRITE-FILE-QUIT: ~%")) ;; (1,$)wq file ;; Writes the addressed lines to file, and then executes a ;; `q' command. ;; (cmd-write-file buffer from to arg) (unless (buffer-got-error buffer) (cmd-quit buffer from to arg))) (defun cmd-edit-or-read (buffer arg linum) " LINUM: NIL ==> Edit, NUMBERP ==> Read " (multiple-value-bind (kind path exists) (file-or-command-arg arg) (declare (ignore exists)) (case kind ((:empty) (if (buffer-path buffer) (progn (unless linum (buffer-erase buffer)) (do-read buffer (buffer-path buffer) (or linum 0))) (buffer-set-error buffer "No current filename"))) ((:path) (setf (buffer-path buffer) path) (unless linum (buffer-erase buffer)) (do-read buffer path (or linum 0))) ((:comand) (setf (buffer-command buffer) path) (unless linum (buffer-erase buffer)) (do-paste buffer (or linum 0) (filter-command-output (do-command buffer :output :result)))) ((:comand-append) (setf (buffer-command buffer) (concatenate 'string (buffer-command buffer) path)) (unless linum (buffer-erase buffer)) (do-paste buffer (or linum 0) (filter-command-output (do-command buffer :output :result)))) ((:invalid) (buffer-set-error buffer path)) (otherwise (buffer-set-error buffer "Internal error: FILE-OR-COMMAND-ARG"))))) (defun cmd-read-file (buffer from to arg) (declare (ignore from)) (dbg (format t "CMD-READ: ~%")) ;; ($)r file ;; Reads file to after the addressed line. If file is not ;; specified, then the default filename is used. If there ;; was no default filename prior to the command, then the ;; default filename is set to file. Otherwise, the default ;; filename is unchanged. The current address is set to the ;; last line read. ;; ;; ($)r !command ;; Reads to after the addressed line the standard output of ;; `!command', (see the !command below). The default file- ;; name is unchanged. The current address is set to the ;; last line read. (with-addresses (buffer (curr to 1)) (cmd-edit-or-read buffer arg curr))) (defun cmd-edit-file-unconditionally (buffer from to arg) (declare (ignore from to)) (dbg (format t "CMD-EDIT-FILE-UNCONDITIONALLY: ~%")) ;; E file Edits file unconditionally. This is similar to the e ;; command, except that unwritten changes are discarded ;; without warning. The current address is set to the last ;; line read. (cmd-edit-or-read buffer arg nil) (unless (buffer-got-error buffer) (setf (buffer-modified buffer) nil) (format *terminal-io* "~D~%" (buffer-current-linum buffer)))) (defun cmd-edit-file (buffer from to arg) (declare (ignore from to)) (dbg (format t "CMD-EDIT-FILE: ~%")) ;; e file Edits file, and sets the default filename. If file is ;; not specified, then the default filename is used. Any ;; lines in the buffer are deleted before the new file is ;; read. The current address is set to the last line read. ;; ;; e !command ;; Edits the standard output of `!command', (see !command ;; below). The default filename is unchanged. Any lines in ;; the buffer are deleted before the output of command is ;; read. The current address is set to the last line read. (unless-modified buffer (cmd-edit-or-read buffer arg nil))) (defun cmd-set-default-filename (buffer from to arg) (declare (ignore from to)) (dbg (format t "CMD-SET-DEFAULT-FILENAME: ~%")) ;; f file Sets the default filename to file. If file is not speci- ;; fied, then the default unescaped filename is printed. (when (string/= "" arg) (let ((pos (skip-spaces arg))) (when (and pos (< 0 pos)) (setq arg (subseq arg pos)))) (if (or (string= "" arg) (handler-case (prog1 nil (probe-file arg)) (error nil t))) (buffer-set-error buffer "Invalid filename") (setf (buffer-path buffer) arg))) (format *terminal-io* "~A~%" (buffer-path buffer))) (defun cmd-print-last-error (buffer from to arg) (declare (ignore from to arg)) (dbg (format t "CMD-PRINT-LAST-ERROR: ~%")) ;; h Prints an explanation of the last error. (format *terminal-io* "~A~%" (buffer-last-error buffer))) (defun cmd-toggle-error-explanations (buffer from to arg) (declare (ignore from to arg)) (dbg (format t "CMD-TOGGLE-ERROR-EXPLANATIONS: ~%")) ;; H Toggles the printing of error explanations. By default, ;; explanations are not printed. It is recommended that ed ;; scripts begin with this command to aid in debugging. (toggle (buffer-show-errors buffer)) (unless (string= "" (buffer-last-error buffer)) (format *terminal-io* "~A~%" (buffer-last-error buffer)))) (defun cmd-toggle-command-prompt (buffer from to arg) (declare (ignore from to arg)) (dbg (format t "CMD-TOGGLE-COMMAND-PROMPT: ~%")) ;; P Toggles the command prompt on and off. Unless a prompt ;; was specified by with command-line option -p string, the ;; command prompt is by default turned off. (toggle (buffer-show-prompt buffer))) (defun cmd-quit (buffer from to arg) (declare (ignore from to arg)) (dbg (format t "CMD-QUIT: ~%")) ;; q Quits ed. (unless-modified buffer (setf (buffer-quit buffer) t))) (defun cmd-quit-unconditionnaly (buffer from to arg) (declare (ignore from to arg)) (dbg (format t "CMD-QUIT-UNCONDITIONNALY: ~%")) ;; Q Quits ed unconditionally. This is similar to the q com- ;; mand, except that unwritten changes are discarded without ;; warning. (setf (buffer-quit buffer) t)) (defun cmd-subshell (buffer from to arg) (declare (ignore from to)) (dbg (format t "CMD-SUBSHELL: ~%")) ;; !command ;; Executes command via sh(1). If the first character of ;; command is `!', then it is replaced by text of the previ- ;; ous `!command'. ed does not process command for back- ;; slash (\) escapes. However, an unescaped `%' is replaced ;; by the default filename. When the shell returns from ;; execution, a `!' is printed to the standard output. The ;; current line is unchanged. (setf (buffer-command buffer) (if (char= (character "!") (char arg 0)) (concatenate 'string (buffer-command buffer) (subseq arg 1)) arg)) (do-command buffer)) ;; remaining free commands: "@%()_[]{};:'\"<>ABCDFIJKLMNORSTUXYZbo" (defparameter *commands* '( ;;cmd from to argument p function ("t" :curr :curr :curr t cmd-copy-lines) ("m" :curr :curr :curr t cmd-move-lines) ("c" :curr :curr nil t cmd-change-lines) ("#" :curr :curr nil t cmd-comment) ("y" :curr :curr nil t cmd-copy) ("d" :curr :curr nil t cmd-delete-lines) ("p" :curr :curr nil t cmd-print-lines) ("n" :curr :curr nil t cmd-print-lines-and-numbers) ("l" :curr :curr nil t cmd-print-lines-unambiguously) ("s" :curr :curr substitution t cmd-substitute) ("j" :curr :next nil t cmd-join-lines) ("g" :first :last regexp nil cmd-edit-matching) ("v" :first :last regexp nil cmd-edit-not-matching) ("G" :first :last regexp t cmd-user-edit-matching) ("V" :first :last regexp t cmd-user-edit-not-matching) ("W" :first :last string nil cmd-append-file) ("w" :first :last string nil cmd-write-file) ("k" nil :curr character t cmd-mark) ("a" nil :curr nil t cmd-append) ("i" nil :curr nil t cmd-insert) ("x" nil :curr nil t cmd-paste) ("=" nil :last nil t cmd-print-line-number) ("r" nil :last string nil cmd-read-file) (nil nil :next nil nil cmd-print-lines) ("z" nil :next number t cmd-scroll-lines) ("h" nil nil nil t cmd-print-last-error) ("q" nil nil nil t cmd-quit) ("Q" nil nil nil t cmd-quit-unconditionnaly) ("P" nil nil nil t cmd-toggle-command-prompt) ("H" nil nil nil t cmd-toggle-error-explanations) ("u" nil nil nil t cmd-undo) ("e" nil nil string nil cmd-edit-file) ("E" nil nil string nil cmd-edit-file-unconditionally) ("f" nil nil string nil cmd-set-default-filename) ("!" nil nil string nil cmd-subshell) ("wq" :first :last string nil cmd-write-file-quit))) (dbg (push '("D" nil nil nil nil cmd-toggle-debug) *commands*) (defun cmd-toggle-debug (buffer from to arg) ;; !command ;; Executes command via sh(1). If the first character of ;; command is `!', then it is replaced by text of the previ- ;; ous `!command'. ed does not process command for back- ;; slash (\) escapes. However, an unescaped `%' is replaced ;; by the default filename. When the shell returns from ;; execution, a `!' is printed to the standard output. The ;; current line is unchanged. (declare (ignore buffer from to arg)) (dbg (format t "CMD-toggle-debug: ~%")) (toggle *show-debug*))) (defun skip-spaces (command &optional (start 0)) " RETURN: The index of the next non white space character in command, starting from position, or nil if end of string. " (do ((start start (1+ start))) ((or (>= start (length command)) (char/= (character " ") (char command start))) (when (< start (length command)) start)))) ;;addresses --> address ;; | address ',' address ;; | ',' | '%' , ';' . ;; ;; ;;address --> '.' | '$' | number ;; | '-' | '^' | '-' number | '^' number ;; | '+' | '+' number | space number ;; | '/' re '/' | '?' re '?' | '//' | '??' ;; | "'" lc . ;; ;;lc --> 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'|'k'|'l'|'m' ;; |'n'|'o'|'p'|'q'|'r'|'s'|'t'|'u'|'v'|'w'|'x'|'y'|'z'. ;; ;;re --> [first] ( ch | '\' ch | '[' char-class ']' | '[' '^' char-class ']' ;; | '^' | '$' | '\(' re '\)' | re '*' ;; | re '\{' num ',' num '\}' ;; | re '\{' num ',' '\}' ;; | re '\{' num '\}' ;; | '\<' | '\>' | '\`' | "\'" | re '\?' | re '\+' ;; | '\b' | '\B' | '\w' | '\W' . ;;first --> '*' . ;; ;;char-class --> '[:alnum:]'|'[:cntrl:]'|'[:lower:]'|'[:space:]' ;; |'[:alpha:]'|'[:digit:]'|'[:print:]'|'[:upper:]' ;; |'[:blank:]'|'[:graph:]'|'[:punct:]'|'[:xdigit:]' ;; |'[.'col-elm'.]'|'[='col-elm'=]'. ;;col-elm --> . (defun parse-address (command position) ;;address --> '.' | '$' | number ;; | '-' | '^' | '-' number | '^' number ;; | '+' | '+' number | space number ;; | '/' re '/' | '?' re '?' | '//' | '??' ;; | "'" lc . (declare (integer position)) (let ((address nil) (ch)) (flet ((parse-optional-number () (setq position (skip-spaces command (1+ position))) (when (and position (setq ch (char command position)) (digit-char-p ch)) (multiple-value-bind (value pos) (parse-integer command :start position :junk-allowed t) (when value (setq address (cons address value))) (setq position pos))))) (setq position (skip-spaces command position)) (when position (setq ch (char command position)) (cond ((char= ch (character ".")) (setq address :curr) (incf position)) ((char= ch (character "$")) (setq address :last) (incf position)) ((digit-char-p ch) (multiple-value-bind (value pos) (parse-integer command :start position :junk-allowed t) (when value (setq address (cons :linum value))) (setq position pos))) ((or (char= ch (character "^")) (char= ch (character "-"))) (setq address :prev) (parse-optional-number)) ((or (char= ch (character " ")) (char= ch (character "+"))) (setq address :next) (parse-optional-number)) ((or (char= ch (character "/")) (char= ch (character "?"))) ;; TODO: regexp ;; eat regexp: (setq address (cons :regexp (do ((terminator ch) (end position (1+ end))) ((or (>= end (length command)) (char= terminator (char command end))) (prog1 (subseq command position (1+ end)) (setq position (1+ end)))) (declare (integer end)))))) ((char= ch (character "'")) (incf position) ;; TODO: when there is an error here it's: "Invalid mark character" ;; TODO: not: "Invalid address" ! (when (< position (length command)) (setq address (cons :mark (char command position))) (incf position))) ))) (values address position))) (defun parse-and-run-command (buffer command) (let ((position (skip-spaces command)) (cmd) (ch) (from) (to) (arg) (print nil)) (buffer-clear-error buffer) (macrolet ((set-error (message) `(buffer-set-error buffer ,message)) (got-error () `(buffer-got-error buffer))) (when position (setq ch (char command position)) (cond ((or (char= (character ",") ch) (char= (character "%") ch)) (setq from :first to :last) (setq position (skip-spaces command (1+ position)))) ((char= (character ";") ch) (setq from :curr to :last) (setq position (skip-spaces command (1+ position)))) ((not (alpha-char-p ch)) (multiple-value-setq (to position) (parse-address command position)) (if (eq to :error) (set-error "Invalid address") (progn (setq position (skip-spaces command position)) (when position (setq ch (char command position)) (when (char= (character ",") ch) (setq from to) (multiple-value-setq (to position) (parse-address command (1+ position))) (if (eq to :error) (set-error "Invalid address") (setq position (skip-spaces command position)))))))))) (dbg (format t "PARC: from= ~S to= ~S position= ~S got-error= ~S~%" from to position (got-error))) (unless (got-error) (if (null position) (setq cmd (assoc nil *commands*)) (setq cmd (assoc (subseq command position (1+ position)) *commands* :test (function string=)) position (1+ position))) (dbg (format t "PARC: command key= ~S ~% cmd= ~S~%" (when position (subseq command (1- position) position)) (nconc (butlast cmd) (list (symbol-name (car (last cmd))))))) (let ((defr (second cmd)) (deto (third cmd)) (argk (fourth cmd)) (accp (fifth cmd)) (cmdf (sixth cmd))) (unless from (setq from defr)) (unless to (setq to deto)) (case argk ((nil)) ((character) (if (and position (< position (length command)) (alpha-char-p (char command position)) (lower-case-p (char command position))) (setf arg (char command position)) (set-error "Invalid mark character"))) ((number) (when position (multiple-value-setq (arg position) (parse-integer command :start position :junk-allowed t)) (unless arg (set-error "Invalid address")))) ((string) (when position (setq arg (subseq command position) position (length command)))) ((regexp) ) ((substitution) ) ((:curr) (when position (multiple-value-setq (arg position) (parse-address command position)) (cond ((eq arg :error) (set-error "Invalid address")) ((null arg) (setq arg :curr))))) (otherwise (set-error "Internal error: *command* table."))) (dbg (format t "PARC: from= ~S to= ~S position= ~S got-error= ~S~%" from to position (got-error)) (format t " arg= ~S ~%" arg)) (unless (got-error) (if (and accp position (< position (length command)) (char= (character "p") (char command position))) (setq print t) (when (and position (skip-spaces command position)) (set-error "Invalid command suffix"))) (unless (got-error) (dbg (format t "PARC: calling (~A ~S ~S ~S ~S ~S)~%" cmdf "BUFFER" from to arg print)) (setf (buffer-print buffer) print) (funcall cmdf buffer from to arg)))))))) (defun edit (buffer) (format *terminal-io* "~&") (setf (buffer-quit buffer) nil) (format *terminal-io* "~D~%" (buffer-length buffer)) (loop (let ((command (read-line *terminal-io* nil nil))) (unless command (return)) (dbg (format t "EDIT: read command ~S~%" command)) (setf (buffer-print buffer) nil) (buffer-clear-error buffer) (parse-and-run-command buffer command) (dbg (format t "EDIT: parc returned (~S ~S ~S)~%" (buffer-print buffer) (buffer-got-error buffer) (buffer-quit buffer))) (if (buffer-got-error buffer) (if (buffer-show-errors buffer) (format *terminal-io* "~A~%" (buffer-last-error buffer)) (format *terminal-io* "?~%")) (when (buffer-print buffer) (let ((current (buffer-current-linum buffer))) (if (limit current 1 (buffer-length buffer)) (format *terminal-io* "~A~%" (buffer-nth-line buffer current)) (progn (buffer-set-error buffer "Invalid address") (if (buffer-show-errors buffer) (format *terminal-io* "~A~%" (buffer-last-error buffer)) (format *terminal-io* "?~%"))))))) (if (buffer-quit buffer) (return) (when (buffer-show-prompt buffer) (format *terminal-io* "~A~%" (buffer-prompt-string buffer))))))) ;; ed &optional x => implementation-dependent ;; ;; ;; ;; Arguments and Values: ;; ;; ;; x---nil, a pathname, a string, or a function name. The default is nil. ;; ;; ;; Description: ;; ;; ;; ed invokes the editor if the implementation provides a resident editor. ;; ;; If x is nil, the editor is entered. If the editor had been previously ;; entered, its prior state is resumed, if possible. ;; ;; If x is a pathname or string, it is taken as the pathname designator ;; for a file to be edited. ;; ;; If x is a function name, the text of its definition is edited. The ;; means by which the function text is obtained is implementation-defined. (defparameter *current-buffer* (make-buffer)) (defun ed (&optional x) " DO: Invokes the ed(1)-like editor. X: NIL, a pathname, a string, or a function name. The default is NIL. " (cond ((null x) (edit *current-buffer*)) ((or (pathnamep x) (stringp x)) (setq *current-buffer* (buffer-read x)) (edit *current-buffer*)) ((symbolp x) (let ((fle (function-lambda-expression (fdefinition x)))) (setq *current-buffer* (buffer-from-string (if (eq 'lambda (car fle)) (format nil "~S~%" (cons 'defun (cons x (cdr fle)))) (format nil "~S is not a function.~%" x)))) (edit *current-buffer*))) ;; TODO: If x is a function name, ... (t (error "Invalid argument ~S." x)))) (defvar test-text "One little boy and Two little girls, climbed up a Tree near the sky. Four birds landed on that tree. Five eggs were layed each on one child head. ") ;; (progn (ext:cd "/home/pascal/src/lisp/encours/") (load "ed.lisp")) ;;;; THE END ;;;;
54,834
Common Lisp
.lisp
1,198
38.262104
99
0.563576
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
4d730992453dabb0dc03bc01e637db793b3dd9aa0805a4af57951a6219e9c33c
5,000
[ -1 ]
5,001
com.informatimago.common-lisp.ed.test.asd
informatimago_lisp/common-lisp/ed/com.informatimago.common-lisp.ed.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.ed.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.ed.test system. ;;;; Tests the com.informatimago.common-lisp.ed system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.ed.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.ed system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.ed.test/") ((#: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.common-lisp.ed" "com.informatimago.common-lisp.cesarum") :components () #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) ;; (let ((*package* (find-package "TESTED-PACKAGE"))) ;; (uiop:symbol-call "TESTED-PACKAGE" ;; "TEST/ALL")) )) ;;;; THE END ;;;;
2,941
Common Lisp
.lisp
67
37.716418
83
0.544568
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
ef738182ae2d9dd7325572c8e0bbdecf13dc19f1285d8248c9c8b4b1441dd772
5,001
[ -1 ]
5,002
com.informatimago.common-lisp.ed.asd
informatimago_lisp/common-lisp/ed/com.informatimago.common-lisp.ed.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.ed.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.ed library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.ed" ;; system attributes: :description "Informatimago Common Lisp Implementation of ED(1)" :long-description " This is the classic ed(1) editor implemented in Common Lisp. For now it's missing regular expressions that should be provided by com.informatimago.common-lisp.regexp (they could also be provided by cl-ppcre or #+clisp regexp). " :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.4.0" :properties ((#:author-email . "[email protected]") (#:date . "Autumn 2010") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.ed/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.regexp") :components ((:file "ed" :depends-on ())) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.ed.test")))) ;;;; THE END ;;;;
2,811
Common Lisp
.lisp
60
43.583333
106
0.606336
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
bcb0d5e2ffacad44fdf4411518df141daa58eb43ab5b28d50019c8091dfe76a0
5,002
[ -1 ]
5,003
package.lisp
informatimago_lisp/common-lisp/telnet/package.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: package.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Defines the telnet package. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2012-04-23 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2012 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.TELNET" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.ASCII" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.UTILITY") (:shadow "DO" "ABORT") (:export ;; Conditions: "TELNET-WARNING" "TELNET-WARNING-NVT" "TELNET-WARNING-FORMAT-CONTROL" "TELNET-WARNING-FORMAT-ARGUMENTS" "TELNET-OPTION-WARNING" "TELNET-OPTION-WARNING-OPTION" "TELNET-ERROR" "TELNET-ERROR-NVT" "TELNET-ERROR-FORMAT-CONTROL" "TELNET-ERROR-FORMAT-ARGUMENTS" "TELNET-OPTION-ERROR" "TELNET-OPTION-ERROR-OPTION" "TELNET-INVALID-OPTION-NAME-ERROR" "TELNET-INVALID-OPTION-NAME" "TELNET-INVALID-CONTROL-ERROR" "TELNET-INVALID-CONTROL" "TELNET-PROTOCOL-ERROR" "TELNET-PROTOCOL-ERROR-OPTION" "TELNET-PROTOCOL-ERROR-ACTION" "TELNET-PROTOCOL-ERROR-MESSAGE" ;; Classes: "NETWORK-VIRTUAL-TERMINAL" "NVT-OPTIONS" "NVT-CLIENT-P" "NVT-SEND-WAIT-P" "NVT-URGENT-MODE-P" "NVT-UP-SENDER" "NVT-DOWN-SENDER" "OPTION" "OPTION-CODE" "OPTION-NAME" ;; Up interface (from up): "SEND-BINARY" "SEND-TEXT" "SEND-CONTROL" "ASCII-DECODER-ENABLED-P" ;; Up interface (to up): "WANT-OPTION-P" "RECEIVE-BINARY" "RECEIVE-TEXT" "RECEIVE-CONTROL" ;; Down interface (to down): "SEND" ;; Down interface (from down): "RECEIVE" ;; Option control: "GET-OPTION" "OPTION-ENABLED-P" "OPTION-NEGOTIATING-P" "ENABLE-OPTION" "DISABLE-OPTION" "OPTION-REGISTER-CLASS" "OPTION-REGISTER-DEFAULT-CLASSES" ;; Implemented by subclasses of OPTION-STATE: "RECEIVE-SUBNEGOTIATION" "ENCODE-SUBNEGOTIATION" "DECODE-SUBNEGOTIATION" ;; Options: ;; STATUS "STATUS" "SEND-STATUS" ;; ) (:documentation " Implements the TELNET protocol. ")) ;;;; THE END ;;;;
3,175
Common Lisp
.lisp
83
35.518072
83
0.653821
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
80d8683fe8eb79e817a4e03e87c5a884a13cb168a0ea864a0111890141d680b4
5,003
[ -1 ]
5,004
status.lisp
informatimago_lisp/common-lisp/telnet/status.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: status.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Implements the STATUS telnet option. ;;;; RFC 859 STATUS ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2012-04-23 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2012 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COM.INFORMATIMAGO.COMMON-LISP.TELNET") (defclass status (option) () (:documentation " The STATUS Telnet Option. Usage: (defvar nvt (make-instance 'network-virtual-terminal)) (option-register-class nvt :status 'status) (enable-option nvt :status :us) (loop :while (option-negotiating-p nvt :status) :do (when (received-message buffer) (receive nvt buffer))) ;; force sending: (send-status (get-option nvt :status) nvt) ;; the status option sends a status automatically upon request. or: (enable-option nvt :status :him) (loop :while (option-negotiating-p nvt :status) :do (when (received-message buffer) (receive nvt buffer))) ;; the request is optional, the remote may send statuses spontaneously. (send-status-request (get-option nvt :status) nvt) (loop :do (when (received-message buffer) (receive nvt buffer))) ;; the RECEIVE-OPTION method of the up-sender is called when a ;; status is received. ")) (defgeneric send-status-request (status nvt)) (defgeneric send-status (status nvt)) (defgeneric receive-status (status nvt bytes &key start end)) (defmethod send-status-request ((opt status) nvt) "Send a STATUS SEND message." (if (option-enabled-p nvt :status :him) (send-raw-bytes nvt (vector IAC SB STATUS tq-SEND IAC SE)) (error 'telnet-option-error :nvt nvt :option opt :format-control "Option DO STATUS not enabled, can't send a STATUS request." :format-arguments '()))) (defmethod send-status ((opt status) nvt) "Send a STATUS IS message." (if (option-enabled-p nvt :status :us) (let ((buffer (make-array 8 :fill-pointer 0 :adjustable t :element-type 'ubyte))) (flet ((send (&rest bytes) (dolist (byte bytes) (vector-push-extend byte buffer (length buffer))))) (send iac) (dolist (opt (nvt-options nvt)) (when (opt-enabled-p opt :us) (send WILL (option-code opt)) (when (= SE (option-code opt)) (send SE))) (when (opt-enabled-p opt :him) (send DO (option-code opt)) (when (= SE (option-code opt)) (send SE))) (when (opt-enabled-p opt) (encode-subnegotiation opt buffer))) (send SE)) (send-raw-bytes nvt buffer)) (error 'telnet-option-error :nvt nvt :option opt :format-control "Option WILL STATUS not enabled, can't send a STATUS." :format-arguments '()))) (defmethod receive-status ((opt status) nvt bytes &key (start 0) (end (length bytes))) "Receive the STATUS IS message in (subseq bytes start end). We send a RECEIVE-OPTION message to the UP-SENDER with a value such as: (:status (:will optcode) (:do optcode) (:sb optcode …) (:error cmd optcode) …) " (receive-option (up-sender nvt) opt (cons :status (loop :with i = (+ start 4) :while (< i (- end 2)) :collect (case (aref bytes i) (#.DO (prog1 (list :do (option-name-for-code (aref bytes (incf i)))) (incf i))) (#.WILL (prog1 (list :will (option-name-for-code (aref bytes (incf i)))) (incf i))) (#.SB (let ((opt (init-option-code nvt (aref bytes (1+ i)))) (end (loop :with j = (+ i 2) :while (< j (- end 2)) :do (case (aref bytes j) (#.SE (if (= SE (aref bytes (1+ j))) (incf j 2) (return (1+ j)))) (#.IAC (if (= IAC (aref bytes (1+ j))) (incf j 2) (return j))) (otherwise (incf j))) :finally (return j)))) (prog1 (decode-subnegotiation opt bytes :start i :end end) (setf i end)))) (otherwise (warn 'telnet-option-warning :nvt nvt :option opt :format-control "Invalid subnegotiation command: ~A" :format-arguments (list (aref bytes i))) (prog1 ;; assuming there's an option code following… (list :error (aref bytes i) (aref bytes (incf i))) (incf i)))))))) (defmethod receive-subnegotiation ((opt status) nvt bytes &key (start 0) (end (length bytes))) "Parses the STATUS subnegotiation. The NVT has already parsed 'IAC SB STATUS' and 'IAC SE'. IAC SB STATUS TQ-SEND IAC SE IAC SB STATUS TQ-IS … IAC SE " (let ((len (- end start)) (subcmd (aref bytes (+ start 3)))) (cond ((and (= len 6) (= subcmd TQ-SEND)) (if (option-enabled-p nvt :status :us) (send-status opt nvt) (cerror "Ignore the status request." 'telnet-option-error :nvt nvt :option opt :format-control "Option DO STATUS not enabled, can't answer to STATUS SEND." :format-arguments '()))) ((and (< 6 len) (= subcmd TQ-IS)) (if (option-enabled-p nvt :status :him) (receive-status opt nvt bytes :start start :end end) (cerror "Ignore the status." 'telnet-option-error :nvt nvt :option opt :format-control "Option WILL STATUS not enabled, can't process STATUS IS." :format-arguments '()))) (t #|otherwise ignore it; is it what should be done?|# (warn 'telnet-option-warning :nvt nvt :option opt :format-control "Invalid subnegotiation message: ~S" :format-arguments (list (subseq bytes start end))))))) ;;;; THE END ;;;;
8,600
Common Lisp
.lisp
182
32.082418
99
0.4801
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
85d8a5e96ad2a647cc54ca8e5cd71726b6e932551bf4abe47f7541db71f21e8e
5,004
[ -1 ]
5,005
telnet.lisp
informatimago_lisp/common-lisp/telnet/telnet.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: telnet.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Implements the TELNET protocol. ;;;; ;;;; Features: ;;;; ;;;; - Small interfaces with the upper layer and with the lower layer. ;;;; (Clients may provide gray-streams or sockets implementing those interfaces.) ;;;; ;;;; - Negotiation of options is implemented using Bernstein's Q Method. ;;;; ;;;; - Subnegotiation of options is dereferred to option subclasses. ;;;; ;;;; - Implements all control functions. ;;;; ;;;; - Implements the TRANSMIT-BINARY option by forwarding bytes ;;;; instead of characters. ;;;; ;;;; - Implements the ECHO option (remote ECHO, not local terminal echo). ;;;; ;;;; - Implements the SUPPRESS-GO-AHEAD option. ;;;; ;;;; - Implements the END-OF-RECORD option. ;;;; ;;;; ;;;; ;;;; ;;;; ;;;; The following RFCs are implemented (checked 'v'): ;;;; ;;;; v RFC 854 ;;;; v RFC 855 ;;;; v RFC 856 ;;;; v RFC 857 ECHO ;;;; v RFC 858 SUPPRESS-GO-AHEAD ;;;; RFC 859 STATUS ;;;; RFC 860 TIMING-MARK ;;;; RFC 861 EXTENDED-OPTION-LIST ;;;; ;;;; RFC 854, RFC 855, RFC 856, RFC 857, RFC 858. RFC 859, RFC 860, RFC 861 ;;;; ;;;; The base telnet protocol specification. These describe the basic ;;;; protocol, and the first set of supported sub-options. ;;;; ;;;; v RFC 885 ;;;; ;;;; The End of Record option. I'm not sure what this is used for, but ;;;; I suspect that the IBM 3270 telnet spec may use it. It also adds a ;;;; new IAC escape sequence (EOR) to the set defined in RFC 854. ;;;; ;;;; RFC 927 ;;;; ;;;; A way to send a user ID in order to avoid having to have a login ;;;; prompt. ;;;; ;;;; RFC 933 ;;;; ;;;; A way to send a piece of text flagged as a 'banner' that is ;;;; constantly displayed on the screen. This is a DoD request so they ;;;; can avoid constantly resending banners that label things as 'top ;;;; secret'. ;;;; ;;;; RFC 1041 ;;;; ;;;; This describes a method to handle 3270 terminals via telnet. ;;;; ;;;; RFC 1073 ;;;; ;;;; This describes a way for telnet sessions to say something when the ;;;; size of their display window changes. ;;;; ;;;; RFC 1079 ;;;; ;;;; How to send information about what baud rate your connection is on ;;;; so programs can make decisions based on this. emacs, for example, ;;;; chooses and uglier, but much more efficient redraw method for ;;;; lower baud rates. ;;;; ;;;; RFC 1091 ;;;; ;;;; This describes a way for a server to query a client about terminal ;;;; types supported by the client's display. One might believe that ;;;; RFC 1408 obsoletes this, but this also describes a way for the ;;;; client and server to negotiate to a mutually agreeable terminal ;;;; type, which can't really be done using the protocol described in ;;;; RFC 1408. For exchanging terminal type information, this protocol ;;;; is preferred over RFC 1408. ;;;; ;;;; RFC 1096 ;;;; ;;;; Describes a method by which a server can query a client about what ;;;; X11 display it is on. This is definitely obsoleted by RFC ;;;; 1408. Future implementations need to understand this mechanism of ;;;; transferring X display information, but the protocol specififed in ;;;; RFC 1408 is the preferred method. ;;;; ;;;; RFC 1097 ;;;; ;;;; This describes a protocol that can be used to flag messages as ;;;; being subliminal messages. ;;;; ;;;; v RFC 1143 ;;;; ;;;; This describes, in detail, option negotiation loop ;;;; problems in the telnet protocol, and how to avoid them ;;;; when writing a telnet implementation. ;;;; ;;;; RFC 1116, RFC 1184 ;;;; ;;;; These two describe how to handle line-at-a-time mode. RFC 1184 ;;;; obsoletes RFC 1116, but linemode is complex, and having both RFCs ;;;; would probably clarify things. Also, linemode adds several IAC ;;;; escapes (EOF, SUSP, and ABORT) to the base set defined in RFC 854. ;;;; ;;;; RFC 1205 ;;;; ;;;; So, you want to pretend to be an IBM 5250 terminal.... ;;;; ;;;; RFC 1372 ;;;; ;;;; Describes a protocol for handling flow control. This is mainly ;;;; concerned with user-level flow control, like hitting Control-S to ;;;; pause output. ;;;; ;;;; RFC 1408, RFC 1571 ;;;; ;;;; Describes a protocol for sending environment variables from client ;;;; to server in the telnet protocol. This protocol could be used ;;;; instead of the terminal type (RFC 1091) and X11 display (RFC 1096) ;;;; protocols. ;;;; ;;;; Both of these RFCs are mentioned because the reference ;;;; implementation of RFC 1408 disagreed with the actual ;;;; implementation. RFC 1571 describes a method for resolving the ;;;; ambiguity. Because of this, the nearly identical protocol ;;;; described in RFC 1572 is the preferred method of sending ;;;; environment variables. ;;;; ;;;; RFC 1416 ;;;; ;;;; Describes a protocol for sending authentication information back ;;;; and forth between client and server. This protocol uses magic ;;;; numbers defined in RFC 1700 to indicate which authentication ;;;; method will be used, or is supported. ;;;; ;;;; RFC 1411 ;;;; ;;;; Describes how to use the protocol described in RFC 1416 to do ;;;; KERBEROS_V4 authentication. ;;;; ;;;; RFC 1572 ;;;; ;;;; Describes an alternate environment variable passing protocol that ;;;; fixes the ambiguities between the reference implementation, and ;;;; the text of the spec in RFC 1408 and RFC 1571. This is the ;;;; preferred environment variable passing protocol. ;;;; ;;;; RFC 2066 ;;;; ;;;; Describes a protocol that can be used to negotiate a character set ;;;; and input translations primarily for multi-lingual telnet. ;;;; ;;;; RFC 2217 ;;;; ;;;; Describes a protocol that can be used to exchange RS232 parameters ;;;; and modem control line state change information via telnet. This ;;;; is so telnet can be used as an interface to a modem pool or ;;;; terminal server. ;;;; ;;;; ;;;; ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2021-05-17 <PJB> Added ASCII-DECODER-ENABLE-P to pass ;;;; binary text buffer. ;;;; 2012-04-18 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2012 - 2021 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COM.INFORMATIMAGO.COMMON-LISP.TELNET") #-(and) " TELNET is a symetrical protocol. At both end lies a NVT, a Network Virtual Terminal. The NVT can send and receive text (ASCII character codes and a few ASCII control codes, or binary (notably for other encodings)), and can send and receive option negotiation messages. +------------+ | up:GSTREAM | +------------+ ^ | | | +---------------+ | | NVT-UP-SENDER | | +---------------+ | ^ | | v +--------------------------+ options --------------->| NETWORK-VIRTUAL-TERMINAL | +--------------------------+ | ^ | v | v +------------+ | +-----------------+ | OPTION-MGR |* | | NVT-DOWN-SENDER | +------------+ | +-----------------+ | | | v +--------------+ | down:GSTREAM | +--------------+ Arrows represent method calls. Typically, GSTREAM may be gray-streams, but that could be any kind of object. There's no class NVT-UP-SENDER or NVT-DOWN-SENDER, only a protocol defined by a set of generic functions. The bytes send by the up gstream to the NVT are transmitted (sometimes after being buffered in the NVT) to the NVT-DOWN-SENDER. The bytes received from the down gstream are parsed for option messages, updating in the NVT the set of configured options, and the text bytes are forwared to the NVT-UP-SENDER. Options can be queried and set by calling directly NVT methods. Internally, the NVT object defers to option managers to manage specific options subnegotiations. " ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Public interfaces. ;;; ;; Conditions (define-condition telnet-warning (warning) ((nvt :initarg :nvt :reader telnet-warning-nvt) (format-control :initarg :format-control :reader telnet-warning-format-control) (format-arguments :initarg :format-arguments :reader telnet-warning-format-arguments)) (:report (lambda (condition stream) (format stream "Telnet Warning with NVT ~S: ~?" (telnet-warning-nvt condition) (telnet-warning-format-control condition) (telnet-warning-format-arguments condition))))) (define-condition telnet-option-warning (telnet-warning) ((option :initarg :option :reader telnet-option-warning-option :type option)) (:report (lambda (condition stream) (format stream "Telnet Warning with NVT ~S, option ~A: ~?" (telnet-warning-nvt condition) (telnet-option-warning-option condition) (telnet-warning-format-control condition) (telnet-warning-format-arguments condition))))) (define-condition telnet-error (error) ((nvt :initarg :nvt :reader telnet-error-nvt) (format-control :initarg :format-control :reader telnet-error-format-control) (format-arguments :initarg :format-arguments :reader telnet-error-format-arguments)) (:report (lambda (condition stream) (if (and (slot-boundp condition 'format-control) (slot-boundp condition 'format-arguments)) (format stream "Telnet Error with NVT ~S: ~?" (telnet-error-nvt condition) (telnet-error-format-control condition) (telnet-error-format-arguments condition)) (format stream "Telnet Error with NVT ~S" (telnet-error-nvt condition)))))) (define-condition telnet-option-error (telnet-error) ((option :initarg :option :reader telnet-option-error-option)) (:report (lambda (condition stream) (if (and (slot-boundp condition 'format-control) (slot-boundp condition 'format-arguments)) (format stream "Telnet Error with NVT ~S, option ~A: ~?" (telnet-error-nvt condition) (telnet-option-error-option condition) (telnet-error-format-control condition) (telnet-error-format-arguments condition)) (format stream "Telnet Error with NVT ~S, option ~A." (telnet-error-nvt condition) (telnet-option-error-option condition)))))) (define-condition telnet-invalid-option-name-error (telnet-error) ((option-name :initarg :option-name :reader telnet-invalid-option-name)) (:report (lambda (condition stream) (format stream "Invalid option-name: ~S given to NVT ~S" (telnet-invalid-option-name condition) (telnet-error-nvt condition))))) (define-condition telnet-invalid-control-error (telnet-error) ((control :initarg :control :reader telnet-invalid-control)) (:report (lambda (condition stream) (format stream "Invalid control: ~S given to NVT ~S" (telnet-invalid-control condition) (telnet-error-nvt condition))))) (define-condition telnet-unknown-command-error (telnet-error) ((command :initarg :command :reader telnet-unknown-command)) (:report (lambda (condition stream) (format stream "Unknown comamnd ~S received by NVT ~S" (telnet-unknown-command condition) (telnet-error-nvt condition))))) ;; Up interface: ;; By default the telnet module decodes received ASCII texts. ;; However, clients may find it less than optimal. So we have the ;; option to disable this decoding. In that case, receive-text is ;; passed a byte vector instead of a string. ;; ;; The client may choose to pass strings or byte vectors to SEND-TEXT, ;; and the telnet module will encode automatically strings. ;; Up interface (from up): (defgeneric send-binary (nvt bytes) (:documentation "Send the binary text. NVT: a NETWORK-VIRTUAL-TERMINAL instance. BYTE: a VECTOR of (UNSIGNED-BYTE 8).")) (defgeneric send-text (nvt text) (:documentation "Send the ASCII text. NVT: a NETWORK-VIRTUAL-TERMINAL instance. TEXT: a string containing only printable ASCII characters and #\newline, or a vector of (unsigned-byte 7) containing only codes between 32 and 126, or (char-code #\newline). When the TEXT is a string, it's encoded into an ASCII code sequence. When the TEXT is a vector of bytes, it's transmitted as is (its content is still checked, to be conservative). ")) (defgeneric send-control (nvt control) (:documentation "Send a function control code. NVT: a NETWORK-VIRTUAL-TERMINAL instance. CONTROL: (member :synch :are-you-there :abort-output :interrupt-process :go-ahead :erase-line :erase-character :break :cr :ff :vt :lf :ht :bs :bel :nul :end-of-record).")) (defgeneric ascii-decoder-enabled-p (nvt) (:documentation "Returns whether text messages are decoded from ASCII. The default is T.")) (defgeneric (setf ascii-decoder-enabled-p) (flag nvt) (:documentation "Sets whether text messages are decoded from ASCII.")) ;; Up interface (to up): (defgeneric want-option-p (up-sender option-name) (:documentation "Asks the upper layer whether the option is wanted. OPTION-NAME: a keyword denoting the option.") (:method (up-sender option-code) (declare (ignorable up-sender option-code)) nil)) (defgeneric receive-option (up-sender option value) (:documentation "Receive a result from an option request. OPTION: the option instance. VALUE: a value the option sends back.")) (defgeneric receive-binary (up-sender bytes &key start end) (:documentation "Receive some binary text. BYTE: a VECTOR of (UNSIGNED-BYTE 8). START, END: bounding index designators of sequence. The defaults are for START 0 and for END nil.")) (defgeneric receive-text (up-sender text &key start end) (:documentation "Receive some ASCII text. TEXT: If (ASCII-DECODER-ENABLED-P nvt) then a string containing only printable ASCII characters and #\newline, else a vector of (unsigned-byte 7) containing only codes between 32 and 126, or (char-code #\newline). ")) (defgeneric receive-control (up-sender control) (:documentation "Receive a function code. CONTROL: (member :are-you-there :abort-output :interrupt-process :go-ahead :erase-line :erase-character :break :cr :ff :vt :lf :ht :bs :bel :nul :end-of-record).")) ;; Down interface (to down): (defgeneric send (down-sender bytes &key start end) (:documentation "Send the bytes to the remote NVT. BYTE: a VECTOR of (UNSIGNED-BYTE 8).")) (defgeneric send-urgent-notification (down-sender)) ;; Down interface (from down): (defgeneric receive (nvt bytes &key start end) (:documentation "Receive bytes from the remote NVT. NVT: a NETWORK-VIRTUAL-TERMINAL instance. BYTE: a VECTOR of (UNSIGNED-BYTE 8).")) ;; option control: (defgeneric option-enabled-p (nvt option-name &optional who) (:documentation "Whether the option is currently enabled, if WHO is nil, then for either end, otherwise for the indicated end. OPTION-NAME: a keyword or fixnum denoting the option. WHO: (member nil :us :him).")) (defgeneric option-negotiating-p (nvt option-name &optional who) (:documentation "Whether the option is currently being negotiated, if WHO is nil, then for either end, otherwise for the indicated end. OPTION-NAME: a keyword or fixnum denoting the option. WHO: (member nil :us :him).")) (defgeneric enable-option (nvt option-name &optional who) (:documentation "Initiate the negotiation to enable the option. OPTION-NAME: a keyword or fixnum denoting the option. WHO: (member nil :us :him).")) (defgeneric disable-option (nvt option-name &optional who) (:documentation "Initiate the negotiation to disable the option. OPTION-NAME: a keyword or fixnum denoting the option. WHO: (member nil :us :him).")) (defun (setf option-enabled-p) (flag nvt option-name &optional who) "Enable or disable the option according to the boolean FLAG. OPTION-NAME: a keyword or fixnum denoting an option." (if flag (enable-option nvt option-name who) (disable-option nvt option-name who))) (defgeneric option-register-class (nvt option-name option-class) (:documentation "Register OPTION-CLASS as the class for a given OPTION-NAME. NOTE: If the option is already initialized with a different class, then CHANGE-CLASS is called on the instance. OPTION-NAME: a keyword or fixnum denoting an option. OPTION-CLASS: a class designator, should be a subclass of OPTION.")) (defgeneric option-register-default-classes (nvt option-names) (:documentation "Register the default option-classes for the option given in OPTION-NAMES. NOTE: If the option is already initialized with a different class, then CHANGE-CLASS is called on the instance. OPTION-NAMES: a list of keyword or fixnum denoting options. RETURN: The subset of OPTION-NAMES (codes are converted into option-names) for which a specific default class exists.")) ;; Implemented by subclasses of OPTION: (defgeneric receive-subnegotiation (option nvt bytes &key start end) (:documentation "Processes the subnegotiation packet (subseq bytes start end) starting with IAC SB and ending with IAC SE.")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Telnet protocol codes. ;;; (eval-when (:compile-toplevel :load-toplevel :execute) (defconstant IAC 255 "Interpret As Command.") (defconstant DONT 254 "(option code) Indicates the demand that the other party stop performing, or confirmation that you are no longer expecting the other party to perform, the indicated option.") (defconstant DO 253 "(option code) Indicates the request that the other party perform, or confirmation that you are expecting the other party to perform, the indicated option.") (defconstant WONT 252 "(option code) Indicates the refusal to perform, or continue performing, the indicated option.") (defconstant WILL 251 "(option code) Indicates the desire to begin performing, or confirmation that you are now performing, the indicated option.") (defconstant SB 250 "(option code) Indicates that what follows is subnegotiation of the indicated option.") (defconstant GA 249 "The Go Ahead signal.") (defconstant EL 248 "The Erase Line function.") (defconstant EC 247 "The Erase Character function.") (defconstant AYT 246 "The Are You There function.") (defconstant AO 245 "The Abort Output function.") (defconstant IP 244 "The Interrupt Process function.") (defconstant BRK 243 "The NVT character Break.") (defconstant DM 242 "The data stream portion of a Synch. This should always be accompanied by a TCP Urgent notification.") (defconstant NOP 241 "No operation.") (defconstant SE 240 "End of subnegotiation parameters.") (defconstant EOR 239 "end or record (IAC EOR)") (defconstant ABORT 238 "line-mode abort") (defconstant SUSP 237 "line-mode suspend") (defconstant EOF 236 "line-mode end-of-file") ;; (defparameter *iac-3* ;; (list will wont do dont sb) ;; "List of command codes taking an option code parameter.") ;; Telnet protocol options code ;; These ones all come from arpa/telnet.h (defconstant TRANSMIT-BINARY 0 "8-bit data path") (defconstant ECHO 1 "echo") (defconstant RCP 2 "prepare to reconnect") (defconstant SUPPRESS-GO-AHEAD 3 "suppress go ahead") (defconstant NAMS 4 "approximate message size") (defconstant STATUS 5 "give status") (defconstant TIMING-MARK 6 "timing mark") (defconstant RCTE 7 "remote controlled transmission and echo") (defconstant NAOL 8 "negotiate about output line width") (defconstant NAOP 9 "negotiate about output page size") (defconstant NAOCRD 10 "negotiate about CR disposition") (defconstant NAOHTS 11 "negotiate about horizontal tabstops") (defconstant NAOHTD 12 "negotiate about horizontal tab disposition") (defconstant NAOFFD 13 "negotiate about formfeed disposition") (defconstant NAOVTS 14 "negotiate about vertical tab stops") (defconstant NAOVTD 15 "negotiate about vertical tab disposition") (defconstant NAOLFD 16 "negotiate about output LF disposition") (defconstant XASCII 17 "extended ascii character set") (defconstant LOGOUT 18 "force logout") (defconstant BM 19 "byte macro") (defconstant DET 20 "data entry terminal") (defconstant SUPDUP 21 "supdup protocol") (defconstant SUPDUPOUTPUT 22 "supdup output") (defconstant SNDLOC 23 "send location") (defconstant TTYPE 24 "terminal type") (defconstant END-OF-RECORD 25 "end or record (option)") (defconstant TUID 26 "TACACS user identification") (defconstant OUTMRK 27 "output marking") (defconstant TTYLOC 28 "terminal location number") (defconstant VT3270REGIME 29 "3270 regime") (defconstant X3PAD 30 "X.3 PAD") (defconstant NAWS 31 "window size") (defconstant TSPEED 32 "terminal speed") (defconstant LFLOW 33 "remote flow control") (defconstant LINEMODE 34 "Linemode option") (defconstant XDISPLOC 35 "X Display Location") (defconstant OLD-ENVIRON 36 "Old - Environment variables") (defconstant AUTHENTICATION 37 "Authenticate") (defconstant ENCRYPT 38 "Encryption option") (defconstant NEW-ENVIRON 39 "New - Environment variables") ;; the following ones come from ;; http://www.iana.org/assignments/telnet-options ;; Unfortunately, that document does not assign identifiers ;; to all of them, so we are making them up. (defconstant TN3270E 40 "TN3270E") (defconstant XAUTH 41 "XAUTH") (defconstant CHARSET 42 "CHARSET") (defconstant RSP 43 "Telnet Remote Serial Port") (defconstant COM-PORT-OPTION 44 "Com Port Control Option") (defconstant SUPPRESS-LOCAL-ECHO 45 "Telnet Suppress Local Echo") (defconstant TLS 46 "Telnet Start TLS") (defconstant KERMIT 47 "KERMIT") (defconstant SEND-URL 48 "SEND-URL") (defconstant FORWARD-X 49 "FORWARD-X") (defconstant PRAGMA-LOGON 138 "TELOPT PRAGMA LOGON") (defconstant SSPI-LOGON 139 "TELOPT SSPI LOGON") (defconstant PRAGMA-HEARTBEAT 140 "TELOPT PRAGMA HEARTBEAT") (defconstant EXTENDED-OPTION-LIST 255 "Extended-Options-List") (defconstant NOOPT 0) ;; sub-option qualifiers (defconstant TQ-IS 0 "option is... ") (defconstant TQ-SEND 1 "send option ") (defconstant TQ-INFO 2 "ENVIRON: informational version of IS ") (defconstant TQ-REPLY 2 "AUTHENTICATION: client version of IS ") (defconstant TQ-NAME 3 "AUTHENTICATION: client version of IS ") (defconstant FLOW-OFF 0 "Disable remote flow control ") (defconstant FLOW-ON 1 "Enable remote flow control ") (defconstant FLOW-RESTART-ANY 2 "Restart output on any char ") (defconstant FLOW-RESTART-XON 3 "Restart output only on XON ") ;; LINEMODE suboptions (defconstant MODE 1) (defconstant FORWARD-MASK 2) (defconstant SLC 3) (defconstant MODE-EDIT #x01) (defconstant MODE-TRAPSIG #x02) (defconstant MODE-ACK #x04) (defconstant MODE-SOFT-TAB #x08) (defconstant MODE-LIT-ECHO #x10) (defconstant MODE-MASK #x1f) ;; Not part of protocol, but needed to simplify things... (defconstant MODE-FLOW #x0100) (defconstant MODE-ECHO #x0200) (defconstant MODE-INBIN #x0400) (defconstant MODE-OUTBIN #x0800) (defconstant MODE-FORCE #x1000) (defconstant SLC-SYNCH 1) (defconstant SLC-BRK 2) (defconstant SLC-IP 3) (defconstant SLC-AO 4) (defconstant SLC-AYT 5) (defconstant SLC-EOR 6) (defconstant SLC-ABORT 7) (defconstant SLC-EOF 8) (defconstant SLC-SUSP 9) (defconstant SLC-EC 10) (defconstant SLC-EL 11) (defconstant SLC-EW 12) (defconstant SLC-RP 13) (defconstant SLC-LNEXT 14) (defconstant SLC-XON 15) (defconstant SLC-XOFF 16) (defconstant SLC-FORW1 17) (defconstant SLC-FORW2 18) (defconstant NSLC 18) (defconstant SLC-NOSUPPORT 0) (defconstant SLC-CANTCHANGE 1) (defconstant SLC-VARIABLE 2) (defconstant SLC-DEFAULT 3) (defconstant SLC-LEVELBITS #x03) (defconstant SLC-FUNC 0) (defconstant SLC-FLAGS 1) (defconstant SLC-VALUE 2) (defconstant SLC-ACK #x80) (defconstant SLC-FLUSHIN #x40) (defconstant SLC-FLUSHOUT #x20) (defconstant OLD-ENV-VAR 1) (defconstant OLD-ENV-VALUE 0) (defconstant ENV-VAR 0) (defconstant ENV-VALUE 1) (defconstant ENV-ESC 2) (defconstant ENV-USERVAR 3) ;; AUTHENTICATION suboptions ;; Who is authenticating who ... (defconstant AUTH-WHO-CLIENT 0 "Client authenticating server ") (defconstant AUTH-WHO-SERVER 1 "Server authenticating client ") (defconstant AUTH-WHO-MASK 1) ;; amount of authentication done (defconstant AUTH-HOW-ONE-WAY 0) (defconstant AUTH-HOW-MUTUAL 2) (defconstant AUTH-HOW-MASK 2) (defconstant AUTHTYPE-NULL 0) (defconstant AUTHTYPE-KERBEROS-V4 1) (defconstant AUTHTYPE-KERBEROS-V5 2) (defconstant AUTHTYPE-SPX 3) (defconstant AUTHTYPE-MINK 4) (defconstant AUTHTYPE-CNT 5) (defconstant AUTHTYPE-TEST 99) ;; ENCRYPTion suboptions (defconstant ENCRYPT-IS 0 "I pick encryption type ... ") (defconstant ENCRYPT-SUPPORT 1 "I support encryption types ... ") (defconstant ENCRYPT-REPLY 2 "Initial setup response ") (defconstant ENCRYPT-START 3 "Am starting to send encrypted ") (defconstant ENCRYPT-END 4 "Am ending encrypted ") (defconstant ENCRYPT-REQSTART 5 "Request you start encrypting ") (defconstant ENCRYPT-REQEND 6 "Request you send encrypting ") (defconstant ENCRYPT-ENC-KEYID 7) (defconstant ENCRYPT-DEC-KEYID 8) (defconstant ENCRYPT-CNT 9) (defconstant ENCTYPE-ANY 0) (defconstant ENCTYPE-DES-CFB64 1) (defconstant ENCTYPE-DES-OFB64 2) (defconstant ENCTYPE-CNT 3) );;eval-when ;; NVT codes ;; They are in COM.INFORMATIMAGO.COMMON-LISP.CESARUM.ASCII ;; (defconstant CR 13 ;; "") ;; ;; (defconstant FF 12 ;; "Moves the printer to the top of the next page, keeping the same ;; horizontal position.") ;; ;; (defconstant VT 11 ;; "Moves the printer to the next vertical tab stop. It remains ;; unspecified how either party determines or establishes where such ;; tab stops are located.") ;; ;; (defconstant LF 10 ;; "") ;; ;; (defconstant HT 9 ;; "Moves the printer to the next horizontal tab stop. It remains ;; unspecified how either party determines or establishes where such ;; tab stops are located.") ;; ;; (defconstant BS 8 ;; "Moves the print head one character position towards the left margin.") ;; ;; (defconstant BEL 7 ;; "Produces an audible or visible signal (which does NOT move the print head).") ;; ;; (defconstant NUL 0 ;; "") (defparameter *option-name-map* `((:transmit-binary ,transmit-binary) (:echo ,echo) (:rcp ,rcp) (:suppress-go-ahead ,suppress-go-ahead) (:nams ,nams) (:status ,status) (:timing-mark ,timing-mark) (:rcte ,rcte) (:naol ,naol) (:naop ,naop) (:naocrd ,naocrd) (:naohts ,naohts) (:naohtd ,naohtd) (:naoffd ,naoffd) (:naovts ,naovts) (:naovtd ,naovtd) (:naolfd ,naolfd) (:xascii ,xascii) (:logout ,logout) (:bm ,bm) (:det ,det) (:supdup ,supdup) (:supdupoutput ,supdupoutput) (:sndloc ,sndloc) (:ttype ,ttype) (:end-of-record ,end-of-record) (:tuid ,tuid) (:outmrk ,outmrk) (:ttyloc ,ttyloc) (:vt3270regime ,vt3270regime) (:x3pad ,x3pad) (:naws ,naws) (:tspeed ,tspeed) (:lflow ,lflow) (:linemode ,linemode) (:xdisploc ,xdisploc) (:old-environ ,old-environ) (:authentication ,authentication) (:encrypt ,encrypt) (:new-environ ,new-environ) (:tn3270e ,tn3270e) (:xauth ,xauth) (:charset ,charset) (:rsp ,rsp) (:com-port-option ,com-port-option) (:suppress-local-echo ,suppress-local-echo) (:tls ,tls) (:kermit ,kermit) (:send-url ,send-url) (:forward-x ,forward-x) (:pragma-logon ,pragma-logon) (:sspi-logon ,sspi-logon) (:pragma-heartbeat ,pragma-heartbeat) (:extended-option-list ,extended-option-list))) (defparameter *option-name-table* (hashtable :elements *option-name-map*) "Maps the option-name to option-code.") (defparameter *option-code-table* (loop :with table = (make-array 256 :initial-element nil) :for (name code) :in *option-name-map* :do (setf (aref table code) name) :finally (return table)) ;; NOTE: EXTENDED-OPTION-LIST may extend this array to 512 slots. "Maps the option-code to option-name.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; RFC1143: The Q Method of Implementing TELNET Option Negotiation ;;; (deftype telnet-action () '(member :do :dont :will :wont)) (deftype side-option-state () '(member :no :want-no :want-yes :yes)) (deftype side-option-queue () '(member :empty :opposite)) (deftype ubyte () '(unsigned-byte 8)) (defclass option () ((code :initarg :code :reader option-code) (name :initarg :name) (#-sbcl us #+sbcl sbcl-has-a-bug-so-we-cannot-name-our-slot-us-see-|https://bugs.launchpad.net/sbcl/+bug/539540| :initform :no :type side-option-state :accessor opt-us) (usq :initform :empty :type side-option-queue :accessor opt-usq) (him :initform :no :type side-option-state :accessor opt-him) (himq :initform :empty :type side-option-queue :accessor opt-himq))) (defgeneric option-name (option)) (defmethod option-name ((opt option)) "RETURN: The option name if it has one, otherwise the option code." (if (slot-boundp opt 'name) (slot-value opt 'name) (option-code opt))) (defun make-option (code name &optional (class 'option)) (make-instance class :code code :name name)) (defmethod print-object ((self option) stream) (print-unreadable-object (self stream :identity t :type t) (format stream "~S (~A) :us ~A :usq ~A :him ~A :himq ~A" (option-name self) (option-code self) (opt-us self) (opt-usq self) (opt-him self) (opt-himq self))) self) (define-condition telnet-protocol-error (telnet-error) ((option :initarg :option :reader telnet-protocol-error-option :type option) (action :initarg :action :reader telnet-protocol-error-action :type telnet-action) (message :initarg :message :reader telnet-protocol-error-message)) (:report (lambda (condition stream) (format stream "Telnet Protocol Error on ~A option ~A: ~A" (telnet-protocol-error-action condition) (option-code (telnet-protocol-error-option condition)) (telnet-protocol-error-message condition))))) (defgeneric opt-enabled-p (option &optional who) (:documentation "Indicate whether the OPTION is enabled, if WHO is nil, then for either end, otherwise for the indicated end. WHO: (member nil :us :him).") (:method ((os option) &optional who) (ecase who ((nil) (or (eq (opt-us os) :yes) (eq (opt-him os) :yes))) ((:us) (eq (opt-us os) :yes)) ((:him) (eq (opt-him os) :yes))))) (defgeneric want-do (option nvt) (:documentation "Initiated locally, to enable the OPTION on the remote.")) (defgeneric want-dont (option nvt) (:documentation "Initiated locally, to disable the OPTION on the remote.")) (defgeneric want-will (option nvt) (:documentation "Initiated locally, to enable the OPTION locally.")) (defgeneric want-wont (option nvt) (:documentation "Initiated locally, to disable the OPTION locally.")) (defgeneric receive-do (option nvt) (:documentation "Initiated remotely, to process a DO message.")) (defgeneric receive-dont (option nvt) (:documentation "Initiated remotely, to process a DONT message.")) (defgeneric receive-will (option nvt) (:documentation "Initiated remotely, to process a WILL message.")) (defgeneric receive-wont (option nvt) (:documentation "Initiated remotely, to process a WONT message.")) (defgeneric agree (nvt option-code) (:documentation "Whether the NVT agrees to enable the option.") (:method (nvt option-code) (declare (ignore nvt option-code)) nil)) (defgeneric send-do (nvt option-code) (:documentation "Implemented by the NVT object to send a DO message.")) (defgeneric send-dont (nvt option-code) (:documentation "Implemented by the NVT object to send a DONT message.")) (defgeneric send-will (nvt option-code) (:documentation "Implemented by the NVT object to send a WILL message.")) (defgeneric send-wont (nvt option-code) (:documentation "Implemented by the NVT object to send a WONT message.")) (defmethod want-do ((os option) nvt) (case (opt-him os) ((:no) (setf (opt-him os) :want-yes) (send-do nvt (option-code os))) ((:yes) (error 'telnet-protocol-error :nvt nvt :option os :action :do :message "already enabled")) ((:want-no) (case (opt-himq os) ((:empty) (setf (opt-himq os) :opposite)) ((:opposite) (error 'telnet-protocol-error :nvt nvt :option os :action :do :message "request is already enqueued")))) ((:want-yes) (case (opt-himq os) ((:empty) (error 'telnet-protocol-error :nvt nvt :option os :action :do :message "already negotiating")) ((:opposite) (setf (opt-himq os) :empty)))))) (defmethod want-dont ((os option) nvt) (case (opt-him os) ((:no) (error 'telnet-protocol-error :nvt nvt :option os :action :do :message "already disabled")) ((:yes) (setf (opt-him os) :want-no) (send-dont nvt (option-code os))) ((:want-no) (case (opt-himq os) ((:empty) (error 'telnet-protocol-error :nvt nvt :option os :action :dont :message "already negotiating")) ((:opposite) (setf (opt-himq os) :empty)))) ((:want-yes) (case (opt-himq os) ((:empty) (setf (opt-himq os) :opposite)) ((:opposite) (error 'telnet-protocol-error :nvt nvt :option os :action :dont :message "request is already enqueued ")))))) (defmethod want-will ((os option) nvt) (case (opt-us os) ((:no) (setf (opt-us os) :want-yes) (send-will nvt (option-code os))) ((:yes) (error 'telnet-protocol-error :nvt nvt :option os :action :will :message "already enabled")) ((:want-no) (case (opt-usq os) ((:empty) (setf (opt-usq os) :opposite)) ((:opposite) (error 'telnet-protocol-error :nvt nvt :option os :action :will :message "request is already enqueued")))) ((:want-yes) (case (opt-usq os) ((:empty) (error 'telnet-protocol-error :nvt nvt :option os :action :will :message "already negotiating")) ((:opposite) (setf (opt-usq os) :empty)))))) (defmethod want-wont ((os option) nvt) (case (opt-us os) ((:no) (error 'telnet-protocol-error :nvt nvt :option os :action :will :message "already disabled")) ((:yes) (setf (opt-us os) :want-no) (send-wont nvt (option-code os))) ((:want-no) (case (opt-usq os) ((:empty) (error 'telnet-protocol-error :nvt nvt :option os :action :wont :message "already negotiating")) ((:opposite) (setf (opt-usq os) :empty)))) ((:want-yes) (case (opt-usq os) ((:empty) (setf (opt-usq os) :opposite)) ((:opposite) (error 'telnet-protocol-error :nvt nvt :option os :action :wont :message "request is already enqueued ")))))) (defmethod receive-will ((os option) nvt) (case (opt-him os) ((:no) (if (agree nvt (option-code os)) (progn (setf (opt-him os) :yes) (send-do nvt (option-code os))) (send-dont nvt (option-code os)))) ((:yes) #|ignore|#) ((:want-no) (warn "DONT ~A answered by WILL ~:*~A" (option-code os)) (case (opt-himq os) ((:empty) (setf (opt-him os) :no)) ((:opposite) (setf (opt-him os) :yes (opt-himq os) :empty)))) ((:want-yes) (case (opt-himq os) ((:empty) (setf (opt-him os) :yes)) ((:opposite) (setf (opt-him os) :want-no (opt-himq os) :empty) (send-dont nvt (option-code os))))))) (defmethod receive-wont ((os option) nvt) (case (opt-him os) ((:no) #|ignore|#) ((:yes) (setf (opt-him os) :no) (send-dont nvt (option-code os))) ((:want-no) (case (opt-himq os) ((:empty) (setf (opt-him os) :no)) ((:opposite) (setf (opt-him os) :want-yes (opt-himq os) :empty) (send-do nvt (option-code os))))) ((:want-yes) (case (opt-himq os) ((:empty) (setf (opt-him os) :no)) ((:opposite) (setf (opt-him os) :no (opt-himq os) :empty)))))) (defmethod receive-do ((os option) nvt) (case (opt-us os) ((:no) (if (agree nvt (option-code os)) (progn (setf (opt-us os) :yes) (send-will nvt (option-code os))) (send-wont nvt (option-code os)))) ((:yes) #|ignore|#) ((:want-no) (warn "WONT ~A answered by DO ~:*~A" (option-code os)) (case (opt-usq os) ((:empty) (setf (opt-us os) :no)) ((:opposite) (setf (opt-us os) :yes (opt-usq os) :empty)))) ((:want-yes) (case (opt-usq os) ((:empty) (setf (opt-us os) :yes)) ((:opposite) (setf (opt-us os) :want-no (opt-usq os) :empty) (send-wont nvt (option-code os))))))) (defmethod receive-dont ((os option) nvt) (case (opt-us os) ((:no) #|ignore|#) ((:yes) (setf (opt-us os) :no) (send-wont nvt (option-code os))) ((:want-no) (case (opt-usq os) ((:empty) (setf (opt-us os) :no)) ((:opposite) (setf (opt-us os) :want-yes (opt-usq os) :empty) (send-will nvt (option-code os))))) ((:want-yes) (case (opt-usq os) ((:empty) (setf (opt-us os) :no)) ((:opposite) (setf (opt-us os) :no (opt-usq os) :empty)))))) ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; BUFFER ;;; ;;; The following functionnal abstraction specifies buffers, that are ;;; used to gather bytes and eat messages in FIFO order. ;;; ;;; This implementation moves eaten bytes down the vector, assuming ;;; there won't be a lot of remaining bytes to move. If this ;;; assumption reveals itself false, then another implementation, ;;; could be written. (declaim (inline make-buffer buffer-length buffer-ref buffer-subseq buffer-search buffer-clear)) (defun make-buffer (initial-size) (make-array initial-size :element-type '(unsigned-byte 8) :adjustable t :fill-pointer 0)) (defun buffer-length (buffer) (length buffer)) (defun buffer-ref (buffer index) (aref buffer index)) (defun buffer-subseq (buffer start end) (subseq buffer start end)) (defun buffer-search (subsequence buffer) (search subsequence buffer)) (defun buffer-clear (buffer) (setf (fill-pointer buffer) 0)) (defun buffer-delete-from-head (buffer size-to-remove) (replace buffer buffer :start2 size-to-remove) (decf (fill-pointer buffer) size-to-remove) buffer) (defun buffer-append (buffer bytes start end) (let* ((old-size (length buffer)) (new-size (+ old-size (- end start)))) (loop :while (< (array-dimension buffer 0) new-size) :do (setf buffer (adjust-array buffer (* 2 (array-dimension buffer 0)) :element-type (array-element-type buffer) :fill-pointer (fill-pointer buffer)))) (setf (fill-pointer buffer) new-size) (replace buffer bytes :start1 old-size :start2 start :end2 end) buffer)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; NETWORK-VIRTUAL-TERMINAL ;;; (defclass network-virtual-terminal () ((name :initform "NVT" :initarg :name :reader nvt-name) (client :initform t :initarg :client :reader nvt-client-p :documentation " Whether the NVT is the client (ie. is on the side that has initiated the connection).") (options :initform (make-hash-table) :documentation " The set of options that have been negotiated; keys are option-code, values are option-class or OPTION instances.") (up-sender :initarg :up-sender :reader up-sender :reader nvt-up-sender :documentation " The object to which the bytes received from the remote NVT are forwarded.") (down-sender :initarg :down-sender :reader down-sender :reader nvt-down-sender :documentation " The object to which the bytes to be sent to the remote NVT are given.") (send-wait-p :initform nil :accessor send-wait-p :reader nvt-send-wait-p :documentation " Whether sending should be suspended (bytes are kept in the send-buffer).") (send-buffer :initform (make-buffer 80) :reader send-buffer :documentation " Bytes received from up, waiting to be sent to the remote NVT.") (receive-buffer :initform (make-buffer 80) :reader receive-buffer :documentation " Bytes received from down, waiting to be parsed by the local NVT.") (urgent-mode-p :initform nil :accessor urgent-mode-p :reader nvt-urgent-mode-p :documentation "Urgent mode: we've received an urgent notification and are discarding text bytes till the next IAC DM.") (ascii-decoder-enabled-p :initform t :accessor ascii-decoder-enabled-p :documentation "Whether received text messages are decoded from ASCII.")) (:documentation "Represents a telnet end-point (both 'client' and 'server').")) (defgeneric init-option-name (nvt option-name)) (defgeneric init-option-code (nvt option-code &optional option-name)) (defgeneric get-option (nvt option-name)) (defmethod print-object ((self network-virtual-terminal) stream) (print-unreadable-object (self stream :identity t :type t) (format stream "~S (~:[server~;client~]) ~@[waiting~]" (nvt-name self) (nvt-client-p self) (nvt-send-wait-p self))) self) (defgeneric nvt-options (nvt)) (defmethod nvt-options ((nvt network-virtual-terminal)) "RETURN: A fresh list of the current OPTION instance in the NVT." (remove-if (function symbolp) (hash-table-values (slot-value nvt 'options)))) (defun process-binary (bytes) "Escape IAC with IAC." (let ((iacnt (count IAC bytes))) (if (plusp iacnt) (loop :with out = (make-array (+ (length bytes) iacnt) :element-type 'ubyte) :with j = -1 :for byte :across bytes :do (if (= IAC byte) (setf (aref out (incf j)) IAC (aref out (incf j)) IAC) (setf (aref out (incf j)) byte)) :finally (return out)) bytes))) (defun process-text (text) "Convert to ASCII bytes." (ascii-bytes text :newline :crlf)) ;; Up interface (from up): ;; TODO: When LINE-MODE we should keep in a buffer until an end of ;; record (CRLF, EOR, FORW1 FORW2, etc) is sent. On the other ;; hand, this may be done by the terminal layer itself? (defgeneric send-raw-bytes (nvt bytes)) (defmethod send-raw-bytes ((nvt network-virtual-terminal) bytes) "Send the binary bytes. NVT: a NETWORK-VIRTUAL-TERMINAL instance. BYTE: a VECTOR of (UNSIGNED-BYTE 8)." (if (send-wait-p nvt) (buffer-append (send-buffer nvt) bytes 0 (length bytes)) (send (down-sender nvt) bytes))) (defmethod send-urgent-notification ((nvt network-virtual-terminal)) (send-urgent-notification (down-sender nvt))) (defmethod send-binary ((nvt network-virtual-terminal) bytes) "Send the binary text. NVT: a NETWORK-VIRTUAL-TERMINAL instance. BYTE: a VECTOR of (UNSIGNED-BYTE 8)." (let ((processed-bytes (process-binary bytes))) (send-raw-bytes nvt processed-bytes))) (defmethod send-text ((nvt network-virtual-terminal) (text string)) "Send the ASCII text. NOTE: To send other characters than printable ASCII characters, use SEND-BINARY. NVT: a NETWORK-VIRTUAL-TERMINAL instance. TEXT: a string containing only printable ASCII characters and #\newline." (let ((processed-bytes (process-text text))) (send-binary nvt processed-bytes))) (defun validate-ascii-bytes (bytes) (loop :with i := 0 :while (< i (length bytes)) :do (let ((code (aref bytes i))) (unless (or (and (<= SP code) (< code DEL)) (and (= CR code) (< (incf i) (length bytes)) (= LF (aref bytes i)))) (error 'decoding-error :code code :coding-system :us-ascii :message (cond ((= CR code) (format nil "Invalid line separator ~S at position ~D; expected a CR-LF (13 10) subsequence." (vector code (aref bytes i)) i)) ((or (< code sp) (= code del)) (format nil "ASCII control code ~D (#x~:*~2,'0X), at position ~D, cannot be converted to characters." code i)) (t (format nil "Non-ASCII code ~D (#x~:*~2,'0X) (greater than 127), at position ~D" code i))))) (incf i)))) (defmethod send-text ((nvt network-virtual-terminal) (bytes vector)) "Send the ASCII bytes. NOTE: To send other characters than printable ASCII characters, use SEND-BINARY. NVT: a NETWORK-VIRTUAL-TERMINAL instance. TEXT: a byte vector containing only printable ASCII characters codes and CR-LF (13 10) subsequences." (validate-ascii-bytes bytes) (send-raw-bytes nvt bytes)) (defmethod send-control ((nvt network-virtual-terminal) control) "Send a function control code. NVT: a NETWORK-VIRTUAL-TERMINAL instance. CONTROL: (member :synch :are-you-there :abort-output :interrupt-process :go-ahead :erase-line :erase-character :break :cr :ff :vt :lf :ht :bs :bel :nul :end-of-record)." (cond ((eq control :synch) (send-raw-bytes nvt (vector IAC DM)) (send-urgent-notification nvt)) ((or (and (option-enabled-p nvt :suppress-go-ahead :us) (eq control :go-ahead)) (and (option-enabled-p nvt :end-of-record :us) (eq control :end-of-record))) #|don't send it|#) (t (send-raw-bytes nvt (if (typep control 'ubyte) (if (or (<= 0 control 31) (<= 127 control)) (vector control) (error 'telnet-invalid-control-error :nvt nvt :control control)) (case control (:erase-line #(#.IAC #.EL)) (:erase-character #(#.IAC #.EC)) (:are-you-there #(#.IAC #.AYT)) (:abort-output #(#.IAC #.AO)) (:interrupt-process #(#.IAC #.IP)) (:go-ahead #(#.IAC #.GA)) (:end-of-record #(#.IAC #.EOR)) (:break #(#.IAC #.BRK)) (:cr #(#.CR)) (:ff #(#.FF)) (:vt #(#.VT)) (:lf #(#.LF)) (:ht #(#.HT)) (:bs #(#.BS)) (:bel #(#.BEL)) (:nul #(#.NUL)) (otherwise (error 'telnet-invalid-control-error :nvt nvt :control control)))))))) ;; Down interface (from down): (defgeneric receive-urgent-notification (nvt)) (defmethod receive-urgent-notification ((nvt network-virtual-terminal)) (setf (urgent-mode-p nvt) t)) ;; We process the input buffer avoiding to make any needless copy ;; (hence the use of START and END parameters). ;; We may modify this input buffer (eg. to remove IAC IAC). ;; However if a buffer contains part or several messages (a sequence ;; of text code, or a telnet command), we copy it to the ;; receive-buffer of the nvt. (defun parse-message (buffer start end) "Return: (values kind len) KIND: (member nil :bytes :iac :iac-sb) indicates the kind of data at the START. LEN: number of bytes from START that belong to the message." (if (= start end) (values nil 0) ; no data yet. (let ((i start) (iac-iac nil)) (cond ((or (/= (aref buffer i) IAC) (and (< (1+ i) end) (= (aref buffer (1+ i)) IAC))) ;; A data byte. (loop (cond ((<= end i) (return-from parse-message (values :bytes (- i start) iac-iac))) ((/= (aref buffer i) IAC) (incf i)) ((and (< (1+ i) end) (= (aref buffer (1+ i)) IAC)) ;; IAC IAC (incf i 2) (setf iac-iac t)) (t (return-from parse-message (values :bytes (- i start) iac-iac)))))) ((or (<= end (1+ i)) (and (<= end (+ 2 i)) (case (aref buffer (1+ i)) ((#.do #.dont #.will #.wont #.sb) t) (otherwise nil)))) ;; just IAC: wait for more data. (return-from parse-message (values nil 0))) ((= (aref buffer (1+ i)) SB) ;; IAC SB (incf i 3) (loop (cond ((<= end i) ;; wait for more data, we don't have IAC SE. (return-from parse-message (values nil 0))) ((/= (aref buffer i) IAC) (incf i)) ((<= end (1+ i)) ;; wait for more data, we don't have IAC SE. (return-from parse-message (values nil 0))) ((= (aref buffer (1+ i)) IAC) ;; IAC IAC (incf i 2)) ((= (aref buffer (1+ i)) SE) ;; IAC SE (incf i 2) (return-from parse-message (values :iac-sb (- i start)))) (t ;; Should not occur? (incf i 2))))) ;; IAC commands: ((let ((command (aref buffer (1+ i)))) (or (= command WILL) (= command WONT) (= command DO) (= command DONT))) (return-from parse-message (values :iac 3))) (t (return-from parse-message (values :iac 2))))))) (defun remove-iac-iac (buffer start end) " PRE: (/= IAC (aref buffer (- end 1))) Actually: buffer contains no other occurence of IAC than IAC IAC pairs. RETURN: the new lengnth. " (loop :with j = start :with i = start :while (< i end) :do (progn (when (= IAC (aref buffer i)) (incf i)) (setf (aref buffer j) (aref buffer i)) (incf j) (incf i)) :finally (return (- j start)))) (defun get-next-chunk (bytes start end) " Split the text into printable chunks and control chunks. Control chunks contain only a single control code. Printable chunks may contain CR-LF sequences. BYTES: contains telnet text from START to END. RETURN: (values :incomplete next) if the bytes are incomplete (CR alone). (values :text next) if the bytes contain only ASCII printable codes and CR-LF. (values :control next code) if the bytes contain a control code. (values :done end) when end≤start. NEXT: the index of the first unprocessed byte. (<= START NEXT END) " (when (<= end start) (return-from get-next-chunk (values :done end))) (let ((i start)) (loop (cond ((<= end i) (if (< start i) (return-from get-next-chunk (values :text i)) (return))) ((ascii-printable-code-p (aref bytes i)) (incf i)) ((= cr (aref bytes i)) (if (<= end (1+ i)) (return-from get-next-chunk (values :incomplete i)) (if (= lf (aref bytes (1+ i))) ;; cr-lf goes to the string. (incf i 2) ;; cr-nul, or cr alone is a CR control code. (if (< start i) (return-from get-next-chunk (values :text i)) (return))))) (t ;; control code. (if (< start i) (return-from get-next-chunk (values :text i)) (return)))))) ;; control code (if (and (= cr (aref bytes start)) (< (1+ start) end) (= nul (aref bytes (1+ start)))) (values :control (+ 2 start) cr) (values :control (1+ start) (aref bytes start)))) (defun convert-control (code) (case code (#.NUL :nul) (#.BEL :bel) (#.BS :bs) (#.HT :ht) (#.LF :lf) (#.VT :vt) (#.FF :ff) (#.CR :cr) (otherwise nil))) (defgeneric dispatch-message (nvt bytes start end)) (defmethod dispatch-message ((nvt network-virtual-terminal) bytes start end) " RETURN: the length of bytes processed. " ;; if (urgent-mode-p nvt) discard text till next IAC DM. ;; interesting signals: IP AO AYT (not EC EL), other IAC. ;; if (option-enabled-p nvt :echo) the echo back the ;; text to the remote. (multiple-value-bind (kind len iac-iac) (parse-message bytes start end) (case kind ((nil) len) (:bytes (when (option-enabled-p nvt :echo :us) (send (down-sender nvt) bytes start (+ start len))) (if (urgent-mode-p nvt) ;; ignore text bytes len (let* ((newlen (if iac-iac (remove-iac-iac bytes start (+ start len)) len)) (newend (+ start newlen))) (if (option-enabled-p nvt :transmit-binary :him) (progn (receive-binary (up-sender nvt) bytes :start start :end newend) len) (loop :with processed = start :do (multiple-value-bind (kind next code) (get-next-chunk bytes processed newend) (ecase kind ((:done :incomplete) (when (< newend end) (replace bytes bytes :start1 (+ processed (- end newend)) :end1 newend :start2 processed :end2 end)) (return (- (+ processed (- end newend)) start))) ((:text) (if (ascii-decoder-enabled-p nvt) (receive-text (up-sender nvt) (ascii-string bytes :newline :crlf :start processed :end newend)) (receive-text (up-sender nvt) bytes :start processed :end newend))) ((:control) (let ((control (convert-control code))) (when control (receive-control (up-sender nvt) control))))) (setf processed next))))))) (:iac (case (aref bytes (1+ start)) (#.DONT (receive-dont (init-option-code nvt (aref bytes (+ 2 start))) nvt)) (#.DO (receive-do (init-option-code nvt (aref bytes (+ 2 start))) nvt)) (#.WONT (receive-wont (init-option-code nvt (aref bytes (+ 2 start))) nvt)) (#.WILL (receive-will (init-option-code nvt (aref bytes (+ 2 start))) nvt)) (#.AYT (receive-control (up-sender nvt) :are-you-there)) (#.AO (receive-control (up-sender nvt) :abort-output)) (#.IP (receive-control (up-sender nvt) :interrupt-process)) (#.GA (unless (option-enabled-p nvt :suppress-go-ahead :him) (receive-control (up-sender nvt) :go-ahead))) (#.DM (if (urgent-mode-p nvt) (setf (urgent-mode-p nvt) nil) #|ignored in non-urgent mode|#)) (#.EL (unless (urgent-mode-p nvt) (receive-control (up-sender nvt) :erase-line))) (#.EC (unless (urgent-mode-p nvt) (receive-control (up-sender nvt) :erase-character))) (#.BRK (unless (urgent-mode-p nvt) (receive-control (up-sender nvt) :break))) (#.EOR (unless (urgent-mode-p nvt) ;; EOR must be negotiated! ;; EOR are intended to signal a unit for display (page). ;; they can be sent after a prompt that doesn't end in a newline. ;; Note receiving them from a terminal is not very meaningful. ;; A server may sent them to the terminal to initiate rendering. ;; https://public.support.unisys.com/aseries/docs/ClearPath-MCP-18.0/88076385-021/section-000020933.html ;; TODO: Do we need to echo EOR? ;; -> Probably not. ;; TODO: Can we echo EOR without having negotiated it? ;; -> Probably not. ;; (when (option-enabled-p nvt :echo :us) ;; (send (down-sender nvt) bytes start (+ start len))) (when (option-enabled-p nvt :end-of-record :him) (receive-control (up-sender nvt) :end-of-record)))) (#.IAC (unless (urgent-mode-p nvt) ;; note: IAC IAC should be processed in :bytes ;; this is just in case of a change in parse-message. (when (option-enabled-p nvt :echo :us) (send (down-sender nvt) bytes start (+ start len))) (receive-binary (up-sender nvt) iac))) (#.NOP) (otherwise (cerror "Ignore the command." 'telnet-unknown-command-error :nvt nvt :command (aref bytes (1+ start))))) len) (:iac-sb (let ((opt (init-option-code nvt (aref bytes (+ 2 start))))) (receive-subnegotiation opt nvt bytes :start start :end len)) len)))) (defmethod receive ((nvt network-virtual-terminal) bytes &key (start 0) (end (length bytes))) "Receive bytes from the remote NVT. NOTE: this may modify the BYTES vector between START and END, eg. in presence of IAC IAC. NVT: a NETWORK-VIRTUAL-TERMINAL instance. BYTE: a VECTOR of (UNSIGNED-BYTE 8)." (when (< start end) (let ((buf (receive-buffer nvt))) (if (plusp (buffer-length buf)) ;; We already have bytes in the buffer. ;; Append the new one and try to parse the buffer. (progn (buffer-append buf bytes start end) (loop (let ((processed (dispatch-message nvt buf 0 (buffer-length buf)))) (incf start processed) (if (plusp processed) (buffer-delete-from-head buf processed) (return))))) ;; The buffer is empty, try to parse the bytes directly. (loop :while (< start end) :do (let ((processed (dispatch-message nvt bytes start end))) (incf start processed) (when (zerop processed) (buffer-append buf bytes start end) (return)))))))) ;; Down interface (to down): (defmethod send-do ((nvt network-virtual-terminal) option-code) "Implemented by the REMOTE object to send a DO message." (send (down-sender nvt) (vector IAC DO option-code))) (defmethod send-dont ((nvt network-virtual-terminal) option-code) "Implemented by the REMOTE object to send a DONT message." (send (down-sender nvt) (vector IAC DONT option-code))) (defmethod send-will ((nvt network-virtual-terminal) option-code) "Implemented by the REMOTE object to send a WILL message." (send (down-sender nvt) (vector IAC WILL option-code))) (defmethod send-wont ((nvt network-virtual-terminal) option-code) "Implemented by the REMOTE object to send a WONT message." (send (down-sender nvt) (vector IAC WONT option-code))) ;; Interface for the STATUS option: (defgeneric decode-subnegotiation (option byte &key start end) (:documentation "Returns a sexp describing the STATUS SB (subseq byte start end). This vector starts with SB option-code and ends with SE. Any data byte equal to SE or IAC is be duplicated. The returned sexp must start with (:SB option-name …). \(Used by RECEIVE-STATUS of class STATUS to decode the SB statuses.) ") (:method ((opt option) byte &key (start 0) (end (length byte))) (declare (ignorable byte start end)) ; for some implementation byte is not used … (cerror "Ignore the subnegotiation status." 'telnet-option-error ;; :nvt nvt ;; TODO: Do we need it? Should we keep the nvt in a dynamic variable? :option opt :format-control "Option STATUS received an unknown subnegotiation status for option ~:@(~A~)." :format-arguments (list (option-name opt))) ;; Let's return nothing instead of a (:sb …) list. (values))) (defgeneric encode-subnegotiation (option buffer) (:documentation " If the OPTION has any subnegotiated status, it should encode them in the buffer. Each subnegotiated status should start with SB and end with SE; Any data byte equal to SE or IAC should be duplicated. SB OPTION-CODE … SE BUFFER: An adjustable vector with a fill-pointer. \(Used by SEND-STATUS of class STATUS to encode the SB statuses.) ") (:method ((opt option) buffer) ;; nothing to add. buffer)) ;; Option control: (defun option-name-for-code (option-code) (and (array-in-bounds-p *option-code-table* option-code) (aref *option-code-table* option-code))) (defun option-code-for-name (option-name) (typecase option-name (keyword (gethash option-name *option-name-table*)) ((integer 0 511) option-name) (t nil))) (defmethod agree ((nvt network-virtual-terminal) option-code) "Whether the NVT agrees to enable the option." (let ((option-name (option-name-for-code option-code))) (when option-name (want-option-p (up-sender nvt) option-name)))) (defmethod init-option-code ((nvt network-virtual-terminal) option-code &optional option-name) (let ((opt (gethash option-code (slot-value nvt 'options))) (option-name (or option-name (option-name-for-code option-code)))) (typecase opt (null (setf (gethash option-code (slot-value nvt 'options)) (make-option option-code option-name))) (option opt) ((or symbol class) (setf (gethash option-code (slot-value nvt 'options)) (make-option option-code option-name opt))) (t (setf (gethash option-code (slot-value nvt 'options)) (make-option option-code option-name)))))) (defmethod init-option-name ((nvt network-virtual-terminal) option-name) (let ((code (option-code-for-name option-name))) (if code (init-option-code nvt code option-name) (error 'telnet-invalid-option-name-error :nvt nvt :option-name option-name)))) (defmethod get-option ((nvt network-virtual-terminal) option-name) " OPTION-NAME: a keyword or fixnum denoting the option. RETURN: the OPTION instance named OPTION-NAME, if it has been initialized (with ENABLE-OPTION or DISABLE-OPTION), or NIL otherwise. " (let ((code (option-code-for-name option-name))) (if code (let ((opt (gethash code (slot-value nvt 'options)))) (typecase opt (option opt) (t nil))) (error 'telnet-invalid-option-name-error :nvt nvt :option-name option-name)))) (defmethod option-enabled-p ((nvt network-virtual-terminal) (option-name t) &optional who) "Whether the option is currently enabled. OPTION-NAME: a keyword or fixnum denoting the option." (let ((opt (get-option nvt option-name))) (and opt (opt-enabled-p opt who)))) (defmethod option-enabled-p ((nvt network-virtual-terminal) (option option) &optional who) "Whether the option is currently enabled. OPTION: an OPTION instance" (opt-enabled-p option who)) (defmethod option-negotiating-p ((nvt network-virtual-terminal) option-name &optional who) "Whether the option is currently being negotiated." (let ((opt (get-option nvt option-name))) (and opt (ecase who ((nil) (and (not (member (opt-us opt) '(:no :yes))) (not (member (opt-him opt) '(:no :yes))))) ((:us) (not (member (opt-us opt) '(:no :yes)))) ((:him) (not (member (opt-him opt) '(:no :yes)))))))) (defmethod enable-option ((nvt network-virtual-terminal) option-name &optional who) "Initiate the negotiation to enable the option. OPTION-NAME: a keyword or fixnum denoting the option. RETURN: The OPTION instance." (let ((opt (init-option-name nvt option-name))) (ecase who ((nil) (want-do opt nvt) (want-will opt nvt)) ((:us) (want-will opt nvt)) ((:him) (want-do opt nvt))) opt)) (defmethod disable-option ((nvt network-virtual-terminal) option-name &optional who) "Initiate the negotiation to disable the option. OPTION-NAME: a keyword or fixnum denoting the option. RETURN: The OPTION instance." (let ((opt (init-option-name nvt option-name))) (ecase who ((nil) (want-dont opt nvt) (want-wont opt nvt)) ((:us) (want-wont opt nvt)) ((:him) (want-dont opt nvt))) opt)) (defmethod option-register-class ((nvt network-virtual-terminal) option-name option-class) "Register OPTION-CLASS as the class for a given OPTION-NAME. NOTE: If the option is already initialized with a different class, then CHANGE-CLASS is called on the OPTION instance. OPTION-NAME: a keyword or fixnum denoting an option. OPTION-CLASS: a class designator." (let ((class (etypecase option-class (symbol (find-class option-class)) (class option-class))) (code (option-code-for-name option-name))) (if code (let ((opt (gethash code (slot-value nvt 'options)))) (typecase opt (option (change-class opt class)) (t (setf (gethash code (slot-value nvt 'options)) class)))) (error 'telnet-invalid-option-name-error :nvt nvt :option-name option-name)))) (defparameter *default-classes* '((:transmit-binary . option) (:echo . option) (:suppress-go-ahead . option) (:end-of-record . option) ;; (:timing-mark . option) (:status . status)) ;; NOTE: when the class is OPTION, it means the option has no ;; specific behavior besides being enabled or disabled (but ;; the NVT may alter its behavior according to the setting of ;; the option). "An a-list of (option-name . class-name).") (defmethod option-register-default-classes ((nvt network-virtual-terminal) option-names) (let ((in-default-classes '())) (dolist (option-name option-names in-default-classes) (let* ((code (option-code-for-name option-name)) (option-name (aref *option-code-table* code)) (entry (assoc option-name *default-classes*))) (when entry (push option-name in-default-classes) (option-register-class nvt option-name (cdr entry))))))) (defmethod initialize-instance ((nvt network-virtual-terminal) &key &allow-other-keys) (call-next-method) (option-register-default-classes nvt (mapcar (function car) *default-classes*)) nvt) ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; THE END ;;;;
74,869
Common Lisp
.lisp
1,643
38.127815
132
0.583153
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
77cff689ef61236b39de14e10987cc78ba34c3d9c0d7663dcd847363ae4b04bb
5,005
[ -1 ]
5,006
com.informatimago.common-lisp.telnet.asd
informatimago_lisp/common-lisp/telnet/com.informatimago.common-lisp.telnet.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.telnet.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.telnet library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2012-04-22 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2012 - 2016 ;;;; ;;;; 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.common-lisp.telnet" ;; system attributes: :description "Informatimago Common Lisp Implementation of the TELNET Protocol" :long-description " This is the core of the TELNET protocol, written in conforming Common Lisp. Additionnal modules (provided in com.informatimago.clext.telnet) are needed to interface with eg. a terminal emulator or a gray-stream, and with a TCP/IP socket or other communication service. " :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.11.0" :properties ((#:author-email . "[email protected]") (#:date . "Spring 2012") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.telnet/") ((#: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.common-lisp.cesarum") :components ((:file "package" :depends-on ()) (:file "telnet" :depends-on ("package")) (:file "status" :depends-on ("package" "telnet"))) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.telnet.test")))) ;;;; THE END ;;;;
2,962
Common Lisp
.lisp
62
44.322581
110
0.610919
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
41550459632ac7f5cae3b6672973ecd497550976524c4a6aa4f8a637386ef827
5,006
[ -1 ]
5,007
com.informatimago.common-lisp.telnet.test.asd
informatimago_lisp/common-lisp/telnet/com.informatimago.common-lisp.telnet.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.telnet.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.telnet.test system. ;;;; Tests the com.informatimago.common-lisp.telnet system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.telnet.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.telnet system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.telnet.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.telnet") :components ((:file "telnet-test" :depends-on nil)) #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) (let ((*package* (find-package "COM.INFORMATIMAGO.COMMON-LISP.TELNET.TEST"))) (uiop:symbol-call "COM.INFORMATIMAGO.COMMON-LISP.TELNET.TEST" "TEST/ALL")))) ;;;; THE END ;;;;
3,022
Common Lisp
.lisp
66
39.5
105
0.563304
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
c46f6712c4ecb34511743357d44edaf21b13367a28d651b95268ed1b62e15f1b
5,007
[ -1 ]
5,008
test.lisp
informatimago_lisp/common-lisp/telnet/test.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: test.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; XXX ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2012-04-24 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2012 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COM.INFORMATIMAGO.COMMON-LISP.TELNET") (defmethod send-binary :before ((self network-virtual-terminal) bytes) (format *trace-output* "~S send-binary ~S~%" self bytes) (force-output *trace-output*)) (defmethod send-text :before ((self network-virtual-terminal) text) (format *trace-output* "~S send-text ~S~%" self text) (force-output *trace-output*)) (defmethod send-control :before ((self network-virtual-terminal) control) (format *trace-output* "~S send-control ~S~%" self control) (force-output *trace-output*)) (defmethod receive :before ((self network-virtual-terminal) bytes &key start end) (format *trace-output* "~S receive ~S~%" self (subseq bytes start end)) (force-output *trace-output*)) (defclass layer () ((name :initform "Anonymous Layer" :initarg :name :reader layer-name) (nvt :accessor layer-nvt))) (defmethod print-object ((self layer) stream) (print-unreadable-object (self stream :identity t :type t) (format stream "~S" (layer-name self))) self) (defclass up-layer (layer) ((wanted-options :initform '() :initarg :wanted-options :accessor wanted-options))) (defmethod want-option-p ((self up-layer) option-name) (find option-name (wanted-options self))) (defmethod receive-option ((self up-layer) option value) (format *trace-output* "~S received option ~S = ~S~%" self option value) (force-output *trace-output*) (list (option-name option) value)) (defmethod receive-binary ((self up-layer) bytes &key (start 0) (end (length bytes))) (let ((packet (subseq bytes start end))) (format *trace-output* "~S received binary: ~S~%" self packet) (force-output *trace-output*) packet)) (defmethod receive-text ((self up-layer) text) (format *trace-output* "~S received text: ~S~%" self text) (force-output *trace-output*) text) (defmethod receive-control ((self up-layer) control) (format *trace-output* "~S received control ~S~%" self control) (force-output *trace-output*) (case control (:are-you-there (send-text (layer-nvt self) (format nil "~%~A is here.~%" (layer-name self))))) #-(and) (:are-you-there :abort-output :interrupt-process :go-ahead :erase-line :erase-character :break :cr :ff :vt :lf :ht :bs :bel :nul :end-of-record) control) (defclass down-layer (layer) ((remote :initform nil :accessor layer-remote))) (defmethod layer-receive ((self down-layer) packet) (format *trace-output* "~S receiving ~S~%" self packet) (force-output *trace-output*) (receive (layer-nvt self) packet :start 0 :end (length packet))) (defmethod send ((self down-layer) bytes &key (start 0) (end (length bytes))) (let ((packet (subseq bytes start end))) (format *trace-output* "~S sending ~S~%" self packet) (force-output *trace-output*) (when (layer-remote self) (layer-receive (layer-remote self) packet)))) (defparameter *wanted-options* '(:transmit-binary :echo :suppress-go-ahead :end-of-record :status)) (defparameter *ulc* (make-instance 'up-layer :name "Client UP" :wanted-options *wanted-options*)) (defparameter *uls* (make-instance 'up-layer :name "Server UP" :wanted-options *wanted-options*)) (defparameter *dlc* (make-instance 'down-layer :name "Client DOWN")) (defparameter *dls* (make-instance 'down-layer :name "Server DOWN")) (defparameter *client* (make-instance 'network-virtual-terminal :name "CLIENT NVT" :client t :up-sender *ulc* :down-sender *dlc*)) (defparameter *server* (make-instance 'network-virtual-terminal :name "SERVER NVT" :client nil :up-sender *uls* :down-sender *dls*)) (setf (layer-nvt *ulc*) *client* (layer-nvt *dlc*) *client* (layer-nvt *uls*) *server* (layer-nvt *dls*) *server* (layer-remote *dls*) *dlc* (layer-remote *dlc*) *dls*) (print-hashtable (slot-value *client* 'options)) ;; (send-binary (layer-nvt self) #(1 2 3 4)) ;; (send-text (layer-nvt self) "Hello") ;; (send-control (layer-nvt self) :bel) (send-text (layer-nvt *ulc*) "Hello") (send-control (layer-nvt *ulc*) :bel) (send-binary (layer-nvt *ulc*) #(1 2 3 4)) (enable-option (layer-nvt *ulc*) :transmit-binary :us) (loop :while (option-negotiating-p (layer-nvt *ulc*) :transmit-binary)) (send-binary (layer-nvt *ulc*) #(1 2 3 4)) (send-text (layer-nvt *ulc*) "World!") (send-control (layer-nvt *ulc*) :bel) (send-control (layer-nvt *ulc*) :are-you-there) (send-control (layer-nvt *ulc*) :interrupt-process) (send-control (layer-nvt *ulc*) :abort-output) (enable-option (layer-nvt *ulc*) :status :us) (loop :while (option-negotiating-p (layer-nvt *ulc*) :status)) (send-status (get-option (layer-nvt *ulc*) :status) (layer-nvt *ulc*)) (send-status (get-option (layer-nvt *ulc*) :status) (layer-nvt *ulc*)) (get-option (layer-nvt *ulc*) :status) (define-condition interrupt-signal-condition (condition) () (:report "interrupt signal")) (defun test/interrupt () (let* ((iota (bt:make-thread (lambda () (unwind-protect (loop :for i :from 1 :do (sleep 1) (princ i) (princ " ") (finish-output)) (princ "Done") (terpri) (finish-output))) :name "iota runner"))) (sleep 10) (bt:interrupt-thread iota (function invoke-debugger) (make-condition 'interrupt-signal-condition)) (princ "Complete.") (terpri) (finish-output)))
7,312
Common Lisp
.lisp
153
41.352941
102
0.611431
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
d629afdfbede237b34a1920ba0ec25ef893756d24983cee047aafba6d608796c
5,008
[ -1 ]
5,009
telnet-test.lisp
informatimago_lisp/common-lisp/telnet/telnet-test.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: telnet-test.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Tests telnet.lisp ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-02-25 <PJB> Extracted from telnet.lisp. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.TELNET.TEST" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.SIMPLE-TEST" "COM.INFORMATIMAGO.COMMON-LISP.TELNET") (:import-from "COM.INFORMATIMAGO.COMMON-LISP.TELNET" "PARSE-MESSAGE" "REMOVE-IAC-IAC" "GET-NEXT-CHUNK" "IAC" "NOP" "SB" "SE" "XDISPLOC") (:export "TEST/ALL")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.TELNET.TEST") (define-test test/parse-message () ;; nothing (assert-true (equal (multiple-value-list (parse-message (vector 1 2 3 4 5) 1 1)) '(nil 0))) ;; :bytes (assert-true (equal (multiple-value-list (parse-message (vector 1 2 3 4 5) 0 5)) '(:bytes 5 nil))) (assert-true (equal (multiple-value-list (parse-message (vector iac iac 1 2 3) 0 5)) '(:bytes 5 t))) (assert-true (equal (multiple-value-list (parse-message (vector 1 2 3 iac iac) 0 5)) '(:bytes 5 t))) (assert-true (equal (multiple-value-list (parse-message (vector 1 2 iac iac 3) 0 5)) '(:bytes 5 t))) (assert-true (equal (multiple-value-list (parse-message (vector 1 2 3 iac nop) 0 5)) '(:bytes 3 nil))) (assert-true (equal (multiple-value-list (parse-message (vector 1 2 iac iac 3 iac nop) 0 7)) '(:bytes 5 t))) (assert-true (equal (multiple-value-list (parse-message (vector 1 2 iac iac 3 iac) 0 6)) '(:bytes 5 t))) ;; iac commands (assert-true (equal (multiple-value-list (parse-message (vector iac nop 1 2 3) 0 5)) '(:iac 2))) (assert-true (equal (multiple-value-list (parse-message (vector iac nop iac iac iac) 0 5)) '(:iac 2))) ;; iac sb (assert-true (equal (multiple-value-list (parse-message (vector iac sb xdisploc 75 85 73 80 69 82 58 48 46 48 iac se 1 2 3) 0 15)) '(:iac-sb 15))) (assert-true (equal (multiple-value-list (parse-message (vector iac sb xdisploc 75 85 73 80 69 82 58 48 46 48 iac se 1 2 3) 0 18)) '(:iac-sb 15))) (assert-true (equal (multiple-value-list (parse-message (vector iac sb xdisploc 75 85 73 80 69 82 58 iac iac 48 46 48 iac se 1 2 3) 0 20)) '(:iac-sb 17))) (assert-true (equal (multiple-value-list (parse-message (vector iac sb xdisploc 75 85 73 80 69 82 58 48 46 48 iac se 1 2 3) 0 14)) '(nil 0))) (assert-true (equal (multiple-value-list (parse-message (vector iac sb xdisploc 75 85 73 80 69 82 58 48 46 48 iac se 1 2 3) 0 13)) '(nil 0)))) (define-test test/remove-iac-iac () (let ((buffer (vector 1 2 3 4 5 6 7 8 9))) (assert-true (= 5 (remove-iac-iac buffer 2 7))) (assert-true (equalp buffer (vector 1 2 3 4 5 6 7 8 9)))) (let ((buffer (vector iac iac 1 2 3 4 5 6 7 8 9))) (assert-true (= 5 (remove-iac-iac buffer 2 7))) (assert-true (equalp buffer (vector iac iac 1 2 3 4 5 6 7 8 9))) (assert-true (= 6 (remove-iac-iac buffer 0 7))) (assert-true (equalp buffer (vector iac 1 2 3 4 5 5 6 7 8 9)))) (let ((buffer (vector iac iac 1 2 3 iac iac 6 7 8 9))) (assert-true (= 4 (remove-iac-iac buffer 2 7))) (assert-true (equalp buffer (vector iac iac 1 2 3 iac iac 6 7 8 9))) (assert-true (= 5 (remove-iac-iac buffer 0 7))) (assert-true (equalp buffer (vector iac 1 2 3 iac iac iac 6 7 8 9))))) (define-test test/get-next-chunk () (assert (equal (let ((buffer (vector 61 62 63 64 13 10 65 66 13 0 67 68 69 70 12 9 71 72 73))) (loop :with start = 0 :for res = (multiple-value-list (get-next-chunk buffer start (length buffer))) :collect res :until (member (first res) '(:done :incomplete)) :do (setf start (second res)))) '((:text 8) (:control 10 13) (:text 14) (:control 15 12) (:control 16 9) (:text 19) (:done 19)))) (assert (equal (let ((buffer (vector 61 62 63 64 13 10 65 66 13 0 67 68 69 70 10 9 71 72 73 13))) (loop :with start = 0 :for res = (multiple-value-list (get-next-chunk buffer start (length buffer))) :collect res :until (member (first res) '(:done :incomplete)) :do (setf start (second res)))) '((:text 8) (:control 10 13) (:text 14) (:control 15 10) (:control 16 9) (:incomplete 19)))) (assert (equal (let ((buffer (vector 1 2 3 4))) (loop :with start = 0 :for res = (multiple-value-list (get-next-chunk buffer start (length buffer))) :collect res :until (member (first res) '(:done :incomplete)) :do (setf start (second res)))) '((:control 1 1) (:control 2 2) (:control 3 3) (:control 4 4) (:done 4))))) (define-test test/all () (test/parse-message) (test/remove-iac-iac) (test/get-next-chunk)) ;;;; THE END ;;;;
7,130
Common Lisp
.lisp
136
40.5
108
0.523203
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
e9025b1c78397ffe54e0e762c6f47055823c28b5e0636c640685b45fdb70c7a9
5,009
[ -1 ]
5,010
com.informatimago.common-lisp.scanner.asd
informatimago_lisp/common-lisp/parser/com.informatimago.common-lisp.scanner.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.scanner.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.scanner library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-07-05 <PJB> Extracted from parser.asd. ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.scanner" ;; system attributes: :description "Informatimago Common Lisp Scanner" :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.5.0" :properties ((#:author-email . "[email protected]") (#:date . "Autumn 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.parser/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.regexp") :components ((:file "packages" :depends-on ()) (:file "scanner" :depends-on ("packages")) (:file "generate-scanner" :depends-on ("packages" "scanner"))) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.scanner.test")))) ;;;; THE END ;;;;
2,775
Common Lisp
.lisp
57
44.859649
110
0.585788
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
f172de00cd1c8f20ee16fc58ac457d3d36c5e4ebd244cdcca455e35f1eb0d781
5,010
[ -1 ]
5,011
scanner.lisp
informatimago_lisp/common-lisp/parser/scanner.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: scanner.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; An abstract scanner class. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2016-01-30 <PJB> SCANNER and TOKEN now inherit from SLOTED-OBJECT. ;;;; 2012-02-07 <PJB> Added a TOKEN class. ;;;; 2005-09-01 <PJB> Made use of iso6429. ;;;; 2004-10-10 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2004 - 2022 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COM.INFORMATIMAGO.COMMON-LISP.PARSER.SCANNER") ;;---------------------------------------------------------------------- ;; TOKEN ;;---------------------------------------------------------------------- ;; We provide a token class, but we use duck-typing, so one could use ;; symbols or strings for tokens too (but losing eg. the line:column ;; feature). (defgeneric token-kind (token) (:documentation "Returns the kind of the token.") (:method ((token symbol)) token) (:method ((token string)) token)) (defgeneric token-text (token) (:documentation "Returns the literal text the token.") (:method ((token symbol)) (symbol-name token)) (:method ((token string)) token)) (defgeneric token-line (token) (:documentation "Returns the line where the token was found.") (:method ((token t)) 0)) (defgeneric token-column (token) (:documentation "Returns the column of the first character of the token.") (:method ((token t)) 0)) (defclass token (sloted-object) ((kind :initarg :kind :accessor token-kind :initform nil :type symbol) (text :accessor token-text :initarg :text :initform "" :type (or null string)) (column :accessor token-column :initarg :column :initform 1 :type (integer 0)) ; 0 is unknown. (line :accessor token-line :initarg :line :initform 1 :type (integer 0))) ; 0 is unknown. (:documentation "A syntactic element.")) (defmethod slots-for-print append ((self token)) (extract-slots self '(kind text column line))) (defvar *end-of-source-kind* (make-symbol "end-of-source")) (defun token-end-of-source-kind () *end-of-source-kind*) (defgeneric token-end-of-source-p (token) (:method ((token t)) nil) (:method ((token token)) (eq (token-kind token) *end-of-source-kind*))) ;;---------------------------------------------------------------------- ;; SCANNER ;;---------------------------------------------------------------------- (eval-when (:compile-toplevel :load-toplevel :execute) (defun char-name-supported-p (name) (ignore-errors (read-from-string (format nil "#\\~A" name))))) ;; Note: the features are defined in .cesarum.characters (defvar *spaces* (coerce (remove-duplicates '(#\Space #+has-newline #\Newline #+has-tab #\Tab #+(and has-return (not newline-is-return)) #\return #+(and has-linefeed (not newline-is-linefeed)) #\linefeed #+has-page #\page)) 'string)) ;; Note we copy some fields in the condition from the scanner, so that ;; they can change in the scanner object between the condition ;; creation and its handling. (defgeneric scanner-error-file (error) (:documentation "The file in which the scanner error was detected.")) (defgeneric scanner-error-line (error) (:documentation "The line on which the scanner error was detected.")) (defgeneric scanner-error-column (error) (:documentation "The column on which the scanner error was detected.")) (defgeneric scanner-error-state (error) (:documentation "The scanner state when error was detected.")) (defgeneric scanner-error-current-token (error) (:documentation "The scanner token where error was detected.")) (defgeneric scanner-error-scanner (error) (:documentation "The scanner that detected the error.")) (defgeneric scanner-error-format-control (error) (:documentation "The error message format control string.")) (defgeneric scanner-error-format-arguments (error) (:documentation "The error message format control arguments.")) (defgeneric scanner-error-invalid-character (error) (:documentation "The invalid character that made the scanner error.")) (define-condition scanner-error (simple-error) ((file :initarg :file :initform "<stdin>" :reader scanner-error-file :documentation "The path of the file.") (line :initarg :line :initform 1 :reader scanner-error-line :documentation "The number of the line. First line is line number 1.") (column :initarg :column :initform 1 :reader scanner-error-column :documentation "The number of the column. First column is column number 1.") (state :initarg :state :initform 0 :reader scanner-error-state) (current-token :initarg :current-token :initform nil :reader scanner-error-current-token) (scanner :initarg :scanner :reader scanner-error-scanner) (format-control :initarg :format-control :initform "" :reader scanner-error-format-control) (format-arguments :initarg :format-arguments :initform '() :reader scanner-error-format-arguments)) (:documentation "A scanner error.")) (define-condition scanner-error-invalid-character (scanner-error) ((invalid-character :initarg :invalid-character :initform nil :reader scanner-error-invalid-character)) (:documentation "An invalid character scanner error.")) (defgeneric scanner-source (scanner) (:documentation "The source can be a PEEK-STREAM, a STREAM, or a STRING.")) (defgeneric scanner-file (scanner) (:documentation "The namestring of the current file being scanned.")) (defgeneric scanner-line (scanner) (:documentation "The number of the current line.")) (defgeneric scanner-column (scanner) (:documentation "The number of the current column.")) (defgeneric scanner-state (scanner) (:documentation "The state of the scanner.")) (defgeneric scanner-spaces (scanner) (:documentation "A string containing the characters considered space by SKIP-SPACES.")) (defgeneric scanner-tab-width (scanner) (:documentation "TAB aligns to column number modulo TAB-WIDTH.")) (defgeneric scanner-current-token (scanner) (:documentation "The last token read.")) (defgeneric scanner-current-text (scanner) (:documentation "Text of the current token")) (defclass scanner (sloted-object) ((source :initarg :source :reader scanner-source :documentation "The source can be a PEEK-STREAM, a STREAM, or a STRING.") (stream :type peek-stream :reader scanner-stream :documentation "The source is wrapped into this PEEK-STREAM. Subclasses may use scanner-stream to read from the source.") (file :initarg :file :accessor scanner-file :type string :initform "<stdin>" :documentation "The namestring of the current file.") (line :initarg :line :accessor scanner-line :type integer :initform 0 :documentation "The number of the current line. First line is line number 1.") (column :initarg :column :accessor scanner-column :type integer :initform 1 :documentation "The number of the current column. First column is column number 1.") (state :initarg :state :accessor scanner-state :initform nil :documentation "The state of the scanner.") (spaces :initarg :spaces :accessor scanner-spaces :type sequence :initform *spaces* :documentation "A string containing the characters considered space by SKIP-SPACES.") (tab-width :initarg :tab-width :accessor scanner-tab-width :type fixnum :initform 8 :documentation "TAB aligns to column number modulo TAB-WIDTH.") (current-token :accessor scanner-current-token :initform nil :documentation "The last token read.") (token-kind-package :accessor scanner-token-kind-package :initform (load-time-value (find-package "COM.INFORMATIMAGO.COMMON-LISP.PARSER.SCANNER")) :initarg :token-kind-package :documentation "The package where the token-kind symbols are interned in.")) (:documentation "An abstract scanner.")) (defmethod scanner-current-text ((scanner scanner)) (prin1-to-string (scanner-current-token scanner))) (defgeneric increment-column-to-next-tab-stop (scanner) (:documentation " DO: Increments the scanner-column to the next tab-stop. RETURN: SCANNER ") (:method ((scanner scanner)) (let ((tab-width (scanner-tab-width scanner))) (setf (scanner-column scanner) ;; Assuming column starts from 1. (1+ (* (ceiling (scanner-column scanner) tab-width) tab-width)) ;; #+column-base=0 (* tab-width (ceiling (scanner-column scanner) tab-width)) )) scanner)) (defgeneric skip-spaces (scanner) (:documentation " DO: Skips over the spaces in the input stream. Updates line and column slots. RETURN: line; column ") (:method ((scanner scanner)) (break "skip-spaces ((scanner scanner))") (loop :for ch = (getchar scanner) :while (and ch (find ch (scanner-spaces scanner))) :finally (when ch (ungetchar scanner ch)) (return (values (scanner-line scanner) (scanner-column scanner)))))) #| SKIP-SPACES can also skip comments. There are several kinds of comment syntaxes: - single-line + introduced by a single specific character in any position (even inside of a token), till the end-of-line; => THIS IS NOT SUPPORTED BY SKIP-SPACES + introduced by a single specific character in any position (outside of a token), till the end-of-line; => SINGLE-LINE-START-TOKEN + introduced by a single character (specific or not) in a specific position, till the end-of-line; => SINGLE-LINE-START-COLUMN + introduced by a multi-character token in any position, till the end-of-line; => SINGLE-LINE-START-TOKEN - multi-line + introduced by a single or multi-character token in any position (outside of a token), till another single or multi-character token. => MULTI-LINE-COMMENT (START-TOKEN, STOP-TOKEN, RECURSIVEP = NIL) - recursive-multi-line + introduced by a single or multi-character token in any position (outside of a token), till another single or multi-character token, with recursive parsing for embedded comments (possibly of the same or another syntax). => MULTI-LINE-COMMENT (START-TOKEN, STOP-TOKEN, RECURSIVEP = T) |# (defclass comment-scanner-mixin () ((comment-syntaxes :initarg :comment-syntaxes :initform '() :type 'list :reader comment-syntaxes))) (defgeneric comment-starting-p (scanner syntax ch)) (defgeneric scan-comment (scanner syntax)) (defmethod skip-spaces ((scanner comment-scanner-mixin)) ;; (break "skip-spaces ((scanner comment-scanner-mixin))") (loop :for ch = (getchar scanner) :do (format t "getchar -> ~S~%" ch) (format t "spacep -> ~S~%" (find ch (scanner-spaces scanner))) (when ch (format t "syntax starting comment -> ~S~%" (some (lambda (syntax) (comment-starting-p scanner syntax ch)) (comment-syntaxes scanner)))) :while (and ch (or (find ch (scanner-spaces scanner)) (some (lambda (syntax) (when (comment-starting-p scanner syntax ch) (ungetchar scanner ch) (scan-comment scanner syntax) t)) (comment-syntaxes scanner)))) :finally (when ch (format t "ungetchar -> ~S~%" ch) (ungetchar scanner ch)) (format t "skipped ~A ~A~2%" (scanner-line scanner) (scanner-column scanner)) (return (values (scanner-line scanner) (scanner-column scanner))))) (defclass single-line-comment () ((start-token :initarg :start-token :reader comment-start-token))) (defmethod comment-starting-p (scanner (syntax single-line-comment) ch) ;; For now, we'll only support 1- or 2- character tokens. (let ((start (comment-start-token syntax))) (check-type start (or (string 1) (string 2)) "Supported comment start tokens must be strings of 1 or 2 characters.") (if (char= (char start 0) ch) (if (< 1 (length start)) (char= (char start 1) (nextchar scanner)) t) nil))) (defmethod scan-comment (scanner (syntax single-line-comment)) (loop :for ch := (getchar scanner) :until (char= ch #\Newline))) (defclass from-column-comment (single-line-scan) ((start-column :initarg :start-column :reader comment-start-column))) (defmethod comment-starting-p (scanner (syntax from-column-comment) ch) ;; For now, we'll only support 1-character tokens in the specific column. (let ((start (comment-start-token syntax)) (column (comment-start-column syntax))) (check-type start (or (string 1) null) "Supported comment start tokens must be strings of 1 character, or NIL.") (and (= (scanner-column scanner) column) (if (null start) (not (find ch (scanner-spaces scanner))) (char= (char start 0) ch))))) (defclass multi-line-comment (single-line-comment) ((stop-token :initarg :stop-token :reader comment-stop-token))) (defmethod comment-stop-p (scanner (syntax multi-line-comment) ch) ;; For now, we'll only support 1- or 2- character tokens. (let ((stop (comment-stop-token syntax))) (check-type stop (or (string 1) (string 2)) "Supported comment stop tokens must be strings of 1 or 2 characters.") (if (char= (char stop 0) ch) (if (< 1 (length stop)) (char= (char stop 1) (nextchar scanner)) t) nil))) (defmethod scan-comment (scanner (syntax multi-line-comment)) (loop :for ch := (getchar scanner) :until (comment-stop-p scanner syntax ch) :finally (when (< 1 (length (comment-stop-token syntax))) (getchar scanner)))) (defclass recursive-line-comment (multi-line-comment) ((stop-token :initarg :stop-token :reader comment-stop-token))) (defmethod scan-comment (scanner (syntax recursive-line-comment)) (loop :for ch := (getchar scanner) :until (comment-stop-p scanner syntax ch) :do (let ((subcomment (find-if (lambda (syntax) (comment-starting-p scanner syntax ch)) (comment-syntaxes scanner)))) (when subcomment (ungetchar scanner ch) (scan-comment scanner subcomment))) :finally (when (< 1 (length (comment-stop-token syntax))) (getchar scanner)))) (defgeneric scan-next-token (scanner &optional parser-data) (:documentation " DO: Scans a new token and store it into (scanner-current-token scanner) PARSER-DATA: Some parsers give information to the scanner. RETURN: (scanner-current-token scanner). ")) (defgeneric (setf scanner-source) (new-source scanner)) (defmethod (setf scanner-source) (new-source (scanner scanner)) (setf (slot-value scanner 'stream) (etypecase (setf (slot-value scanner 'source) new-source) (peek-stream (slot-value scanner 'source)) (stream (make-instance 'peek-stream :spaces (scanner-spaces scanner) :stream (slot-value scanner 'source))) (string (make-instance 'peek-stream :spaces (scanner-spaces scanner) :stream (make-string-input-stream (slot-value scanner 'source)))))) (slot-value scanner 'source)) (defmethod initialize-instance :after ((scanner scanner) &rest args &key &allow-other-keys) (declare (ignore args)) (setf (scanner-source scanner) (slot-value scanner 'source))) (defmethod slots-for-print append ((self scanner)) (extract-slots self '(line column current-token source))) ;;; We implement the generic functions of peek-stream to track columns ;;; and lines. (defmethod nextchar ((scanner scanner) &optional (peek-type nil)) ;; No impact on line/column. (nextchar (scanner-stream scanner) peek-type)) (defmethod getchar ((scanner scanner)) (let ((ch (getchar (scanner-stream scanner)))) (case ch ((#\Newline) (incf (scanner-line scanner)) (setf (scanner-column scanner) 1)) #+has-tab ((#\Tab) (increment-column-to-next-tab-stop scanner)) (otherwise ;; including #\Return #+has-linefeed #\Linefeed #+has-page #\Page (incf (scanner-column scanner)))) ch)) (defmethod ungetchar ((scanner scanner) (ch null)) ch) (defmethod ungetchar ((scanner scanner) (ch character)) (let ((ch (ungetchar (scanner-stream scanner) ch))) (case ch ((#\Newline) ;; We don't know the length of the last line. (decf (scanner-line scanner)) (setf (scanner-column scanner) 0)) #+has-tab ((#\Tab) ;; We don't know how many characters there was in the last tab-width. (setf (scanner-column scanner) (truncate (1- (scanner-column scanner)) (scanner-tab-width scanner)))) (otherwise ;; including #\Return #+has-linefeed #\Linefeed #+has-page #\Page (decf (scanner-column scanner)))) ch)) (defmethod readline ((scanner scanner)) #-(and) (with-output-to-string (out) (loop :for ch = (getchar scanner) :until (find ch #(#\Newline #\Return #+has-linefeed #\Linefeed #+has-page #\Page)) :do (write-char ch out))) (prog1 (readline (scanner-stream scanner)) (incf (scanner-line scanner)) (setf (scanner-column scanner) 1))) (defgeneric make-current-token (scanner) (:documentation "Makes an instance of the TOKEN class or a subclass thereof, filled with the current information in the scanner object.") (:method ((scanner scanner)) (let ((current (scanner-current-token scanner))) (if (typep current 'token) current (make-instance 'token :line (scanner-line scanner) :column (scanner-column scanner) :text (scanner-current-text scanner) :kind (etypecase current (string (intern current (scanner-token-kind-package scanner))) (symbol current))))))) ;;;; THE END ;;;;
21,304
Common Lisp
.lisp
432
40.905093
120
0.598451
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
8ae388501e826fa01e545fcc24ccdb9bc0a5ca876cb77f3c283f47465921692c
5,011
[ -1 ]
5,012
scanner-test.lisp
informatimago_lisp/common-lisp/parser/scanner-test.lisp
(eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.PARSER.SCANNER.TESTS" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.PARSER.SCANNER" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.SIMPLE-TEST" "COM.INFORMATIMAGO.COMMON-LISP.REGEXP.REGEXP") (:export "TEST-ALL")) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.PARSER.SCANNER.TESTS.TOKENS" (:use)) (in-package "COM.INFORMATIMAGO.COMMON-LISP.PARSER.SCANNER.TESTS") (defclass test-scanner (comment-scanner-mixin buffered-scanner) () (:default-initargs :spaces (coerce #(#\space #\newline #\tab ) 'string) :token-kind-package (load-time-value (find-package "COM.INFORMATIMAGO.COMMON-LISP.PARSER.SCANNER.TESTS.TOKENS")) :token-symbol-package (load-time-value (find-package "COM.INFORMATIMAGO.COMMON-LISP.PARSER.SCANNER.TESTS.TOKENS")))) (defmethod scan-next-token ((scanner test-scanner) &optional parser-data) "RETURN: (scanner-current-token scanner)" (declare (ignore parser-data)) (let (match) (setf match (string-match (format nil "^([~A]+)" (coerce (scanner-spaces scanner) 'string)) (scanner-buffer scanner) :start (1- (scanner-column scanner)))) (when match (setf (scanner-column scanner) (1+ (match-end 1 match)))) (let ((pos (1- (scanner-column scanner)))) (cond ((scanner-end-of-source-p scanner) (setf (scanner-column scanner) (1+ (length (scanner-buffer scanner))) (scanner-current-text scanner) "<END OF SOURCE>" (scanner-current-token scanner) (token-end-of-source-kind))) ((scanner-end-of-line-p scanner) (advance-line scanner)) ((setf match (string-match '"^([0-9][0-9]*)" (scanner-buffer scanner) :start pos)) (setf (scanner-column scanner) (1+ (match-end 1 match)) (scanner-current-text scanner) (match-string 1 (scanner-buffer scanner) match) (scanner-current-token scanner) 'integer)) ((setf match (string-match '"^([A-Za-z][-A-Za-z0-9]*)" (scanner-buffer scanner) :start pos)) (setf (scanner-column scanner) (1+ (match-end 1 match)) (scanner-current-text scanner) (match-string 1 (scanner-buffer scanner) match) (scanner-current-token scanner) 'identifier)) (t (error 'scanner-error-invalid-character :file (scanner-file scanner) :line (scanner-line scanner) :column (scanner-column scanner) :state (scanner-state scanner) :current-token (scanner-current-token scanner) :scanner scanner :invalid-character (aref (scanner-buffer scanner) pos) :format-control "Invalid character ~S at position: ~D~%" :format-arguments (list (aref (scanner-buffer scanner) pos) (scanner-column scanner))))))) (setf (scanner-current-token scanner) (make-current-token scanner))) (defun make-test-scanner (source) (make-instance 'test-scanner :source source)) (defun scan-all-tokens (scanner) (loop :for token := (progn (skip-spaces scanner) (scan-next-token scanner)) :until (token-end-of-source-p token) :collect (ecase (token-kind token) ((identifier) (intern (string-upcase (token-text token)) (load-time-value *package*))) ((integer) (parse-integer (token-text token)))))) (define-test raw-scan () (let ((scanner (make-test-scanner " begin hello world 421 end "))) (format t "Scanning text: ~S~%" (scanner-source scanner)) (check equal (scan-all-tokens scanner) '(begin hello world 421 end)))) (define-test test-getchar () (let* ((input " begin ; comment hello world ;; anotheer comment ;;; comment 421;comment end;comment ") (scanner (make-test-scanner input))) (format t "Scanning text: ~S~%" (scanner-source scanner)) (setf (slot-value scanner 'comment-syntaxes) (list (make-instance 'single-line-comment :start-token ";"))) (check equal (with-output-to-string (*standard-output*) (loop :for ch := (getchar scanner) :while ch :do (princ ch))) input))) (define-test test-skip-spaces () (let* ((input " begin ; comment hello world ;; anotheer comment ;;; comment 421;comment end;comment ") (expected-output '("begin" "hello" "world" "421" "end")) (scanner (make-test-scanner input))) (format t "Scanning text: ~S~%" (scanner-source scanner)) (setf (slot-value scanner 'comment-syntaxes) (list (make-instance 'single-line-comment :start-token ";"))) (check equal (print (loop :until (scanner-end-of-source-p scanner) :do (print (multiple-value-list (skip-spaces scanner))) :collect (with-output-to-string (output) (loop :for ch := (getchar scanner) :while (and ch (not (or (find ch (scanner-spaces scanner)) (some (lambda (syntax) (when (comment-starting-p scanner syntax ch) (ungetchar scanner ch) (scan-comment scanner syntax) t)) (comment-syntaxes scanner))))) :do (princ ch output) :finally (when ch (ungetchar scanner ch)))))) expected-output))) (define-test test-semi-colon-comment () (let ((scanner (make-test-scanner " begin ; comment hello world ;; anotheer comment ;;; comment 421;comment end;comment "))) (format t "Scanning text: ~S~%" (scanner-source scanner)) (setf (slot-value scanner 'comment-syntaxes) (list (make-instance 'single-line-comment :start-token ";"))) (check equal (scan-all-tokens scanner) '(begin hello world 421 end)))) (define-test test-all () (raw-scan) (test-getchar) (test-skip-spaces) (test-semi-colon-comment)) #| (make-instance 'single-line-comment :start-token ";") from-column-comment multi-line-comment recursive-line-comment (define-test test-all () (test-comment-)) |#
6,905
Common Lisp
.lisp
151
34.039735
119
0.56854
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
4e5c622a8cd6b693512ecc37149a75112d4685c9d8fc36b5dc375d2a37225959
5,012
[ -1 ]
5,013
parser.lisp
informatimago_lisp/common-lisp/parser/parser.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: parser.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; An abstract parser class. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2004-10-10 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2004 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COM.INFORMATIMAGO.COMMON-LISP.PARSER.PARSER") (defgeneric parser-scanner (parser) (:documentation "The scanner of the parser.")) (defgeneric parser-token (parser) (:documentation "The current token of the parser.")) (defgeneric parser-next-token (parser) (:documentation "The next-token of the parser.")) (defclass parser () ((scanner :accessor parser-scanner :initform nil :initarg :scanner) (token :accessor parser-token :initform nil :documentation "current token") (next-token :accessor parser-next-token :initform nil :documentation "next token")) (:documentation "A parser.")) (defmethod print-object ((self parser) out) (print-unreadable-object (self out :type t :identity t) (format out " :scanner ~S :token (~S ~S) :next (~S ~S)" (parser-scanner self) (parser-token self) (token-text (parser-token self)) (parser-next-token self) (token-text (parser-next-token self)))) self) (defgeneric parser-error-parser (error) (:documentation "The parser that signaled the error.")) (defgeneric parser-error-token (error) (:documentation "The token where the error was detected.")) (defgeneric parser-error-next-token (error) (:documentation "The next-token where the error was detected.")) (defgeneric parser-error-format-control (error) (:documentation "The error message format control string.")) (defgeneric parser-error-format-arguments (error) (:documentation "The error message format control arguments.")) (define-condition parser-error (error) ((parser :initarg :parser :reader parser-error-parser) (token :initarg :token :reader parser-error-token) (next-token :initarg :next-token :reader parser-error-next-token) (format-control :initarg :format-control :reader parser-error-format-control) (format-arguments :initarg :format-arguments :reader parser-error-format-arguments)) (:documentation "A parser error.") (:report (lambda (condition stream) (format stream "~?; (~S ~S) (~S ~S)" (parser-error-format-control condition) (parser-error-format-arguments condition) (parser-error-token condition) (token-text (parser-error-token condition)) (parser-error-next-token condition) (token-text (parser-error-next-token condition)))))) (defgeneric advance (parser) (:documentation "Shitf next-token into token and scan the next token.")) (defgeneric report-error (parser message &rest arguments) (:documentation "Signal a parser-error.")) (defmethod advance ((parser parser)) (multiple-value-bind (tok val) (scan-next-token (parser-scanner parser)) (declare (ignore val)) (setf (parser-token parser) (parser-next-token parser) (parser-next-token parser) tok)) parser) (defmethod report-error ((parser parser) message &rest arguments) (error 'parser-error :parser parser :token (parser-token parser) :next-token (parser-next-token parser) :format-control message :format-arguments arguments)) ;;;; THE END ;;;;
4,691
Common Lisp
.lisp
99
42.818182
87
0.645747
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
a015882646a111ca5143172bf2d6eb4b604e827f4d4941d1e3c89a6de4549858
5,013
[ -1 ]
5,014
com.informatimago.common-lisp.parser.test.asd
informatimago_lisp/common-lisp/parser/com.informatimago.common-lisp.parser.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.parser.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.parser.test system. ;;;; Tests the com.informatimago.common-lisp.parser system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.parser.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.parser system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.parser.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.parser") :components () #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) ;; (let ((*package* (find-package "TESTED-PACKAGE"))) ;; (uiop:symbol-call "TESTED-PACKAGE" ;; "TEST/ALL")) )) ;;;; THE END ;;;;
2,969
Common Lisp
.lisp
67
38.134328
86
0.548966
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
2f342113a0330bbc8a9ad8408f28566d2b19d8432e2b6c92648fd5ced5ef5b81
5,014
[ -1 ]
5,015
com.informatimago.common-lisp.scanner.test.asd
informatimago_lisp/common-lisp/parser/com.informatimago.common-lisp.scanner.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.scanner.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.scanner.test system. ;;;; Tests the com.informatimago.common-lisp.scanner system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-07-05 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.scanner.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.scanner system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Summer 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.parser.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.scanner") :components () #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) ;; (let ((*package* (find-package "TESTED-PACKAGE"))) ;; (uiop:symbol-call "TESTED-PACKAGE" ;; "TEST/ALL")) )) ;;;; THE END ;;;;
2,974
Common Lisp
.lisp
67
38.208955
86
0.550086
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
9edc5af44376e884796eecb043e977e93438a47c3985be2da23b0351d8980f6c
5,015
[ -1 ]
5,016
com.informatimago.common-lisp.parser.asd
informatimago_lisp/common-lisp/parser/com.informatimago.common-lisp.parser.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.parser.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.parser library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.parser" ;; system attributes: :description "Informatimago Common Lisp Scanner and Parser Abstract Classes" :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.4.0" :properties ((#:author-email . "[email protected]") (#:date . "Summer 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.parser/") ((#:albert #:formats) . ("docbook")) ((#:albert #:docbook #:template) . "book") ((#:albert #:docbook #:bgcolor) . "white") ((#:albert #:docbook #:textcolor) . "black")) :depends-on ("com.informatimago.common-lisp.cesarum" "com.informatimago.common-lisp.regexp") :components ((:file "packages" :depends-on ()) (:file "scanner" :depends-on ("packages")) (:file "generate-scanner" :depends-on ("packages" "scanner")) (:file "parser" :depends-on ("packages" "scanner"))) #+asdf-unicode :encoding #+asdf-unicode :utf-8 #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.parser.test")))) ;;;; THE END ;;;;
2,824
Common Lisp
.lisp
57
45.45614
110
0.583002
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
651c81f14360eb2c617cdd78033073850780b5e7979a1b7e884873752cefd02e
5,016
[ -1 ]
5,017
packages.lisp
informatimago_lisp/common-lisp/parser/packages.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: packages.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Defines the packages for the abstract scanner and parsers. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2015-07-02 <PJB> Extracted. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2004 - 2016 ;;;; ;;;; 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/>. ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COMMON-LISP-USER") (declaim (declaration also-use-packages)) (declaim (also-use-packages "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.ECMA048")) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.PARSER.SCANNER" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.UTILITY" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.PEEK-STREAM" "COM.INFORMATIMAGO.COMMON-LISP.REGEXP.REGEXP") (:export "DEFINE-SCANNER" ;; TOKEN: "TOKEN" "TOKEN-KIND" "TOKEN-TEXT" "TOKEN-LINE" "TOKEN-COLUMN" "TOKEN-END-OF-SOURCE-P" "TOKEN-END-OF-SOURCE-KIND" "KIND" "TEXT" "LINE" "COLUMN" "WORD-EQUAL" "*SPACE*" ;; SCANNER: "SCANNER" "SCANNER-SOURCE" "SCANNER-FILE" "SCANNER-LINE" "SCANNER-COLUMN" "SCANNER-STATE" "SCANNER-SPACES" "SCANNER-TAB-WIDTH" "SCANNER-TOKEN-KIND-PACKAGE" "SCANNER-CURRENT-TOKEN" ;; SCANNER-ERROR condition: "SCANNER-ERROR" "SCANNER-ERROR-LINE" "SCANNER-ERROR-COLUMN" "SCANNER-ERROR-STATE" "SCANNER-ERROR-CURRENT-TOKEN" "SCANNER-ERROR-SCANNER" "SCANNER-ERROR-FORMAT-CONTROL" "SCANNER-ERROR-FORMAT-ARGUMENTS" "SCANNER-ERROR-INVALID-CHARACTER" ;; SCANNER methods: "SKIP-SPACES" "SCAN-NEXT-TOKEN" "MAKE-CURRENT-TOKEN" ;; PEEK-STREAM methods specialized on SCANNER: "NEXTCHAR" "UNGETCHAR" "GETCHAR" ;; BUFFERED-SCANNER methods: "BUFFERED-SCANNER" "SCANNER-BUFFER" "SCANNER-CURRENT-TEXT" "GENERATE-SCANNER" "ADVANCE-LINE" "READLINE" "SCANNER-END-OF-SOURCE-P" "SCANNER-END-OF-LINE-P" "ACCEPT" "PRINT-SCANNER-ERROR" "PRINT-PARSER-ERROR" ;; COMMENT-SCANNER-MIXIN "COMMENT-SCANNER-MIXIN" "COMMENT-SYNTAXES" "SINGLE-LINE-COMMENT" "FROM-COLUMN-COMMENT" "MULTI-LINE-COMMENT" "RECURSIVE-LINE-COMMENT" "COMMENT-START-TOKEN" "COMMENT-START-COLUMN" "COMMENT-STOP-TOKEN" "COMMENT-STARTING-P" "COMMENT-STOP-P" "SCAN-COMMENT") (:documentation " An abstract scanner class. A method to the SCAN-NEXT-TOKEN generic function needs to be provided. License: AGPL3 Copyright Pascal J. Bourguignon 2004 - 2022 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.COMMON-LISP.PARSER.PARSER" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.UTILITY" "COM.INFORMATIMAGO.COMMON-LISP.PARSER.SCANNER") (:export "PARSER" "PARSER-SCANNER" "PARSER-NEXT-TOKEN" "PARSER-TOKEN" "ADVANCE" "REPORT-ERROR" "PARSER-ERROR" "PARSER-ERROR-PARSER" "PARSER-ERROR-TOKEN" "PARSER-ERROR-NEXT-TOKEN" "PARSER-ERROR-FORMAT-CONTROL" "PARSER-ERROR-FORMAT-ARGUMENTS") (:documentation " An abstract parser class. License: AGPL3 Copyright Pascal J. Bourguignon 2004 - 2015 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/> ")) ;;;; THE END ;;;;
5,523
Common Lisp
.lisp
133
37.669173
83
0.688769
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
99ca5ce7407668ace6a40d82880f1abcf82cc21e1c6e835ea90c756201fe5f63
5,017
[ -1 ]
5,018
com.informatimago.common-lisp.lisp-text.test.asd
informatimago_lisp/common-lisp/lisp-text/com.informatimago.common-lisp.lisp-text.test.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: com.informatimago.common-lisp.lisp-text.test.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: None ;;;;USER-INTERFACE: None ;;;;DESCRIPTION: ;;;; ;;;; This file defines the com.informatimago.common-lisp.lisp-text.test system. ;;;; Tests the com.informatimago.common-lisp.lisp-text system. ;;;; ;;;;USAGE: ;;;; ;;;;AUTHORS: ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS: ;;;; 2015-02-23 <PJB> Created. ;;;;BUGS: ;;;; ;;;;LEGAL: ;;;; ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2015 - 2016 ;;;; ;;;; 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.common-lisp.lisp-text.test" ;; system attributes: :description "Tests the com.informatimago.common-lisp.lisp-text system." :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.2.0" :properties ((#:author-email . "[email protected]") (#:date . "Winter 2015") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.lisp-text.test/") ((#: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.common-lisp.cesarum" "com.informatimago.common-lisp.lisp-text") :components () #+asdf3 :perform #+asdf3 (asdf:test-op (operation system) (declare (ignore operation system)) ;; (let ((*package* (find-package "TESTED-PACKAGE"))) ;; (uiop:symbol-call "TESTED-PACKAGE" ;; "TEST/ALL")) )) ;;;; THE END ;;;;
2,990
Common Lisp
.lisp
67
38.447761
89
0.549812
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
69e2183e096b269ae905f5476309d97622c1e3d89f4fd72b12ea57259ddd7808
5,018
[ -1 ]
5,019
com.informatimago.common-lisp.lisp-text.asd
informatimago_lisp/common-lisp/lisp-text/com.informatimago.common-lisp.lisp-text.asd
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: com.informatimago.common-lisp.lisp-text.asd ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; ASD file to load the com.informatimago.common-lisp.lisp-text library. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2010-10-31 <PJB> Created this .asd file. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2016 ;;;; ;;;; 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.common-lisp.lisp-text" ;; system attributes: :description "Informatimago Common Lisp Text Source Utilities" :author "Pascal J. Bourguignon <[email protected]>" :maintainer "Pascal J. Bourguignon <[email protected]>" :licence "AGPL3" ;; component attributes: :version "1.4.0" :properties ((#:author-email . "[email protected]") (#:date . "Autumn 2010") ((#:albert #:output-dir) . "/tmp/documentation/com.informatimago.common-lisp.lisp-text/") ((#: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.common-lisp.lisp-reader") :components ((:file "source-text" :depends-on ())) #+adsf3 :in-order-to #+adsf3 ((asdf:test-op (asdf:test-op "com.informatimago.common-lisp.lisp-text.test")))) ;;;; THE END ;;;;
2,549
Common Lisp
.lisp
53
44.90566
113
0.592622
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
cb53a49c93147a156decba6593a973b829602fc80cf80b7748b40dcc07d4ddd2
5,019
[ -1 ]
5,020
source-text.lisp
informatimago_lisp/common-lisp/lisp-text/source-text.lisp
;;;;************************************************************************** ;;;;FILE: source-text.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; This package exports functions to read and manipulate ;;;; Common Lisp sources. Most of the text source properties ;;;; are kept (file position, line number, comments, feature ;;;; tests, etc), while no package is created and no symbol is ;;;; interned (TODO: but perhaps keywords?) ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2007-03-07 <PJB> Created. ;;;;BUGS ;;;; ;;;; Check the implementation of these features: ;;;; - write classes for source objects (symbols, packages, feature tests, etc). ;;;; - write reader macros. ;;;; - write (port from pjb-emacs.el) the "source" walker WALK-FORMS (walk-sexp), etc. ;;;; ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2007 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.LISP-TEXT.SOURCE-TEXT" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.LISP-READER.READER") (:shadowing-import-from "COM.INFORMATIMAGO.COMMON-LISP.LISP-READER.READER" "READTABLE" "COPY-READTABLE" "MAKE-DISPATCH-MACRO-CHARACTER" "READ" "READ-PRESERVING-WHITESPACE" "READ-DELIMITED-LIST" "READ-FROM-STRING" "READTABLE-CASE" "READTABLEP" "SET-DISPATCH-MACRO-CHARACTER" "GET-DISPATCH-MACRO-CHARACTER" "SET-MACRO-CHARACTER" "GET-MACRO-CHARACTER" "SET-SYNTAX-FROM-CHAR" "WITH-STANDARD-IO-SYNTAX" "*READ-BASE*" "*READ-DEFAULT-FLOAT-FORMAT*" "*READ-EVAL*" "*READ-SUPPRESS*" "*READTABLE*") (:export "BUILD-LINE-INDEX" "GET-LINE-AND-COLUMN" ;; ---- ;; "*SOURCE-READTABLE*" "*SOURCE-SIGNAL-ERRORS*" "SOURCE-READ" "SOURCE-OBJECT" "SOURCE-OBJECT-FILE" "SOURCE-OBJECT-POSITION" "SOURCE-OBJECT-TEXT" "SOURCE-OBJECT-SUBFORM" "SOURCE-TOKEN" "SOURCE-TOKEN-TEXT" "SOURCE-TOKEN-TRAITS" "SOURCE-LEXICAL-ERROR" "SOURCE-LEXICAL-ERROR-ERROR" "MACRO-CHARACTER-MIXIN" "MACRO-CHARACTER" "DISPATCH-MACRO-CHARACTER-MIXIN" "DISPATCH-MACRO-ARGUMENT" "DISPATCH-MACRO-SUB-CHARACTER" "COMMENT" "COMMENT-TEXT" "SOURCE-SEMICOLON-COMMENT" "SOURCE-STRING" "SOURCE-STRING-VALUE" "SOURCE-SUBFORM" "SOURCE-QUOTE" "SOURCE-BACKQUOTE" "SOURCE-UNQUOTE" "SOURCE-SPLICE" "SOURCE-SEQUENCE" "SOURCE-SEQUENCE-ELEMENTS" "SOURCE-LIST" "SOURCE-LABEL-REFERENCE" "SOURCE-LABEL-REFERENCE-LABEL" "SOURCE-LABEL-DEFINITION" "SOURCE-LABEL-DEFINITION-LABEL" "SOURCE-LABEL-DEFINITION-FORM" "SOURCE-FEATURE" "SOURCE-NOT-FEATURE" "SOURCE-READ-EVAL" "SOURCE-TOKEN" "SOURCE-SHARP-PIPE-COMMENT" "SOURCE-FUNCTION" "SOURCE-VECTOR" "SOURCE-BIT-VECTOR" "SOURCE-CHARACTER" "SOURCE-CHARACTER" "SOURCE-ARRAY" "SOURCE-NUMBER" "SOURCE-NUMBER-VALUE" "SOURCE-BASE-NUMBER" "SOURCE-BASE-NUMBER-BASE" "SOURCE-BASE-NUMBER-SPECIFIC" "SOURCE-COMPLEX" "SOURCE-PATHNAME" "SOURCE-STRUCTURE" ;; ---- ;; "SOURCE-ATOM-P" "MAP-SOURCE-STREAM" "MAP-SOURCE-FILE" ) (:documentation " This package exports functions to read and manipulate Common Lisp sources. Most of the text source properties are kept (file position, line number, comments, feature tests, etc), while no package is created and no symbol is interned. Copyright Pascal J. Bourguignon 2007 - 2007 This package is provided under the GNU General Public License. See the source file for details.")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.LISP-TEXT.SOURCE-TEXT") ;;; ---------------------------------------- ;;; (defun build-line-index (file-path &key (external-format :default)) " DO: Build an index of the line positions in the file. FILE-PATH: The pathname of a text file. EXTERNAL-FORMAT: Passed to OPEN. Default: :default. RETURN: A vector of file positions of the beginning of each line. " (with-open-file (input file-path :external-format external-format) (let ((line-positions (make-array 0 :adjustable t :fill-pointer 0 :element-type '(integer 0)))) (loop :for pos = (file-position input) :do (vector-push-extend pos line-positions) :while (peek-char #\newline input nil nil) :do (read-char input) :finally (return line-positions))))) ;;; Copied from utility.lisp to avoid package loops (defun dichotomy-search (vector value compare &key (start 0) (end (length vector)) (key (function identity))) " PRE: entry is the element to be searched in the table. (<= start end) RETURN: (values found index order) POST: (<= start index end) +-------------------+----------+-------+----------+----------------+ | Case | found | index | order | Error | +-------------------+----------+-------+----------+----------------+ | x < a[min] | FALSE | min | less | 0 | | a[i] = x | TRUE | i | equal | 0 | | a[i] < x < a[i+1] | FALSE | i | greater | 0 | | a[max] < x | FALSE | max | greater | 0 | +-------------------+----------+-------+----------+----------------+ " (let* ((curmin start) (curmax end) (index (truncate (+ curmin curmax) 2)) (order (funcall compare value (funcall key (aref vector index)))) ) (loop :while (and (/= 0 order) (/= curmin index)) :do (if (< order 0) (setf curmax index) (setf curmin index)) (setf index (truncate (+ curmin curmax) 2)) (setf order (funcall compare value (funcall key (aref vector index))))) (when (and (< start index) (< order 0)) (setf order 1) (decf index)) (assert (or (< (funcall compare value (funcall key (aref vector index))) 0) (and (> (funcall compare value (funcall key (aref vector index))) 0) (or (>= (1+ index) end) (< (funcall compare value (funcall key (aref vector (1+ index)))) 0))) (= (funcall compare value (funcall key (aref vector index))) 0))) (values (= order 0) index order))) (defun get-line-and-column (line-positions pos) (multiple-value-bind (foundp index order) (dichotomy-search line-positions pos (lambda (a b) (cond ((< a b) -1) ((> a b) 1) (t 0)))) (declare (ignore foundp order)) ;; The case x < a[min] cannot occur since (= 0 (aref line-positions 0)) ;; and (<= 0 pos) (values index (- pos (aref line-positions index))))) ;;; ---------------------------------------- ;;; (defvar *stream* nil "The source stream.") (defvar *file* nil "The pathname of the source file.") (defvar *start* nil "The start file position of the current reader dispatch macro character.") (defvar *macro-character* nil "The current dispatch macro character.") ;;; ---------------------------------------- ;;; ;;; ---------------------------------------- ;;; (defclass source-object () ((file :accessor source-object-file :initarg :file :initform nil :type (or null string pathname)) (position :accessor source-object-position :initarg :position :initform nil :type (or null integer) :documentation "This are file-positions. We don't keep track of line/column, since this can be done by reading the source file again, as a character file instead of a sexp file..") (text :accessor source-object-text :initarg :text :initform nil :type (or null string)))) (defmethod print-object ((self source-object) stream) (if *print-readably* (format stream "~A" (source-object-text self)) (print-unreadable-object (self stream :type t :identity t))) self) ;;; ---------------------------------------- ;;; (defun read-string-between-file-positions (stream start end) " PRE: (eq 'character (stream-element-type stream)) and START and END are file positions of this STREAM. RETURN: A string containing the characters read between the START and END file positions in the STREAM. POST: (= end (file-position stream)) " (let ((buffer (make-array (- end start) :element-type 'character :fill-pointer 0))) (file-position stream start) (loop :while (< (file-position stream) end) :do (vector-push (read-char stream) buffer) ;; We could use copy-seq to return a simple-string, ;; but it's not worth it. :finally (unless (= (file-position stream) end) (warn "While reading beetween file positions, ~ reached a different file position: ~A < ~A" end (file-position stream))) (return buffer)))) (defvar *source-signal-errors* nil " NIL ==> return source-lexical-error objects T ==> signal the errors. ") (defun read-source-object (stream start class make-arguments) " DO: Read a source-object instance, of class CLASS, and re-read the STREAM from START to the file position after reading the source-object instance, as SOURCE-OBJECT-TEXT. START: The file position in STREAM of the first character of the source object. The current file position may be beyond this START position, when we're called from a reader macro (1) or a reader dispatch macro (2+). MAKE-ARGUMENTS: A function returning a plist of keyword and values to be passed as argument to (make-instance class ...) This function should be doing the reading of the source-object. RETURN: A new source-object instance of class CLASS, or an instance of SOURCE-LEXICAL-ERROR in case of error (READER-ERROR). " (let* ((inst (handler-case (apply (function make-instance) class :file (ignore-errors (pathname stream)) :position start (funcall make-arguments)) (end-of-file (err) (error err)) (error (err) (if *source-signal-errors* (error err) (make-instance 'source-lexical-error :file (ignore-errors (pathname stream)) :position start :error err)))))) (setf (source-object-text inst) (read-string-between-file-positions stream start (file-position stream))) inst)) (defmacro building-source-object (stream start class &rest args &key &allow-other-keys) " USAGE: (building-source-object stream *start* 'source-object-class :attribute (source-read stream t nil t) :other-attribute (read-line stream t nil t) #| ... |#) RETURN: the source-object-class instance build. DO: Keep track of the file position to seek back and read again the source, for the text attribute of the instance. " `(read-source-object ,stream ,start ,class (lambda () (list ,@args)))) ;;; ---------------------------------------- ;;; (defclass source-token (source-object) ((token :accessor source-token-text :initarg :token) (traits :accessor source-token-traits :initarg :traits))) (defun source-parse-token (token) " DO: Parse the lisp reader token and return a source token object. RETURN: okp ; the parsed lisp object if okp, or an error message if (not okp) " (values t (building-source-object *stream* *start* 'source-token :token (com.informatimago.common-lisp.lisp-reader.reader::token-text token) :traits (com.informatimago.common-lisp.lisp-reader.reader::token-traits token)))) ;;; ---------------------------------------- ;;; (defclass source-lexical-error (source-object) ((error :accessor source-lexical-error-error :initarg :error :initform nil :type (or null condition)))) (defmethod print-object ((self source-lexical-error) stream) (if *print-readably* (call-next-method) (print-unreadable-object (self stream :type t :identity t) (format stream "in file ~S at position ~S: ~A" (source-object-file self) (source-object-position self) (source-lexical-error-error self)))) self) ;;; ---------------------------------------- ;;; (defmacro building-reader-macro-source-object (stream macro-character class &rest args &key &allow-other-keys) " DO: Calls BUILDING-SOURCE-OBJECT, keeping track of the file position of the MACRO-CHARACTER. MACRO-CHARACTER: The macro character that has been read (as passed to the reader macro). " `(building-source-object ,stream *start* ,class :macro-character ,macro-character ,@args)) ;;; ---------------------------------------- ;;; (defclass macro-character-mixin () ((macro-character :accessor macro-character :initarg :macro-character))) (defclass dispatch-macro-character-mixin (macro-character-mixin) ((argument :accessor dispatch-macro-argument :initarg :argument) (sub-character :accessor dispatch-macro-sub-character :initarg :sub-character))) ;;;--------------------------------------------- ;;; STANDARD READER MACRO FUNCTIONS ;;;--------------------------------------------- (defgeneric comment-text (comment) (:documentation "The text of the comment.")) (defclass comment (source-object) ((comment :accessor comment-text :initarg :comment)) (:documentation "Represents a source comment.")) ;;; ---------------------------------------- ;;; (defclass source-semicolon-comment (comment macro-character-mixin) ()) (defun source-reader-macro-line-comment (stream ch) "Source reader ; macro reader." (building-reader-macro-source-object stream ch 'source-semicolon-comment :comment (read-line stream nil ""))) ;;; ---------------------------------------- ;;; (defclass source-string (source-object macro-character-mixin) ((value :accessor source-string-value :initarg :value :initform nil :type (or null string)))) (defun source-reader-macro-string (stream delim) "Source reader \" macro reader." (building-reader-macro-source-object stream delim 'source-string :value (flet ((error-eof () (com.informatimago.common-lisp.lisp-reader.reader::serror 'simple-end-of-file stream "input stream ~S ends within a string" stream))) (loop :named read-string :with rst = (readtable-syntax-table *readtable*) :with string = (make-array 64 :element-type 'character :adjustable t :fill-pointer 0) :for ch = (read-char stream nil nil t) :do (cond ((null ch) (error-eof)) ((eql ch delim) (return-from read-string string)) ((= (com.informatimago.common-lisp.lisp-reader.reader::character-syntax (com.informatimago.common-lisp.lisp-reader.reader::character-description rst ch)) com.informatimago.common-lisp.lisp-reader.reader::+cs-single-escape+) (let ((next (read-char stream nil nil))) (when (null next) (error-eof)) (vector-push-extend next string))) (t (vector-push-extend ch string))))))) ;;; ---------------------------------------- ;;; (defclass source-subform (source-object macro-character-mixin) ((subform :accessor source-object-subform :initarg :subform))) ;;; ---------------------------------------- ;;; (defclass source-quote (source-subform macro-character-mixin) ()) (defun source-reader-macro-quote (stream ch) "Source reader ' macro reader." (building-reader-macro-source-object stream ch 'source-quote :subform (source-read stream t nil t))) ;;; ---------------------------------------- ;;; (defclass source-backquote (source-subform macro-character-mixin) ()) (defun source-reader-macro-backquote (stream ch) "Source reader ` macro reader." (building-reader-macro-source-object stream ch 'source-backquote :subform (source-read stream t nil t))) ;;; ---------------------------------------- ;;; (defclass source-unquote (source-subform macro-character-mixin) ()) (defclass source-splice (source-subform macro-character-mixin) ()) (defun source-reader-macro-comma (stream ch) "Source reader , macro reader." (building-reader-macro-source-object stream ch (if (char= #\@ (peek-char nil stream t nil t)) 'source-splice 'source-unquote) :subform (source-read stream t nil t))) ;;; ---------------------------------------- ;;; (defclass source-sequence (source-object) ((elements :accessor source-sequence-elements :initarg :elements :initform nil :type sequence :documentation " Works for conses, lists, and invalid stuff put in parentheses, like ( . . ) Dots are represented by a source-object, so they can appear even in invalid syntaxes. "))) (defclass source-list (source-sequence macro-character-mixin) ()) (defun source-reader-macro-left-parenthesis (stream ch) "Source reader ( macro reader." (building-reader-macro-source-object stream ch 'source-list :elements (loop :until (char= #\) (peek-char t stream t nil t)) :collect (source-read stream t nil t) :finally (read-char stream t nil t)))) ;;; ---------------------------------------- ;;; (defun source-reader-macro-error-start (stream ch) ;; Actually exits thru the error handler... (building-reader-macro-source-object stream ch 'source-lexical-error :error (com.informatimago.common-lisp.lisp-reader.reader::serror 'simple-reader-error stream "an object cannot start with ~C" ch))) ;;; ---------------------------------------- ;;; (defun make-source-dispatch-macro-character (macro-character &optional (readtable *readtable*)) " PRE: MACRO-CHARACTER is a reader dispatch macro character. POST: The dispatching reader macro function for the MACRO-CHARACTER is replaced by a function that encapsulates the original dispatching reader macro function, in a binding to *START* of the file position of the MACRO-CHARACTER. " (multiple-value-bind (dispatch non-terminating-p) (get-macro-character macro-character readtable) (set-macro-character macro-character (lambda (stream macro-character) (unread-char macro-character stream) (let ((*start* (file-position stream)) (*macro-character* macro-character)) (read-char stream) (funcall dispatch stream macro-character))) non-terminating-p readtable))) (defmacro building-reader-dispatch-macro-source-object (stream argument sub-char class &rest initargs &key &allow-other-keys) `(building-source-object ,stream *start* ,class :macro-character *macro-character* :argument ,argument :sub-character ,sub-char ,@initargs)) ;;;--------------------------------------------- ;;; STANDARD READER DISPATCH MACRO FUNCTIONS ;;;--------------------------------------------- (defclass source-label-reference (source-object dispatch-macro-character-mixin) ((label :accessor source-label-reference-label :initarg :label :type (integer 0)))) (defun source-reader-dispatch-macro-label-reference (stream arg sub-char) "Source reader ## dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-label-reference :label (or arg (com.informatimago.common-lisp.lisp-reader.reader::serror 'simple-reader-error stream "a number must be given between # and #")))) ;;; ---------------------------------------- ;;; (defclass source-label-definition (source-object dispatch-macro-character-mixin) ((label :accessor source-label-definition-label :initarg :label :type (integer 0)) (form :accessor source-label-definition-form :initarg :form))) (defun source-reader-dispatch-macro-label-definition (stream arg sub-char) "Source reader #= dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-label-definition :label (or arg (com.informatimago.common-lisp.lisp-reader.reader::serror 'simple-reader-error stream "a number must be given between # and =")) :form (source-read stream t nil t))) ;;; ---------------------------------------- ;;; (defclass source-feature (source-subform dispatch-macro-character-mixin) ()) (defun source-reader-dispatch-macro-feature (stream arg sub-char) "Source reader #+ dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-feature :subform (let ((*package* (find-package "KEYWORD")) (*read-suppress* nil)) (source-read stream t nil t)))) (defclass source-not-feature (source-subform dispatch-macro-character-mixin) ()) (defun source-reader-dispatch-macro-not-feature (stream arg sub-char) "Source reader #- dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-not-feature :subform (let ((*package* (find-package "KEYWORD")) (*read-suppress* nil)) (source-read stream t nil t)))) ;;; ---------------------------------------- ;;; (defclass source-read-eval (source-subform dispatch-macro-character-mixin) ()) (defun source-reader-dispatch-macro-read-eval (stream arg sub-char) "Source reader #. dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-read-eval :subform (source-read stream t nil t))) ;;; ---------------------------------------- ;;; ;;; We cannot decide between some symbol and integer, or the type of ;;; floating point before knowing *read-case* and *READ-DEFAULT-FLOAT-FORMAT* ;;; ;; (defclass source-symbol (source-token) ;; ((name :accessor source-symbol-name ;; :initarg :name) ;; (qualifier :accessor source-symbol-qualifier ;; :initarg :qualifier ;; :type (member nil :external :internal) ;; :initform nil) ;; (package :accessor source-symbol-package ;; :initarg :package ;; :initform nil ;; :documentation " ;; Either a string containing the package name, when it's explicitely qualified, ;; or nil when the symbol has no package (#:example), or the symbol *PACKAGE* ;; for unqualified symbols. ;; "))) ;; ;; ;; (defclass source-number (source-token) ;; ((value :accessor source-number-value ;; :initarg :value))) (defun source-reader-dispatch-macro-uninterned (stream arg sub-char) "Source reader #: dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-token :token (multiple-value-bind (tokenp token) (com.informatimago.common-lisp.lisp-reader.reader::read-token stream t nil t nil nil *readtable*) (if tokenp (make-instance 'source-token ;; TODO: Here, we know we have a symbol whatever... :file (pathname stream) :position *start* :token token) (com.informatimago.common-lisp.lisp-reader.reader::serror 'simple-reader-error stream "token expected after #:"))))) ;;; ---------------------------------------- ;;; (defun source-reader-dispatch-macro-unreadable (stream arg sub-char) "Source reader #< dispatch macro reader." (declare (ignore sub-char arg)) ;; TODO: see if we can do something to read #< ... (com.informatimago.common-lisp.lisp-reader.reader::serror 'simple-reader-error stream "objects printed as #<...> cannot be read back in")) ;;; ---------------------------------------- ;;; (defclass source-sharp-pipe-comment (comment dispatch-macro-character-mixin) ()) (defun source-reader-dispatch-macro-comment (stream arg sub-char) "Source reader #| dispatch macro reader." ;; #|...|# is treated as a comment by the reader. It must be balanced ;; with respect to other occurrences of #| and |#, but otherwise may ;; contain any characters whatsoever. (building-reader-dispatch-macro-source-object stream arg sub-char 'source-token :comment (loop :with comment = (make-array 0 :adjustable t :fill-pointer 0 :element-type 'character) :with level = 1 :with state = :normal :until (zerop level) :do (let ((ch (read-char stream t nil t))) (vector-push-extend ch comment) (case state ((:normal) (case ch ((#\#) (setf state :sharp)) ((#\|) (setf state :pipe)))) ((:sharp) (case ch ((#\#)) ((#\|) (incf level) (setf state :normal)) (otherwise (setf state :normal)))) ((:pipe) (case ch ((#\#) (decf level) (setf state :normal)) ((#\|)) (otherwise (setf state :normal)))))) :finally (progn (decf (fill-pointer comment) 2) (return comment))))) ;;; ---------------------------------------- ;;; (defclass source-function (source-subform dispatch-macro-character-mixin) ()) (defun source-reader-dispatch-macro-function (stream arg sub-char) "Source reader #' dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-function :subform (source-read stream t nil t))) ;;; ---------------------------------------- ;;; (defclass source-vector (source-sequence dispatch-macro-character-mixin) ()) (defun source-reader-dispatch-macro-vector (stream arg sub-char) "Source reader #( dispatch macro reader." ;; If an unsigned decimal integer appears between the # and (, it ;; specifies explicitly the length of the vector. The consequences are ;; undefined if the number of objects specified before the closing ) ;; exceeds the unsigned decimal integer. If the number of objects ;; supplied before the closing ) is less than the unsigned decimal ;; integer but greater than zero, the last object is used to fill all ;; remaining elements of the vector. The consequences are undefined if ;; the unsigned decimal integer is non-zero and number of objects ;; supplied before the closing ) is zero. For example, (building-reader-dispatch-macro-source-object stream arg sub-char 'source-vector :elements (loop :until (char= #\) (peek-char t stream t nil t)) :collect (source-read stream t nil t) :finally (read-char stream t nil t)))) ;;; ---------------------------------------- ;;; (defclass source-bit-vector (source-sequence dispatch-macro-character-mixin) ()) (defun source-reader-dispatch-macro-bit-vector (stream arg sub-char) "Source reader #* dispatch macro reader. URL: <http://www.lispworks.com/documentation/HyperSpec/Body/02_dhd.htm> " ;; Syntax: #*<<bits>> ;; ;; A simple bit vector is constructed containing the indicated bits (0's ;; and 1's), where the leftmost bit has index zero and the subsequent ;; bits have increasing indices. ;; ;; Syntax: #<<n>>*<<bits>> ;; ;; With an argument n, the vector to be created is of length n. If the ;; number of bits is less than n but greater than zero, the last bit is ;; used to fill all remaining bits of the bit vector. ;; ;; The notations #* and #0* each denote an empty bit vector. ;; ;; Regardless of whether the optional numeric argument n is provided, the ;; token that follows the asterisk is delimited by a normal token ;; delimiter. However, (unless the value of *read-suppress* is true) an ;; error of type reader-error is signaled if that token is not composed ;; entirely of 0's and 1's, or if n was supplied and the token is ;; composed of more than n bits, or if n is greater than one, but no bits ;; were specified. Neither a single escape nor a multiple escape is ;; permitted in this token. (building-reader-dispatch-macro-source-object stream arg sub-char 'source-bit-vector :elements (com.informatimago.common-lisp.lisp-reader.reader::reader-dispatch-macro-bit-vector stream arg sub-char))) ;;; ---------------------------------------- ;;; (defclass source-character (source-object dispatch-macro-character-mixin) ((character :accessor source-character :initarg :character))) (defun source-reader-dispatch-macro-char (stream arg sub-char) "Source reader #\\ dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-character :character (read-char stream t nil t))) ;;; ---------------------------------------- ;;; (defclass source-array (source-subform dispatch-macro-character-mixin) ()) (defun source-reader-dispatch-macro-array (stream arg sub-char) "Source reader #A dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-array :subform (source-read stream t nil t))) ;;; ---------------------------------------- ;;; (defclass source-number (source-object) ((value :accessor source-number-value :initarg :value))) (defclass source-base-number (source-number dispatch-macro-character-mixin) ((base :accessor source-base-number-base :initarg :base) (specificp :accessor source-base-number-specific :initarg :specificp))) (defun source-reader-dispatch-macro-binary (stream arg sub-char) "Source reader #B dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-base-number :base 2. :specificp t :value (com.informatimago.common-lisp.lisp-reader.reader::read-rational-in-base stream arg sub-char 2.))) (defun source-reader-dispatch-macro-octal (stream arg sub-char) "Source reader #O dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-base-number :base 8. :specificp t :value (com.informatimago.common-lisp.lisp-reader.reader::read-rational-in-base stream arg sub-char 8.))) (defun source-reader-dispatch-macro-hexadecimal (stream arg sub-char) "Source reader #X dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-base-number :base 16. :specificp t :value (com.informatimago.common-lisp.lisp-reader.reader::read-rational-in-base stream arg sub-char 16.))) (defun source-reader-dispatch-macro-radix (stream arg sub-char) "Source reader #R dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-base-number :base arg :specificp nil :value (if arg (com.informatimago.common-lisp.lisp-reader.reader::read-rational-in-base stream nil sub-char arg) (com.informatimago.common-lisp.lisp-reader.reader::serror stream "the number base must be given between # and ~A" sub-char)))) ;;; ---------------------------------------- ;;; (defclass source-complex (source-subform dispatch-macro-character-mixin) ()) (defun source-reader-dispatch-macro-complex (stream arg sub-char) "Source reader #C dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-base-complex :subform (let ((c (source-read stream t nil t))) (if (and (com.informatimago.common-lisp.lisp-reader.reader::proper-list-p c) (= 2 (length c)) (every (function realp) c)) c (com.informatimago.common-lisp.lisp-reader.reader::serror 'simple-reader-error stream "bad syntax for complex number: #C~S" c))))) ;;; ---------------------------------------- ;;; (defclass source-pathname (source-subform dispatch-macro-character-mixin) ()) (defun source-reader-dispatch-macro-pathname (stream arg sub-char) "Source reader #P dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-pathname :subform (source-read stream t nil t) )) ;;; ---------------------------------------- ;;; (defclass source-structure (source-subform dispatch-macro-character-mixin) ()) (defun source-reader-dispatch-macro-structure (stream arg sub-char) "Source reader #S dispatch macro reader." (building-reader-dispatch-macro-source-object stream arg sub-char 'source-structure :subform (source-read stream t nil t))) ;;; ---------------------------------------- ;;; (defun source-reader-dispatch-macro-error-invalid (stream sub-char arg) (building-reader-dispatch-macro-source-object stream arg sub-char 'source-lexical-error :error (com.informatimago.common-lisp.lisp-reader.reader::serror 'simple-reader-error stream "objects printed as # in view of *PRINT-LEVEL* cannot be read back in"))) ;;; ---------------------------------------- ;;; (defun make-source-readtable () " RETURN: A new readtable where all the reader macros are set to return source objects instead of lisp objects. " (let ((readtable (copy-readtable nil))) (macrolet ((smc (&rest clauses) `(progn ,@(mapcar (lambda (clause) `(set-macro-character ,(first clause) (function ,(second clause)) ,(third clause) readtable)) clauses)))) (smc (#\; source-reader-macro-line-comment nil) (#\" source-reader-macro-string nil) (#\' source-reader-macro-quote nil) (#\` source-reader-macro-backquote nil) (#\, source-reader-macro-comma nil) (#\( source-reader-macro-left-parenthesis nil) (#\) source-reader-macro-error-start nil))) (macrolet ((dmc (&rest clauses) `(progn ,@(mapcar (lambda (clause) `(set-dispatch-macro-character ,(first clause) ,(second clause) (function ,(third clause)) readtable)) clauses)))) (make-dispatch-macro-character #\# t readtable) (dmc (#\# #\SPACE source-reader-dispatch-macro-error-invalid) (#\# #\NEWLINE source-reader-dispatch-macro-error-invalid) (#\# #\# source-reader-dispatch-macro-label-reference) (#\# #\' source-reader-dispatch-macro-function) (#\# #\( source-reader-dispatch-macro-vector) (#\# #\* source-reader-dispatch-macro-bit-vector) (#\# #\+ source-reader-dispatch-macro-feature) (#\# #\- source-reader-dispatch-macro-not-feature) (#\# #\. source-reader-dispatch-macro-read-eval) (#\# #\: source-reader-dispatch-macro-uninterned) (#\# #\< source-reader-dispatch-macro-unreadable) (#\# #\= source-reader-dispatch-macro-label-definition) (#\# #\A source-reader-dispatch-macro-array) (#\# #\B source-reader-dispatch-macro-binary) (#\# #\C source-reader-dispatch-macro-complex) (#\# #\O source-reader-dispatch-macro-octal) (#\# #\P source-reader-dispatch-macro-pathname) (#\# #\R source-reader-dispatch-macro-radix) (#\# #\S source-reader-dispatch-macro-structure) (#\# #\X source-reader-dispatch-macro-hexadecimal) (#\# #\\ source-reader-dispatch-macro-char) (#\# #\| source-reader-dispatch-macro-comment) ;; clisp extensions: ;; (#\# #\! reader-dispatch-macro-executable) ;; (#\# #\" reader-dispatch-macro-clisp-pathname) ;; (#\# #\, reader-dispatch-macro-load-eval) ;; (#\# #\Y SYSTEM::CLOSURE-READER) )) (setf (readtable-parse-token readtable) (function source-parse-token)) readtable)) (defvar *source-readtable* (make-source-readtable) "The source readtable.") (defun source-read (&optional input-stream (eof-error-p t) (eof-value nil) (recursive-p nil) (preserve-whitespace-p nil)) (let ((*read-suppress* nil) ; we do want the source! (*readtable* *source-readtable*) (*stream* input-stream) (*file* (ignore-errors (pathname input-stream)))) (unless preserve-whitespace-p (peek-char t input-stream nil nil t)) (let ((*start* (file-position input-stream))) ;; (read input-stream eof-error-p eof-value recursive-p) ;; We want to allow all-dots tokens. (com.informatimago.common-lisp.lisp-reader.reader::read-1 input-stream eof-error-p eof-value recursive-p preserve-whitespace-p nil t)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defgeneric source-atom-p (self) (:method ((self source-object)) (declare (ignorable self)) t) (:method ((self source-list)) (declare (ignorable self)) nil)) (defgeneric map-subforms (fun self) (:method (fun (self source-object)) (funcall fun self) (values)) (:method (fun (self source-array)) (funcall fun self) (values)) (:method (fun (self source-complex)) (funcall fun self) (values)) (:method (fun (self source-pathname)) (funcall fun self) (values)) (:method (fun (self source-subform)) (funcall fun self) (map-subforms fun (source-object-subform self))) (:method (fun (self source-label-definition)) (funcall fun self) (map-subforms fun (source-label-definition-form self))) (:method (fun (self source-list)) (funcall fun self) (dolist (item (source-sequence-elements self) (values)) (map-subforms fun item)))) (defun map-source-stream (fun source-stream &key (deeply t) (only-atoms nil)) (loop :for top-level-form = (source-read source-stream nil source-stream t) :until (eq top-level-form source-stream) :if deeply :do (map-subforms (if only-atoms (lambda (x) (when (source-atom-p x) (funcall fun x))) fun) top-level-form) :else :do (when (or (not only-atoms) (source-atom-p top-level-form)) (funcall fun top-level-form)))) (defun map-source-file (fun source-file &key (deeply t) (only-atoms nil) (external-format :default)) " FUN: A function (source-object) source-object: An instance of source-object parsed from a source file. When atoms is true, FUN is called only on source-objects not representing cons cells (lists). " (with-open-file (src source-file :external-format external-format) (map-source-stream fun src :deeply deeply :only-atoms only-atoms))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; To be tested: ;;; ;;; '(#1=#2=#3=#4=a #2# #3# #4#) #|| (use-package :com.informatimago.common-lisp.lisp-text.source-text) (defparameter *some* (with-open-file (src "source-text.lisp") (loop :for item = (source-read src nil src) :until (eq item src) :collect item :until (typep item 'source-lexical-error) :do (princ "**") (let ((*print-readably* nil)) (print item)) :do (princ "==") (let ((*print-readably* t )) (prin1 item))))) (defparameter *some* (with-input-from-string (src "(a b c) (d e f)") (loop :for item = (source-read src nil src) :until (eq item src) :collect item :until (typep item 'source-lexical-error) :do (princ "**") (let ((*print-readably* nil)) (print item)) :do (princ "==") (let ((*print-readably* t )) (prin1 item))))) (with-input-from-string (src " ") (com.informatimago.common-lisp.lisp-reader.reader::read-token src nil :eof t nil nil reader::*readtable*)) (with-input-from-string (src " ") (com.informatimago.common-lisp.lisp-reader.READER::READ-0/1 src nil :eof nil NIL NIL T)) (with-input-from-string (src " ") (source-read src nil :eof)) (defparameter *some* (with-open-file (src "source-text.lisp") (loop :for item = (source-text:source-read src nil src) :until (eq item src) :collect item :until (typep item 'source-lexical-error) :do (let ((*print-readably* t)) (prin1 item))))) (with-input-from-string (src "#+(and)(a b c #-(or) d e)") (source-read src nil :eof)) (with-input-from-string (src "( a . b . c ... d #+(and)(a b c) #-(or)(d e))") (source-read src nil :eof)) (setf *some* (with-input-from-string (src "'(#1=#2=#3=#4=a #2# #3# #4#)") (source-read src nil :eof))) ||# ;; (with-input-from-string (src "(a (b c #(1 2 3) (e f) g) h) (1 2 3)") ;; (let ((*print-readably* t)) ;; (map-source-stream (lambda (x) (terpri) (prin1 x)) src))) ;; ;; (with-input-from-string (src "(a (b c (1 2 3) (e f) g) h) (1 2 3)") ;; (let ((*print-readably* t)) ;; (map-source-stream (lambda (x) (terpri) (prin1 x)) src ;; :deeply t :only-atoms nil))) ;; ;; (with-input-from-string (src "(a (b c #(1 2 3) (e f) g) h) (1 2 3)") ;; (map-source-stream (lambda (x) ;; (terpri) ;; (let ((*print-readably* t)) (prin1 x))) ;; src :deeply t :only-atoms nil)) ;;;; The End ;;;;
44,861
Common Lisp
.lisp
991
37.669021
119
0.586891
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
fe23c7a055531ff106bc37ea245b13344b02056bbbec4bd8a0098cd1bfb72a17
5,020
[ -1 ]
5,021
avl.lisp
informatimago_lisp/common-lisp/obsolete-or-incomplete/avl.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: avl.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; An implementation of AVL trees (Adelson-Velskii & Landis Balanced Trees). ;;;; ;;;;EXAMPLE ;;;; ;;;; (let ((tree (avl-empty))) ;;;; (setf tree (avl-insert tree v1 comparef)) ;;;; (setf tree (avl-insert tree v2 comparef)) ;;;; (setf (avl-insert tree v3 comparef)) ;;;; (setf (avl-insert tree v4 comparef)) ;;;; (assert (eq v3 (avl-value (avl-search tree v3 comparef)))) ;;;; (avl-walk tree :prefix (lambda (v) (print "(")) ;;;; :infix (lambda (v) (print v)) ;;;; :suffix (lambda (v) (print ")")) )) ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2004-01-09 <PJB> Created. ;;;;BUGS ;;;; - Not debugged yet. There's a problem in avl-insert ;;;; (the test function fails in avl-insert). ;;;; ;;;; - Removing nodes is not implemented. ;;;; ;;;; - The data type is not encapsulated. At least we should keep ;;;; the compare function along with it. And some green functions ;;;; (avl-count) would be nice too. ;;;; ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2004 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (in-package "COMMON-LISP-USER") (defpackage "COM.INFORMATIMAGO.COMMON-LISP.OBSOLETE-OR-INCOMPLEPTE.AVL" (:use "COMMON-LISP" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.LIST" "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.UTILITY") (:export "AVL-WALK" "AVL-SEARCH" "AVL-VALUE" "AVL-INSERT" "AVL-EMPTY" "AVL") (:import-from "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.LIST" "MAKE-LIST-OF-RANDOM-NUMBERS") (:import-from "COM.INFORMATIMAGO.COMMON-LISP.CESARUM.UTILITY" "UNTIL" "WHILE") (:documentation "This package exports an AVL balanced binary tree data type. Copyright Pascal J. Bourguignon 2003 - 2004 This package is provided under the GNU General Public License. See the source file for details.")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.OBSOLETE-OR-INCOMPLEPTE.AVL") (defstruct avl (left nil :type (or null avl)) (right nil :type (or null avl)) (unbalance 0 :type integer) (value) ) ;;AVL (defun avl-rl (avl) " DO: Rotate left. RETURN: The rotated tree. PRE: (a!=NULL)&&(a->droite!=NULL) a=<p,U,<q,V,W>> POST: a=<q,<p,U,V>,W> " (assert (and avl (avl-right avl))) (psetf avl (avl-right avl) (avl-right avl) (avl-left avl) (avl-left avl) avl) avl) ;;AVL-RL (defun avl-rr (avl) " DO: Rotate right. RETURN: The rotated tree. PRE: (a!=NULL)&&(a->gauche!=NULL) a=<q,<p,U,V>,W> POST: a=<p,U,<q,V,W>> " (assert (and avl (avl-left avl))) (psetf avl (avl-left avl) (avl-left avl) (avl-right avl) (avl-right avl) avl) avl) ;;AVL-RR (defun avl-rlr (avl) " DO: Rotate left-right. RETURN: The rotated tree. PRE: (a!=NULL)&&(a->gauche!=NULL)&&(a->gauche->droite!=NULL) a=<r,<p,T,<q,U,V>>,W> POST: a=<q,<p<T,U>,<r,V,W>> " (assert (and avl (avl-left avl) (avl-right (avl-left avl)))) (setf (avl-left avl) (avl-rl (avl-left avl))) (setf avl (avl-rr avl)) avl) ;;AVL-RLR (defun avl-rrl (avl) " DO: Rotate right-left. RETURN: The rotated tree. PRE: (a!=NULL)&&(a->droite!=NULL)&&(a->droite->gauche!=NULL) a=<r,T,<p,<q,U,V>,W>> POST: a=<q,<r,T,U>,<p,V,W>> " (assert (and avl (avl-right avl) (avl-left (avl-right avl)))) (setf (avl-right avl) (avl-rr (avl-right avl))) (setf avl (avl-rl avl)) avl) ;;AVL-RRL (defun avl-empty () " RETURN: A new empty AVL tree. " nil) ;;AVL-EMPTY (defun avl-search (avl value compare) " COMPARE: A function (x y) --> { -1, 0, +1 } indicating whether x<y, x=y or x>y. RETURN: The avl node such as (funcall compare value (avl-value avl)) == 0 or nil of none found. " (while avl (case (funcall compare value (avl-value avl)) ((-1) (setf avl (avl-left avl))) ((0) (return-from avl-search avl)) ((1) (setf avl (avl-right avl))))) nil) ;;AVL-SEARCH (defun avl-insert (avl value compare) " COMPARE: A function (x y) --> { -1, 0, +1 } indicating whether x<y, x=y or x>y. RETURN: The modified avl tree where a new node has been added for value. " (let (y a p aa pp) (setf y (make-avl :value value)) (when (null avl) (return-from avl-insert y)) (setf a avl aa nil p a pp nil) ;; aa est le pere de a; pp est le pere de p (while p ;; Descente a la recherche de la feuille, en memorisant le ;; dernier noeud pointe par a dont le desequilibrage est +/-1. (unless (zerop (avl-unbalance p)) (setf a p aa pp)) (setf pp p) (if (<= (funcall compare value (avl-value p)) 0) (setf p (avl-left p)) (setf p (avl-right p)))) ;; adjonction (if (<= (funcall compare value (avl-value pp)) 0) (setf (avl-left pp) y) (setf (avl-right pp) y)) ;; modification du desequilibre sur le chemin de a a y (setf p a) (until (eq p y) (if (<= (funcall compare value (avl-value p)) 0) (progn (incf (avl-unbalance p)) (setf p (avl-left p))) (progn (decf (avl-unbalance p)) (setf p (avl-right p))))) ;; reequilibrage (case (avl-unbalance a) ((-1 0 +1) (return-from avl-insert avl)) ((+2) (case (avl-unbalance (avl-left a)) ((+1) (setf a (avl-rr a) (avl-unbalance a) 0 (avl-unbalance (avl-right a)) 0)) ((-1) (setf a (avl-rlr a)) (case (avl-unbalance a) ((+1) (setf (avl-unbalance (avl-left a)) 0 (avl-unbalance (avl-right a)) -1)) ((-1) (setf (avl-unbalance (avl-left a)) +1 (avl-unbalance (avl-right a)) 0)) ((0) ;; case when (eq a y) (setf (avl-unbalance (avl-left a)) 0 (avl-unbalance (avl-right a)) 0))) (setf (avl-unbalance a) 0)))) ((-2) (case (avl-unbalance (avl-right a)) ((-1) (setf a (avl-rl a) (avl-unbalance a) 0 (avl-unbalance (avl-left a)) 0)) ((+1) (setf a (avl-rrl a)) (case (avl-unbalance a) ((+1) (setf (avl-unbalance (avl-right a)) 0 (avl-unbalance (avl-left a)) +1)) ((-1) (setf (avl-unbalance (avl-right a)) -1 (avl-unbalance (avl-left a)) 0)) ((0) ;; case when (eq a y) (setf (avl-unbalance (avl-right a)) 0 (avl-unbalance (avl-left a)) 0))) (setf (avl-unbalance a) 0))))) ;; mise a jour des pointeurs apres une rotation (cond ((null aa) (setf avl a)) ((<= (funcall compare (avl-value a) (avl-value aa)) 0) (setf (avl-left aa) a)) (t (setf (avl-right aa) a))) avl)) ;;AVL-INSERT (defun avl-walk (avl &key (prefix (function identity)) (infix (function identity)) (suffix (function identity))) " DO: Walks the avl tree applying the functions prefix, infix, and suffix on the value of each node. " (when avl (funcall prefix (avl-value avl)) (avl-walk (avl-left avl) :prefix prefix :infix infix :suffix suffix) (funcall infix (avl-value avl)) (avl-walk (avl-right avl) :prefix prefix :infix infix :suffix suffix) (funcall suffix (avl-value avl))) ) ;;AVL-WALK (defun test (size) (let* ((data (delete-duplicates (make-list-of-random-numbers size))) (hash (make-hash-table :size size)) (tree (avl-empty))) (flet ((reset (hash) (maphash (lambda (k v) (declare (ignore k)) (setf (second v) 0)) hash)) (check (hash) (maphash (lambda (k v) (declare (ignore k)) (assert (= 1 (second v)))) hash)) (compare (a b) (cond ((< (first a) (first b)) -1) ((> (first a) (first b)) +1) (t 0)))) ;; -1- fill a tree. (dolist (item data) (let ((record (list item 0))) (setf (gethash (first record) hash) record) (setf tree (avl-insert tree record (function compare))))) ;; -2- check we have all the data. (dolist (item data) (let* ((node (avl-search tree (gethash item hash) (function compare))) (record (and node (avl-value node)))) (assert record) (assert (eql (first record) (gethash (second record) hash))))) ;; -3- walk the tree (three ways) and check we get all the data. (dolist (mode '(:prefix :infix :suffix)) (reset hash) (avl-walk tree mode (lambda (record) (incf (third record)))) (check hash))))) ;;test ;;;; avl.lisp -- -- ;;;;
10,421
Common Lisp
.lisp
263
32.140684
83
0.53055
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
af980a7d7bf71c3dc9f7ccb8f9d7bcded39e1651c7f0b3275c82eb1a9ea0e0e4
5,021
[ -1 ]
5,022
database.lisp
informatimago_lisp/common-lisp/obsolete-or-incomplete/database.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: database.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; A Lisp Database access layer. ;;;; ;;;; This package defines a generic API to access databases. ;;;; ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2003-09-22 <PJB> Creation. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2003 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (in-package "COMMON-LISP-USER") (defpackage "COM.INFORMATIMAGO.COMMON-LISP.OBSOLETE-OR-INCOMPLEPTE.DATABASE" (:use "COMMON-LISP") (:export "INITIALIZE-INSTANCE" "OBJECT-FILTER" "SET-OBJECT-FILTER" "ORDER-LIST" "SET-ORDER-LIST" "FETCH-OBJECTS" "COUNT-OBJECTS" "DELETE-OBJECT" "INSERT-OBJECT" "CREATE-OBJECT" "DATASOURCE" "DEF-ENTITY" "INTERNAL-ORDER-LIST" "DEFAULT-ORDER-LIST" "USER-SORT-ATTRIBUTES" "LIST-ATTRIBUTES" "ATTRIBUTES" "CONSTRUCTOR" "PLURAL" "ENTITY" "INPUT" "COMMENT" "EDIT-CONTROL" "SHOW-CONTROL" "OUTPUT" "ACCESSOR" "NAME" "REF" "ATTRIBUTE" "MESSAGE" "VALUE" "PLACE" "DATA-ERROR") (:documentation "This package defines a generic API to access databases. Copyright Pascal J. Bourguignon 2003 - 2003 This package is provided under the GNU General Public License. See the source file for details.")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.OBSOLETE-OR-INCOMPLEPTE.DATABASE") (defgeneric attribute-with-ref (self ref)) (defgeneric create-object (self &rest args)) (defgeneric count-objects (self)) (defgeneric set-order-list (self order-list)) (defgeneric set-object-filter (self object-filter)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ENTITIES -- meta information about database entities ;;; ;;; This meta information describes the entities and their attributes, ;;; with human readable names, input and output functions, etc. ;;; (define-condition data-error (error) ((place :accessor place :initarg :place) ;; The variable name that contains a bad value. (value :accessor value :initarg :value) ;; The bad value. (message :accessor message :initarg :message) ;; The message explaining the problem. ) (:documentation "A condition occuring when bad input data is detected.") (:report (lambda (condition stream) (format stream "~&A ~a attribute cannot contain ~A.~%~A~%" (place condition) (value condition) (message condition)))) ) ;;DATA-ERROR (defclass attribute () ( (ref :accessor ref :initarg :ref :type symbol :documentation "A reference to the attribute.") (name :accessor name :initarg :name :type string :documentation "A human readable name for the attribute.") (accessor :accessor accessor :initarg :accessor :type symbol :documentation "The accessor function name.") (output :accessor output :initarg :output :documentation ":HIDDEN, or a (lambda (attribute) ...) returning a human readble string representation of the value to be displayed.") (show-control :accessor show-control :initarg :show-control :documentation "Describes to the UI layer how to show the attribute (read-only).") (edit-control :accessor edit-control :initarg :edit-control :documentation "Describes to the UI layer how to edit the attribute (read-write).") (comment :accessor comment :initarg :comment :type string :documentation "A comment/help to be displayed along with the attribute.") (input :accessor input :initarg :input :documentation "A function used to check and convert the input value from the form attribute returning the input value, or signaling a DATA-ERROR.") ) (:documentation "Description of a entity attribute.") ) ;;ATTRIBUTE (defclass entity () ( (ref :accessor ref :initarg :ref :type symbol :documentation "A reference to the entity description. The value slot of this symbol stores the ENTITY instance.") (name :accessor name :initarg :name :type string :documentation "A human readable name for the entity represented by this entity.") (plural :accessor plural :initarg :plural :type string :documentation "The plural form of the NAME.") (constructor :accessor constructor :initarg :constructor :type symbol :documentation "The constructor function symbol, used to make a new entity." ) (attributes :accessor attributes :initarg :attributes :type list :documentation "The list of ATTRIBUTE descriptions.") (list-attributes :accessor list-attributes :initarg :list-attributes :type list :documentation "The list of ATTRIBUTE references that must be used for lists, in order.") (user-sort-attributes :accessor user-sort-attributes :initarg :user-sort-attributes :type list :documentation "The list of ATTRIBUTE references available as sort criteria to the user. Note: this ought to be a sublist of list-attributes.") (default-order-list :accessor default-order-list :initarg :default-order-list :type list :documentation "The order list used as default sort criteria. A list of (ATTRIBUTE-reference (OR :ASCEND :DESCENT)).") (internal-order-list :accessor internal-order-list :initarg :internal-order-list :type list :documentation "An addition order list appended to the user order lists, to get a consistent sort order. A list of (ATTRIBUTE-reference (OR :ASCEND :DESCENT)).") ) (:documentation "Description of a entity.") ) ;;ENTITY (defmethod attribute-with-ref ((self entity) (ref symbol)) (car (member ref (attributes self) :key (function ref))) ) ;;attribute-with-ref ;;; ------------------------------------------------------------------------ ;;; Defining entities and their attributes easily. ;;; ---------------------------------------------- ;;; (defun gather-attributes (arguments expected) ;; This is the attributes of the CLOS object ENTITY and ATTRIBUTE! (do ((attributes '()) (arg arguments (cddr arg))) ((null arg) (nreverse attributes)) (let ((tok-process (assoc (first arg) expected))) (unless tok-process (error "Unexpected token at: ~S." arg)) (push (first arg) attributes) (push (funcall (coerce (cdr tok-process) 'function) (eval (second arg))) attributes))) ) ;;GATHER-ATTRIBUTES (defun make-type-check (type attribute) (lambda (attrib) (unless (typep attrib type) (error "Expected a ~A as ~A instead of ~S." type attribute attrib)) attrib) ) ;;MAKE-TYPE-CHECK (defmacro def-entity (instvar &rest args) " DO: Generate an instruction to make an instance of a ENTITY description. This instance is assigned to the variable INSTVAR. " `(defparameter ,instvar (apply (function make-instance) 'entity (gather-attributes (cons :ref '(',instvar ,@args)) `((:ref . ,(make-type-check 'symbol "entity reference")) (:name . ,(make-type-check 'string "entity name")) (:plural . ,(make-type-check 'string "entity plural")) (:constructor . ,(make-type-check 'symbol "entity constructor")) (:list-attributes . ,(make-type-check 'list "entity list attributes")) (:user-sort-attribute . ,(make-type-check 'list "entity user sort list")) (:default-order-list . ,(make-type-check 'list "entity default order list")) (:internal-order-list . ,(make-type-check 'list "entity internal order list")) (:attributes . ,(lambda (attributes) (mapcar (lambda (attrib) (gather-attributes (cons :ref (cons (list 'quote (car attrib)) (cdr attrib))) '((:ref . ,(make-type-check 'symbol "attribute reference")) (:name . ,(make-type-check 'string "attribute name")) (:accessor . ,(make-type-check 'symbol "attribute accessor")) (:output . (lambda (attrib) (cond ((eq attrib :hidden) attrib) ((functionp attrib) attrib) ((and (listp attrib) (eq 'lambda (first attrib))) (eval attrib)) ((and (listp attrib) (eq 'function (first attrib))) (eval attrib)) ((and (symbolp attrib) (fboundp attrib)) (eval `(function ,attrib))) (t (error "Expected :HIDDEN or a function as attribute output instead of ~S." attrib))))) (:show-control . ,(function identity)) ;;(MAKE-TYPE-CHECK 'LIST "attribute SHOW-control widget")) (:edit-control . ,(function identity)) ;;(MAKE-TYPE-CHECK 'LIST "attribute EDIT-control widget")) (:comment . ,(make-type-check '(or null string) "attribute comment")) (:input . (lambda (attrib) (cond ((functionp attrib) attrib) ((and (listp attrib) (eq 'lambda (first attrib))) (eval attrib)) ((and (listp attrib) (eq 'function (first attrib))) (eval attrib)) ((and (symbolp attrib) (fboundp attrib)) (eval `(function ,attrib))) (t (error "Expected a function as attribute input instead of ~S." attrib))))) ) )) attributes)))) ))) ) ;;DEF-ENTITY ;;; ------------------------------------------------------------------------ ;;; Editing entities ;;; --------------- ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; DATASOURCE abstraction ;;; (defclass datasource () ( (entity :accessor entity :initarg :entity :type entity :documentation "The ENTITY describing the objects contained in this DATASOURCE.") (order-list :accessor order-list :initarg :order-list :type list :documentation "The order list used to sort the data.") (object-filter :accessor object-filter :initarg :object-filter-list :type list :documentation "The filter used to select the data from the source.") ) (:documentation "An abstract data source.") ) ;;DATASOURCE (defmethod initialize-instance :after ((self datasource) &rest initargs &key &allow-other-keys) " DO: Initalize the instance. " (declare (ignore initargs)) (setf (object-filter self) t) ;; return all objects. self) ;;INITIALIZE-INSTANCE (defmethod create-object ((self datasource) &rest args) "Creates a new instance of the ENTITY. This instance is not inserted into the DATASOURCE: use INSERT-OBJECT. The ARGS are passed to the entity constructor function." (apply (constructor (entity self)) args) ) ;;CREATE-OBJECT (defgeneric insert-object (datasource object) (:documentation "Inserts the OBJECT into the DATASOURCE.") ) ;;INSERT-OBJECT (defgeneric delete-object (datasource object) (:documentation "Deletes the OBJECT from the DATASOURCE.") ) ;;DELETE-OBJECT (defmethod count-objects ((self datasource)) "Returns the number of OBJECTS present in the DATASOURCE. This default implementation just fetches all the objects and count them. It should rather be overriden by subclasses!" (length (fetch-objects self)) ) ;;COUNT-OBJECTS (defgeneric fetch-objects (datasource &key start end) (:documentation "Returns a list of objects found in the DATASOURCE. When the key START and END are present, returns only this range of objects.") ) ;;FETCH-OBJECTS (defmethod set-order-list ((self datasource) (order-list list)) "Set the ORDER-LIST of the DATASOURCE. Next time FETCH-OBJECTS will be called, the objects will be returned in following this ORDER-LIST. An ORDER-LIST has the following syntax: ( ( FIELD-REF :ASCEND|:DESCENT )* ) When NIL, the default-user-order-list from the entity is used." (setf (order-list self) order-list) ) ;;SET-ORDER-LIST (defmethod set-object-filter ((self datasource) (object-filter t)) "Set the OBJECT-FILTER of the DATASOURCE. Next time FETCH-OBJECTS or COUNT-OBJECTS will be called, only objects passing this OBJECT-FILTER will be returned or counted. An OBJECT-FILTER has the following syntax: OBJECT-FILTER ::= NIL ;; no object is selected. | T ;; all objects are selected. | (NOT OBJECT-FILTER) | (AND OBJECT-FILTER*) | (OR OBJECT-FILTER*) | (MATCHES FIELD-REF PATTERN) | (= EXPRESSION EXPRESSION) | (/= EXPRESSION EXPRESSION) | (< EXPRESSION EXPRESSION) | (<= EXPRESSION EXPRESSION) | (> EXPRESSION EXPRESSION) | (>= EXPRESSION EXPRESSION) | (MEMBER FIELD-REF (EXPRESSION*)) . EXPRESSION ::= (* EXPRESSION*) | (/ EXPRESSION EXPRESSION) | (+ EXPRESSION*) | (- EXPRESSION EXPRESSION) | (- EXPRESSION) | FIELD-REF | STRING | NUMBER . PATTERN ::= STRING . ;; with zero, one or more '_' or '%' wildcards. FIELD-REF ::= SYMBOL . " (setf (object-filter self) object-filter) ) ;;SET-OBJECT-FILTER ;;;; database.lisp -- -- ;;;;
15,525
Common Lisp
.lisp
377
33.084881
124
0.584404
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
f1c61a5c1a73409ebf26ff0cd2927c76b2e9249b759c0e911a75e6aea0279d0b
5,022
[ -1 ]
5,023
dictionary.lisp
informatimago_lisp/common-lisp/obsolete-or-incomplete/dictionary.lisp
;;;; -*- coding:utf-8 -*- ;;;;**************************************************************************** ;;;;FILE: dictionary.lisp ;;;;LANGUAGE: COMMON-LISP/CLOS ;;;;SYSTEM: COMMON-LISP ;;;;USER-INTERFACE: None ;;;;NOWEB: t ;;;;DESCRIPTION ;;;; This is a Dictionary class. "<em>legacy code</em>" Silly implementation ;;;; using linked lists to store the couples. ;;;; Should be redone using hash tables. ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2004-01-25 <PJB> Removed import from CLOS (it's all in COMMON-LISP!). ;;;; 1995-10-16 <PJB> Creation. ;;;;BUGS ;;;; Silly implementation using linked lists to store the couples. ;;;; Should be redone using hash tables. ;;;; ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 1995 - 2016 ;;;; ;;;; 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/> ;;;;**************************************************************************** (in-package "COMMON-LISP-USER") (defpackage "COM.INFORMATIMAGO.COMMON-LISP.OBSOLETE-OR-INCOMPLEPTE.DICTIONARY" (:use "COMMON-LISP") (:export "APPLY-TO-ASSOCIATIONS" "CONTAINS-KEY?" "CONTAINS-ASSOCIATION?" "PUT-AT-KEY" "ASSOCIATION-AT-KEY" "VALUE-AT-KEY" "GET-VALUES" "GET-KEYS" "DICTIONARY" "DICTIONARY-SUMMARY") (:documentation "This is a DICTIONARY class. Silly implementation using linked lists to store the couples. Should be redone using hash tables. Copyright Pascal J. Bourguignon 1995 - 1995 This package is provided under the GNU General Public License. See the source file for details.")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.OBSOLETE-OR-INCOMPLEPTE.DICTIONARY") (defun dictionary-summary () (format t "~%") ;; egrep -i '^(DEFCLASS|^(DEFMETHOD' dictionary.lisp |sed -e 's/(DEFCLASS \(.*\)/ (FORMAT T "Class \1~%")/' -e 's/(DEFMETHOD\(.*\)/ (FORMAT T "\1~%")/' (format t "Class DICTIONARY ()~%") (format t " GET-KEYS ((SELF DICTIONARY))~%") (format t " GET-VALUES ((SELF DICTIONARY))~%") (format t " VALUE-AT-KEY ((SELF DICTIONARY) KEY)~%") (format t " ASSOCIATION-AT-KEY ((SELF DICTIONARY) KEY)~%") (format t " PUT-AT-KEY ((SELF DICTIONARY) KEY VALUE)~%") (format t " CONTAINS-ASSOCIATION? ((SELF DICTIONARY) ASSOCIATION)~%") (format t " CONTAINS-KEY? ((SELF DICTIONARY) KEY)~%") (format t " APPLY-TO-ASSOCIATIONS ((SELF DICTIONARY) FUNC)~%")) ;; M-x insert-generic RET (defgeneric get-keys (a)) (defgeneric get-values (a)) (defgeneric value-at-key (a b)) (defgeneric association-at-key (a b)) (defgeneric put-at-key (a b c)) (defgeneric contains-association? (a b)) (defgeneric contains-key? (a b)) (defgeneric apply-to-associations (a b)) (defclass dictionary () ((associations :accessor associations :initform '()))) (defmethod get-keys ((self dictionary)) (mapcar (function car) (associations self))) (defmethod get-values ((self dictionary)) (mapcar (function cdr) (associations self))) (defun dictionary-private-association-at-key (associations key) (cond ((null associations) associations) ((eq (caar associations) key) (car associations)) (t (dictionary-private-association-at-key (cdr associations) key)))) (defmethod value-at-key ((self dictionary) key) (let ((assoc (dictionary-private-association-at-key (associations self) key))) (if (null assoc) assoc (cdr assoc)))) (defmethod association-at-key ((self dictionary) key) (dictionary-private-association-at-key (associations self) key)) (defmethod put-at-key ((self dictionary) key value) (let ((assoc (dictionary-private-association-at-key (associations self) key))) (cond ((null assoc) (setf (associations self) (cons (cons key value) (associations self)))) (t (rplacd assoc value))))) (defmethod contains-association? ((self dictionary) association) (member association (associations self))) (defmethod contains-key? ((self dictionary) key) (member key (mapcar 'car (associations self)))) (defmethod apply-to-associations ((self dictionary) func) (declare (type (function (cons) t) func)) (mapcar func (associations self))) ;;;; dictionary.lisp -- -- ;;;;
5,123
Common Lisp
.lisp
113
42.283186
156
0.63733
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
f8da8bc800c1111a2e477655a3125f9a443dcaa4ae887249c69df03dff6e8513
5,023
[ -1 ]
5,024
rfc2047.lisp
informatimago_lisp/common-lisp/obsolete-or-incomplete/rfc2047.lisp
;;;; -*- mode:lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: rfc2047.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Implements RFC2047 encoding and decoding. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2007-10-23 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2007 - 2016 ;;;; ;;;; 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/> ;;;;************************************************************************** (eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (copy-readtable nil))) (in-package "COMMON-LISP-USER") (declaim (declaration also-use-packages)) ;; (declaim (ALSO-USE-PACKAGES "COM.INFORMATIMAGO.COMMON-LISP.???")) (defpackage "COM.INFORMATIMAGO.COMMON-LISP.OBSOLETE-OR-INCOMPLEPTE.RFC2047" (:use "COMMON-LISP") (:export) (:documentation "Implements RFC2047 encoding and decoding. Copyright Pascal J. Bourguignon 2007 - 2007 This package is provided under the GNU General Public License. See the source file for details.")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.OBSOLETE-OR-INCOMPLEPTE.RFC2047") (defun encode (string &key (start 0) (end 0) (junk-allowed nil)) ) (defun decode (string) ) ;; Network Working Group K. Moore ;; Request for Comments: 2047 University of Tennessee ;; Obsoletes: 1521, 1522, 1590 November 1996 ;; Category: Standards Track ;; ;; ;; MIME (Multipurpose Internet Mail Extensions) Part Three: ;; Message Header Extensions for Non-ASCII Text ;; ;; Status of this Memo ;; ;; This document specifies an Internet standards track protocol for the ;; Internet community, and requests discussion and suggestions for ;; improvements. Please refer to the current edition of the "Internet ;; Official Protocol Standards" (STD 1) for the standardization state ;; and status of this protocol. Distribution of this memo is unlimited. ;; ;; Abstract ;; ;; STD 11, RFC 822, defines a message representation protocol specifying ;; considerable detail about US-ASCII message headers, and leaves the ;; message content, or message body, as flat US-ASCII text. This set of ;; documents, collectively called the Multipurpose Internet Mail ;; Extensions, or MIME, redefines the format of messages to allow for ;; ;; (1) textual message bodies in character sets other than US-ASCII, ;; ;; (2) an extensible set of different formats for non-textual message ;; bodies, ;; ;; (3) multi-part message bodies, and ;; ;; (4) textual header information in character sets other than US-ASCII. ;; ;; These documents are based on earlier work documented in RFC 934, STD ;; 11, and RFC 1049, but extends and revises them. Because RFC 822 said ;; so little about message bodies, these documents are largely ;; orthogonal to (rather than a revision of) RFC 822. ;; ;; This particular document is the third document in the series. It ;; describes extensions to RFC 822 to allow non-US-ASCII text data in ;; Internet mail header fields. ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; Moore Standards Track [Page 1] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; Other documents in this series include: ;; ;; + RFC 2045, which specifies the various headers used to describe ;; the structure of MIME messages. ;; ;; + RFC 2046, which defines the general structure of the MIME media ;; typing system and defines an initial set of media types, ;; ;; + RFC 2048, which specifies various IANA registration procedures ;; for MIME-related facilities, and ;; ;; + RFC 2049, which describes MIME conformance criteria and ;; provides some illustrative examples of MIME message formats, ;; acknowledgements, and the bibliography. ;; ;; These documents are revisions of RFCs 1521, 1522, and 1590, which ;; themselves were revisions of RFCs 1341 and 1342. An appendix in RFC ;; 2049 describes differences and changes from previous versions. ;; ;; 1. Introduction ;; ;; RFC 2045 describes a mechanism for denoting textual body parts which ;; are coded in various character sets, as well as methods for encoding ;; such body parts as sequences of printable US-ASCII characters. This ;; memo describes similar techniques to allow the encoding of non-ASCII ;; text in various portions of a RFC 822 [2] message header, in a manner ;; which is unlikely to confuse existing message handling software. ;; ;; Like the encoding techniques described in RFC 2045, the techniques ;; outlined here were designed to allow the use of non-ASCII characters ;; in message headers in a way which is unlikely to be disturbed by the ;; quirks of existing Internet mail handling programs. In particular, ;; some mail relaying programs are known to (a) delete some message ;; header fields while retaining others, (b) rearrange the order of ;; addresses in To or Cc fields, (c) rearrange the (vertical) order of ;; header fields, and/or (d) "wrap" message headers at different places ;; than those in the original message. In addition, some mail reading ;; programs are known to have difficulty correctly parsing message ;; headers which, while legal according to RFC 822, make use of ;; backslash-quoting to "hide" special characters such as "<", ",", or ;; ":", or which exploit other infrequently-used features of that ;; specification. ;; ;; While it is unfortunate that these programs do not correctly ;; interpret RFC 822 headers, to "break" these programs would cause ;; severe operational problems for the Internet mail system. The ;; extensions described in this memo therefore do not rely on little- ;; used features of RFC 822. ;; ;; ;; ;; Moore Standards Track [Page 2] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; Instead, certain sequences of "ordinary" printable ASCII characters ;; (known as "encoded-words") are reserved for use as encoded data. The ;; syntax of encoded-words is such that they are unlikely to ;; "accidentally" appear as normal text in message headers. ;; Furthermore, the characters used in encoded-words are restricted to ;; those which do not have special meanings in the context in which the ;; encoded-word appears. ;; ;; Generally, an "encoded-word" is a sequence of printable ASCII ;; characters that begins with "=?", ends with "?=", and has two "?"s in ;; between. It specifies a character set and an encoding method, and ;; also includes the original text encoded as graphic ASCII characters, ;; according to the rules for that encoding method. ;; ;; A mail composer that implements this specification will provide a ;; means of inputting non-ASCII text in header fields, but will ;; translate these fields (or appropriate portions of these fields) into ;; encoded-words before inserting them into the message header. ;; ;; A mail reader that implements this specification will recognize ;; encoded-words when they appear in certain portions of the message ;; header. Instead of displaying the encoded-word "as is", it will ;; reverse the encoding and display the original text in the designated ;; character set. ;; ;; NOTES ;; ;; This memo relies heavily on notation and terms defined RFC 822 and ;; RFC 2045. In particular, the syntax for the ABNF used in this memo ;; is defined in RFC 822, as well as many of the terminal or nonterminal ;; symbols from RFC 822 are used in the grammar for the header ;; extensions defined here. Among the symbols defined in RFC 822 and ;; referenced in this memo are: 'addr-spec', 'atom', 'CHAR', 'comment', ;; 'CTLs', 'ctext', 'linear-white-space', 'phrase', 'quoted-pair'. ;; 'quoted-string', 'SPACE', and 'word'. Successful implementation of ;; this protocol extension requires careful attention to the RFC 822 ;; definitions of these terms. ;; ;; When the term "ASCII" appears in this memo, it refers to the "7-Bit ;; American Standard Code for Information Interchange", ANSI X3.4-1986. ;; The MIME charset name for this character set is "US-ASCII". When not ;; specifically referring to the MIME charset name, this document uses ;; the term "ASCII", both for brevity and for consistency with RFC 822. ;; However, implementors are warned that the character set name must be ;; spelled "US-ASCII" in MIME message and body part headers. ;; ;; ;; ;; ;; ;; ;; Moore Standards Track [Page 3] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; This memo specifies a protocol for the representation of non-ASCII ;; text in message headers. It specifically DOES NOT define any ;; translation between "8-bit headers" and pure ASCII headers, nor is ;; any such translation assumed to be possible. ;; ;; 2. Syntax of encoded-words ;; ;; An 'encoded-word' is defined by the following ABNF grammar. The ;; notation of RFC 822 is used, with the exception that white space ;; characters MUST NOT appear between components of an 'encoded-word'. ;; ;; encoded-word = "=?" charset "?" encoding "?" encoded-text "?=" ;; ;; charset = token ; see section 3 ;; ;; encoding = token ; see section 4 ;; ;; token = 1*<Any CHAR except SPACE, CTLs, and especials> ;; ;; especials = "(" / ")" / "<" / ">" / "@" / "," / ";" / ":" / " ;; <"> / "/" / "[" / "]" / "?" / "." / "=" ;; ;; encoded-text = 1*<Any printable ASCII character other than "?" ;; or SPACE> ;; ; (but see "Use of encoded-words in message ;; ; headers", section 5) ;; ;; Both 'encoding' and 'charset' names are case-independent. Thus the ;; charset name "ISO-8859-1" is equivalent to "iso-8859-1", and the ;; encoding named "Q" may be spelled either "Q" or "q". ;; ;; An 'encoded-word' may not be more than 75 characters long, including ;; 'charset', 'encoding', 'encoded-text', and delimiters. If it is ;; desirable to encode more text than will fit in an 'encoded-word' of ;; 75 characters, multiple 'encoded-word's (separated by CRLF SPACE) may ;; be used. ;; ;; While there is no limit to the length of a multiple-line header ;; field, each line of a header field that contains one or more ;; 'encoded-word's is limited to 76 characters. ;; ;; The length restrictions are included both to ease interoperability ;; through internetwork mail gateways, and to impose a limit on the ;; amount of lookahead a header parser must employ (while looking for a ;; final ?= delimiter) before it can decide whether a token is an ;; "encoded-word" or something else. ;; ;; ;; ;; ;; ;; Moore Standards Track [Page 4] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; IMPORTANT: 'encoded-word's are designed to be recognized as 'atom's ;; by an RFC 822 parser. As a consequence, unencoded white space ;; characters (such as SPACE and HTAB) are FORBIDDEN within an ;; 'encoded-word'. For example, the character sequence ;; ;; =?iso-8859-1?q?this is some text?= ;; ;; would be parsed as four 'atom's, rather than as a single 'atom' (by ;; an RFC 822 parser) or 'encoded-word' (by a parser which understands ;; 'encoded-words'). The correct way to encode the string "this is some ;; text" is to encode the SPACE characters as well, e.g. ;; ;; =?iso-8859-1?q?this=20is=20some=20text?= ;; ;; The characters which may appear in 'encoded-text' are further ;; restricted by the rules in section 5. ;; ;; 3. Character sets ;; ;; The 'charset' portion of an 'encoded-word' specifies the character ;; set associated with the unencoded text. A 'charset' can be any of ;; the character set names allowed in an MIME "charset" parameter of a ;; "text/plain" body part, or any character set name registered with ;; IANA for use with the MIME text/plain content-type. ;; ;; Some character sets use code-switching techniques to switch between ;; "ASCII mode" and other modes. If unencoded text in an 'encoded-word' ;; contains a sequence which causes the charset interpreter to switch ;; out of ASCII mode, it MUST contain additional control codes such that ;; ASCII mode is again selected at the end of the 'encoded-word'. (This ;; rule applies separately to each 'encoded-word', including adjacent ;; 'encoded-word's within a single header field.) ;; ;; When there is a possibility of using more than one character set to ;; represent the text in an 'encoded-word', and in the absence of ;; private agreements between sender and recipients of a message, it is ;; recommended that members of the ISO-8859-* series be used in ;; preference to other character sets. ;; ;; 4. Encodings ;; ;; Initially, the legal values for "encoding" are "Q" and "B". These ;; encodings are described below. The "Q" encoding is recommended for ;; use when most of the characters to be encoded are in the ASCII ;; character set; otherwise, the "B" encoding should be used. ;; Nevertheless, a mail reader which claims to recognize 'encoded-word's ;; MUST be able to accept either encoding for any character set which it ;; supports. ;; ;; ;; ;; Moore Standards Track [Page 5] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; Only a subset of the printable ASCII characters may be used in ;; 'encoded-text'. Space and tab characters are not allowed, so that ;; the beginning and end of an 'encoded-word' are obvious. The "?" ;; character is used within an 'encoded-word' to separate the various ;; portions of the 'encoded-word' from one another, and thus cannot ;; appear in the 'encoded-text' portion. Other characters are also ;; illegal in certain contexts. For example, an 'encoded-word' in a ;; 'phrase' preceding an address in a From header field may not contain ;; any of the "specials" defined in RFC 822. Finally, certain other ;; characters are disallowed in some contexts, to ensure reliability for ;; messages that pass through internetwork mail gateways. ;; ;; The "B" encoding automatically meets these requirements. The "Q" ;; encoding allows a wide range of printable characters to be used in ;; non-critical locations in the message header (e.g., Subject), with ;; fewer characters available for use in other locations. ;; ;; 4.1. The "B" encoding ;; ;; The "B" encoding is identical to the "BASE64" encoding defined by RFC ;; 2045. ;; ;; 4.2. The "Q" encoding ;; ;; The "Q" encoding is similar to the "Quoted-Printable" content- ;; transfer-encoding defined in RFC 2045. It is designed to allow text ;; containing mostly ASCII characters to be decipherable on an ASCII ;; terminal without decoding. ;; ;; (1) Any 8-bit value may be represented by a "=" followed by two ;; hexadecimal digits. For example, if the character set in use ;; were ISO-8859-1, the "=" character would thus be encoded as ;; "=3D", and a SPACE by "=20". (Upper case should be used for ;; hexadecimal digits "A" through "F".) ;; ;; (2) The 8-bit hexadecimal value 20 (e.g., ISO-8859-1 SPACE) may be ;; represented as "_" (underscore, ASCII 95.). (This character may ;; not pass through some internetwork mail gateways, but its use ;; will greatly enhance readability of "Q" encoded data with mail ;; readers that do not support this encoding.) Note that the "_" ;; always represents hexadecimal 20, even if the SPACE character ;; occupies a different code position in the character set in use. ;; ;; (3) 8-bit values which correspond to printable ASCII characters other ;; than "=", "?", and "_" (underscore), MAY be represented as those ;; characters. (But see section 5 for restrictions.) In ;; particular, SPACE and TAB MUST NOT be represented as themselves ;; within encoded words. ;; ;; ;; ;; Moore Standards Track [Page 6] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; 5. Use of encoded-words in message headers ;; ;; An 'encoded-word' may appear in a message header or body part header ;; according to the following rules: ;; ;; (1) An 'encoded-word' may replace a 'text' token (as defined by RFC 822) ;; in any Subject or Comments header field, any extension message ;; header field, or any MIME body part field for which the field body ;; is defined as '*text'. An 'encoded-word' may also appear in any ;; user-defined ("X-") message or body part header field. ;; ;; Ordinary ASCII text and 'encoded-word's may appear together in the ;; same header field. However, an 'encoded-word' that appears in a ;; header field defined as '*text' MUST be separated from any adjacent ;; 'encoded-word' or 'text' by 'linear-white-space'. ;; ;; (2) An 'encoded-word' may appear within a 'comment' delimited by "(" and ;; ")", i.e., wherever a 'ctext' is allowed. More precisely, the RFC ;; 822 ABNF definition for 'comment' is amended as follows: ;; ;; comment = "(" *(ctext / quoted-pair / comment / encoded-word) ")" ;; ;; A "Q"-encoded 'encoded-word' which appears in a 'comment' MUST NOT ;; contain the characters "(", ")" or " ;; 'encoded-word' that appears in a 'comment' MUST be separated from ;; any adjacent 'encoded-word' or 'ctext' by 'linear-white-space'. ;; ;; It is important to note that 'comment's are only recognized inside ;; "structured" field bodies. In fields whose bodies are defined as ;; '*text', "(" and ")" are treated as ordinary characters rather than ;; comment delimiters, and rule (1) of this section applies. (See RFC ;; 822, sections 3.1.2 and 3.1.3) ;; ;; (3) As a replacement for a 'word' entity within a 'phrase', for example, ;; one that precedes an address in a From, To, or Cc header. The ABNF ;; definition for 'phrase' from RFC 822 thus becomes: ;; ;; phrase = 1*( encoded-word / word ) ;; ;; In this case the set of characters that may be used in a "Q"-encoded ;; 'encoded-word' is restricted to: <upper and lower case ASCII ;; letters, decimal digits, "!", "*", "+", "-", "/", "=", and "_" ;; (underscore, ASCII 95.)>. An 'encoded-word' that appears within a ;; 'phrase' MUST be separated from any adjacent 'word', 'text' or ;; 'special' by 'linear-white-space'. ;; ;; ;; ;; ;; ;; ;; Moore Standards Track [Page 7] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; These are the ONLY locations where an 'encoded-word' may appear. In ;; particular: ;; ;; + An 'encoded-word' MUST NOT appear in any portion of an 'addr-spec'. ;; ;; + An 'encoded-word' MUST NOT appear within a 'quoted-string'. ;; ;; + An 'encoded-word' MUST NOT be used in a Received header field. ;; ;; + An 'encoded-word' MUST NOT be used in parameter of a MIME ;; Content-Type or Content-Disposition field, or in any structured ;; field body except within a 'comment' or 'phrase'. ;; ;; The 'encoded-text' in an 'encoded-word' must be self-contained; ;; 'encoded-text' MUST NOT be continued from one 'encoded-word' to ;; another. This implies that the 'encoded-text' portion of a "B" ;; 'encoded-word' will be a multiple of 4 characters long; for a "Q" ;; 'encoded-word', any "=" character that appears in the 'encoded-text' ;; portion will be followed by two hexadecimal characters. ;; ;; Each 'encoded-word' MUST encode an integral number of octets. The ;; 'encoded-text' in each 'encoded-word' must be well-formed according ;; to the encoding specified; the 'encoded-text' may not be continued in ;; the next 'encoded-word'. (For example, "=?charset?Q?=?= ;; =?charset?Q?AB?=" would be illegal, because the two hex digits "AB" ;; must follow the "=" in the same 'encoded-word'.) ;; ;; Each 'encoded-word' MUST represent an integral number of characters. ;; A multi-octet character may not be split across adjacent 'encoded- ;; word's. ;; ;; Only printable and white space character data should be encoded using ;; this scheme. However, since these encoding schemes allow the ;; encoding of arbitrary octet values, mail readers that implement this ;; decoding should also ensure that display of the decoded data on the ;; recipient's terminal will not cause unwanted side-effects. ;; ;; Use of these methods to encode non-textual data (e.g., pictures or ;; sounds) is not defined by this memo. Use of 'encoded-word's to ;; represent strings of purely ASCII characters is allowed, but ;; discouraged. In rare cases it may be necessary to encode ordinary ;; text that looks like an 'encoded-word'. ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; Moore Standards Track [Page 8] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; 6. Support of 'encoded-word's by mail readers ;; ;; 6.1. Recognition of 'encoded-word's in message headers ;; ;; A mail reader must parse the message and body part headers according ;; to the rules in RFC 822 to correctly recognize 'encoded-word's. ;; ;; 'encoded-word's are to be recognized as follows: ;; ;; (1) Any message or body part header field defined as '*text', or any ;; user-defined header field, should be parsed as follows: Beginning ;; at the start of the field-body and immediately following each ;; occurrence of 'linear-white-space', each sequence of up to 75 ;; printable characters (not containing any 'linear-white-space') ;; should be examined to see if it is an 'encoded-word' according to ;; the syntax rules in section 2. Any other sequence of printable ;; characters should be treated as ordinary ASCII text. ;; ;; (2) Any header field not defined as '*text' should be parsed ;; according to the syntax rules for that header field. However, ;; any 'word' that appears within a 'phrase' should be treated as an ;; 'encoded-word' if it meets the syntax rules in section 2. ;; Otherwise it should be treated as an ordinary 'word'. ;; ;; (3) Within a 'comment', any sequence of up to 75 printable characters ;; (not containing 'linear-white-space'), that meets the syntax ;; rules in section 2, should be treated as an 'encoded-word'. ;; Otherwise it should be treated as normal comment text. ;; ;; (4) A MIME-Version header field is NOT required to be present for ;; 'encoded-word's to be interpreted according to this ;; specification. One reason for this is that the mail reader is ;; not expected to parse the entire message header before displaying ;; lines that may contain 'encoded-word's. ;; ;; 6.2. Display of 'encoded-word's ;; ;; Any 'encoded-word's so recognized are decoded, and if possible, the ;; resulting unencoded text is displayed in the original character set. ;; ;; NOTE: Decoding and display of encoded-words occurs *after* a ;; structured field body is parsed into tokens. It is therefore ;; possible to hide 'special' characters in encoded-words which, when ;; displayed, will be indistinguishable from 'special' characters in the ;; surrounding text. For this and other reasons, it is NOT generally ;; possible to translate a message header containing 'encoded-word's to ;; an unencoded form which can be parsed by an RFC 822 mail reader. ;; ;; ;; ;; ;; Moore Standards Track [Page 9] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; When displaying a particular header field that contains multiple ;; 'encoded-word's, any 'linear-white-space' that separates a pair of ;; adjacent 'encoded-word's is ignored. (This is to allow the use of ;; multiple 'encoded-word's to represent long strings of unencoded text, ;; without having to separate 'encoded-word's where spaces occur in the ;; unencoded text.) ;; ;; In the event other encodings are defined in the future, and the mail ;; reader does not support the encoding used, it may either (a) display ;; the 'encoded-word' as ordinary text, or (b) substitute an appropriate ;; message indicating that the text could not be decoded. ;; ;; If the mail reader does not support the character set used, it may ;; (a) display the 'encoded-word' as ordinary text (i.e., as it appears ;; in the header), (b) make a "best effort" to display using such ;; characters as are available, or (c) substitute an appropriate message ;; indicating that the decoded text could not be displayed. ;; ;; If the character set being used employs code-switching techniques, ;; display of the encoded text implicitly begins in "ASCII mode". In ;; addition, the mail reader must ensure that the output device is once ;; again in "ASCII mode" after the 'encoded-word' is displayed. ;; ;; 6.3. Mail reader handling of incorrectly formed 'encoded-word's ;; ;; It is possible that an 'encoded-word' that is legal according to the ;; syntax defined in section 2, is incorrectly formed according to the ;; rules for the encoding being used. For example: ;; ;; (1) An 'encoded-word' which contains characters which are not legal ;; for a particular encoding (for example, a "-" in the "B" ;; encoding, or a SPACE or HTAB in either the "B" or "Q" encoding), ;; is incorrectly formed. ;; ;; (2) Any 'encoded-word' which encodes a non-integral number of ;; characters or octets is incorrectly formed. ;; ;; A mail reader need not attempt to display the text associated with an ;; 'encoded-word' that is incorrectly formed. However, a mail reader ;; MUST NOT prevent the display or handling of a message because an ;; 'encoded-word' is incorrectly formed. ;; ;; 7. Conformance ;; ;; A mail composing program claiming compliance with this specification ;; MUST ensure that any string of non-white-space printable ASCII ;; characters within a '*text' or '*ctext' that begins with "=?" and ;; ends with "?=" be a valid 'encoded-word'. ("begins" means: at the ;; ;; ;; ;; Moore Standards Track [Page 10] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; start of the field-body, immediately following 'linear-white-space', ;; or immediately following a "(" for an 'encoded-word' within '*ctext'; ;; "ends" means: at the end of the field-body, immediately preceding ;; 'linear-white-space', or immediately preceding a ")" for an ;; 'encoded-word' within '*ctext'.) In addition, any 'word' within a ;; 'phrase' that begins with "=?" and ends with "?=" must be a valid ;; 'encoded-word'. ;; ;; A mail reading program claiming compliance with this specification ;; must be able to distinguish 'encoded-word's from 'text', 'ctext', or ;; 'word's, according to the rules in section 6, anytime they appear in ;; appropriate places in message headers. It must support both the "B" ;; and "Q" encodings for any character set which it supports. The ;; program must be able to display the unencoded text if the character ;; set is "US-ASCII". For the ISO-8859-* character sets, the mail ;; reading program must at least be able to display the characters which ;; are also in the ASCII set. ;; ;; 8. Examples ;; ;; The following are examples of message headers containing 'encoded- ;; word's: ;; ;; From: =?US-ASCII?Q?Keith_Moore?= <[email protected]> ;; To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <[email protected]> ;; CC: =?ISO-8859-1?Q?Andr=E9?= Pirard <[email protected]> ;; Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= ;; =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?= ;; ;; Note: In the first 'encoded-word' of the Subject field above, the ;; last "=" at the end of the 'encoded-text' is necessary because each ;; 'encoded-word' must be self-contained (the "=" character completes a ;; group of 4 base64 characters representing 2 octets). An additional ;; octet could have been encoded in the first 'encoded-word' (so that ;; the encoded-word would contain an exact multiple of 3 encoded ;; octets), except that the second 'encoded-word' uses a different ;; 'charset' than the first one. ;; ;; From: =?ISO-8859-1?Q?Olle_J=E4rnefors?= <[email protected]> ;; To: [email protected], [email protected] ;; Subject: Time for ISO 10646? ;; ;; To: Dave Crocker <[email protected]> ;; Cc: [email protected], [email protected] ;; From: =?ISO-8859-1?Q?Patrik_F=E4ltstr=F6m?= <[email protected]> ;; Subject: Re: RFC-HDR care and feeding ;; ;; ;; ;; ;; ;; Moore Standards Track [Page 11] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; From: Nathaniel Borenstein <[email protected]> ;; (=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=) ;; To: Greg Vaudreuil <[email protected]>, Ned Freed ;; <[email protected]>, Keith Moore <[email protected]> ;; Subject: Test of new header generator ;; MIME-Version: 1.0 ;; Content-type: text/plain; charset=ISO-8859-1 ;; ;; The following examples illustrate how text containing 'encoded-word's ;; which appear in a structured field body. The rules are slightly ;; different for fields defined as '*text' because "(" and ")" are not ;; recognized as 'comment' delimiters. [Section 5, paragraph (1)]. ;; ;; In each of the following examples, if the same sequence were to occur ;; in a '*text' field, the "displayed as" form would NOT be treated as ;; encoded words, but be identical to the "encoded form". This is ;; because each of the encoded-words in the following examples is ;; adjacent to a "(" or ")" character. ;; ;; encoded form displayed as ;; --------------------------------------------------------------------- ;; (=?ISO-8859-1?Q?a?=) (a) ;; ;; (=?ISO-8859-1?Q?a?= b) (a b) ;; ;; Within a 'comment', white space MUST appear between an ;; 'encoded-word' and surrounding text. [Section 5, ;; paragraph (2)]. However, white space is not needed between ;; the initial "(" that begins the 'comment', and the ;; 'encoded-word'. ;; ;; ;; (=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=) (ab) ;; ;; White space between adjacent 'encoded-word's is not ;; displayed. ;; ;; (=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=) (ab) ;; ;; Even multiple SPACEs between 'encoded-word's are ignored ;; for the purpose of display. ;; ;; (=?ISO-8859-1?Q?a?= (ab) ;; =?ISO-8859-1?Q?b?=) ;; ;; Any amount of linear-space-white between 'encoded-word's, ;; even if it includes a CRLF followed by one or more SPACEs, ;; is ignored for the purposes of display. ;; ;; ;; ;; Moore Standards Track [Page 12] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; (=?ISO-8859-1?Q?a_b?=) (a b) ;; ;; In order to cause a SPACE to be displayed within a portion ;; of encoded text, the SPACE MUST be encoded as part of the ;; 'encoded-word'. ;; ;; (=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=) (a b) ;; ;; In order to cause a SPACE to be displayed between two strings ;; of encoded text, the SPACE MAY be encoded as part of one of ;; the 'encoded-word's. ;; ;; 9. References ;; ;; [RFC 822] Crocker, D., "Standard for the Format of ARPA Internet Text ;; Messages", STD 11, RFC 822, UDEL, August 1982. ;; ;; [RFC 2049] Borenstein, N., and N. Freed, "Multipurpose Internet Mail ;; Extensions (MIME) Part Five: Conformance Criteria and Examples", ;; RFC 2049, November 1996. ;; ;; [RFC 2045] Borenstein, N., and N. Freed, "Multipurpose Internet Mail ;; Extensions (MIME) Part One: Format of Internet Message Bodies", ;; RFC 2045, November 1996. ;; ;; [RFC 2046] Borenstein N., and N. Freed, "Multipurpose Internet Mail ;; Extensions (MIME) Part Two: Media Types", RFC 2046, ;; November 1996. ;; ;; [RFC 2048] Freed, N., Klensin, J., and J. Postel, "Multipurpose ;; Internet Mail Extensions (MIME) Part Four: Registration ;; Procedures", RFC 2048, November 1996. ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; Moore Standards Track [Page 13] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; 10. Security Considerations ;; ;; Security issues are not discussed in this memo. ;; ;; 11. Acknowledgements ;; ;; The author wishes to thank Nathaniel Borenstein, Issac Chan, Lutz ;; Donnerhacke, Paul Eggert, Ned Freed, Andreas M. Kirchwitz, Olle ;; Jarnefors, Mike Rosin, Yutaka Sato, Bart Schaefer, and Kazuhiko ;; Yamamoto, for their helpful advice, insightful comments, and ;; illuminating questions in response to earlier versions of this ;; specification. ;; ;; 12. Author's Address ;; ;; Keith Moore ;; University of Tennessee ;; 107 Ayres Hall ;; Knoxville TN 37996-1301 ;; ;; EMail: [email protected] ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; Moore Standards Track [Page 14] ;; ;; RFC 2047 Message Header Extensions November 1996 ;; ;; ;; Appendix - changes since RFC 1522 (in no particular order) ;; ;; + explicitly state that the MIME-Version is not requried to use ;; 'encoded-word's. ;; ;; + add explicit note that SPACEs and TABs are not allowed within ;; 'encoded-word's, explaining that an 'encoded-word' must look like an ;; 'atom' to an RFC822 parser.values, to be precise). ;; ;; + add examples from Olle Jarnefors (thanks!) which illustrate how ;; encoded-words with adjacent linear-white-space are displayed. ;; ;; + explicitly list terms defined in RFC822 and referenced in this memo ;; ;; + fix transcription typos that caused one or two lines and a couple of ;; characters to disappear in the resulting text, due to nroff quirks. ;; ;; + clarify that encoded-words are allowed in '*text' fields in both ;; RFC822 headers and MIME body part headers, but NOT as parameter ;; values. ;; ;; + clarify the requirement to switch back to ASCII within the encoded ;; portion of an 'encoded-word', for any charset that uses code switching ;; sequences. ;; ;; + add a note about 'encoded-word's being delimited by "(" and ")" ;; within a comment, but not in a *text (how bizarre!). ;; ;; + fix the Andre Pirard example to get rid of the trailing "_" after ;; the =E9. (no longer needed post-1342). ;; ;; + clarification: an 'encoded-word' may appear immediately following ;; the initial "(" or immediately before the final ")" that delimits a ;; comment, not just adjacent to "(" and ")" *within* *ctext. ;; ;; + add a note to explain that a "B" 'encoded-word' will always have a ;; multiple of 4 characters in the 'encoded-text' portion. ;; ;; + add note about the "=" in the examples ;; ;; + note that processing of 'encoded-word's occurs *after* parsing, and ;; some of the implications thereof. ;; ;; + explicitly state that you can't expect to translate between ;; 1522 and either vanilla 822 or so-called "8-bit headers". ;; ;; + explicitly state that 'encoded-word's are not valid within a ;; 'quoted-string'. ;; ;; ;; ;; Moore Standards Track [Page 15] ;; ;;;; THE END ;;;;
37,605
Common Lisp
.lisp
889
41.221597
83
0.661635
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
94a320ae7c303964e81bc3547d89584935d9488e9f5452c8a62763359c5964da
5,024
[ -1 ]
5,025
isbn.lisp
informatimago_lisp/common-lisp/obsolete-or-incomplete/isbn.lisp
;;;; -*- coding:utf-8 -*- ;;;;*************************************************************************** ;;;;FILE: isbn.lisp ;;;;LANGUAGE: Common-Lisp ;;;;SYSTEM: Common-Lisp ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; Compute ISBN check digit. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <[email protected]> ;;;;MODIFICATIONS ;;;; 2004-08-28 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; AGPL3 ;;;; ;;;; Copyright Pascal J. Bourguignon 2004 - 2016 ;;;; ;;;; 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/> ;;;;*************************************************************************** (in-package "COMMON-LISP-USER") (defpackage "COM.INFORMATIMAGO.COMMON-LISP.OBSOLETE-OR-INCOMPLEPTE.ISBN" (:use "COMMON-LISP") (:export "COMPUTE-ISBN-CHECK") (:documentation " Compute ISBN check digit. Copyright Pascal J. Bourguignon 2004 - 2004 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ")) (in-package "COM.INFORMATIMAGO.COMMON-LISP.OBSOLETE-OR-INCOMPLEPTE.ISBN") (defun compute-isbn-check (isbn) (when (or (not (stringp isbn)) (/= 9 (length isbn)) (not (every (function digit-char-p) isbn))) (error "An ISBN must be a string of 9 digits.")) (aref "0123456789X" (- 11 (mod (reduce (function +) (mapcar (function *) (map 'list (lambda (ch) (parse-integer (string ch))) isbn) '(10 9 8 7 6 5 4 3 2))) 11))));;COMPUTE-ISBN-CHECK (defun test () (assert (char= #\4 (compute-isbn-check "052135938")))) ;;;; isbn.lisp -- -- ;;;;
2,676
Common Lisp
.lisp
63
36.968254
83
0.561828
informatimago/lisp
20
6
0
AGPL-3.0
9/19/2024, 11:26:28 AM (Europe/Amsterdam)
c0c294de7f3b884c52d08bb81f372062e3f20ba0c20c5b0fd93cba75e5b8666f
5,025
[ -1 ]