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
sequencelengths
1
47
35,971
gdl2xml.lisp
lisp-mirror_gendl/apps/translators/xml/source/gdl2xml.lisp
;; ;; Copyright 2002, 2009, 2012 Genworks International and Genworks BV ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdlxml) (define-object gdl2xml (definition-tree) :input-slots (name-symbol (output-file (merge-pathnames (format nil "~a.xml" (string (the name-symbol))) (glisp:temporary-folder)))) :computed-slots ((xml-string (with-output-to-string(ss) (with-format (xml ss) (write-the gdlxml)))) (slot-plists (let (result) (dolist (section (list-elements (the sections)) (nreverse result)) (dolist (message (list-elements (the-object section messages))) (let ((section-key (the-object message section-key)) (keyword (the-object message key)) (source-code-body (the-object message source-code-body)) (source-code-argument-list (the-object message source-code-argument-list)) (remark-string (the-object message remark-string)) (modifiers (the-object message modifiers))) (let ((object? (member section-key (list :objects :hidden-objects))) (*package* (the object-package))) (push (append (list :section-key (format nil "~a" section-key) :keyword (format nil "~a" keyword) :default (unless object? (when source-code-body (format nil "~s" source-code-body))) :argument-list (when source-code-argument-list (format nil "~s" source-code-argument-list)) :remark-string (when remark-string (format nil "~a" remark-string)) :type (when object? (format nil "~s" (getf source-code-body :type))) :sequence (when (and object? (getf source-code-body :sequence)) (format nil "~s" (getf source-code-body :sequence))) :pass-down (when (and object? (getf source-code-body :pass-down)) (format nil "~s" (getf source-code-body :pass-down))) :inputs (when object? (remove-plist-keys source-code-body (list :type :sequence :pass-down)))) (mapcan #'(lambda(modifier) (list modifier (format nil "~a" modifier))) modifiers)) result))))))) (mixin-lists (let ((*package* (the object-package))) (mapcar #'(lambda(mixin) `(:mixin :name ,(format nil "~s" mixin))) (the mixin-data)))) (lxml `((:gdlxml :package ,(package-name (the object-package))) ((:define-object :name ,(string (the name-symbol))) (:documentation ,@(mapcan #'(lambda(key value) (list key `(escape-string ,value))) (plist-keys (the object-documentation)) (plist-values (the object-documentation)))) (:mixins ,@(the mixin-lists)) (:slots ,@(mapcar #'(lambda(slot-plist) (if (getf slot-plist :type) `((:slot ,@(mapcan #'(lambda(key) (let ((value (getf slot-plist key))) `(,key ,(when value `(escape-string ,value))))) (list :section-key :keyword :remark-string :type :sequence :pass-down))) (:inputs ,@(mapcar #'(lambda(key value) `(:input :keyword (escape-string ,(string key)) :default (escape-string ,(format nil "~s" value)))) (plist-keys (getf slot-plist :inputs)) (plist-values (getf slot-plist :inputs))))) `(:slot ,@(mapcan #'(lambda(key) (let ((value (getf slot-plist key))) `(,key ,(when value `(escape-string ,value))))) (list :section-key :keyword :default :argument-list :remark-string :settable :defaulting))))) (the slot-plists))))))) :functions ((write-xml-file! (&key (output-file (the output-file))) (with-open-file (out output-file :direction :output :if-exists :supersede :if-does-not-exist :create) (write-string (the xml-string) out) (values))))) (define-format xml (base-format)) (define-lens (xml definition-tree)() :output-functions ((gdlxml () ;; ;; FLAG be on the lookout for an alternative to this use of eval ;; (eval `(cl-who:with-html-output (*stream* nil :indent t) ,(the lxml)))))) (defun gdl2xml (name-symbol &key (output-file (format nil "/tmp/~a.xml" (string name-symbol)))) "Void. Emits an XML file representing the object definition named by name-symbol. The outputted file will be named after the name symbol (default is /tmp/[name].xml where [name] is the symbol name given). :arguments (name-symbol \"Symbol. This quoted symbol must name an already-defined GDL object.\") :&key ((output-file \"/tmp/[symbol-name].xml\") \"string or pathname naming the desired output file\")" (the-object (make-object 'gdl2xml :name-symbol name-symbol :output-file output-file) (write-xml-file!)))
5,453
Common Lisp
.lisp
112
42
117
0.653875
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
8d1a6c57f450ac6007981aade0c75c04024f2d66525f8ff34ba49ede58bcac7a
35,971
[ -1 ]
35,972
assembly.lisp
lisp-mirror_gendl/apps/timer/source/assembly.lisp
(in-package :timer-journaler) (define-object journal-entry () :input-slots ((name nil :settable) ; name of the user (email nil :settable) ; email of the user (time-set nil :settable) ; amount of time timer was set for (universal-time-start nil :settable) ; actual time timer was started (universal-time-end nil :settable) ; actual time timer ended (content nil :settable)) ; content of the journal :computed-slots ((duration (when (and (the universal-time-start) (the universal-time-end)) (- (the universal-time-end)(the universal-time-start)))) (pause-time (when (and (the time-set) (the duration)) (- (the duration) (the time-set)))) (inner-html (with-cl-who-string () (when (the universal-time-start) (htm ((:div :class "journal-time") (fmt "Started: ~a" (iso-8601-date (the universal-time-start) :include-time? t))))) (when (the universal-time-end) (htm ((:div :class "journal-time") (fmt "Finished: ~a" (iso-8601-date (the universal-time-end) :include-time? t))))) (when (the time-set) (htm ((:div :class "journal-time") (fmt "Planned Duration: ~a:~a" (floor (/ (the time-set) 60)) (mod (the time-set) 60))))) (when (the duration) (htm ((:div :class "journal-time") (fmt "Actual Duration: ~a:~a" (floor (/ (the duration) 60)) (mod (the duration) 60))))) (when (the pause-time) (htm ((:div :class "journal-time") (fmt "Total Pause Time: ~a:~a" (floor (/ (the pause-time) 60)) (mod (the pause-time) 60))))) (when (the content) (htm ((:div :class "journal-descr") (fmt "~a" (the content))))))))) (define-object assembly (background-timer-mixin base-ajax-sheet) :input-slots ((timer-minutes-default 0) (timer-seconds-default 3)) :computed-slots ((use-jquery? t) (current-journal-entry nil :settable) (timer-paused? nil :settable) (title "Genworks Timer and Journaler") (main-sheet-body (with-cl-who-string () (when gwl:*developing?* (str (the development-links))) ((:script :type "text/javascript") "$(window).focus(function() { timerStart(); // console.log('welcome (back)'); }); $(window).blur(function() { console.log('bye bye'); });") ((:div :id "content") (str (the ajax-scripts-section main-div)) (str (the imported-scripts)) ((:h1 :id "header") "timer") (str (the timer-form main-div)) (str (the journal-form main-div)) ((:ul :id "journal") (str (the journal-entries-display main-div)))))) (additional-header-content (with-cl-who-string () (:link :href "/timer-static/style/styles.css" :rel "stylesheet" :type "text/css"))) (imported-scripts (with-cl-who-string () ;;(:script :src "https://code.jquery.com/jquery-2.1.4.min.js") ;;(:script :src "/timer-static/plugins/hideseek/jquery.hideseek.min.js") (:script :src "/timer-static/scripts.js") ;;(:script :src "/timer-static/jq-scripts.js") )) (journal-recordable? (and (not (the timer-paused?)) (zerop (the background-minutes)) (zerop (the background-seconds)) (the current-journal-entry)))) :objects ((entries :type 'journal-entry :sequence (:indices nil)) (timer-form-min :type 'text-form-control :domain :number :id "minutes" :size 2 :default (format nil "~2,'0d" (the timer-default-form-min value))) (timer-form-sec :type 'text-form-control :domain :number :id "seconds" :size 2 :default (format nil "~2,'0d" (the timer-default-form-sec value))) (timer-default-form-min :type 'text-form-control :ajax-submit-on-change? t :id "default-minutes" :size 2 :default (format nil "~a" (the timer-minutes-default))) (timer-default-form-sec :type 'text-form-control :ajax-submit-on-change? t :id "default-seconds" :size 2 :default (format nil "~2,'0d" (the timer-seconds-default))) (name-form :type 'text-form-control :default "Name" :id "user-name") (email-form :type 'text-form-control :default "Email" :id "user-email") (journal-entry-form :type 'text-form-control :default "Description of task" :id "journal-entry") (timer-start-button :type 'button-form-control :onclick "timerStart();" :label (if (the timer-paused?) "Restart" "Start")) (timer-pause-button :type 'button-form-control :onclick "timerPause();" :label "Pause") (timer-reset-button :type 'button-form-control :onclick "timerReset();" :label "Reset") (record-journal-button :type 'button-form-control :onclick "recordJournal();" :label "Record") (ajax-scripts-section :type 'sheet-section :inner-html (with-cl-who-string () ((:script :type "text/javascript") "function visibilityChanged () {if !(document.hidden) {alert('vis. changed not hidden event')}};" (fmt "function startTimerAjax () {~a}" (the (gdl-ajax-call :null-event? t :form-controls (list (the timer-form-min) (the timer-form-sec)) :function-key :start-timer-tasks))) (fmt "function recordJournalAjax () {~a}" (the (gdl-ajax-call :form-controls (list (the journal-entry-form)) :function-key :record-journal-entry))) (fmt "function pauseTimerAjax () {~a}" (the (gdl-ajax-call :function-key :pause-timer-tasks))) (fmt "function resetTimerAjax () {~a}" (the (gdl-ajax-call :function-key :reset-timer-tasks))) (fmt "function endTimerAjax () {~a}" (the (gdl-ajax-call :function-key :end-timer-tasks)))))) (journal-entries-display :type 'sheet-section :inner-html (with-cl-who-string () (:ul (dolist (entry (reverse (list-elements (the entries)))) (htm ((:li :class "journal-entry") (str (the-object entry inner-html)))))))) (timer-form :type 'sheet-section :inner-html (with-cl-who-string () "Timer" (:br) (str (the timer-form-min form-control-string)) ":" (str (the timer-form-sec form-control-string)) (:br) (when (or (not (the current-journal-entry)) (the timer-paused?)) (str (the timer-start-button form-control-string))) (when (and (the current-journal-entry) (not (the timer-paused?)) (not (the journal-recordable?))) (str (the timer-pause-button form-control-string))))) (journal-form :type 'sheet-section :inner-html (with-cl-who-string () (when (the journal-recordable?) (str (the journal-entry-form form-control-string)) (str (the record-journal-button form-control-string)))))) :functions ((start-timer-tasks () (if (the timer-paused?) (the (set-slot! :timer-paused? nil)) (let* ((name (the name-form value)) (gensym (subseq (write-to-string (gensym)) 2)) (universal-time (get-universal-time)) (start-minutes (the timer-form-min value)) (start-seconds (the timer-form-sec value)) (index (make-keyword (string-append name "-" gensym "-" (write-to-string universal-time))))) (the entries (insert! index)) (the (entries index) (set-slots! (list :name name :email (the email-form value) :time-set (+ (* start-minutes 60) start-seconds) :universal-time-start universal-time))) (the (set-slot! :current-journal-entry (the (entries index)))) (the timer-default-form-min (set-slot! :value start-minutes)) (the timer-default-form-sec (set-slot! :value start-seconds)))) (the start-background-timer)) (end-timer-tasks () (the current-journal-entry (set-slot! :universal-time-end (get-universal-time))) (the zero!)) ;; ;; FLAG -- split this into separate drift-check and zeroing of the values. ;; (zero! () (unless (and (zerop (the timer-form-min value)) (<= (the timer-form-sec value) 1)) (warn "Web page timer and background timer have drifted more than one second: ~a:~a~%" (the timer-form-min value) (the timer-form-sec))) (the timer-form-min (set-slot! :value 0)) (the timer-form-sec (set-slot! :value 0))) (pause-timer-tasks () (the timer-form-sec (set-slot! :value (the background-seconds))) (the timer-form-min (set-slot! :value (the background-minutes))) (the cancel-background-timer) (the (set-slot! :timer-paused? t))) (reset-timer-tasks () (the timer-form-min restore-defaults!) (the timer-form-sec restore-defaults!) (the cancel-background-timer) (when (the current-journal-entry) (the entries (delete! (the current-journal-entry index))) (the (restore-slot-default! :current-journal-entry)))) (record-journal-entry () (when (the journal-recordable?) (the current-journal-entry (set-slot! :content (the journal-entry-form value))) (the (restore-slot-default! :current-journal-entry)) (the reset-timer-tasks)))))
9,072
Common Lisp
.lisp
201
38.621891
102
0.633832
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
54d4c877ff4bfb1621ad2b780f0a416ab84f39503eb1b9d3aaf8635350cfaa98
35,972
[ -1 ]
35,973
background-timer.lisp
lisp-mirror_gendl/apps/timer/source/background-timer.lisp
(in-package :timer-journaler) (define-object background-timer-mixin () :computed-slots ((background-seconds 0 :settable) (background-minutes 0 :settable) (background-timer-thread nil :settable)) :functions ((timer-finished () (sleep 0.2) (format t "~&~%Timer Finished. Background-minutes: ~a Background-seconds: ~a Form-minutes: ~a Form-seconds: ~a " (the background-minutes) (the background-seconds) (the timer-form-min value) (the timer-form-sec value)) (sleep 120) (cl-smtp:send-email *smtp-server* "[email protected]" "[email protected]" "Journal Entry needed" (format nil "Dear Citizen, Your latest time unit has expired and no journal entry has been received. Please take care of this matter immediately at the following location: http://genworks.com~a Regards, Bureau of Records Enforcement The Ministry of Time " (the url)))) (cancel-background-timer () (when (the background-timer-thread) (bt:destroy-thread (the background-timer-thread))) (the (restore-slot-defaults! (list :background-timer-thread :background-minutes :background-seconds)))) (start-background-timer () (when (the background-timer-thread) (warn "Background timer already running. Terminating...~%") (the cancel-background-timer)) (the (set-slots! (list :background-seconds (the timer-form-sec value) :background-minutes (the timer-form-min value)))) (format t "~&~%Starting Background Timer, min: ~a, sec: ~a~%~%" (the background-minutes) (the background-seconds)) (let ((thread (bt:make-thread #'(lambda() (let ((real-time (get-internal-real-time))) (do () ((and (zerop (the background-minutes)) (zerop (the background-seconds))) (the timer-finished)) (sleep (/ (- 1000 (- (get-internal-real-time) real-time)) 1000)) (setq real-time (get-internal-real-time)) (let ((seconds (1- (the background-seconds)))) (if (= seconds -1) (the (set-slots! (list :background-seconds 59 :background-minutes (1- (the background-minutes))))) (the (set-slot! :background-seconds seconds)))) (the timer-form-min (set-slot! :value (the background-minutes))) (the timer-form-sec (set-slot! :value (the background-seconds))) (when *debug?* (format t "~&~%Background Timer woke up, min: ~a, sec: ~a~%~%" (the background-minutes) (the background-seconds)))))) :name "Background timer"))) (the (set-slot! :background-timer-thread thread :remember? nil)))))) ;; ;; FLAG -- for debug use only. ;; (defun kill-bt () (let ((threads (remove-if-not #'(lambda(proc) (string-equal (bt:thread-name proc) "Background timer")) (bt:all-threads)))) (mapc #'bt:destroy-thread threads)))
2,901
Common Lisp
.lisp
76
32.394737
124
0.662799
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
6643127123e9b2d5d32d38c1823b873132492da8bd990d6f4492e61b57e13b0b
35,973
[ -1 ]
35,974
assembly-cherie.lisp
lisp-mirror_gendl/apps/timer/source/assembly-cherie.lisp
(in-package :timer-journaler) (define-object journal-entry () :input-slots ((name "" :settable) ; name of the user (email "" :settable) ; email of the user (time-set "" :settable) ; amount of time timer was set for (universal-time-start 0 :settable) ; actual time timer was started (universal-time-end 0 :settable) ; actual time timer ended (content "" :settable)) ; content of the journal :computed-slots ((id ; unique identifier for this journal entry (concatenate 'string (the name) (write-to-string (the universal-time-start)))) (time-elapsed ; actual amount of time elapsed (decode-universal-time (- (the universal-time-end) (the universal-time-start))))) :functions ; Creates the string serialization of the journal entry. ((to-serialization () (write-to-string (list (the name) (the email) (the time-set) (the universal-time-start) (the universal-time-end) (the content) (the id)) :readably t)) ; Reads from the serialization of the journal entry. ; Populates the fields of this journal entry object. (from-serialization (serialized-string) (let ((deserialization (read-from-string serialized-string)) (fields-list (list :name :email :time-set :universal-time-start :universal-time-end :content :id))) (mapcar (lambda (x y) (the (set-slot! x y :warn-on-non-toplevel? nil))) fields-list deserialization))) ; Creates the HTML representation of this journal entry (to-html () (with-cl-who-string () ((:li :class "journal-entry") ((:div :class "journal-time") (fmt "~a" (the time-set))) ((:div :class "journal-descr") (fmt "~a" (the content)))))))) (define-object assembly (background-timer-mixin base-ajax-sheet) :input-slots ((timer-minutes-default 20) (timer-seconds-default 0) (current-journal-entry nil) (timer-paused nil)) :computed-slots ((force-update-flag nil :settable) ; ------------------------------------------------------------------------------ ; ; Main sheet body puts everything together. (main-sheet-body (with-cl-who-string () ((:div :id "content") (str (the ajax-scripts)) (str (the imported-scripts)) ((:h1 :id "header") "timer") (str (the timer-defaults-form main-div)) (str (the timer-form main-div)) (str (the journal-form main-div)) ((:ul :id "journal") (str (the journal-entries-display main-div)))))) (additional-header-content (the imported-css)) ; ------------------------------------------------------------------------------ ; ; Custom javascript and css sheet-sections and ajax calls. ; CSS that we are importing from the outside world. (imported-css (with-cl-who-string () (:link :href "/timer-static/style/styles.css" :rel "stylesheet" :type "text/css"))) ; Scripts that we are importing from the outside world. (imported-scripts (with-cl-who-string () (:script :src "https://code.jquery.com/jquery-2.1.4.min.js") (:script :src "/timer-static/plugins/hideseek/jquery.hideseek.min.js") (:script :src "/timer-static/scripts.js"))) ; Ajax calls generated using gdl-ajax-call (ajax-scripts (with-cl-who-string () ((:script :type "text/javascript") (str (string-append (format nil "function startTimerAjax () {~a}" (the (gdl-ajax-call :form-controls (list (the timer-form-min) (the timer-form-sec) (the name-form) (the email-form)) :function-key :start-timer-tasks))) (format nil "function recordJournalAjax () {~a}" (the (gdl-ajax-call :form-controls (list (the journal-entry-form)) :function-key :record-journal-entry))) (format nil "function pauseTimerAjax () {~a}" (the (gdl-ajax-call :function-key :pause-timer-tasks))) (format nil "function resetTimerAjax () {~a}" (the (gdl-ajax-call :function-key :reset-timer-tasks))) (format nil "function endTimerAjax () {~a}" (the (gdl-ajax-call :function-key :end-timer-tasks))))))))) :objects (; This section is pretty heavy, so I'm commenting it as good as I can. ; ------------------------------------------------------------------------------ ; ; Form field objects. ; The minutes field. (timer-form-min :type 'text-form-control :default (format nil "~a" (the timer-minutes-default)) :id "minutes" :size 2) ; The seconds field. (timer-form-sec :type 'text-form-control :default (format nil "~2,'0d" (the timer-seconds-default)) :id "seconds" :size 2) ; The default minutes field. (timer-default-form-min :type 'text-form-control :ajax-submit-on-change? t :default (format nil "~a" (the timer-minutes-default)) :id "default-minutes" :size 2) ; The default seconds field. (timer-default-form-sec :type 'text-form-control :ajax-submit-on-change? t :default (format nil "~2,'0d" (the timer-seconds-default)) :id "default-seconds" :size 2) ; The field for your name. (name-form :type 'text-form-control :default "Name" :id "user-name") ; The field for your email. (email-form :type 'text-form-control :default "Email" :id "user-email") ; The field for your journal entry's content. (journal-entry-form :type 'text-form-control :default "Description of task" :id "journal-entry") ; ------------------------------------------------------------------------------ ; ; Now we have a few buttons: start the timer, pause the timer, and reset the timer, ; as well as a button to record the journal entry. ; Starts the timer. Note: You must enter a name and email to start the timer. (timer-start-button :type 'button-form-control :onclick "timerStart();" :label "Start") ; Pauses the timer. (timer-pause-button :type 'button-form-control :onclick "timerPause();" :label "Pause") ; Resets the timer. (timer-reset-button :type 'button-form-control :onclick "timerReset();" :label "Reset") ; Records the journal entry. (record-journal-button :type'button-form-control :onclick "recordJournal();" :label "Record") ; ------------------------------------------------------------------------------ ; ; Sheet section for displaying journal entries. There is a toggle flag that ; allows this section to refresh every time a journal entry is added. ; ; Note to developer: This opens the file using the email field, ; reads it into a list of serialized strings, and then does a mapcar ; over the serialized strings to turn them into HTML. ; Finally, it uses reduce over the mapcar to append all the HTML together. (journal-entries-display :type 'sheet-section :inner-html (let ((serialized-strings (with-open-file (stream (string-append (namestring *db-path*) (the email-form value)) :direction :input :if-does-not-exist :create) (loop for str = (read stream nil) while str collect str))) (temp-journal-object (make-object 'journal-entry))) (the force-update-flag) (reduce 'string-append (mapcar #'(lambda (s) (the-object temp-journal-object (from-serialization s)) (the-object temp-journal-object to-html)) serialized-strings)))) ; ------------------------------------------------------------------------------ ; ; Finally, some sheet-sections to put these pieces all together. ; The form for the timer. (timer-form :type 'sheet-section :inner-html (with-cl-who-string () "Timer" (:br) (str (the timer-form-min form-control-string)) ":" (str (the timer-form-sec form-control-string)) (:br) (str (the name-form form-control-string)) (str (the email-form form-control-string)) (str (the timer-start-button form-control-string)) (str (the timer-pause-button form-control-string)) (str (the timer-reset-button form-control-string)))) ; The form for the timer defaults. (timer-defaults-form :type 'sheet-section :inner-html (with-cl-who-string () "Defaults" (:br) (str (the timer-default-form-min form-control-string)) ":" (str (the timer-default-form-sec form-control-string)))) ; The form for the journal entry. (journal-form :type 'sheet-section :inner-html (with-cl-who-string () (str (the journal-entry-form form-control-string)) (str (the record-journal-button form-control-string))))) :functions ( ; ------------------------------------------------------------------------------ ; ; Helper functions. ; Toggles the update flag for the journal entries display. (toggle-update-flag! () (the (set-slot! :force-update-flag (not (the force-update-flag))))) ; ------------------------------------------------------------------------------ ; ; Main functions: one for starting the timer, one for stopping it. ; Called when the start button is pressed. Creates and sets current-journal-entry ; but only if the timer was not just paused. Starts the background timer. (start-timer-tasks () (if (the timer-paused) nil (progn (the (set-slot! :current-journal-entry (make-object 'journal-entry :name (the name-form value) :email (the email-form value) :time-set (format nil "~a:~a" (the timer-form-min value) (the timer-form-sec value)) :universal-time-start (get-universal-time)))) (the (set-slot! :timer-paused nil)))) (the start-background-timer)) ; Called when the timer runs down to zero. Cancels the background timer and fills in ; the current journal entry's end timestamp. (end-timer-tasks () (the current-journal-entry (set-slot! :universal-time-end (get-universal-time))) (the cancel-background-timer)) ; Called when the pause button is pressed. Cancels the background timer, ; and sets the timer-paused flag to t. (pause-timer-tasks () (the cancel-background-timer) (the (set-slot! :timer-paused t))) ; Called when the reset button is pressed. Cancels the background timer. (reset-timer-tasks () (the cancel-background-timer) (the timer-form-min restore-defaults!) (the timer-form-sec restore-defaults!)) ; Called when the button for recording the journal entry is pressed. ; It records the journal entry's content and then writes it to a file. (record-journal-entry () (print-variables (the background-minutes) (the background-seconds)) (the toggle-update-flag!) (if (and (zerop (the background-minutes)) (zerop (the background-seconds))) (progn (the current-journal-entry (set-slot! :content (the journal-entry-form value))) (with-open-file (stream (string-append (namestring *db-path*) (the email-form value)) :direction :output :if-does-not-exist :create :if-exists :append) (write (the current-journal-entry to-serialization) :stream stream))) nil))))
11,590
Common Lisp
.lisp
303
32.122112
88
0.602882
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
c2e5d8ac07e158ecee278c6348b5b129c8bfee2d54e834795d819cbce60f579c
35,974
[ -1 ]
35,975
publish.lisp
lisp-mirror_gendl/apps/timer/source/publish.lisp
(in-package :timer-journaler) (publish-gwl-app "/timer" 'assembly) (publish-gwl-app "/timer-journaler" 'assembly) (publish-gwl-app "/tj" 'assembly)
149
Common Lisp
.lisp
4
36
46
0.743056
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
259361e9b32b6e86fdcaa51b35fa3d37b9cd83eba28e51f919eb4c589516d884
35,975
[ -1 ]
35,976
initialize.lisp
lisp-mirror_gendl/apps/timer/source/initialize.lisp
(in-package :timer-journaler) (defun initialize () (setq *db-path* (merge-pathnames "../db/" *source-path*)) (setq *static-path* (merge-pathnames "../static/" *source-path*)) (publish-directory :prefix "/timer-static/" :destination (format nil "~a" (probe-file (merge-pathnames "../static/" *static-path*))))) (initialize)
341
Common Lisp
.lisp
8
39.375
93
0.67378
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
5db1b809c07ad9e2aea564dd086c8b8d64c25bd237da7fb69f02d483e409dcf3
35,976
[ -1 ]
35,977
parameters.lisp
lisp-mirror_gendl/apps/timer/source/parameters.lisp
(in-package :timer-journaler) (defparameter *debug?* nil) (defparameter *source-path* (make-pathname :directory (pathname-directory (glisp:source-pathname)) :name nil :type nil)) (defparameter *db-path* (merge-pathnames "../db/" *source-path*) "Pathname or string. Points to the directory containing the database files. This is expected to be set at startup in a runtime application.") (defparameter *static-path* (merge-pathnames "../static/" *source-path*) "Pathname or string. Points to the directory containing the static files. This is expected to be set at startup in a runtime application.") (defparameter *smtp-server* "localhost") (setq gwl:*developing?* t) (setq *debug?* t)
706
Common Lisp
.lisp
14
47.928571
78
0.754026
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
d1c2c40551778e381fc82879603f40b1360b1bd55b2240925c43a7f92a6012b7
35,977
[ -1 ]
35,978
package.lisp
lisp-mirror_gendl/apps/yadd/source/package.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :common-lisp-user) #+allegro (eval-when (:compile-toplevel :load-toplevel :execute) (require :phtml)) (gwl:define-package :yadd (:documentation #.(glisp:system-description :yadd)) (:export #:assembly #:ass #:assy #:package-dokumentation #:document-package #:object-dokumentation #:function-dokumentation))
1,276
Common Lisp
.lisp
33
33.969697
71
0.699595
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
5aca41177579d8e124a1d2f4eeda9b08bc330613a61fe5f6e9fc5b13fc159b5e
35,978
[ -1 ]
35,979
publish.lisp
lisp-mirror_gendl/apps/yadd/source/publish.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :yadd) (defun publish-yadd (server) (publish-shared :path "/yadd-lookup" :server server :object-type 'yadd::all) (publish :path "/user-yadd" :server server :function #'(lambda(req ent) (gwl-make-part req ent "yadd:assembly"))) (publish-shared :path "/yadd" :object-type 'yadd:assy) (publish :path "/package-yadd" :server server :function #'(lambda(req ent) (gwl-make-part req ent "yadd:package-dokumentation")))) (pushnew 'publish-yadd *publishers*)
1,487
Common Lisp
.lisp
36
35.055556
81
0.670399
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
74487920af103488e490c33eaf9da5f3448804f87ab7bac852d313d9a31d66dd
35,979
[ -1 ]
35,980
test-part.lisp
lisp-mirror_gendl/apps/yadd/source/test-part.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (gdl:define-package :yadd-sample (:export #:assembly #:doc)) (in-package :yadd-sample) (define-object assembly (base-object) :documentation (:description "Takes a driveline specification along with some optimization parameters, and returns a list, :results, describing the top candidates according to the specified fitness criteria." :author "David J. Cooper Jr. [Genworks]" :examples "Please see code for ld-driveline:assembly for prototypical example.") :input-slots ("Number. Documentation for A" a "Number. Documentation for B" b ("Number. Documentation for C" C 25)) :computed-slots (("List of Plists (supported). These plists contain descriptions of the top candidates, one plist per candidate. Each plist is of the following form: <pre> (:phase-angles &lt;chosen phase angles&gt; :crank-angle &lt;chosen crank angle&gt; :pinion-angle &lt;chosen pinion angle&gt; ....) </pre> :implementation The list is collected up from each of the Winners, a quantified set of parts. Each Winner computes its own :results-list - please see the documentation for Winner for the specifics of this. " results nil) ("Array of Double-floats (supported). Each element in this array represents a particular combination of vertex-list and phase-angle. :purpose The top :number-of-solutions from this array are returned. :implementation This uses the built-in sort function. Some speedup might be realized by making one pass through the :score-array looking for the top candidates, rather than sorting the whole thing. However, this sort has not been observed to be a bottlneck." sorted-score-array nil)) :objects (("winner, loser. :purpose Object to compute details for each of the top candidates. :implementation Please see the definition of the object winner." :winners :type 'winner :sequence (:size 20))) :functions (("List of lists of 3D Points. Computes next possible sets of points from the given state :arguments (start-list \"List of 3D Points. Vertex-list to start from\" previous-uj-parameters \"Plist. Standard U-Joint parameters plist from previous joint\" current-uj-parameters \"Plist. Standard U-Joint parameters plist from current joint\" joint-number \"Integer. Joint ordinal number, indexed starting from 1\" number-of-shafts \"Integer. Total number of shafts in design\" nominal-rear-suspension-point \"3D Point. Heuristic point at design condition in rear suspension\" style \"Keyword Symbol. Hanger Style, either :hanger or :sitter\" facing \"Keyword Symbol. Direction hanger is facing, either :forward or :rearward\")" find-next-vertices ()) ("Double-float Number. Recursively Computes angle for hanger and shaft which results in exact 90-degree square angle between bearing and shaft. :arguments (from-point \"3D Point. Previous U-joint Point\" hanger-corner \"3D Point. Corner of Hanger (H1 down or up from Hanger-Attach)\" hanger-attach \"3D Point. Hanger Attach Point\" b2 \"Double-float Number. Bearing Height\" style \"Keyword Symbol. Hanger Style, either :hanger or :sitter\" facing \"Keyword Symbol. Direction hanger is facing, either :forward or :rearward\" hanger-vector-normal \"3D Vector. Perpendicular to Hanger attach plate\") :&optional ((angle-to-try 0) \"Angle in Degrees. Changes slightly through each recursion.\" (delta 10) \"Angle in Degrees. Amount to change with each recursion. Gets halved with each recursion.\" (tolerance 0.001) \"Angle in Degrees. When resultant angle is this close to 90, we say we are done.\" (depth 0) \"Integer. Starts at zero and increments one with each recursion. Used to terminate any runaway recursions.\") :&key (try \"This is our first try\") " compute-hanger-angle (from-point hanger-corner hanger-attach b2 style facing hanger-vector-normal &optional (angle-to-try 0) (delta 10) (tolerance 0.001) (depth 0)) (declare (ignore from-point hanger-corner hanger-attach b2 style facing hanger-vector-normal angle-to-try delta tolerance depth))))) (define-object winner (base-object)) (define-object loser (base-object)) (define-object test (base-object) :objects ((doc :type 'yadd:object-dokumentation :part-symbol-supplied "assembly" :part-package-supplied "yadd-test")))
5,673
Common Lisp
.lisp
103
47.271845
129
0.699191
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
a1daa8b5e0abec2795dd123ea1443a1f26e64f352beb1bba4a5485484c8756e8
35,980
[ -1 ]
35,981
format-documentation.lisp
lisp-mirror_gendl/apps/yadd/source/format-documentation.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :yadd) (define-object format-doc (doc-links-mixin) :computed-slots ((heading "Object Definitions") (part-type 'format-dokumentation) (symbols (remove-duplicates (let (result (package-object (the :package-object))) (do-symbols (symbol (the :package) (sort (nreverse result) #'string< :key #'symbol-name)) (when (and (eql (symbol-package symbol) package-object) (typep symbol 'gdl-format-symbol) (gdl::gdl-documentation (find-class symbol))) (push symbol result)))))) (symbols-external (remove-duplicates (let (result (package-object (the :package-object))) (do-external-symbols (symbol (the :package) (sort (nreverse result) #'string< :key #'symbol-name)) (when (and (eql (symbol-package symbol) package-object) (typep symbol 'gdl-format-symbol) (gdl::gdl-documentation (find-class symbol))) (push symbol result))))))))
2,080
Common Lisp
.lisp
40
40.675
105
0.609383
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
e2ed9f07a6a73e7747290ce28ad7804ec40b7f63a90cff91f5590f04d0e72ed8
35,981
[ -1 ]
35,982
function-documentation.lisp
lisp-mirror_gendl/apps/yadd/source/function-documentation.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :yadd) (define-object function-doc (doc-links-mixin) :input-slots (package return-object) :computed-slots ((heading "Function and Macro Definitions") (part-type 'function-dokumentation) (symbols (remove-duplicates (let (result (package-object (the :package-object))) (do-symbols (sym (the :package) (sort (nreverse result) #'string< :key #'symbol-name)) (when (and (eql (symbol-package sym) package-object) (glisp:function-documentation sym)) (push sym result)))))) (symbols-external (remove-duplicates (let (result (package-object (the :package-object))) (do-external-symbols (sym (the :package) (sort (nreverse result) #'string< :key #'symbol-name)) (when (and (eql (symbol-package sym) package-object) (glisp:function-documentation sym)) (push sym result)))))))) (define-object function-dokumentation (doc-string-parser-mixin remark-writers-mixin base-yadd-sheet) :input-slots (return-object symbol (show-package? nil)) :computed-slots ((strings-for-display (format nil "~a" (the symbol))) (doc-string (glisp:function-documentation (the symbol))) (macro? (macro-function (the symbol))) (dom-body (progn (print-variables (the root-path)) `((:p ,(format nil "~a" (the section-plist)))))) ) :functions ((write-html-sheet nil (html (:html (:head (the default-header-content) (:title (:princ (format nil "~a: ~s" (if (the macro?) "Macro" "Function") (the symbol))))) (:body (when *developing?* (html (:p (the (write-development-links))))) ;;(when *adsense?* (html (:p (:princ *adsense-code*)))) (:p (when (the :return-object) (the (:write-back-link :display-string "&lt;-Back")))) (:h2 (:princ (format nil "~a: ~:(~s~)" (if (the macro?) "Macro" "Function") (the symbol)))) (:p ((:table :width "100%" :border 0 :cellpadding 1 :cellspacing 0) (the (:write-row :show-package? (the :show-package?))))) (:p (when (the :return-object) (the (:write-back-link :display-string "&lt;-Back")))) (:p (the :write-footer)))))) (write-row (&key show-package?) (html (:tr ((:td :align :left) (:b (:princ (format nil "~a" (the symbol)))) (when (getf (the :section-plist) :type) (html " " (:i (the (:write-type (getf (the :section-plist) :type) :show-supported-flag? nil)))))) ((:td :align :right) :br)) (:tr ((:td :colspan 2) (the (:write-remark-body (the :section-plist) :show-package (when show-package? (symbol-package (the symbol))))))) (:tr ((:td :colspan 2) :br)))) (remark-string nil (the :doc-string))))
4,594
Common Lisp
.lisp
101
31.089109
104
0.508918
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
99f336b69e5d7092b43e21d306b45584ac02a53c815e707a202d67cfde300803
35,982
[ -1 ]
35,983
zzinit.lisp
lisp-mirror_gendl/apps/yadd/source/zzinit.lisp
;; ;; Copyright 2002-2011, 2012 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :yadd) (glisp:set-features *these-features*)
837
Common Lisp
.lisp
21
38.571429
70
0.758918
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
c742eb024d2471f77a22c5959e9d1957011b4ae178bf3d71e9fca93c8ccc7d06
35,983
[ -1 ]
35,984
initialize.lisp
lisp-mirror_gendl/apps/yadd/source/initialize.lisp
;; ;; Copyright 2002-2011, 2012 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :yadd) (defun initialize () (glisp:set-settings *settings*))
853
Common Lisp
.lisp
21
39.333333
70
0.755422
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
8b258f82c9722eb2d84bcf8d36d89bacfeb3f0b010e788f921428c84d9d3356d
35,984
[ -1 ]
35,985
genworks.lisp
lisp-mirror_gendl/apps/yadd/source/genworks.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :com.genworks.lisp) (defun autoloaded-packages () (append (list :win :windows :regexp) (remove-duplicates #-allegro nil #+allegro (append (mapcar #'(lambda(name) (glisp:intern (glisp:upcase name) :keyword)) (mapcar #'first excl::*autoload-package-name-alist*)) (mapcar #'rest excl::*autoload-package-name-alist*)) ))) #-(or allegro lispworks sbcl cmu ccl) (error "Need implementation for function-documentation for the currently running Lisp.~%") (defun function-documentation (function-symbol) #+allegro (get function-symbol 'excl::%fun-documentation) #+lispworks (get function-symbol 'system::%fun-documentation) #+(or cmu sbcl ccl) (documentation function-symbol 'function)) #-(or allegro lispworks sbcl cmu ccl) (error "Need implementation for variable-documentation for the currently running Lisp.~%") (defun variable-documentation (function-symbol) #+allegro (get function-symbol 'excl::%var-documentation) #+lispworks (get function-symbol 'system::%var-documentation) #+(or cmu sbcl ccl) (documentation function-symbol 'variable))
1,879
Common Lisp
.lisp
38
46.842105
128
0.747271
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
f370e9ab7871738ea653319940a594b0aa5bb056e86cfe7db7270f5570446755
35,985
[ -1 ]
35,986
parameters.lisp
lisp-mirror_gendl/apps/yadd/source/parameters.lisp
;; ;; Copyright 2002-2011, 2012 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :yadd) (defparameter *these-features* (list :yadd)) (defparameter *settings* nil)
873
Common Lisp
.lisp
22
38.454545
70
0.758539
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
646a27621697ec6f980964a74b80ded8c24eda133e3041efea9c60b4d5aa3f0a
35,986
[ -1 ]
35,987
ass.lisp
lisp-mirror_gendl/apps/yadd/source/ass.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :yadd) (define-object index (ass) :computed-slots ((packages-to-ignore (list :gwl-user :yadd-test :yadd-sample :genworks)))) (define-object ass (assembly) :computed-slots ((packages-to-ignore (list :gwl-user :yadd-test :yadd-sample :genworks)))) (define-object assy (ass) :computed-slots ((packages-to-ignore (list :gwl-user :yadd-test :yadd-sample :genworks :stripe :documents)))) (define-object all (assembly) :computed-slots ((packages-to-ignore nil)))
1,370
Common Lisp
.lisp
33
38.515152
96
0.73167
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
f2c3d9969c7320766153698fe7d07a0cfb31ad734face5dff53ea236d81eb5a2
35,987
[ -1 ]
35,988
variable-documentation.lisp
lisp-mirror_gendl/apps/yadd/source/variable-documentation.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :yadd) (define-object variable-doc (doc-links-mixin) :computed-slots ((heading "Variables and Constants") (part-type 'variable-dokumentation) (symbols (remove-duplicates (let (result (package-object (the :package-object))) (do-symbols (symbol (the :package) (sort (nreverse result) #'string< :key #'symbol-name)) (when (and (eql (symbol-package symbol) package-object) (glisp:variable-documentation symbol)) (push symbol result)))))) (symbols-external (remove-duplicates (let (result (package-object (the :package-object))) (do-external-symbols (symbol (the :package) (sort (nreverse result) #'string< :key #'symbol-name)) (when (and (eql (symbol-package symbol) package-object) (glisp:variable-documentation symbol)) (push symbol result)))))))) (define-object variable-dokumentation (doc-string-parser-mixin remark-writers-mixin base-yadd-sheet) :input-slots ( ;;symbol (show-package? nil)) :computed-slots ((remark-string (glisp:variable-documentation (the symbol)))) :functions ((write-html-sheet nil (html (:html (:head (the default-header-content) (:title (:princ (format nil "Documentation for ~s" (the :symbol))))) (:body (when *developing?* (html (:p (the (write-development-links))))) (:p (when (the :return-object) (the (:write-back-link :display-string "&lt;-Back")))) (:h2 (:princ (format nil "~a: ~:(~s~)" (if (constantp (the symbol)) "Constant" "Parameter") (the :symbol)))) (:p ((:table :width "100%" :border 0 :cellpadding 1 :cellspacing 0) (the (:write-row)))) (let ((new-list (copy-list (the :section-plist)))) (remf new-list :type) (remf new-list :value-default) (remf new-list :intro) (mapcar #'(lambda (key value) (html (:dt (:i (:princ (string-capitalize (case key (:&optional "Optional Arguments") (:&key "Keyword Arguments") (otherwise key)))) ":")) (:dd (case key (:arguments (the (:write-arguments value))) ((:&optional :&key) (the (:write-optional-arguments value))) (otherwise (html (:princ value))))))) (plist-keys new-list) (plist-values new-list))) (:p (when (the :return-object) (the (:write-back-link :display-string "&lt;-Back")))) (:p (the :write-footer)))))) (write-row nil (html (:tr ((:td :align :left) (:b (:princ (format nil "~a" (the :symbol)))) (when (getf (the :section-plist) :type) (html " " (:i (the (:write-type (getf (the :section-plist) :type) :show-supported-flag? nil))))) (when (getf (the :section-plist) :value-default) (html ", " "Default Value: " (:tt (:princ (read-from-string (getf (the :section-plist) :value-default)))))))) (:tr ((:td :align :left) (:princ (getf (the :section-plist) :intro))))))))
5,401
Common Lisp
.lisp
109
30.247706
104
0.453057
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
0f9f2e47813b6bc3b6079003d72dd1e5da425aeb63cbae110ab97bf75ba3d1ca
35,988
[ -1 ]
35,989
base-framework.lisp
lisp-mirror_gendl/apps/gorg/source/base-framework.lisp
(in-package :glsite) ;; ;; FLAG -- In a production environment (where source directory might ;; not be there) this parameter must be set at initialization/startup ;; time to the correct location. ;; (defparameter *system-home* "~dcooper8/genworks/gendl/apps/gorg/") (defparameter *templates-folder* (let ((static (merge-pathnames "static/templates/" *system-home*))) (translate-logical-pathname (make-pathname :name nil :type nil :defaults static)))) (defparameter *cache-static-content?* nil) ;; ;; Quick hack for a read-from-static function with local demand-filled ;; hash table, which can be used by all object instances so they can ;; share the static data. If we have a toplevel Gendl object presiding ;; over all session root-level objects, we might be able to do ;; something for this which is more elegant and uniform with Gendl ;; style: ;; (let ((templates-folder *templates-folder*) (static-content-ht (make-hash-table))) (defun clear-static () (clrhash static-content-ht)) (defun read-static (name) (let ((key (make-keyword name))) (or (gethash key static-content-ht) (let ((value (let ((template (merge-pathnames (format nil "~a.html" name) templates-folder))) (if (probe-file template) (with-open-file (stream template) (let ((data (make-string (file-length stream)))) (read-sequence data stream) data)) (let ((warn-string (format nil "<p>No template found for ~a<p>" template))) (progn (warn warn-string) warn-string)))))) (if *cache-static-content?* (setf (gethash key static-content-ht) value) value)))))) ; the landing page computes the header and footer ; and also holds references for all of the pages. (define-object landing (base-ajax-sheet) :computed-slots ((section-names (list "about" "license" "downloads" "documentation" "demos" "getinvolved")) (title "Gendl") (main-sheet-body (with-cl-who-string () (str (read-static "header")) ;; ;; FLAG - this wants to go at the top of every "page" ;; (when gwl:*developing?* (str (the development-links))) (str (reduce #'(lambda (x y) (concatenate 'string x y)) (mapsend (the sections) :main-sheet-body))) (str (read-static "footer"))))) :objects ((sections :type 'section :sequence (:size (length (the section-names))) :name (nth (the-child index) (the section-names))))) (define-object section (base-ajax-sheet) :input-slots (name) :computed-slots ((main-sheet-body (concatenate 'string (with-cl-who-string () ((:a :name (the name)))) (read-static (the name))))))
2,668
Common Lisp
.lisp
66
35.863636
95
0.677132
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
ce8d70a7f88adf9d0db30020278444a8d720cdde06b7a150b04c13e21c1026ac
35,989
[ -1 ]
35,990
package.lisp
lisp-mirror_gendl/apps/gorg/source/package.lisp
;; ;; Copyright 2002-2011, 2012 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (gwl:define-package :glsite (:export #:landing #:clear-static #:initialize))
945
Common Lisp
.lisp
21
42.761905
77
0.74295
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
eb3a4e34f26baf66877591f52e453bdad0caafb5ca400c7ed85801f8194e5e94
35,990
[ -1 ]
35,991
publish.lisp
lisp-mirror_gendl/apps/gorg/source/publish.lisp
;; ;; Copyright 2002-2011, 2012 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :glsite) (defparameter *gorg-hosts* (list "gendl.org" "www.gendl.org" "gendl.com" "www.gendl.com") #+nil (list "localhost" "xenie" "gendlformacosx.com" "www.gendlformacosx.com" "gendlformacos.com" "www.gendlformacos.com" "gendlformacosx.org" "www.gendlformacosx.org" "gendlformacos.org" "www.gendlformacos.org" "macos.gendl.com" "www.macos.gendl.com" "macos.gendl.org" "www.macos.gendl.org" "macosx.gendl.com" "www.macosx.gendl.com" "macosx.gendl.org" "www.macosx.gendl.org" "gendl.org" "www.gendl.org" "gendl.com" "www.gendl.com")) (defun initialize () (let ((static (or (when (glisp:source-pathname) (probe-file (make-pathname :name nil :type nil :defaults (merge-pathnames "../static/" (translate-logical-pathname (glisp:source-pathname)))))) (probe-file (merge-pathnames "static/" *system-home*)) (probe-file (merge-pathnames "gorg-static/" glisp:*gdl-program-home*))))) (if static (progn (setq static (namestring static)) (dolist (host *gorg-hosts*) (publish-directory :prefix "/gorgstat/" :destination static :host host))) (warn "static directory does not exist in gorg publish."))) ;; ;; FLAG Put this back in when we get cookies working and lose the ugly ;; "/sessions/..." url ;; ;;(publish-gwl-app "/" "glsite:landing") ;; (publish-shared :host "gendl.org" :path "/" :object-type 'landing) (publish-shared :path "/gorg" :object-type 'landing) #+nil (dolist (host *gorg-hosts*) (publish-shared :host host :path "/" :object-type 'landing))) ;; ;; FLAG -- arrange to call this on production startup. ;; ;;(initialize)
2,532
Common Lisp
.lisp
68
34.029412
76
0.70516
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
6bf0ff608b09f0a757636320319c31df75283a599e79605ff48382dff16b8b8c
35,991
[ -1 ]
35,992
zzinit.lisp
lisp-mirror_gendl/gwl-graphics/zzinit/source/zzinit.lisp
;; ;; Copyright 2002-2011, 2012 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl-graphics) (pushnew :gwl-graphics *these-features*) (glisp:set-features *these-features*)
885
Common Lisp
.lisp
22
39
70
0.760743
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
29a943fe100ed3fbfb262978a1a9053aed50230efbbf0124a74e1429474936b9
35,992
[ -1 ]
35,993
initialize.lisp
lisp-mirror_gendl/gwl-graphics/zzinit/source/initialize.lisp
;; ;; Copyright 2002-2011, 2012 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl-graphics) (defun initialize ())
829
Common Lisp
.lisp
21
38.190476
70
0.757764
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
d470d50f3f14a5bf0f0d3925a7e0f957922dba8f0dffd97886072f9f98244bc9
35,993
[ -1 ]
35,994
package.lisp
lisp-mirror_gendl/gwl-graphics/svg/source/package.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl-user) (gwl:define-package :svg (:use :geom-base))
933
Common Lisp
.lisp
22
40.045455
71
0.739802
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
2e634d4101d077aeeca6a2c333c6ac91cc2bc91a806a6140dacd59bb9305be7b
35,994
[ -1 ]
35,995
package.lisp
lisp-mirror_gendl/gwl-graphics/raphael/source/package.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl-user) (gwl:define-package :raphael (:use :geom-base) (:export #:raphael))
957
Common Lisp
.lisp
22
41.136364
71
0.73899
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
5cfcb78e372730dc9cb8d3303eef1819ceb4b23b4f4f0b446d09a8cada9bbe40
35,995
[ -1 ]
35,996
tests.lisp
lisp-mirror_gendl/gwl-graphics/raphael/source/tests.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;;
864
Common Lisp
.lisp
20
40.8
71
0.744048
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
8a37a8e2cb4da8954deb23bdc58032aac5973852bed861225a81980f0f47249c
35,996
[ -1 ]
35,997
formats.lisp
lisp-mirror_gendl/gwl-graphics/raphael/source/formats.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :raphael)
891
Common Lisp
.lisp
21
39.857143
71
0.743619
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
ab35017cd019baf7c6df33b0ddf60878f5f4f9bc500fa25cd6c769035a248759
35,997
[ -1 ]
35,998
application-mixin.lisp
lisp-mirror_gendl/gwl-graphics/gwl/source/application-mixin.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defparameter *icon-hash* nil) (define-object node-mixin (layout-mixin) :documentation (:description "Generates a default GWL user interface with a model-inputs area, user-navigable tree with child applications, graphics view with controls, and rule display. Child objects should be of type <tt>node-mixin</tt> or <tt>application-mixin</tt>. Child hidden-objects may be of any type. The <tt>ui-display-list-objects</tt> is appended up automatically from those of the children.") :input-slots (("Integer. Determines how many descendant levels to show in the tree initially. Default is 1." default-tree-depth 1) ("GDL object list. Appends additional objects to the automatically-appended <tt>ui-display-list-objects</tt> from the children." node-ui-display-list-objects nil)) :computed-slots ((child-nodes (remove-if-not #'(lambda (kid) (typep kid 'layout-mixin)) (the :children))) ("List of GDL object roots. The leaves of these objects will be displayed in the graphics. Defaults to the appended result of children's <tt>ui-display-list-objects</tt>." ui-display-list-objects (apply #'append (the :node-ui-display-list-objects) (mapcar #'(lambda (kid) (when (<= (the-object kid depth) *max-node-depth*) (ensure-list (the-object kid :ui-display-list-objects)))) (the :child-nodes)))) (node-ui-display-list-leaves nil) (ui-display-list-leaves (apply #'append (the :node-ui-display-list-leaves) (mapcar #'(lambda (kid) (when (<= (the-object kid depth) *max-node-depth*) (ensure-list (the-object kid :ui-display-list-leaves)))) (the :child-nodes)))) (tree-state (if (< (the depth) (the :default-tree-depth)) :open :closed) :settable)) :trickle-down-slots (tree-root)) (define-lens (html-format node-mixin) () :output-functions ((tree (&key (current-node self)) (if (eql self (the :tree-root)) (let ((*icon-hash* (make-hash-table))) (html ((:table :border 0 :cellpadding 0 :cellspacing 0) :newline (write-the (:tree-row :current-node current-node))))) (write-the :tree-root (:tree :current-node current-node)))))) (define-object application-mixin (layout-mixin) :documentation (:description "This mixin generates a default GWL user interface, similar to <tt>node-mixin</tt>, but you should use <tt>application-mixin</tt> if this is a leaf-level application (i.e. has no children of type <tt>node-mixin</tt> or <tt>application-mixin</tt>")) (define-skin infinite ()) (define-lens (html-format layout-mixin)() :skin infinite :output-functions ((main-sheet () (with-html-output (*html-stream* nil :prologue t :indent t) (:html (:head (:title (str (the :page-title))) (:link :rel "stylesheet" :href "/static/css/main.css" :type "text/css" :media "screen") "<!--[if IE]><link rel=\"stylesheet\" href=\"/static/css/ie.css\" type=\"text/css\" media=\"screen\" /><![endif]-->" (:script :type "text/javascript" :src "/static/js/niftycube.js")) ((:body :class "demo") (when *developing?* (write-the (:development-links))) ((:div :class "content") (:center (with-html-form (:multipart? (the multipart-form?)) ((:div :class "column_left") (:h3 (str (the :inputs-title))) (write-the (:model-inputs))) ((:div :class "column_center") (:h2 (str (the strings-for-display))) (write-the viewport)) ((:div :class "footer") (the (:write-standard-footer)))))))))) (viewport () (ecase (the image-format) (:links (the (write-geometry-links))) ((:png :jpeg) (the write-geometry)) (:vrml (the write-embedded-vrml-world)))) (model-inputs ()) (tree () (let ((tree-root (the :tree-root))) (when (and tree-root (typep tree-root 'node-mixin)) (write-the :tree-root (:tree :current-node self))))) (tree-row (&key current-node) (with-html-output (*html-stream* nil :indent t) (htm :newline (:tr (let ((depth (the :depth))) (dotimes (n depth) (cond ((and (= n (1- depth)) (the :last-node?)) (setf (gethash n *icon-hash*) :l) (htm ((:td :width 20 ) ((:img :src "/images/gwl/l-t.gif"))))) ((= n (1- depth)) (setf (gethash n *icon-hash*) :t) (htm ((:td :width 20 ) ((:img :src "/images/gwl/t-t.gif"))))) ((member (gethash n *icon-hash*) (list :i :t)) (setf (gethash n *icon-hash*) :i) (htm ((:td :width 20 ) ((:img :src "/images/gwl/i-t.gif"))))) (t (htm ((:td :width 20 ) :br)))))) (if (and (typep self 'node-mixin) (the :child-nodes)) (htm ((:td :width 9 ) ((:input :type :image :src (ecase (the :tree-state) (:open "/images/gwl/minus.gif") (:closed "/images/gwl/plus.gif")) :name (format nil ":tree-toggle+~a" (the :url-encoded-root-path)))))) (htm ((:td :width 5 :align :center) ((:img :src "/images/gwl/red-dot.gif" :width 8 ))))) ((:td :nowrap :nowrap :colspan (1+ (- (the :total-depth) (the :depth)))) (if (eql self current-node) (htm (:b (str (the :strings-for-display)))) ;;(the (:write-self-link)) ;;(str (the self-link)) (htm (:b (str (the :strings-for-display)))) #+nil (htm ((:a :href (the url)) (str (the strings-for-display)))) ))) (when (and (typep self 'node-mixin) (eql (the :tree-state) :open)) (mapc #'(lambda(node) (write-the-object node (:tree-row :current-node current-node))) (the :child-nodes)))))) (violated-rules () (when (the :violated-rules) (with-html-output (*html-stream* nil :indent t) (:table (dolist (rule (the :violated-rules)) (htm (:tr (:td (the-object rule (:write-self-link :target "Rule-Display" :display-color :red :display-string (format nil "~a~a~a" (the-object rule :rule-title) (if (the-object rule :rule-result) ": " "") (or (the-object rule :rule-result) "")))))))))))) (other-rules () (when (the :other-rules) (with-html-output (*html-stream* nil :indent t) (:table (dolist (rule (the :other-rules)) (htm (:tr (:td (the-object rule (:write-self-link :target "Rule-Display" :display-color :blue :display-string (format nil "~a~a~a" (the-object rule :rule-title) (if (the-object rule :rule-result) ": " "") (or (the-object rule :rule-result) "")))))))))))))) (define-lens (html-format layout-mixin)() :output-functions ( (viewport () (ecase (the image-format) (:links (the (write-geometry-links))) ((:png :jpeg) (the write-geometry)) (:vrml (the write-embedded-vrml-world)))) (main-sheet () (if (getf (the view-object query-plist) :resize-pdf) (the view-object (write-html-sheet)) (html (format *html-stream* "<!doctype HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">~%") (:html (:head (:title (:princ (the :page-title)))) ((:body :if* (the :body-bgcolor) :bgcolor (lookup-color (the :body-bgcolor) :format :hex)) (when (the show-title?) (html (:center (:h2 (:princ (the :page-title)))))) (when *developing?* (the (:write-development-links))) (:center (with-html-form (:multipart? (the multipart-form?)) (:p (:table (:tr ((:td :valign :top :if* (the :inputs-bgcolor) :bgcolor (lookup-color (the :inputs-bgcolor) :format :hex) :rowspan (if (the display-tree?) 1 2)) (:center (:h3 (:princ (the :inputs-title)))) (write-the (:model-inputs))) ((:td :rowspan 2 :valign :top) (write-the viewport)) (when (the display-rules?) (html ((:td :valign :top :if* (the :violated-rules-bgcolor) :bgcolor (lookup-color (the :violated-rules-bgcolor) :format :hex)) (:center (:h3 (:princ (the :violated-rules-title)))) (write-the (:violated-rules)))))) (:tr (when (the display-tree?) (html ((:td :valign :top :if* (the :tree-bgcolor) :bgcolor (lookup-color (the :tree-bgcolor) :format :hex)) (:center (:h3 (:princ (the :tree-title)))) (write-the (:tree))))) (when (the display-rules?) (html ((:td :align :left :valign :top :if* (the :other-rules-bgcolor) :bgcolor (lookup-color (the :other-rules-bgcolor) :format :hex)) (:center (:h3 (:princ (the :other-rules-title)))) (write-the (:other-rules)))))))))) :hr (the (:write-standard-footer))))))) (model-inputs ()) (tree () (let ((tree-root (the :tree-root))) (when (and tree-root (typep tree-root 'node-mixin)) (write-the :tree-root (:tree :current-node self))))) ;; ;; FLAG -- try to replace this tree with the generic one in ;; tree.lisp and remove duplicate *icon-hash* defparameter. ;; (tree-row (&key current-node) (html :newline (:tr (let ((depth (the :depth))) (dotimes (n depth) (cond ((and (= n (1- depth)) (the :last-node?)) (setf (gethash n *icon-hash*) :l) (html ((:td :width 20 ) ((:img :src "/images/gwl/l-t.gif"))))) ((= n (1- depth)) (setf (gethash n *icon-hash*) :t) (html ((:td :width 20 ) ((:img :src "/images/gwl/t-t.gif"))))) ((member (gethash n *icon-hash*) (list :i :t)) (setf (gethash n *icon-hash*) :i) (html ((:td :width 20 ) ((:img :src "/images/gwl/i-t.gif"))))) (t (html ((:td :width 20 ) :br)))))) (if (and (typep self 'node-mixin) (the :child-nodes)) (html ((:td :width 9 ) ((:input :type :image :src (ecase (the :tree-state) (:open "/images/gwl/minus.gif") (:closed "/images/gwl/plus.gif")) :name (format nil ":tree-toggle+~a" (the :url-encoded-root-path)))))) (html ((:td :width 5 :align :center) ((:img :src "/images/gwl/red-dot.gif" :width 8 ))))) ((:td :nowrap :nowrap :colspan (1+ (- (the :total-depth) (the :depth)))) (if (eql self current-node) (html (:b (:princ (the :strings-for-display)))) (html (:princ (the self-link))) ;;(the (:write-self-link)) ))) (when (and (typep self 'node-mixin) (eql (the :tree-state) :open)) (mapc #'(lambda(node) (write-the-object node (:tree-row :current-node current-node))) (the :child-nodes))))) (violated-rules () (when (the :violated-rules) (html (:table (dolist (rule (the :violated-rules)) (html (:tr (:td (the-object rule (:write-self-link :target "Rule-Display" :display-color :red :display-string (format nil "~a~a~a" (the-object rule :rule-title) (if (the-object rule :rule-result) ": " "") (or (the-object rule :rule-result) "")))))))))))) (other-rules () (when (the :other-rules) (html (:table (dolist (rule (the :other-rules)) (html (:tr (:td (the-object rule (:write-self-link :target "Rule-Display" :display-color :blue :display-string (format nil "~a~a~a" (the-object rule :rule-title) (if (the-object rule :rule-result) ": " "") (or (the-object rule :rule-result) "")))))))))))))) (define-object gwl-rule-object (base-html-graphics-sheet base-rule-object) :documentation (:description "Used to display a rule as a GWL web page. Mixes together <tt>base-html-sheet</tt> and <tt>base-rule-object</tt>.")) (define-lens (html-format gwl-rule-object)() :output-functions ((main-sheet () (html (:html (:head (:title (:princ (the :rule-title)))) (:body (when gwl:*developing?* (write-the (development-links))) (:center (:h2 (:princ (the :rule-title)))) ((:table :border 0) (:tr ((:td :valign :top) (write-the (:main-area))) (:td (write-the (:right-user-area)))) (:tr (:td (write-the (:bottom-user-area))))))))) (main-area () (html (:table (:tr ((:td :colspan 2) (the (write-self-link :display-string "Redemand Sheet")))) (:tr ((:td :bgcolor :yellow) "Title") (:td (:princ (the :rule-title)))) (:tr ((:td :bgcolor :yellow) "Description") (:td (:princ (the :rule-description)))) (:tr ((:td :bgcolor :yellow) "Result") (:td (:princ (the :rule-result)))) (:tr ((:td :bgcolor :yellow) "Violated?") (:td (if (the :violated?) (html (:b ((:font :color :red) "Yes"))) (html (:b ((:font :color :green) "No"))))))))) (right-user-area ()) (bottom-user-area ())))
17,829
Common Lisp
.lisp
335
34.441791
147
0.462767
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
d6c2ec77b7dd5467b6a8cfe69e7fa07d10e12d924bf3b8c59c07813fdc14ffdd
35,998
[ -1 ]
35,999
base-ajax-graphics-sheet.lisp
lisp-mirror_gendl/gwl-graphics/gwl/source/base-ajax-graphics-sheet.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (define-object base-ajax-graphics-sheet (base-ajax-sheet base-html-graphics-sheet) :documentation (:description "This mixes together base-ajax-sheet with base-html-graphics-sheet, and adds html-format output-functions for several of the new formats such as ajax-enabled png/jpeg and Raphael vector graphics." :examples "FLAG -- Fill in!!!") :input-slots ((respondent (the bashee) :defaulting) (empty-display-list-message nil) ("Number. Thickness of default border around graphics viewport. Default is 1." viewport-border-default 1) (vector-graphics-onclick? t) ("Plist of keys and strings. The default formats for graphics display. Defaults to: <pre> (list :png \"PNG image\" :jpeg \"jpeg image\" :raphael \"SVG/VML\") </pre>" image-format-plist (list :png "PNG image" :jpeg "jpeg image" :x3dom "X3DOM" ;;:web3d "VRML/X3D" :raphael "SVG/VML")) ("Keyword symbol, one of the keys from (the image-format-plist). Default for the image-format-selector. Defaults to :png." image-format-default :png) ("Default view initially in the view-selector which is automatically included in the view-controls." view-direction-default :trimetric) (zoom-factor-renderer 1) ("Boolean. Include raphael javascript library in the page header? Default nil. " use-raphael? nil) ("Boolean. Include raphael graphing library in the page header? Default nil. " use-raphael-graf? nil) ("List of GDL objects containing geometry. These are the actual objects themselves, not nodes which have children or other descendants that you want to display. If you want to display the leaves of certain nodes, include the objects for those nodes in the display-list-object-roots, not here. Defaults to nil." display-list-objects nil) ("List of GDL objects. The leaves of each of these objects will be included in the geometry display. Defaults to nil." display-list-object-roots nil) ("3D vector. This is the normal vector of the view plane onto which to project the 3D objects. Defaults to (getf *standard-views* (the view-selector value)), and (the view-selector value) defaults to :top." projection-vector (getf *standard-views* (the view-selector value))) ("List of GDL objects. These objects are not used in computing the scale or centering for the display list. Defaults to nil." immune-objects nil) ("Array of three numbers between 0 and 1. RGB Color in decimal format. Color to be used for the background of the viewport. Defaults to the <tt>:background</tt> from the global <tt>*colors-default*</tt> parameter." background-color (lookup-color (getf *colors-default* :background) :format :decimal)) ("Number in angular degrees. The maximum angle of the view frustrum for perspective views. Defaults to 45 which is natural human eye field of view. " field-of-view-default 45) ("Keyword symbol. Determines the default image format. Defaults to the currently selected value of the image-format-selector, which itself defaults to :raphael." image-format (the image-format-selector value)) ("Boolean. Indicates whether standard view-controls panel should be included with the graphics." include-view-controls? t) (x3dom-view-controls? t) ;; ;; FLAG -- probably not needed, inherited from skeleton-ui-mixin via base-ajax-sheet, base-html-sheet, sheet-section. ;; (inner-html (with-cl-who-string () (write-the inner-html))) (on-drag-function nil) (on-drop-function nil) (on-touchmove-function nil) (viewport-js-text (format nil " function x3draw () { if (x3dom.type != 'undefined') x3dom.reload(); var elem = document.getElementById('view-~(~a~)'); if (elem) elem.setAttribute('set_bind', 'true'); var x3dom1 = document.getElementById('x3dom-1'); if (x3dom1) xruntime= x3dom1.runtime; xruntime.resetView(); } x3draw(); " (the view-selector value))) ) :computed-slots ((js-to-eval :parse :settable) (js-always-to-eval nil) (raphael-canvas-id (format nil "raphael-~a" (the base64-encoded-root-path))) (raphael-string (unless (the no-graphics?) (with-error-handling () (with-output-to-string (ss) (with-format (raphael ss :page-width (the view-object page-width) :page-length (the view-object page-length) :background-color (the background-color) :foreground-color (the foreground-color)) (write-the view-object cad-output)))))) (svg-string (if (the no-graphics?) (with-cl-who-string () ((:div :id "empty-viewport" :class "empty-viewport") (str (the empty-display-list-message)))) (with-error-handling () (with-output-to-string (ss) (with-format (svg ss :background-color (the background-color) :foreground-color (the foreground-color)) (write-the view-object cad-output)))))) ("String of valid HTML. This can be used to include the PNG or JPG raster-graphics of the geometry." raster-graphics (with-cl-who-string () (write-the raster-graphics))) ("String of valid HTML. This can be used to include the SVG or VML vector-graphics of the geometry." vector-graphics (with-cl-who-string () (write-the vector-graphics))) ("String of valid HTML. This can be used to include the x3dom tag content for the geometry." x3dom-graphics (with-cl-who-string () (write-the embedded-x3dom-world))) ("String of valid HTML. This includes the image-format-selector, the reset-zoom-button, and the view-selector, in a simple table layout. You can override this to make the view-controls appear any way you want and include different and/or additional form-controls." view-controls (with-cl-who-string () ((:div (:class "gdlFormControls")) (:table (:tr (:td (str (the view-selector html-string))) (:td (str (the image-format-selector html-string))) (:td (str (the reset-zoom-button form-control-string)))))))) ("String of valid HTML. This can be used to include the geometry, in the format currently selected by the image-format-selector. If the include-view-controls? is non-nil, the view-controls will be appended at the bottom of the graphics inside a table." graphics (with-cl-who-string () (:table (:tr ((:td :align :center) (str (ecase (the image-format-selector value) (:x3dom (the x3dom-graphics)) ((:png :jpeg :jpg) (the raster-graphics)) (:raphael (the vector-graphics)))))) (when (and (member (the image-format) (list :jpeg :jpg :png :raphael )) (the include-view-controls?)) (htm (:tr (:td (str (the view-controls)))))) (when (and (member (the image-format) (list :x3dom)) (the include-view-controls?)) (htm (:tr (:td (str (the image-format-selector html-string)))))) ))) ("3D point. This is the upper-right corner of the bounding box of the dragged and/or dropped element." dropped-x-y nil :settable) ("Plist with :width and :height. The dimensions of the bounding-box of the dragged and/or dropped element." dropped-height-width nil :settable) ("List representing GDL root-path. This is the root path of the dragged and/or dropped object. This is not tested to see if it is part of the same object tree as current self." dropped-object nil :settable) (viewport-script (progn (the inner-html) (cond ((eql (the image-format-selector value) :x3dom) (with-cl-who-string () (:div ((:script :type "text/javascript") (str (the viewport-js-text)))))) (t ""))))) :hidden-objects ((view-object :type 'web-drawing :pass-down (projection-vector immune-objects background-color field-of-view-default raphael-canvas-id zoom-factor-renderer) :page-length (the length) :page-width (the width) :empty-display-list-message (the empty-display-list-message) :objects (the display-list-objects) :object-roots (the display-list-object-roots)) ("Object of type menu-form-control. Its value slot can be used to determine the format of image displayed." image-format-selector :type 'menu-form-control :size 1 :prompt "Format" :onchange (the (gdl-ajax-call :form-controls (list (the-child)))) :choice-plist (the image-format-plist) :default (the image-format-default)) (reset-zoom-button :type 'button-form-control :label "Fit" :onclick (the (gdl-ajax-call :function-key :reset-zoom!))) (view-selector :type 'menu-form-control :size 1 :prompt "View" :onchange (the (gdl-ajax-call :form-controls (list (the-child)))) :choice-list (plist-keys (the standard-views)) ;;:default :top :default (the view-direction-default) )) :functions ( ;; ;; FLAG -- copied from base-html-graphics-sheet's logic for dig-point and report-point -- ;; factor out the repeated code! ;; ;; FLAG -- standardize on length instead of height for Y coord. ;; (model-x-y (local-x-y) (when local-x-y (destructuring-bind (&key x y) local-x-y (let ((x (- x (half (the view-object width)))) (y (let ((y (- (the view-object length) y))) (- y (half (the view-object length)))))) (let ((adjusted (scalar*vector (the view-object user-scale) (add-vectors (make-point (get-x (the view-object user-center) ) (get-y (the view-object user-center)) 0) (scalar*vector (/ (the view-object user-scale)) (make-point x y 0)))))) (let ((model-point (the view-object main-view (model-point adjusted)))) model-point)))))) (reset-zoom! () (the view-object (restore-slot-defaults! (list :user-center :user-scale)))) ("Void. Writes an embedded X3D tag with content for the <tt>view-object</tt> child of this object. The <tt>view-object</tt> child should exist and be of type <tt>web-drawing</tt>." write-embedded-x3dom-world (&key (include-view-controls? nil)) (write-the (embedded-x3dom-world :include-view-controls? include-view-controls?))) (set-js-vals! (js-vals) (let ((dropped-x-y (the (model-x-y (destructuring-bind (&key x y &allow-other-keys) js-vals (list :x x :y y))))) (dropped-height-width (destructuring-bind (&key width height &allow-other-keys) js-vals (list :width (/ width (the view-object view-scale)) :height (/ height (the view-object view-scale))))) (dropped-object (with-error-handling () (base64-decode-list (getf js-vals :name))))) (the (set-slots! (list :dropped-x-y dropped-x-y :dropped-height-width dropped-height-width :dropped-object dropped-object))))) (on-drag () (when (the on-drag-function) (funcall (the on-drag-function)))) (on-drop () (when (the on-drop-function) (funcall (the on-drop-function)))) (on-touchmove () (when (the on-touchmove-function) (funcall (the on-touchmove-function)))))) (define-lens (html-format base-ajax-graphics-sheet)() :output-functions ((main-view () (with-cl-who () ((:table :border (the viewport-border-default)) (:tr (:td (str (the graphics))))))) (svg-vector-graphics () (with-cl-who () (when (typep (the :view-object) 'null-part) (error "A valid :view-object of type web-drawing is required in the sheet to call the :raphael-canvas method.")) (str (the svg-string)))) (vector-graphics () (with-cl-who () (when (typep (the :view-object) 'null-part) (error "A valid :view-object of type web-drawing is required in the sheet to call the :raphael-canvas method.")) (let ((no-graphics? (the no-graphics?))) (htm ((:div :id (the raphael-canvas-id) :style (format nil "cursor: ~a; /* height: ~apx; width: ~apx; */ overflow:hidden; clip: rect(0px ~apx ~apx 0px); z-index: 1; /* position: relative; */ " (if (the vector-graphics-onclick?) "crosshair" "arrow") (the view-object length) (the view-object width) (the view-object width) (the view-object length)) :onclick (unless (or no-graphics? (not (the vector-graphics-onclick?))) (the (gdl-ajax-call :function-key :dig-point)))) (if no-graphics? (htm ((:table :border 1 :cellspacing 0 :cellpadding 0 :bgcolor :white) (:tr ((:td :width (the :view-object :width) :height (the :view-object :length) :align :center :valign :center) (:big (:b "No Graphics Object Specified")))))) (let ((raphael-string (the raphael-string))) (htm ((:script :type "text/javascript") (str raphael-string)))))))))) ("Void. Writes an embedded X3D tag and included content for the <tt>view-object</tt> child of this object. The <tt>view-object</tt> child should exist and be of type <tt>web-drawing</tt>." embedded-x3dom-world (&key (include-view-controls? nil)) (declare (ignore include-view-controls?)) ;; (the (restore-slot-default! :js-to-eval)) (with-cl-who () (when (typep (the :view-object) 'null-part) (error "A valid :view-object of type web-drawing is required in the sheet to call the :write-embedded-x3d-world function.")) (cond ((the no-graphics?) (htm ((:div :id "empty-viewport" :class "empty-viewport") (str (the empty-display-list-message))))) (t (let ((*display-controls* (the display-controls-hash))) (htm (:span ((:|X3D| :id "x3dom-1" :style "background: #d3d3d3" :width (format nil "~apx" (the view-object page-width)) :height (format nil "~apx" (the view-object page-length)) ) (:|Scene| ((:|navigationinfo| :|id| "navi" :|transitionTime| "0.0" )) (with-format (x3d *stream*) (let ((*onclick-function* (the onclick-function))) (write-the view-object cad-output)))))) ;; ;; FLAG -- conditionalize this in for tasty compatibility. ;; ;;((:script) "x3dom.reload();") )))))) (raster-graphics () (when (typep (the :view-object) 'null-part) (error "A valid :view-object of type web-drawing is required in the sheet to call the :write-geometry method.")) (with-cl-who () (cond ((the no-graphics?) (htm ((:div :id "empty-viewport" :class "empty-viewport") (str (the empty-display-list-message))))) ((typep (the image-url) 'error) (the (set-slot! :view-toggle nil)) (write-the geometry-error)) (t (let ((image-url (the image-url))) (htm ((:img :id "myimage" :style "cursor: crosshair;" :src image-url :onclick (the (gdl-ajax-call :function-key :dig-point)) :border 0 :width (the :view-object :page-width) :height (the :view-object :page-length)))))))))))
17,116
Common Lisp
.lisp
370
37.345946
122
0.633056
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
853a63e3b039e4c9982dde85347df76f6793d31a7a4d75722120b004aa416f19
35,999
[ -1 ]
36,000
x3d-try.lisp
lisp-mirror_gendl/gwl-graphics/gwl/source/x3d-try.lisp
(in-package :gwl) (publish :path "/x3d-box-red" :function #'(lambda(req ent) (with-http-response (req ent) (with-http-body (req ent) (let ((*stream* *html-stream*)) (with-cl-who () (:shape (:appearance ((:material :diffusecolor "1 0 0"))) ((:box :size "10 20 30"))))))))) (publish :path "/x3d-box-blue" :function #'(lambda(req ent) (with-http-response (req ent) (with-http-body (req ent) (let ((*stream* *html-stream*)) (with-cl-who () (:shape (:appearance ((:material :diffusecolor "0 0 1"))) ((:box :size "10 20 30")))))))))
616
Common Lisp
.lisp
15
34.133333
108
0.553512
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
84fea4ec65239b6fe134e7707a5574c62b24ee0b94bab4bae9f9ce574f7c5559
36,000
[ -1 ]
36,001
web-drawing.lisp
lisp-mirror_gendl/gwl-graphics/gwl/source/web-drawing.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (define-object web-drawing (geom-base::renderer-mixin base-drawing ) :documentation (:description "Container object for displaying a view of geometric or text-based entities in a web application. This is supposed to be the type of the view-object hidden-child of base-html-graphics-sheet. Also, in a GWL application using application-mixin, you can include one object of this type in the ui-display-list-leaves. " :examples "<pre> (in-package :gwl-user) (define-object test-html-graphics-sheet (base-html-graphics-sheet) :objects ((b-splines :type 'test-b-spline-curves) (boxed-spline :type 'surf:boxed-curve :curve-in (the b-splines (curves 0)) :orientation (alignment :top (the (face-normal-vector :rear))) :show-box? t) (view-object :type 'web-drawing :page-length (the graphics-height value) :page-width (the graphics-width value) :projection-vector (getf *standard-views* (the view)) :object-roots (the ui-display-roots)) (graphics-height :type 'text-form-control :default 350) (graphics-width :type 'text-form-control :default 500) (bg-color :type 'text-form-control :default :black) (fg-color :type 'text-form-control :default :white)) :computed-slots ((background-color (lookup-color (the :bg-color value) :format :decimal)) (foreground-color (lookup-color (the :fg-color value) :format :decimal)) (view :trimetric :settable) (\"list of gdl objects. Objects to be displayed in the graphics window.\" ui-display-roots (list (the b-splines) (the boxed-spline))))) (define-lens (html-format test-html-graphics-sheet)() :output-functions ((main-sheet () (with-html-output (*html-stream* nil :indent t) (:html (:head (:title \"Test HTML Graphics Sheet\")) (:body (when gwl:*developing?* (the write-development-links)) (:h2 (:center \"Test HTML Graphics Sheet\")) (with-html-form (:cl-who? t) (:table (:tr (:td (:ul (:li (str (the graphics-height html-string))) (:li (str (the graphics-width html-string))) (:li (str (the bg-color html-string))) (:li (str (the fg-color html-string)))) (:p (:input :type :submit :value \" OK \"))) (:td (write-the geometry))))))))))) (publish :path \"/t-h-g-s\" :function #'(lambda(req ent) (gwl-make-object req ent \"gwl-user::test-html-graphics-sheet\"))) (define-object test-b-spline-curves (base-object) :input-slots ((control-points (list (make-point 0 0 0) (make-point 2 3.0 0.0) (make-point 4 2.0 0.0) (make-point 5 0.0 0.0) (make-point 4 -2.0 0.0) (make-point 2 -3.0 0.0) (make-point 0 0 0)))) :objects ((curves :type 'surf:b-spline-curve :sequence (:size 6) :control-points (the control-points) :degree (1+ (the-child :index)) :display-controls (list :line-thickness (* 0.3 (the-child index)) :color (ecase (the-child index) (0 :red) (1 :orange) (2 :yellow) (3 :green) (4 :blue) (5 :red-violet)))) (points :type 'point :sequence (:size (length (rest (the control-points)))) :center (nth (the-child index) (rest (the control-points))) :display-controls (list :color :green)))) </pre> " ) :input-slots (("String. Unique ID on the page for the raphael canvas div. By default this is passed in from the base-ajax-graphics-sheet and based on its root-path, but can be specified manually if you are making a web-drawing on your own. Defaults (in the standalone case) to \"RaphaelCanvas\"" raphael-canvas-id "RaphaelCanvas") ("3D vector. This is the normal vector of the view plane onto which to project the 3D objects. Defaults to (getf *standard-views* :top)." projection-vector (getf *standard-views* :top)) ("List of GDL objects. The leaves of each of these objects will be included in the geometry display. Defaults to nil." object-roots nil) ("List of GDL objects. These nodes (not their leaves but the actual objects) will be included in the geometry display. Defaults to nil." objects nil) (view-scale (getf (the main-view view-contents-data) :view-scale)) (view-center (getf (the main-view view-contents-data) :view-center)) ("List of GDL objects. These objects are not used in computing the scale or centering for the display list. Defaults to nil." immune-objects nil)) :computed-slots ((user-center (make-vector 0 0) :settable) (user-scale 1 :settable) (center (make-point 0 0 0)) (image-file (dolist (object (the objects)) (when (and (typep object 'gdl::gdl-basis) (the-object object image-file)) (return (the-object object image-file)))))) :trickle-down-slots (user-scale) :objects (("GDL object of type geom-base:base-view. This is the actual drawing view which is used to present the geometry. Defaults to an internally-computed object, this should not be overridden in user code." main-view :type 'base-view ;;:center (make-point 0 0 0) :pass-down (projection-vector object-roots objects view-scale view-center user-scale ;;user-center -- FLAG -- probably not needed? immune-objects))))
7,181
Common Lisp
.lisp
131
41.717557
141
0.592157
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
e77e5dd4d965e430158966b1edba00884275fa5e596af1a35857a3386cbb3e13
36,001
[ -1 ]
36,002
process-graphics-fields.lisp
lisp-mirror_gendl/gwl-graphics/gwl/source/process-graphics-fields.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defun process-graphics-fields (query query-plist root-object requestor) (setq query-plist (mapcan #'(lambda(key value) (list (if (or (string-equal key "image.x") (string-equal key "image.y")) (make-keyword (string-upcase key)) key) value)) (plist-keys query-plist) (plist-values query-plist))) (let ((tree-toggle-path (let ((item (find ":tree-toggle+" (mapcar #'string-downcase (mapcar #'first query)) :test #'search))) (when item (list (query-arg-to-root-path nil nil (subseq item (length ":tree-toggle+") (- (length item) 2))) t)))) (view-object (let ((candidate (the-object requestor :view-object))) (when (not (typep candidate 'null-part)) candidate))) (restore? (getf query-plist :restore-view)) (image.x (read-safe-string (getf query-plist :IMAGE.X))) (image.y (read-safe-string (getf query-plist :IMAGE.Y)))) (the-object requestor toggle-view-toggle!) (cond ((second tree-toggle-path) (let ((tree-toggle-node (the-object root-object (:follow-root-path (first tree-toggle-path))))) (the-object tree-toggle-node (:set-slot! :tree-state (ecase (the-object tree-toggle-node :tree-state) (:open :closed) (:closed :open)))))) (restore? (the-object view-object (restore-slot-defaults! (list :user-center :user-scale)))) ((and image.x image.y) (the-object requestor (dig-point :x image.x :y image.y)))) (remove-plist-key (remove-plist-key query-plist :IMAGE.X) :IMAGE.Y)))
2,866
Common Lisp
.lisp
52
41.846154
111
0.592115
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
0a5c4c69b38e96942919afe8d626db89a4eff3f337fd8bf8e0f37992f60c218f
36,002
[ -1 ]
36,003
test-geom.lisp
lisp-mirror_gendl/gwl-graphics/gwl/source/test-geom.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl-user) #+nil (define-object assy (application-mixin) :computed-slots ((width (read-from-string (or (getf (the :query-plist) :width) "10"))) (length (read-from-string (or (getf (the :query-plist) :length) "10"))) (height (read-from-string (or (getf (the :query-plist) :height) "10"))) (ui-display-list-objects (list (the box) (the cone) (the cylinder) (the torus) (the sphere) ;;(the spherical-cap) (the box-2) (the box-3) (the arc) (the route-pipe) (the polyline-projection) (the polyline) ))) :objects ((box :type 'box) (cone :type 'cone :radius-1 1.5 :radius-2 2 :arc (half pi) :inner-radius-1 1 :inner-radius-2 1.5) (cone-right :type 'cone :radius-1 0 :radius-2 5 :display-controls (list :color :green)) (cone-left :type 'cone :radius-1 0 :radius-2 5 :display-controls (list :color :red) :center (translate (the center) :front 10) :orientation (alignment :left (the (face-normal-vector :left)) :top (the (face-normal-vector :top)) :rear (the (face-normal-vector :front)))) (cylinder :type 'cylinder :radius 1 :center (translate (the :center) :down 3) :inner-radius 0.5) (torus :type 'torus :center (translate (the :center) :up 5) :arc pi :major-radius (the :length) :minor-radius (* (the :length) 0.30) :inner-minor-radius (* (the :length) 0.40) :draw-centerline-arc? t :number-of-transverse-sections 10 :number-of-longitudinal-sections 7) (sphere :type 'sphere :center (the :center) :radius (/ (the :box :length) 3) :number-of-horizontal-sections 21 :number-of-vertical-sections 10) ;; ;; FLAG -- this spherical cap is bugged. ;; #+nil(spherical-cap :type 'spherical-cap :center (the :center) :axis-length (twice (the-child :base-radius)) :base-radius (/ (the :box :length) 3) ;;:cap-thickness (* (the-child :axis-length) 0.05) :number-of-horizontal-sections 21 :number-of-vertical-sections 10) (box-2 :type 'box :display-controls (list :color :red) :length 2 :width 4 :height 8 :orientation (alignment :top (the (:face-normal-vector :right)) :right (rotate-vector-d (the (:face-normal-vector :rear)) 45 (the (:face-normal-vector :right)))) :center (the :center)) (box-3 :type 'box :length 2 :width 2 :height 2 :center (translate (the (:edge-center :rear :left)) :down 3)) (arc :type 'arc :radius 3 :center (the (:face-center :rear)) :orientation (alignment :top (the (:face-normal-vector :rear)))) (route-pipe :type 'route-pipe :display-controls (list :color :blue) ;;:default-bend-radius 0.5 :radius-list (list 0.5 1 2) :outer-pipe-radius .3 :inner-pipe-radius .2 :vertex-list (list (make-point -5 -5 -5) (make-point 0 0 0) (make-point 5 -5 -5) (make-point 5 5 5))) (polyline-projection :type 'global-filleted-polygon-projection :display-controls (list :color :green) :default-radius 0.5 :vertex-list (list (the (:face-center :left)) (the (:face-center :right)) (the (:face-center :rear)) (the (:face-center :front)) (the (:face-center :left))) :projection-vector (the (:face-normal-vector :top)) :projection-depth 3) (polyline :type 'global-filleted-polyline :default-radius 0.5 :vertex-list (list (the (:face-center :left)) (the (:face-center :right)) (the (:face-center :rear)) (the (:face-center :front)) )))) #+nil (publish :path "/gwl/test-geom" :function #'(lambda(req ent) (gwl-make-part req ent "gwl-user::assy")))
6,164
Common Lisp
.lisp
118
33.669492
101
0.492455
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
ce2f90ae9dd7e91272e55ca6ae565b0a22ff52b24c929ef5f7303e5fdda3323e
36,003
[ -1 ]
36,004
base-html-graphics-sheet.lisp
lisp-mirror_gendl/gwl-graphics/gwl/source/base-html-graphics-sheet.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (define-object geometry-view-mixin () :documentation (:description "Internal mixin for use inside e.g. base-html-graphics-sheet.") :input-slots ((display-controls-hash nil) ("Number. Length (\"height\" of screen window) of the graphics viewport. Default is 300." length 300) ("Number. Width of the graphics viewport. Default is 300." width 300) (onclick-function nil) (use-bsplines? nil) ("GDL web-drawing object. This must be overridden in the specialized class." view-object nil) ) :computed-slots ((view-toggle nil :settable) (pdf-url (let ((url (format nil "~a~a" (let ((url (the url)))(subseq url 0 (- (length url) (length "index.html")))) (make-pathname :name "image" :type "pdf")))) ;; ;; Pre-demand the output in order to set up dependency tracking. ;; (with-format (pdf (make-broadcast-stream) :page-width (the view-object page-width) :page-length (the view-object page-length)) (write-the view-object cad-output)) (publish :path url :content-type "application/pdf" :format :binary :function #'(lambda (req ent) (let ((*display-controls* (the display-controls-hash))) (with-http-response (req ent) (setf (reply-header-slot-value req :cache-control) "no-cache") (with-http-body (req ent) (with-format (pdf (request-reply-stream req) :page-width (the view-object page-width) :page-length (the view-object page-length)) (write-the view-object cad-output))))))) (push url (gethash (make-keyword (the instance-id)) *url-hash-table*)) url)) (x3d-url (let ((url (format nil "~a~a" (let ((url (the url)))(subseq url 0 (- (length url) (length "index.html")))) (make-pathname :name "model" :type "x3d")))) (the view-toggle) ;; ;; Pre-demand the output in order to set up dependency tracking. ;; (with-format (x3d (make-broadcast-stream)) (write-the view-object cad-output)) ;; ;; FLAG - find a leighter-weight way to pre-demand the output. ;; (publish :path url :content-type "model/x3d+xml" :function (lambda (req ent) (let ((*display-controls* (the display-controls-hash))) (with-http-response (req ent) (setf (reply-header-slot-value req :cache-control) "max-age=1") (with-http-body (req ent) (let ((reply-stream (request-reply-stream req)) (*req* req) (*ent* ent)) (let ((*onclick-function* (the onclick-function))) (let ((*stream* reply-stream)) (with-cl-who () (:|X3D| (:|Scene| (with-format (x3d reply-stream :use-bsplines? (the use-bsplines?)) (write-the view-object cad-output))))))))))))) (push url (gethash (make-keyword (the instance-id)) *url-hash-table*)) url) :uncached) (vrml-url (let ((url (format nil "~a~a" (let ((url (the url)))(subseq url 0 (- (length url) (length "index.html")))) (make-pathname :name "model" :type "wrl")))) ;; ;; Pre-demand the output in order to set up dependency tracking. (with-format (vrml (make-broadcast-stream)) (write-the view-object cad-output)) ;; ;; FLAG - find a more lightweight method to pre-demand the output. ;; (publish :path url :content-type "x-world/x-vrml" :function (lambda (req ent) (let ((*display-controls* (the display-controls-hash))) (with-http-response (req ent) ;;(setf (reply-header-slot-value req :cache-control) "no-cache") ;;(setf (reply-header-slot-value req :cache-control) "max-age=2") (setf (reply-header-slot-value req :cache-control) "max-age=1") (with-http-body (req ent) (let ((reply-stream (request-reply-stream req)) (*req* req) (*ent* ent)) (when *debug?* (let ((*onclick-function* (the onclick-function))) (with-format (vrml "/tmp/try.wrl") (write-the view-object cad-output)))) (let ((*onclick-function* (the onclick-function))) (with-format (vrml reply-stream :use-bsplines? (the use-bsplines?)) (write-the view-object cad-output))))))))) (push url (gethash (make-keyword (the instance-id)) *url-hash-table*)) url)) (2d-boxes? (the view-object main-view 2d-boxes)) (image-url (if (the 2d-boxes?) (let ((url (format nil "~a~a" (let ((url (the url)))(subseq url 0 (- (length url) (length "index.html")))) (make-pathname :name (format nil "image~a" (gensym)) :type (ecase (the image-format) (:png "png") (:jpeg "jpg")))))) ;; ;; Pre-demand the output in order to set up dependency tracking. ;; (the view-toggle) (multiple-value-bind (result error) (;;ignore-errors progn (the view-object objects) (the view-object object-roots) (ecase (the image-format) (:png (with-format (pdf (make-broadcast-stream) :page-width (the view-object page-width) :page-length (the view-object page-length) :background-color (the background-color) :foreground-color (the foreground-color)) (write-the view-object cad-output))) (:jpeg (with-format (jpeg (make-broadcast-stream) :page-width (the view-object page-width) :page-length (the view-object page-length) :background-color (the background-color) :foreground-color (the foreground-color) ) (write-the view-object cad-output))))) (declare (ignore result)) (if (the view-object image-file) (publish-file :path url :file (the view-object image-file)) (unless (typep error 'error) (publish :path url :content-type "image/png" :format :binary :function #'(lambda (req ent) (let ((*display-controls* (the display-controls-hash))) (with-http-response (req ent) (setf (reply-header-slot-value req :cache-control) "no-cache") (with-http-body (req ent) (ecase (the image-format) (:png (with-format (png (request-reply-stream req) :page-width (the view-object page-width) :page-length (the view-object page-length) :background-color (the background-color) :foreground-color (the foreground-color)) (write-the view-object cad-output))) (:jpeg (with-format (jpeg (request-reply-stream req) :page-width (the view-object page-width) :page-length (the view-object page-length) :background-color (the background-color) :foreground-color (the foreground-color)) (write-the view-object cad-output))))))))) ;; ;; FLAG -- we should unpublish all the previous ones here. ;; (push url (gethash (make-keyword (the instance-id)) *url-hash-table*)))) (if (typep error 'error) error url))) "/static/gwl/images/slack_in.gif" ))) :hidden-objects (;;(view-object :type 'web-drawing) )) (define-object base-html-graphics-sheet (base-html-sheet geometry-view-mixin base-object) :documentation (:description "This mixin allows a part to be displayed as a web page in GWL, and to contain one graphics area. It requires the geom-base module to be loaded. This will probably be extended to allow more than one graphics area. This mixin inherits from base-html-sheet, so just like with <tt>base-html-sheet</tt> you can prepare the output with the <tt>write-html-sheet</tt> function in a the object which mixes this in, or in a <tt>main-sheet</tt> output-function in an html-format view of the object. ") :input-slots (("Plist of keywords and 3D vectors. Indicates the views to show in the graphics controls." standard-views *standard-views*) (available-image-formats (list :png :jpeg)) ("Keyword symbol. Determines the default image format. Defaults to :png" image-format :png :settable) ("Boolean. Determines whether to use native bspline data in the vrml" use-bsplines? nil ) ("Keyword symbol. Determines the default view from the <tt>standard-views</tt>. Defaults to :trimetric." view :trimetric :settable) ("Keyword symbol, one of :in, :out, or :none, or nil. If :in, then clicks in the graphics area will increase the zoom factor by (the zoom-factor). If :out, then clicks will decrease the factor by that amount. If :none or nil, then clicks will have no effect." zoom-mode :in :settable) ("Number. The factor used for zooming in or out." zoom-factor 2 :settable) ("Keyword symbol, one of <tt>:zoom-and-center</tt>, <tt>:report-point</tt>, or <tt>:measure-distance</tt>. <ul> <li>If <tt>:zoom-and-center</tt>, sets the user-center and user-scale accordingly when graphics area is clicked.</li> <li>If <tt>:report-point</tt>, the slot <tt>digitized-point</tt> is set with the x y value. </li> <li>If <tt>measure-distance</tt>, the slot <tt>:digitized-distance</tt> is set with the resultant distance.</li> </ul> Default is <tt>:zoom-and-center</tt>" digitation-mode :zoom-and-center :settable) (zoom-factor-renderer 1 :settable) (field-of-view-default 1 :settable :defaulting)) :trickle-down-slots (field-of-view-default) :computed-slots ( (digitation-modes (list :zoom-and-center :report-point :measure-distance)) (digitized-point nil :settable) (digitized-distance nil :settable) (pan-distance 50 :settable) (view-depth 0 :settable) (view-toggle nil :settable) (no-graphics? (and (null (the :view-object :object-roots)) (null (the :view-object :objects)))) ) :functions ( (dig-point (&key (x *clicked-x*) (y *clicked-y*)) (when *debug?* (print-variables x y)) (when (and x y) (let ((local-point (make-point (- x (half (the view-object width))) (let ((y (- (the view-object length) y))) (- y (half (the view-object length))))))) (when *debug?* (print-variables local-point)) (let ((digitized-point (add-vectors (the view-object user-center) (scalar*vector (/ (the view-object user-scale)) local-point)))) (when *debug?* (print-messages digitation-mode)) (ecase (the digitation-mode) (:measure-distance (let ((new-point (the view-object main-view (model-point (make-point (get-x local-point) (get-y local-point) 0)))) (old-point (the digitized-point))) (if (null old-point) (progn (the (set-slot! :digitized-point new-point)) (the (restore-slot-default! :digitized-distance))) (progn (the (set-slot! :digitized-distance (list :total (3d-distance old-point new-point) :x (- (get-x new-point) (get-x old-point)) :y (- (get-y new-point) (get-y old-point)) :z (- (get-z new-point) (get-z old-point))))) (the (restore-slot-default! :digitized-point)))))) (:report-point (the (report-point (get-x local-point) (get-y local-point)))) (:zoom-and-center (when *debug?* (format t "we are on zoom-and-center...~%")) (when *debug?* (print-variables (the view-object width) (the view-object length))) (let ((out-of-bounds? (and (> x (- (the view-object width) 30)) (> y (- (the view-object length) 30))))) (print-variables out-of-bounds?) (when (and (not out-of-bounds?) (member (the zoom-mode) (list :in :out))) (when *debug?* (format t "Zooming in the graphics...~%")) (let ((zoom-factor (if (eql (the zoom-mode) :in) (the zoom-factor) (/ (the zoom-factor))))) (the view-object (set-slot! :user-center (make-point (get-x digitized-point) (get-y digitized-point)))) (the view-object (set-slot! :user-scale (* (the view-object user-scale) zoom-factor)))))))))))) ("Void. Process the points selected by digitizing in the graphics. You can override this function to do your own processing. By default, it prints the information to the console. :arguments (x \"Number. The X Coordinate of the digitized point.\" y \"Number. The Y Coordinate of the digitized point.\")" report-point (x y) (print-variables x y) (let ((adjusted (scalar*vector (the view-object user-scale) (add-vectors (make-point (get-x (the view-object user-center) ) (get-y (the view-object user-center)) 0) (scalar*vector (/ (the view-object user-scale)) (make-point x y 0)))))) (let ((model-point (the view-object main-view (model-point adjusted)))) (the (set-slot! :digitized-point model-point))))) ("Keyword symbol, string, list, or vector. Default background for the graphics viewport. Can be specified as a name (keyword or string) in *color-table*, an html-style hex string (starting with #), or a decimal RGB triplet in a list or vector. The default comes from the :background entry in <tt>*colors-default*</tt>." background-color () (lookup-color (getf *colors-default* :background) :format :decimal)) ("Keyword symbol, string, list, or vector. Default foreground for the graphics viewport. Can be specified as a name (keyword or string) in *color-table*, an html-style hex string (starting with #), or a decimal RGB triplet in a list or vector. The default comes from the :foreground entry in <tt>*colors-default*</tt>." foreground-color () (lookup-color (getf *colors-default* :foreground) :format :decimal)) (toggle-view-toggle! () (the (set-slot! :view-toggle (not (the view-toggle))))) (write-geometry-links (&key (include-view-controls? t)) (write-the (geometry-links :include-view-controls? include-view-controls?))) ("Void. Writes an image tag and publishes an image for the <tt>view-object</tt> child of this object. The <tt>view-object</tt> child should exist and be of type <tt>web-drawing</tt>. For objects of type <tt>gwl:application-mixin</tt> or <tt>gwl:node-mixin</tt>, this is done automatically. For the time being, we recommend that you use <tt>gwl:application-mixin</tt> or <tt>gwl:node-mixin</tt> if you want to display geometric parts in a GWL application. :&key ((include-view-controls? t) \"Boolean. Determines whether the standard view controls are displayed below the image.\")" write-geometry (&key (include-view-controls? t) use-ajax?) (write-the (geometry :include-view-controls? include-view-controls? :use-ajax? use-ajax?))) (write-view-controls (&key width) (write-the (view-controls :width width))) ("Void. Writes an OBJECT tag and publishes an X3D world for the <tt>view-object</tt> child of this object. The <tt>view-object</tt> child should exist and be of type <tt>web-drawing</tt>." write-embedded-x3d-world (&key (include-view-controls? nil)) (write-the (embedded-x3d-world :include-view-controls? include-view-controls?))) ("Void. Writes an EMBED tag and publishes a VRML world for the <tt>view-object</tt> child of this object. The <tt>view-object</tt> child should exist and be of type <tt>web-drawing</tt>." write-embedded-vrml-world (&key (include-view-controls? t)) (write-the (embedded-vrml-world :include-view-controls? include-view-controls?))) (write-image-format-selector () (write-the image-format-selector)) (write-vrml-view-controls (&key width) (write-the (vrml-view-controls :width width))))) (define-lens (html-format base-html-graphics-sheet)() :output-functions ( (geometry-error () (html ((:table :border 1 :cellspacing 0 :cellpadding 0 :bgcolor :white) (:tr ((:td :width (the :view-object :width) :height (the :view-object :length) :align :center :valign :center) (:big (:b "Graphics Threw Error: " (:princ-safe (the image-url))))))))) ("Void. Writes an image tag and publishes an image for the <tt>view-object</tt> child of this object. The <tt>view-object</tt> child should exist and be of type <tt>web-drawing</tt>. For objects of type <tt>gwl:application-mixin</tt> or <tt>gwl:node-mixin</tt>, this is done automatically. For the time being, we recommend that you use <tt>gwl:application-mixin</tt> or <tt>gwl:node-mixin</tt> if you want to display geometric parts in a GWL application. :&key ((include-view-controls? t) \"Boolean. Determines whether the standard view controls are displayed below the image.\")" geometry (&key (include-view-controls? t) use-ajax?) (when (typep (the :view-object) 'null-part) (error "A valid :view-object of type web-drawing is required in the sheet to call the :write-geometry method.")) (cond ((and (null (the :view-object :object-roots)) (null (the :view-object :objects))) (html ((:table :border 1 :cellspacing 0 :cellpadding 0 :bgcolor :white) (:tr ((:td :width (the :view-object :width) :height (the :view-object :length) :align :center :valign :center) (:big (:b "No Graphics Object Specified")))) ))) ((typep (the image-url) 'error) (the (set-slot! :view-toggle nil)) (write-the geometry-error)) (t (let ((image-url (the image-url))) (html ((:table :border 0 :cellspacing 0 :cellpadding 0) (:tr ((:td :bgcolor :yellow) (if use-ajax? (html ((:img :id "myimage" :style "cursor: pointer;" :src image-url :onclick (format nil "return digitizePoint(event, '~a', '~s');" (the instance-id) (the root-path-local)) :border 0 :width (the :view-object :page-width) :height (the :view-object :page-length)))) (html ((:input :type :image :src image-url :alt "Loading Graphics..." :name "image" :border 0 :width (the :view-object :page-width) :height (the :view-object :page-length))))))) ;; FLAG!: the following is untested but working in the vrml-world part of the code (if include-view-controls? (html (:tr (:td (write-the (view-controls :width (the :view-object :width) :use-ajax? use-ajax?)) (html :br))))))))))) (geometry-links (&key (include-view-controls? t)) (when (typep (the :view-object) 'null-part) (error "A valid :view-object of type web-drawing is required in the sheet to call the :write-geometry method.")) (html ((:table :cellspacing 0 :cellpadding 0 :bgcolor :white) (:tr ((:td :width (the :view-object :width) :height (the :view-object :length) :align :center :valign :center) (:ul (:li ((:a :href (the pdf-url)) "View PDF File of Geometry")) (:li ((:a :href (the vrml-url)) "View VRML File of Geometry"))))) ;; FLAG!: the following is untested but working in the vrml-world part of the code (if include-view-controls? (html (:tr ((:td :width (the :view-object :width) :height 100) (write-the (:view-controls :width (the :view-object :width))) (html :br)))))))) (view-controls (&key width use-ajax?) (if use-ajax? (html ((:table :if* width :width width :cellpadding 1 :cellspacing 0) (:tr ((:td :align :center :bgcolor (gethash :goldenrod-medium *color-table*)) "View from " ((:select :size 1 :onchange (format nil "gdlsetcontrol ('~a', '~s', ':view', this.value)" (the instance-id) (the root-path-local))) (dolist (view-key (plist-keys (the :standard-views))) (html ((:option :value view-key :if* (eql view-key (the :view)) :selected :selected) (:princ (string-capitalize view-key))))))) (:newline) ((:td :align :center :valign :center :bgcolor (gethash :red-violet-medium *color-table*)) (:newline) ((:select :size 1 :onchange (format nil "gdlsetcontrol ('~a', '~s', ':digitation-mode', this.value)" (the instance-id) (the root-path-local))) (dolist (dig-mode (the digitation-modes)) (html ((:option :value dig-mode :if* (eql dig-mode (the digitation-mode)) :selected :selected) (:princ (string-capitalize dig-mode)))))) ((:input :onclick (format nil "gdlsetcontrol ('~a', '(:view-object :viewport)', '(:user-center :user-scale)', 'gdl::restore-default')" (the instance-id)) :type :submit :value "Restore" )) (case (the digitation-mode) (:report-point (html :br (if (null (the digitized-point)) (html "Please Select a Point") (html (:princ (format nil "Selected: (~4,2f, ~4,2f, ~4,2f)" (get-x (the digitized-point)) (get-y (the digitized-point)) (get-z (the digitized-point)))))))) (:measure-distance (html :br (cond ((the digitized-distance) (html "total: " (:princ (format nil "~4,2f," (getf (the digitized-distance) :total))) " x:" (:princ (format nil "~4,2f," (getf (the digitized-distance) :x))) " y:" (:princ (format nil "~4,2f," (getf (the digitized-distance) :y))) " z:" (:princ (format nil "~4,2f" (getf (the digitized-distance) :z))))) ((null (the digitized-point)) (html "Please Select the First Point")) (t (html "Please Select the Second Point")) )))))) (:tr ((:td :bgcolor (gethash :blue-steel-light *color-table*)) (:table (:tr (:td "Zoom Factor: " ((:input :type :string :size 1 :value (the zoom-factor) :onchange (format nil "gdlsetcontrol ('~a', '~s', ':zoom-factor', this.value)" (the instance-id) (the root-path-local)))))))) (the write-image-format-selector)))) (html ((:table :if* width :width width :cellpadding 1 :cellspacing 0) (:tr ((:td :align :center :bgcolor (gethash :goldenrod-medium *color-table*)) ((:input :type :submit :name :change-view :value "View")) " from " ((:select :name :view :size 1 :onchange "this.form.submit()") (dolist (view-key (plist-keys (the :standard-views))) (html ((:option :value view-key :if* (eql view-key (the :view)) :selected :selected) (:princ (string-capitalize view-key))))))) ((:td :align :center :valign :center :bgcolor (gethash :red-violet-medium *color-table*)) ((:input :type :submit :name :restore-view :value "Restore")) " the Default View")) (:tr ((:td :bgcolor (gethash :blue-steel-light *color-table*)) (:table (:tr (:td "Click in Graphics to Recenter and Zoom In by a factor of " ((:input :type :string :size 1 :name :zoom-factor :value (the :zoom-factor)))) (:td ((:select :name :digitation-mode :size 1 :onchange "this.form.submit()") (dolist (view-key (the digitation-modes) ;;(the (list :zoom-and-center :report-point) ) (html ((:option :value view-key :if* (eql view-key (the :digitation-mode)) :selected :selected) (:princ (string-capitalize view-key)))))) (case (the digitation-mode) (:report-point (html :br (if (null (the digitized-point)) (html "Please Select a Point") (html (:princ (format nil "Selected: (~4,2f, ~4,2f, ~4,2f)" (get-x (the digitized-point)) (get-y (the digitized-point)) (get-z (the digitized-point)))))))) (:measure-distance (html :br (cond ((the digitized-distance) (html "total: " (:princ (format nil "~4,2f," (getf (the digitized-distance) :total))) " x:" (:princ (format nil "~4,2f," (getf (the digitized-distance) :x))) " y:" (:princ (format nil "~4,2f," (getf (the digitized-distance) :y))) " z:" (:princ (format nil "~4,2f" (getf (the digitized-distance) :z))))) ((null (the digitized-point)) (html "Please Select the First Point")) (t (html "Please Select the Second Point")) )))) ))) ".") (the write-image-format-selector)))))) ("Void. Writes an OBJECT tag and publishes an X3D world for the <tt>view-object</tt> child of this object. The <tt>view-object</tt> child should exist and be of type <tt>web-drawing</tt>." embedded-x3d-world (&key (include-view-controls? nil)) (when (typep (the :view-object) 'null-part) (error "A valid :view-object of type web-drawing is required in the sheet to call the :write-embedded-x3d-world function.")) (cond ((and (null (the :view-object :object-roots)) (null (the :view-object :objects))) (html-stream *stream* ((:table :cellspacing 0 :cellpadding 0 :bgcolor :white) (:tr ((:td :width (the :view-object :width) :height (the :view-object :height) :align :center :valign :center) (:big (:b "No Graphics Object Specified"))))))) (t (let ((x3d-url (the x3d-url))) (html-stream *stream* ((:table :cellspacing 0 :cellpadding 0) (:tr (:td ((:object :id "x3d" :type "model/x3d+xml" ;;:src x3d-url :data x3d-url :width (the view-object page-width) :height (the view-object page-length))))) (when include-view-controls? (html (:tr ((:td :width (the :view-object :width) :height 100) (the (write-vrml-view-controls :width (the :view-object :width))) (html :br))))))))))) ("Void. Writes an EMBED tag and publishes a VRML world for the <tt>view-object</tt> child of this object. The <tt>view-object</tt> child should exist and be of type <tt>web-drawing</tt>." embedded-vrml-world (&key (include-view-controls? t)) (when (typep (the :view-object) 'null-part) (error "A valid :view-object of type web-drawing is required in the sheet to call the :write-embedded-vrml-world function.")) (cond ((and (null (the :view-object :object-roots)) (null (the :view-object :objects))) (html-stream *stream* ((:table :cellspacing 0 :cellpadding 0 :bgcolor :white) (:tr ((:td :width (the :view-object :width) :height (the :view-object :height) :align :center :valign :center) (:big (:b "No Graphics Object Specified"))))))) (t (let ((vrml-url (the vrml-url))) (html-stream *stream* ((:table :cellspacing 0 :cellpadding 0) (:tr (:td ((:embed :type "model/vrml" :src vrml-url :width (the view-object page-width) :vrml_dashboard "false" :height (the view-object page-length))) )) (if include-view-controls? (html (:tr ((:td :width (the :view-object :width) :height 100) (the (write-vrml-view-controls :width (the :view-object :width))) (html :br))))))))))) (image-format-selector () (html ((:td :align :center :bgcolor (gethash :green-lime *color-table*)) ((:input :type :submit :name :change-view-format :value "Format")) ((:select :name :image-format :size 1 :onchange "this.form.submit()") (dolist (view-key (the available-image-formats)) (html ((:option :value view-key :if* (eql view-key (the :image-format)) :selected :selected) (:princ (string-capitalize view-key))))))))) (vrml-view-controls (&key width) (html ((:table :if* width :width width :cellpadding 1 :cellspacing 0) (:tr (the write-image-format-selector) ((:td :align :center :bgcolor (gethash :goldenrod-medium *color-table*)) ((:input :type :submit :name :change-view :value "View")) " from " ((:select :name :view :size 1 :onchange "this.form.submit()") (dolist (view-key (plist-keys (the :standard-views))) (html ((:option :value view-key :if* (eql view-key (the :view)) :selected :selected) (:princ (string-capitalize view-key))))))) ((:td :align :center :bgcolor (gethash :blue-steel *color-table*)) "Zoom Factor: " ((:input :type :text :size 5 :name :zoom-factor-renderer :value (the zoom-factor-renderer)))) ((:td :align :center :bgcolor (gethash :lime *color-table*)) "Field of View: " ((:input :type :text :size 5 :name :field-of-view-default :value (the field-of-view-default)))) ((:td :align :center :bgcolor (gethash :red-orange *color-table*)) ((:input :type :submit :name :apply :value " Apply"))) ((:td :align :center :valign :center :bgcolor (gethash :goldenrod-medium *color-table*)))))))))
38,294
Common Lisp
.lisp
623
40.288925
151
0.496685
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
bfd294a8a6038d6ed0a803d6de5dedaea8edafdcb6c8db5f815dff74e6fc0a9a
36,004
[ -1 ]
36,005
layout-mixin.lisp
lisp-mirror_gendl/gwl-graphics/gwl/source/layout-mixin.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (define-object layout-mixin (base-html-graphics-sheet) :documentation (:description "This is mixed into both <tt>node-mixin</tt> and <tt>application-mixin</tt>. It contains the common messages for nodes in a GWL application tree. For any <tt>node-mixin</tt> or <tt>application-mixin</tt>, you may override the default (empty) <tt>model-inputs</tt> output-function of the corresponding html-format view to make specific model-inputs for that node.") :input-slots (("String. The title to display on the page and in the tree. Defaults to <tt>(the strings-for-display)</tt>." page-title (the :strings-for-display)) ("Boolean. Indicates whether to display the title at the top of the page. Defaults to T." show-title? t) ("String. Title for the model-inputs section. Defaults to \"Model Inputs\"." inputs-title "Model Inputs") ("String. Title for the Tree section. Defaults to \"Assembly Tree\" if the tree-root is only a subclass of <tt>application-mixin</tt>, and \"Assembly Tree\" if the tree-root is an actual node with child applications." tree-title (if (typep (the :tree-root) 'node-mixin) "Assembly Tree" "Standalone App")) ("String. Title for the violated-rules section. Defaults to \"Violated Rules\"." violated-rules-title "Violated Rules") ("String. Title for the other-rules section. Defaults to \"Other Rules\"." other-rules-title "Other Rules") ("Keyword symbol. Color keyword from <tt>*color-table*</tt> for the body background. Defaults to <tt>:blue-sky</tt>." body-bgcolor :blue-sky) ("Keyword symbol. Color keyword from <tt>*color-table*</tt> for the model-inputs area background. Defaults to <tt>:aquamarine</tt>." inputs-bgcolor :aquamarine) ("Keyword symbol. Color keyword from <tt>*color-table*</tt> for the violated-rules area background. Defaults to <tt>:aquamarine</tt>." violated-rules-bgcolor :aquamarine) ("Keyword symbol. Color keyword from <tt>*color-table*</tt> for the other-rules area background. Defaults to <tt>:aquamarine</tt>." other-rules-bgcolor :aquamarine) ("Keyword symbol. Color keyword from <tt>*color-table*</tt> for the tree area background. Defaults to <tt>:aquamarine</tt>." tree-bgcolor :aquamarine) ("Integer. Height (top to bottom on screen) in pixels of the graphics area. Defaults to 500." graphics-height 500 :defaulting) ("Integer. Height (left to right on screen) in pixels of the graphics area. Defaults to 500." graphics-width 500 :defaulting) ("List of GDL objects. This should be overridden with a list of objects of your choice. The leaves of these objects will be scaled to fit and displayed in the graphics area. Defaults to NIL." ui-display-list-objects nil) ("List of GDL objects. This should be overridden with a list of objects of your choice. These objects (not their leaves, but these actual nodes) will be scaled to fit and displayed in the graphics area. Defaults to NIL." ui-display-list-leaves nil) (depth (if (eql self (the :tree-root)) 0 (1+ (the :parent :depth)))) (remaining-depth (if (or (null (the :child-nodes)) (eql (the :tree-state) :closed)) 0 (1+ (apply #'max (mapsend (the :child-nodes) :remaining-depth))))) (total-depth (if (eql self (the :tree-root)) (the :remaining-depth) (the :parent :total-depth))) (last-node? (and (not (eql self (the :tree-root))) (eql self (lastcar (the :parent :child-nodes))))) ("List of GDL objects of type <tt>base-rule-object</tt> or (preferably) <tt>gwl-base-rule-object</tt>. Links to these will be displayed in the other-rules section. Default to the collection of all objects of type <tt>base-rule-object</tt> from this node in the tree down to the leaves, whose <tt>violated?</tt> message evaluates to NIL." other-rules (maptree self #'identity #'(lambda (item) (and (typep item 'base-rule-object) (not (the-object item suppress-display?)) (not (the-object item :violated?)))) #'(lambda(item) (or (and (typep item 'layout-mixin) (> (the-object item depth) *max-node-depth*)) (typep item 'base-rule-object))))) ("List of GDL objects of type <tt>base-rule-object</tt> or (preferably) <tt>gwl-base-rule-object</tt>. Links to these will be displayed in the other-rules section. Default to the collection of all objects of type <tt>base-rule-object</tt> from this node in the tree down to the leaves, whose <tt>violated?</tt> message evaluates to non-NIL." violated-rules (maptree self #'identity #'(lambda (item) (and (typep item 'base-rule-object) (not (the-object item suppress-display?)) (the-object item :violated?))) #'(lambda(item) (or (and (typep item 'layout-mixin) (> (the-object item depth) *max-node-depth*)) (typep item 'base-rule-object))))) ("Boolean. Indicates whether the Rules panel should be displayed. Defaults to T." display-rules? t :defaulting) ("Boolean. Indicates whether the Tree area should be displayed. Defaults to T." display-tree? t :defaulting) ("Boolean. Determines whether the standard-saved-slots are automatically used by default for the saved-slots. This is a trickle-down slot so its value will be passed to descendent objects automatically. The default value is NIL." use-standard-saved-slots? nil :defaulting) ("List of keyword symbols. Determines which formats are available in the Preferences. Defaults to :png, :jpeg, and :vrml." available-image-formats (list :png :jpeg :vrml :links)) (image-format :png) (length 0) (width 0) (height 0) ("Boolean. Determines whether the embedded form will support multipart MIME parts. Defaults to NIL." multipart-form? nil)) :trickle-down-slots (tree-root display-rules? display-tree? use-standard-saved-slots? graphics-height graphics-width) :computed-slots ((child-nodes nil) ("List of keyword symbols or lists. The first of this list should be the unique name for this tree node for the purposes of saving slots. The rest of this list is made up of either keyword symbols or lists. A keyword symbol indicates the name of a slot to be saved in the current object. These slot names should correspond to <tt>:settable</tt> slots of this object. A list indicates slots to be saved in a child object, specified as follows: the first of the list is the name of the child part, and the rest is made up of keywords naming the slots in the child part to be saved. These should correspond to <tt>:settable</tt> slots in the child object. The default value is the <tt>standard-saved-slots</tt> if the <tt>use-standard-saved-slots?</tt> is non-NIL, NIL otherwise." saved-slots (when (the use-standard-saved-slots?) (the standard-saved-slots))) ("List of keyword symbols. The first of this list is the <tt>name-for-display</tt> of this object. The rest of the list are all the keyword symbols representing the settable computed-slots and input-slots which have a default value. Required input-slots (i.e. input-slots without a default value) are not included in this list. If you wish to include required inputs with the saved-slots, you should explicitly append them to this list when specifying the <tt>saved-slots</tt>." standard-saved-slots (let ((slots (append (the (message-list :category :settable-computed-slots :message-type :local)) (the (message-list :category :settable-optional-input-slots :message-type :local)) (the (message-list :category :settable-defaulted-input-slots :message-type :local))))) (when slots (cons (the name-for-display) slots))))) :hidden-objects ((view-object :type 'web-drawing :object-roots (ensure-list (the :ui-display-list-objects)) :objects (ensure-list (the :ui-display-list-leaves)) :page-width (the :graphics-width) :page-length (the :graphics-height) :projection-vector (getf *standard-views* (the :view)))) :functions ((write-html-sheet nil (with-format (html-format t) (write-the (:main-sheet)))) (restore! ()) ("Void. Reads the slots data from <tt>filename</tt>, restores the corresponding slots in this object and matching descendant objects, and calls the <tt>restore!</tt> function on each object. :&key ((filename \"/tmp/&lt;object type&gt;\") \"String or pathname. Name of file to be read.\")" read-saved-slots (&key (filename (format nil "/tmp/~(~a~).gdl" (the type)))) (with-open-file (in filename) (let ((*package* (find-package (second (read in)))) result) (let ((result (do ((node-list (read in nil nil) (read in nil nil))) ((null node-list) (nreverse result)) (push node-list result)))) (the (restore-saved-slots result))))) (values)) ("Void. Writes the unique application name names and values of all saved-slots in this and all descendants which are of type node-mixin or application-mixin. :&key ((filename-or-stream \"/tmp/&lt;object type&gt;\") \"String, pathname, or stream. Name or stream for file to be written\")" write-saved-slots (&key (filename-or-stream (format nil "/tmp/~(~a~).gdl" (the type))) (toplevel? t)) (let ((*print-right-margin* 100) (*print-case* :capitalize)) (if (streamp filename-or-stream) (the (write-saved-slots-to-stream filename-or-stream :toplevel? toplevel?)) (with-open-file (out filename-or-stream :direction :output :if-exists :supersede :if-does-not-exist :create) (the (write-saved-slots-to-stream out :toplevel? toplevel?)))) (values))) (restore-saved-slots (slots) (let* ((app-id (first (the saved-slots))) (value-plist (rest (find app-id slots :key #'first)))) (mapc #'(lambda(slot) (if (atom slot) (let ((value (eval (getf value-plist slot)))) (the (set-slot! slot value))) (let ((self (the (evaluate (first slot)))) (values (getf value-plist (first slot)))) (mapc #'(lambda(sub-slot) (let ((value (getf values sub-slot))) (the (set-slot! sub-slot value)))) (rest slot))))) (rest (the saved-slots))) (the restore!) (mapc #'(lambda(child) (the-object child (restore-saved-slots slots))) (remove-if-not #'(lambda(child) (typep child 'layout-mixin)) (the children))))) (write-saved-slots-to-stream (stream &key toplevel?) (when toplevel? (print `(in-package ,(make-keyword (package-name *package*))) stream)) (when (the saved-slots) (print (cons (first (the saved-slots)) (mapcan #'(lambda(key) (if (atom key) (list key (readable-expression (the (evaluate key)))) (list (first key) (mapcan #'(lambda(sub-key) (list sub-key (readable-expression (the (evaluate (first key)) (evaluate sub-key))))) (rest key))))) (rest (the saved-slots)))) stream)) (mapc #'(lambda(child) (the-object child (write-saved-slots :filename-or-stream stream :toplevel? nil))) (remove-if-not #'(lambda(child) (typep child 'layout-mixin)) (the children))))))
14,043
Common Lisp
.lisp
206
53.218447
142
0.599284
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
d4e6e893b746c174f568de390562dfc7b2be0565a0808622fb8d4d7eba699d10
36,005
[ -1 ]
36,006
parameters.lisp
lisp-mirror_gendl/gwl-graphics/source/parameters.lisp
;; ;; Copyright 2002, 2009 Genworks International and Genworks BV ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl-graphics) (defparameter *these-features* (list :gwl-graphics))
941
Common Lisp
.lisp
22
41.409091
70
0.762842
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
a1f296b4a83b9e174fc125574f7ecd945f45f2d03760a1bae13a211519baa428
36,006
[ -1 ]
36,007
zzinit.lisp
lisp-mirror_gendl/gwl/zzinit/source/zzinit.lisp
;; ;; Copyright 2002-2011, 2012 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defparameter *these-features* (list :gwl)) (glisp:set-features *these-features*)
880
Common Lisp
.lisp
22
38.727273
70
0.757009
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
1ccf7e5e7c48da1ea3ca6f4816cde9ec326c78ec60f7a7c797a239da96815191
36,007
[ -1 ]
36,008
initialize.lisp
lisp-mirror_gendl/gwl/zzinit/source/initialize.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defvar *static-home* nil) (defun ensure-static-relative-pathname (relative) (let ((pathname (merge-pathnames relative *static-home*))) (or (probe-file pathname) (warn "Expected static subdirectory ~a does not appear to exist.~%" pathname)))) (defun publish-images (server) (let ((destination (ensure-static-relative-pathname "gwl/images/"))) (when destination (publish-directory :prefix "/images/gwl/" :server server :destination (namestring destination))))) (defun publish-statics (server) (let ((destination (ensure-static-relative-pathname ""))) (when destination (publish-directory :headers (list (cons :cache-control "public, max-age=3600, must-revalidate")) :prefix "/static/" :server server :destination (namestring destination))))) (defun publish-style (server) (let ((destination (ensure-static-relative-pathname "gwl/style/"))) (when destination (publish-directory :prefix "/style/" :server server :destination (namestring destination))))) (dolist (func (list 'publish-images 'publish-statics 'publish-style)) (pushnew func *publishers*)) (defvar *aserve-listeners* 25) (defvar *aserve-port* 9000) (defvar *aserve-start-args* nil) ;; ;; FLAG -- get platform-specific stuff below into :glisp package. ;; #+nil (defun client-test (port) #+allegro (multiple-value-bind (result error) (ignore-errors (glisp:with-timeout (2 (error "AllegroServe port probe timed out on port ~a. Perhaps a zombie process is holding port ~a?~%" port port)) (#+nil net.aserve.client:do-http-request drakma:http-request (format nil "http://localhost:~a" port)))) (declare (ignore result)) (when (typep error 'error) port)) #-allegro (let* ((result (handler-case (let ((sock (usocket:socket-listen "localhost" port))) (usocket:socket-close sock)) (usocket:address-in-use-error (e) :in-use) (t (e) :unknown)))) (unless (member result '(:in-use :unknown)) port))) (defun client-test (port) #-ccl (multiple-value-bind (result error) (ignore-errors (glisp:with-timeout (2 (error "AllegroServe port probe timed out on port ~a. Perhaps a zombie process is holding port ~a?~%" port port)) (net.aserve.client:do-http-request (format nil "http://127.0.0.1:~a" port)))) (declare (ignore result)) (when (typep error 'error) port)) #+ccl (let* ((result (handler-case (let ((sock (usocket:socket-listen "127.0.0.1" port))) (usocket:socket-close sock)) (usocket:address-in-use-error (e) (declare (ignore e)) :in-use) (t (e) (declare (ignore e)) :unknown)))) (unless (or (member result '(:in-use :unknown)) #+windows-host (ignore-errors (net.aserve.client:do-http-request (format nil "http://127.0.0.1:~a" port)))) port))) (defun start-gwl (&key (port *aserve-port*) (listeners *aserve-listeners*) ;; ;; FLAG -- figure out external-format for the other Lisps. ;; (external-format #+allegro :utf8-base #-allegro :utf8) aserve-start-args) (net.aserve:shutdown) (let ((wait-time 1)) (block :outer (do () (nil) (let ((port port)) (block :inner (do ((port-free? (client-test port) (client-test port))) (port-free? (format t (if (> wait-time 1) "~&Retrying AllegroServe on ~a...~%" "~&Trying to start AllegroServe on ~a...~%") port) (if (ignore-errors (apply #'net.aserve:start :port port :listeners listeners :external-format external-format aserve-start-args)) (return-from :outer port) (progn (sleep (random wait-time)) (return-from :inner)))) (incf port)))) (incf wait-time 0.1)))) (publish-uris)) (defvar *settings* (list (list '*static-home* *static-home* #'(lambda() (or (and glisp:*gendl-source-home* (probe-file (merge-pathnames "gwl/static/" glisp:*gendl-source-home*))) (and glisp:*gdl-home* (probe-file (merge-pathnames "static/" glisp:*gdl-home*))) (and glisp:*gdl-program-home* (probe-file (merge-pathnames "static/" glisp:*gdl-program-home*))) (warn "~%Static home not found in source directory or parent of program directory.~%")))))) ;; ;; FLAG -- move publishes into global param with the basic publishing data and ;; call general-purpose publish function on this data. ;; also detect changes in the publishing to include in return value. ;; (defun initialize () ;; ;; FLAG -- investigate if this initialize-multiprocessing business ;; is still needed, currently LW-only. ;; (glisp:initialize-multiprocessing) (when (find-package :zacl) (setq excl:*initial-terminal-io* *terminal-io*) (setf (slot-value net.aserve:*wserver* 'net.aserve::log-stream) excl:*initial-terminal-io* (slot-value (slot-value net.aserve:*wserver* 'net.aserve::default-vhost) 'net.aserve::log-stream) excl:*initial-terminal-io*)) (setq *iid-random-state* (make-random-state t)) (let (anything-changed?) (setq anything-changed? (glisp:set-settings *settings*)) (start-gwl) anything-changed?)) ;; ;; FLAG -- get platform-specific stuff into glisp package. ;; #+(and ccl windows-target) (in-package :ccl) #-(and ccl windows-target) (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter *set-_?* nil) (defparameter *set-$?* nil) (unless (get-dispatch-macro-character #\# #\_) (setq *set-_?* t) (set-dispatch-macro-character #\# #\_ #'(lambda(s subchar arg) (declare (ignore s subchar arg))nil))) (unless (get-dispatch-macro-character #\# #\$) (setq *set-$?* t) (set-dispatch-macro-character #\# #\$ #'(lambda(s subchar arg) (declare (ignore s subchar arg)) nil)))) #+(and ccl windows-target) (let (*warn-if-redefine-kernel*) (defun %windows-sleep (millis) #+nil (unless (typep millis 'unsigned-byte 32) (setq millis (coerce 1000000000 '(unsigned-byte 32)))) (do ((new-value (round (/ millis 10)) (round (/ millis 10)))) ((typep millis '(unsigned-byte 32))) (setq millis new-value)) (do* ((start (floor (get-internal-real-time) (floor internal-time-units-per-second 1000)) (floor (get-internal-real-time) (floor internal-time-units-per-second 1000))) (millis millis (- stop start)) (stop (+ start millis))) ((or (<= millis 0) (not (eql (#_SleepEx millis #$true) #$WAIT_IO_COMPLETION))))))) #-(and ccl windows-target) (eval-when (:compile-toplevel :load-toplevel :execute) (when *set-_?* (set-dispatch-macro-character #\# #\_ nil)) (when *set-$?* (set-dispatch-macro-character #\# #\$ nil)))
7,603
Common Lisp
.lisp
190
35.421053
129
0.670896
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
a886166ceb66068d143da7259f1e98db37ed8da7018786250b912e927a8bf18c
36,008
[ -1 ]
36,009
grid-form-element.lisp
lisp-mirror_gendl/gwl/form-elements/source/grid-form-element.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (define-object grid-form-control (skeleton-form-control) :documentation (:description "Beginnings of spread-sheet-like grid control. To do: Add row button, sort by column values, save & restore snapshot. Easy way for user to customize layout and markup. Allow for all types of form-control for each column. ") :input-slots (("List of lists. These values become the default row and column values for the grid." default (error "You must specify a default")) (keys (if (the key-row?) (first (the default)) (error "You need to specify keys."))) (key-row? (and (every #'keywordp (first (the default))) (not (every #'keywordp (second (the default)))))) ("List of plists. Each plist contains the desired form-control inputs for the respective column in the table." form-control-attributes nil) ("List of lists plists. Each list corresponds to one row and contains plists desired form-control inputs for the respective column in the table." form-control-inputs nil) ("List of symbols naming GDL object types. This must be the same length as a row of the table. The corresponding form-element in the grid will be of the specified type. Default is nil, which means all the form-controls will be of type 'text-form-control." form-control-types nil) (value (mapsend (the rows) :value)) ("Boolean. Should each row have a delete button? Default is nil." include-delete-buttons? nil) ("List of strings. One for each row." row-labels nil) ) :computed-slots ((raw-rows (if (the key-row?) (rest (the default)) (the default))) (raw-row-array (coerce (the raw-rows) 'array)) (form-controls (apply #'append (list-elements (the rows) (the-element form-controls))))) :objects ((rows :type 'grid-row :sequence (:indices (list-of-numbers 0 (1- (array-dimension (the raw-row-array) 0)))) :default (aref (the raw-row-array) (the-child index)) :form-control-inputs (nth (the-child index) (the form-control-inputs)) :include-delete-buttons? (the include-delete-buttons?) :row-label (nth (the-child index) (the row-labels)) :pass-down (form-control-attributes form-control-types))) :functions ((restore-defaults! () (dolist (row (list-elements (the rows))) (dolist (cell (list-elements (the-object row cells))) (the-object cell (restore-slot-default! :value))))))) (define-lens (html-format grid-form-control)() :output-functions ((form-control () (with-html-output (*stream* nil) ((:table :border 1) (:tr (when (the include-delete-buttons?) (htm (:th :br))) (when (the row-labels) (htm (:th :br))) (dolist (key (the keys)) (htm (:th (str key))))) (dolist (row (list-elements (the rows))) (htm (:tr (write-the-object row form-control))))))))) (define-object grid-row (skeleton-form-control) :input-slots (default form-control-attributes (form-control-types nil) (form-control-inputs nil) include-delete-buttons? row-label) :computed-slots ((default-array (coerce (the default) 'array)) (value (mapsend (the cells) :value)) (%form-control-types (or (the form-control-types) (make-list (length (the default)) :initial-element 'text-form-control))) (form-controls (if (typep (the %delete-button%) 'null-part) (list-elements (the cells)) (cons (the %delete-button%) (list-elements (the cells)))))) ;; ;; FLAG -- support list of types here. ;; :objects ((%delete-button% :type (if (the include-delete-buttons?) 'button-form-control 'null-part) :button-type :submit :default "x") (cells :type (:sequence (the %form-control-types)) :parameters (append (nth (the-child index) (the form-control-attributes)) (nth (the-child index) (the form-control-inputs))) :sequence (:size (length (the default))) :default (aref (the default-array) (the-child index))))) (define-lens (html-format grid-row)() :output-functions ((form-control () (with-html-output (*stream* nil) (when (the include-delete-buttons?) (htm (:td (write-the %delete-button% form-control)))) (when (the row-label) (htm (:td (str (the row-label))))) (dolist (cell (list-elements (the cells))) (htm (:td (write-the-object cell form-control))))))))
5,957
Common Lisp
.lisp
123
38.211382
102
0.617397
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
447a92f386a7dcfca169365c3518715c5459107602ebccb22a7d6d708694af74
36,009
[ -1 ]
36,010
primitives.lisp
lisp-mirror_gendl/gwl/form-elements/source/primitives.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (define-object skeleton-form-control (skeleton-ui-element) :documentation (:author "Dave Cooper, Genworks" :description "Computes standard values for base-form-control and similar container objects, e.g. grid-form-control. Does not perform the actual bashing and computation of result value, should be mixed in to something which does this.") :input-slots (("Boolean. Set this to t if the form-control should always occur first in an outputted snapshot file. Defaults to nil." primary? nil) ("String. You can use this to specify a user-defined class for the form-control. Defaults to nil, which means no class attribute will be generated." class nil) ("Keyword symbol. The ID attribute for this tag. Defaults to (the field-name)." id (the field-name)) ("Keyword symbol. The name of this field. Computed from the object name within the tree." field-name (make-keyword-sensitive (the base64-encoded-root-path))) ) :computed-slots ( (form-controls nil) ("String of valid HTML. Also known as simply form-control. This is the default HTML which can be included in a form in a web page to display this form control. Default is the output from form-control method of the lens for html-format and the specific type of this object, returned as a string." form-control-string (with-output-to-string (*stream*) (with-format (html-format *stream*) (write-the form-control)))) ("String of valid HTML. This is the default HTML which can be included in a form in a web page to display this form control. Previously known as form-control-string. Default is the form-control-string." form-control (the form-control-string)) ("String of valid HTML. This is the default HTML which can be included in a form in a web page to display this form control, wrapped with labels and table cells." html-string (with-output-to-string (*stream*) (with-format (html-format *stream*) (write-the string)))) )) (define-object base-form-control (skeleton-form-control) :documentation (:author "Dave Cooper, Genworks" :description "This object can be used to represent a single HTML form control. It captures the initial default value, some display information such as the label, and all the standard HTML tag attributes for the tag e.g. INPUT, SELECT, TEXTAREA. GWL will process the data types according to specific rules, and validate the typed value according to other default rules. A custom validation-function can also be provided by user code. Sequences of these objects (with :size, :indices, :matrix, and :radial) are supported. This facility and its documentation is expected to undergo significant and frequent upgrades in the remainder of GDL 1573 and upcoming 1575. Current to-do list: <ol> <li> Currently this works with normal HTTP form submission and full page reloading. We intend to make it work with AJAX and surgical page update as well. <li> We intend to provide inputs for all the standard tag attributes for the accompanying LABEL tag for the form control. <li> Additional form control elements to be included, to cover all types of form elements specified in current HTML standard from http://www.w3.org/TR/html401/interact/forms.html#h-17.2.1 <ul> <li>button-form-control: submit buttons, reset buttons, push buttons. <li>checkbox-form-control: checkboxes, radio buttons (multiple of these must be able to have same name) <li>menu-form-control: select, along with optgroup and option. <li>text-form-control: single-line text input (including masked passwords) and multi-line (TEXTAREA) text input. <li>file-form-control: file select for submittal with a form. <li>hidden-form-control: input of type hidden. <li>object-form-control: (not sure how this is supposed to work yet). </ul> </ol> Also, we have to study and clarify the issue of under what conditions values can possibly take on nil values, and what constitutes a required field as opposed to a non-validated field, and whether a blank string on a text input should be represented as a nil value or as an empty string. Note that checkbox-form-control and menu-form-control currently get automatically included in the possible-nils. " :examples " <pre> (in-package :gwl-user) (define-object test-form (base-html-sheet) :objects ((username :type 'text-form-control :size 35 :maxlength 30 :allow-nil? t :default \"Ron Paul\") (age :type 'text-form-control :size 5 :validation-function #'(lambda(input) (or (null input) (> 80 input 70))) :domain :number ;;:default 72 :default nil ) (bio :type 'text-form-control :rows 8 :size 120 :default \" Congressman Ron Paul is the leading advocate for freedom in our nation's capital. As a member of the U.S. House of Representatives, Dr. Paul tirelessly works for limited constitutional government, low taxes, free markets, and a return to sound monetary policies. He is known among his congressional colleagues and his constituents for his consistent voting record. Dr. Paul never votes for legislation unless the proposed measure is expressly authorized by the Constitution. In the words of former Treasury Secretary William Simon, Dr. Paul is the one exception to the Gang of 535 on Capitol Hill.\") (issues :type 'menu-form-control :choice-list (list \"Taxes\" \"Health Care\" \"Foreign Policy\") :default \"Taxes\" :multiple? t) (color :type 'menu-form-control :size 7 :choice-plist (list :red \"red\" :green \"green\" :blue \"blue\" :magenta \"magenta\" :cyan \"cyan\" :yellow \"yellow\" :orange \"orange\") :validation-function #'(lambda(color) (if (intersection (ensure-list color) (list :yellow :magenta)) (list :error :disallowed-color-choice) t)) ;;:append-error-string? nil :multiple? t :default :red ;;:onchange \"alert('hey now');\" ) (early-riser? :type 'checkbox-form-control :default nil) (favorite-links :type 'text-form-control :sequence (:size 3) :size 70 :default \"http://\"))) (define-lens (html-format test-form)() :output-functions ((main-sheet () (with-html-output (*html-stream* nil :indent t) (:html (:head (:title \"Test Form\")) (:body (:h2 (:center \"Test Form\")) (the write-development-links) (with-html-form (:cl-who? t) (:p (str (the username html-string))) (:p \"(internal value is: \" (fmt \"~s\" (the username value)) \")\") (:p (str (the age html-string))) (:p \"(internal value is: \" (fmt \"~s\" (the age value)) \")\") (:p (str (the bio html-string))) (:p (:table (:tr (:td (str (the issues html-string)))) (:tr (:td (str (the color html-string)))))) (:p (str (the early-riser? html-string))) (dolist (link (list-elements (the favorite-links))) (htm (str (the-object link html-string)))) (:p ((:input :type :submit :value \" OK \")))))))))) (publish :path \"/fe\" :function #'(lambda(req ent) (gwl-make-object req ent \"gwl-user::test-form\"))) </pre> " ) :input-slots (("Lisp value of a type compatible with (the domain). This is the initial default value for the control. This must be specified by user code, or an error will result." default (error "You must specify a default for the ~a at ~s." (the type) (reverse (the root-path)))) ("String. The prompt used in the label. " prompt (string-capitalize (glisp:replace-regexp (string (if (null (the index)) (make-keyword (the %name%)) (make-keyword (format nil "~a#~a" (the %name%) (the index))))) "-" " "))) ("Boolean. Regardless of :domain, if this is non-nil, nil values will be accepted. Defaults to t if (the default) is nil, otherwise defaults to nil." allow-nil? (null (the default))) (email? nil) ("Boolean. If non-nil, then values which fail the type or validation test will still be allowed to be the value. Default is t." allow-invalid? t) ("Boolean. If non-nil, then values which fail the type test will still be allowed to be the value. Default is nil." allow-invalid-type? nil) ("Boolean. Regardless of :domain, if this is non-nil, empty strings will convert to nil. Defaults to (the allow-nil?)" nullify-empty-string? (the allow-nil?)) ("Boolean. This switch determines whether this form-control should be preset before the final setting, in order to allow any interdependencies to be detected for validation or detecting changed values. Default is nil." preset? nil) ("Keyword symbol, one of :number, :keyword, :list-of-strings, :list-of-anything, or :string. This specifies the expected and acceptable type for the submitted form value. If possible, the submitted value will be coerced into the specified type. The default is based upon the Lisp type of (the default) provided as input to this object. If the default is nil, the domain will default to :string" domain (if (null (the default)) :string (typecase (the default) (number :number) (keyword :keyword) (list (cond ((every #'stringp (the default)) :list-of-strings) (t :list-of-anything))) (otherwise :string)))) ("Boolean. Determines whether a default error string is appended to string ouput-function for html-format (and therefore html-string computed-slot as well). Defaults to t." append-error-string? t) ("Keyword symbol or nil. Specifies where the label tag goes, if any. Can be :table-td (label goes in a td before the form control), :table-td-append (label goes in a td after the form control), :prepend (label tag wraps around form control and label text comes before form control), :append (label tag wraps around form control and label text comes after form control), :table-with-class (like :table-td, but adds a class \"form-control\" to the table), or :as-div (puts label and control inside a div of class \"form-control\"). Default is :as-div" label-position :as-div) ("Function of one argument. The argument will be the submitted form value converted to the proper type. The return value from this function can be nil, any non-nil value, or a plist with keys :validated-value and :error. The following behavior applies: <ul> <li> If the function returns nil, error is set to :unspecified-validation-fail.</li> <li> If the function returns a plist with keys :validated-value and :error, and if :error is non-nil, it means the value is not acceptable, the form-controls error message is set to this error (usually a keyword symbol), and the error string will be appended to the html-string by default. </li> <li> If the function returns any other value, then the properly typed submitted form value is considered valid and is used. </ul> In the case of an error, the form-control's failed-value message is set to the properly typed submitted form value. If allow-invalid? is non-nil, then the form-control's value message is also set to this value (i.e. the invalid value is still accepted, even though a non-nil error is present). Default is (list :validated-value value :error nil)." validation-function #'(lambda(value) (declare (ignore value)) t ;;(list :validated-value value :error nil) )) ("Boolean. If set to non-nil, this field's value will be sent to server upon change. Default is nil." ajax-submit-on-change? nil) ("Boolean. If set to non-nil, this field's value will be sent to server upon enter. Default is nil." ajax-submit-on-enter? nil) ("String. Text to place in the field by default, overwritten as soon as the field is selected. Works only in HTML5. Default is nil." placeholder nil) ("Boolean. Maps to HTML form control attribute of the same name. Default is nil." disabled? nil) ("Boolean. Maps to HTML form control attribute of the same name. Default is nil." readonly? nil) ("Boolean. Maps to HTML form control attribute of the same name. Default is nil." ismap? nil) ("Number or nil. Maps to HTML form control attribute of the same name. Default is nil." size nil) ("Number or nil. Maps to HTML form control attribute of the same name. Default is nil." maxlength nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." src nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." alt nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." usemap nil) ("Integer or nil. Maps to HTML form control attribute of the same name. Default is nil." tabindex nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." accesskey nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onfocus nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onblur nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onselect nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil, unless ajax-submit-on-change? is non-nil, in which case it calls ajax to set current form value." onchange (when (the ajax-submit-on-change?) (the parent (gdl-ajax-call :form-controls (list self))))) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil, unless ajax-submit-on-enter? is non-nil, in which case it calls ajax to set current form value." onenter (when (the ajax-submit-on-enter?) (the parent (gdl-ajax-call :form-controls (list self))))) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onclick nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." ondblclick nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onmousedown nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onmouseup nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onmouseover nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onmousemove nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onmouseout nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onkeypress nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onkeydown nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." onkeyup nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." accept nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." lang nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." title nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." style nil) ("String or nil. Maps to HTML form control attribute of the same name. Default is nil." align nil)) :computed-slots (("String or error object. This will be set to a validation error if any, and cleared when the error is gone." error nil :settable) ("Lisp value. The value which was attempted to be set but failed validation." failed-value nil :settable) ("Lisp value. The current value of this form control." value (the default) :settable)) :functions (("Void. Restores the default for the value, the failed-value, and the error." restore-defaults! () (the (restore-slot-defaults! (list :error :failed-value :value)))) (validate-and-set! (raw-value) (let ((result-plist (the (validate-type raw-value)))) (when (and (the allow-invalid-type?) (getf result-plist :error)) (setq result-plist (list :typed-value raw-value :error nil))) (if (getf result-plist :error) (the (set-error-state! :value raw-value :error (getf result-plist :error))) (let ((value (getf result-plist :typed-value))) (setq result-plist (the (validate-value value))) (cond ((null result-plist) (the (set-error-state! :value value :error :unspecified-validation-fail))) ((and (consp result-plist) (evenp (length result-plist)) (getf result-plist :error)) (the (set-error-state! :value value :error (getf result-plist :error)))) ((and (consp result-plist) (evenp (length result-plist)) (getf result-plist :validated-value)) (the (set-new-value! (getf result-plist :validated-value)))) (t (the (set-new-value! value)))))))) (set-actual-slot! (new-value) ;;(the (set-slot! :value new-value)) (the (set-slot-if-needed! :value new-value :infer-types? nil))) (set-new-value! (new-value) (the (set-actual-slot! new-value)) (the (restore-slot-defaults! (list :error :failed-value))) (list (the field-name) new-value)) (set-error-state! (&key value error) (when (the allow-invalid?) (the (set-actual-slot! value))) (the (set-slot! :error (format nil "~a" error))) (the (set-slot! :failed-value value))) (validate-value (typed-value) (funcall (the validation-function) typed-value)) (tweak-raw-value-and-domain (&key raw-value domain) (values raw-value domain)) (validate-type (raw-value) (let ((domain (the domain))) (multiple-value-bind (raw-value domain) (the (tweak-raw-value-and-domain :raw-value raw-value :domain domain)) (cond ((and (the allow-nil?) (the nullify-empty-string?) (equalp raw-value "")) (list :typed-value nil :error nil)) (t (ecase domain (:pass-thru (list :typed-value (read-safe-string raw-value) :error nil)) (:string (list :typed-value raw-value :error nil)) (:boolean (let ((item (read-safe-string raw-value))) (if item (list :typed-value t :error nil) (list :typed-value nil :error nil)))) (:keyword (multiple-value-bind (typed-value error) (ignore-errors (make-keyword raw-value)) (list :typed-value typed-value :error (when (typep error 'error) error)))) ((:list-of-strings :list-of-anything) (multiple-value-bind (typed-value error) (ignore-errors (ensure-list (read-safe-string raw-value))) (list :typed-value typed-value :error (when (typep error 'error) error)))) (:number (multiple-value-bind (typed-value error) (ignore-errors (read-safe-string raw-value)) (cond ((typep error 'error) (list :typed-value nil :error (when (typep error 'error) error))) ((numberp typed-value) (list :typed-value typed-value :error nil)) (t (list :typed-value typed-value :error :should-be-a-number))))) (:symbol (multiple-value-bind (typed-value error) (ignore-errors (if (keywordp raw-value) raw-value (intern raw-value *package*))) (list :typed-value typed-value :error (when (typep error 'error) error)))))))))))) (define-lens (html-format base-form-control)() :output-functions ( (:label (&key include-prompt?) (with-html-output (*stream* nil) ((:label :for (the id)) (when include-prompt? (htm (str (the prompt))))))) (prompt () (with-html-output (*stream* nil) (str (the prompt)))) (form-control () (when *debug?* (format t "~&Writing from form-control of base-form-control~%")) (with-html-output (*stream*) "empty form-control (str (the root-path))")) (string () (with-html-output (*stream* nil) (cond ((the prompt) (ecase (the label-position) (:prepend (htm ((:label :for (the id)) (write-the prompt)) (write-the form-control))) (:append (htm (write-the form-control) ((:label :for (the id)) (write-the prompt)))) (:as-div (htm ((:div :class "form-control") (write-the (:label :include-prompt? t)) (write-the form-control)))))) (t (write-the form-control))) (when (and (the error) (the append-error-string?)) (htm :br (:i ((:span :style "color: red") (str (the error)) (when (the failed-value) (htm ", failed value is: " (fmt "~s" (the failed-value)))))))))))) ;; Text ;; (define-object text-form-control (base-form-control) :documentation (:author "Dave Cooper, Genworks" :description "This represents a INPUT TYPE=TEXT or TEXTAREA form control tag." :examples "Please see base-form-control for all the examples.") :input-slots (("Integer. The number of rows. If more than 1, this will be a TEXTAREA. Defaults to 1." rows 1) ("Boolean. Specifies whether this should be a password form control with obscured screen text. Note that this does not automatically give encrypted transmission to the server - you need SSL for that. Defaults to nil. Use password-form-control to get a default of t." password? nil) ("Boolean. Specifies whether this should be a number form control with support for numerical input. Defaults to nil. Use number-form-control to get a default of t." number? nil) ("Integer. The number of columns for a TEXTAREA (if rows is > 1). Defaults to (the size)." cols (the size))) :computed-slots ((str-ready-string (if (eql (the domain) :pass-thru) (escape-string (format nil "~s" (the value))) (escape-string (format nil "~a" (or (the value) "")))))) :functions ((set-actual-slot! (new-value) (the (set-slot-if-needed! :value (if (and (stringp new-value) (> (length new-value) 1) (eql (aref new-value (1- (length new-value))) #\Newline)) (subseq new-value 0 (1- (length new-value))) new-value) :infer-types? nil))))) (define-object password-form-control (text-form-control) :computed-slots ((password? t))) (define-object number-form-control (text-form-control) :input-slots ((min nil) (max nil) (step nil) (domain :number)) :computed-slots ((number? t))) (define-object email-form-control (text-form-control) :computed-slots ((email? t))) (define-lens (html-format text-form-control)() :output-functions ((form-control () (when *debug?* (print-messages value domain str-ready-string)) (if (> (the rows) 1) (with-expanded-html-output (*stream* nil) ((:textarea :rows (the rows) :cols (the cols) :name (the field-name) :id (the id)) (when (the str-ready-string) (str (the str-ready-string))))) (with-expanded-html-output (*stream* nil) ((:input :type (cond ((the password?) :password) ((the number?) :number) ((the email?) :email) (t :text) ) :value (when (the str-ready-string) (the str-ready-string)) :min (when (and (the number?) (the min)) (the min)) :max (when (and (the number?) (the max)) (the max)) :step (when (and (the number?) (the step)) (the step)) :name (the field-name) :id (the id)))))))) ;; ;; Select ;; (define-object menu-form-control (base-form-control) :documentation (:author "Dave Cooper, Genworks" :description "This represents a SELECT form control tag wrapping some OPTION tags. OPTIONGROUP is not yet implemented, but will be." :examples "<pre> ... :objects ((menu-1 :type 'menu-form-control :choice-plist (list 1 \"one\" 2 \"two\"))) ... </pre> Please see base-form-control for a broader example which uses more form-control primitives together.") :input-slots (("List. Display values, also used as return values, for selection list. Specify this or choice-plist, not both." choice-list nil) ("Boolean. Are multiple selections allowed? Default is nil." multiple? nil) ("List of keyword symbols. Each of these should match a key in the choice-plist, and where there is a match, that key will be disabled in the rendering." disabled-keys nil) ("Boolean. Indicates whether this should be included in possible-nils. Defaults to (the multiple?)" possible-nil? (the multiple?)) ("Plist. Keywords and display values for the selection list. Specify this or choice-list, not both." choice-plist (if (null (the choice-list)) (error "Either choice-list or choice-plist must be given.") (mapcan #'(lambda(choice) (list choice choice)) (the choice-list)))) ("Plist. Keywords and CSS style for display of each choice. The keys should correspond to the keys in choice-plist, or the items in choice-list if no choice-plist is given." choice-styles nil) ("Number. How many choices to display" size 3) ("Predicate function of two arguments. Defaults based on type of first in choice-plist: eql for keywords, string-equal for strings, and equalp otherwise." test (typecase (first (the effective-choice-plist)) (keyword #'eql) (string #'string-equal) (otherwise #'equalp)))) :computed-slots ((effective-choice-plist (or (the choice-plist) (mapcan #'(lambda(choice) (list choice choice)) (the choice-list)))) (display-format-string (etypecase (second (the effective-choice-plist)) (number "~s") (list "~s") (symbol "~s") (string "~a"))) (format-string (ecase (the domain) ((:list-of-anything :keyword :number :symbol) "~s") ((:string :pass-thru) "~a")))) :functions ((tweak-raw-value-and-domain (&key raw-value domain) (if (the multiple?) (ecase domain (:keyword (multiple-value-bind (possible-list error) (ignore-errors (read-safe-string raw-value)) (cond ((typep error 'error) (error error)) ((listp possible-list) (values (mapcar #'make-keyword possible-list) :list-of-anything)) (t (values (make-keyword raw-value) :keyword))))) ((:string :pass-thru) (multiple-value-bind (possible-list error) (ignore-errors (read-safe-string raw-value)) (cond ((typep error 'error) (error error)) ((listp possible-list) (values possible-list :list-of-strings)) (t (values raw-value :string))))) ((:number :list-of-anything) (multiple-value-bind (possible-list error) (ignore-errors (read-safe-string raw-value)) (cond ((typep error 'error) (error error)) ((listp possible-list) (values (mapcar #'read-safe-string possible-list) :list-of-anything)) (t (values (read-safe-string raw-value) :number)))))) (ecase domain (:list-of-anything (values (read-safe-string raw-value) :list-of-anything)) (:symbol (values (read-safe-string raw-value) :symbol)) (:keyword (values (make-keyword raw-value) :keyword)) ((:string :pass-thru) (values raw-value :string)) (:number (values raw-value :number))))))) (define-lens (html-format menu-form-control)() :output-functions ((form-control () (with-expanded-html-output (*stream* nil) ((:select :name (the field-name) :id (the id) :multiple (when (the multiple?) t)) (dolist (key (plist-keys (the effective-choice-plist))) (with-cl-who () ((:option :value (format nil (the format-string) key) :style (getf (the choice-styles) key) :multiple (the multiple?) :disabled (when (member key (the disabled-keys)) "disabled") :selected (let ((selected? (cond ((listp key) (funcall (the test) key (the value))) (t (member key (ensure-list (the value)) :test (the test)))))) (when selected? "selected"))) (fmt (the display-format-string) (first (rest (member key (the effective-choice-plist) :test (the test))))))))))))) ;; ;; Radio ;; (define-object radio-form-control (menu-form-control) :documentation (:description "Produces a standard radio-button form control.") :input-slots (("Keyword symbol or nil. Specifies where the description for each radio goes, if any. Can be: <dl> <dt><strong>:paragraph-prepend (or :p-prepend or :p)</strong></dt> <dd>Description goes in a paragraph tag before the input tag.</dd> <dt><strong>:paragraph-append (or :p-append)</strong></dt> <dd>Description goes in a paragraph tag after the input tag</dd> <dt><strong>:table-row-prepend (or :table-tr or :table-tr-prepend)</strong></dt> <dd>Description goes in a table cell wrapped in a table row before the input tag table cell</dd> <dt><strong>:table-row-append (or :table-tr-append)</strong></dt> <dd>Description goes in a table cell wrapped in a table row after the input tag table cell</dd> <dt><strong>nil (or any other value)</strong></dt> <dd>No description, only the bare input tag for the radio</dd> </dl> Default is :paragraph-append." description-position :paragraph-append) ("String. Allows you to specify a class for the table surrounding the radio input elements. Defaults to empty string." table-class "")) :computed-slots ((multiple? nil))) (define-lens (html-format radio-form-control)() :output-functions (("Void. Outputs the actual input tag. Undocumented but in theory can be overridden in a subclass by user code. Contact Genworks if you need this documented." input-tag (&key key count) (with-expanded-html-output (*stream* nil) ((:input :type :radio :name (the field-name) :id (format nil "~a-~a" (the id) count) :disabled (when (member key (the disabled-keys)) "disabled") :value (format nil (the format-string) key) :checked (funcall (the test) key (the value)))))) ("Void. Outputs the input tag with description. Undocumented but in theory can be overridden in a subclass by user code. Contact Genworks if you need this documented." labeled-input-tag (&key key value count) (with-html-output (*stream*) (case (the description-position) ((:paragraph-prepend :p-prepend :p) (htm (:p (fmt (the display-format-string) value) (write-the (input-tag :key key :count count))))) ((:paragraph-append :p-append) (htm (:p (write-the (input-tag :key key :count count)) (fmt (the display-format-string) value)))) ((:table-row-prepend :table-tr :table-tr-prepend) (htm (:tr (:td (write-the (input-tag :key key :count count))) (:td (fmt (the display-format-string) value))))) ((:table-row-append :table-tr-append) (htm (:tr (:td (fmt (the display-format-string) value)) (:td (write-the (input-tag :key key :count count)))))) (otherwise (write-the (input-tag :key key :count count)))))) (form-control () (with-html-output (*stream*) ((:table :class (the table-class)) (let ((count -1)) (mapc #'(lambda(key value) (write-the (labeled-input-tag :key key :value value :count (incf count)))) (plist-keys (the effective-choice-plist)) (plist-values (the effective-choice-plist))))))))) ;; ;; Button ;; (define-object button-form-control (base-form-control) :input-slots ((label (the value)) (content (the :label)) (button-type :button) (default " OK "))) (define-lens (html-format button-form-control)() :output-functions ((form-control () (with-expanded-html-output (*stream* nil) ((:button :name (the field-name) :id (the id) :type (the button-type) :value (the value)) (str (the content))))))) ;; ;; Checkbox ;; (define-object checkbox-form-control (base-form-control) :documentation (:author "Dave Cooper, Genworks" :description "This represents a INPUT of TYPE CHECKBOX" :examples "Please see base-form-control for all the examples.") :input-slots (("Keyword symbol. The domain defaults to :boolean for the checkbox-form-control. However, this can be overridden in user code if the checkbox is supposed to return a meaningful value other than nil or t (e.g. for a group of checkboxes with the same name, where each can return a different value)." domain :boolean) ("Boolean. Indicates whether this should be included in possible-nils. Defaults to t." possible-nil? t))) (define-lens (html-format checkbox-form-control)() :output-functions ((form-control () (with-expanded-html-output (*stream* nil) ((:input :name (the field-name) :id (the id) :type :checkbox :value :on :checked (if (the value) t)))))))
37,712
Common Lisp
.lisp
674
44.614243
188
0.618882
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
df957da732c0eab8c4872911cf7ac45c6d6dce991dbc47145dd7b0236aec7d67
36,010
[ -1 ]
36,011
macros.lisp
lisp-mirror_gendl/gwl/form-elements/source/macros.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defmacro with-expanded-html-output ((var &optional stream &key prologue ((:indent cl-who::*indent*) cl-who::*indent*)) &body body) (let ((new-body (mapcar #'(lambda(form) (cond ((and (listp form) (listp (first form)) (member (first (first form)) '(:input :select :textarea :button))) (cons (append (first form) `(:disabled (if (the disabled?) t nil) ;; ;; The new HTML5 stuff: ;; :placeholder (the placeholder) :class (the class) :readonly (if (the readonly?) t nil) :ismap (if (the ismap?) t nil) :size (the size) :maxlength (the maxlength) :src (the src) :alt (the alt) :usemap (the usemap) :tabindex (the tabindex) :accesskey (the accesskey) :onfocus (the onfocus) :onblur (the onblur) :onselect (the onselect) :onchange (the onchange) :ondblclick (the ondblclick) :onclick (the onclick) :onmousedown (the onmousedown) :onmouseup (the onmouseup) :onmouseover (the onmouseover) :onmousemove (the onmousemove) :onmouseout (the onmouseout) :onkeypress (the onkeypress) :onkeydown (the onkeydown) :onkeyup (the onkeyup) :accept (the accept) :lang (the lang) :title (the title) :style (the style) :align (the align))) (rest form))) (t form))) body))) `(with-html-output (,var ,stream :prologue ,prologue :indent :indent) ,@new-body)))
3,891
Common Lisp
.lisp
70
28.842857
100
0.398048
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
61372e41270af6c7b8c3101fffff996eeeb2fc42275822f2e704f50a1eb36d4a
36,011
[ -1 ]
36,012
base-ajax-sheet.lisp
lisp-mirror_gendl/gwl/ajax/source/base-ajax-sheet.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defmacro w-c-w-s ((&rest args) &rest body) `(with-cl-who-string ,args ,@body)) (defun prepend-url-depth (string depth) (string-append (format nil "~v@{~A~:*~}" depth "../") string)) (define-object base-ajax-sheet (base-html-sheet) :documentation (:description "(Note: this documentation will be moved to the specific docs for the html-format/base-ajax-sheet lens, when we have lens documentation working properly) Produces a standard main-sheet for html-format which includes the standard GDL Javascript to enable code produced with gdl-ajax-call to work, and optionally to include the standard JQuery library. If you want to define your own main-sheet, then there is no use for base-ajax-sheet, you can just use base-html-sheet. But then you have to include any needed Javascript yourself, e.g. for gdl-ajax-call support or jQuery. The html-format lens for base-ajax-sheet also defines a user hook function, main-sheet-body, which produces a \"No Body has been defined\" message by default, but which you can fill in your own specific lens to do something useful for the body." :examples "<pre> (in-package :gdl-user) (gwl:define-package :ajax-test (:export #:assembly)) (in-package :ajax-test) (define-object assembly (base-ajax-sheet) :objects ((inputs-section :type 'inputs-section) (outputs-section :type 'outputs-section :box (the viewport box) :color (the inputs-section color)) (viewport :type 'viewport :box-color (the inputs-section color)))) (define-lens (html-format assembly)() :output-functions ((main-sheet-body () (with-cl-who () (:table (:tr (:td (str (the inputs-section main-div))) (:td (str (the outputs-section main-div))) (:td (str (the viewport main-div))))))))) (define-object inputs-section (sheet-section) :computed-slots ((color (the menu-control value))) :objects ((menu-control :type 'menu-form-control :choice-list (list :red :green :blue) :default :red :onchange (the (gdl-ajax-call :form-controls (list (the-child))))) (little-grid :type 'grid-form-control :form-control-types '(text-form-control text-form-control button-form-control) :form-control-attributes '((:ajax-submit-on-change? t) (:ajax-submit-on-change? t)) :form-control-inputs (mapcar #'(lambda(row) (list nil nil (list :onclick (the (gdl-ajax-call :function-key :do-something! :arguments (list (the-object row index))))))) (list-elements (the-child rows))) :default '((:color :number :press-me) (:red 42 \"OK\") (:blue 50 \"OK\")))) :computed-slots ((inner-html (with-cl-who-string () (str (the little-grid form-control-string)) (str (the menu-control html-string))))) :functions ((do-something! (index) (format t \"Processing row ~a...~%\" index)))) (define-object outputs-section (sheet-section) :input-slots (color box) :computed-slots ((inner-html (with-cl-who-string () (:p \"The box volume is: \" (fmt \"~a\" (the box volume))) (:p \"The box color is: \" ((:span :style (format nil \"color: ~a\" (the color))) (str (the color)))))))) (define-object viewport (base-ajax-graphics-sheet) :input-slots (box-color) :computed-slots ((length 300) (width 300) (display-list-objects (list (the box))) (projection-vector (getf *standard-views* (the view-selector value))) (inner-html (with-cl-who-string () (str (the view-selector html-string)) (str (the reset-zoom-button form-control-string)) (str (the raster-graphics))))) :objects ((box :type 'box :length 20 :width 25 :height 30 :display-controls (list :color (the box-color))))) (publish-gwl-app \"/ajax-test\" \"ajax-test:assembly\") </pre>") :input-slots ((local-assets? t) (url-depth 0) ("String of HTML. The main body of the page. This can be specified as input or overridden in subclass, otherwise it defaults to the content produced by the :output-function of the same name in the applicable lens for html-format." main-sheet-body (with-output-to-string (*stream*) (with-format (html-format *stream*) (write-the main-sheet-body)))) ("String or nil. Names the value of class attribute for the body tag. Default is nil." body-class nil) ("String or nil. Names the value of class attribute for the head tag. Default is nil." head-class nil) ("String or nil. Names the value of class attribute for the html tag. Default is nil." html-class nil) ("String of Javascript or nil. This Javascript will go into the :onload event of the body. Default is nil." body-onload nil) ("String of Javascript or nil. This Javascript will go into the :onpageshow event of the body. Default is nil." body-onpageshow nil) ("String of Javascript or nil. This Javascript will go into the :onresize event of the body. Default is nil." body-onresize nil) ("String or nil. Contains the string for the doctype at the top of the document. Default is the standard doctype for HTML5 and later." doctype-string "<!DOCTYPE HTML>") (use-ajax? t ) ;; of course because this is base-ajax-sheet. But we can override if needed. ("Boolean. Include jquery javascript libraries in the page header? Default nil." use-jquery? nil :settable) (use-raphael? nil) (use-svgpanzoom? nil) (use-x3dom? nil) (use-fontawesome? nil) (use-anyresize? nil) (include-default-favicon? t) ("String. The title of the web page. Defaults to \"Genworks GDL -\" .followed by the strings-for-display." title (format nil "Genworks GDL - ~a" (the strings-for-display))) ("String of valid HTML. Additional tag content to go into the page header, if you use the default main-sheet message and just fill in your own main-sheet-body, as is the intended use of the base-ajax-sheet primitive." additional-header-content nil :settable) ;; FLAG JB-100203 added an input slot to the base-ajax-sheet in order for the end user ;; to supply an additional set of javascript JUST BEFORE THE BODY ;; this is enable the user to add jquery code '$(document).ready(function () { /// };' ;; and execute parts of this. This is complementary of the ui-specific-layout-js, which can ;; only be an external js file. This is inline javascript ("valid javascript. This javascript is added to the head of the page, just before the body." additional-header-js-content nil :settable) ("Absolute URI in the browser. This is additional JavaScript that needs to be loaded in order to initiate the layout of a user interface. Defaults to nil." ui-specific-layout-js nil :settable) ;;(respondent (the bashee) :defaulting) (respondent (the bashee)) ) :trickle-down-slots (respondent) :computed-slots ( ("String of HTML. Provides the developer control links for current sheet." development-links (with-cl-who-string () (write-the development-links)))) :hidden-objects ((standard-javascript-section :type 'sheet-section :js-to-eval :parse :inner-html (with-cl-who-string (:indent t) (when (the use-jquery?) (htm ((:script :src "/static/3rdpty/jquery/js/jquery.min.js")) ((:script :src "/static/3rdpty/jquery/js/jquery-ui.min.js")) ((:script :src "/static/3rdpty/jquery/js/jquery.layout.min.js")) ((:script :src "/static/3rdpty/jquery/js/superfish.min.js")) ((:script :src "/static/3rdpty/jquery/js/jquery.bgiframe.js")))) (when (the use-x3dom?) (htm ((:script :src (if (the local-assets?) "/static/3rdpty/x3dom/x3dom.js" "https://www.x3dom.org/download/1.7.2/x3dom.js") :id "x3dom_script")) #+nil ((:link :href (if (the local-assets?) "/static/3rdpty/x3dom/x3dom.css" "https://www.x3dom.org/download/1.7.2/x3dom.css") :rel "stylesheet")))) (when (the use-raphael?) (htm ((:script :id "raphael-script" :src (if (the local-assets?) "/static/3rdpty/raphael/js/raphael-min.js" "https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.7/raphael.min.js"))))) (when (the use-svgpanzoom?) (htm ((:script :id "svg-panzoom" :src (if (the local-assets?) "/static/3rdpty/svgpanzoom/svg-pan-zoom.min.js" "https://cdn.jsdelivr.net/npm/[email protected]/dist/svg-pan-zoom.min.js"))))) (when (the use-fontawesome?) (htm ((:link :id "fontawesome-css" :rel "stylesheet" :href (if (the local-assets?) "/static/3rdpty/fa/css/all.min.css" "https://use.fontawesome.com/releases/v5.3.1/css/all.css") :integrity (unless (the local-assets?) "sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU") :crossorigin "anonymous")))) (when (the use-anyresize?) (htm ((:script :id "anyresize-script" :src (if (the local-assets?) "/static/3rdpty/resize/any-resize-event.js" "https://is.gd/sAeEPt"))))) (when (the use-ajax?) (htm ((:script) (fmt "~%var gdliid = '~a';" (the instance-id))) ((:script :src (if (the local-assets?) "/static/gwl/js/gdlajax1593g.js" "https://genworks.com/static/gwl/js/gdlajax1593g.js"))))) (when (the ui-specific-layout-js) (htm ((:script :type "text/javascript" :src (the ui-specific-layout-js)))))))) :functions ((prepend-url-depth (string) (prepend-url-depth string (the url-depth))) (back-link (&key (display-string "&lt;-Back")) (w-c-w-s () ((:a :href (the return-object url)) (str display-string)))) (update-root! () (unpublish-instance-urls (the instance-id) (the url)) (the root update!) (the url) ) (reset-html-sections! () ;;(the (restore-slot-default! :%html-sections%)) ) (self-link (&key (display-string (the strings-for-display)) (display-color nil) (target nil) (title nil) class id on-click on-mouse-over on-mouse-out local-anchor) (with-cl-who-string () (write-the (self-link :display-string display-string :display-color display-color :target target :title title :class class :id id :on-click on-click :on-mouse-over on-mouse-over :on-mouse-out on-mouse-out :local-anchor local-anchor)))) (set-self () (if *break-on-set-self?* (progn (set-self self) (let ((*package* (symbol-package (the type)))) (break))) (progn (set-self self)))) ("Void. This is a hook function which applications can use to restore automatically from a saved snapshot file." custom-snap-restore! () ) )) (define-lens (html-format base-ajax-sheet)() :output-functions ((main-sheet () (with-cl-who () (str (the doctype-string)) ((:html :lang "en" :class (the html-class)) ((:head :class (the head-class)) (:title (str (the title))) (:meta :charset "UTF-8") (when (the include-default-favicon?) (htm (:link :rel "icon" :type "image/x-icon" :href "/static/gwl/images/favicon.ico"))) (when (the additional-header-content) (str (the additional-header-content))) (str (the standard-javascript-section main-div)) (when (the additional-header-js-content) (str (the additional-header-js-content)))) ((:body :class (the body-class) :onpageshow (the body-onpageshow) :onload (the body-onload) :onresize (the body-onresize)) (the reset-html-sections!) (str (the main-sheet-body)) #+nil ((:div :id (the dom-id)) (str (the main-sheet-body)) ) )))) (development-links () (with-cl-who () (:p (write-the update-full-link) " | " (write-the break-link) ))) (self-link (&key (display-string (the strings-for-display)) (display-color nil) (target nil) (title nil) class id on-click on-mouse-over on-mouse-out local-anchor) (with-cl-who () ((:a :href (if local-anchor (format nil "~a#~a" (the url) local-anchor) (the :url)) :target target :onmouseover on-mouse-over :onmouseout on-mouse-out :title title :class class :onclick on-click :id id) (if display-color (htm ((:font :color display-color) (str display-string))) (htm (str display-string)))))) (break-link (&key (display-string "SetSelf")) (with-cl-who () ((:span :style "color: blue; cursor: pointer;" :onclick (the (gdl-ajax-call :function-key :set-self))) (str display-string)))) (update-full-link () (with-cl-who () ((:span :style "color: blue; cursor: pointer;" :onclick (string-append (the (gdl-sjax-call :function-key :update-root!)) " location.reload(true);" )) "Update!"))) (main-sheet-body () (with-html-output (*stream*) "No Body has been defined."))))
16,470
Common Lisp
.lisp
362
33.254144
108
0.570396
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
4e7c97ece02bc900ce7e79540345c4ddcdc98e6bbdfd218a83790c6e4ce16cb2
36,012
[ -1 ]
36,013
ajax.lisp
lisp-mirror_gendl/gwl/ajax/source/ajax.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defparameter *ajax-snap-restore?* nil) (defparameter *self* nil) (defun quick-save (self &key (snap-folder (glisp:snap-folder))) (when *ajax-snap-restore?* (let ((snap-file (merge-pathnames (make-pathname :name (format nil "~a" (the instance-id)) :type "snap") snap-folder))) (with-error-handling () (the (write-snapshot :filename snap-file)))))) (defun restore-from-snap (iid) (when *ajax-snap-restore?* (let ((new-self (let ((snap-file (merge-pathnames (make-pathname :name (format nil "~a" iid) :type "snap") (glisp:snap-folder)))) (when (probe-file snap-file) (with-error-handling () (read-snapshot :filename snap-file :keys-to-ignore (list :time-last-touched :time-instantiated :expires-at))))))) (when new-self (setf (gethash (make-keyword (the-object new-self instance-id)) *instance-hash-table*) (list new-self nil)) (when (typep new-self 'session-control-mixin) (the-object new-self set-expires-at)) (the-object new-self set-instantiation-time!) (the-object new-self set-time-last-touched!) (format t "~%~%*************** Session ~a Restarted! ***************~%~%" (the-object new-self instance-id)) ;; ;; Force it to set html-sections. ;; ;; But, have to do the one at root-path as well if root-path is not nil. ;; (the-object new-self main-sheet-body) (the-object new-self custom-snap-restore!) ) ;; ;; FLAG for testing only. ;; return error object instead of just throwing an error here. ;; (unless new-self (error "Restoring of session ~a was not possible.~%" iid)) new-self))) (defparameter *new-debug?* nil) (defun gdlAjax (req ent) (let* ((query-plist (gwl::assoc-list-to-plist (request-query req))) (plist (progn (when *debug?* (print-variables query-plist)) (read-safe-string (base64-decode-safe (coerce (getf query-plist :|args|) 'string))))) (fields (progn (when *debug?* (print-variables plist)) (let ((encoded-fields (read-safe-string (base64-decode-safe (coerce (getf query-plist :|fields|) 'string))))) (mapcan #'(lambda(key value) (list key (if (or (glisp:match-regexp "^radio-" (string-downcase (format nil "~a" key))) (glisp:match-regexp "-checkedp$" (string-downcase (format nil "~a" key)))) value (base64-decode-safe value)))) (plist-keys encoded-fields) (plist-values encoded-fields))))) (raw-fields (getf query-plist :|raw-fields|)) (iid (getf plist :|iid|)) (self (first (gethash (make-keyword-sensitive iid) gwl:*instance-hash-table*))) (self (or self (restore-from-snap iid))) (plist-raw plist) (plist (decode-from-ajax plist self)) (bashee (getf plist :|bashee|)) (respondent (progn (when *debug?* (print-variables plist)) (or (getf plist :|respondent|) bashee))) (function (getf plist :|function|)) (js-vals (let ((jsvals (getf query-plist :|jsvals|))) (when jsvals (read-from-string jsvals)))) (arguments (getf plist :|arguments|))) (setq *self* self) (when *debug?* (let ((bashee-root (the-object bashee root-path)) (respondent-root (the-object respondent root-path))) (print-variables plist-raw plist raw-fields bashee-root respondent-root fields function) )) (let ((*clicked-x* (let ((string (getf query-plist :|x|))) (when string (ignore-errors (parse-integer string))))) (*clicked-y* (let ((string (getf query-plist :|y|))) (when string (ignore-errors (parse-integer string))))) (js-to-eval-previi (mapcar #'(lambda(section) (the-object section js-to-eval)) (the-object respondent html-sections)))) (let ((f-e-p (make-object 'form-element-processor :bashee bashee :query-plist (merge-plist-duplicates fields)))) (the-object f-e-p validate-and-set!) (when *debug?* (setq *f-e-p* f-e-p))) (when js-vals (the-object bashee (set-js-vals! js-vals))) (when function (with-error-handling (:timeout *ajax-timeout*) (the-object bashee ((evaluate function) (:apply arguments))))) (when (and respondent (the-object respondent root) (typep (the-object respondent root) 'session-control-mixin)) (the-object respondent root (set-expires-at))) (when (and respondent (the-object respondent root) (typep (the-object respondent root) 'session-control-mixin)) (the-object respondent root (set-time-last-touched!))) #+nil ;; FLAG -- add this back when cleaning up remote-objects. (when (and respondent (the-object respondent root) (the-object respondent root (set-remote-host! req)))) (quick-save self) (respond-with-new-html-sections req ent respondent :js-to-eval-previi js-to-eval-previi)))) (defun publish-gdlajax (server) (publish :path "/gdlAjax" :function 'gdlAjax :server server)) (pushnew 'publish-gdlajax *publishers*) #+nil (defun publish-gdlajax () (with-all-servers (server) (publish :path "/gdlAjax" :function 'gdlAjax :server server))) ;;(publish-gdlajax) ;; ;; FLAG -- remove this defunct version. ;; ;; (publish :path "/gdlAjax" :function 'gdlAjax) (defun wrap-cdata (string) (string-append "<![CDATA[" string "]]>")) (defun respond-with-nothing (req ent) (with-http-response (req ent :content-type "text/xml") (with-http-body (req ent) (with-html-output(*html-stream* nil) )))) (defun respond-with-new-html-sections (req ent respondent &key js-to-eval-previi) (the-object (make-object 'ajax-response :req req :ent ent :respondent respondent :js-to-eval-previi js-to-eval-previi) respond!)) (defparameter *current-status* nil) (eval-when (:compile-toplevel :load-toplevel :execute) (setq *current-status* *compile-dependency-tracking?*) (setq *compile-dependency-tracking?* nil)) (define-object ajax-response () :input-slots (req ent respondent (js-to-eval-previi nil)) :computed-slots ((security-ok? (the respondent root do-security-check)) (html-sections-stale (remove-if-not #'(lambda(object) (the-object object stale?)) (list-elements (the html-sections)))) (replace-lists (mapsend (the html-sections-stale) :replace-list)) (html-section-objects (the respondent html-sections)) (mismatch? (< (length (the js-to-eval-previi)) (length (the replace-lists))))) :objects ((html-sections :type 'html-replacement-section :sequence (:size (length (the html-section-objects))) :js-to-eval-previous (nth (the-child index) (the js-to-eval-previi)) :section (nth (the-child index) (the html-section-objects)))) :functions ((respond! () (when *debug?* (print-messages replace-lists)) (when (the mismatch?) (warn "the js-to-eval-previous is not the same length as html-section-objects in ~s~%" (the respondent))) (with-http-response ((the req) (the ent) :content-type "text/xml") (with-http-body ((the req) (the ent)) (with-html-output (*html-stream* nil) (when *debug?* (print-variables (socket:remote-host (net.aserve:request-socket (the req))))) (:document (mapc #'(lambda(replace-pair js-to-eval-status) (declare (ignore js-to-eval-status)) ;; this can play into the flag (when *debug?* (print-variables (base64-decode-safe (getf replace-pair :dom-id)))) (destructuring-bind (&key dom-id inner-html js-to-eval) replace-pair (let ((js-to-eval? (and js-to-eval (not (string-equal js-to-eval ""))))) (when (or inner-html js-to-eval?) (htm (:html-section (:|replaceId| (str dom-id)) (:|newHTML| (str (if inner-html (wrap-cdata (if (the security-ok?) inner-html (with-cl-who-string () (:i "Security Error")))) ""))) (:|jsToEval| (str (if (and js-to-eval? (the security-ok?)) (wrap-cdata js-to-eval) ""))))))))) (the replace-lists) (the js-to-eval-previi))))))))) (define-object html-replacement-section () :input-slots (section js-to-eval-previous) :computed-slots ((status (the section (slot-status :inner-html))) (js-status (the section (slot-status :js-to-eval))) (stale? (or (eql (the status) :unbound) (eql (the js-status) :unbound))) (dom-id (the section dom-id)) (inner-html (when (eql (the status) :unbound) (let ((timeout? nil)) (multiple-value-bind (value error backtrace) (ignore-errors-with-backtrace (the section inner-html)) (cond ((typep error 'error) (with-cl-who-string () (:i (esc (format nil "!! This section threw error: ~a !!" error))) (:pre (esc backtrace)))) (timeout? (with-cl-who-string () (:i (fmt "!! This section timed out after ~a seconds. You can reload to get previous state" *ajax-timeout*)) (:pre (esc backtrace)))) (t value)))))) (js-to-eval (multiple-value-bind (value error) (ignore-errors (the section js-to-eval)) (if (typep error 'error) (with-cl-who-string () (:i (fmt "alert('This section threw error: ~a !!');" error))) (if (equalp value :parse) "parseme" value)))) (replace-list (progn (when *debug?* (print-variables (the stale?) (the section root-path))) ;;(print-variables (the section root-path)) (when t ;; (the stale?) ;; already filtering for stale? before calling now. (list :dom-id (the dom-id) :inner-html (the inner-html) :js-to-eval (the js-to-eval))))))) (eval-when (:compile-toplevel :load-toplevel :execute) (setq *compile-dependency-tracking?* *current-status*)) #+nil (defun remove-html-sections (sections string) (remove-substrings string (mapsend sections :main-div))) #+nil (defun remove-substrings (string substrings) (let ((result string)) (dolist (substring substrings result) (setq result (replace-substring result substring "")))))
11,838
Common Lisp
.lisp
247
38.611336
121
0.613508
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
3fa494d81bea964241ea2fbccbd9ad724dbe2f7c4b4d1ed218a0c3a57b784f45
36,013
[ -1 ]
36,014
parameters.lisp
lisp-mirror_gendl/gwl/ajax/source/parameters.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defparameter *ajax-timeout* 60)
925
Common Lisp
.lisp
22
39.318182
71
0.742985
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
ebd8e603e956b12ff35dab61e45e2a17926388c028fc3e51b7790ee56faf5a65
36,014
[ -1 ]
36,015
slider-form-control.lisp
lisp-mirror_gendl/gwl/js-libs/jquery/source/slider-form-control.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :jquery) (define-object slider-form-control (text-form-control) :input-slots ( (slider-min 0) (slider-max 200) (slider-onmouseup nil) (read-only? nil) (default 0) (size 5) (readonly? (the read-only?)) (style "margin-left: 10px; height: 19px; top: 10px; font: 0.7em Trebuchet MS, Arial, Helvetica, sans-serif;") (title "slider value") (css-file "/jquery/css/slider.css")) :computed-slots ( (slider-id (format nil "~a-slider" (the id))) (slider-value (the value)) ;(the default) (slider-stepping 1) (slider-init-function (format nil " var slider1Value = ~a; var slider1Stepping = ~a; var slider1Min = ~a; var slider1Max = ~a; var slider_init = function() { $(\"#~a\").slider({ 'stepping': slider1Stepping, 'min': slider1Min, 'max': slider1Max, 'startValue': ~a, //slider1Value, 'slide': function(e, ui){ document.getElementById(\"~a\").value = ui.value;}}); $(\"#~a\").attr(\"value\",slider1Value); $(\"#~a\").blur(function(){ var slider1Value = this.value; if (slider1Value >= slider1Min && slider1Value <= slider1Max){ $('#~a').slider('moveTo',slider1Value); }else{ alert('Please enter a value between '+slider1Min+' and '+slider1Max); return false; }}); //alert('About to move slider...'); $('#~a').slider('moveTo',~a); }; " (the slider-value) (the slider-stepping) (the slider-min) (the slider-max) (the slider-id) (the slider-value) (the id) (the id) (the id) (the slider-id) (the slider-id) (the slider-value) )) (js-string (string-append (the slider-init-function) "$(document).ready(slider_init);")))) (define-lens (html-format slider-form-control)() :output-functions ((form-control () (html-stream *stream* (:div ;; ;; FLAG -- insert only one of these if any sliders detected in page. ;; ((:link :rel "stylesheet" :type "text/css" :href (format nil "~a" (the css-file)))) ((:script :type "text/javascript" :language "JavaScript") (:princ (the js-string))) (:table (:tr (:td (:princ (format nil "~a" (the slider-min)))) (:td ((:div :id (the slider-id) :class "ui-slider-1" :style "margin: 2px; margin-left: 2px; margin-right: 2px;" :if* (the slider-onmouseup) :onmouseup (the slider-onmouseup)) ((:div :class "ui-slider-handle")))) (:td (:princ (format nil "~a" (the slider-max)))) (:td (call-next-method)))) )))))
4,389
Common Lisp
.lisp
98
30.918367
113
0.54904
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
5a65c6bdd5f8b1f2c3d25a3993d36ab312f76e592e8910dbeaced587d236622b
36,015
[ -1 ]
36,016
package.lisp
lisp-mirror_gendl/gwl/js-libs/jquery/source/package.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl-user) (gwl:define-package :jquery (:export #:slider-form-control ))
953
Common Lisp
.lisp
22
40.863636
71
0.741622
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
dcf08750a38db2dabf211f2de09ab3421c3aadb4806c75acb5c15ac840f4c5dd
36,016
[ -1 ]
36,017
session-report.lisp
lisp-mirror_gendl/gwl/gwl-session/source/session-report.lisp
(in-package :gwl) ;;-------------------------------------------------- ;; Author : Brian Sorg, Liberating Insight ;; ;; ;; Date : created April 3rd, 2005 ;; ;; Copyright April 2005 Liberating Insight LLC ;; ;; License: Users of this file are granted the rights to distribute ;; and use this software as governed by the terms of the ;; Lisp Lesser GNU Public License ;; (http://opensource.franz.com/preamble.html), also known ;; as the LLGPL. ;;------------------------------------------------- (defun session-report () "Returns list of instances in a runtime environment. Those that are of type session-control-mixin, it provides more detailed information, that can be useful in tracking the session life. Currently, this is intended to run from the lisp command prompt." (let ((session-active 0) (session-recovery 0) (unknown 0)) (maphash #'(lambda (k v) (let ((inst (car v))) (if (typep inst 'session-control-mixin) (let ((recovery? (typep inst 'session-recovery))) (if recovery? (incf session-recovery) (incf session-active)) (format t "Key: ~a Org Type: ~s Is Active?: ~a Expires: ~a~%" k (the-object inst :org-type) (not (typep inst 'session-recovery)) (when (the-object inst expires-at) (multiple-value-bind (sec min hr day mon yr) (decode-universal-time (the-object inst expires-at)) (format nil "~d-~2,'0d-~2,'0d :: ~2,'0d:~2,'0d:~2,'0d" yr mon day hr min sec))))) (progn (incf unknown) (format t "~a ~s~%" k inst))))) *instance-hash-table*) (format t "~2%************ Summary **************~%") (format t " Active sessions: ~d Recovery sessions: ~d Other sessions: ~d ----- Total sessions: ~d" session-active session-recovery unknown (+ session-active session-recovery unknown))))
1,969
Common Lisp
.lisp
48
35.416667
255
0.577104
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
e315633fca7dc3de68aa8c052cf4628282512d70b0e18da9b04829649bda9380
36,017
[ -1 ]
36,018
session-control-mixin.lisp
lisp-mirror_gendl/gwl/gwl-session/source/session-control-mixin.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) ;;-------------------------------------------------- ;; Author : Brian Sorg, Liberating Insight ;; Revised: David Cooper, Genworks, 2004-09-16 ;; ;; Date : created September 10 ;; ;; Copyright September 2004 Liberating Insight LLC ;;------------------------------------------------- ;; ;; Definition moved to answer.lisp. ;;
1,230
Common Lisp
.lisp
32
35.84375
71
0.670608
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
e7b755372f532160a82f9d9006c16210737738fa5da2e34a53df6b313019684e
36,018
[ -1 ]
36,019
functions.lisp
lisp-mirror_gendl/gwl/gwl-session/source/functions.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defun start-session-reaper (&key (minutes 20) (debug? t) (listeners 20) extra-functions) (format t "~2%Lauching Expired Session Reaper to awaken and run every ~a minute~:p~2%" minutes) (glisp:process-run-function "GWL Session Reaper" #'(lambda() (do ()(nil) (sleep (* minutes 60)) (when debug? (format t "~&Reaper waking up...~%")) (when *reap-expired-sessions?* (maphash #'(lambda(key val) (declare (ignore key)) (when (typep (first val) 'session-control-mixin) (the-object (first val) (clear-expired-session :debug? debug?)))) *instance-hash-table*)) ;; ;; FLAG -- we need to finish any open requests first, then lock out ;; any new requests while all this is happening... ;; (glisp:w-o-interrupts (let ((port (server-port))) (when (and port (>= port 1000)) (net.aserve:shutdown) (net.aserve:start :port port :listeners listeners))) (mapc #'funcall (ensure-list extra-functions)) (glisp:gc-full)))))) (defun publish-make-and-answer (server) (publish :path "/make" :server server :content-type "text/html" :function 'make-object-internal) (publish :path "/answer" :server server :content-type "text/html" :function 'answer)) (pushnew 'publish-make-and-answer *publishers*) (defun publish-fixed-prefix (fixed-prefix) (with-all-servers (server) (publish :path (string-append "/" fixed-prefix "/make") :server server :content-type "text/html" :function 'make-object-internal) (publish :path (string-append "/" fixed-prefix "/answer") :server server :content-type "text/html" :function 'answer)))
2,862
Common Lisp
.lisp
62
36.903226
98
0.617476
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
d0a1a19861a5f256b369b76e849e58b9d820eb6c2cf098027fa32ac330ef3b33
36,019
[ -1 ]
36,020
session-recovery.lisp
lisp-mirror_gendl/gwl/gwl-session/source/session-recovery.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) ;;-------------------------------------------------- ;; Author : Brian Sorg, Liberating Insight ;; ;; Date : created September 10 ;; ;; Copyright September 2004 Liberating Insight LLC ;;------------------------------------------------- ;; ;; definition moved to answer.lisp ;;
1,172
Common Lisp
.lisp
31
35.483871
71
0.669604
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
76accbc355c599f69de2188e39cd6e264eb495bd8cb460c5287b716a0ddcd873
36,020
[ -1 ]
36,021
parameters.lisp
lisp-mirror_gendl/gwl/gwl-session/source/parameters.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defparameter *reap-expired-sessions?* t "Allows one to turn on and off the expired session reaper without starting and stopping the reaper thread")
1,045
Common Lisp
.lisp
22
44.590909
149
0.750745
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
11cd7390ea9ce3d80268bed9d6fdf9c16481fd2235ec84d7515ea567435da348
36,021
[ -1 ]
36,022
session-control-auto-refresh.lisp
lisp-mirror_gendl/gwl/gwl-session/source/session-control-auto-refresh.lisp
(in-package :gwl) ;;-------------------------------------------------- ;; Author : Brian Sorg, Liberating Insight ;; ;; Date : created Nov 30, 2004 ;; ;; Copyright November 2004 Liberating Insight LLC ;; ;; License: Users of this file are granted the rights to distribute ;; and use this software as governed by the terms of the ;; Lisp Lesser GNU Public License ;; (http://opensource.franz.com/preamble.html), also known ;; as the LLGPL. ;;------------------------------------------------- (defun session-control-auto-refresh (timeout &optional (html-stream *html-stream*)) "Adding this javascript function into the header of a web page will cause the page to timeout and reload repeatedly. This is intended to be used such that when an instance is open in an active browser the page will automatically update the expires-at function even if the operator takes an extended break from the application. It works by checking if any forms exist on this page. If they do it will submit the first form on the page when the timeout value is reached. This is done to avoid the Post Data confirmation warning that most browser present. If no forms are found it will use the reload(true) function to reload the page. :arguments (timeout \"Time in seconds between page reloads\") :&optional (html-stream \"Stream which the output should be sent to. Default is *html-stream*\") " (format html-stream " <script language=\"Javascript\" type=\"text/javascript\"> <!-- sessionAutoRefreshID = window.setTimeout(\"autoRefresh() ;\",~a); function autoRefresh () { var pageForms = document.forms.length ; if (pageForms == 0) { window.location.reload(true) ; } else { document.forms[0].submit() ; } } // --> </script> " (* timeout 1000)))
1,908
Common Lisp
.lisp
41
42.04878
168
0.656318
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
d15c0edc753165c9ec29375361d14db395c96e62297419986da6fed83b66a704
36,022
[ -1 ]
36,023
test.lisp
lisp-mirror_gendl/gwl/gwl-session/source/test.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl-user) (define-object test (gwl::session-control-mixin base-html-sheet) :computed-slots ((expires-at (+ (get-universal-time) 10)) (recovery-url "/test.gdl") (recovery-expires-at (+ (the expires-at) (* 60 2))))) ;; 2 minutes after the recovery instance created ;; ;; FLAG -- move into main package.lisp for GWL. ;; (eval-when (compile load eval) (export 'session-control-mixin)) (define-view (html-format test) () :output-functions ((main-sheet () (html (:html (:body (when gwl:*developing?* (the (write-development-links))) (:p (the write-self-link)) (with-html-form () ((:input :type :submit))))))))) (publish :path "/test.gdl" :function #'(lambda (req ent) (gwl-make-object req ent "gwl-user::test")))
1,713
Common Lisp
.lisp
43
35.186047
106
0.6774
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
d514ca07781d2c0317f26d2387a541f358ed98b1c70bd1b82796e0701c423d17
36,023
[ -1 ]
36,024
cleanup.lisp
lisp-mirror_gendl/gwl/gwl-session/source/cleanup.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (eval-when (compile load eval) (export 'clear-old-timers)) (define-object old-timers () :input-slots ((idle-time-required 600)) :computed-slots ((root-instances (let (result) (maphash #'(lambda(key val) (declare (ignore key)) (push (first val) result)) *instance-hash-table*) result)) (old-timers-ids (mapsend (remove-if-not #'(lambda(instance) (> (- (get-universal-time) (the-object instance time-last-touched)))) (the root-instances)) :instance-id))) :functions ((clear () (mapc #'(lambda(id) (clear-instance id)) (the old-timers-ids))))) (defun clear-old-timers (&key (idle-time-required 600)) "Void. This is a lighter-weight alternative to the session-object-mixin for timing out instances in a web application. :&key ((idle-time-required 600) \"Time in seconds. The maximum age of a session for timeout.\") " (the-object (make-object 'old-timers :idle-time-required idle-time-required) clear)) (defun clear-all-instances () "Void. Clears all instances from GWL's master table of root-level instances. The instance IDs are the numbers you see in published GWL URIs, and are available as the \"instance-id\" message within each GWL object which inherit from base-html-sheet. Clearing all the instances makes available for garbage collection all memory used by the object hierarchies rooted at the instances, as well as all associated published URIs. :example <pre> (clear-all-instance) </pre>" (maphash #'(lambda(key val) (declare (ignore val)) (unless (member key *keys-to-preserve*) (clear-instance key))) *instance-hash-table*)) (defparameter *instance-finalizers* nil "CL Function of one argument. The argument is a keyword representing a GWL Instance ID. This is an application-specific function (either a symbol naming a function, or a lambda expression) which will be run after an instance is cleared with the standard clear-instance function. The default is nil which indicates that no finalizer function will be run.") (defun clear-instance (id) "Void. Clears the specified instance from GWL's master table of root-level instances. The instance ID is the same number you see in published GWL URIs, and is available as the \"instance-id\" message within all GWL objects which inherit from base-html-sheet. Clearing the specified instance makes available for garbage collection all memory used by the object hierarchy rooted at the instance, as well as all associated published URIs. :arguments (id \"Integer or Keyword Symbol. The key whose entry you wish to clear from the *instance-hash-table*.\") :example <pre> (clear-instance 639) </pre>" (when (not (keywordp id)) (setq id (make-keyword id))) (clear-instance-from-hash id) (unpublish-instance-urls id) (dolist (finalizer *instance-finalizers*) (funcall finalizer id))) (defun unpublish-instance-urls (id &optional base-url) (when (not (keywordp id)) (setq id (make-keyword id))) (setq base-url (when base-url (subseq base-url 0 (- (length base-url) (length "index.html"))))) (when *debug?* (print-variables id base-url)) (let ((urls (gethash id *url-hash-table*)) remaining-urls) (mapc #'(lambda(url) (if (or (null base-url) (and (search base-url url) (not (search "$$tatu" url)))) (progn (when *debug?* (format t "found one~%")) ;; ;; FLAG figure out what to do for proxy locators ;; (unless (typep (first (wserver-locators *wserver*)) 'net.aserve::locator-proxy) ;; ;;FLAG DEBUG ;; (when *debug?* (let ((url-to-unpub url)) (print-variables url-to-unpub))) (net.aserve::unpublish-entity (first (wserver-locators *wserver*)) url nil nil))) (push url remaining-urls))) urls) (if remaining-urls (setf (gethash id *url-hash-table*) (nreverse remaining-urls)) (remhash id *url-hash-table*)))) ;; ;; !!!! ;; !!!! FLAG -- also remove all urls from *descriptive-url-hash* and *url-hash-table* ;; !!!! ;; (defun clear-instance-from-hash (id) (when (not (keywordp id)) (setq id (make-keyword id))) (remhash id *instance-hash-table*))
5,452
Common Lisp
.lisp
109
42.559633
116
0.66325
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
2194a70f06762f285fd7ad5a17e829ddf96e3bdf5555778e8f623a1542ba1a60
36,024
[ -1 ]
36,025
presets.lisp
lisp-mirror_gendl/gwl/source/presets.lisp
(in-package :gwl) ;; ;; FLAG --- need to use asdf around-compile method (or something like ;; it) to set these only temporarily. ;; (setq cl-who:*prologue* "<!doctype HTML>") (setq cl-who:*attribute-quote-char* #\") (setq cl-who:*downcase-tokens-p* nil)
255
Common Lisp
.lisp
8
30.75
69
0.699187
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
84c2dad5a8b94f2d5ae2e9cab9c709232631b2a01a8d823f8b7a495618a14b3e
36,025
[ -1 ]
36,026
security-check-failed.lisp
lisp-mirror_gendl/gwl/source/security-check-failed.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (define-object security-check-failed (base-html-sheet)) (define-lens (html-format security-check-failed)() :output-functions ((main-sheet () (with-cl-who () (:html (:head (:title "Security Check Failed")) (:body (:center (:h2 "Security Check Failed")) (:p "This is most likely because you are coming from a different IP address than the one originally assigned to this session.")))))))
1,336
Common Lisp
.lisp
30
40.366667
155
0.70679
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
e6a12c707238ac1c01e700476ade5301662fd2c62bf35d6a4303af2df3094387
36,026
[ -1 ]
36,027
package.lisp
lisp-mirror_gendl/gwl/source/package.lisp
(in-package :common-lisp-user) ;; ;; FLAG -- clean out symbol dependencies of (:net.aserve :net.aserve.client :net.uri :net.html.generator :cl-who) ;; (eval-when (:compile-toplevel :load-toplevel :execute) (use-package (list :gwl :net.aserve :net.aserve.client :net.uri :net.html.generator :cl-who) :gwl)) (eval-when (:compile-toplevel :load-toplevel :execute) (defmacro gwl:define-package (name &rest args) `(gdl:define-package ,name (:shadow #:define-package) (:use :gwl :net.aserve :net.aserve.client :net.uri :net.html.generator :cl-who) ,@args))) (gwl:define-package :gwl-user)
613
Common Lisp
.lisp
13
43.846154
113
0.705882
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
d7b55fd202e711b98920547923ad792d75f2626d4307b9c26c37f5ca4a7f8427
36,027
[ -1 ]
36,028
accessories.lisp
lisp-mirror_gendl/gwl/source/accessories.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (define-object update (base-html-sheet) :input-slots (return-to)) (define-lens (html-format update)() :output-functions ((main-sheet () (let ((root (the :root)) (return-to-root-path (the :return-to :root-path))) (the return-to (:update!)) ;; FLAG -- handle condition where this part no longer exists ;; after update. ;; (the-object root (:follow-root-path return-to-root-path) (:write-html-sheet)))))) (define-object update-full (base-html-sheet) :input-slots (return-to)) (define-lens (html-format update-full)() :output-functions ((main-sheet () (let ((root (the :root)) (return-to-root-path (the :return-to :root-path))) (the-object root (:update!)) ;; FLAG -- handle condition where this part no longer exists ;; after update. ;; (the-object root (:follow-root-path return-to-root-path) (:write-html-sheet)))))) (define-object break-on (base-html-sheet) :input-slots (break-on) :functions ((write-html-sheet nil (set-self (the break-on)) (the break-on write-html-sheet))))
2,112
Common Lisp
.lisp
59
30.033898
71
0.658853
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
03311cb746bfd613d9bff5d782315e8e11c398e0513f25c75a9f84439f83bc3c
36,028
[ -1 ]
36,029
gdl-remote.lisp
lisp-mirror_gendl/gwl/source/gdl-remote.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) ;; ;; This is now defined up-front in gdl/base/prereqs/source/utilities.lisp. ;; #+nil (defclass gdl-remote () () (:metaclass gdl-class))
1,032
Common Lisp
.lisp
27
35.740741
75
0.732733
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
38a0fea19c54becc367bfb68e6cca53e60813f37a8d1c1462f28f14e51f4a2ae
36,029
[ -1 ]
36,030
publish.lisp
lisp-mirror_gendl/gwl/source/publish.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defparameter *bug* nil) (defparameter *remote-hash-lock* (bt:make-lock "remote-hash-lock")) (defparameter *remote-proxy-lock* (bt:make-lock "remote-proxy-lock")) (defparameter *remote-evaluate-lock* (bt:make-lock "remote-evaluate-lock")) (defparameter *remote-fetch-input-lock* (bt:make-lock "remote-fetch-input-lock")) (defparameter *request-server-ipaddr* nil) (defmethod decode-plist-from-url ((syntax (eql :lisp)) argstring) (base64-decode-list argstring)) (defmethod decode-plist-from-url ((syntax (eql :json)) string) (let* ((argstring (base64-decode-safe string)) (yason-string (read-safe-string argstring)) (plist (yason:parse yason-string :object-key-fn #'make-keyword :object-as :plist))) (unstringify-plist plist))) (defparameter *remote-syntax* nil) (defun remote-function-handler (handler &key (encode t)) ;;&optional lock #'(lambda (req ent) (progn ;; bt:with-lock-held (lock) (let* ((socket (request-socket req)) (*request-server-ipaddr* (socket:ipaddr-to-dotted (socket:local-host socket))) (*ipaddr* (socket:ipaddr-to-dotted (socket:remote-host socket))) (query (request-query req)) (args (rest (assoc "args" query :test #'string-equal))) (syntax-string (rest (assoc "syntax" query :test #'string-equal))) (*remote-syntax* (if syntax-string (read-safe-string syntax-string) :json)) (args-list (decode-plist-from-url *remote-syntax* args))) (when (eql excl:*current-case-mode* :case-sensitive-lower) (setq args-list (downcase-plist args-list))) (glisp:with-heuristic-case-mode () (with-http-response (req ent) (with-http-body (req ent) (let ((value (funcall handler args-list))) (if encode (let ((encoded-value (base64-encode-safe (format nil "~s" (encode-for-http value))))) (html (format *html-stream* "~a" encoded-value))) (html (format *html-stream* "~s" value))))))))))) (defun igetf (plist key) (or (getf plist key) (getf plist (make-keyword (string-upcase key))))) (defun normalize-case (string) (print-variables string) #-allegro string #+allegro (if (eql excl:*current-case-mode* :case-sensitive-lower) (string-downcase string) string)) (defun publish-dgdl-funcs (server) (publish-file :path "/favicon.ico" :server server :file (format nil "~a" (if glisp:*genworks-source-home* (merge-pathnames "gwl/static/gwl/images/favicon.ico" glisp:*gendl-source-home*) (merge-pathnames "static/gwl/images/favicon.ico" glisp:*gdl-home*)))) (publish :path "/fetch-remote-input" :server server :function (remote-function-handler #'(lambda (args-list) ;; ;; FLAG -- consider a warning if package not found ;; (let ((*package* (or (find-package (igetf args-list :package)) *package*))) (let* ((object (the-object (gethash (let ((id (igetf args-list :remote-id))) #+allegro (when (eql excl:*current-case-mode* :case-sensitive-lower) (setq id (make-keyword (string-downcase id)))) (print-variables id) id) *remote-objects-hash*) (follow-root-path (igetf args-list :remote-root-path)))) (part-name (make-keyword (normalize-case (igetf args-list :part-name)))) (index (igetf args-list :index)) (child (if index (the-object object ((evaluate part-name) index)) (the-object object (evaluate part-name)))) (message (igetf args-list :message)) (gdl::*notify-cons* (decode-from-http (igetf args-list :notify-cons))) (args (igetf args-list :args))) (if object (multiple-value-bind (value error) (ignore-errors (apply (symbol-function (glisp:intern (normalize-case message) :gdl-inputs)) object (glisp:intern (normalize-case part-name) :gdl-acc) child args)) (if (typep error 'error) (let ((error-string (glisp:replace-regexp (format nil "~a" error) "\\n" " "))) (cond ((or (search "could not handle" error-string) #+nil (search "which is the root" error-string) (search "instances could handle" error-string)) 'gdl-rule:%not-handled%) (t (when *debug?* (format t "Throwing error on fetch-input server because gwl::*debug?* is set to non-nil~%") (error error)) (list :error (format nil "~a" error))))) value)) (list :error :no-such-object (igetf args-list :remote-id)))))))) #+nil (publish :path "/fetch-remote-input" :server server :function (remote-function-handler #'(lambda (args-list) ;; ;; FLAG -- consider a warning if package not found ;; (let ((*package* (or (find-package (getf args-list :package)) *package*))) (let* ((object (the-object (gethash (getf args-list :remote-id) *remote-objects-hash*) (follow-root-path (getf args-list :remote-root-path)))) (part-name (getf args-list :part-name)) (index (getf args-list :index)) (child (if index (the-object object ((evaluate part-name) index)) (the-object object (evaluate part-name)))) (message (getf args-list :message)) (gdl::*notify-cons* (decode-from-http (getf args-list :notify-cons))) (args (getf args-list :args))) (if object (multiple-value-bind (value error) (ignore-errors (apply (symbol-function (glisp:intern message :gdl-inputs)) object (glisp:intern part-name :gdl-acc) child args)) (if (typep error 'error) (let ((error-string (glisp:replace-regexp (format nil "~a" error) "\\n" " "))) (cond ((or (search "could not handle" error-string) #+nil (search "which is the root" error-string) (search "instances could handle" error-string)) 'gdl-rule:%not-handled%) (t (when *debug?* (format t "Throwing error on fetch-input server because gwl::*debug?* is set to non-nil~%") (error error)) (list :error (format nil "~a" error))))) value)) (list :error :no-such-object (getf args-list :remote-id)))))))) (publish :path "/unbind-slots" :server server :function (remote-function-handler #'(lambda (args-list) (let ((object (let ((root (the-object (gethash (getf args-list :remote-id) *remote-objects-hash*)))) (when root (the-object root (follow-root-path (getf args-list :remote-root-path)))))) (slot (getf args-list :slot))) (when object (gdl::unbind-dependent-slots object slot)) nil)))) (publish :path "/send-remote-message" :server server :function (remote-function-handler 'send-remote-message)) (publish :path "/send-remote-output" :server server :function (remote-function-handler #'(lambda (args-list) (let ((*package* (or (find-package (getf args-list :package)) *package*))) (let ((object (the-object (gethash (getf args-list :remote-id) *remote-objects-hash*) (follow-root-path (getf args-list :remote-root-path)))) (*%format%* (apply #'make-instance (getf (getf args-list :format) :type) (decode-from-http (rest (rest (getf args-list :format)))))) (message (getf args-list :message)) (args (getf args-list :args))) (with-output-to-string (*stream*) (apply (glisp:intern message :gdl-output) *%format%* object t ;; flag pick up skin args))))))) ;; ;; FLAG -- return proper error when requested object type does not exist ;; or make-object fails for any other reason. ;; (publish :path "/make-remote-object" :server server :function (remote-function-handler #'(lambda (args-list) (when *debug?* (format t "~%In make-remote-object response func:~%") (print-variables args-list)) (let ((*package* (or (find-package (getf args-list :package)) *package*)) (name (getf args-list :name)) (index (getf args-list :index)) (rest-args (remove-plist-keys args-list (list :parent-form :current-id :name :index :type :package :host :port))) (current-id (getf args-list :current-id)) (parent-form (getf args-list :parent-form))) (setf parent-form (multiple-value-bind (type plist) (destructure-object-from-http parent-form) (setf (getf plist :host) *ipaddr*) (construct-object-for-http type plist))) (when current-id (let ((removed? (remhash current-id *remote-objects-hash*))) (when removed? (format t "~&~%Removed stale remote object with ID ~s.~%~%" current-id)))) (let ((object (make-object (read-safe-string (getf args-list :type)) :type (read-safe-string (getf args-list :type)))) (new-id (make-keyword (make-new-instance-id)))) (the-object object (set-slot! :%name% name :warn-on-non-toplevel? nil)) (the-object object (set-slot! :remote-id new-id :remember? nil :warn-on-non-toplevel? nil)) (the-object object (set-slot! :%index% index :warn-on-non-toplevel? nil)) (setf (slot-value object 'gdl-acc::%parent%) (list (decode-from-http parent-form) nil t)) (setf (gethash new-id *remote-objects-hash*) object) (format t "~&~%Created new remote object with ID ~s and arglist: ~s~%~%" new-id rest-args) new-id))) :encode nil)) (publish :path "/delete-remote-object" :server server :function (remote-function-handler #'(lambda (args-list) (let* ((current-id (getf args-list :current-id)) (object (gethash current-id *remote-objects-hash*))) (cond (object (remhash current-id *remote-objects-hash*) (the-object object (set-slot! :remote-id nil :remember? nil :warn-on-non-toplevel? nil)) :ok) (t :unknown-id)))) :encode nil)) ) (pushnew 'publish-dgdl-funcs *publishers*) (defun send-remote-message (args-list) (when *debug?* (format t "~%In send-remote-message-object response func:~%") (print-variables args-list *ipaddr* *request-server-ipaddr*)) (let ((*package* (or (find-package (getf args-list :package)) *package*))) (let ((object (when (gethash (getf args-list :remote-id) *remote-objects-hash*) (the-object (gethash (getf args-list :remote-id) *remote-objects-hash*) (follow-root-path (getf args-list :remote-root-path))))) (message (getf args-list :message)) (gdl::*notify-cons* (decode-from-http (getf args-list :notify-cons))) (args (getf args-list :args))) (when *debug?* (print-variables args)) (if object (multiple-value-bind (value error) (progn ;; bt:with-lock-held (*remote-evaluate-lock*) (ignore-errors (if args (the-object object ((evaluate message) (:apply args))) (the-object object (evaluate message))))) (if (typep error 'error) (progn (when *debug?* (error error)) (list :error (format nil "~a" error))) value)) (list :error :no-such-object (getf args-list :remote-id)))))) ;;; ;;; FLAG -- Should *remote-proxies-hash* be a weak-on-value hash table? ;;; (defmethod evaluate-object ((category (eql :remote-gdl-instance)) args) (let ((hash-key (list (getf args :id) (getf args :root-path)))) (progn ;; bt:with-lock-held (*remote-proxy-lock*) (or (gethash hash-key gwl::*remote-proxies-hash* ) (progn (format t "~%~%~s Not found in hash - creating fresh ~%~%" (getf args :id)) (setf (gethash hash-key *remote-proxies-hash*) ;; Note that this avoids the usual request to create a new target on the remote ;; by specifying the :remote-id arg explicitly. (gdl::make-object-internal 'remote-object :%parent% (list nil nil t) :%index% (list (getf args :index) nil t) :remote-id (list (getf args :id) nil t) :host (list (or *ipaddr* (getf args :host)) nil t) :port (list (getf args :port) nil t) :remote-root-path (list (getf args :root-path) nil t) :remote-type (list (multiple-value-bind (result error) (ignore-errors (read-from-string (getf args :type))) (if (typep error 'error) :unknown result)) nil t)))))))) (defun clear-dgdl () (clrhash *remote-proxies-hash*) (clrhash *remote-objects-hash*))
17,347
Common Lisp
.lisp
296
38.324324
142
0.488558
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
ccbb0fba4ce868308b305063e623a61d0a278d23487af5ab4ba2aacc3c66f1ac
36,030
[ -1 ]
36,031
base-html-sheet.lisp
lisp-mirror_gendl/gwl/source/base-html-sheet.lisp
;; ;; Copyright 2013 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defmethod encode-for-ajax ((item t)) item) (defmethod encode-for-ajax ((item list)) (when item (cons (encode-for-ajax (first item)) (encode-for-ajax (rest item))))) (defmethod encode-for-ajax ((self gdl::root-path-container)) (list :%container-rp% (the root-path))) (defmethod encode-for-ajax ((self gdl::gdl-basis)) (list :%rp% (the root-path))) (defmethod decode-from-ajax ((item t) self) (declare (ignore self)) item) (defmethod decode-from-ajax ((item list) self) (when item (cond ((eql (first item) :%rp%) (the (follow-root-path (getf item :%rp%)))) ((eql (first item) :%container-rp%) (make-object 'gdl::root-path-container :root-path (getf item :%container-rp%))) (t (cons (decode-from-ajax (first item) self) (decode-from-ajax (rest item) self)))))) (defmacro with-cl-who ((&rest args) &body body) "Form. Sets up body to be evaluated with cl-who and output the resulting string to the default *stream* Note that the args are spliced into cl-who:with-html-output after *stream* nil, so for example you can do <pre> (with-cl-who (:indent t) ...) </pre> and it will expand into: <pre> (with-html-output (*stream* nil :indent t) ...) </pre> ." `(with-format (html-format *stream*) (with-html-output (*stream* nil ,@args) ,@body))) (defmacro with-cl-who-string ((&rest args) &body body) "Form. Sets up body to be evaluated with our with-cl-who return the resulting string instead of side-effecting anything at all to the default *stream*." `(with-output-to-string (*stream*) (with-cl-who (,@args) ,@body))) (defmacro with-htm (&body body) `(with-cl-who-string () ,@body)) (define-object base-html-sheet (sheet-section) :documentation (:description "This mixin allows a part to be displayed as a web page in GWL. The main output can be specified either in a <tt>write-html-sheet</tt> function in the object which mixes this in, or in a <tt>main-sheet</tt> output-function in an html-format view of the object.") :input-slots ( (respondent (the bashee) :defaulting) ;;(respondent (the bashee)) ("GDL object. Default object to which control will return with the write-back-link method" return-object (the :parent)) ("String. Name of a browser frame or window to display this page. Default of NIL indicates to use the same window." target nil) (instance-id nil :defaulting) (cookies-to-send nil) (cookies-received nil :settable) (fixed-url-prefix nil :defaulting) (tree-root (the root) :defaulting) ;; ;; Stuff to support dashboard ;; (time-last-touched nil :settable) (time-instantiated nil :settable) (last-visited-root-path nil :settable) (remote-host-original nil :settable) (remote-host nil :settable) ("List of keyword symbols. Messages corresponding to form fields which should not be retained against Updates to the model (e.g. calls to the update! function or hitting the Update button or link in the browser in development mode). Defaults to NIL (the empty list)." transitory-slots nil) ("Boolean. Determines whether a a sanity check is done (with the <tt>check-sanity</tt> function) before presenting the response page if this page is a respondent. Default is NIL." check-sanity? nil) (home-page nil :defaulting) ($$tatu-object (the $$tatu) :settable) ($$ta2-object (the $$ta2) :settable) (plain-url? nil :defaulting) (host nil :defaulting) (query-toplevel nil :settable)) :computed-slots ( ("Plist. Extra http headers to be published with the URI for this page." header-plist nil) ;; ;; FLAG -- replace localhost with computed hostname from running machine. ;; (full-url (when *wserver* (format nil "http://localhost:~a~a" (server-port) (the url)))) ("String. The web address in the current session which points at this page. Published on demand." url (let ((url (if (the plain-url?) (format nil "/~a" (the (compute-url))) (format nil "~a/sessions/~a/~a" (if (the fixed-url-prefix) (format nil "/~a" (the fixed-url-prefix)) "") (the :instance-id) (the (compute-url)))))) (with-all-servers (server) (publish :path url :server server :content-type "text/html; charset=UTF-8" :host (the host) :function #'(lambda (req ent) (the before-response!) (present-part req ent url :instance-id (when (the plain-url?) (the instance-id)) :header-plist (the header-plist) :fixed-prefix (the fixed-url-prefix))))) (pushnew url (gethash (make-keyword (the instance-id)) *url-hash-table*) :test #'string-equal) (when (the fixed-url-prefix) (publish-fixed-prefix (the fixed-url-prefix))) (setf (gethash url *descriptive-url-hash*) (the root-path)) (when *debug?* (print-variables url)) url)) ("Plist. Contains submitted form field names and values for which no corresponding settable computed-slots exist. Where corresponding settable computed-slots exist, their values are set from the submitted form fields automatically." query-plist nil :settable) (%internal-hidden-object-keywords% (append (list :$$update :$$update-full :$$break :$$tatu :$$ta2 :color-palette :security-check-failed) (call-next-method)))) :trickle-down-slots (tree-root instance-id plain-url? host home-page query-toplevel fixed-url-prefix) :hidden-objects (($$update :type 'update :return-to self) ($$update-full :type 'update-full :return-to self) ($$break :type 'break-on :break-on self) ($$tatu :type (read-safe-string "tatu:assembly") :root-object self) ($$ta2 :type (if (find-package :ta2) (read-safe-string "ta2:assembly") 'null-part) ;;:root (the-child) :root-object self) (security-check-failed :type 'security-check-failed) (color-palette :type 'color-palette)) :functions ( (do-security-check () (or *bypass-security-check?* (the plain-url?) (eql (the remote-host) (the remote-host-original)))) (descriptive-url () (string-append (the descriptive-url-base) ".html")) (descriptive-url-base () (let ((url (let ((escaped-strings-for-display (html-escape (the strings-for-display)))) (if (the parent) (string-append (the parent descriptive-url-base) "/" escaped-strings-for-display) escaped-strings-for-display)))) url)) (compute-url () (compute-url (the root-path))) (set-self () (if *break-on-set-self?* (progn (set-self self) (let ((*package* (symbol-package (the type)))) (break))) (progn (set-self self)))) ("Void. Calls restore-defaults! on all the form-controls in this sheet." restore-form-controls! () (dolist (form-control (the form-controls)) (the-object form-control restore-defaults!))) (set-remote-host! (req &key original?) (if original? (the (set-slot! :remote-host-original (glisp:remote-host (request-socket req)))) (the (set-slot! :remote-host (glisp:remote-host (request-socket req)))))) (set-time-last-touched! () (the (set-slot! :time-last-touched (get-universal-time)))) (set-instantiation-time! () (the (set-slot! :time-instantiated (get-universal-time)))) ;; ;; FLAG -- make sure the instance-urls are in fact being ;; unpublished whenever we do an update! of a base-html-sheet. ;; ("NIL or error object. This function checks the \"sanity\" of this object. By default, it checks that following the object's root-path from the root resolves to this object. If the act of following the root-path throws an error, this error will be returned. Otherwise, if the result of following the root-path does not match the identity of this object, an error is thrown indicating this. Otherwise, NIL is returned and no error is thrown. You can override this function to do what you wish. It should return NIL if the object is found to be \"sane\" and an throw an error otherwise. If check-sanity? is set to T in this object, this function will be invoked automatically within an ignore-errors by the function handling the GWL \"/answer\" form action URI when this object is a respondent, before the main-sheet is presented." check-sanity () (let ((sanity (the root (follow-root-path (the root-path))))) (when (not (eql self sanity)) (error "Object identity does not match its root-path (failed sanity check).")))) ("Void. Emits a page explaining the sanity error. This will be invoked instead of the write-main-sheet if check-sanity? is set to T and the check-sanity throws an error. You may override this function to do what you wish. By default a minimal error message is displayed and a link to the root object is presented. :arguments (error \"an error object, presumably from the <tt>check-sanity</tt> function.\")" sanity-error (error) (html (:html (:head (:title "Error computing response page")) (:body (:p "The expected Respondent object could not be presented. The error was: " (:pre (:princ-safe error))) (when (ignore-errors (the root-path)) (html (:p "The reference chain to the expected Respondent was: " (:pre (:prin1-safe (cons 'the (reverse (the root-path)))))))) (:p "Click " (:b (the root (write-self-link :display-string "Here"))) " to visit the root of the site hierarchy.")))))) :input-slots (("Void. This is an empty function by default, but can be overridden in a user specialization of base-html-sheet, to do some processing before the header-plist is evaluated and before the HTTP response is actually initiated, but after the cookies-received have been set." process-cookies! nil) ("Void. This is an empty function by default, but can be overridden in a user specialization of base-html-sheet, to do some processing before the header-plist is evaluated and before the HTTP response is actually initiated." before-response! nil) ("Void. This is an empty function by default, but can be overridden in the respondent of a form, to do some processing before the respondent's <tt>write-html-sheet</tt> function runs to present the object. This can be useful especially for objects which are subclasses of higher-level mixins such as <tt>application-mixin</tt> and <tt>node-mixin</tt>, where you do not have direct access to the <tt>write-html-sheet</tt> function and typically only define the <tt>model-inputs</tt> function. It is not always reliable to do processing in the <tt>model-inputs</tt> function, since some slots which depend on your intended modifications may already have been evaluated by the time the <tt>model-inputs</tt> function runs." before-present! nil) ("Void. This is an empty function by default, but can be overridden in the respondent of a form, to do some processing after the respondent's <tt>write-html-sheet</tt> function runs to present the object." after-present! nil) ("Void. This is an empty function by default, but can be overridden in the requestor of a form, to do some processing before the requestor's form values are set into the specified bashee." before-set! nil) ("Void. This is an empty function by default, but can be overridden in the requestor of a form, to do some processing after the requestor's form values are set into the specified bashee." after-set! nil)) :functions ((self-link (&key (display-string (the strings-for-display)) (display-color nil) (target nil) (title nil) class id on-click on-mouse-over on-mouse-out local-anchor) (with-cl-who-string () ((:a :href (if local-anchor (format nil "~a#~a" (the url) local-anchor) (the :url)) :target target :onmouseover on-mouse-over :onmouseout on-mouse-out :title title :class class :onclick on-click :id id) (if display-color (htm ((:font :color display-color) (str display-string))) (str display-string))))) ("Void. Emits a hyperlink pointing to self. Note that if you need extra customization on the display-string (e.g. to include an image tag or other arbitrary markup), use with-output-to-string in conjunction with the html-stream macro. :&key ((display-string (the :strings-for-display)) \"String. String to be displayed.\" (display-color nil) \"Keyword symbol or HTML color string. Determines the color of the displayed link text. Default of NIL indicates web browser default (usually blue).\" (target (the :target)) \"String. Names a frame or window to open the link when clicked.\" (class nil) \"String. Names a stylesheet class.\" (id nil) \"String. Names a stylesheet id.\" (on-mouse-over nil) \"String. Javascript code to run on mouse over.\" (on-mouse-out nil) \"String. Javascript code to run on mouse out.\")" write-self-link (&key (display-string (the :strings-for-display)) (display-color nil) (title nil) (target (the :target)) class id local-anchor on-click on-mouse-over on-mouse-out) (with-format (html-format *stream*) (write-the (self-link :display-string display-string :display-color (when display-color (lookup-color display-color :format :hex)) :target target :title title :class class :id id :local-anchor local-anchor :on-click on-click :on-mouse-over on-mouse-over :on-mouse-out on-mouse-out)))) (write-back-link (&key (display-string (if (and (the return-object) (the return-object strings-for-display)) (the return-object strings-for-display) "&lt;-Back")) (display-color nil) (title nil) (target (the :target)) class id local-anchor on-mouse-over on-mouse-out) (when (the return-object) (the return-object (write-self-link :display-string display-string :display-color (when display-color (lookup-color display-color :format :hex)) :target target :title title :class class :id id :local-anchor local-anchor :on-mouse-over on-mouse-over :on-mouse-out on-mouse-out)))) ("Void. Creates a default unordered list with links to each child part of self. The text of the links will come from each child's strings-for-display." write-child-links nil (html (:ul (mapc #'(lambda (child) (html (:li (the-object child :write-self-link)))) (the :children))))) (devo-links-string () (with-output-to-string (*html-stream*) (with-format (html-format *html-stream*) (write-the local-development-links)))) ("Void. Writes links for access to the standard developer views of the object, currently consisting of an update (Refresh!) link, a Break link, and a ta2 link." write-development-links () (let ((*stream* (or *html-stream* *stream*))) (with-format (html-format *stream*) (write-the development-links)))) ;; ;; FLAG -- superseded by form-controls ;; -- but still used in bus demo, need to rewrite that interface!! ;; ("Void. Writes an HTML Select field with Options. :&key ((size 1) \"Integer. determines size of selection list. Default of 1 is a pulldown menu.\" name \"Keyword symbol or string. Determines the name of the field, which should probably match a settable computed-slot.\" keys \"List of strings, numbers, or symbols. Values, the selected one of which will be returned as the value of the field.\" (values keys) \"List of strings. Keys to display in the selection-list.\" tabindex \"Integer. If given, this will generate the tabindex tag for this HTML input field.\")" select-choices (&key (size 1) name keys (values keys) tabindex (use-default? t)) (html ((:select :name name :size size :if* tabindex :tabindex tabindex) (mapc #'(lambda (key value) (html ((:option :value key :if* (and use-default? (equalp key (the (evaluate name)))) :selected :selected) (:princ value)))) keys values)))) ("Void. Writes some standard footer information. Defaults to writing Genworks and Franz copyright and product links. Note that VAR agreements often require that you include a ``powered by'' link to the vendor on public web pages." write-standard-footer (&key (include-copyright? t) (copyright-only? nil)) (html ((:p :class "copyrightFooter") (when (or include-copyright? copyright-only?) (html "Copyright &copy; " (multiple-value-bind (seconds minutes hours date month year) (get-decoded-time) (declare (ignore seconds minutes hours date month)) (html (:princ year))) " " ((:a :href "http://www.genworks.com") "Genworks") (:sup "&reg;") " " ((:a :href "http://www.genworks.com") "International") ". ")) (when copyright-only? (html "All rights reserved.")) (when (not copyright-only?) (html "This site is powered by " ((:a :href "http://www.franz.com") "Allegro CL") " and " ((:a :href "http://www.genworks.com") "Genworks") " GDL."))))) ("Void. This GDL function should be redefined to generate the HTML page corresponding to this object. It can be specified here, or as the <tt>main-sheet</tt> output-function in an html-format lens for this object's type. This <tt>write-html-sheet</tt> function, if defined, will override any <tt>main-sheet</tt> function defined in the lens. Typically a <tt>write-html-sheet</tt> function would look as follows: :example <pre> (write-html-sheet () (html (:html (:head (:title (:princ (the :page-title)))) (:body ;;; fill in your body here )))) </pre>" write-html-sheet () (with-format (html-format *html-stream* ) (write-the (main-sheet))))))
21,359
Common Lisp
.lisp
427
39.215457
178
0.615181
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
5563baffc1909c3c0281d0c1405a556e5b283520b43cb368c0d42d93d7b6aaf2
36,031
[ -1 ]
36,032
utilities.lisp
lisp-mirror_gendl/gwl/source/utilities.lisp
(in-package :gwl) (eval-when (:compile-toplevel :load-toplevel :execute) (#+allegro excl:without-redefinition-warnings #-allegro progn (defmacro with-error-handling ((&key (error? nil) (timeout 2) (timeout-body `(warn "Timed Out after ~a Seconds" ,timeout))) &body body) "[Macro]. Wraps the <b>body</b> of code with error-trapping and system timeout. A warning is given if an error condition occurs with <b>body</b>. :&key ((timeout 2) \"Timeout in Seconds.\" timeout-body \"Body of code to evaluate if timeout occurs. Default is to print a warning and return nil.\") :&rest (body \"Body of code to be wrapped\")" (if error? `(progn ,@body) (let ((values (gensym)) (error (gensym))) (let ((code `(let* ((,values (multiple-value-list (ignore-errors ,@body))) (,error (second ,values))) (if (and ,error (typep ,error 'error)) (progn (warn "~a" ,error) (values nil ,error)) (apply #'values ,values))))) (if timeout `(,(glisp:with-timeout-sym) (,timeout ,timeout-body) ,code) code))))))) (defun server-port (&optional (wserver net.aserve:*wserver*)) (when wserver (let ((socket (net.aserve:wserver-socket wserver))) (when socket (glisp:local-port socket))))) (defun announce-server-port () (let ((port (server-port))) (when port (format t "~&~%***** ~%Your Webserver is running on Port ~a.~%*****~%" port))))
1,540
Common Lisp
.lisp
36
35.25
86
0.59973
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
ef1c38d7ff746a413d3ad4bc709529ea89d44dfc6dfee180ce48de849a3e3442
36,032
[ -1 ]
36,033
log-utils.lisp
lisp-mirror_gendl/gwl/source/log-utils.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defvar *log-buffer* nil) (defvar *log-report-buffer* nil) (defvar *log-file* nil) (defparameter *aserve-log-request-after-functions* nil) (defun start-log-maker (&key (interval 30) (resolve-dns? t) (server net.aserve:*wserver*)) (setq *log-file* (format nil "/home/dcooper8/kitchen/logs-~a-~a.lisp" (gwl::iso-time (get-universal-time)) (server-port server))) (glisp:process-run-function "log-maker" #'(lambda() (do ()(nil) (clear-log-buffer :resolve-dns? resolve-dns?) (sleep interval))))) (defun read-log-entries () (when (and *log-file* (probe-file *log-file*)) (clear-log-buffer :resolve-dns? t) (with-open-file (in *log-file*) (let (result) (do ((entry (read in nil) (read in nil))) ((null entry) (nreverse result)) (push entry result)))))) (defun clear-log-buffer (&key resolve-dns?) (let (temp-buffer) (glisp:w-o-interrupts (setq temp-buffer *log-buffer*) (setq *log-buffer* nil)) (ensure-directories-exist (make-pathname :directory (pathname-directory *log-file*))) (with-open-file (out *log-file* :direction :output :if-exists :append :if-does-not-exist :create) (dolist (log temp-buffer) (let* ((ipaddr (getf log :ip-address)) (name (when resolve-dns? (or (socket:ipaddr-to-hostname ipaddr) (format nil "Unknown (~a)" ipaddr))))) (let ((processed-log (append (list :start-iso-time (when (getf log :start-time) (iso-time (getf log :start-time))) :end-iso-time (when (getf log :end-time) (iso-time (getf log :end-time))) :domain name) log))) (print processed-log out))))))) (defun iso-time (universal-time) (multiple-value-bind (seconds minutes hours date month year) (decode-universal-time universal-time) (format nil "~a-~2,,,'0@a-~2,,,'0@aT~2,,,'0@a:~2,,,'0@a:~2,,,'0@a" year month date hours minutes seconds))) (defmethod net.aserve::log-request :after ((req http-request)) (dolist (function *aserve-log-request-after-functions*) (funcall function req))) #+nil (defmethod monkey-log ((req http-request)) (when *log-file* (let* ((ipaddr (socket:remote-host (request-socket req))) (end-time (net.aserve::request-reply-date req)) (start-time (net.aserve::request-request-date req)) (code (let ((object (net.aserve::request-reply-code req))) (if object (net.aserve::response-number object) 999))) (length (or (net.aserve::request-reply-content-length req) (glisp:socket-bytes-written (request-socket req)))) (referrer (net.aserve:header-slot-value req :referer)) (user-agent (net.aserve::header-slot-value req :user-agent))) (let* ((uri (net.aserve::request-uri req)) (log-plist (list :ip-address (socket:ipaddr-to-dotted ipaddr) :start-time start-time :end-time end-time :code code :length length :query (request-query req) :uri-path (net.aserve::uri-path uri) :uri-host (net.aserve::uri-host uri) :uri-port (net.aserve::uri-port uri) :uri-scheme (net.aserve::uri-scheme uri) :method (net.aserve::request-method req) :referrer referrer :user-agent user-agent))) (when (not (or (search "cgi-bin" (getf log-plist :uri-path)) (search "ubb" (getf log-plist :uri-path)))) (glisp:w-o-interrupts (if *log-buffer* (nconc *log-buffer* (list log-plist)) (setq *log-buffer* (list log-plist)))))))))
4,628
Common Lisp
.lisp
96
40.21875
125
0.631579
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
892a84262081f5ac55c8389acb03ca45a70bad8a4ac266820a01d96281cfa553
36,033
[ -1 ]
36,034
remote-test.lisp
lisp-mirror_gendl/gwl/source/remote-test.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl-user) (define-object remote-test (base-object) :computed-slots ((width 10 :settable) (length 20 :settable) (height 30 :settable) (remote-color (the remote-cylinder color)) ) :objects ((remote-cylinder :type 'remote-object :remote-type 'cylinder :host "localhost" :port 9001 :radius 50 :length (the length)) (cylinder :type 'cylinder :radius (the width)) (remotes :type 'remote-object :sequence (:size 10) :remote-type 'box-with-cylinder :host "localhost" :port 9001 :cylinder (the cylinder) :width (* (the width) (the-child index)) :height (twice (the-child width)) :length (the length)))) (define-object box-with-cylinder (box) :computed-slots ((color :blue :settable)) :input-slots ((cylinder nil))) (gwl:define-package :master) (gwl:define-package :slave) (in-package :master) (define-object master () :objects ((slave :type 'remote-object :remote-type 'slave::slave :test-symbol 'gdl-user::heynow :host "localhost" :port 9000))) (in-package :slave) (define-object slave () :input-slots (test-symbol) :computed-slots ((message "hey now")) :functions ((test-print () (print-messages test-symbol message))))
2,421
Common Lisp
.lisp
70
27.028571
71
0.633524
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
fbf8453d10870ed272694fc5aad3b9a5a787b02c34efad2ab71eb17c3962f6e7
36,034
[ -1 ]
36,035
base64-utils.lisp
lisp-mirror_gendl/gwl/source/base64-utils.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defun base64-encode-list (list) "String. Encodes a list into base64 without the trailing = signs. :arguments (list \"list\") " (base64-encode-safe (format nil "~s" list))) (defun base64-encode-safe (string) "String. Encodes a string into base64 without the trailing = signs. :arguments (string \"string\") " (let ((cl-ppcre:*allow-quoting* t)) (glisp:replace-regexp (glisp:replace-regexp (glisp:replace-regexp (glisp:replace-regexp (glisp:replace-regexp (funcall glisp:*base64-encode-func* string) "=" "") "\\Q+\\E" "-") "/" "_") "\\n" "") "\\r" ""))) (defun base64-decode-list (string) "List. Decodes a base64 string into a Lisp list. :arguments (string \"string\") " ;; ;; FLAG -- removed string-downcase for the decoded-string. Watch for this; don't know ;; why it was there in the first place. ;; (let ((decoded-string (base64-decode-safe string))) (read-safe-string decoded-string))) (defun base64-decode-safe (string) "String. Decodes a base64 string without need for trailing = signs into a decoded string. :arguments (string \"string\") " (when *debug?* (print-variables string)) (let ((padding (make-string (mod (- 4 (mod (length string) 4)) 4) :initial-element #\=))) (funcall glisp:*base64-decode-func* (string-append (glisp:replace-regexp (glisp:replace-regexp string "-" "+") "_" "/") padding)))) #+allegro (defun string-to-compressed-base64-string (string) (excl:usb8-array-to-base64-string (let* ((vector (make-array 5 :element-type '(unsigned-byte 8))) (deflate-stream (make-instance 'util.zip:deflate-stream :target vector))) (write-string string deflate-stream) (close deflate-stream) (util.zip:deflate-stream-vector-combined deflate-stream)))) #+allegro (defun compressed-base64-string-to-string (string) (let ((array (excl:base64-string-to-usb8-array string))) (excl:with-input-from-buffer (in array) (util.zip:skip-gzip-header in) (let ((inflate-stream (make-instance 'util.zip:inflate-stream :input-handle in)) (result nil) (newline (format nil "~%"))) (do ((line (read-line inflate-stream nil nil) (read-line inflate-stream nil nil))) ((null line) result) (setq result (if result (string-append result newline line) line)))))))
3,198
Common Lisp
.lisp
73
40.287671
101
0.706285
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
e6ac1b9b048530331bbe68054daf45f240f3d864d588c75722113cd032cdc861
36,035
[ -1 ]
36,036
with-all-servers.lisp
lisp-mirror_gendl/gwl/source/with-all-servers.lisp
;; ;; Copyright 2016 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defmacro with-all-servers ((server) &rest body) (let ((server-var (gensym))) `(dolist (,server-var (list *wserver* *ssl-server*)) (when ,server-var (let ((,server ,server-var)) ,@body)))))
1,068
Common Lisp
.lisp
26
38.961538
70
0.728585
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
1fa4c6843ece501725257b8bd55ab1a561277bc95cc9a923476c53c48b4eff1d
36,036
[ -1 ]
36,037
vanilla-remote.lisp
lisp-mirror_gendl/gwl/source/vanilla-remote.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (eval-when (:compile-toplevel :load-toplevel :execute) (undefine-object 'remote-object)) (define-object vanilla-remote (vanilla-mixin* gdl-remote gdl::gdl-basis) :no-vanilla-mixin? t)
1,089
Common Lisp
.lisp
24
42.25
89
0.735099
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
f95bf305a0ee5bac5ee8444151dd2f7fcf88be1f2f45f13089dd6d6e63665312
36,037
[ -1 ]
36,038
answer.lisp
lisp-mirror_gendl/gwl/source/answer.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defparameter *f-e-p* nil) (define-object session-control-mixin () :documentation (:description "Mixin to the root object of the part which you wish to have session control over" :author "Brian Sorg, Liberating Insight LLC (revised Dave Cooper, Genworks)") :input-slots (("Universal time after which the session should expire" expires-at nil :settable) ("Length of time a session should last without activity in minutes" session-duration 20) ("Boolean. Determines whether expired sessions are replaced by recovery object. Default is nil." use-recovery-object? nil) ("Expiration time of the recovery object. After the recovery object has replaced the orginal instance at what time should the recovery instance expire?" recovery-expires-at (+ (get-universal-time) (* 60 (the session-duration)))) ("Url to which a user will be redirected if requesting a session that has been cleared" recovery-url *recovery-url-default*) ("Type of original object, useful when viewing session report log" org-type (type-of self)) (;; For future use %state-plist% '(0))) :functions (("This is the function called to check for and handle session control :&key ((debug? nil) \"Boolean. Prints debug statement if needed\")" clear-expired-session (&key debug?) (when debug? (format t "Validating instance ~a~% of class ~a~% Current Universal Time: ~a.~% Expiration Time: ~a.~% Clear now? ~a.~%" (the instance-id) (class-of self) (get-universal-time) (the expires-at) (the (clear-now?)))) (when (the clear-now?) (the (session-clean-up)) (glisp:w-o-interrupts (clear-instance (the instance-id)) (when (and (the use-recovery-object?) (the recovery-expires-at)) (let ((recovery (make-object 'session-recovery :instance-id (the instance-id) :expires-at (the recovery-expires-at) :recovery-url (the recovery-url) :state-plist (the %state-plist%) :org-type (the org-type)))) (setf (gethash (make-keyword (the instance-id)) *instance-hash-table*) ;; ;; FLAG -- that last entry is actually supposed to be the skin class. ;; (list recovery (list 0) t))))))) ("Gets called right before the instance is going to get cleared. Is intended to be used to stop any instance states that may not be elequently handled by the garbage collector. ie database connections, multiprocessing locks, open streams etc." session-clean-up ()) ("Boolean. Test to run to see if this session has expired and needs to be cleared now." clear-now? () (when (the expires-at) (> (get-universal-time) (the expires-at)))) ("Method which will set the expires-at slot to the current time + the session-duration" set-expires-at (&optional (duration (the session-duration))) (the (set-slot! :expires-at (+ (get-universal-time) (* 60 duration))))))) (define-object session-recovery (session-control-mixin) :input-slots (instance-id )) (defun answer (req ent) (let ((query (request-query req))) (when *debug?* (format t "before multi-part processing, query is: ~s~%" query)) (when (null query) (setq query (process-multipart-submission req))) (when gwl::*debug?* (print-variables query)) (let* ((requestor (query-arg-to-root-path query "requestor")) (iid (make-keyword (rest (assoc "iid" query :test #'string-equal)))) (hash-entry (gethash iid *instance-hash-table*)) (root-object (first hash-entry)) (skin (third hash-entry)) (recovery-object? (typep root-object 'session-recovery)) (requestor (when (and root-object (not recovery-object?)) (the-object root-object (follow-root-path requestor)))) (bashee (when requestor (the-object requestor bashee))) (rest-plist (when (not recovery-object?) (merge-plist-duplicates (assoc-list-to-plist (remove-if #'(lambda(item) (member (first item) (list "requestor" "iid") :test #'string-equal)) query) :case-sensitive? t)))) (possible-nils (when (not recovery-object?) (the-object requestor possible-nils))) (rest-plist (when requestor (append rest-plist (mapcan #'(lambda(key) (list key nil)) (set-difference possible-nils (plist-keys rest-plist)))))) (settables (when bashee (the-object bashee %settable-slots%))) (rest-keys (plist-keys rest-plist)) (query-plist (mapcan #'(lambda(key) (list key (getf rest-plist key))) (remove-if #'(lambda(key) (gethash (make-keyword-sensitive key) settables)) rest-keys)))) (let ((respondent (the-object requestor respondent))) (the-object respondent root (set-remote-host! req)) (unless (the-object respondent root do-security-check) (with-http-response (req ent) (setf (reply-header-slot-value req :cache-control) "no-cache") (setf (reply-header-slot-value req :pragma) "no-cache") (with-http-body (req ent) (let ((*req* req) (*ent* ent)) (the-object respondent root security-check-failed write-html-sheet)))) (return-from answer nil))) (when gwl::*debug?* (print-variables query requestor iid hash-entry root-object recovery-object? requestor bashee rest-plist possible-nils settables rest-keys query-plist)) (let ((fe-processor (make-object 'form-element-processor :bashee bashee :query-plist query-plist))) (cond (recovery-object? (with-http-response (req ent :response *response-moved-permanently*) (setf (reply-header-slot-value req :location) (defaulting (the-object root-object recovery-url) *failed-request-url*)) (setf (reply-header-slot-value req :cache-control) "no-cache") (setf (reply-header-slot-value req :pragma) "no-cache") (with-http-body (req ent)))) ((null requestor) (net.aserve::failed-request req)) (t (let ((*query-plist* query-plist) (*field-plist* rest-plist)) (the-object requestor (before-set!))) ;;(when *debug?* (print-variables *query-plist* rest-plist rest-keys)) (when *debug?* (setq *f-e-p* fe-processor)) (dolist (key rest-keys) (when (gethash (make-keyword-sensitive key) settables) ;;(when *debug?* (print-variables key)) (the-object bashee (set-slot-if-needed! (make-keyword-sensitive key) (getf rest-plist key))))) (the-object fe-processor validate-and-set!) (when (and (fboundp 'process-graphics-fields) (typep (the-object requestor) (read-from-string "gwl:base-html-graphics-sheet")) (the-object requestor (evaluate :view-object))) (setq query-plist (funcall (read-from-string "gwl::process-graphics-fields") query query-plist root-object requestor))) (when (not (equalp (the-object bashee query-plist) query-plist)) (the-object bashee (set-slot! :query-plist query-plist :remember? (not (member :query-plist (the-object bashee transitory-slots)))))) (let ((result (let ((*req* req) (*ent* ent) (*skin* skin) (*query* query)) (the-object requestor (after-set!))))) (let ((respondent (if (and (consp result) (eql (first result) :go-to)) (second result) (the-object requestor respondent)))) ;; ;; Dashboard stuff ;; ;; ;; FLAG - use actual application-root rather than simple root. ;; (when (typep root-object 'session-control-mixin) (the-object root-object (set-expires-at))) (the-object respondent root (set-time-last-touched!)) (the-object respondent root (set-slot! :last-visited-root-path (the-object respondent root-path))) ;; ;; ;; (with-http-response (req ent :response *response-found*) (setf (reply-header-slot-value req :cache-control) "no-cache") (setf (reply-header-slot-value req :pragma) "no-cache") (setf (reply-header-slot-value req :location) (the-object respondent url)) (let ((keys (plist-keys (the-object respondent header-plist))) (values (plist-values (the-object respondent header-plist)))) (mapc #'(lambda(key val) (setf (reply-header-slot-value req key) val)) keys values)) (with-http-body (req ent) (let ((*req* req) (*ent* ent) (*skin* skin)) (multiple-value-bind (check error) (when (the-object respondent check-sanity?) (ignore-errors (the-object respondent check-sanity))) (declare (ignore check)) (if error (the-object respondent (sanity-error error))))))))))))))) (defun process-multipart-submission (req) (let (sep query (directory (glisp:temporary-folder))) (do ()(nil) (multiple-value-bind (kind name filename content-type) (parse-multipart-header (get-multipart-header req)) (declare (ignorable content-type)) (when filename (setq sep (max (or (position #\/ filename :from-end t) -1) (or (position #\\ filename :from-end t) -1))) (setq filename (subseq filename (1+ sep) (length filename)))) (case kind (:eof (return query)) (:data (push (cons name (get-all-multipart-data req)) query)) (:file (let ((output-path (merge-pathnames filename directory))) (push (cons name (format nil "~a" output-path)) query) (with-open-file (out output-path :direction :output :if-exists :supersede :element-type '(unsigned-byte 8)) (let ((buffer (make-array 4096 :element-type '(unsigned-byte 8)))) (do ()(nil) (let ((count (get-multipart-sequence req buffer))) (when (null count) (return)) (write-sequence buffer out :end count)))))))))))) (defun make-object-internal (req ent) (let ((query (request-query req))) (let ((part (rest (or (assoc "object" query :test #'string-equal) (assoc "part" query :test #'string-equal))))) (gwl-make-part req ent part)))) (defun gwl-make-part (&rest args) (apply #'gwl-make-object args)) (defparameter *weak-objects* (glisp:make-weak-hash-table)) (defmethod restore-ui-object ((ui-server gwl-gdl-ui) object) (when (typep object 'base-html-sheet) (format t "~&Restoring GWL UI status for ~s...~%" object) ;; ;; FLAG -- handle skins ;; (let* ((instance-id (the-object object instance-id)) (current (gethash (make-keyword-sensitive instance-id) *instance-hash-table*)) (root-part-and-version (list object *dummy-version*))) (setf (gethash (first root-part-and-version) *weak-objects*) t) (when current (warn "Instance ID of restored object, ~a, is already in use. Generating new instance id..." instance-id) (setq instance-id (make-new-instance-id)) (format t "~&New Instance ID is: ~a~%" (progn (the-object object (set-slot! :instance-id instance-id)) (the-object object instance-id)))) (the-object (first root-part-and-version) url) (setf (gethash (make-keyword-sensitive instance-id) *instance-hash-table*) root-part-and-version)))) (defun %gwl-make-object% (part &key make-object-args share? skin) (let* ((instance-id (if share? "share" (make-new-instance-id))) (current (gethash (make-keyword-sensitive instance-id) *instance-hash-table*)) (skin (if skin (make-instance skin) t)) (root-part-and-version (if (or (not share?) (not current)) (list (apply #'make-object (read-safe-string part) :instance-id instance-id make-object-args) *dummy-version*) current))) (setf (gethash (first root-part-and-version) *weak-objects*) t) (setq root-part-and-version (append root-part-and-version (list skin))) (when (or (not share?) (not current)) (setf (gethash (make-keyword-sensitive instance-id) *instance-hash-table*) root-part-and-version)) (first root-part-and-version))) (defun gwl-make-object (req ent part &key make-object-args share? skin (instance-id (when share? "share"))) "Void. Used within the context of the body of a :function argument to Allegroserve's publish function, makes an instance of the specified part and responds to the request with a redirect to a URI representing the instance. :arguments (req \"Allegroserve request object, as used in the function of a publish\" ent \"Allegroserve entity object, as used in the function of a publish\" package-and-part \"String. Should name the colon- (or double-colon)-separated package-qualified object name\") :&key ((make-object-args nil) \"Plist of keys and values. These are passed to the object upon instantiation.\" (share? nil) \"Boolean. If non-nil, the instance ID will be the constant string ``share'' rather than a real instance id.\") :example <pre> (publish :path \"/calendar\" :function #'(lambda(req ent) (gwl-make-object req ent \"calendar:assembly\"))) </pre>" (unless instance-id (setq instance-id (make-new-instance-id))) (let ((query (request-query req))) (let ((part (or part (rest (assoc "part" query :test #'string-equal))))) (let* ((current (gethash (make-keyword-sensitive instance-id) *instance-hash-table*)) (skin (if skin (make-instance skin) t)) (root-part-and-version (if (or (not share?) (not current)) (list (apply #'make-object (read-safe-string part) :instance-id instance-id ;;:query-toplevel query make-object-args) *dummy-version*) current))) (setf (gethash (first root-part-and-version) *weak-objects*) t) (setq root-part-and-version (append root-part-and-version (list skin))) (when (or (not share?) (not current)) (setf (gethash (make-keyword-sensitive instance-id) *instance-hash-table*) root-part-and-version)) (let ((object (first root-part-and-version))) (when (typep object 'session-control-mixin) (the-object object set-expires-at)) (the-object object set-instantiation-time!) (the-object object set-time-last-touched!) (the-object object (set-remote-host! req :original? t))) (with-http-response (req ent :response *response-found*) (setf (reply-header-slot-value req :location) (format nil "~a" (the-object (first root-part-and-version) url))) (setf (reply-header-slot-value req :cache-control) "no-cache") (setf (reply-header-slot-value req :pragma) "no-cache") (with-http-body (req ent))))))) (defun publish-shared (&key path object-type object host (server *wserver*) (key (make-keyword-sensitive (format nil "~a_~a" host path)))) "Void. Used to publish a site which is to have a shared toplevel instance tree, and no URI rewriting (i.e. no \"/sessions/XXX/\" at the beginning of the path). So, this site will appear to be a normal non-dynamic site even though the pages are being generated dynamically. :&key ((path nil) \"String. The URI path to be published.\" (object-type nil) \"Symbol. The type of the toplevel object to be instantiated.\" (host nil) \"hostname for the URI to be published.\" (server *wserver*) \"Allegroserve server object. If you have additional servers other than the default <tt>*wserver*</tt> (e.g. an SSL server) you may want to call this function for each server.\") :example <pre> (publish-shared :path \"/\" :object-type 'site:assembly :host (list \"www.genworks.com\" \"ww2.genworks.com\" \"mccarthy.genworks.com\")) </pre>" (let ((object (or object (make-object (if (stringp object-type) (read-safe-string object-type) object-type) :instance-id key :plain-url? t :host host)))) (setf (gethash key *instance-hash-table*) (list object)) (publish :path path :server server :host host :content-type "text/html" :function #'(lambda(req ent) (let ((*req* req) (*ent* ent) (object (first (gethash key *instance-hash-table*)))) (with-http-response (req ent :response *response-found*) (setf (reply-header-slot-value req :location) (format nil "~a" (the-object object url))) (setf (reply-header-slot-value req :cache-control) "no-cache") (setf (reply-header-slot-value req :pragma) "no-cache") (with-http-body (req ent)) )))))) (define-object form-element-processor () :input-slots (bashee query-plist) :computed-slots ( (form-element-objects (the bashee form-controls)) (force-validation-for (the bashee force-validation-for)) (form-element-keys (mapcar #'(lambda(object) (the-object object field-name)) (the form-element-objects))) (radios (mapcan #'(lambda(key) (when (and (glisp:match-regexp "^radio-" (string-downcase (format nil "~a" key))) (string-equal (second (getf (the query-plist) key)) "true")) (list (make-keyword-sensitive (glisp:replace-regexp (glisp:replace-regexp (glisp:replace-regexp (format nil "~a" key) "^RADIO-" "") "^radio-" "") "-.*" "")) (first (getf (the query-plist) key))))) (plist-keys (the query-plist)))) (query-plist-all (append (the radios) (mapcan #'(lambda(key val) (unless (or (glisp:match-regexp "^radio-" (string-downcase (format nil "~a" key))) (glisp:match-regexp "-checkedp$" (string-downcase (format nil "~a" key)))) (list key val))) (plist-keys (the query-plist)) (plist-values (the query-plist))))) (checked-booleans (mapcan #'(lambda(key) (when (glisp:match-regexp "-checkedp$" (string-downcase (format nil "~a" key ))) (list (make-keyword-sensitive (glisp:replace-regexp (glisp:replace-regexp (format nil "~a" key ) "-checkedp$" "") "-CHECKEDP$" "")) (let ((checked (getf (the query-plist) key))) (not (string-equal checked "false")))))) (plist-keys (the query-plist)))) (form-elements-to-bash% (let ((submitted-elements (let* ((query-plist-keys (plist-keys (the query-plist-all))) ;; ;; Comment out this #+nil and uncomment the one below to switch to ;; 1579p007 behavior (i.e. ability to have form-element from ;; anywhere in the tree). This really should be the correct ;; behavior. ;; (keys (remove-if-not #'(lambda(key) ;; FLAG -- check for value ;; form-control object for ;; each key ;; (typep (ignore-errors (the bashee root (follow-root-path (base64-decode-list (string key))))) 'base-form-control)) query-plist-keys)) ;; ;; #+nil (keys (remove-if-not #'(lambda(key) (find key query-plist-keys)) (the form-element-keys)))) (mapcan #'(lambda(key) (list key (if (member key (the checked-booleans)) (getf (the checked-booleans) key) (getf (the query-plist-all) key)))) keys)))) (let ((result (append submitted-elements (mapcan #'(lambda(object) (list (the-object object field-name) (the-object object value))) (remove-if #'(lambda(objct) (member (the-object objct field-name) (plist-keys submitted-elements))) (ensure-list (the force-validation-for))))))) result))) (form-elements-to-bash (the form-elements-to-bash%)) #+nil (form-elements-to-bash (mapcan #'(lambda(key val) ;; ;; The comparison of old and new should work, to avoid unneeded ;; bashing when the old and new values are the same. ;; (let (#+nil (new (getf (the bashee root (follow-root-path (base64-decode-list (string key))) (validate-type val)) :typed-value)) #+nil (old (the bashee root (follow-root-path (base64-decode-list (string key))) value))) ;;(unless (equalp new old) (list key val)) (list key val) )) (plist-keys (the form-elements-to-bash%)) (plist-values (the form-elements-to-bash%))))) :functions ((validate-and-set! () (dotimes (n 2) (dolist (key (plist-keys (the form-elements-to-bash))) (let ((*out-of-bounds-sequence-reference-action* :silent)) (let ((element (the bashee root (follow-root-path (base64-decode-list (string key)))))) (when element (unless (eql (first (the-object element root-path)) :%delete-button%) (when (or (= n 1) (the bashee preset-all?) (the-object element preset?)) (the-object element (validate-and-set! (getf (the form-elements-to-bash) key)))))))))) (dolist (key (plist-keys (the form-elements-to-bash))) (let ((*out-of-bounds-sequence-reference-action* :silent)) (let ((element (the bashee root (follow-root-path (base64-decode-list (string key)))))) (when element (when *debug?* (print-variables (the-object element root-path))) (when (eql (first (the-object element root-path)) :%delete-button%) (the-object element parent aggregate (delete! (the-object element parent index)))))))))))
27,822
Common Lisp
.lisp
457
41.560175
247
0.526823
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
c5827a3d692faf8222a997766650e273bdf53f0b8982318cc25bcf4f819f4e91
36,038
[ -1 ]
36,039
macros.lisp
lisp-mirror_gendl/gwl/source/macros.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (define-object form-mixin ()) (define-lens (html-format form-mixin)() :output-functions ((:form (slot-names &key (size-default 5) (sizes (make-list (length slot-names) :initial-element size-default)) (prompts (mapcar #'(lambda(slot-name) (symbol-name slot-name)) slot-names)) (cellpadding 0) (heading-color :yellow)) (html (:p ((:table :cellpadding cellpadding) (:tr ((:th :colspan 2) "Dimensions")) (mapc #'(lambda(slot-name prompt size) (html (:tr ((:td :bgcolor heading-color) (:princ (string-capitalize prompt))) (:td ((:input :type :text :name (symbol-name slot-name) :size size :value (or (the (evaluate slot-name)) ""))))))) slot-names prompts sizes))) (:p ((:input :type :submit :name :subbmit :value " OK "))))))) (defmacro html-form (slot-names &key (size-default 5) (sizes (make-list (length slot-names) :initial-element size-default)) (prompts (mapcar #'(lambda(slot-name) (symbol-name slot-name)) slot-names)) (cellpadding 0) (heading-color :yellow)) `(html (:p ((:table :cellpadding ,cellpadding) (:tr ((:th :colspan 2) "Dimensions")) ,@(mapcar #'(lambda(slot-name prompt size) `(:tr ((:td :bgcolor ,heading-color) (:princ ,(string-capitalize prompt))) (:td ((:input :type :text :name ,(symbol-name slot-name) :size ,size :value (or (the ,slot-name) "")))))) slot-names prompts sizes))) (:p ((:input :type :submit :name :subbmit :value " OK "))))) (defmacro with-html-form ((&key name id multipart? enctype target requestor on-submit suppress-border? local-anchor cl-who?) &body body) "Enclose a body of code with a form. FLAG -- fill in. " (let ((%enctype% (gensym)) (fixed-prefix (gensym))) `(let ((,%enctype% (cond (,enctype ,enctype) (,multipart? "multipart/form-data"))) (,fixed-prefix (let ((prefix (the fixed-url-prefix))) (when prefix (string-append "/" prefix))))) (,@(if cl-who? '(with-html-output (*stream* nil :indent t)) '(html ;;html-stream *stream* )) ((:form :method :|post| :id ,id :action (string-append (or ,fixed-prefix "") (format nil (if ,local-anchor (format nil "/answer#~a" ,local-anchor) "/answer"))) :name ,(or name `(the root-path-string)) ,@(if cl-who? `(:enctype ,%enctype%) `(:if* ,%enctype% :enctype ,%enctype%)) ,@(if cl-who? `(:target ,target) `(:if* ,target :target ,target)) ,@(if cl-who? `(:on-submit ,on-submit) `(:if* ,on-submit :onsubmit ,on-submit)) ,@(if cl-who? `(:style ,(when suppress-border? "padding: 0; border: 0; margin: 0")) `(:if* ,suppress-border? :style "padding: 0; border: 0; margin: 0"))) ((:input :type :hidden :name :|requestor| :value ,(if (null requestor) `(the url-encoded-root-path) `(the-object ,requestor url-encoded-root-path)))) ((:input :type :hidden :name :|iid| :value (the instance-id))) ,@body)))))
4,580
Common Lisp
.lisp
81
42.716049
127
0.553469
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
c3a5d9ec89983e93f99b6ac4263d16c0f02e5424bb25445a607bbe4dd8e02d3d
36,039
[ -1 ]
36,040
remote-object.lisp
lisp-mirror_gendl/gwl/source/remote-object.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defvar *agile-debug?* nil) (defparameter *send-plist* nil) (defparameter *make-object-plist* nil) (defparameter *fetch-plist* nil) (defvar *preferred-remote-syntax* :lisp) ;; or :json (defmethod encode-plist-for-url ((syntax (eql :lisp)) encoded-plist) (let ((*print-case* :downcase)) (base64-encode-list encoded-plist))) (defun upcase-plist (plist) (change-plist-case plist :up)) (defun downcase-plist (plist) (change-plist-case plist :down)) (defun change-plist-case (plist up-or-down) (let ((function (ecase up-or-down (:up #'string-upcase) (:down #'string-downcase)))) (mapcan #'(lambda(key value) (list (make-keyword (funcall function key)) (cond ((keywordp value) (make-keyword (funcall function value))) ((symbolp value) (cond ((null value) nil) (t (funcall function (string (intern (string value) (symbol-package value))))))) ((consp value) (change-plist-case value up-or-down)) ((stringp value) value) (t value)))) (plist-keys plist) (plist-values plist)))) (defmethod encode-plist-for-url ((syntax (eql :json)) plist) (let ((yason-string (with-output-to-string (s) (yason:encode (yasonify plist) s)))) (base64-encode-safe (format nil "~s" yason-string)))) #+nil (defun yasonify (value) (cond ((or (null value) (eql value t) (numberp value) (stringp value)) value) ((vectorp value) (map 'vector #'yasonify value)) ((atom value) (let ((*print-readably* t)) (format nil "~s" value))) ((and (keywordp (car value)) (evenp (length value))) (loop with hash = (make-hash-table :test 'equal) for (key val) on value by #'cddr do (setf (gethash (symbol-name key) hash) (yasonify val)) finally (print-hash hash) (return hash))) (t (mapcar #'yasonify value)))) (defun yasonify (value) (cond ((or (null value) (eql value t) (numberp value) (stringp value)) value) ((vectorp value) (map 'vector #'yasonify value)) ((atom value) (let ((*print-readably* t)) (format nil "~s" value))) ((and (keywordp (car value)) (evenp (length value))) (loop with hash = (make-hash-table :test 'equal) for (key val) on value by #'cddr do (setf (gethash (symbol-name key) hash) (yasonify val)) finally (return hash))) (t (mapcar #'yasonify value)))) (defun register-remote-object (obj) #-ccl (declare (ignore obj)) #+ccl (ccl:terminate-when-unreachable obj) nil) (defun do-remote-execute (request host port remote-syntax plist &key (decode t)) (let* ((encoded-plist (encode-plist-args plist)) (argstring (encode-plist-for-url remote-syntax encoded-plist)) (result (net.aserve.client:do-http-request (let ((*print-case* :downcase)) (format nil "http://~a:~a/~a?args=~a&syntax=~s" host port request argstring remote-syntax))))) ;; Note that for now, return values do not obey remote-syntax, they are always in lisp.... (if decode (decode-from-http (read-safe-string (base64-decode-safe result))) (read-safe-string result)))) (define-object remote-object (vanilla-remote) :no-vanilla-mixin? t :input-slots (remote-type (input-parameters nil) host port (remote-syntax *preferred-remote-syntax*) (remote-root-path nil) (remote-id (read-safe-string (let* ((current-id (the previous-id)) (plist (append (list :current-id current-id) (the remote-object-args)))) (when *agile-debug?* (setq *make-object-plist* (append (remove-plist-keys plist (list :parent-form :name)) (list :name (string (getf plist :name))) (list :parent-form (multiple-value-bind (type parent-plist) (destructure-object-from-http (getf plist :parent-form)) (declare (ignore type)) (stringify-plist parent-plist)))))) (let ((new-id (the (remote-execute "make-remote-object" plist :decode nil)))) (the (set-slot! :previous-id new-id :remember? nil :warn-on-non-toplevel? nil)) (register-remote-object self) new-id))) :settable)) :computed-slots ((remote-object-args (append (list :type (format nil "~a::~a" (string-downcase (package-name (symbol-package (the remote-type)) )) (string-downcase (symbol-name (the remote-type)))) :package (encode-for-http *package*) ;;:host (the host) :name (the %name%) :index (the index) :parent-form (the parent-form) ) (the input-parameters))) ;;(remote-object-args-json (cl-json: ) ;; FLAG -- fill in! (parent-form (encode-for-http (the parent))) (local-remote-id nil :settable) (previous-id nil :settable)) :functions ((remote-execute (request plist &key (decode t)) (do-remote-execute request (the host) (the port) (the remote-syntax) plist :decode decode)) (fetch-input (message part-name child &rest args) ;; ;; FLAG -- *notify-cons* is going to be broken now... have to unmarshal/marshal from hash table. ;; hold off on doing this until we switch to an Abstract Associative Map. ;; (let ((plist (list :message (make-keyword message) :part-name (make-keyword part-name) :index (the-object child index) :notify-cons (encode-for-http gdl::*notify-cons*) :args args :remote-id (the remote-id) :remote-root-path (the remote-root-path) :package *package*))) (when *agile-debug?* (setq *fetch-plist* (encode-plist-args plist))) (the (remote-execute "fetch-remote-input" plist)))) (unbind-remote-slot (slot) (let ((plist (list :slot slot :remote-id (the remote-id) :remote-root-path (the remote-root-path)))) (the (remote-execute "unbind-slots" plist)))) (send (message &rest args) (let ((plist (list :message (make-keyword message) :notify-cons (encode-for-http gdl::*notify-cons*) :args args :remote-id (the remote-id) :remote-root-path (the remote-root-path) :package *package*))) (when *agile-debug?* (setq *send-plist* (stringify-plist (encode-plist-args plist)))) (let ((result (the (remote-execute "send-remote-message" plist)))) (cond ((and (consp result) (eql (first result) :error) (eql (second result) :no-such-object)) (progn (warn "~&Remote object returned error, creating a new one...~%") (the (set-slot! :remote-id nil :warn-on-non-toplevel? nil)) (the (restore-slot-default! :remote-id)) (the (send (:apply (cons message args)))))) ((and (consp result) (eql (first result) :error)) (format *error-output* "~&~%Remote object threw error:~%~%") (error (format nil (second result)))) (t result))))) (send-output (message format &rest args) (let ((plist (list :message (make-keyword message) :format format :args args :remote-id (the remote-id) :remote-root-path (the remote-root-path) :package *package*))) (let ((result (the (remote-execute "send-remote-output" plist)))) (write-string result *stream*)))))) ;; ;; FLAG -- promote this to a generic glisp finalizer scheme ;; (defparameter *remotes-to-purge* nil) (defparameter *remotes-to-purge-lock* (bt:make-lock)) #+ccl (defmethod ccl:terminate ((object remote-object)) (let ((data (list (the-object object host) (the-object object port) (the-object object remote-syntax) (the-object object remote-id)))) (bt:with-lock-held (*remotes-to-purge-lock*) (push data *remotes-to-purge*)))) (defun terminate-remotes () (loop (let ((remote (bt:with-lock-held (*remotes-to-purge-lock*) (pop *remotes-to-purge*)))) (unless remote (return)) (destructuring-bind (host port syntax id) remote (let ((result (do-remote-execute "delete-remote-object" host port syntax (list :current-id (make-keyword id)) :decode nil))) (unless (string-equal result "ok") (warn "Terminate of ~a returned ~a.~%" id result))))))) (defun launch-terminator () (bt:make-thread #'(lambda() (do () (nil) (sleep 5) (terminate-remotes))) :name "remote terminator, wakes every 5 seconds and cleans up stale remotes.")) (defun decode-from-http (item) (if (consp item) (multiple-value-bind (object-type initargs) (destructure-object-from-http item) (or (and object-type (evaluate-object object-type initargs)) (mapcar #'decode-from-http item))) item)) (defun encode-plist-args (plist) ;; ;; FLAG -- not sure if this is the perfect place to do this - have to downcase to work ;; with mlisp slave. ;; (let ((*print-case* :downcase)) #+allegro (when (eql excl:*current-case-mode* :case-sensitive-lower) (setq plist (upcase-plist plist))) (when plist (cons (first plist) (cons (encode-for-http (second plist)) (encode-plist-args (rest (rest plist)))))))) (defun stringify-plist (plist) (loop for (key val) on plist by #'cddr collect key collect (cond ((or (null val) (eql val t) (numberp val)) val) ((atom val) (format nil "~s" val)) ((keywordp (car val)) (stringify-plist val)) (t (mapcar #'stringify-plist val))))) (defun unstringify-plist (plist) (loop for (key val) on plist by #'cddr collect key collect (cond ((or (null val) (eql val t)) val) ((atom val) (read-safe-string val)) ((keywordp (car val)) (unstringify-plist val)) (t (mapcar #'unstringify-plist val))))) (defmethod encode-for-http ((item t)) item) (defmethod encode-for-http ((item pathname)) (format nil "~a" item)) (defmethod encode-for-http ((item package)) (string-downcase (package-name item))) (defmethod encode-for-http ((item list)) (with-standard-io-syntax (when item (cons (encode-for-http (first item)) (encode-for-http (rest item)))))) (defmethod encode-for-http ((item base-format)) (let ((slots-plist (mapcan #'(lambda(slot-definition) (let ((name (glisp:slot-definition-name slot-definition))) (list (make-keyword name) (encode-for-http (slot-value item name))))) (glisp:class-slots (class-of item))))) (append (list :type (class-name (class-of item))) slots-plist))) ;; ;; FLAG -- replace item with self and get rid of the-object ;; (defmethod encode-for-http ((item gdl-remote)) (let ((id (or (the-object item root local-remote-id) (let ((new-id (make-keyword (make-new-instance-id)))) (setf (gethash new-id *remote-objects-hash*) (the-object item root)) (the-object item root (set-slot! :local-remote-id new-id :remember? nil :warn-on-non-toplevel? nil)) new-id)))) (encode-remote-gdl-instance item id))) (defmethod encode-for-http ((item gdl::gdl-basis)) (let ((id (or (the-object item root remote-id) (let ((new-id (make-keyword (make-new-instance-id)))) (setf (gethash new-id *remote-objects-hash*) (the-object item root)) (the-object item root (set-slot! :remote-id new-id :remember? nil :warn-on-non-toplevel? nil)) new-id)))) (encode-remote-gdl-instance item id))) (defun gwl-host () ;; FIXME: better way to get this ? (when (boundp '*wserver*) (let ((sock (wserver-socket *wserver*))) (when sock (glisp:local-host sock))))) (defun encode-remote-gdl-instance (item id) (construct-object-for-http :remote-gdl-instance (list :id id :index (the-object item index) :type (format nil "~s" (the-object item type)) :root-path (the-object item root-path) :host (or *request-server-ipaddr* :unknown) :port (server-port)))) (defun construct-object-for-http (type plist) (list* :object-type type plist)) (defun destructure-object-from-http (list) (if (evenp (length list)) (alexandria:when-let (object-type (getf list :object-type)) (values object-type (remove-plist-key list :object-type))) ;; Support old object format for backward compatibility. (when (keywordp (first list)) (values (first list) (rest list))))) (defmethod print-object ((object remote-object) stream) (format stream "#<remote GDL object of type ~s>, a.k.a. " (the-object object remote-type)) (call-next-method))
15,629
Common Lisp
.lisp
310
37.106452
152
0.556065
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
d2536c204376739a4bcc3a47136712dc1a3e537e6babb9c74da31de92c918e2c
36,040
[ -1 ]
36,041
genworks.lisp
lisp-mirror_gendl/gwl/source/genworks.lisp
(in-package :com.genworks.lisp) (defun local-port (socket) (#+(or allegro zacl) socket:local-port #-(or allegro zacl abcl) acl-compat.socket:local-port #+abcl #'(lambda(socket) (declare (ignore socket) 0)) socket)) (defun remote-host (socket) #+(or allegro zacl) (socket:remote-host socket) #-(or allegro zacl abcl) (acl-compat.socket:remote-host socket)) ;; ;; FLAG -- add abcl ;; (defun local-host (socket) #+(or allegro zacl) (socket:local-host socket) #-(or allegro zacl abcl) (acl-compat.socket:local-host socket)) (defun with-timeout-sym () "Returns the appropriate symbol for with-timeout, for substitution within macros." #+(or allegro zacl) 'sys:with-timeout #+abcl 'bordeaux-threads:with-timeout #-(or allegro zacl abcl) 'acl-compat.mp:with-timeout) (defmacro with-timeout ((seconds &body timeout-body) &body body) #+(or allegro zacl) `(sys:with-timeout (,seconds ,@timeout-body) ,@body) #+abcl `(bordeaux-threads:with-timeout (,seconds ,@timeout-body) ,@body) #-(or allegro zacl abcl) `(acl-compat.mp:with-timeout (,seconds ,@timeout-body) ,@body))
1,102
Common Lisp
.lisp
23
45.086957
90
0.714286
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
0a92ba0a54962e7f51e6c75abf2b3f3da842bf64f3319c402f96ab32242cf8cf
36,041
[ -1 ]
36,042
defparameters.lisp
lisp-mirror_gendl/gwl/source/defparameters.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defclass gwl-gdl-ui ()()) (setq *ui-server* (make-instance 'gwl-gdl-ui)) (defparameter *keys-to-preserve* (list :/yadd)) (defparameter *bypass-security-check?* nil "Boolean. Indicates whether security check for same IP address is bypassed. Defaults to nil.") (defparameter *max-id-value* 999 "Integer. The maximum number to use for the randomly-generated instance ids for URI identifiers. Defaults to 999." ) (defparameter *server* nil) (defparameter *mime-file-types* (let ((ht (make-hash-table :size (hash-table-size net.aserve::*mime-types*) :test #'equalp))) (maphash #'(lambda(file-type mime-type) (let ((value (gethash mime-type ht))) (if value (nconc (gethash mime-type ht) (list file-type)) (setf (gethash mime-type ht) (list file-type))))) net.aserve::*mime-types*) ht)) (defparameter *iid-random-state* (make-random-state t)) (defparameter *query-plist* nil) (defparameter *field-plist* nil) (defparameter *max-node-depth* 100) (defparameter *js-incremental-search* ;; ;; FLAG -- rewrite as func with params. ;; (list :script " function incrementalSearch(which_key, modifiers) {searchString = document.main_form.selection.value; for(i=0;i<document.main_form.INGREDIENT.options.length;i++) {listIndex=i; if (searchString.toUpperCase() <= document.main_form.INGREDIENT.options[i].text.toUpperCase()) {break;}} document.main_form.INGREDIENT.selectedIndex = listIndex;}" :on-key-up "this.blur();this.focus();incrementalSearch(event.which, event.modifiers);")) (defparameter *req* nil "AllegroServe Request object. Dynamically bound to the current request object within a write-html-sheet or main-sheet function.") (defparameter *ent* nil "AllegroServe Entity object. Dynamically bound to the current entity object within a write-html-sheet or main-sheet function.") (defparameter *query* nil "Association list. Dynamically bound to the current query list within any of the form response methods.") (defvar *instance-hash-table* (make-hash-table) "Hash table. Keys are session ids and values are lists with GWL root objects and a dummy (for now) version.") (defvar *break-on-set-self?* nil "Boolean. Set this to non-nil if you want a break and *background-interaction* in emacs when the setSelf link is pressed. Defaults to nil.") (defvar *jump-to-toplevel-on-set-self?* nil "Boolean. Set this to non-nil if you want to jump to the toplevel interaction buffer in emacs when setSelf link is pressed and <tt>*break-on-set-self?*</t> is nil. Defaults to t.") (defparameter *remote-objects-hash* (glisp:make-weak-hash-table :weakness :value)) (defparameter *remote-proxies-hash* (make-hash-table :test #'equalp)) (defparameter *ipaddr* nil) (defparameter *compass-regions* '((:rect ((30 30) (50 50)) :recenter) (:polygon ((28 27) (40 2) (54 27)) :north) (:polygon ((28 56) (42 81) (54 56)) :south) (:polygon ((2 41) (26 30) (26 54)) :west) (:polygon ((55 29) (81 42) (55 54)) :east) (:polygon ((18 30) (11 12) (29 18)) :northwest) (:polygon ((58 18) (71 12) (66 30)) :northeast) (:polygon ((12 71) (16 53) (30 66)) :southwest) (:polygon ((53 65) (65 52) (71 71)) :southeast) )) (defvar *url-hash-table* (make-hash-table :test #'equalp)) (defvar *debug?* nil) (defvar *ssl-server* nil) (defvar *graphics-mode* :raster) (defparameter *clicked-x* nil) (defparameter *clicked-y* nil) (defparameter *descriptive-url-hash* (make-hash-table :test #'equalp)) (defparameter *failed-request-url* "/" "The redirection url that will be returned for a failed-request") (defparameter *process-cookies?* nil) (defparameter *recovery-url-default* "/" "The url that the session-control-mixin will use for the recovery url") (defparameter *publishers* nil "List of functions which accept server argument to do any aserve publishings.") (defun publish-uris () (with-all-servers (server) (dolist (publisher (reverse *publishers*)) (funcall publisher server))))
5,155
Common Lisp
.lisp
98
46.959184
125
0.687488
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
84108968567045b31aaf94114e13817d1e9dd666d39fa5b8fa57cfdf27b7c6a4
36,042
[ -1 ]
36,043
ignore-errors-with-backtrace.lisp
lisp-mirror_gendl/gwl/source/ignore-errors-with-backtrace.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defmacro ignore-errors-with-backtrace (&body body) "Like IGNORE-ERRORS, but in case of failure, return backtrace string as third value." `(block %debug-escape (handler-bind ((error (lambda (condition) (let ((backtrace (glisp:get-backtrace))) (return-from %debug-escape (values nil condition backtrace)))))) ,@body)))
1,286
Common Lisp
.lisp
29
39.413793
88
0.703465
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
0fe471e91847b2687266b1bb7d2fedd19a6b49633921a4f13671b30a30c62396
36,043
[ -1 ]
36,044
base-html-sheet.lisp
lisp-mirror_gendl/gwl/source/cookies/base-html-sheet.lisp
;; ;; Copyright 2013 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defmethod encode-for-ajax ((item t)) item) (defmethod encode-for-ajax ((item list)) (when item (cons (encode-for-ajax (first item)) (encode-for-ajax (rest item))))) (defmethod encode-for-ajax ((self gdl::root-path-container)) (list :%container-rp% (the root-path))) (defmethod encode-for-ajax ((self gdl::gdl-basis)) (list :%rp% (the root-path))) (defmethod decode-from-ajax ((item t) self) (declare (ignore self)) item) (defmethod decode-from-ajax ((item list) self) (when item (cond ((eql (first item) :%rp%) (the (follow-root-path (getf item :%rp%)))) ((eql (first item) :%container-rp%) (make-object 'gdl::root-path-container :root-path (getf item :%container-rp%))) (t (cons (decode-from-ajax (first item) self) (decode-from-ajax (rest item) self)))))) (defmacro with-cl-who ((&rest args) &body body) "Form. Sets up body to be evaluated with cl-who and output the resulting string to the default *stream* Note that the args are spliced into cl-who:with-html-output after *stream* nil, so for example you can do <pre> (with-cl-who (:indent t) ...) </pre> and it will expand into: <pre> (with-html-output (*stream* nil :indent t) ...) </pre> ." `(with-format (html-format *stream*) (with-html-output (*stream* nil ,@args) ,@body))) (defmacro with-cl-who-string ((&rest args) &body body) "Form. Sets up body to be evaluated with our with-cl-who return the resulting string instead of side-effecting anything at all to the default *stream*." `(with-output-to-string (*stream*) (with-cl-who (,@args) ,@body))) (defmacro with-htm (&body body) `(with-cl-who-string () ,@body)) (define-object base-html-sheet (sheet-section) :documentation (:description "This mixin allows a part to be displayed as a web page in GWL. The main output can be specified either in a <tt>write-html-sheet</tt> function in the object which mixes this in, or in a <tt>main-sheet</tt> output-function in an html-format view of the object.") :input-slots (("GDL object. Default object to which control will return with the write-back-link method" return-object (the :parent)) ("String. Name of a browser frame or window to display this page. Default of NIL indicates to use the same window." target nil) (instance-id nil :defaulting) (cookies-to-send nil) (cookies-received nil :settable) (fixed-url-prefix nil :defaulting) (tree-root (the root) :defaulting) ;; ;; Stuff to support dashboard ;; (time-last-touched nil :settable) (time-instantiated nil :settable) (last-visited-root-path nil :settable) (remote-host-original nil :settable) (remote-host nil :settable) ("List of keyword symbols. Messages corresponding to form fields which should not be retained against Updates to the model (e.g. calls to the update! function or hitting the Update button or link in the browser in development mode). Defaults to NIL (the empty list)." transitory-slots nil) ("Boolean. Determines whether a a sanity check is done (with the <tt>check-sanity</tt> function) before presenting the response page if this page is a respondent. Default is NIL." check-sanity? nil) (home-page nil :defaulting) ($$tatu-object (the $$tatu) :settable) ($$ta2-object (the $$ta2) :settable) (use-cookie? nil :defaulting) (plain-url? (the use-cookie?) :defaulting) (host nil :defaulting) (query-toplevel nil :settable)) :computed-slots ( ("Plist. Extra http headers to be published with the URI for this page." header-plist nil) ;; ;; FLAG -- replace localhost with computed hostname from running machine. ;; (full-url (when *wserver* (format nil "http://localhost:~a~a" (server-socket) (the url)))) ("String. The web address in the current session which points at this page. Published on demand." url (let ((url (if (the plain-url?) (format nil "~a/~a" (if (the fixed-url-prefix) (format nil "/~a" (the fixed-url-prefix)) "") (the (compute-url))) (format nil "~a/sessions/~a/~a" (if (the fixed-url-prefix) (format nil "/~a" (the fixed-url-prefix)) "") (the :instance-id) (the (compute-url)))))) (with-all-servers (server) (publish :path url :server server :content-type "text/html" :host (the host) :function #'(lambda (req ent) (the before-response!) (present-part req ent url :instance-id (when (and (the plain-url?) (not (the use-cookie?))) (the instance-id)) :header-plist (the header-plist) :fixed-prefix (the fixed-url-prefix))))) (unless (the use-cookie?) (pushnew url (gethash (make-keyword (the instance-id)) *url-hash-table*) :test #'string-equal)) (setf (gethash url *descriptive-url-hash*) (the root-path)) (when *debug?* (print-variables url)) url)) ("Plist. Contains submitted form field names and values for which no corresponding settable computed-slots exist. Where corresponding settable computed-slots exist, their values are set from the submitted form fields automatically." query-plist nil :settable) (%internal-hidden-object-keywords% (append (list :$$update :$$update-full :$$break :$$tatu :$$ta2 :color-palette :security-check-failed) (call-next-method)))) :trickle-down-slots (tree-root instance-id plain-url? host home-page query-toplevel fixed-url-prefix use-cookie?) :hidden-objects (($$update :type 'update :return-to self) ($$update-full :type 'update-full :return-to self) ($$break :type 'break-on :break-on self) ($$tatu :type (read-safe-string "tatu:assembly") :root-object self) ($$ta2 :type (if (find-package :ta2) (read-safe-string "ta2:assembly") 'null-part) ;;:root (the-child) :root-object self) (security-check-failed :type 'security-check-failed) (color-palette :type 'color-palette)) :functions ( (do-security-check () (or *bypass-security-check?* (the plain-url?) (eql (the remote-host) (the remote-host-original)))) (descriptive-url () (string-append (the descriptive-url-base) ".html")) (descriptive-url-base () (let ((url (let ((escaped-strings-for-display (html-escape (the strings-for-display)))) (if (the parent) (string-append (the parent descriptive-url-base) "/" escaped-strings-for-display) escaped-strings-for-display)))) url)) (url-base () (if (the root?) "" (string-append (the parent url-base) (string-downcase (glisp:replace-regexp (the strings-for-display) "\\s" "-")) "/"))) (compute-url () (string-append (the url-base) "index.html") ;;(compute-url (the root-path)) ) (set-self () (if *break-on-set-self?* (progn (set-self self) (let ((*package* (symbol-package (the type)))) (break))) (progn (set-self self)))) ("Void. Calls restore-defaults! on all the form-controls in this sheet." restore-form-controls! () (dolist (form-control (the form-controls)) (the-object form-control restore-defaults!))) (set-remote-host! (req &key original?) (if original? (the (set-slot! :remote-host-original (glisp:remote-host (request-socket req)))) (the (set-slot! :remote-host (glisp:remote-host (request-socket req)))))) (set-time-last-touched! () (the (set-slot! :time-last-touched (get-universal-time)))) (set-instantiation-time! () (the (set-slot! :time-instantiated (get-universal-time)))) ;; ;; FLAG -- make sure the instance-urls are in fact being ;; unpublished whenever we do an update! of a base-html-sheet. ;; ("NIL or error object. This function checks the \"sanity\" of this object. By default, it checks that following the object's root-path from the root resolves to this object. If the act of following the root-path throws an error, this error will be returned. Otherwise, if the result of following the root-path does not match the identity of this object, an error is thrown indicating this. Otherwise, NIL is returned and no error is thrown. You can override this function to do what you wish. It should return NIL if the object is found to be \"sane\" and an throw an error otherwise. If check-sanity? is set to T in this object, this function will be invoked automatically within an ignore-errors by the function handling the GWL \"/answer\" form action URI when this object is a respondent, before the main-sheet is presented." check-sanity () (let ((sanity (the root (follow-root-path (the root-path))))) (when (not (eql self sanity)) (error "Object identity does not match its root-path (failed sanity check).")))) ("Void. Emits a page explaining the sanity error. This will be invoked instead of the write-main-sheet if check-sanity? is set to T and the check-sanity throws an error. You may override this function to do what you wish. By default a minimal error message is displayed and a link to the root object is presented. :arguments (error \"an error object, presumably from the <tt>check-sanity</tt> function.\")" sanity-error (error) (html (:html (:head (:title "Error computing response page")) (:body (:p "The expected Respondent object could not be presented. The error was: " (:pre (:princ-safe error))) (when (ignore-errors (the root-path)) (html (:p "The reference chain to the expected Respondent was: " (:pre (:prin1-safe (cons 'the (reverse (the root-path)))))))) (:p "Click " (:b (the root (write-self-link :display-string "Here"))) " to visit the root of the site hierarchy."))))) ("Void. This is an empty function by default, but can be overridden in a user specialization of base-html-sheet, to do some processing before the header-plist is evaluated and before the HTTP response is actually initiated, but after the cookies-received have been set." process-cookies! ()) ("Void. This is an empty function by default, but can be overridden in a user specialization of base-html-sheet, to do some processing before the header-plist is evaluated and before the HTTP response is actually initiated." before-response! ()) ("Void. This is an empty function by default, but can be overridden in the respondent of a form, to do some processing before the respondent's <tt>write-html-sheet</tt> function runs to present the object. This can be useful especially for objects which are subclasses of higher-level mixins such as <tt>application-mixin</tt> and <tt>node-mixin</tt>, where you do not have direct access to the <tt>write-html-sheet</tt> function and typically only define the <tt>model-inputs</tt> function. It is not always reliable to do processing in the <tt>model-inputs</tt> function, since some slots which depend on your intended modifications may already have been evaluated by the time the <tt>model-inputs</tt> function runs." before-present! ()) ("Void. This is an empty function by default, but can be overridden in the respondent of a form, to do some processing after the respondent's <tt>write-html-sheet</tt> function runs to present the object." after-present! ()) ("Void. This is an empty function by default, but can be overridden in the requestor of a form, to do some processing before the requestor's form values are set into the specified bashee." before-set! ()) ("Void. This is an empty function by default, but can be overridden in the requestor of a form, to do some processing after the requestor's form values are set into the specified bashee." after-set! ()) (self-link (&key (display-string (the strings-for-display)) (display-color nil) (target nil) (title nil) class id on-click on-mouse-over on-mouse-out local-anchor) (with-cl-who-string () ((:a :href (if local-anchor (format nil "~a#~a" (the url) local-anchor) (the :url)) :target target :onmouseover on-mouse-over :onmouseout on-mouse-out :title title :class class :onclick on-click :id id) (if display-color (htm ((:font :color display-color) (str display-string))) (str display-string))))) ("Void. Emits a hyperlink pointing to self. Note that if you need extra customization on the display-string (e.g. to include an image tag or other arbitrary markup), use with-output-to-string in conjunction with the html-stream macro. :&key ((display-string (the :strings-for-display)) \"String. String to be displayed.\" (display-color nil) \"Keyword symbol or HTML color string. Determines the color of the displayed link text. Default of NIL indicates web browser default (usually blue).\" (target (the :target)) \"String. Names a frame or window to open the link when clicked.\" (class nil) \"String. Names a stylesheet class.\" (id nil) \"String. Names a stylesheet id.\" (on-mouse-over nil) \"String. Javascript code to run on mouse over.\" (on-mouse-out nil) \"String. Javascript code to run on mouse out.\")" write-self-link (&key (display-string (the :strings-for-display)) (display-color nil) (title nil) (target (the :target)) class id local-anchor on-click on-mouse-over on-mouse-out) (with-format (html-format *stream*) (write-the (self-link :display-string display-string :display-color (when display-color (lookup-color display-color :format :hex)) :target target :title title :class class :id id :local-anchor local-anchor :on-click on-click :on-mouse-over on-mouse-over :on-mouse-out on-mouse-out)))) (write-back-link (&key (display-string (if (and (the return-object) (the return-object strings-for-display)) (the return-object strings-for-display) "&lt;-Back")) (display-color nil) (title nil) (target (the :target)) class id local-anchor on-mouse-over on-mouse-out) (when (the return-object) (the return-object (write-self-link :display-string display-string :display-color (when display-color (lookup-color display-color :format :hex)) :target target :title title :class class :id id :local-anchor local-anchor :on-mouse-over on-mouse-over :on-mouse-out on-mouse-out)))) ("Void. Creates a default unordered list with links to each child part of self. The text of the links will come from each child's strings-for-display." write-child-links nil (html (:ul (mapc #'(lambda (child) (html (:li (the-object child :write-self-link)))) (the :children))))) (devo-links-string () (with-output-to-string (*html-stream*) (with-format (html-format *html-stream*) (write-the local-development-links)))) ("Void. Writes links for access to the standard developer views of the object, currently consisting of an update (Refresh!) link, a Break link, and a ta2 link." write-development-links () (let ((*stream* (or *html-stream* *stream*))) (with-format (html-format *stream*) (write-the development-links)))) ;; ;; FLAG -- superseded by form-controls ;; -- but still used in bus demo, need to rewrite that interface!! ;; ("Void. Writes an HTML Select field with Options. :&key ((size 1) \"Integer. determines size of selection list. Default of 1 is a pulldown menu.\" name \"Keyword symbol or string. Determines the name of the field, which should probably match a settable computed-slot.\" keys \"List of strings, numbers, or symbols. Values, the selected one of which will be returned as the value of the field.\" (values keys) \"List of strings. Keys to display in the selection-list.\" tabindex \"Integer. If given, this will generate the tabindex tag for this HTML input field.\")" select-choices (&key (size 1) name keys (values keys) tabindex (use-default? t)) (html ((:select :name name :size size :if* tabindex :tabindex tabindex) (mapc #'(lambda (key value) (html ((:option :value key :if* (and use-default? (equalp key (the (evaluate name)))) :selected :selected) (:princ value)))) keys values)))) ("Void. Writes some standard footer information. Defaults to writing Genworks and Franz copyright and product links. Note that VAR agreements often require that you include a ``powered by'' link to the vendor on public web pages." write-standard-footer (&key (include-copyright? t) (copyright-only? nil)) (html ((:p :class "copyrightFooter") (when (or include-copyright? copyright-only?) (html "Copyright &copy; " (multiple-value-bind (seconds minutes hours date month year) (get-decoded-time) (declare (ignore seconds minutes hours date month)) (html (:princ year))) " " ((:a :href "http://www.genworks.com") "Genworks") (:sup "&reg;") " " ((:a :href "http://www.genworks.com") "International") ". ")) (when copyright-only? (html "All rights reserved.")) (when (not copyright-only?) (html "This site is powered by " ((:a :href "http://www.franz.com") "Allegro CL") " and " ((:a :href "http://www.genworks.com") "Genworks") " GDL."))))) ("Void. This GDL function should be redefined to generate the HTML page corresponding to this object. It can be specified here, or as the <tt>main-sheet</tt> output-function in an html-format lens for this object's type. This <tt>write-html-sheet</tt> function, if defined, will override any <tt>main-sheet</tt> function defined in the lens. Typically a <tt>write-html-sheet</tt> function would look as follows: :example <pre> (write-html-sheet () (html (:html (:head (:title (:princ (the :page-title)))) (:body ;;; fill in your body here )))) </pre>" write-html-sheet () (with-format (html-format *html-stream*) (write-the (main-sheet))) )))
21,658
Common Lisp
.lisp
438
38.657534
178
0.611685
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
03a3abf3733101d3e4ec0a0a78bc2bd8774bb0edc4a2580a0ec5437067dcb79c
36,044
[ -1 ]
36,045
answer.lisp
lisp-mirror_gendl/gwl/source/cookies/answer.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defparameter *f-e-p* nil) (define-object session-control-mixin () :documentation (:description "Mixin to the root object of the part which you wish to have session control over" :author "Brian Sorg, Liberating Insight LLC (revised Dave Cooper, Genworks)") :input-slots (("Universal time after which the session should expire" expires-at nil :settable) ("Length of time a session should last without activity in minutes" session-duration 20) ("Boolean. Determines whether expired sessions are replaced by recovery object. Default is nil." use-recovery-object? nil) ("Expiration time of the recovery object. After the recovery object has replaced the orginal instance at what time should the recovery instance expire?" recovery-expires-at (+ (get-universal-time) (* 60 (the session-duration)))) ("Url to which a user will be redirected if requesting a session that has been cleared" recovery-url *recovery-url-default*) ("Type of original object, useful when viewing session report log" org-type (type-of self)) (;; For future use %state-plist% '(0))) :functions (("This is the function called to check for and handle session control :&key ((debug? nil) \"Boolean. Prints debug statement if needed\")" clear-expired-session (&key debug?) (when debug? (format t "Validating instance ~a~% of class ~a~% Current Universal Time: ~a.~% Expiration Time: ~a.~% Clear now? ~a.~%" (the instance-id) (class-of self) (get-universal-time) (the expires-at) (the (clear-now?)))) (when (the clear-now?) (the (session-clean-up)) (glisp:w-o-interrupts (clear-instance (the instance-id)) (when (and (the use-recovery-object?) (the recovery-expires-at)) (let ((recovery (make-object 'session-recovery :instance-id (the instance-id) :expires-at (the recovery-expires-at) :recovery-url (the recovery-url) :state-plist (the %state-plist%) :org-type (the org-type)))) (setf (gethash (make-keyword (the instance-id)) *instance-hash-table*) ;; ;; FLAG -- that last entry is actually supposed to be the skin class. ;; (list recovery (list 0) t))))))) ("Gets called right before the instance is going to get cleared. Is intended to be used to stop any instance states that may not be elequently handled by the garbage collector. ie database connections, multiprocessing locks, open streams etc." session-clean-up ()) ("Boolean. Test to run to see if this session has expired and needs to be cleared now." clear-now? () (when (the expires-at) (> (get-universal-time) (the expires-at)))) ("Method which will set the expires-at slot to the current time + the session-duration" set-expires-at (&optional (duration (the session-duration))) (the (set-slot! :expires-at (+ (get-universal-time) (* 60 duration))))))) (define-object session-recovery (session-control-mixin) :input-slots (instance-id )) (defun answer (req ent) (let ((query (request-query req))) (when *debug?* (format t "before multi-part processing, query is: ~s~%" query)) (when (null query) (setq query (process-multipart-submission req))) (when gwl::*debug?* (print-variables query)) (let* ((requestor (query-arg-to-root-path query "requestor")) (iid (make-keyword (rest (assoc "iid" query :test #'string-equal)))) (hash-entry (gethash iid *instance-hash-table*)) (root-object (first hash-entry)) (skin (third hash-entry)) (recovery-object? (typep root-object 'session-recovery)) (requestor (when (and root-object (not recovery-object?)) (the-object root-object (follow-root-path requestor)))) (bashee (when requestor (the-object requestor bashee))) (rest-plist (when (not recovery-object?) (merge-plist-duplicates (assoc-list-to-plist (remove-if #'(lambda(item) (member (first item) (list "requestor" "iid") :test #'string-equal)) query) :case-sensitive? t)))) (possible-nils (when (not recovery-object?) (the-object requestor possible-nils))) (rest-plist (when requestor (append rest-plist (mapcan #'(lambda(key) (list key nil)) (set-difference possible-nils (plist-keys rest-plist)))))) (settables (when bashee (the-object bashee %settable-slots%))) (rest-keys (plist-keys rest-plist)) (query-plist (mapcan #'(lambda(key) (list key (getf rest-plist key))) (remove-if #'(lambda(key) (gethash (make-keyword-sensitive key) settables)) rest-keys)))) (let ((respondent (the-object requestor respondent))) (the-object respondent root (set-remote-host! req)) (unless (the-object respondent root do-security-check) (with-http-response (req ent) (setf (reply-header-slot-value req :cache-control) "no-cache") (setf (reply-header-slot-value req :pragma) "no-cache") (with-http-body (req ent) (let ((*req* req) (*ent* ent)) (the-object respondent root security-check-failed write-html-sheet)))) (return-from answer nil))) (when gwl::*debug?* (print-variables query requestor iid hash-entry root-object recovery-object? requestor bashee rest-plist possible-nils settables rest-keys query-plist)) (let ((fe-processor (make-object 'form-element-processor :bashee bashee :query-plist query-plist))) (cond (recovery-object? (with-http-response (req ent :response *response-moved-permanently*) (setf (reply-header-slot-value req :location) (defaulting (the-object root-object recovery-url) *failed-request-url*)) (setf (reply-header-slot-value req :cache-control) "no-cache") (setf (reply-header-slot-value req :pragma) "no-cache") (with-http-body (req ent)))) ((null requestor) (net.aserve::failed-request req)) (t (let ((*query-plist* query-plist) (*field-plist* rest-plist)) (the-object requestor (before-set!))) ;;(when *debug?* (print-variables *query-plist* rest-plist rest-keys)) (when *debug?* (setq *f-e-p* fe-processor)) (dolist (key rest-keys) (when (gethash (make-keyword-sensitive key) settables) ;;(when *debug?* (print-variables key)) (the-object bashee (set-slot-if-needed! (make-keyword-sensitive key) (getf rest-plist key))))) (the-object fe-processor validate-and-set!) (when (and (fboundp 'process-graphics-fields) (typep (the-object requestor) (read-from-string "gwl:base-html-graphics-sheet")) (the-object requestor (evaluate :view-object))) (setq query-plist (funcall (read-from-string "gwl::process-graphics-fields") query query-plist root-object requestor))) (when (not (equalp (the-object bashee query-plist) query-plist)) (the-object bashee (set-slot! :query-plist query-plist :remember? (not (member :query-plist (the-object bashee transitory-slots)))))) (let ((result (let ((*req* req) (*ent* ent) (*skin* skin) (*query* query)) (the-object requestor (after-set!))))) (let ((respondent (if (and (consp result) (eql (first result) :go-to)) (second result) (the-object requestor respondent)))) ;; ;; Dashboard stuff ;; ;; ;; FLAG - use actual application-root rather than simple root. ;; (when (typep root-object 'session-control-mixin) (the-object root-object (set-expires-at))) (the-object respondent root (set-time-last-touched!)) (the-object respondent root (set-slot! :last-visited-root-path (the-object respondent root-path))) ;; ;; ;; (with-http-response (req ent :response *response-found*) (setf (reply-header-slot-value req :cache-control) "no-cache") (setf (reply-header-slot-value req :pragma) "no-cache") (setf (reply-header-slot-value req :location) (the-object respondent url)) (let ((keys (plist-keys (the-object respondent header-plist))) (values (plist-values (the-object respondent header-plist)))) (mapc #'(lambda(key val) (setf (reply-header-slot-value req key) val)) keys values)) (with-http-body (req ent) (let ((*req* req) (*ent* ent) (*skin* skin)) (multiple-value-bind (check error) (when (the-object respondent check-sanity?) (ignore-errors (the-object respondent check-sanity))) (declare (ignore check)) (if error (the-object respondent (sanity-error error))))))))))))))) (defun process-multipart-submission (req) (let (sep query (directory (glisp:temporary-folder))) (do ()(nil) (multiple-value-bind (kind name filename content-type) (parse-multipart-header (get-multipart-header req)) (declare (ignorable content-type)) (when filename (setq sep (max (or (position #\/ filename :from-end t) -1) (or (position #\\ filename :from-end t) -1))) (setq filename (subseq filename (1+ sep) (length filename)))) (case kind (:eof (return query)) (:data (push (cons name (get-all-multipart-data req)) query)) (:file (let ((output-path (merge-pathnames filename directory))) (push (cons name (format nil "~a" output-path)) query) (with-open-file (out output-path :direction :output :if-exists :supersede :element-type '(unsigned-byte 8)) (let ((buffer (make-array 4096 :element-type '(unsigned-byte 8)))) (do ()(nil) (let ((count (get-multipart-sequence req buffer))) (when (null count) (return)) (write-sequence buffer out :end count)))))))))))) (defun make-object-internal (req ent) (let ((query (request-query req))) (let ((part (rest (or (assoc "object" query :test #'string-equal) (assoc "part" query :test #'string-equal))))) (gwl-make-part req ent part)))) (defun gwl-make-part (&rest args) (apply 'gwl-make-object args)) (defparameter *weak-objects* (glisp:make-weak-hash-table)) (defmethod restore-ui-object ((ui-server gwl-gdl-ui) object) (when (typep object 'base-html-sheet) (format t "~&Restoring GWL UI status for ~s...~%" object) ;; ;; FLAG -- handle skins ;; (let* ((instance-id (the-object object instance-id)) (current (gethash (make-keyword-sensitive instance-id) *instance-hash-table*)) (root-part-and-version (list object *dummy-version*))) (setf (gethash (first root-part-and-version) *weak-objects*) t) (when current (warn "Instance ID of restored object, ~a, is already in use. Generating new instance id..." instance-id) (setq instance-id (make-new-instance-id)) (format t "~&New Instance ID is: ~a~%" (progn (the-object object (set-slot! :instance-id instance-id)) (the-object object instance-id)))) (the-object (first root-part-and-version) url) (setf (gethash (make-keyword-sensitive instance-id) *instance-hash-table*) root-part-and-version)))) (defun %gwl-make-object% (part &key make-object-args share? skin) (let* ((instance-id (if share? "share" (make-new-instance-id))) (current (gethash (make-keyword-sensitive instance-id) *instance-hash-table*)) (skin (if skin (make-instance skin) t)) (root-part-and-version (if (or (not share?) (not current)) (list (apply #'make-object (read-safe-string part) :instance-id instance-id make-object-args) *dummy-version*) current))) (setf (gethash (first root-part-and-version) *weak-objects*) t) (setq root-part-and-version (append root-part-and-version (list skin))) (when (or (not share?) (not current)) (setf (gethash (make-keyword-sensitive instance-id) *instance-hash-table*) root-part-and-version)) (first root-part-and-version))) (defun gwl-make-object (req ent part &key make-object-args share? skin (instance-id (if share? "share" (make-new-instance-id)))) "Void. Used within the context of the body of a :function argument to Allegroserve's publish function, makes an instance of the specified part and responds to the request with a redirect to a URI representing the instance. :arguments (req \"Allegroserve request object, as used in the function of a publish\" ent \"Allegroserve entity object, as used in the function of a publish\" package-and-part \"String. Should name the colon- (or double-colon)-separated package-qualified object name\") :&key ((make-object-args nil) \"Plist of keys and values. These are passed to the object upon instantiation.\" (share? nil) \"Boolean. If non-nil, the instance ID will be the constant string ``share'' rather than a real instance id.\") :example <pre> (publish :path \"/calendar\" :function #'(lambda(req ent) (gwl-make-object req ent \"calendar:assembly\"))) </pre>" (let ((query (request-query req))) (let* ((part (or part (rest (assoc "part" query :test #'string-equal)))) (part-type (read-safe-string part)) (session-urls? (not (assoc "cookies" query :test #'string-equal))) (path (format nil "~a/~a" (package-name (symbol-package part-type)) part-type))) (let* ((current (gethash (make-keyword-sensitive instance-id) *instance-hash-table*)) (skin (if skin (make-instance skin) t)) (root-part-and-version (if (or (not share?) (not current)) (list (apply #'make-object part-type :instance-id instance-id ;;:query-toplevel query :use-cookie? (not session-urls?) :fixed-url-prefix (unless session-urls? path) make-object-args) *dummy-version*) current))) (setf (gethash (first root-part-and-version) *weak-objects*) t) (setq root-part-and-version (append root-part-and-version (list skin))) (when (or (not share?) (not current)) (setf (gethash (make-keyword-sensitive instance-id) *instance-hash-table*) root-part-and-version)) (let ((object (first root-part-and-version))) (when (typep object 'session-control-mixin) (the-object object set-expires-at)) (the-object object set-instantiation-time!) (the-object object set-time-last-touched!) (the-object object (set-remote-host! req :original? t)) (with-http-response (req ent :response *response-found*) (setf (reply-header-slot-value req :location) (format nil "~a" (the-object (first root-part-and-version) url))) (when (the-object object use-cookie?) (set-cookie-header req :name "iid" :path (let ((prefix (the-object object fixed-url-prefix))) (when prefix (string-append "/" prefix))) :value instance-id)) (setf (reply-header-slot-value req :cache-control) "no-cache") (setf (reply-header-slot-value req :pragma) "no-cache") (with-http-body (req ent)))))))) (defun publish-shared (&key path object-type host (server *wserver*) (key (make-keyword-sensitive path))) "Void. Used to publish a site which is to have a shared toplevel instance tree, and no URI rewriting (i.e. no \"/sessions/XXX/\" at the beginning of the path). So, this site will appear to be a normal non-dynamic site even though the pages are being generated dynamically. :&key ((path nil) \"String. The URI path to be published.\" (object-type nil) \"Symbol. The type of the toplevel object to be instantiated.\" (host nil) \"hostname for the URI to be published.\" (server *wserver*) \"Allegroserve server object. If you have additional servers other than the default <tt>*wserver*</tt> (e.g. an SSL server) you may want to call this function for each server.\") :example <pre> (publish-shared :path \"/\" :object-type 'site:assembly :host (list \"www.genworks.com\" \"ww2.genworks.com\" \"mccarthy.genworks.com\")) </pre>" (let ((object (make-object (if (stringp object-type) (read-safe-string object-type) object-type) :instance-id key :plain-url? t :host host))) (setf (gethash key *instance-hash-table*) (list object)) (publish :path path :server server :host host :content-type "text/html" :function #'(lambda(req ent) (let ((*req* req) (*ent* ent) (object (first (gethash key *instance-hash-table*)))) (with-http-response (req ent) (setf (reply-header-slot-value req :cache-control) "no-cache") (setf (reply-header-slot-value req :pragma) "no-cache") (with-http-body (req ent) (the-object object write-html-sheet)))))))) (define-object form-element-processor () :input-slots (bashee query-plist) :computed-slots ( (form-element-objects (the bashee form-controls)) (force-validation-for (the bashee force-validation-for)) (form-element-keys (mapcar #'(lambda(object) (the-object object field-name)) (the form-element-objects))) (radios (mapcan #'(lambda(key) (when (and (glisp:match-regexp "^radio-" (string-downcase (format nil "~a" key))) (string-equal (second (getf (the query-plist) key)) "true")) (list (make-keyword-sensitive (glisp:replace-regexp (glisp:replace-regexp (glisp:replace-regexp (format nil "~a" key) "^RADIO-" "") "^radio-" "") "-.*" "")) (first (getf (the query-plist) key))))) (plist-keys (the query-plist)))) (query-plist-all (append (the radios) (mapcan #'(lambda(key val) (unless (or (glisp:match-regexp "^radio-" (string-downcase (format nil "~a" key))) (glisp:match-regexp "-checkedp$" (string-downcase (format nil "~a" key)))) (list key val))) (plist-keys (the query-plist)) (plist-values (the query-plist))))) (checked-booleans (mapcan #'(lambda(key) (when (glisp:match-regexp "-checkedp$" (string-downcase (format nil "~a" key ))) (list (make-keyword-sensitive (glisp:replace-regexp (glisp:replace-regexp (format nil "~a" key ) "-checkedp$" "") "-CHECKEDP$" "")) (let ((checked (getf (the query-plist) key))) (not (string-equal checked "false")))))) (plist-keys (the query-plist)))) (form-elements-to-bash% (let ((submitted-elements (let* ((query-plist-keys (plist-keys (the query-plist-all))) ;; ;; Comment out this #+nil and uncomment the one below to switch to ;; 1579p007 behavior (i.e. ability to have form-element from ;; anywhere in the tree). This really should be the correct ;; behavior. ;; (keys (remove-if-not #'(lambda(key) ;; FLAG -- check for value ;; form-control object for ;; each key ;; (typep (ignore-errors (the bashee root (follow-root-path (base64-decode-list (string key))))) 'base-form-control)) query-plist-keys)) ;; ;; #+nil (keys (remove-if-not #'(lambda(key) (find key query-plist-keys)) (the form-element-keys)))) (mapcan #'(lambda(key) (list key (if (member key (the checked-booleans)) (getf (the checked-booleans) key) (getf (the query-plist-all) key)))) keys)))) (let ((result (append submitted-elements (mapcan #'(lambda(object) (list (the-object object field-name) (the-object object value))) (remove-if #'(lambda(objct) (member (the-object objct field-name) (plist-keys submitted-elements))) (ensure-list (the force-validation-for))))))) result))) (form-elements-to-bash (the form-elements-to-bash%)) #+nil (form-elements-to-bash (mapcan #'(lambda(key val) ;; ;; The comparison of old and new should work, to avoid unneeded ;; bashing when the old and new values are the same. ;; (let (#+nil (new (getf (the bashee root (follow-root-path (base64-decode-list (string key))) (validate-type val)) :typed-value)) #+nil (old (the bashee root (follow-root-path (base64-decode-list (string key))) value))) ;;(unless (equalp new old) (list key val)) (list key val) )) (plist-keys (the form-elements-to-bash%)) (plist-values (the form-elements-to-bash%))))) :functions ((validate-and-set! () (dotimes (n 2) (dolist (key (plist-keys (the form-elements-to-bash))) (let ((*out-of-bounds-sequence-reference-action* :silent)) (let ((element (the bashee root (follow-root-path (base64-decode-list (string key)))))) (when element (unless (eql (first (the-object element root-path)) :%delete-button%) (when (or (= n 1) (the bashee preset-all?) (the-object element preset?)) (the-object element (validate-and-set! (getf (the form-elements-to-bash) key)))))))))) (dolist (key (plist-keys (the form-elements-to-bash))) (let ((*out-of-bounds-sequence-reference-action* :silent)) (let ((element (the bashee root (follow-root-path (base64-decode-list (string key)))))) (when element (when *debug?* (print-variables (the-object element root-path))) (when (eql (first (the-object element root-path)) :%delete-button%) (the-object element parent aggregate (delete! (the-object element parent index)))))))))))
28,160
Common Lisp
.lisp
467
41.24197
247
0.52784
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
98da192577d6c73f16c2e3d9246b8cf52dfc0688c3feb0c5c0029474d229b0d8
36,045
[ -1 ]
36,046
macros.lisp
lisp-mirror_gendl/gwl/source/cookies/macros.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gwl) (defmacro with-all-servers ((server) &rest body) (let ((server-var (gensym))) `(dolist (,server-var (list *wserver* *ssl-server*)) (when ,server-var (let ((,server ,server-var)) ,@body))))) (define-object form-mixin ()) (define-lens (html-format form-mixin)() :output-functions ((:form (slot-names &key (size-default 5) (sizes (make-list (length slot-names) :initial-element size-default)) (prompts (mapcar #'(lambda(slot-name) (symbol-name slot-name)) slot-names)) (cellpadding 0) (heading-color :yellow)) (html (:p ((:table :cellpadding cellpadding) (:tr ((:th :colspan 2) "Dimensions")) (mapc #'(lambda(slot-name prompt size) (html (:tr ((:td :bgcolor heading-color) (:princ (string-capitalize prompt))) (:td ((:input :type :text :name (symbol-name slot-name) :size size :value (or (the (evaluate slot-name)) ""))))))) slot-names prompts sizes))) (:p ((:input :type :submit :name :subbmit :value " OK "))))))) (defmacro html-form (slot-names &key (size-default 5) (sizes (make-list (length slot-names) :initial-element size-default)) (prompts (mapcar #'(lambda(slot-name) (symbol-name slot-name)) slot-names)) (cellpadding 0) (heading-color :yellow)) `(html (:p ((:table :cellpadding ,cellpadding) (:tr ((:th :colspan 2) "Dimensions")) ,@(mapcar #'(lambda(slot-name prompt size) `(:tr ((:td :bgcolor ,heading-color) (:princ ,(string-capitalize prompt))) (:td ((:input :type :text :name ,(symbol-name slot-name) :size ,size :value (or (the ,slot-name) "")))))) slot-names prompts sizes))) (:p ((:input :type :submit :name :subbmit :value " OK "))))) (defmacro with-html-form ((&key name id multipart? enctype target requestor on-submit suppress-border? local-anchor cl-who?) &body body) "Enclose a body of code with a form. FLAG -- fill in. " (let ((%enctype% (gensym)) (fixed-prefix (gensym))) `(let ((,%enctype% (cond (,enctype ,enctype) (,multipart? "multipart/form-data"))) (,fixed-prefix (let ((prefix (the fixed-url-prefix))) (when prefix (string-append "/" prefix))))) (,@(if cl-who? '(with-html-output (*stream* nil :indent t)) '(html ;;html-stream *stream* )) ((:form :method :|post| :id ,id :action (string-append (or ,fixed-prefix "") (format nil (if ,local-anchor (format nil "/answer#~a" ,local-anchor) "/answer"))) :name ,(or name `(the root-path-string)) ,@(if cl-who? `(:enctype ,%enctype%) `(:if* ,%enctype% :enctype ,%enctype%)) ,@(if cl-who? `(:target ,target) `(:if* ,target :target ,target)) ,@(if cl-who? `(:on-submit ,on-submit) `(:if* ,on-submit :onsubmit ,on-submit)) ,@(if cl-who? `(:style ,(when suppress-border? "padding: 0; border: 0; margin: 0")) `(:if* ,suppress-border? :style "padding: 0; border: 0; margin: 0"))) ((:input :type :hidden :name :|requestor| :value ,(if (null requestor) `(the url-encoded-root-path) `(the-object ,requestor url-encoded-root-path)))) ((:input :type :hidden :name :|iid| :value (the instance-id))) ,@body))))) #+nil (defmacro with-html-form ((&key name multipart? enctype target requestor on-submit suppress-border? local-anchor cl-who?) &body body) "Enclose a body of code with a form. FLAG -- fill in. " (let ((%enctype% (gensym)) ;;(fixed-prefix (gensym)) ) `(let ((,%enctype% (cond (,enctype ,enctype) (,multipart? "multipart/form-data"))) ;;(,fixed-prefix (the fixed-url-prefix)) ) (,@(if cl-who? '(with-html-output (*stream* nil :indent t)) '(html ;;html-stream *stream* )) ((:form :method :|post| :action (string-append "" ;;(or ,fixed-prefix "") (format nil (if ,local-anchor (format nil "/answer#~a" ,local-anchor) "/answer"))) :name ,(or name `(the root-path-string)) ,@(if cl-who? `(:enctype ,%enctype%) `(:if* ,%enctype% :enctype ,%enctype%)) ,@(if cl-who? `(:target ,target) `(:if* ,target :target ,target)) ,@(if cl-who? `(:on-submit ,on-submit) `(:if* ,on-submit :onsubmit ,on-submit)) ,@(if cl-who? `(:style ,(when suppress-border? "padding: 0; border: 0; margin: 0")) `(:if* ,suppress-border? :style "padding: 0; border: 0; margin: 0"))) ((:input :type :hidden :name :|requestor| :value ,(if (null requestor) `(the url-encoded-root-path) `(the-object ,requestor url-encoded-root-path)))) ((:input :type :hidden :name :|iid| :value (the instance-id))) ,@body)))))
6,573
Common Lisp
.lisp
115
42.486957
127
0.540367
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
0c3932345f227181bb1c860ad067fccd977e08e4c46c6bad5fdf1e1a84ceefec
36,046
[ -1 ]
36,047
package.lisp
lisp-mirror_gendl/cl-lite/source/package.lisp
;; ;; Copyright 2002, 2009 Genworks International and Genworks BV ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl-user) (gdl:define-package :cl-lite (:documentation #.(glisp:system-description :cl-lite)) (:export #:cl-lite #:codebase-directory-node))
1,021
Common Lisp
.lisp
24
40.958333
70
0.755287
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
7f22a772f08f75ee1813b64077b6b83c521d88bdb35d79d7640e510741bdd1a0
36,047
[ -1 ]
36,048
cl-lite.lisp
lisp-mirror_gendl/cl-lite/source/cl-lite.lisp
;; -*- coding: utf-8 -*- ;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :cl-lite) (defun cl-lite (pathname &rest args) " Traverses pathname in an alphabetical depth-first order, compiling and loading any lisp files found in source/ subdirectories. A lisp source file will only be compiled if it is newer than the corresponding compiled fasl binary file, or if the corresponding compiled fasl binary file does not exist. A bin/source/ will be created, as a sibling to each source/ subdirectory, to contain the compiled fasl files. If the :create-fasl? keyword argument is specified as non-nil, a concatenated fasl file, named after the last directory component of pathname, will be created in the (glisp:temporary-directory). [Note: this new documentation still needs proper formatting] If the :create-asd-file? keyword argument is specified as non-nil, a .asd file suitable for use with ASDF will be emitted into the directory indicated by the pathname argument. Note that ASDF (Another System Definition Utility), possibly with help of Quicklisp, is (as of 2013-03-12) the recommended way for handling Common Lisp system modules. As of version 2.31.9, ASDF is also capable of generating fasl \"bundle\" files as with the :create-fasl? argument to cl-lite. For the :author, :version, and :license arguments in the generated .asd file, the files author.isc, version.isc, and license.isc, respectively, are consulted, if they exist. They are searched for first in the codebase toplevel directory (the pathname argument to this function), then in the (user-homedir-pathname). The version defaults to the current ISO-8601 date without dashes, e.g. \"20130312\". Please see the Genworks Documentation for an overview of Quicklisp and ASDF, and see the Quicklisp and ASDF project documentation for detailed information. The source code for Quicklisp and ASDF should also be included with your Gendl distribution, and these are typically loaded by default into the development environment. For additional inputs to the cl-lite function, please see codebase-directory-node object for additional inputs (which can be given as keyword args to this function)." (glisp:begin-redefinitions-ok) (let ((result (let ((package-file-ht (glisp:make-sans-value-equalp-hash-table))) (remf args :show-redefinition-warnings? ) (with-compilation-unit () (let ((object (apply #'make-object 'codebase-directory-node :pathname pathname args))) (unless nil ;;(the-object object dry-run?) (the-object object (compile-and-load :package-file-ht package-file-ht))) (when (the-object object create-asd-file?) (the-object object (write-asd-file)))))))) (glisp:end-redefinitions-ok) result)) (defun cl-patch (pathname &rest args) " Traverses pathname in a manner identical to cl-lite, but only those files for which the source is newer than the corresponding fasl binary file (or for which the corresponding fasl binary file does not exist) will be loaded. Use this for incremental updates where the unmodified source files do not depend on the modified source files." (apply #'cl-lite pathname :load-always? nil args)) (defun cl-config (pathname-host config-name &key create-fasl?) (let* ((base-dir (pathname-directory (translate-logical-pathname pathname-host))) (base-device (pathname-device (translate-logical-pathname pathname-host))) (config-spec (glisp:sexpr-from-file (make-pathname :directory (append base-dir (list "configs")) :device base-device :name config-name :type "config"))) (bin-files (apply #'append (mapcar #'cl-lite (mapcar #'(lambda(component) (make-pathname :directory (append base-dir component) :device base-device)) config-spec))))) (when create-fasl? (glisp:concatenate-fasls bin-files (make-pathname :directory (append base-dir (list "configs")) :device base-device :name config-name :type glisp:*fasl-extension*))))) (eval-when (:compile-toplevel :load-toplevel :execute) (define-object directory-node nil :input-slots (pathname (pathname-root (the pathname)) (strings-for-display (format nil "~a" (the :local-name))) (subdir-type 'directory-node) (additional-parameters nil) (dry-run? nil)) :computed-slots ((device (pathname-device (the ppathname))) (ppathname (probe-file (translate-logical-pathname (pathname (the pathname))))) (contents (sort (glisp:directory-list (the ppathname)) #'(lambda (x y) (string< (file-namestring x) (file-namestring y))))) (local-name (lastcar (pathname-directory (or (the ppathname) (the pathname))))) (subdir-pathnames (mapcar #'pathname-directory (remove-if-not #'glisp:file-directory-p (the contents)))) ) :trickle-down-slots (device) :objects ((subdirs :type (the :subdir-type) :sequence (:size (length (the :subdir-pathnames))) :pathname-root (the pathname-root) :pathname (make-pathname :device (the :device) :directory (nth (the-child :index) (the :subdir-pathnames))) :pass-down (dry-run?) :parameters (the :additional-parameters))))) (defun asd-generator (pathname) (the-object (make-object 'asd-generator :pathname pathname) generate-all!)) (define-object asd-generator (directory-node) :computed-slots ((local-asd-files (remove-if-not #'(lambda(item) (string-equal (pathname-type item) "asd")) (the contents))) (all-asd-files (apply #'append (the local-asd-files) (mapsend (the subdirs) :all-asd-files))) (directories-in-need (mapcar #'(lambda(asd-file) (make-pathname :defaults asd-file :name nil :type nil)) (the all-asd-files))) (subdir-type 'asd-generator)) :functions ((generate-all! () (dolist (directory (the directories-in-need)) (cl-lite directory :create-asd-file? t))))) (define-object codebase-directory-node (directory-node) :documentation (:description "Models a filesystem directory for use by the cl-lite program.") :functions ((read-isc-file (name) (let ((files-to-check (mapcar #'(lambda(path) (merge-pathnames (make-pathname :type "isc") (merge-pathnames name path))) (list (the pathname) (user-homedir-pathname))))) (dolist (file files-to-check) (when (probe-file file) (return (glisp:sexpr-from-file file))))))) :input-slots ( (description (concatenate 'string "The Gendl® " (or (the (read-isc-file "description")) (format nil "~a Subsystem" (the local-name))))) (author (or (the (read-isc-file "author")) "Genworks International")) (version (or (the (read-isc-file "version")) (replace-substring (iso-8601-date (get-universal-time)) "-" ""))) (license (or (the (read-isc-file "license")) "Affero Gnu Public License (http://www.gnu.org/licenses/)")) ("Plist of keywords and lists of strings. Maps directory names to their default type classifications." type-mapping (list :tables '(("tables") ("table")) :source '(("source" "icons") ("lisp" "cl" "gdl" "gendl")) :qa '(("qa") ("lisp")) :exercises '(("exercises")))) ("List of strings. Identifies the names of directories considered to hold binaries. Default is (list \"bin\" \"patch\")" bin-subdir-names (list "bin" "patch")) ("List of strings. Identifies the names of directories which are part of a vc-system control files and therefore should be treated as special subdirectories. Default is (list \"CVS\")" special-subdir-names (list "CVS")) (fasl-type glisp:*fasl-extension*) ("String or pathname object. Designates the pathname for the filesystem directory in which the built concatenated fasls are written. Defaults to <tt>(glisp:temporary-folder)</tt>" fasl-output-path (glisp:temporary-folder)) (fasl-output-device (pathname-device (the fasl-output-path))) (fasl-output-directory (pathname-directory (the fasl-output-path))) ("String. Names the built concatenated fasl when <tt>(the create-fasl?)</tt> is non-nil. Defaults to <tt>(the local-name)</tt> " fasl-output-name (the local-name)) ("String. Names the fasl extension used by the compiler. Defaults to the local fasl output type." fasl-output-type glisp:*fasl-extension*) (parent-dir (the :parent)) ("List of strings. Lists directory names which should be ignored as having compilable source code for the build." source-files-to-ignore (list "system")) ("Boolean. Determines whether to write a concatenated fasl for the build. Defaults to nil. NOTE: this is not currently supported in cl-lite. " create-fasl? nil) (create-asd-file? nil) (dry-run? (the create-asd-file?)) ("Boolean. Determines whether to load the individual compiled fasls even if the source has not changed. Defaults to nil (i.e. we assume we are loading into a clean system and need all the initial definitions.)." load-always? t) (encoding-line ";;;; -*- coding: utf-8 -*-") ) :computed-slots ( (strings-for-display (let ((string (enough-namestring (the pathname) (the pathname-root)))) (if (string-equal string "") (string-append (lastcar (pathname-directory (the pathname))) "/") string))) (additional-parameters (list :type-mapping (the :type-mapping) :bin-subdir-names (the :bin-subdir-names) :special-subdir-names (the :special-subdir-names) :fasl-type (the :fasl-type) :load-always? (the :load-always?))) (subdir-type 'codebase-directory-node) (subdir-pathnames (the :subdir-computation :subdir-pathnames)) (type-matches (the :subdir-computation :type-matches)) (relevant-files (the :file-computation :relevant-files)) (binary-directory (let ((base-dir (pathname-directory (the :ppathname)))) (let ((binary-directory (make-pathname :device (the :device) :directory (append (butlast base-dir) (list "bin" (lastcar base-dir)))))) (unless (the dry-run?) (format t "~&*** Creating ~s~%" binary-directory) (ensure-directories-exist binary-directory)) (pathname-directory binary-directory)))) (local-package-files (remove-if-not #'(lambda (file) (and (string-equal (pathname-name file) "package") (or (string-equal (pathname-type file) "lisp") (string-equal (pathname-type file) "cl")))) (the :contents))) (package-files (sort (flatten (append (the :local-package-files) (mapcar #'(lambda (subdir) (the-object subdir :package-files)) (list-elements (the :subdirs))))) #'string< :key #'pathname-name)) (asd-file (let ((asd-file-name (make-pathname :name (the fasl-output-name) :type "asd"))) (or (and (the ppathname) (merge-pathnames asd-file-name (the ppathname))) (error "Could not create ~a in ~a.~%Directory does not exist.~%" asd-file-name (the pathname))))) ;; ;; This has to be able to be a string in case it has e.g. #-allegro ;; conditionals in it. ;; (asdf-depends-on (let ((sexpr (glisp:sexpr-from-file (merge-pathnames (make-pathname :name "depends-on" :type "isc") (the ppathname))))) (if (stringp sexpr) (format nil "%%remove%%~a%%remove%%" sexpr) sexpr))) #+nil (asdf-defsystem-depends-on (let ((sexpr (glisp:sexpr-from-file (merge-pathnames (make-pathname :name "defsystem-depends-on" :type "isc") (the ppathname))))) (if (stringp sexpr) (format nil "%%remove%%~a%%remove%%" sexpr) sexpr))) (asdf-defsystem-depends-on (let ((sexpr (glisp:sexpr-from-file (merge-pathnames (make-pathname :name "defsystem-depends-on" :type "isc") (the ppathname))))) (if (and sexpr (not (stringp sexpr))) (error "defsystem-depends-on.isc should be either nil or a string containing the expression to go inside the actual list form in the asdf file. It came in as ~s instead.~%" sexpr) sexpr))) (additional-asd-code (let ((asd-code-file (merge-pathnames (make-pathname :name "additional-asd-code" :type "isc") (the ppathname)))) (when (probe-file asd-code-file) (with-open-file (in asd-code-file :external-format :utf-8) (let (result) (let (*read-eval*) (do ((form (read in nil nil) (read in nil nil))) ((null form) (nreverse result)) (push form result)))))))) ;; ;; sanitize any strings for the depends-on ;; (asdf-system-lines (let ((temp-file (glisp:temporary-file))) (with-open-file (out temp-file :direction :output :if-exists :supersede :if-does-not-exist :create :external-format :utf-8) (pprint (the %asdf-system-list) out)) (with-open-file (in temp-file :external-format :utf-8) (let (result) (do ((line (read-line in nil) (read-line in nil))) ((null line) (nreverse result)) (push (glisp:replace-regexp (glisp:replace-regexp line "%%remove%%\"" "") "\"%%remove%%" "") result)))))) (%asdf-system-list (let ((binaries (the compile-and-load))) (append `("%%remove%%asdf:defsystem%%remove%%" ,(read-from-string (format nil "#:~a" (pathname-name (the asd-file)))) :description ,(the description) :author ,(the author) :license ,(the license) :serial t :version ,(the version) :depends-on ,(the asdf-depends-on) ,(format nil "%%remove%%#-asdf-unicode :defsystem-depends-on #-asdf-unicode ~a%%remove%%" (format nil "(:asdf-encodings~a~a)" (if (the asdf-defsystem-depends-on) " " "") (or (the asdf-defsystem-depends-on) ""))) ,(format nil "%%remove%%#+asdf-unicode :defsystem-depends-on #+asdf-unicode ~a%%remove%%" (format nil "(~a)" (or (the asdf-defsystem-depends-on) ""))) "%%remove%%#+asdf-encodings :encoding #+asdf-encodings :utf-8%%remove%%" ;; ;; FLAG -- maybe can get rid of binaries and need to call (the compile-and-load) ;; :components ,(mapcar #'(lambda(binary source) (let ((binary (make-pathname :directory (remove "bin" (pathname-directory binary) :test #'string-equal) :defaults binary))) (let ((namestring (replace-substring (namestring (make-pathname :name (pathname-name binary) :type nil ;;(pathname-type source) :defaults (enough-namestring binary (the ppathname)))) "\\" "/"))) (list (if (string-equal (pathname-type source) "lisp") :file (make-keyword (pathname-type source))) namestring) #+nil (list :file namestring :pathname (merge-pathnames namestring ""))))) binaries (the source-file-list))))) :uncached) (source-file-list (apply #'append (list-elements (the source-files) (the-element pathname)) (mapcar #'(lambda(subdir) (the-object subdir source-file-list)) (list-elements (the subdirs))))) ) :objects ((source-files :type 'file :sequence (:size (length (getf (the file-computation relevant-files) :source))) :pathname (nth (the-child index) (getf (the file-computation relevant-files) :source)))) :hidden-objects ((subdir-computation :type 'subdir-computation :exclude-names (append (the :bin-subdir-names) (first (getf (the :type-mapping) :exercises))) :subdirs-unordered-in (the :subdirs-unordered) :subdirs-in (the :subdirs) :pathname (the :ppathname) :pass-down (:local-name :contents :type-mapping :parent-dir)) (file-computation :type 'file-computation :pass-down (:pathname :type-mapping :type-matches :contents :subdir-pathnames :source-files-to-ignore)) (subdirs-unordered :type (the :subdir-type) :sequence (:size (length (the :subdir-computation :subdir-pathnames-unordered))) :pathname (make-pathname :device (the :device) :directory (nth (the-child :index) (the :subdir-computation :subdir-pathnames-unordered))) :parameters (the :additional-parameters))) :functions ((write-asd-file () (with-open-file (out (the asd-file) :direction :output :if-exists :supersede :if-does-not-exist :create :external-format :utf-8) (let ((*print-right-margin* 70) (*print-case* :downcase)) (write-string (the encoding-line) out) (format out "~%") (dolist (line (the asdf-system-lines)) (write-string line out) (format out "~%")) (when (the additional-asd-code) (format out "~%~%") (pprint (the additional-asd-code) out)))) (the asd-file)) (compile-and-load (&key (create-fasl? (the :create-fasl?)) (package-file-ht (make-hash-table)) (dry-run? (the dry-run?))) (let ((list-of-binaries nil) (sources-found? (and (or (getf (the :type-matches) :source) (getf (the :type-matches) :tables)) (or (getf (the :relevant-files) :source) (getf (the :relevant-files) :tables)))) (packages-found? (the :package-files))) (when (or sources-found? packages-found?) (format *trace-output* "~&~%; CL-LITE is now processing: ~a...~%~%" (the :ppathname))) (when (and (not dry-run?) packages-found?) (mapc #'(lambda (file) (if (null (gethash file package-file-ht)) (progn (load file) (setf (gethash file package-file-ht) t)))) (the :package-files))) (dolist (subdir (list-elements (the :subdirs))) (let ((list (the-object subdir (:compile-and-load :package-file-ht package-file-ht :dry-run? dry-run?)))) (setq list-of-binaries (append list-of-binaries list)))) (when (getf (the :type-matches) :source) (dolist (file (getf (the :relevant-files) :source)) (let ((output-file (make-pathname :directory (the :binary-directory) :device (the :device) :name (pathname-name file) :type (the :fasl-type)))) (let ((output-date (when (probe-file output-file) (file-write-date output-file))) (file-date (file-write-date file))) (when (and (not dry-run?) (or (null output-date) (<= output-date file-date))) (compile-file file :output-file output-file)) (setq list-of-binaries (append list-of-binaries (list output-file))) (when (and (not dry-run?) (or (the :load-always?) (or (null output-date) (<= output-date file-date)))) (load output-file)))))) (when (getf (the :type-matches) :tables) (dolist (file (getf (the :relevant-files) :tables)) (let ((output-file (make-pathname :directory (the :binary-directory) :device (the :device) :name (pathname-name file) :type (the :fasl-type)))) (let ((output-date (file-write-date output-file)) (file-date (file-write-date file))) (when (or (null output-date) (<= output-date file-date)) (funcall (read-from-string "peruse-file") file :load nil :output-file output-file)) (setq list-of-binaries (append list-of-binaries (list output-file))) (when (or (the :load-always?) (or (null output-date) (<= output-date file-date))) (load output-file)))))) (if create-fasl? (let ((fasl-name (make-pathname :directory (the fasl-output-directory) :device (the fasl-output-device) :name (the fasl-output-name) :type (the fasl-output-type)))) (glisp:concatenate-fasls list-of-binaries fasl-name) (format *trace-output* "~%~%Created Fasl File: ~a~%~%" fasl-name) fasl-name ) list-of-binaries))))) (define-object file () :input-slots (pathname) :computed-slots ((strings-for-display (file-namestring (the pathname))))) (define-object file-computation () :input-slots (pathname type-mapping type-matches contents subdir-pathnames source-files-to-ignore) :computed-slots ((ordering-bias (glisp:sexpr-from-file (make-pathname :directory (pathname-directory (the :pathname)) :device (the :device) :name "file-ordering" :type "isc"))) ;; ;; FLAG -- read this info once in the parent directory object, not here for each file! ;; ;; FLAG -- convert to use read-isc-file function ;; ;; (ignore-list (glisp:sexpr-from-file (make-pathname :directory (pathname-directory (the :pathname)) :device (the :device) :name "ignore-list" :type "isc"))) (relevant-files (let (key) (mapcar #'(lambda (thing) (if (not (listp thing)) (setq key thing) (let ((ordered-pathnames (remove nil (mapcar #'(lambda (name) (find name (getf (the :relevant-files-unordered) key) :test #'string= :key #'pathname-name)) (the :ordering-bias))))) (remove-duplicates (append ordered-pathnames thing) :test #'equalp :from-end t)))) (the :relevant-files-unordered)))) (relevant-files-unordered (apply #'append (mapcar #'(lambda (key) (list key (when (getf (the :type-matches) key) (sort (remove-if #'(lambda (file) (and (eql key :source) (member (pathname-name file) (append (the :source-files-to-ignore) (the :ignore-list)) :test #'string=))) (remove-if-not #'(lambda (file) (member (pathname-type file) (second (getf (the :type-mapping) key)) :test #'string=)) (set-difference (the :contents) (the :subdir-pathnames)))) #'(lambda (x y) (string< (file-namestring x) (file-namestring y))))))) (ind-filter #'evenp (the :type-mapping))))))) (define-object subdir-computation () :input-slots (pathname local-name contents exclude-names subdirs-in subdirs-unordered-in type-mapping parent-dir) :computed-slots ( ;; ;; FLAG -- convert to use read-isc-file function. ;; (ordering-bias (glisp:sexpr-from-file (make-pathname :directory (pathname-directory (the :pathname)) :device (the :device) :name "system-ordering" :type "isc"))) (ignore-list (glisp:sexpr-from-file (make-pathname :directory (pathname-directory (the :pathname)) :device (the :device) :name "ignore-list" :type "isc"))) (subdir-pathnames-unordered (sort (set-difference (mapcar #'pathname-directory (remove-if-not #'glisp:file-directory-p (the :contents))) (the :exclude-names) :test #'(lambda (path name) (and (the :exclude-names) (string-equal name (lastcar path))))) #'string-lessp :key #'lastcar)) (subdir-pathnames (remove-if #'(lambda (pathname) (and (the :ignore-list) (member pathname (the :ignore-list) :test #'(lambda (path name) (string-equal name (lastcar path)))))) (remove-duplicates (append (mapcar #'(lambda (name) (append (pathname-directory (the :pathname)) (list name))) (the :ordering-bias)) (the :subdir-pathnames-unordered)) :from-end t :test #'equalp))) (type-matches (apply #'append (mapcar #'(lambda (key) (list key (member (the :local-name) (first (getf (the :type-mapping) key)) :test #'string=))) (ind-filter #'evenp (the :type-mapping))))))) (defun ind-filter (fn list) (let (result (count -1)) (dolist (elem list (nreverse result)) (when (funcall fn (incf count)) (push elem result)))))
32,162
Common Lisp
.lisp
641
32.597504
108
0.500691
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
00d523eef9ced6da836010687bb725f2dccb6c7cf93f938c62ada0f45f33f22e
36,048
[ -1 ]
36,049
zzinit.lisp
lisp-mirror_gendl/cl-lite/source/zzinit.lisp
;; ;; Copyright 2002-2011, 2012 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :cl-lite) (glisp:set-features *these-features*)
840
Common Lisp
.lisp
21
38.714286
70
0.75765
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
0583ac788811c59b04685f9e320874e898414b4ecadcc3786e8d38e2777577ed
36,049
[ -1 ]
36,050
initialize.lisp
lisp-mirror_gendl/cl-lite/source/initialize.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :cl-lite) (defun initialize ())
885
Common Lisp
.lisp
22
39
70
0.759861
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
74951376ea2b900bf3a94c7d2bd414698aeab2aa3245ff9350f96635ce8cbe75
36,050
[ -1 ]
36,051
parameters.lisp
lisp-mirror_gendl/cl-lite/source/parameters.lisp
;; ;; Copyright 2002, 2009 Genworks International and Genworks BV ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :cl-lite) (defparameter *these-features* (list :cl-lite))
931
Common Lisp
.lisp
22
40.954545
70
0.760221
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
03d76bc836b66c0776afb2340fd958bbb38d1a5554a40eae8942e16d3b1b98cb
36,051
[ -1 ]
36,052
zzinit.lisp
lisp-mirror_gendl/base/zzinit/source/zzinit.lisp
;; ;; Copyright 2002-2011, 2012 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gendl) (defparameter *these-features* (list :base)) (glisp:set-features *these-features*)
910
Common Lisp
.lisp
22
38.863636
71
0.739773
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
7fbd8668ed33194d31135cc9a0855ccebc12ad3af41c6120a313d59ab6425b84
36,052
[ -1 ]
36,053
initialize.lisp
lisp-mirror_gendl/base/zzinit/source/initialize.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defun initialize () (setq glisp:*gdl-program-home* (probe-file (glisp:executable-homedir-pathname))) (setq glisp:*gdl-home* (make-pathname :name nil :type nil :directory (butlast (pathname-directory glisp:*gdl-program-home*)) :defaults glisp:*gdl-program-home*)) (setq glisp:*gendl-home* glisp:*gdl-home*) (when (find-package :asdf) (funcall (read-from-string "asdf:initialize-output-translations"))) (setq *quicklisp-home* (or (when (and (find-package :ql) (boundp (read-from-string "ql:*quicklisp-home*")) (probe-file (symbol-value (read-from-string "ql:*quicklisp-home*")))) (symbol-value (read-from-string "ql:*quicklisp-home*"))) (probe-file (merge-pathnames "quicklisp/" glisp:*gendl-home*)) (probe-file (merge-pathnames "genworks/quicklisp/" glisp:*gendl-home*)) (when glisp:*genworks-source-home* (probe-file (merge-pathnames "quicklisp/" glisp:*genworks-source-home*))) (probe-file (merge-pathnames "genworks/quicklisp/dists/quicklisp/distinfo.txt" glisp:*gdl-home*)))) (when (and (find-package :ql) (boundp (read-from-string "ql:*quicklisp-home*")) (not (probe-file (symbol-value (read-from-string "ql:*quicklisp-home*"))))) (setf (symbol-value (read-from-string "ql:*quicklisp-home*")) *quicklisp-home*)) (pushnew (make-keyword (format nil "gendl-~a" *gendl-version*)) *features*) (glisp::set-genworks-source-home-if-known) (glisp::set-gendl-source-home-if-known) (glisp:set-default-float-format) (glisp:set-defpackage-behavior) (glisp:set-default-package) (glisp:set-window-titles))
2,469
Common Lisp
.lisp
49
46.959184
96
0.720582
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
a871df154a5322aeac0ff47db89a73ace25baf2c969c12a993821d0813214dd7
36,053
[ -1 ]
36,054
reference.lisp
lisp-mirror_gendl/base/macros/source/reference.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defmacro the (&rest reference-chain) "Lisp object. Sends the <tt>reference-chain</tt> to <tt>self</tt>, which typically means it is used within the context of a define-object where self is automatically lexically bound. :arguments (reference-chain \"(&rest). A spliced-in list of symbols naming messages, which can be slots or objects starting from <tt>self</tt>. For referring to elements of a quantified set, or for passing arguments to GDL functions which take arguments, use parentheses around the message name and enclose the quantified element index or function arguments after the message name.\") :example This example sends the <tt>length</tt> message to the ``zeroth'' element of the quantified set of arms contained in the body which is contained in the robot which is contained in self: <pre> (the robot body (arms 0) length) </pre>" `(the-object self ,@reference-chain)) (defmacro the-object (object &rest reference-chain) "Lisp object. Sends the <tt>reference-chain</tt> to <tt>object</tt>, which must be specified as a Lisp expression (e.g. a variable) which evaluates to a GDL object. :arguments (reference-chain \"(&rest). A spliced-in list of symbols naming messages, which can be slots or objects starting from <tt>object</tt>. For referring to elements of a quantified set, or for passing arguments to GDL functions which take arguments, use parentheses around the message name and enclose the quantified element index or function arguments after the message name.\") :example This example sends the <tt>length</tt> message to the ``zeroth'' element of the quantified set of arms contained in the body which is contained in the robot which is contained in <tt>object</tt>: <pre> (the-object object robot body (arms 0) length) </pre>" (if reference-chain (let ((first (first reference-chain)) evaluate? apply?) (let ((message (cond ((atom first) (glisp:intern (symbol-name first) :gdl-slots)) ((and (symbolp (first first)) (not (eql (first first) 'evaluate))) (glisp:intern (symbol-name (first first)) :gdl-slots)) ((eql (first first) 'evaluate) (setq evaluate? t) (second first)) ((and (consp (first first)) (eql (first (first first)) 'evaluate)) (setq evaluate? t) (second (first first))))) (args (cond ((and (listp first) (eql (first first) 'evaluate)) nil) ((and (listp first) (listp (first (rest first))) (eql (first (first (rest first))) :apply)) (setq apply? t)(second (first (rest first)))) ((listp first) (rest first)))) ;;(new-object (gensym)) (new-object '+new-object+) ) `(the-object ,(if *undeclared-parameters-enabled?* (if evaluate? `(if (fboundp (glisp:intern (symbol-name ,message) :gdl-slots)) (funcall (symbol-function (glisp:intern (symbol-name ,message) :gdl-slots)) ,object ,@args) (let ((,new-object (getf (gdl-slots::%parameters% ,object) (make-keyword ,message) 'gdl-rule:%not-handled%))) (if (eql ,new-object 'gdl-rule:%not-handled%) (not-handled-error ,object ',message ',args) ,new-object))) `(if (fboundp ',message) (,message ,object ,@args) (let ((,new-object (getf (gdl-slots::%parameters% ,object) ,(make-keyword message) 'gdl-rule:%not-handled%))) (if (eql ,new-object 'gdl-rule:%not-handled%) (not-handled-error ,object ',message ',args) ,new-object)))) (cond ((and evaluate? apply?) `(apply (symbol-function (glisp:intern (symbol-name ,message) :gdl-slots)) ,object ,args)) (evaluate? `(funcall (symbol-function (glisp:intern (symbol-name ,message) :gdl-slots)) ,object ,@args)) (apply? `(apply ',message ,object ,args)) (t `(,message ,object ,@args)))) ,@(rest reference-chain)))) object)) (defmacro theo (object &rest reference-chain) `(the-object ,object ,@reference-chain)) (defmacro the-child (&rest reference-chain) "similar to ``the,'' but used to refer to the child part from within an :objects or :hidden-objects specification. This is often used for sending the <tt>index</tt> message to an element of a quantified set. :arguments (reference-chain \"(&rest). A spliced-in list of symbols naming messages relative to the child object.\")" `(the-object child ,@reference-chain)) (defun not-handled-error (object message &optional args) (if (the-object object root?) (error "~s, which is the root object, could not handle the ~s message~a." object (make-keyword message) (if args (format nil "~%with args: ~s " args) "")) (error "Neither ~s nor any of its ancestor instances could handle the ~s message~a The path to the containing object is: ~s" object (make-keyword message) (if args (format nil "~%with args: ~s " args) "") (append '(the :root) (symbols-as-keywords (reverse (the-object object :root-path))))))) (defmacro with-format ((format stream-or-file &rest args) &body body) "Void [Macro]. Used to establish an output format and a stream to which data is to be sent. This is the experimental new version of the <tt>with-format</tt> macro, which supports a full range of output options such as page dimensions, view transforms, view scales, etc. :example <pre> (gdl::with-format (pdf \"/tmp/box.pdf\" :view-transform (getf *standard-views* :trimetric)) (write-the-object (make-instance 'box :length 100 :width 100 :height 100) cad-output)) </pre>" (let (;;(flag (gensym)) (flag '+flag+) ) `(let ((*%format%* (make-instance ',format ,@args))) (let ((*stream* (if (or (stringp ,stream-or-file) (pathnamep ,stream-or-file)) (open ,stream-or-file :if-does-not-exist (or (format-slot if-does-not-exist) :create) :if-exists (or (format-slot if-exists) :error) :direction (or (format-slot direction) :output) :external-format (format-slot external-format) :element-type (format-slot element-type)) ,stream-or-file)) (,flag t)) (unwind-protect (progn (multiple-value-prog1 ,(case format ;; ;; NOTE -- most interesting formats are currently ;; folded in with the geom modules. ;; (otherwise `(progn ,@body))) (setq ,flag nil))) (when (and (or (stringp ,stream-or-file) (pathnamep ,stream-or-file)) (streamp *stream*)) (close *stream* :abort ,flag))) nil)))) (defmacro write-env (&rest method-calls) "Void [Macro] (usually used just for outputting). Within the context of a <tt>with-format</tt>, calls functions of the format object, optionally with arguments. Typically these functions will output data to the <tt>stream</tt> established by the <tt>with-format</tt>. :arguments (function-calls \"(&rest). Functions on the named output-format to be called.\") :example <pre> (with-format (base-format my-object) (write-env (:a \"Hello World, my object's length is: \") (:a (the length)))) </pre>" `(progn ,@(mapcar #'(lambda(method-call) (typecase method-call (string `(write-string ,method-call *stream*)) (otherwise (if (atom (first method-call)) `(,(glisp:intern (symbol-name (first method-call)) :gdl-format) *%format%* ,@(rest method-call)) `(funcall (glisp:intern (symbol-name (apply (function ,(first (first method-call))) ',(rest (first method-call)))) :gdl-format) *%format%* ,@(rest method-call)))))) method-calls))) #+nil (defmacro write-env (&rest method-calls) "Void [Macro] (usually used just for outputting). Within the context of a <tt>with-format</tt>, calls functions of the format object, optionally with arguments. Typically these functions will output data to the <tt>stream</tt> established by the <tt>with-format</tt>. :arguments (function-calls \"(&rest). Functions on the named output-format to be called.\") :example <pre> (with-format (base-format my-object) (write-env (:a \"Hello World, my object's length is: \") (:a (the length)))) </pre>" `(progn ,@(mapcar #'(lambda(method-call) (typecase method-call (string `(write-string ,method-call *stream*)) (otherwise `(,(glisp:intern (symbol-name (first method-call)) :gdl-format) *%format%* ,@(rest method-call))))) method-calls))) (defmacro write-the (&rest args) "Lisp object [Macro]. Typcially used only to send output, not for the return value. This macro is used within the body of a <tt>with-format</tt>. It sends the <tt>reference-chain</tt> to <tt>self</tt>, which typically means it is used within the context of a define-object where self is automatically lexically bound. The reference-chain must terminate with an output-function defined for the combination of the output-format specified in the enclosing <tt>with-format</tt>, and the object identified by <tt>self</tt>. :arguments (reference-chain \"(&rest). A spliced-in list of symbols naming messages, which can be slots or objects starting from <tt>self</tt>, terminating with the name of an output-function. For referring to elements of a quantified set, or for passing arguments to GDL functions which take arguments, use parentheses around the message name and enclose the quantified element index or function arguments after the message name.\")" `(write-the-object self ,@args)) (defmacro write-the-object (object &rest reference-chain) "Lisp object [Macro]. Typcially used only to send output, not for the return value. This macro is used within the body of a <tt>with-format</tt>. It sends the <tt>reference-chain</tt> to <tt>object</tt>, which must be specified as a Lisp expression (e.g. a variable) which evaluates to a GDL object. The reference-chain must terminate with an output-function defined for the combination of the output-format specified in the enclosing <tt>with-format</tt>, and the object identified by <tt>object</tt>. :arguments (reference-chain \"(&rest). A spliced-in list of symbols naming messages, which can be slots or objects starting from <tt>object</tt>, terminating with the name of an output-function. For referring to elements of a quantified set, or for passing arguments to GDL functions which take arguments, use parentheses around the message name and enclose the quantified element index or function arguments after the message name.\")" (when (null reference-chain) (error "write-the-object must be given at least one item after the object")) (let* ((last (ensure-list (lastcar reference-chain))) (butlast (butlast reference-chain)) (message (glisp:intern (symbol-name (first last)) :gdl-output)) (args (rest last))) `(,message *%format%* (the-object ,object ,@butlast) *skin* ,@args))) (defparameter *skin* t) (defmacro format-slot (slot-name) "Lisp object [Macro]. Returns the value of the given slot within the context of the current <tt>with-format</tt> output format object. :arguments (slot-name \"Symbol.\")" `(slot-value *%format%* ',(glisp:intern (symbol-name slot-name) :gdl-acc))) (defmacro set-format-slot (slot-name value) "Void [Macro]. Sets the value of the given slot within the context of the current <tt>with-format</tt> output format object. :arguments (slot-name \"Symbol.\" value \"Lisp Value\")" `(setf (slot-value *%format%* ',(glisp:intern (symbol-name slot-name) :gdl-acc)) ,value)) (defmacro with-format-slots ((&rest slots) &body body) "Void [Macro]. Wrap this around a body of code which should have access to multiple slots from the context of the current <tt>with-format</tt> output format object. :arguments (slots \"List of Symbols.\")" `(let (,@(mapcar #'(lambda(slot) `(,slot (format-slot ,slot))) slots)) ,@body))
14,474
Common Lisp
.lisp
235
49.438298
129
0.615784
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
d48b2c412f35590c11ecb95bb0239778f2458ad781f32dbba280b841964c6549
36,054
[ -1 ]
36,055
defaulting.lisp
lisp-mirror_gendl/base/macros/source/defaulting.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defmacro defaulting (form &optional default) "Lisp object. Returns a default value if the reference-chain is not handled. :arguments (form \"Reference-chain with the or the-object\" default \"Lisp expression. Default value to return if reference-chain cannot be handled.\")" (let ((value '+value+ #+nil (gensym)) (error '+error+ #+nil (gensym))) `(multiple-value-bind (,value ,error) (ignore-errors ,form) (cond ((and ,error (typep ,error 'error) (let ((string (glisp:replace-regexp (format nil "~a" ,error) (format nil "~%") " "))) (or (and (search "attempt to call" string) (search "gdl-slots::" string)) (search "nor any of its ancestor instances could handle the" string) (search "which is the root object, could not handle the" string)))) ,default) ((typep ,error 'error) (error ,error)) (t ,value)))))
1,867
Common Lisp
.lisp
36
45.194444
104
0.663181
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
c0b38fa3095e440e99790246496c4203be2abea576777cea2e09c12c6d90256e
36,055
[ -1 ]
36,056
define-format.lisp
lisp-mirror_gendl/base/macros/source/define-format.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defmacro define-format (name mixin-list &key slots functions documentation) "Standard-class [Macro]. Defines a standard GDL output format for use with GDL views. :arguments (name \"Symbol.\" mixin-list \"List of symbols.\") :&key (documentation \"Plist containing keys and strings for author, description, etc.\" slots \"List of lists or symbols. If a list, the list should contain a symbol, a default value, and optionally a documentation string. If a symbol, this is the name of the slot and there will be no default value.\" functions \"List of format-function definitions. Each definition is made up of a symbol, an argument-list, and a body.\")" (let (;;(old-format-functions (gensym)) ;;(new-format-functions (gensym)) ;;(class (gensym)) (old-format-functions '+old-format-functions+) (new-format-functions '+new-format-functions+) (class '+class+) ) `(progn (defclass ,name ,mixin-list ,(mapcar #'(lambda(slot) (if (atom slot) `(,(glisp:intern (symbol-name slot) :gdl-acc) :initarg ,(make-keyword slot)) `(,(glisp:intern (symbol-name (first slot)) :gdl-acc) :initform ,(second slot) :initarg ,(make-keyword (first slot)) :documentation ,(or (third slot) "")))) slots) (:metaclass gdl-format-class)) (let ((,class (find-class ',name))) (let ((,old-format-functions (format-functions ,class)) (,new-format-functions ',(mapcar #'first-symbol (remove nil functions)))) (dolist (key (set-difference ,old-format-functions ,new-format-functions)) (let ((method (ignore-errors (find-method (symbol-function (glisp:intern (symbol-name key) :gdl-format)) nil (list (find-class ',name)) nil)))) (when method (format t "~%Removing format function: ~a for format definition: ~s~%" key ',name) (remove-method (symbol-function (glisp:intern (symbol-name key) :gdl-format)) method)))) (setf (format-functions ,class) ,new-format-functions) (setf (gdl-documentation ,class) ',documentation))) ,@(format-functions-section name (remove nil functions)) (find-class ',name) ))) (defun format-functions-section (name methods) (mapcar #'(lambda(method) (let* ((attr-sym (first method)) (lambda-list (second method)) (body (rest (rest method)))) `(defmethod ,(glisp:intern (symbol-name attr-sym) :gdl-format) ((format ,name) &rest ,args-arg) (apply #'(lambda ,lambda-list ,@body) ,args-arg)))) methods)) (defmacro define-lens (format-and-object mixin-lists &key (skin t) output-functions amend? documentation) "Void [Macro]. Defines output-functions for the combination of the given output-format and GDL object. :arguments (format-and-object \"List of two symbols. The first should name an output-format previously defined with <tt>define-format</tt>, and the second should name a GDL object previously defined with <tt>define-object</tt>.\" mixin-list \"NIL. This is not supported and should be left as NIL or an empty list for now.\") :&key ((skin t) \"Name of a skin defined with define-skin. This allows a class hierarchy of look and feel for each view combination. Defaults to T, a generic skin.\") (output-functions \"List of format-function definitions. Each definition is made up of a symbol, an argument-list, and a body. The code in the body may refer to the dynamically bound variable <tt>stream</tt> for writing output.\")" (declare (ignore mixin-lists)) ;; FLAG -- might use mixins for new derived (name-mangled) class for holding attributes ;; ;; FLAG -- include skin in keeping track of function names ;; (let (;;(old-output-functions (gensym)) ;;(new-output-functions (gensym)) ;;(format-class (gensym)) ;;(object-class (gensym)) ;;(skin-class (gensym)) (old-output-functions '+old-output-functions+) (new-output-functions '+new-output-functions+) (format-class '+format-class+) (object-class '+object-class+) (skin-class '+skin-class+) (remote? (or (eql (second format-and-object) 'remote-object) (eql (second format-and-object) 'gdl-remote)))) `(progn (let ((,format-class (find-class ',(first format-and-object))) (,object-class (find-class ',(second format-and-object))) (,skin-class (find-class ',skin))) (let ((,old-output-functions (let ((ht (gethash ,object-class (output-functions ,format-class)))) (when ht (gethash ,skin-class ht)))) (,new-output-functions ',(mapcar #'first-symbol (remove nil output-functions)))) ,(when (not (or amend? remote?)) `(dolist (key (set-difference ,old-output-functions ,new-output-functions)) (let ((method (ignore-errors (find-method (symbol-function (glisp:intern (symbol-name key) :gdl-output)) nil (list (find-class ',(first format-and-object)) (find-class ',(second format-and-object)) (find-class ',skin)) nil)))) (when method (format t " Removing output function: ~a for view of format: ~a on object definition: ~s with skin: ~s~%" key ',(first format-and-object) ',(second format-and-object) ',skin) (remove-method (symbol-function (glisp:intern (symbol-name key) :gdl-output)) method))))) (let ((current (gethash ,object-class (output-functions ,format-class)))) (unless current (setf (gethash ,object-class (output-functions ,format-class)) (make-hash-table)))) (setf (gethash ,skin-class (gethash ,object-class (output-functions ,format-class))) ,(if amend? `(remove-duplicates (append ,old-output-functions ,new-output-functions)) new-output-functions)) (let ((current (gethash ,object-class (view-documentation ,format-class)))) (unless current (setf (gethash ,object-class (view-documentation ,format-class)) (make-hash-table)))) (setf (gethash ,skin-class (gethash ,object-class (view-documentation ,format-class))) ',documentation))) ,@(view-output-functions-section (first format-and-object) (second format-and-object) skin (remove nil output-functions) :remote? remote?)))) (defmacro define-view (&rest args) (warn "The name define-view is deprecated, please use define-lens instead.") `(define-lens ,@args)) (defun view-output-functions-section (format object-type-name skin format-functions &key remote?) ;; ;; FLAG -- consider reversing the order of args format and object-type ;; (mapcar #'(lambda(function) (view-output-function format object-type-name skin function :remote? remote?)) format-functions)) (defun view-output-function (format object-type-name skin function &key remote?) (let* ((attr-remarks (message-strings function)) (attr-sym (glisp:intern (symbol-name (message-symbol function)) :gdl-output)) (lambda-list (second (strip-strings function))) (body (rest (rest (strip-strings function)))) (has-declare? (and (consp body) (consp (first body)) (eql (first (first body)) 'declare)))) (let (;;(method (gensym)) (method '+method+)) ;; ;; FLAG -- do we need this `remove nil' ? ;; (remove nil `(let ((,method (defmethod ,attr-sym ((format ,format) (self ,object-type-name) (skin ,skin) &rest ,args-arg) ,(when (and *compile-documentation-database?* attr-remarks) attr-remarks) (apply #'(lambda ,lambda-list ,(if has-declare? (first body) `(declare)) (block ,(make-keyword attr-sym) ,@(if has-declare? (rest body) body))) ,args-arg)))) (declare (ignorable ,method)) (eval-when (:compile-toplevel :load-toplevel :execute) (glisp:begin-redefinitions-ok)) ,(when (and *compile-for-dgdl?* (not remote?)) `(defmethod ,attr-sym ((format ,format) (self gdl-remote) (skin ,skin) &rest ,args-arg) ,(when (and *compile-documentation-database?* attr-remarks) attr-remarks) (funcall #'(lambda (&rest ,args-arg) ,(if has-declare? (first body) `(declare)) (block ,(make-keyword attr-sym) (the (send-output (:apply (cons ,(make-keyword attr-sym) (cons *%format%* ,args-arg)))))))))) (eval-when (:compile-toplevel :load-toplevel :execute) (glisp:end-redefinitions-ok)) ;; ;; FLAG -- implement this documentation properly and according to ANSI stanards. ;; #-clisp ,(when (and *compile-documentation-database?* attr-remarks) `(when *load-documentation-database?* (setf (documentation ,method nil) ,attr-remarks)))))))) (defmacro define-skin (name &optional mixins slots) `(defclass ,name ,mixins ,slots (:metaclass gdl-skin-class))) (defmacro defcompanion (&rest args) (declare (ignore args)) (error "The Defcompanion translator is not loaded. Please load it with (require :defpart) and try compiling this code again. Also please see the file defpart.txt in the GDL documentation set for information on using the translator to convert legacy icad-style code."))
11,122
Common Lisp
.lisp
178
49.988764
167
0.610921
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
9102f4894a82b35f3b495b6c2a071b947b165283556065d7707d71aca956ac86
36,056
[ -1 ]
36,057
functions.lisp
lisp-mirror_gendl/base/expanders/source/functions.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defun functions-section (name functions) (mapcar #'(lambda(function) (let ((second (second (strip-strings function)))) (etypecase second (list (uncached-function name function)) (keyword (ecase second ((:cached :cached-equalp) (cached-function name function :test 'equalp)) (:cached-= (cached-function name function :test '=)) (:cached-eq (cached-function name function :test 'eq)) (:cached-eql (cached-function name function :test 'eql)) (:cached-equal (cached-function name function :test 'equal))))))) functions)) (defun uncached-function (name function) (let* ((attr-remarks (message-strings function)) (attr-sym (glisp:intern (symbol-name (message-symbol function)) :gdl-acc)) (lambda-list (second (strip-strings function))) (body (rest (rest (strip-strings function)))) (has-declare? (and (consp body) (consp (first body)) (eql (first (first body)) 'declare)))) `(progn ,@(remove nil (list (when (and *compile-documentation-database?* attr-remarks) `(when *load-documentation-database?* (let ((ht (or (message-documentation (find-class ',name)) (setf (message-documentation (find-class ',name)) (make-hash-table))))) (setf (gethash (make-keyword ',attr-sym) ht) ,attr-remarks)))) (when *compile-source-code-database?* `(when *load-source-code-database?* (let ((ht (or (message-source (find-class ',name)) (setf (message-source (find-class ',name)) (make-hash-table))))) (setf (gethash (make-keyword ',attr-sym) ht) ',(cons lambda-list body))))) `(defmethod ,(glisp:intern (symbol-name attr-sym) :gdl-slots) ((self ,name) &rest ,args-arg) (apply #'(lambda ,lambda-list ,(if has-declare? (first body) `(declare)) ,(when *compile-circular-reference-detection?* `(when (and *run-with-circular-reference-detection?* (member (list self ',attr-sym) *till-now* :test #'equalp)) (error "Circular reference detected"))) (let ,(remove nil (list (when *compile-circular-reference-detection?* `(*till-now* (when *run-with-circular-reference-detection?* (cons (list self ',attr-sym) *till-now*)))))) (block ,(make-keyword attr-sym) (let ((*error-on-not-handled?* t)) ,@(if has-declare? (rest body) body))))) ,args-arg)) (when (and *compile-for-dgdl?* (not (string-equal (symbol-name name) "remote-object"))) `(when (or (not (fboundp ',(glisp:intern attr-sym :gdl-slots))) (not (find-method (symbol-function ',(glisp:intern attr-sym :gdl-slots)) nil (list (find-class 'gdl-remote)) nil))) (defmethod ,(glisp:intern attr-sym :gdl-slots) ((,self-arg gdl-remote) &rest ,args-arg) (the-object ,self-arg (send (:apply (cons ,(make-keyword (symbol-name attr-sym)) ,args-arg))))))) ;; ;; FLAG -- why is this needed?? ;; `(when (or (not (fboundp ',(glisp:intern (symbol-name attr-sym) :gdl-slots))) (not (find-method (symbol-function ',(glisp:intern (symbol-name attr-sym) :gdl-slots)) nil (list (find-class 'gdl-basis)) nil))) (defmethod ,(glisp:intern (symbol-name attr-sym) :gdl-slots) ((,self-arg gdl-basis) &rest ,args-arg) ;;(declare (ignore ,args-arg)) (let ((,parent-arg (the-object ,self-arg %parent%))) (if (or (null ,parent-arg) ,args-arg) (not-handled ,self-arg ,(make-keyword attr-sym) ,args-arg) (,(glisp:intern (symbol-name attr-sym) :gdl-inputs) ,parent-arg (the-object ,self-arg :%name%) ,self-arg)))))))))) (defun cached-function (name function &key (test #'eql)) (let* ((attr-remarks (message-strings function)) (attr-sym (glisp:intern (symbol-name (message-symbol function)) :gdl-acc)) (lambda-list (third (strip-strings function))) (body (rest (rest (rest (strip-strings function))))) (has-declare? (and (consp body) (consp (first body)) (eql (first (first body)) 'declare)))) `(progn ,@(remove nil (list (when (and *compile-documentation-database?* attr-remarks) `(when *load-documentation-database?* (let ((ht (or (message-documentation (find-class ',name)) (setf (message-documentation (find-class ',name)) (make-hash-table))))) (setf (gethash (make-keyword ',attr-sym) ht) ,attr-remarks)))) (when *compile-source-code-database?* `(when *load-source-code-database?* (let ((ht (or (message-source (find-class ',name)) (setf (message-source (find-class ',name)) (make-hash-table))))) (setf (gethash (make-keyword ',attr-sym) ht) ',(cons lambda-list body))))) ;; ;; FLAG -- keep up-to-date to correspond to standard with-dependency-tracking macro ;; ;; add checks for *root-checking-enabled?* ;; (let ((value '+value+ #+nil (gensym))) `(defmethod ,(glisp:intern (symbol-name attr-sym) :gdl-slots) ((self ,name) &rest ,args-arg) (let ((,value (,attr-sym self))) (if (not (eq (first (ensure-list ,value)) 'gdl-rule::%unbound%)) (when (and *run-with-dependency-tracking?* *notify-cons*) (add-notify-cons *notify-cons* ,value)) (setq ,value (setf (,attr-sym self) (list (make-hash-table :test ',test) (when (and *run-with-dependency-tracking?* *notify-cons*) (list (copy-list *notify-cons*))))))) (or (gethash ,(ecase test ((eql eq =) `(first ,args-arg)) ((equalp equal) `,args-arg)) (first ,value)) (setf (gethash ,(ecase test ((eql eq =) `(first ,args-arg)) ((equalp equal) `,args-arg)) (first ,value)) (let (,(remove nil (when *compile-dependency-tracking?* `(*notify-cons* (when *run-with-dependency-tracking?* (list self ',attr-sym)))))) (apply #'(lambda ,lambda-list ,(if has-declare? (first body) `(declare)) (block ,(make-keyword attr-sym) (let ((*error-on-not-handled?* t)) ,@(if has-declare? (rest body) body)))) ,args-arg))))))))))))
8,876
Common Lisp
.lisp
142
42.683099
127
0.502626
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
edd4d9f9fc35c7a1c36b2d7ac1241c14af93ddad79430afe30c8deaa4992b5a5
36,057
[ -1 ]
36,058
methods.lisp
lisp-mirror_gendl/base/expanders/source/methods.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defun methods-section (name methods) (mapcar #'(lambda(method) (let ((second (second (strip-strings method)))) (etypecase second (list (uncached-method name method)) (keyword (ecase second ((:cached :cached-equalp) (cached-method name method :test 'equalp)) (:cached-= (cached-method name method :test '=)) (:cached-eq (cached-method name method :test 'eq)) (:cached-eql (cached-method name method :test 'eql)) (:cached-equal (cached-method name method :test 'equal))))))) methods)) (defun uncached-method (name method) (let* ((attr-remarks (message-strings method)) (attr-sym (glisp:intern (symbol-name (message-symbol method)) :gdl-acc)) (lambda-list (second (strip-strings method))) (body (rest (rest (strip-strings method)))) (has-declare? (and (consp body) (consp (first body)) (eql (first (first body)) 'declare)))) `(progn ,@(remove nil (list (when (and *compile-documentation-database?* attr-remarks) `(when *load-documentation-database?* (let ((ht (or (message-documentation (find-class ',name)) (setf (message-documentation (find-class ',name)) (make-hash-table))))) (setf (gethash (make-keyword ',attr-sym) ht) ,attr-remarks)))) (when *compile-source-code-database?* `(when *load-source-code-database?* (let ((ht (or (message-source (find-class ',name)) (setf (message-source (find-class ',name)) (make-hash-table))))) (setf (gethash (make-keyword ',attr-sym) ht) ',(cons lambda-list body))))) ;; ;; FLAG -- put this in when we know how to derive generic-function lambda-list from the lambda-list. ;; ;; FLAG -- use extract-lambda-list from glisp (make one) or c2mop package of :closer-mop. ;; #+nil `(eval-when (:compile-toplevel :load-toplevel :execute) (unless (fboundp ',(glisp:intern attr-sym :gdl-slots)) (defgeneric ,(glisp:intern attr-sym :gdl-slots) (,self-arg ,@lambda-list)))) `(defmethod ,(glisp:intern attr-sym :gdl-slots) ((self ,name) ,@lambda-list) ,(if has-declare? (first body) `(declare)) ,(when *compile-circular-reference-detection?* `(when (and *run-with-circular-reference-detection?* (member (list self ',attr-sym) *till-now* :test #'equalp)) (error "Circular reference detected"))) (let ,(remove nil (list (when *compile-circular-reference-detection?* `(*till-now* (when *run-with-circular-reference-detection?* (cons (list self ',attr-sym) *till-now*)))))) (block ,(make-keyword attr-sym) ,@(if has-declare? (rest body) body))) )))))) (defun cached-method (name method &key (test #'eql)) (declare (ignore name method test)) (error "Cached methods not yet supported"))
4,339
Common Lisp
.lisp
80
41.0375
106
0.579011
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
8fb2edabee70dbe0ee1c64f41c021c1fc3ea2f597ed4cc7681eeb59a1bd1fd85
36,058
[ -1 ]
36,059
computed-slots.lisp
lisp-mirror_gendl/base/expanders/source/computed-slots.lisp
;; ;; Copyright 2002-2012 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defparameter *trickle-down-basis-method-hash* (make-hash-table)) (defun message-generics (messages) `((eval-when (:compile-toplevel :load-toplevel :execute) ,@(append (mapcar #'(lambda(message) `(unless (fboundp ',(glisp:intern message :gdl-slots)) (defgeneric ,(glisp:intern message :gdl-slots) (,self-arg &rest ,args-arg)))) messages) (mapcar #'(lambda(message) `(unless (fboundp ',(glisp:intern message :gdl-inputs)) (defgeneric ,(glisp:intern message :gdl-inputs) (,parent-arg ,val-arg ,self-arg)))) messages))) ,@(mapcar #'(lambda(message) `(unless (find-method (symbol-function ',(glisp:intern message :gdl-inputs)) nil (list (find-class 'gdl-basis) (find-class t) (find-class 'gdl-basis)) nil) (defmethod ,(glisp:intern message :gdl-inputs) ((,parent-arg gdl-basis) ,part-arg (,self-arg gdl-basis)) (declare (ignore ,part-arg)) (gdl-rule::lookup-parameters ,self-arg ,(make-keyword message))))) messages))) (eval-when (:compile-toplevel :load-toplevel :execute) (defpackage :iq (:use) (:export #:qlet))) (eval-when (:compile-toplevel :load-toplevel :execute) (defmacro iq:qlet ((&rest args) &rest body) (declare (ignore args body)) (error "Query-attributes are not supported in this Gendl distribution.~%"))) (defun computed-slots-section (name computed-slots &key query?) (mapcan #'(lambda(attribute) (let ((attr-remarks (message-strings attribute)) (attr-sym (intern (symbol-name (message-symbol attribute)) :gdl-acc)) (attr-expr (message-source-code attribute))) (remove nil (list (when (and name *compile-documentation-database?* attr-remarks) `(when *load-documentation-database?* (let ((ht (or (message-documentation (find-class ',name)) (setf (message-documentation (find-class ',name)) (make-hash-table))))) (setf (gethash (make-keyword ',attr-sym) ht) ,attr-remarks)))) (when (and name *compile-source-code-database?*) `(when *load-source-code-database?* (let ((ht (or (message-source (find-class ',name)) (setf (message-source (find-class ',name)) (make-hash-table))))) (setf (gethash (make-keyword ',attr-sym) ht) ',attr-expr)))) (when name `(defmethod ,(glisp:intern (symbol-name attr-sym) :gdl-slots) ((self ,name) &rest ,args-arg) (declare (ignore ,args-arg)) (let ((*error-on-not-handled?* t)) (with-dependency-tracking (,attr-sym) ,(if query? `(iq:qlet (()) ,attr-expr) attr-expr)) #+nil (with-dependency-tracking (,attr-sym) ,(if query? (error "Query-slots are not supported in this distribution of Genworks GDL.") attr-expr))))) (when (and *compile-for-dgdl?* (not (string-equal (symbol-name name) "remote-object"))) `(when (or (not (fboundp ',(glisp:intern attr-sym :gdl-slots))) (not (find-method (symbol-function ',(glisp:intern attr-sym :gdl-slots)) nil (list (find-class 'gdl-remote)) nil))) (defmethod ,(glisp:intern attr-sym :gdl-slots) ((,self-arg gdl-remote) &rest ,args-arg) (the-object ,self-arg (send (:apply (cons ,(make-keyword (symbol-name attr-sym)) ,args-arg))))))) `(unless (find-method (symbol-function ',(glisp:intern (symbol-name attr-sym) :gdl-slots)) nil (list (find-class 'gdl-basis)) nil) (defmethod ,(glisp:intern (symbol-name attr-sym) :gdl-slots) ((,self-arg gdl-basis) &rest ,args-arg) ;;(declare (ignore ,args-arg)) (let ((,parent-arg (the-object ,self-arg %parent%))) (if (or (null ,parent-arg) ,args-arg) (not-handled ,self-arg ,(make-keyword attr-sym) ,args-arg) (let ((,val-arg (let (*error-on-not-handled?*) (,(glisp:intern (symbol-name attr-sym) :gdl-inputs) ,parent-arg (the-object ,self-arg :%name%) ,self-arg)))) (if (eql ,val-arg 'gdl-rule:%not-handled%) (not-handled ,self-arg ,(make-keyword attr-sym) ,args-arg) ,val-arg)))))))))) computed-slots)) ;; ;; FLAG -- this can be made much shorter for all but the slots which ;; are only declared as trickle-downs and not otherwise declared (a ;; rare situation). ;; (defun trickle-down-slots-section (slots &key from-objects?) (mapcan #'(lambda(slot) (remove nil (list (unless from-objects? ;; ;; FLAG -- duplicated from objects.lisp, inputs.lisp, functions.lisp, and above in this file. ;; ;; FLAG -- this must be get-riddable. Test carefully because trickle-downs are relatively rare. ;; ;; FLAG -- maybe don't remove, could have a trickle-down which is not otherwise declared as a message. `(unless (and (fboundp ',(glisp:intern (symbol-name slot) :gdl-inputs)) (find-method (symbol-function ',(glisp:intern (symbol-name slot) :gdl-inputs)) nil (list (find-class 'gdl-basis) (find-class t) (find-class 'gdl-basis)) nil)) (defmethod ,(glisp:intern (symbol-name slot) :gdl-inputs) ((,parent-arg gdl-basis) ,part-arg (,self-arg gdl-basis)) (declare (ignore ,part-arg)) (let ((,val-arg (getf (the-object ,self-arg %parameters%) ,(make-keyword (symbol-name slot)) 'gdl-rule:%not-handled%))) (if (eql ,val-arg 'gdl-rule:%not-handled%) (not-handled ,parent-arg ,(make-keyword slot)) ,val-arg))))) ;; ;; FLAG -- collect all the trickle-downs and group this at the top in the one eval-when. ;; `(eval-when (:compile-toplevel :load-toplevel :execute) ,@(remove nil `((unless (fboundp ',(glisp:intern (symbol-name slot) :gdl-trickle-downs)) (defgeneric ,(glisp:intern (symbol-name slot) :gdl-trickle-downs) (,self-arg &rest ,args-arg))) ,(unless from-objects? `(unless (fboundp ',(glisp:intern (symbol-name slot) :gdl-slots)) (defgeneric ,(glisp:intern (symbol-name slot) :gdl-slots) (,self-arg &rest ,args-arg))))))) `(unless (find-method (symbol-function ',(glisp:intern (symbol-name slot) :gdl-trickle-downs)) nil (list (find-class 'gdl-basis)) nil) (defmethod ,(glisp:intern (symbol-name slot) :gdl-trickle-downs) ((,self-arg gdl-basis) &rest ,args-arg) (trickle-down-basis ,self-arg ',slot ,args-arg))) ;; ;; FLAG -- we need to redefine the standard gdl-basis method here for trickle-down-slots, ;; figure out how to do it without the crude off/on of redefinition warnings. ;; ;;`(eval-when (:compile-toplevel :load-toplevel :execute) (glisp:begin-redefinitions-ok)) `(unless (gethash ',(glisp:intern (symbol-name slot) :gdl-slots) *trickle-down-basis-method-hash*) (defmethod ,(glisp:intern (symbol-name slot) :gdl-slots) ((,self-arg gdl-basis) &rest ,args-arg) (chase-up-trickle-down ',(glisp:intern (symbol-name slot) :gdl-slots) ,self-arg ,args-arg)) (setf (gethash ',(glisp:intern (symbol-name slot) :gdl-slots) *trickle-down-basis-method-hash*) t)) #+nil `(defmethod ,(glisp:intern (symbol-name slot) :gdl-slots) ((,self-arg gdl-basis) &rest ,args-arg) (chase-up-trickle-down ',(glisp:intern (symbol-name slot) :gdl-slots) ,self-arg ,args-arg)) #+nil `(unless (find-method (symbol-function ',(glisp:intern (symbol-name slot) :gdl-slots)) nil (list (find-class 'gdl-basis)) nil) (defmethod ,(glisp:intern (symbol-name slot) :gdl-slots) ((,self-arg gdl-basis) &rest ,args-arg) (chase-up-trickle-down ',(glisp:intern (symbol-name slot) :gdl-slots) ,self-arg ,args-arg))) ;;`(eval-when (:compile-toplevel :load-toplevel :execute) (glisp:end-redefinitions-ok)) ))) slots))
9,160
Common Lisp
.lisp
153
49.627451
146
0.613593
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
942310aca8b5d24a7fb4ffc6729ebd93ce5cd3d8987fa7dd5d6dc9f13fb31e34
36,059
[ -1 ]
36,060
inputs.lisp
lisp-mirror_gendl/base/expanders/source/inputs.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defun not-handled (object message &optional args) (if *error-on-not-handled?* (not-handled-error object message args) 'gdl-rule:%not-handled%)) (defun input-slots-generics (input-slots) (let ((input-slot-syms (mapcar #'(lambda(input) (glisp:intern (if (symbolp (first input)) (first input) (second input)) :gdl-inputs)) input-slots))) `(eval-when (:compile-toplevel :load-toplevel :execute) ,@(append (mapcar #'(lambda(input-sym) `(unless (fboundp ',input-sym) (defgeneric ,input-sym (,parent-arg ,val-arg ,self-arg)))) input-slot-syms))))) (defun input-methods (name attr-sym keys expressions special-keys) (let ((input '+input+ #+nil(gensym))) (let ((remove-defunct-expressions (list `(dolist (,input (set-difference (getf (child-inputs (find-class ',name)) ',attr-sym) ',keys)) (let ((method (find-method (symbol-function (glisp:intern (symbol-name ,input) :gdl-inputs)) nil (list (find-class ',name) (glisp:eql-specializer ',attr-sym) (find-class t)) nil))) (when method (remove-method (symbol-function (glisp:intern (symbol-name ,input) :gdl-inputs)) method) (format t "~%Removing object input ~a for object ~a of object definition ~s~%" ,input ',attr-sym ',name)))) `(setf (getf (child-inputs (find-class ',name)) ',attr-sym) (set-difference ',keys ',special-keys))))) (append remove-defunct-expressions (remove nil (mapcan #'(lambda(input expr) (when (not (member input special-keys)) (let ((input-sym (glisp:intern (symbol-name input) :gdl-acc))) (list `(defmethod ,(glisp:intern (symbol-name input-sym) :gdl-inputs) ((self ,name) (,part-arg (eql ',attr-sym)) (child t)) (let ((*error-on-not-handled?* t)) ,expr)))))) keys expressions)))))) (defun input-slots-section (name input-slots) (mapcan #'(lambda(input) (let* ((attr-sym (glisp:intern (symbol-name (if (symbolp input) input (message-symbol input))) :gdl-acc)) (attr-remarks (when (consp input) (message-strings input)))) (remove nil (list (when (and *compile-documentation-database?* attr-remarks) `(when *load-documentation-database?* (let ((ht (or (message-documentation (find-class ',name)) (setf (message-documentation (find-class ',name)) (make-hash-table))))) (setf (gethash (make-keyword ',attr-sym) ht) ,attr-remarks)))) (when (and *compile-for-dgdl?* (not (eql attr-sym 'gdl-acc::type))) `(unless (find-method (symbol-function ',(glisp:intern attr-sym :gdl-inputs)) nil (list (find-class 'gdl-remote) t (find-class 'gdl-basis)) nil) (defmethod ,(glisp:intern attr-sym :gdl-inputs) ((,parent-arg gdl-remote) ,part-arg (,self-arg gdl-basis)) (the-object ,parent-arg (fetch-input ,(make-keyword attr-sym) ,part-arg ,self-arg))))) ;; ;; FLAG -- added recently, because why wouldn't we need default message handlers for input-slots? ;; ;; FLAG -- did this cause problems for DAP? Keep an eye out for this. ;; ;; ;; FLAG -- as per report from DAP, this apparently break some things. ;; ;; #+nil `(unless (find-method (symbol-function ',(glisp:intern (symbol-name attr-sym) :gdl-slots)) nil (list (find-class 'gdl-basis)) nil) (defmethod ,(glisp:intern (symbol-name attr-sym) :gdl-slots) ((,self-arg gdl-basis) &rest ,args-arg) (let ((,parent-arg (the-object ,self-arg %parent%))) (if (or (null ,parent-arg) ,args-arg) (not-handled ,self-arg ,(make-keyword attr-sym) ,args-arg) (let ((,val-arg (let (*error-on-not-handled?*) (,(glisp:intern (symbol-name attr-sym) :gdl-inputs) ,parent-arg (the-object ,self-arg :%name%) ,self-arg)))) (if (eql ,val-arg 'gdl-rule:%not-handled%) (not-handled ,self-arg ,(make-keyword attr-sym) ,args-arg) ,val-arg)))))) `(defmethod ,(glisp:intern (symbol-name attr-sym) :gdl-slots) ((self ,name) &rest ,args-arg) ;;(declare (ignore ,args-arg)) (let ((*error-on-not-handled?* t)) (with-dependency-tracking (,attr-sym self) (let ((,parent-arg (the-object self %parent%))) (let ((,val-arg (if ,parent-arg (let (*error-on-not-handled?*) (,(glisp:intern (symbol-name attr-sym) :gdl-inputs) ,parent-arg (the-object self %name%) self)) 'gdl-rule:%not-handled%))) (cond ((not (eql ,val-arg 'gdl-rule:%not-handled%)) ,val-arg) ((and ,parent-arg (fboundp ',(glisp:intern (symbol-name attr-sym) :gdl-trickle-downs))) (if ;;(member ,(make-key attr-sym) (the-object ,parent-arg :%trickle-down-slots%)) (gethash ,(make-keyword attr-sym) (the-object ,parent-arg :%trickle-down-slots%)) (,(glisp:intern (symbol-name attr-sym) :gdl-slots) ,parent-arg) (funcall (symbol-function ',(glisp:intern (symbol-name attr-sym) :gdl-trickle-downs)) ,parent-arg))) (t (not-handled self ,(make-keyword attr-sym) ,args-arg)))))))))))) input-slots)) (defun optional-input-slots-section (name input-slots &optional (defaulted? nil)) (mapcan #'(lambda(input) (let ((attr-remarks (message-strings input)) (attr-sym (glisp:intern (symbol-name (message-symbol input)) :gdl-acc)) (attr-expr (message-source-code input))) (remove nil (list (when (and *compile-documentation-database?* attr-remarks) `(when *load-documentation-database?* ;; ;; FLAG -- make the hash table the initform rather than this clumsy "or" conditional. ;; (let ((ht (or (message-documentation (find-class ',name)) (setf (message-documentation (find-class ',name)) (make-hash-table))))) (setf (gethash (make-keyword ',attr-sym) ht) ,attr-remarks)))) (when *compile-source-code-database?* `(when *load-source-code-database?* ;; ;; FLAG -- make the hash table the initform rather than this clumsy "or" conditional. ;; (let ((ht (or (message-source (find-class ',name)) (setf (message-source (find-class ',name)) (make-hash-table))))) (setf (gethash (make-keyword ',attr-sym) ht) ',attr-expr)))) `(eval-when (:compile-toplevel :load-toplevel :execute) (glisp:begin-redefinitions-ok)) (when (and *compile-for-dgdl?* (not (string-equal (symbol-name name) "remote-object"))) `(unless (find-method (symbol-function ',(glisp:intern attr-sym :gdl-inputs)) nil (list (find-class 'gdl-remote) t (find-class 'gdl-basis)) nil) (when (or (not (fboundp ',(glisp:intern attr-sym :gdl-slots))) (not (find-method (symbol-function ',(glisp:intern attr-sym :gdl-slots)) nil (list (find-class 'gdl-remote)) nil))) (defmethod ,(glisp:intern attr-sym :gdl-slots) ((self gdl-remote) &rest ,args-arg) (the (send (:apply (cons ,(make-keyword (symbol-name attr-sym)) ,args-arg)))))))) (when *compile-for-dgdl?* `(unless (find-method (symbol-function ',(glisp:intern attr-sym :gdl-inputs)) nil (list (find-class 'gdl-remote) t (find-class 'gdl-basis)) nil) (defmethod ,(glisp:intern (symbol-name attr-sym) :gdl-inputs) ((,parent-arg gdl-remote) ,part-arg (,self-arg gdl-basis)) (the-object ,parent-arg (fetch-input ,(make-keyword attr-sym) ,part-arg ,self-arg))))) `(eval-when (:compile-toplevel :load-toplevel :execute) (glisp:end-redefinitions-ok)) `(defmethod ,(glisp:intern (symbol-name attr-sym) :gdl-slots) ((self ,name) &rest ,args-arg) (declare (ignore ,args-arg)) (let ((*error-on-not-handled?* t)) (with-dependency-tracking (,attr-sym) (let ((,parent-arg (the :%parent%))) (let ((,val-arg (if ,parent-arg (let (*error-on-not-handled?*) (,(glisp:intern (symbol-name attr-sym) :gdl-inputs) ,parent-arg (the :%name%) self)) 'gdl-rule:%not-handled%))) ,(if defaulted? `(if (eql ,val-arg 'gdl-rule:%not-handled%) (let ((,val-arg (if ,parent-arg (let (*error-on-not-handled?*) (if (fboundp ',(glisp:intern (symbol-name attr-sym) :gdl-trickle-downs)) (,(glisp:intern (symbol-name attr-sym) :gdl-trickle-downs) self) 'gdl-rule:%not-handled%)) ,val-arg))) (if (eql ,val-arg 'gdl-rule:%not-handled%) ,attr-expr ,val-arg)) ,val-arg) `(if (eql ,val-arg 'gdl-rule:%not-handled%) ,attr-expr ,val-arg))))))))))) input-slots))
11,581
Common Lisp
.lisp
186
44.053763
140
0.518785
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
542d9d2436790893e4c59b1406f3652c36b88c18966386e195fb6f670f17bf37
36,060
[ -1 ]
36,061
sequence.lisp
lisp-mirror_gendl/base/rest/source/sequence.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (define-object standard-sequence (quantification) :documentation (:description "A standard sequence quantification is generated as a result of specifying <tt>:sequence (:size [number-expression]))</tt> in an <tt>:objects</tt> specification. Unlike a variable-sequence quantification (specified with <tt>:sequence (:indices ...))</tt>), elements cannot be surgically inserted or deleted from a standard sequence. If a value upon which the [number-expression] depends becomes modified, each member of the sequence will be reinstantiated as it is demanded.") :input-slots (number-of-elements child-types) :computed-slots ( (safe-list-elements (multiple-value-bind (list error) (ignore-errors (let ((result-list nil)) (dotimes (n (length (the :array)) (nreverse result-list)) (multiple-value-bind (object error) (ignore-errors (the (:get-member n))) (let ((child (cond ((typep error 'error) (list :object-key (list (make-keyword (the %name%)) n) :error error)) ((typep object 'null-object) nil) (t object)))) (when child (push child result-list))))))) (if (typep error 'error) (list (list :object-key (make-keyword (format nil "~a[agg]" (the %name%))) :error error)) list))) (list-elements-uncached (let ((result-list nil)) (dotimes (n (length (the :array)) (nreverse result-list)) (let ((object (the (:get-member n)))) (when (not (typep object 'null-object)) (push object result-list))))) :uncached) (list-elements (let ((result-list nil)) (dotimes (n (length (the :array)) (nreverse result-list)) (let ((object (the (:get-member n)))) (when (not (typep object 'null-object)) (push object result-list)))))) (array (let ((number-of-elements (the number-of-elements))) (when (or (not (integerp number-of-elements)) (minusp number-of-elements)) (error " The number of elements specified for a ':sequence (:size ...)' must evaluate to a non-negative integer. In ~s, it evaluated to ~s. " (append '(the :root) (symbols-as-keywords (reverse (the :root-path))) ) number-of-elements)) (let* ((current-array (previous-value self :array)) (child-types (the child-types)) (new-array (make-array (list number-of-elements) :initial-element nil))) (dotimes (n (min (length current-array) (length new-array)) new-array) (setf (aref new-array n) (aref current-array n)) (let ((child-type (if (atom child-types) child-types (or (nth n child-types) (first (last child-types)))))) (when (and (aref new-array n) (not (eql (class-of (aref new-array n)) child-type))) (change-class (aref new-array n) child-type))))))) (first (the (:get-member 0))) (last (the (:get-member (1- (length (the :array))))))) :functions ((instantiated-indices () (let (result (array (the :array))) (dotimes (n (the :number-of-elements) (nreverse result)) (when (aref array n) (push n result))))) (get-member (index) (let ((child-types (the child-types)) (array (the array))) (typecase index (number (if (>= index (length array)) (ecase *out-of-bounds-sequence-reference-action* (:error (error "Attempt to access element index ~a in sequence which only has ~a elements, the root-path to the sequence is ~s." index (length array) (cons 'the (reverse (the root-path))))) (:warn (warn "Attempt to access element index ~a in sequence which only has ~a elements -- the root-path to the sequence is ~s. *********** returning nil ************. " index (length array) (cons 'the (reverse (the root-path))))) (:silent nil)) (or (aref array index) (setf (aref array index) (make-object-internal (if (atom child-types) child-types (or (nth index child-types) (first (last child-types)))) :%name% (list (glisp:intern (symbol-name (the :name-for-display)) :gdl-acc) nil t) :%parent% (list (the :parent) nil t) :%root% (gdl-acc::%root% self) :%aggregate% (list self nil t) :%index% (list index nil t)))))) (keyword (ecase index (:first (the :first)) (:last (the :last))))))))) ;; FLAG -- this needs a lot of work -- have to truly get rid of ;; members when deactivated, and not answer for indexes which are not ;; present. ;; (define-object variable-sequence (quantification) :documentation (:description "A variable-sequence quantification is generated as a result of specifying <tt>:sequence (:indices ...))</tt> in an <tt>:objects</tt> specification. Unlike a normal sequence quantification (specified with <tt>:sequence (:size ...))</tt>), elements can be surgically inserted and deleted from a variable-sequence.") :input-slots (:element-index-list :child-types) :computed-slots ((lock (glisp:make-lock)) (ht (progn (the :child-types) ;; ;; FLAG -- consider increasing initial size or rehash-size ;; (let ((ht (make-hash-table :size (length (the :element-index-list))))) (dolist (index (the :element-index-list) ht) (setf (gethash index ht) nil)))) :settable) (safe-list-elements (multiple-value-bind (list error) (ignore-errors (let ((result-list nil)) (dolist (n (the element-index-list) (nreverse result-list)) (multiple-value-bind (object error) (ignore-errors (the (:get-member n))) (let ((child (cond ((typep error 'error) (list :object-key (list (make-keyword (the %name%)) n) :error error)) ((typep object 'null-object) nil) (t object)))) (when child (push child result-list))))))) (if (typep error 'error) (list (list :object-key (make-keyword (format nil "~a[agg]" (the %name%))) :error error)) list))) (list-elements (mapcar #'(lambda(index) (the (:get-member index))) (the :element-index-list))) (number-of-elements (length (the :element-index-list))) (first (the (:get-member (first (the :element-index-list))))) (last (the (:get-member (first (last (the :element-index-list))))))) :functions ((exists? (index) (gethash index (the ht))) ("Void. Resets the variable sequence to its default list of indices (i.e. clears out any inserted or deleted elements and re-evaluates the expression to compute the original list of indices)" reset! () (glisp:with-lock-held ((the lock)) (the (restore-slot-default! :element-index-list)) (the (restore-slot-default! :ht)))) (instantiated-indices () (remove-if-not #'(lambda(index) (second (multiple-value-list (gethash index (the :ht))))) (the :element-index-list))) (get-member (index) (multiple-value-bind (value found?) (gethash index (the ht)) (cond (value value) (found? (setf (gethash index (the :ht)) (make-object-internal (the :child-types) :%name% (list (glisp:intern (symbol-name (the :name-for-display)) :gdl-acc) nil t) :%parent% (list (the :parent) nil t) :%root% (gdl-acc::%root% self) :%aggregate% (list self nil t) :%index% (list index nil t)))) (t (error "The element ~a is not active in ~s" index self))))) (deactivate! (index) (the (:delete! index))) ("Void. Deletes the element identified with the given index. :arguments (index \"Integer, Symbol, or other object matching with <tt>eql</tt>. The identifier used when the element was initialized or inserted.\")" delete! (index) (glisp:with-lock-held ((the lock)) (the (:set-slot! :ht (the :ht) :remember? nil)) (remhash index (the ht)) (the (:modify-attribute! :element-index-list (remove index (the :element-index-list)))))) (activate! (index) (the (:insert! index))) ("Void. Inserts a new element identified with the given index. :arguments (index \"Integer, Symbol, or other object matching with <tt>eql</tt>. The identifier to be used to access this element.\")" insert! (index) (multiple-value-bind (value found?) (gethash index (the ht)) (declare (ignore value)) (if (not found?) (glisp:with-lock-held ((the lock)) (setf (gethash index (the ht)) nil) (the (set-slot! :ht (the ht) :remember? nil)) (the (set-slot! :element-index-list (append (the element-index-list) (list index))))) (error "The element ~a is already active in ~s" index self)))))) (define-object radial-sequence (standard-sequence) :documentation (:description "A radial sequence quantification is generated as a result of specifying <tt>:sequence (:radial [number-expression]))</tt> in an <tt>:objects</tt> specification.") :computed-slots ( ) :functions ( )) (define-object matrix-sequence (standard-sequence) :documentation (:description "A matrix sequence quantification is generated as a result of specifying <tt>:sequence (:matrix direction-keyword number direction-keyword number))</tt> in an <tt>:objects</tt> specification. The direction-keywords can be one of <tt>:lateral</tt>, <tt>:longitudinal</tt>, and <tt>:vertical</tt>. The items will be arranged spread out evenly in the directions specified. Centers can also be provided explicitly based on the indices. The indices to a matrix sequence consist of a list of numbers rather than a single number as with a normal sequence.") :computed-slots ((safe-list-elements (multiple-value-bind (list error) (ignore-errors (let ((result-list nil)) (dotimes (m (second (the number-of-elements)) (nreverse result-list)) (dotimes (n (fourth (the number-of-elements))) (multiple-value-bind (object error) (ignore-errors (the (:get-member m n))) (let ((child (cond ((typep error 'error) (list :object-key (list (make-keyword (the %name%)) m n) :error error)) ((typep object 'null-object) nil) (t object)))) (when child (push child result-list)))))))) (if (typep error 'error) (list (list :object-key (make-keyword (format nil "~a[agg]" (the %name%))) :error error)) list))) (list-elements (let ((result-list nil)) (dotimes (m (second (the number-of-elements)) (nreverse result-list)) (dotimes (n (fourth (the number-of-elements))) (let ((object (the (:get-member m n)))) (when (not (typep object 'null-object)) (push object result-list))))))) (array (let ((standard-axes '(:longitudinal :lateral :vertical)) (number-of-elements (the number-of-elements))) (when (not (listp number-of-elements)) (error " Matrix quantification needs two direction keywords each with a value evaluating to a number.")) (let ((axis-1 (first number-of-elements)) (rows (second number-of-elements)) (axis-2 (third number-of-elements)) (columns (fourth number-of-elements))) (when (not (and (member axis-1 standard-axes) (integerp rows) (member axis-2 standard-axes) (integerp columns))) (error " Malformed Matrix Sequence")) (the :child-types) (make-array (list rows columns) :initial-element nil)))) (first (the (get-member 0 0))) (last (the (get-member (1- (second (the number-of-elements))) (1- (fourth (the number-of-elements))))))) :functions ( (get-member (row column) (let ((child-types (the child-types)) (array (the array))) (typecase row (number (or (aref array row column) (setf (aref array row column) (make-object-internal (if (atom child-types) child-types ;; ;; FLAG -- allow list of list of child types ;; (first child-types)) :%name% (list (glisp:intern (symbol-name (the :name-for-display)) :gdl-acc) nil t) :%parent% (list (the :parent) nil t) :%root% (gdl-acc::%root% self) :%aggregate% (list self nil t) :%index% (list (list row column) nil t))))) (keyword (ecase row (:first (the :first)) (:last (the :last))))))))) (defun previous-value (object slot) (let ((slot (glisp:intern slot :gdl-acc))) (let ((value (slot-value object slot))) (when (and (consp value) (eq (first value) 'gdl-rule::%unbound%)) (fourth value)))))
16,317
Common Lisp
.lisp
318
36.314465
150
0.532261
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
36d3c9d30d7a661c39ac9927b1563442aa6f598b53513949dd027311224feb4a
36,061
[ -1 ]
36,062
quantification.lisp
lisp-mirror_gendl/base/rest/source/quantification.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (define-object quantification () :documentation (:description "A quantification is an aggregate created as a result of specifying <tt>:sequence (:size ...))</tt> or <tt>:sequence (:indices ...))</tt> in an <tt>:objects</tt> specification. Usually, the elements of a quantified set are referenced by using extra parentheses around the message in the reference chain and using the index number. But the aggregate itself also supports certain messages, documented here. One message, <tt>number-of-elements</tt>, is not listed in the normal messages section because it is internal. It can be used, and returns an integer representing the cardinality of the aggregate.") :input-slots ((remember-children? nil)) :computed-slots ((index nil) ("GDL Object. Returns the first element of the aggregate." first nil) ("GDL Object. Returns the last element of the aggregate." last nil)))
1,831
Common Lisp
.lisp
35
48.428571
140
0.735509
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
8e9696ce50301f27f7893c66de2c720a596800d37f891cde43fa8d229f67c81b
36,062
[ -1 ]
36,063
utilities.lisp
lisp-mirror_gendl/base/rest/source/utilities.lisp
;; ;; Copyright 2002-2012 Genworks International ;; ;; Except otherwise noted in documentation below, this source file is ;; part of the General-purpose Declarative Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defmacro with-error-handling ((&key (error? nil) (timeout nil) (timeout-body `(warn "Timed Out after ~a Seconds" ,timeout))) &body body) "[Macro]. Wraps the <b>body</b> of code with error-trapping and system timeout. A warning is given if an error condition occurs with <b>body</b>. :&key ((timeout 2) \"Timeout in Seconds.\" timeout-body \"Body of code to evaluate if timeout occurs. Default is to print a warning and return nil.\") :&rest (body \"Body of code to be wrapped\")" (declare (ignore timeout-body)) (if error? `(progn ,@body) (let ((values '+values+ #+nil (gensym)) (error '+error+ #+nil (gensym))) (let ((code `(let* ((,values (multiple-value-list (ignore-errors ,@body))) (,error (second ,values))) (if (and ,error (typep ,error 'error)) (progn (warn "~a" ,error) (values nil ,error)) (apply #'values ,values))))) (if timeout (error "Need implementation for timeout in with-error-handling.~%") code))))) (defun read-safe-string (string) "Lisp object. Reads an item from string, protecting against lisp evaluation with the `#.' reader macro. Throws an error if evaluation would have occured. :arguments (string \"string\") " (if (not (stringp string)) string (when (not (zerop (length string))) (let ((*read-eval* nil)) (read-from-string string))))) (defun alist2plist (alist) "Plist. Converts an assoc-list to a plist. :arguments (alist \"Assoc-List\") " (when alist (cons (first (first alist)) (cons (second (first alist)) (alist2plist (rest alist)))))) (defun replace-substring (string old new) "String. Replaces all substring occurrences of <b>old</b> with <b>new</b> in <b>string</b>. Note: In a full GDL system, you will have glisp:replace-regexp, which is more powerful and probably more efficient than this. :arguments (string \"String. The source string.\" old \"String. The substring to be replaced.\" new \"String. The substring to replace it with.\") :see-also <tt>excl:replace-regexp</tt> " (let ((position (search old string))) (if position (string-append (subseq string 0 position) new (replace-substring (subseq string (+ position (length old))) old new)) string))) (defun lastcar (list) "Lisp Object. Returns the last element of <b>list</b>. :arguments (list \"List\")" (first (last list))) (defun mapsend (object-list message &rest args) "List. Returns a new list which is the result of sending <b>message</b> to each GDL object in <b>object-list</b>. :arguments (object-list \"List of GDL objects.\" message \"Keyword symbol.\")" (declare (ignore args)) (let ((object-list (if (typep object-list 'quantification) (list-elements object-list) object-list))) (mapcar #'(lambda(object) (the-object object (evaluate message))) object-list))) (defun list-of-n-numbers (num1 num2 n) "Returns a list of n numbers equally spaced between bounds num1 and num2, inclusive." (let ((increment (/ (- num2 num1) (- n 1))) (result-list nil)) (dotimes (i (- n 1) (nreverse (cons num2 result-list))) (push (+ num1 (* i increment)) result-list)))) (defun list-of-numbers (num1 num2 &optional (increment 1)) "List of Numbers. Returns a list of incrementing numbers starting from <b>num1</b> and ending with <b>num2</b>, inclusive. :arguments (num1 \"Number\" num2 \"Number\") :&optional ((increment 1) \"Number. The distance between the returned listed numbers.\")" (let ((result-list nil)) (dotimes (i (1+ (floor (/ (- num2 num1) increment))) (nreverse result-list)) (push (+ (* i increment) num1) result-list)))) (defun half (num) "Number. Returns the result of dividing <b>num</b> by the integer <tt>2</tt>. The type of the returned number will depend on the type of <b>num</b>. :arguments (num \"Number\")" (let ((result (/ num 2))) (if *bias-to-double-float?* (to-double-float result) result))) (defun twice (num) "Number. Returns the result of multiplying <b>num</b> by the integer <tt>2</tt>. The type of the returned number will depend on the type of <b>num</b>. :arguments (num \"Number\")" (let ((result (+ num num))) (if *bias-to-double-float?* (to-double-float result) result))) (defun index-filter (fn list) "List. Returns all elements of <b>list</b> for whose index (starting at zero) the function <b>fn</b> returns non-NIL. :arguments (fn \"Function object (e.g. a lambda expression)\" list \"List\")" (let ((count 0) (result-list nil)) (dolist (elem list (nreverse result-list)) (when (funcall fn count) (push elem result-list)) (incf count)))) (defun flatten (tree &aux result) "List. Returns a new list consisting of only the leaf-level atoms from <b>list</b>. Since nil is technically a list, <tt>flatten</tt> also has the effect of removing nils from <b>list</b>, but may be inefficient if used only for this purpose. For removing nil values from a list, consider using <tt>remove nil ...</tt> instead. :note from Stack Overflow forum: http://stackoverflow.com/questions/25866292/flatten-a-list-using-common-lisp :note Creative Commons license <pre> (defun flatten (lst &aux (result '())) (labels ((rflatten (lst1) (dolist (el lst1 result) (if (listp el) (rflatten el) (push el result))))) (nreverse (rflatten lst)))) </pre> :note This will not work with dotted lists, only with actual lists. If you need dotted lists, use the old definition of flatten, from Paul Graham On Lisp: <pre> (defun flatten (tree) (if (atom tree) (ensure-list tree) (nconc (flatten (car tree)) (if (cdr tree) (flatten (cdr tree)))))) </pre> :arguments (list \"List\") :see-also <tt>remove</tt>" (labels ((rflatten (tree1) (dolist (el tree1 result) (if (listp el) (rflatten el) (push el result))))) (nreverse (rflatten tree)))) (defun split (string &optional (split-chars (list #\space #\newline #\return #\tab))) "List of Strings. Returns a list containing the elements of <b>string</b> after having been split according to <b>split-chars</b> as delimiting characters. :arguments (string \"String\") :&optional ((split-chars (list #\\space #\\newline #\\return #\\tab)) \"List of characters\") :see-also <tt>glisp:split-regexp</tt>" (let ((split-chars (if (atom split-chars) (list split-chars) split-chars))) (let ((non-white (position nil string :test #'(lambda(item1 item2) (declare (ignore item1)) (not (member item2 split-chars)))))) (let ((newlines-before (count #\newline (subseq string 0 non-white)))) (append (make-list newlines-before :initial-element :newline) (when non-white (let ((white (position nil (subseq string non-white) :test #'(lambda(item1 item2) (declare (ignore item1)) (member item2 split-chars))))) (cons (subseq string non-white (when white (+ white non-white))) (when white (split (subseq string (+ non-white white)) split-chars)))))))))) (defun always (arg) "T. Always returns the value <tt>T</tt> regardless of <b>arg</b>. :arguments (arg \"Lisp object. Ignored\")" (declare (ignore arg)) t) (defun never (arg) "NIL. Always returns the value <tt>NIL</tt> regardless of <b>arg</b>. :arguments (arg \"Lisp object. Ignored\")" (declare (ignore arg))) ;; ;; FLAG -- creates too many lists look into using some kind of ;; sequence composition or series package ;; (defun maptree (node fn &optional (accept? #'always) (prune? #'never) (get-children :children)) "List. Returns the results of applying <b>fn</b> to each GDL object in the object tree rooted at <b>node</b> in a ``depth-first'' tree traversal. :arguments (node \"GDL object\" fn \"Function. Operates on a single argument which is a GDL object\") :&optional ((accept? #'always) \"Function. Determines which nodes to accept in the final result\" (prune? #'never) \"Function. Determines which nodes to prune from the tree traversal\" (get-children :children) \"Keyword symbol :children or Function. Function applied to a given node to get its children. The default, keyword symbol :children, uses the node's normal children as returned by (the-object node children).\")" (let ((object-list (flatten (traverse-tree node prune? get-children)))) (mapcar fn (remove-if-not accept? object-list)))) (defun traverse-tree (node &optional prune? (get-children :children)) (cons node (when (not (funcall prune? node)) (mapcar #'(lambda(child) (traverse-tree child prune? get-children)) (cond ((eql get-children :children) (the-object node :children)) ((keywordp get-children) (the-object node (evaluate get-children))) ((functionp get-children) (funcall get-children node)) (t (error " Get-Children arg of ~s Not Handled by traverse-tree" node))))))) (defun hash-table-copy (ht) (let ((new-hash (make-hash-table :size (hash-table-count ht) :test (hash-table-test ht)))) (maphash #'(lambda(key val) (setf (gethash key new-hash) val)) ht) new-hash)) (defun hash-table-compare (ht1 ht2 &key (test 'equalp)) (unless (and (= (hash-table-size ht1) (hash-table-size ht2)) (eql (hash-table-test ht1) (hash-table-test ht2))) (error "For hash-table-compare, sizes and tests for hash tables must be the same")) (let ((new-hash (make-hash-table :size (hash-table-size ht1) :test (hash-table-test ht1)))) (maphash #'(lambda(key val1) (let ((val2 (gethash key ht2))) (setf (gethash key new-hash) (if (funcall test val1 val2) 'gdl-rule::%same% val1)))) ht1) new-hash)) (defun expandit (form &optional (stream *standard-output*)) (let ((*print-case* :downcase) (*print-right-margin* 60)) (if (streamp stream) (pprint (macroexpand-1 (macroexpand-1 form)) stream) (with-open-file (stream stream :direction :output :if-exists :supersede :if-does-not-exist :create) (pprint (macroexpand-1 (macroexpand-1 form)) stream))))) (defun undefine-object (object-name-symbol) "NIL. Clears all definitions associated with <b>object-name</b> from the currently running GDL session. :arguments (object-name \"Non-keyword Symbol naming a GDL object type\")" ;; ;; FLAG -- repeated code from define-object -- try to factor out. ;; (when (find-class object-name-symbol nil) (let ((message-keys (get object-name-symbol :%gdl-messages%))) (dolist (key message-keys) (let ((method (find-method (symbol-function (glisp:intern (symbol-name key) :gdl-slots)) nil (list (find-class object-name-symbol)) nil))) (if (null method) (warn "No Method Found for Message ~s of object ~s~%" key object-name-symbol) (remove-method (symbol-function (glisp:intern (symbol-name key) :gdl-slots)) method))))) (setf (find-class object-name-symbol) nil)) (setf (get object-name-symbol :%gdl-messages%) nil)) (defun safe-sort (list &rest args) "List. Nondestructive analog of the Common Lisp <tt>sort</tt> function. Returns a freshly created list. :arguments (list \"List. The list to be sorted.\") :&rest (args \"Argument list. Identical to the arguments for Common Lisp <tt>sort</tt>.\")" (let ((copy (copy-list list))) (apply #'sort copy args))) (defun gdl-object-symbol? (symbol) (eql (class-of (find-class symbol nil)) (find-class 'gdl-class))) (deftype gdl-object-symbol () '(satisfies gdl-object-symbol?)) (defun gdl-format-symbol? (symbol) (eql (class-of (find-class symbol nil)) (find-class 'gdl-format-class))) (deftype gdl-format-symbol () '(satisfies gdl-format-symbol?)) ;; ;; From Paul Graham ACL ;; (defun most (function list) "List. Returns the member of <b>list</b> which returns the maximum numerical value when <b>function</b> is applied to it. As second value is returned which is the actual maximum value (the return-value of <b>function</b> as applied). This function comes from the Paul Graham book <u>ANSI Common Lisp</u>. :arguments (function \"Function\" list \"List\")" (if (null list) (values nil nil) (let* ((wins (first list)) (max (funcall function wins))) (dolist (obj (rest list)) (let ((score (funcall function obj))) (when (> score max) (setq wins obj max score)))) (values wins max)))) (defun least (function list) "List. Returns the member of <b>list</b> which returns the minimum numerical value when <b>function</b> is applied to it. As second value is returned which is the actual minimum value (the return-value of <b>function</b> as applied). This function comes from the Paul Graham book <u>ANSI Common Lisp</u>. :arguments (function \"Function\" list \"List\")" (if (null list) (values nil nil) (let* ((wins (first list)) (min (funcall function wins))) (dolist (obj (rest list)) (let ((score (funcall function obj))) (when (< score min) (setq wins obj min score)))) (values wins min)))) (defun ^2 (number) "Number. Return <b>number</b> raised to the power two (2). :arguments (number \"Number\")" (* number number)) (defun number-round (number &optional decimal-places) "Number. Returns <b>number</b> rounded to <b>decimal-places</b> decimal places. :arguments (number \"Number\" decimal-places \"Integer\")" (if (null decimal-places) number (coerce (/ (round (* number (expt 10 decimal-places))) (expt 10 decimal-places)) 'double-float))) (defun number-format (number &optional decimal-places) "String. Returns a string displaying <b>number</b> rounded to <b>decimal-places</b> decimal places. :arguments (number \"Number\" decimal-places \"Integer\")" (let ((rep (number-round number decimal-places))) (if (and (or (null decimal-places) (zerop decimal-places)) (= rep (truncate rep))) (format nil "~a" (truncate rep)) (format nil (format nil "~~,~af" decimal-places) (coerce rep 'double-float))))) ;; ;; FLAG -- handle points of 2 and 4 dimensions. ;; (defun near-to? (number near-to &optional (tolerance *zero-epsilon*)) "Boolean. Predicate to test if number is within tolerance of <b>near-to</b>. The default tolerance is the value of the parameter <tt>*zero-epsilon*</tt>. :arguments (number \"Number\" near-to \"Number\") :&optional ((tolerance *zero-epsilon*) \"Number\")" (< (abs (- number near-to)) tolerance)) (defun near-zero? (number &optional (tolerance *zero-epsilon*)) "Boolean. Returns non-NIL iff <b>number</b> is greater than <b>tolerance</b> different from zero. :arguments (number \"Number\") :&optional ((tolerance *zero-epsilon*) \"Number\") :see-also <tt>zerop</tt> (Common Lisp function)" (near-to? number 0 tolerance)) (defun status-message (string) "NIL. Prints <b>string</b>, followed by a newline, to <tt>*trace-output*</tt>, which is generally the system console. :arguments (string \"String\")" (write-string string *trace-output*) (format *trace-output* "~%")) (defun safe-float (number) "Double-float Number. Coerces <b>number</b> to a double-precision floating-point number if possible. If this is not possible, returns <tt>0.0d0</tt> (i.e. zero in the form of a double-precision floating-point number). :arguments (number \"Number\")" (if (typep number '(or integer float ratio)) (coerce number 'double-float) 0.0d0)) (defun round-to-nearest (number interval) "Number. Rounds <b>number</b> to the nearest <b>interval</b>. :arguments (number \"Number\" interval \"Number\")" ;;(* (round number interval) interval) (/ (round number interval) (/ interval)) ) (defun fround-to-nearest (number interval) "Number. Rounds <b>number</b> to the nearest <b>interval</b>, using type contagion rules for floating-point similar to the CL \"fround\" function. :arguments (number \"Number\" interval \"Number\")" (* (fround number interval) interval)) (defun find-all-superclasses (class &optional (local? nil)) (let ((directs (glisp:direct-superclasses class))) (if local? directs (remove-duplicates (flatten (mapcan #'(lambda(direct) (list direct (find-all-superclasses direct))) directs)) :from-end t)))) (defun symbols-as-keywords (item) (when item (cond ((symbolp item) (make-keyword item)) ((listp item) (mapcar #'symbols-as-keywords item)) (t item)))) (defmethod readable-expression ((object t) &optional self) (declare (ignore self)) (error "Objects of type ~a cannot currently be written out and read back into GDL reliably. Please do not use objects of this type as the value for toplevel inputs or settable slots, or contact Genworks with an enhancement request to include a readable output format for this object type." (type-of object))) (defmethod readable-expression ((object hash-table) &optional self) (let (keys vals) (maphash #'(lambda(key val) (push key keys) (push val vals)) object) `(let ((ht (make-hash-table))) (mapc #'(lambda(key val) (setf (gethash key ht) val)) ,(readable-expression (nreverse keys) self) ,(readable-expression (nreverse vals) self)) ht))) (defmethod readable-expression ((object cons) &optional self) (with-error-handling (:timeout nil) `(list ,@(mapcar #'(lambda(expr) (readable-expression expr self)) object)))) (defmethod readable-expression ((object number) &optional self) (declare (ignore self)) object) (defmethod readable-expression ((object string) &optional self) (declare (ignore self)) object) (defmethod readable-expression ((object symbol) &optional self) (declare (ignore self)) `',object) (defmethod readable-expression ((object array) &optional self) (declare (ignore self)) object) (defmethod readable-expression ((object pathname) &optional self) (declare (ignore self)) object) (defmethod lookup-color ((color string) &key (format :decimal) (ground :foreground)) (if (and (eql (aref color 0) #\#) (= (length color) 7)) (ecase format (:hex color) (:decimal (let ((red (subseq color 1 3)) (green (subseq color 3 5)) (blue (subseq color 5 7))) (let* ((*read-base* 16) (red (to-single-float (div (read-safe-string red) 255))) (green (to-single-float (div (read-safe-string green) 255))) (blue (to-single-float (div (read-safe-string blue) 255)))) (values (make-array 3 :initial-contents (list red green blue)) t))))) (progn (when (= (length color) 6) (setq color (string-append "#" color))) (ecase format (:decimal (multiple-value-bind (decimal found?) (gethash color *color-table-decimal*) (values (coerce (or decimal (lookup-color (getf *colors-default* ground) :format :decimal)) 'vector) found?))) (:hex (if (eql (aref color 0) #\#) (values color t) (multiple-value-bind (hex found?) (gethash (make-keyword color) *color-table*) (values (or hex (lookup-color (getf *colors-default* ground) :format :hex)) found?)))))))) (defmethod lookup-color ((color symbol) &key (format :decimal) (ground :foreground)) (ecase format (:decimal (multiple-value-bind (decimal found?) (gethash color *color-table-decimal*) (values (coerce (or decimal (lookup-color (getf *colors-default* ground) :format :decimal)) 'vector) found?))) (:hex (multiple-value-bind (hex found?) (gethash (make-keyword color) *color-table*) (values (or hex (lookup-color (getf *colors-default* ground) :format :hex)) found?))))) (defmethod lookup-color ((color vector) &key (format :decimal) (ground :foreground)) (declare (ignore ground)) (ecase format (:decimal (values (map 'vector #'to-single-float color) t)) (:hex (setq color (make-array 3 :initial-contents (list (truncate (* (aref color 0) 255)) (truncate (* (aref color 1) 255)) (truncate (* (aref color 2) 255))))) (string-upcase (let ((*print-base* 16)) (values (format nil "#~2,,,'0@a~2,,,'0@a~2,,,'0@a" (aref color 0)(aref color 1)(aref color 2)) t)))))) (defmethod lookup-color ((color cons) &key (format :decimal) (ground :foreground)) (declare (ignore ground)) (ecase format (:decimal (values (coerce (mapcar #'to-single-float color) 'vector) t)) (:hex (let ((*print-base* 16)) (values (format nil "#~2,,,'0@a~2,,,'0@a~2,,,'0@a" (truncate (* (first color) 255)) (truncate (* (second color) 255)) (truncate (* (third color) 255))) t))))) ;; ;; FLAG -- remove this defunct version. ;; #+nil (defmethod lookup-color ((color null) &key (format :decimal) (ground :foreground)) (unless (and (eql ground :foreground) (eql (getf *colors-default* :foreground) :black)) (values (lookup-color (getf *colors-default* ground) :format format) nil))) (defmethod lookup-color ((color null) &key (format :decimal) (ground :foreground)) (values (lookup-color (getf *colors-default* ground) :format format) nil)) (defun cyclic-nth (number list) "Lisp object. Returns nth from the list, or wraps around if nth is greater than the length of the list." (nth (mod number (length list)) list)) (defun set-self (object) (setf (symbol-value 'self) object)) (eval-when (compile load eval) (export 'with-error-handling)) (defmethod evaluate-object ((category t) args) (declare (ignore args)) nil) (defun iso-8601-date (universal-time &key include-time?) "String. Returns the ISO8601 formatted date and possibly time from a Common Lisp universal time integer, e.g. 2007-11-30 or 2007-11-30T13:45:10" (multiple-value-bind (seconds minutes hours date month year day daylight-savings? timezone) (decode-universal-time universal-time) (declare (ignore day daylight-savings? timezone)) (format nil "~a-~2,,,'0@a-~2,,,'0@a~a" year month date (if include-time? (format nil "T~2,,,'0@a:~2,,,'0@a:~2,,,'0@a" hours minutes seconds) "")))) (defun universal-time-to-plist (universal-time) (multiple-value-bind (seconds minutes hours date month year) (decode-universal-time universal-time) (list :seconds (format nil "~2,,,'0@a" seconds) :minutes (format nil "~2,,,'0@a" minutes) :hours (format nil "~2,,,'0@a" hours) :date (format nil "~2,,,'0@a" date) :month (format nil "~2,,,'0@a" month) :year (format nil "~a" year) :full-date (format nil "~a-~2,,,'0@a-~2,,,'0@a" year month date)))) (defun universal-time-from-iso-8601 (iso8601-date) "Integer representing Common Lisp Universal Time. Returns the universal time from a date formatted as an iso-8601 date, optionally with time, e.g. 2012-07-08 or 2012-07-08T13:33 or 2012-07-08T13:33:00" (destructuring-bind (date &optional (time "00:00:00")) ;;(glisp:split-regexp "t" (string-downcase iso8601-date)) (split (string-downcase iso8601-date) #\t) (destructuring-bind (year month date) ;;(glisp:split-regexp "-" date) (split date #\-) (destructuring-bind (hours minutes &optional (seconds "00")) ;;(glisp:split-regexp ":" time) (split time #\:) (encode-universal-time (parse-integer seconds) (parse-integer minutes) (parse-integer hours) (parse-integer date) (parse-integer month) (parse-integer year)))))) (defun print-hash (hash) (maphash #'(lambda(key val) (print-variables key val)) hash)) (defun list-hash (hash) (let (result) (maphash #'(lambda(key val) (if result (nconc result (list key val)) (setq result (list key val)))) hash) result)) (defun make-fresh-copy (&key object make-object-args) (apply #'make-object (the-object object type) make-object-args)) (defun read-snapshot (&key (filename "/tmp/snap.gdl") string stream object keep-bashed-values? make-object-args keys-to-ignore (keys-to-ignore-default (list :query-plist :view-toggle :cookies-received))) "GDL Instance. Reads the snapshot data from stream, from the string, or from file indicated by filename. If no optional keyword <tt>object</tt> argument is given, a new GDL instance based on the data in the snapshot file is returned. If an <tt>object</tt> is given, the object should be compatible in type to that specified in the snapshot file, and this existing object will be modified to contain the set slot values and toplevel inputs as specified in the snapshot file. :&key ((filename \"/tmp/snap.gdl\") \"String or pathname. File to be read. If either string or stream is specified, this will not be used.\" (string nil) \"String of data. The actual snapshot contents, stored in a string. If stream is specified, this will not be used.\" (stream nil) \"Stream open for input. A stream from which the snapshot data can be read.\" (keep-bashed-values? nil) \"Boolean. Indicates whether to keep the currently bashed values in object before reading snap values into it.\" (object nil) \"GDL object. Existing object to be modified with restored values.\")" (let ((keys-to-ignore (append keys-to-ignore keys-to-ignore-default))) (cond (stream (read-snapshot-from-stream stream :object object :keep-bashed-values? keep-bashed-values? :make-object-args make-object-args :keys-to-ignore keys-to-ignore)) (string (with-input-from-string (in string) (read-snapshot-from-stream in :object object :keep-bashed-values? keep-bashed-values? :make-object-args make-object-args :keys-to-ignore keys-to-ignore))) (filename (with-open-file (in filename) (read-snapshot-from-stream in :object object :keep-bashed-values? keep-bashed-values? :make-object-args make-object-args :keys-to-ignore keys-to-ignore)))))) (defun read-snapshot-from-stream (in &key object keep-bashed-values? make-object-args keys-to-ignore) (let ((package-form (read in))) (when (or (null package-form) (not (find-package (second package-form)))) (error "Invalid package specification at beginning of stream ~s.~%" in)) (let* ((*package* (find-package (second package-form))) (root-form (read in))) (when (or (null root-form) (not (eql (class-of (find-class (first root-form))) (find-class 'gdl-class)))) (error "Invalid object type specifier as first element of second form in ~a.~%" root-form)) (let* ((object (cond ((and object keep-bashed-values?) object) (object (the-object object restore-tree!) object) (t (progn (apply #'make-object (first root-form) make-object-args)))))) (let ((self object) (value-plist (rest root-form))) (mapc #'(lambda(key expression) (unless (member key keys-to-ignore) (when self (the-object self (set-slot! key (eval expression) :re-sort? nil))))) (plist-keys value-plist) (plist-values value-plist))) (let (forms) (do ((form (read in nil nil) (read in nil nil))) ((null form) forms) (push form forms)) (setq forms (nreverse forms)) (let* ((forms (double-length-sort forms)) (primaries (remove-if-not #'(lambda(item) (or (getf (rest item) :%primary?%) (getf (rest item) :element-index-list))) forms)) (non-primaries (remove-if #'(lambda(item) (or (getf (rest item) :%primary?%) (getf (rest item) :element-index-list))) forms)) (forms (append primaries non-primaries))) (dolist (form forms) (let ((root-path (first form)) (value-plist (rest form))) (let ((self (with-error-handling (:timeout nil) (the-object object (follow-root-path root-path))))) (when self (mapc #'(lambda(key expression) (unless (member key keys-to-ignore) (the-object self (set-slot! key (eval `(let ((self ,self)) ,expression)) :re-sort? nil)))) (plist-keys value-plist) (plist-values value-plist)))))))) object)))) #+nil (defun read-snapshot-from-stream (in &key object keep-bashed-values? make-object-args keys-to-ignore) (let (forms) (do ((form (read in nil nil) (read in nil nil))) ((null form) forms) (push form forms)) (setq forms (nreverse forms)) (let ((package-form (first forms))) (when (or (null package-form) (not (find-package (second package-form)))) (error "Invalid package specification at beginning of snapshot data.~%")) (let* ((*package* (find-package (second package-form))) (root-form (second forms))) (when (or (null root-form) (not (atom (first root-form))) (not (eql (class-of (find-class (first root-form))) (find-class 'gdl-class)))) (warn "Invalid root-form: ~a.~%" root-form) (setq root-form (first (remove-if-not #'(lambda(form) (atom (first form))) (rest forms)))) (setq forms (cons package-form (cons root-form (remove root-form (rest forms) :test #'equalp))))) (let* ((object (cond ((and object keep-bashed-values?) object) (object (the-object object restore-tree!) object) (t (progn (apply #'make-object (first root-form) make-object-args)))))) (let ((self object) (value-plist (rest root-form))) (mapc #'(lambda(key expression) (unless (member key keys-to-ignore) (when self (the-object self (set-slot! key (eval expression) :re-sort? nil))))) (plist-keys value-plist) (plist-values value-plist))) (let* ((forms (double-length-sort forms)) (primaries (remove-if-not #'(lambda(item) (or (getf (rest item) :%primary?%) (getf (rest item) :element-index-list))) forms)) (non-primaries (remove-if #'(lambda(item) (or (getf (rest item) :%primary?%) (getf (rest item) :element-index-list))) forms)) (forms (append primaries non-primaries))) (dolist (form forms) (let ((root-path (first form)) (value-plist (rest form))) (let ((self (with-error-handling (:timeout nil) (the-object object (follow-root-path root-path))))) (when self (mapc #'(lambda(key expression) (unless (member key keys-to-ignore) (the-object self (set-slot! key (eval `(let ((self ,self)) ,expression)) :re-sort? nil)))) (plist-keys value-plist) (plist-values value-plist))))))) object))))) ;; ;; FLAG -- remove this defunction version. ;; #+nil (defun read-snapshot (&key (filename "/tmp/snap.gdl") object keep-bashed-values? make-object-args keys-to-ignore) "GDL Instance. Reads the snapshot file indicated by filename. If no optional keyword <tt>object</tt> argument is given, a new GDL instance based on the data in the snapshot file is returned. If an <tt>object</tt> is given, the object should be compatible in type to that specified in the snapshot file, and this existing object will be modified to contain the set slot values and toplevel inputs as specified in the snapshot file. :&key ((filename \"/tmp/snap.gdl\") \"String or pathname. File to be read.\" (keep-bashed-values? nil) \"Boolean. Indicates whether to keep the currently bashed values in object before reading snap values into it.\" (object nil) \"GDL object. Existing object to be modified with restored values.\")" (with-open-file (in filename) (let ((package-form (read in))) (when (or (null package-form) (not (find-package (second package-form)))) (error "Invalid package specification at beginning of ~a.~%" filename)) (let* ((*package* (find-package (second package-form))) (root-form (read in))) (when (or (null root-form) (not (eql (class-of (find-class (first root-form))) (find-class 'gdl-class)))) (error "Invalid object type specifier as first element of second form in ~a.~%" root-form)) (let ((object (cond ((and object keep-bashed-values?) object) (object (the-object object restore-tree!) object) (t (progn (apply #'make-object (first root-form) make-object-args)))))) (let ((self object) (value-plist (rest root-form))) (mapc #'(lambda(key expression) (unless (member key keys-to-ignore) (when self (the-object self (set-slot! key (eval expression)))))) (plist-keys value-plist) (plist-values value-plist))) (let ((forms-ht (make-hash-table))) (do ((form (read in nil nil) (read in nil nil))) ((null form)) (push form (gethash (length (first form)) forms-ht))) (let* ((forms (list-hash forms-ht)) (forms (mapcar #'list (plist-keys forms) (plist-values forms))) (forms (plist-values (alist2plist (sort forms #'< :key #'first)))) (forms (mapcar #'(lambda(group) (let ((primaries (remove-if-not #'(lambda(item) (or (getf (rest item) :%primary?%) (getf (rest item) :element-index-list))) group)) (non-primaries (remove-if #'(lambda(item) (or (getf (rest item) :%primary?%) (getf (rest item) :element-index-list))) group))) (append primaries non-primaries))) forms)) (forms (apply #'append forms))) (dolist (form forms) (let ((root-path (first form)) (value-plist (rest form))) (let ((self (with-error-handling (:timeout nil) (the-object object (follow-root-path root-path))))) (when self (mapc #'(lambda(key expression) (unless (member key keys-to-ignore) (the-object self (set-slot! key (eval `(let ((self ,self)) ,expression)))))) (plist-keys value-plist) (plist-values value-plist)))))))) object))))) (defun write-plist (&key plist output-path) "Pretty-prints a plist to a file with standard I/O syntax. :&key ((plist nil) \"List. The list to be printed to the file\" (output-path nil) \"Pathname of a file. The file to be created or superseded.\") " (with-open-file (out output-path :direction :output :if-exists :new-version :if-does-not-exist :create) (with-standard-io-syntax (pprint plist out)))) (defun min-max-search (function comparison low high &optional (tolerance *zero-epsilon*) verbose?) (when verbose? (print-variables high low)) (if (near-to? high low tolerance) high (let* ((mid (half (+ low high))) (lower (half (+ low mid))) (upper (half (+ mid high))) (lower-value (funcall function lower)) (upper-value (funcall function upper))) (if (funcall comparison lower-value upper-value) (min-max-search function comparison low mid tolerance verbose?) (min-max-search function comparison mid high tolerance verbose?))))) (defun binary-search (function value low high &key (tolerance *zero-epsilon*) (search-granularity *zero-epsilon*) verbose?) (when verbose? (print-variables high low)) (if (near-to? high low search-granularity) (progn (warn "binary search did not converge, returning best guess") high) (let* ((mid (half (+ low high))) (mid-value (funcall function mid))) (print-variables mid mid-value) (cond ((near-to? mid-value value tolerance) mid) ((> mid-value value) (binary-search function value low mid :tolerance tolerance :search-granularity search-granularity :verbose? verbose?)) ((< mid-value value) (binary-search function value mid high :tolerance tolerance :search-granularity search-granularity :verbose? verbose?)))))) (defun gdl-rule::lookup-parameters (self message) (let ((value (getf (the %parameters%) message 'gdl-rule:%not-handled%))) (if (eql value 'gdl-rule:%not-handled%) (not-handled self message) value))) (defparameter *dep-hash-threshhold* 1000) (defparameter *invalid-aggregate-behavior* :error) (defun add-notify-cons (notify-cons value &optional self message) ;; ;; FLAG -- this was added as a fix for github Issue #69, but causes ;; a regression by polluting the dependency graph with normal objects ;; which may then become unbound spuriously. Retracted until a more ;; benign fix for Issue #69 can be determined. ;; ;;(declare (ignore self message)) ;; ;; FLAG -- we put back the extra tracking of notify-cons but only if ;; the message does not name a GDL object -- we don't want those ;; being the target of dependencies or they can be orphaned. ;; (when (and self message) (let ((aggregate (gdl-acc::%aggregate% (first notify-cons)))) (when (and (consp aggregate) (first aggregate) (not (consp (gdl-acc::%aggregate% self)))) (let ((agg (first aggregate))) (if agg (let ((num-value (gdl-acc::number-of-elements agg))) (when (and (consp num-value) (let ((value (funcall message self))) (not (and (consp value) (typep (first value) 'gdl-basis))))) (add-notify-cons (list self message) num-value))) (let ((error-message (format nil " !!! Invalid internal Gendl data structure detected. notify-cons = ~s aggregate = ~a value = ~s self = ~a message = ~s !!! " notify-cons aggregate value self message))) (ecase *invalid-aggregate-behavior* (:error (error error-message)) (:warn (warn error-message)) (nil )))))))) (let ((second (second value))) (if (and (listp second) (< (length second) *dep-hash-threshhold*)) (let ((matching-sublist (assoc (first notify-cons) (second value)))) (if matching-sublist (pushnew (second notify-cons) (rest matching-sublist)) (push (copy-list notify-cons) (second value)))) (progn (when (listp second) (setf (second value) (alist-to-hash second))) (pushnew (second notify-cons) (gethash (first notify-cons) (second value))))))) (defun alist-to-hash (alist) (let ((ht (make-hash-table :size (twice *dep-hash-threshhold*) :rehash-size *dep-hash-threshhold*))) (dolist (entry alist ht) (destructuring-bind (object . messages) entry (setf (gethash object ht) messages))))) #+nil (defun add-notify-cons (notify-cons value &optional self message) (when (and self message) (let ((aggregate (gdl-acc::%aggregate% (first notify-cons)))) (when (consp aggregate) (add-notify-cons (list self message) (gdl-acc::number-of-elements (first aggregate)))))) (let ((matching-sublist (assoc (first notify-cons) (second value)))) (if matching-sublist (pushnew (second notify-cons) (rest matching-sublist)) (push (copy-list notify-cons) (second value))))) (defparameter *loaded-hotpatches* nil) (defun load-hotpatches (&key (directory (merge-pathnames "hotpatches/" (glisp:executable-homedir-pathname)))) (if (not (and (probe-file directory) (glisp:file-directory-p directory))) (warn "~s does not exist and/or is not a directory~%" directory) (let* ((files (directory directory)) (source-files (sort (remove-if-not #'(lambda(file) (let ((type (pathname-type file))) (or (string-equal type "lisp") (string-equal type "gdl") (string-equal type "gendl")))) files) #'string-lessp :key #'namestring))) (when (or (not (glisp:featurep :allegro)) (glisp:featurep :compiler)) (dolist (file source-files) (with-error-handling () (#+allegro excl:compile-file-if-needed #-allegro compile-file file)))) (setq files (directory directory)) (let ((compiled-files (sort (let ((fasl-type (pathname-type (compile-file-pathname "foo")))) (remove-if-not #'(lambda(file) (string-equal (pathname-type file) fasl-type)) files)) #'string-lessp :key #'namestring))) (dolist (file compiled-files) (unless (find file *loaded-hotpatches* :test #'equalp) (with-error-handling () (load file) (pushnew file *loaded-hotpatches* :test #'equalp)))))))) (defun double-length-sort (&optional (list)) (let ((first (safe-sort list #'(lambda(item1 item2) (let ((first1 (first (first item1))) (first2 (first (first item2)))) (< (if (consp first1) (length first1) 0) (if (consp first2) (length first2) 0))))))) (stable-sort first #'(lambda(x y) (< (length (first x)) (length (first y)))))))
43,678
Common Lisp
.lisp
829
44.414958
145
0.63555
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
2361b591c19cf2c27bde6b1e0fd5f66fbd6f02aa722465a3e1587a5e056768a8
36,063
[ -1 ]
36,064
make-part.lisp
lisp-mirror_gendl/base/rest/source/make-part.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defparameter *warn-on-invalid-toplevel-inputs?* t) (defun make-part (&rest args) (apply #'make-object args)) ;; ;; FLAG -- cache the computation of input-slots based on type, and ;; look up input-slots on subsequent calls. Then reactivate this ;; make-object. ;; #+nil (defun make-object (object-type &rest args) "GDL Object. Instantiates an object with specified initial values for input-slots. :arguments (object-name \"Symbol. Should name a GDL object type.\" arguments \"spliced-in plist. A plist of keyword symbols and values for initial <tt>input-slots</tt>.\")" (let (*notify-cons* (keys (plist-keys args)) (vals (plist-values args))) (let ((object (apply #'make-instance object-type :allow-other-keys t (list :%name% (list (format nil "~a" object-type) nil t) :%parent% (list nil nil t))))) (let ((input-slots (append (the-object object (message-list :category :required-input-slots)) (the-object object (message-list :category :optional-input-slots)) (the-object object (message-list :category :settable-optional-input-slots)) (the-object object (message-list :category :defaulted-input-slots)) (the-object object (message-list :category :settable-defaulted-input-slots))))) (mapc #'(lambda(key val) (if (member key input-slots) (setf (slot-value object (glisp:intern key :gdl-acc)) (list val nil t)) (when *warn-on-invalid-toplevel-inputs?* (warn "~&~%~s is not a defined input-slot for ~s. The argument ~s, and its value ~s, have been ignored [you may (setq *warn-on-invalid-toplevel-inputs?* nil) to suppress this warning).~%~%" key object-type key val)))) keys vals)) (setf (gdl-acc::%root% object) object (gdl-acc::%toplevel-inputs% object) args) object))) (defun make-object (object-type &rest args) "GDL Object. Instantiates an object with specified initial values for input-slots. :arguments (object-name \"Symbol. Should name a GDL object type.\" arguments \"spliced-in plist. A plist of keyword symbols and values for initial <tt>input-slots</tt>.\")" (let (*notify-cons* (keys (plist-keys args)) (vals (plist-values args))) (let ((object (apply #'make-instance object-type :allow-other-keys t ;; FLAG -- tell me again why we should allow other keys? (append (list :%name% (list (format nil "~a" object-type) nil t) :%parent% (list nil nil t) :%god-parents% (getf args :god-parents)) (mapcan #'(lambda(key val) (unless (eql key :god-parents) (list key (list val nil t)))) keys vals))))) (setf (gdl-acc::%root% object) object (gdl-acc::%toplevel-inputs% object) args) (the-object object initialize-instance!) object))) ;; ;; FLAG -- remove this defunct version. ;; #+nil (defun make-object (object-type &rest args) "GDL Object. Instantiates an object with specified initial values for input-slots. :arguments (object-name \"Symbol. Should name a GDL object type.\" arguments \"spliced-in plist. A plist of keyword symbols and values for initial <tt>input-slots</tt>.\")" (let (*notify-cons* (keys (plist-keys args)) (vals (plist-values args))) (let ((object (apply #'make-instance object-type :allow-other-keys t (append (list :%name% (list (format nil "~a" object-type) nil t) :%parent% (list nil nil t)) (mapcan #'(lambda(key val) (list key (list val nil t))) keys vals))))) (setf (gdl-acc::%root% object) object (gdl-acc::%toplevel-inputs% object) args) object))) (defun make-object-internal (object-type &rest args) (let ((object (apply #'make-instance object-type :allow-other-keys t args))) (the-object object initialize-instance!) object)) #+nil (defun make-object-internal (object-type &rest args) (apply #'make-instance object-type :allow-other-keys t args)) (defun make-canonical-part (&rest args) (apply #'make-object args)) (defun make-self (object-type &rest args) (setf (symbol-value 'self) (apply #'make-object object-type args)))
5,524
Common Lisp
.lisp
110
41
117
0.622832
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
ed27ba51dbe5a65210e69566449e187edfd229d20c78ff01426cf71a6ccbd8bc
36,064
[ -1 ]
36,065
null-part.lisp
lisp-mirror_gendl/base/rest/source/null-part.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (define-object null-object () :documentation (:description "A part with no geometric representation and no children. Use this in a conditional <tt>:type</tt> expression if you want to turn off a branch of the tree conditionally.") :computed-slots ((%vertex-array% (make-array (list 0))) (%line-vertex-indices% nil) (%curve-vertex-indices% nil) (%lines-to-draw% nil) (%curves-to-draw% nil) (%2d-bounding-box% nil) (path-info nil) )) (define-object null-part (null-object))
1,413
Common Lisp
.lisp
34
38
104
0.722386
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
fc666adfed024126fd70f250e1ea528e1194ae1f0d54a2d5714c51d4bbf151ff
36,065
[ -1 ]
36,066
aggregate.lisp
lisp-mirror_gendl/base/rest/source/aggregate.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defmacro the-element (&rest args) "Lisp Object [Macro]. Acts similarly to <tt>the-object</tt> for each element of an aggregate, within the context of a <tt>list-elements</tt>, <tt>append-elements</tt>, <tt>max-of-elements</tt>, <tt>min-of-elements</tt>, <tt>sum-elements</tt>, or a query operator (query operators are not yet documented). :arguments (args \"(&rest). Standard reference chain applicable to the element.\")" `(the-object %object% ,@args)) (defmacro list-elements (aggregate &optional expression filter) "List of GDL Objects [Macro]. Returns a listing of the elements of an aggregate, with an optional <tt>the-element</tt> expression and filter. If an expression is given, the list of results from the expressions is returned. If no expression is given, a list of the objects themselves is returned. :arguments (aggregate \"GDL aggregate object. (e.g. from a <tt>:sequence (:size ..)</tt> <tt>:object</tt> specification).\") :&optional (expression \"Expression using <tt>the-element</tt>. Similar to a <tt>the-object</tt> reference.\" filter \"Function of one argument. Can be used to filter the result list.\")" (cond ((and expression filter) `(let ((%objects% (if (typep ,aggregate 'quantification) (the-object ,aggregate :list-elements) (the-object ,aggregate :children)))) (mapcar #'(lambda(%object%) ,expression) (remove-if-not #'(lambda(%object%) ,filter) %objects%)))) (expression `(mapcar #'(lambda(%object%) ,expression) (if (typep ,aggregate 'quantification) (the-object ,aggregate :list-elements) (the-object ,aggregate :children)))) (t `(if (typep ,aggregate 'quantification) (the-object ,aggregate :list-elements) (the-object ,aggregate :children))))) ;; ;; FLAG -- rewrite the following without using apply so we don't risk ;; hitting function argument limit. ;; (defmacro append-elements (aggregate &optional expression filter) "List of Objects [Macro]. Returns an appended list of <tt>expression</tt> from each element of an aggregate, with an optional filter. :arguments (aggregate \"GDL aggregate object. (e.g. from a <tt>:sequence (:size ..)</tt> <tt>:object</tt> specification).\") :&optional (expression \"Expression using <tt>the-element</tt>. Similar to a <tt>the-object</tt> reference, which should return a list.\")" (unless expression (error "append-elements requires an expression keyword argument, using the-element.~%")) (let ((result '+result+ #+nil (gensym)) (value '+value+ #+nil (gensym))) `(let ((,result nil)) (dolist (%object% (the-object ,aggregate :list-elements)) (let ((,value (copy-list ,expression))) (let ((,value (funcall (or ,filter #'identity) ,value))) (if (null ,result) (setq ,result ,value) (nconc ,result ,value))))) ,result))) #+nil (defmacro append-elements (aggregate &optional expression filter) "List of Objects [Macro]. Returns an appended list of <tt>expression</tt> from each element of an aggregate, with an optional filter. :arguments (aggregate \"GDL aggregate object. (e.g. from a <tt>:sequence (:size ..)</tt> <tt>:object</tt> specification).\") :&optional (expression \"Expression using <tt>the-element</tt>. Similar to a <tt>the-object</tt> reference, which should return a list.\")" (cond ((and expression filter) `(let ((%objects% (the-object ,aggregate :list-elements))) (apply #'append (mapcar #'(lambda(%object%) ,expression) (remove-if-not #'(lambda(%object%) ,filter) %objects%))))) (expression `(apply #'append (mapcar #'(lambda(%object%) ,expression) (the-object ,aggregate :list-elements)))) (t (error "Macro append-elements requires an expression.")))) (defmacro max-of-elements (aggregate &optional expression filter) "Number [Macro]. Returns the maximum of <tt>expression</tt> from each element of an aggregate, with an optional filter. :arguments (aggregate \"GDL aggregate object. (e.g. from a <tt>:sequence (:size ..)</tt> <tt>:object</tt> specification).\") :&optional (expression \"Expression using <tt>the-element</tt>. Similar to a <tt>the-object</tt> reference, which should return a number.\")" (cond ((and expression filter) `(let ((%objects% (the-object ,aggregate :list-elements))) (apply #'max (mapcar #'(lambda(%object%) ,expression) (remove-if-not #'(lambda(%object%) ,filter) %objects%))))) (expression `(apply #'max (mapcar #'(lambda(%object%) ,expression) (the-object ,aggregate :list-elements)))) (t (error "Macro max-of-elements requires an expression.")))) (defmacro min-of-elements (aggregate &optional expression filter) "Number [Macro]. Returns the minimum of <tt>expression</tt> from each element of an aggregate, with an optional filter. :arguments (aggregate \"GDL aggregate object. (e.g. from a <tt>:sequence (:size ..)</tt> <tt>:object</tt> specification).\") :&optional (expression \"Expression using <tt>the-element</tt>. Similar to a <tt>the-object</tt> reference, which should return a number.\")" (cond ((and expression filter) `(let ((%objects% (the-object ,aggregate :list-elements))) (apply #'min (mapcar #'(lambda(%object%) ,expression) (remove-if-not #'(lambda(%object%) ,filter) %objects%))))) (expression `(apply #'min (mapcar #'(lambda(%object%) ,expression) (the-object ,aggregate :list-elements)))) (t (error "Macro max-of-elements requires an expression.")))) (defmacro sum-elements (aggregate &optional expression filter) "Number [Macro]. Returns the sum of <tt>expression</tt> from each element of an aggregate, with an optional filter. :arguments (aggregate \"GDL aggregate object. (e.g. from a <tt>:sequence (:size ..)</tt> <tt>:object</tt> specification).\") :&optional (expression \"Expression using <tt>the-element</tt>. Similar to a <tt>the-object</tt> reference, which should return a number.\")" (cond ((and expression filter) `(let ((%objects% (the-object ,aggregate :list-elements))) (apply #'+ (mapcar #'(lambda(%object%) ,expression) (remove-if-not #'(lambda(%object%) ,filter) %objects%))))) (expression `(apply #'+ (mapcar #'(lambda(%object%) ,expression) (the-object ,aggregate :list-elements)))) (t (error "Macro sum-elements requires an expression."))))
7,811
Common Lisp
.lisp
132
51.113636
141
0.643034
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
44ebef831e69292f66f0ad759d5dbff1426ac0522c7940bb0e8f1b35f73e5535
36,066
[ -1 ]
36,067
base-rule-object.lisp
lisp-mirror_gendl/base/rest/source/base-rule-object.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (define-object base-rule-object () :documentation (:description "Encapsulates a basic computation, usually to be displayed to the user. Typically this would be used as a mixin into a more sophisticated rule-object, but the type can be used to detect objects which should be processed as \"rules.\"") :input-slots ( ("String. Title to be used with the rule object. Defaults to NIL." rule-title nil) ("String. Short description of the rule (generally one line). Defaults to NIL." rule-description nil) ("Boolean. Indicates whether this rule violates a standard condition." violated? nil) ("String. The basic return-value, or result, of evaluating the rule." rule-result nil) ("String. Verbose description of the purpose of the rule." rule-description-help nil) ("String. Verbose description of how the rule result is computed." rule-result-help nil) ("Boolean. Determines whether the rule is displayed by default in reports etc." :suppress-display? nil) ("String. Determines the rule's default name in various internal GDL contexts. Defaults to the <tt>rule-title</tt>, or \"Unnamed Rule\" if <tt>rule-title</tt> is NIL." strings-for-display (or (the :rule-title) "Unnamed Rule")))) #| Consider the following renaming scheme: title ;; one-line title for linked display etc. [static] target-result ;; from a database lookup or user entry - target value or range. [quasi-static] description ;; one-line verbose description maybe displayed on mouseover [static] verbose-description ;; describes the purpose of the rule. [static] verbose-result ;; natural language description of actual formulas in the rule. [static] violated? ;; boolean or range [evaluated at runtime] result ;; Current result of "running" the rule, [evaluated at runtime] |#
2,789
Common Lisp
.lisp
54
47.055556
103
0.737791
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
5a8f30899e58b7a3c45f0211d9e148ef5b3967b6edf5f7ad930be0605e827592
36,067
[ -1 ]
36,068
parameters.lisp
lisp-mirror_gendl/base/rest/source/parameters.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (glisp:define-constant 2pi (* 2 pi) "Number (Constant). Twice the internal Lisp value for pi.") (glisp:define-constant pi/2 (/ pi 2) "Number (Constant). Half the internal Lisp value for pi.") (glisp:define-constant +phi+ 1.618 "Number (Constant). The Golden Ratio.") (defparameter *zero-epsilon* 0.001 "Number. The value used to test for closeness to zero in some functions. Defaults to 0.001") (glisp:define-constant +kappa+ 0.5522847498307936d0) (defvar *current-version* nil) (defparameter *force-restore-slot-default?* nil) (defparameter *override-non-settables?* t) (defparameter *bias-to-double-float?* nil "Boolean. Indicates whether the following functions should always return double-floats: <ul> <li><tt>half</tt> <li><tt>twice</tt> </ul>. Defaults to nil. ") (defparameter *color-plist* (list :periwinkle "#aaaaff" :aqua "#00ffff" :aquamarine "#70db93" :aquamarine-medium "#32cd99" :black "#000000" :blue "#0000ff" :blue-cadet "#5f9f9f" :blue-corn-flower "#42426f" :blue-light "#c0d9d9" :blue-medium "#3232cd" :blue-midnight "#2f2f4f" :blue-midnight-new "#00009c" :blue-navy "#23238e" :blue-neon "#4d4dff" :blue-rich "#5959ab" :blue-sky "#3299cc" :blue-slate "#007fff" :blue-slate-dark "#6b238e" :blue-slate-medium "#7f00ff" :blue-steel "#236b8e" :blue-steel-light "#8f8fbd" :blue-violet "#9f5f9f" :brass "#b5a642" :bronze "#8c7853" :bronze-ii "#a67d3d" :brown "#a62a2a" :brown-dark "#5c4033" :brown-dark-very "#5c4033" :chocolate-bakers "#5c3317" :chocolate-semi-sweet "#6b4226" :copper "#b87333" :copper-cool "#d98719" :coral "#ff7f00" :cyan "#00ffff" :feldspar "#d19275" :firebrick "#8e2323" :fuchsia "#ff00ff" :gold "#cd7f32" :gold-bright "#d9d919" :gold-old "#cfb53b" :goldenrod "#dbdb70" :goldenrod-medium "#eaeaae" :green "#008000" :green-copper "#527f76" :green-copper-dark "#4a766e" :green-dark "#2f4f2f" :green-forest "#238e23" :green-forest-medium "#6b8e23" :green-hunter "#215e21" :green-lime "#32cd32" :green-olive-dark "#4f4f2f" :green-pale "#8fbc8f" :green-sea "#238e68" :green-sea-medium "#426f42" :green-spring "#00ff7f" :green-spring-medium "#7fff00" :green-yellow "#93db70" :green-yellow2 "#99cc32" :gray "#808080" :grey "#c0c0c0" :grey-dim "#545454" :grey-light "#a8a8a8" :grey-light-very "#cdcdcd" :grey-slate-dark "#2f4f4f" :khaki "#9f9f5f" :lime "#00ff00" :magenta "#ff00ff" :maroon "#800000" :navy "#000080" :olive "#808000" :orange "#ff7f00" :orange-mandarian "#e47833" :orange-mandarin "#e47833" :orchid "#db70db" :orchid-dark "#9932cd" :orchid-medium "#9370db" :pink "#bc8f8f" :pink-neon "#ff6ec7" :pink-spicy "#ff1cae" :plum "#eaadea" :purple "#800080" :purple-dark "#871f78" :quartz "#d9d9f3" :red "#ff0000" :red-indian "#4e2f2f" :red-orange "#ff2400" :red-violet "#cc3299" :red-violet-medium "#db7093" :rose-dusty "#856363" :salmon "#6f4242" :scarlet "#8c1717" :sienna "#8e6b23" :silver "#c0c0c0" :sky-summer "#38b0de" :tan "#db9370" :tan-dark "#97694f" :tan-new "#ebc79e" :teal "#008080" :thistle "#d8bfd8" :turquoise "#adeaea" :turquoise-dark "#7093db" :turquoise-medium "#70dbdb" :violet "#4f2f4f" :wheat "#d8d8bf" :white "#ffffff" :wood-dark "#855e42" :wood-light "#e9c2a6" :wood-medium "#a68064" :yellow "#ffff00") "Plist. Maps color name keywords to string containing HTML-style hex RGB color value, e.g. \"#FFFFFF\" for pure white.") (defun color-compare (color1 color2) (let ((r1 (glisp:hex-string-to-integer (subseq color1 1 3))) (r2 (glisp:hex-string-to-integer (subseq color2 1 3))) (g1 (glisp:hex-string-to-integer (subseq color1 3 5))) (g2 (glisp:hex-string-to-integer (subseq color2 3 5))) (b1 (glisp:hex-string-to-integer (subseq color1 5 7))) (b2 (glisp:hex-string-to-integer (subseq color2 5 7)))) (< (+ r1 g1 b1) (+ r2 g2 b2)))) (defparameter *color-plist-sorted* (let ((names (plist-keys *color-plist*)) (hexes (plist-values *color-plist*))) (let* ((pairs (mapcar #'list names hexes)) (sorted-pairs (sort pairs #'color-compare :key #'second))) (mapcan #'identity sorted-pairs)))) (defparameter *color-table* (let ((ht (make-hash-table))) (mapc #'(lambda(key val) (setf (gethash key ht) val)) (plist-keys *color-plist-sorted*) (plist-values *color-plist-sorted*)) ht) "Hash Table. Built from the <tt>*color-plist*</tt>, this hash table is keyed on the same keys.") (defparameter *paper-size-plist* (list :letter (list :verbose-name "Letter (8.5x11)" :width 612 :height 792) :letter-landscape (list :verbose-name "Letter Landscape (11x8.5)" :width 792 :height 612) :tabloid (list :verbose-name "Tabloid (11x17)" :width 792 :height 1224) :ledger (list :verbose-name "Ledger (17x11)" :width 1224 :height 792) :legal (list :verbose-name "Legal (8.5x14)" :width 612 :height 1008) :legal-landscape (list :verbose-name "Legal Landscape (14x8.5)" :width 1008 :height 612) :executive (list :verbose-name "Exec. (7.5x10)" :width 540 :height 720) :a3 (list :verbose-name "A3 (11.69x16.53)" :width 841.68 :length 1190.16) :a4 (list :verbose-name "A4 (8.26x11.69)" :width 594.72 :height 841.68) :a5 (list :verbose-name "A5 (5.83x8.26)" :width 419.76 :height 594.72) :b4 (list :verbose-name "B4 (9.83x13.93)" :width 707.76 :height 1001.96) :b5 (list :verbose-name "B5 (7.17x10.12)" :width 516.24 :height 728.64))) (defparameter *paper-size-table* (let ((ht (make-hash-table))) (mapc #'(lambda(key val) (setf (gethash key ht) val)) (plist-keys *paper-size-plist*) (plist-values *paper-size-plist*)) ht)) (defun div (&rest nums) "Floating-point number. Divides using rational division and converts the result (which may be a pure rational number) to a floating-point number. :arguments (numerator \"Number.\" denominator \"Number.\") :&optional (more-denominators \"(&rest). More numbers to divide by.\")" (to-double-float (case (length nums) (1 (/ (first nums))) (2 (/ (first nums) (second nums))) (otherwise (/ (apply #'div (butlast nums)) (lastcar nums)))))) (defparameter *rgb-cube-colors* (let ((colors (list "FF" "CC" "99" "66" "33" "00")) result) (dolist (red colors (coerce (nreverse result) 'vector)) (dolist (green colors) (dolist (blue colors) (push (format nil "#~a~a~a" red green blue) result)))))) (defun rgb-cube-colors (&key (components (list "FF" "CC" "99" "66" "33" "00"))) (let (result) (dolist (red components (coerce (nreverse result) 'vector)) (dolist (green components) (dolist (blue components) (push (format nil "#~a~a~a" red green blue) result)))))) (defparameter *color-table-decimal* (let ((ht (make-hash-table :test #'equalp))) (mapc #'(lambda(key val) (setf (gethash key ht) (list (to-single-float (div (glisp:hex-string-to-integer (subseq val 1 3)) 255)) (to-single-float (div (glisp:hex-string-to-integer (subseq val 3 5)) 255)) (to-single-float (div (glisp:hex-string-to-integer (subseq val 5 7)) 255))))) (plist-keys *color-plist-sorted*) (plist-values *color-plist-sorted*)) (mapc #'(lambda(key) (setf (gethash key ht) (list (to-single-float (div (glisp:hex-string-to-integer (subseq key 1 3)) 255)) (to-single-float (div (glisp:hex-string-to-integer (subseq key 3 5)) 255)) (to-single-float (div (glisp:hex-string-to-integer (subseq key 5 7)) 255))))) (coerce *rgb-cube-colors* 'list)) ht) "Hash table. Same as <tt>*color-table*</tt> except the results are returned as a list of three decimal integers (for Red, Green, Blue) in the range of 0-254.") (defparameter *display-controls* nil) (defparameter *eager-setting-enabled?* nil) (defparameter *leaf-resets* nil) (defparameter *ensure-lists-when-bashing?* nil "Boolean. Determines whether lists are enforced to stay as lists with set-slot-if-needed method of vanilla-mixin. Default is nil.") (defparameter *out-of-bounds-sequence-reference-action* :error "Keyword symbol :warn, :error, or :silent. Determines what happens when you try to access a member of a GDL sequence which is out of bounds. If :warn or :silent, an out-of-bounds reference will simply return nil. If :error, it will throw an error as was the old behavior. Defaults to :error.") (defparameter *remember-previous-slot-values?* nil "Boolean. Determines whether the system keeps track of previous slot values (accessible with previous-value function) after bashings are done. Leave this set to nil to improve memory performance.") (defparameter *onclick-function* nil) (defparameter *with-format-if-exists* :supersede "keyword symbol. Establishes the default for the :if-exists format-slot of the base-format. If you want to change this default behavior, you can override this parameter globally or bind it dynamically. Alternatively you can specify a different value for :if-exists in the call to with-format. Valid keywords are the same as for Common Lisp open or with-open-file. Default is :supersede. :example <pre> (let ((*with-format-if-exists* :error)) (with-format (x3d \"/tmp/box.x3d\") (write-the-object (make-instance 'box :length 100 :width 100 :height 100) cad-output))) (with-format (x3d \"/tmp/box.x3d\" :if-exists :error) (write-the-object (make-instance 'box :length 100 :width 100 :height 100) cad-output) </pre> " ) (defparameter *with-format-if-does-not-exist* :create "keyword symbol. Establishes the default for the :if-does-not-exist format-slot of the base-format. If you want to change this default behavior, you can override this parameter globally or bind it dynamically. Alternatively you can specify a different value for :if-does-not-exist in the call to with-format. Valid keywords are the same as for Common Lisp open or with-open-file. Default is :create. :example <pre> (let ((*with-format-if-does-not-exist* :error)) (with-format (x3d \"/tmp/box.x3d\") (write-the-object (make-instance 'box :length 100 :width 100 :height 100) cad-output))) (with-format (x3d \"/tmp/box.x3d\" :if-does-not-exist :error) (write-the-object (make-instance 'box :length 100 :width 100 :height 100) cad-output) </pre> " ) (defparameter *with-format-direction :output "keyword symbol. Establishes the default for the :direction format-slot of the base-format. If you want to change this default behavior, you can override this parameter globally or bind it dynamically. Alternatively you can specify a different value for :direction in the call to with-format. Valid keywords are the same as for Common Lisp open or with-open-file. Default is :output. Normally this should not be changed in user code.") (defparameter *with-format-external-format* glisp:*external-text-format* "External-format. The default for the :external-format format-slot for the base format. Defaults to glisp:*external-text-format*.") ;; ;; FLAG -- determine what this should really be, i.e. establish a glisp:*element-type-default* ;; (defparameter *with-format-element-type* nil "Element-type. The default for the :element-type format-slot for the base format. Defaults to nil. Needs a better default.") (defparameter *allow-nil-list-of-numbers?* nil "Boolean. If set to t, allows list-of-numbers function to return nil instead of error when num1 is greater than num2 with positive increment or vice-versa. Default is nil.")
14,336
Common Lisp
.lisp
313
36.613419
134
0.611891
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
88bf895b68e075d8df984daa84249d2e763f5b1ace8fc4705cfa9530b7412878
36,068
[ -1 ]
36,069
ignore-errors-with-backtrace.lisp
lisp-mirror_gendl/base/rest/source/ignore-errors-with-backtrace.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defmacro ignore-errors-with-backtrace (&body body) "Like IGNORE-ERRORS, but in case of failure, return backtrace string as third value." `(block %debug-escape (handler-bind ((error (lambda (condition) (let ((backtrace (glisp:get-backtrace condition))) (return-from %debug-escape (values nil condition backtrace)))))) ,@body)))
1,296
Common Lisp
.lisp
29
39.758621
88
0.705036
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
2aef4cf604e97a7444c9505579dd69c5e92a8fcc607a88a3553e1649a9d328d9
36,069
[ -1 ]
36,070
bodies.lisp
lisp-mirror_gendl/base/rest/source/bodies.lisp
;; ;; Copyright 2002-2011 Genworks International ;; ;; This source file is part of the General-purpose Declarative ;; Language project (GDL). ;; ;; This source file contains 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 source file 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 source file. If not, see ;; <http://www.gnu.org/licenses/>. ;; (in-package :gdl) (defun instantiate-part-on-demand (self self-type attr-sym) (let ((current-object (previous-value self attr-sym))) (if current-object (prog1 (change-class current-object self-type) (unless (eql attr-sym 'gdl-acc::root-object-object) (the-object current-object (update! :replace-bashed-values? nil)))) (make-object-internal self-type :%name% (list attr-sym nil t) :%parent% (list self nil t) :%root% (gdl-acc::%root% self))))) (defun chase-up-trickle-down (slot-symbol self args) (let ((keyword (make-keyword slot-symbol))) (let ((parent (the-object self parent))) ;; ;; FLAG -- make sure 'args' below is correct - it was removed in 1590 p002.lisp (which is now gone). ;; (if (null parent) (not-handled self keyword args) (let ((result (let (*error-on-not-handled?*) (funcall (symbol-function (glisp:intern slot-symbol :gdl-inputs)) parent (the %name%) self)))) (if (eql result 'gdl-rule:%not-handled%) (let ((result (let (*error-on-not-handled?*) (cond (;;(member keyword (the-object parent %trickle-down-slots%)) (gethash keyword (the-object parent %trickle-down-slots%)) (apply (symbol-function slot-symbol) parent args)) (t (apply (symbol-function (glisp:intern slot-symbol :gdl-trickle-downs)) parent args)))))) (if (eql result 'gdl-rule:%not-handled%) (not-handled self keyword args) result)) result)))))) (defun trickle-down-basis (self slot args) (let ((keyword (make-keyword slot))) (let (*error-on-not-handled?* (parent (the parent))) (cond ((null parent) (not-handled self keyword args)) (;;(member keyword (the-object parent %trickle-down-slots%)) (gethash keyword (the-object parent %trickle-down-slots%)) (apply (symbol-function (glisp:intern slot :gdl-slots)) parent args)) (t (apply (symbol-function (glisp:intern slot :gdl-trickle-downs)) parent args))))))
3,112
Common Lisp
.lisp
58
44.293103
122
0.624221
lisp-mirror/gendl
0
0
0
AGPL-3.0
9/19/2024, 11:44:17 AM (Europe/Amsterdam)
a6974ac447403081e26d14e4f4f23d43b60067b653538b490e884b93183f8486
36,070
[ -1 ]