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
8,347
controller.lisp
evrim_core-server/src/web/framework/controller.lisp
;; ------------------------------------------------------------------------- ;; Coretal Controller ;; ------------------------------------------------------------------------- (in-package :core-server) ;; ------------------------------------------------------------------------- ;; Generic Unauthorized Controller ;; ------------------------------------------------------------------------- (defcomponent <core:controller/unauthorized (secure-object/unauthorized) ((redirect-location :host both :initform "index.html"))) (defmethod/remote init ((self <core:controller/unauthorized)) (alert "Sorry, you are unauthorized.") (setf (slot-value (slot-value window 'location) 'href) (redirect-location self))) ;; ------------------------------------------------------------------------- ;; Simple Page Controller ;; ------------------------------------------------------------------------- (defcomponent <core:simple-controller (secure-object <:div) ((pages :host local :export nil :type <core:simple-page :documentation "List of pages" :initarg :children) (default-page :host both :type string :documentation "Name of the default page") (constants :host remote :type abstract-widget-map* :authorize t :documentation "Constant widgets associated with this controller") (plugins :host remote :type plugin* :authorize t :documentation "Plugins that extends functions of this controller")) (:default-initargs :levels '(<core:controller/unauthorized <core:simple-controller/anonymous <core:simple-controller/authorized) :permissions '((owner . 2) (group . 2) (other . 2) (anonymous . 1) (unauthorized . 0)) :owner (make-simple-user :name "admin") :group (make-simple-group :name "admin"))) ;; ------------------------------------------------------------------------- ;; Anonymous Controller ;; ------------------------------------------------------------------------- (defcomponent <core:simple-controller/anonymous (history-mixin <core:simple-controller secure-object/authorized) ((secure-object :host lift :type <core:simple-controller) (pages :host local :lift t :export nil :authorize t :type <core::simple-page*) (plugins :host remote :lift t :authorize t :type plugin*) (default-page :host remote :lift t) (constants :host remote :lift t :authorize t) (core-css :host remote :initform +core.css+) (_page :host remote))) (defmethod/remote destroy ((self <core:simple-controller/anonymous)) (mapcar-cc (lambda (a) (destroy a)) (constants self)) (aif (_page self) (destroy it) nil) (delete-slots self 'constants) (call-next-method self)) (defmethod/local get-page ((self <core:simple-controller/anonymous) name) (aif (find name (pages self) :key #'name :test #'string=) (authorize (secure.application self) (secure.user self) it))) (defmethod/remote load-page ((self <core:simple-controller/anonymous) name) (let ((ctor (get-page self name))) (cond (ctor (if (_page self) (destroy (_page self))) (setf (_page self) (make-component ctor :controller self)) (mapcar-cc (lambda (a) (make-web-thread (lambda () (on-page-load a name)))) (constants self))) (t (_debug (list "page not found" name)) nil)))) (defmethod/remote get-page-in-the-url ((self <core:simple-controller/anonymous)) (get-parameter "page")) (defmethod/remote set-page-in-the-url ((self <core:simple-controller/anonymous) _name) (unless (eq _name (get-page-in-the-url self)) (set-parameter "page" _name))) (defmethod/remote on-history-change ((self <core:simple-controller/anonymous)) (_debug (list "on-history-change" self)) (let ((page (_page self)) (anchor (or (get-page-in-the-url self) (default-page self)))) (if page (let ((name (name page))) (if (and (not (eq name anchor)) (not (eq name window.location.pathname))) (load-page self anchor) (call-next-method self))) (load-page self anchor)))) (defmethod/remote init ((self <core:simple-controller/anonymous)) (load-css (core-css self)) (setf (plugins self) (mapcar-cc (lambda (plugin) (call/cc plugin self)) (plugins self))) (setf (constants self) (mapcar-cc (lambda (a) (make-component a :controller self)) (constants self))) (load-page self (or (get-parameter "page") (default-page self))) (start-history-timeout self) (_debug "loaded.")) ;; ------------------------------------------------------------------------- ;; Authorized Controller ;; ------------------------------------------------------------------------- (defcomponent <core:simple-controller/authorized (<core:simple-controller/anonymous) ())
4,697
Common Lisp
.lisp
100
43.21
84
0.584951
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
f9daf90fd3a2d8c487696c0afe0ebd0ff32538ae15b873cdda0b74a9c6c86553
8,347
[ -1 ]
8,348
taskbar.lisp
evrim_core-server/src/web/coretal/taskbar.lisp
(in-package :core-server) ;; ------------------------------------------------------------------------- ;; Task Mixin aka Taskbar Element ;; ------------------------------------------------------------------------- (defcomponent <core:task (<:ul) ((taskbar :host remote :initform nil) (title :host remote :initform ""))) (defmacro/js title (self) `(get-title ,self)) (defmethod/remote get-title ((self <core:task)) (slot-value self 'title)) (defmethod/remote destroy ((self <core:task)) (remove-task (taskbar self) self) (call-next-method self)) (defmethod/remote init ((self <core:task)) (add-task (taskbar self) self) (call-next-method self)) (defmethod/remote toast ((self <core:task) message) (toast (taskbar self) message)) ;; ------------------------------------------------------------------------- ;; Coretal Menu Task ;; ------------------------------------------------------------------------- (defcomponent <core:menu-task (<core:task) ()) (defmethod/remote init ((self <core:menu-task)) (add-class self "core-menu") (call-next-method self)) (defmethod/remote add-menu ((self <core:menu-task) item) (append self (<:li item))) (defmethod/remote remove-menu ((self <core:menu-task) item) (.remove-child self item)) ;; ------------------------------------------------------------------------- ;; Taskbar Component ;; ------------------------------------------------------------------------- (defcomponent <core:taskbar (<:div) ((tasks :host remote :initform nil) (last-update-timestamp :host remote :initform 0) (toaster :host remote) (toaster-ctor :host remote :initform (<core:toaster-task)) (menu :host remote :initform (<core:menu-task)) (taskbar-css :host remote :initform +taskbar.css+) (title :host remote :initform "[Core Server]") (hidden-p :host remote :initform nil) (coretal-icon :host remote))) (defmethod/remote get-title ((self <core:taskbar)) (slot-value self 'title)) (defmethod/remote refresh-titles ((self <core:taskbar)) (mapcar-cc (lambda (task) (destructuring-bind (task title div) task (if (typep (title task) 'string) (setf (slot-value title 'inner-h-t-m-l) (title task)) (progn (setf (slot-value title 'inner-h-t-m-l) "") (append title (title task)))))) (tasks self))) (defmethod/remote remove-task ((self <core:taskbar) item) (let ((lst (reduce0-cc (lambda (acc atom) (destructuring-bind (task title div) atom (cond ((eq item task) (when (slot-value div 'parent-node) (.remove-child (slot-value div 'parent-node) div)) acc) (t (cons atom acc))))) (tasks self)))) (setf (tasks self) lst) lst)) (defmethod/remote task-mouseover ((self <core:taskbar) task) (if (slot-value task 'mouseover) (make-web-thread (lifte (mouseover task))))) (defmethod/remote task-mouseout ((self <core:taskbar) task) (if (slot-value task 'mouseover) (make-web-thread (lifte (mouseout task))))) (defmethod/remote add-task ((self <core:taskbar) task) (let* ((task-title (<:div :class "taskbar-title" (title task))) (content (<:div :class "taskbar-content" task)) (div (<:div :class "left" (<:a :onmouseover (lifte (task-mouseover self task)) :onmouseout (lifte (task-mouseout self task)) task-title content)))) (append (slot-value self 'first-child) div) (setf (tasks self) (cons (list task task-title div) (remove-task self task))))) (defmethod/remote remove-menu ((self <core:taskbar) item) (remove-menu (menu self) item) item) (defmethod/remote add-menu ((self <core:taskbar) item) (add-menu (menu self) item) item) (defmethod/remote toast ((self <core:taskbar) message) (toast (toaster self) message)) (defmethod/remote do-open-console ((self <core:taskbar)) (do-open (toaster self))) (defmethod/remote show-taskbar ((self <core:taskbar)) (setf document.body.style.margin-top "36px") (let* ((_style (if window.get-computed-style (window.get-computed-style document.body null) document.body.current-style)) (_bg (slot-value _style 'background-image))) (if (and (> (slot-value _bg 'length) 0) (not (eq _bg "none"))) (setf (slot-value document.body.style 'background-position) "0 36px"))) (show self) (hide (coretal-icon self)) (set-cookie "coretal-hidden-p" false)) (defmethod/remote hide-taskbar ((self <core:taskbar)) (setf document.body.style.margin-top "0px") (let* ((_style (if window.get-computed-style (window.get-computed-style document.body null) document.body.current-style)) (_bg (slot-value _style 'background-image))) (if (and (> (slot-value _bg 'length) 0) (not (eq _bg "none"))) (setf (slot-value document.body.style 'background-position) "0 0px"))) (hide self) (show (coretal-icon self)) (set-cookie "coretal-hidden-p" true)) (defmethod/remote init ((self <core:taskbar)) (load-css (taskbar-css self)) (add-class self "core-taskbar") (add-class self "core") (append self (<:div :class "row1 width-100p")) ;; (<:div :class "clear") (append self (<:div :class "row2 clear"));; width-100p (setf (menu self) (make-component (menu self) :taskbar self :title (title self))) (when (null (toaster self)) (setf (toaster self) (make-component (toaster-ctor self) :taskbar self))) (add-menu self (<:a :onclick (lifte (do-open-console self)) (_ "Console") (<:span :class "subtitle" (_ "Show log console")))) (setf (coretal-icon self) (<:div :class "coretal-icon" "Powered by " (<:img :src "http://www.coretal.net/style/images/icon20px.gif") " " (<:a :class "coretal-icon" :onclick (lifte (show-taskbar self)) (<:span :class "coretal-name" "Coretal.net")))) (cond ((eq (get-cookie "coretal-hidden-p") "true") (setf (hidden-p self) t)) ((eq (get-cookie "coretal-hidden-p") "false") (setf (hidden-p self) nil))) (if (hidden-p self) (hide-taskbar self) (show-taskbar self)) (make-web-thread (lambda () (append (slot-value document 'body) (coretal-icon self)) (prepend (slot-value document 'body) self))) (call-next-method self)) (defmethod/remote destroy ((self <core:taskbar)) (remove-class self "core-taskbar") (remove-class self "core") (setf document.body.style.margin-top "0px") (.remove-child document.body (coretal-icon self)) (.remove-child document.body self) (remove-css (taskbar-css self)) (destroy (menu self)) (mapcar-cc (lambda (a) (.remove-child self a)) (reverse (slot-value self 'child-nodes))) (call-next-method self))
6,637
Common Lisp
.lisp
163
36.699387
77
0.623486
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
45d801a56e91163fdfcd552188709f8c9f955d36b48429d87b87771363b5fd70
8,348
[ -1 ]
8,349
i18n.lisp
evrim_core-server/src/web/coretal/i18n.lisp
(in-package :core-server) ;; ------------------------------------------------------------------------- ;; Language Pack ;; ------------------------------------------------------------------------- (defcomponent <core:language-pack () ((pack :host remote :initform nil) (name :host remote :initform "en" :print t)) (:ctor <core:language-pack)) (defmethod/remote init ((self <core:language-pack)) (when (null (slot-value +language-data+ (name self))) (setf (slot-value +language-data+ (name self)) (jobject))) (let ((data (slot-value +language-data+ (name self)))) (mapcar (lambda (a) (setf (slot-value data (car a)) (car (cdr a)))) (pack self)))) ;; ------------------------------------------------------------------------- ;; Turkish Language Pack ;; ------------------------------------------------------------------------- (defparameter +tr-data+ (list (cons "About Coretal.net" "Coretal.net Hakkında") (cons "Learn more about our services" "Hizmetlerimiz hakkında bilgi edinin") (cons "Close" "Kapat") (cons "Hide this taskbar" "Bu paneli gizle") (cons "Console" "Konsol") (cons "Show log console" "Kayıtları göster") (cons "Log Console" "Kayıtlar geçmişi") (cons "close" "kapat") ;; Months (cons "January" "Ocak") (cons "February" "Şubat") (cons "March" "Mart") (cons "April" "Nisan") (cons "May" "Mayıs") (cons "June" "Haziran") (cons "July" "Temmuz") (cons "August" "Ağustos") (cons "September" "Eylül") (cons "October" "Ekim") (cons "November" "Kasım") (cons "December" "Aralık") ;; UI/Sidebar (cons "Do you want to discard changes?" "Değişiklikleri göz ardı etmek istyor musunuz?") (cons "close this sidebar" "bu paneli kapat") ;; Demo Plugin (cons (concatenate 'string "This demo requires password of the site owner. " "Please enter password in order to " "load the demo.") (concatenate 'string "Bu uygulama test aşamasındadır. " "Eğer sitenin sahibi iseniz, parolanızı girip" " test işlemlerini gerçekleştirebilirsiniz.")) ;; Authentication Plugin (cons "Login or Register" "Kayıt ve Giriş") (cons "Open a new session" "Sistemde oturum açın") (cons "Welcome" "Hoşgeldin") (cons "you are now logged-in" "sisteme giriş onaylandı") (cons "Change Password" "Parolamı Değiştir") (cons "Change your password" "Parolanızı güncelleyin") (cons "Logout" "Çıkış") (cons "End your session" "Oturumu kapat") (cons "Username" "İsim, Soyisim") (cons "Email" "Eposta") (cons "Enter your full name" "İsminizi ve soyisminizi girin") (cons "Enter your email address" "Eposta adresinizi girin") (cons "Enter your password" "Parolanızı girin") (cons "Re-enter your password" "Parolanızı tekrar girin") (cons "agreement" "Sözleşme") (cons "I accept the terms in the" "metnindeki hususları kabul ediyorum") (cons "Register" "Kayıt ol") (cons "Login" "Oturum Aç") (cons "Cancel" "İptal") (cons "forgot password?" "unuttunuz mu?") (cons "Send my password" "Parolamı gönder") (cons "register" "kayıt ol") (cons "login" "oturum aç") (cons "Sign in with" "Sosyal medya ile oturum açın") (cons "Old Password" "Eski Parola") (cons "New Password" "Yeni Parola") (cons "New Password (verify)" "Yeni Parola (onay)") (cons "Change" "Güncelle") (cons "retry" "hata") (cons "Two passwords do not match." "Parolalar birbirini tutmuyor.") (cons "Do you want to retry?" "Tekrar denemek istiyor musunuz?") (cons "An error occurred." "Üzgünüm, sistemde bir hata oluştu.") (cons "thank you" "teşekkürler") (cons "Your credentials has been updated." "Parolanız güncellendi.") (cons "Thank you" "Teşekkürler") (cons "Yes" "Evet") (cons "No" "Hayır") (cons "Your password is too short." "Parolanız çok kısa.") (cons "Your email is invalid." "Eposta adresiniz geçersiz.") (cons "This field is required." "Bu alan zorunlu.") (cons "This box must be checked." "Bu kutu işaretli olmalı.") (cons "This field is required." "Bu alan zorunludur.") (cons "%1 is not a number." "%1 değeri sayı olmalıdır.") (cons "Enter a number" "Bir sayı girin") (cons "Enter a date" "Tarih seçin") ;; Authentication Manager (cons "Two passwords do not match." "Girdiğiniz iki parola birbirinden farklı.") (cons "Do you want to retry?" "Tekrar denemek ister misiniz?") (cons "Your credentials has been updated." "Parolanız güncellendi.") (cons "Thank you." "Teşekkür ederiz.") (cons "Authentication failed." "Giriş reddedildi.") (cons "Sorry, this email is already registered on our system." "Üzgünüm, bu eposta sistemde kayıtlı.") (cons "error" "hata") ;; Feedback Plugin (cons "Feedback" "Geri bildirim") (cons "Give us feedback or report a bug" "Öneri ve/veya şikayetlerinizi bildirin") (cons "Your feedback has been sent" "İstekleriniz kaydedildi") (cons "Thank you for your feedback" "Teşekkür ederiz") (cons "Feedback Console" "Geri Bildirim Paneli") (cons "Enter your name" "İsminiz") (cons "Enter your email" "Eposta adresiniz") (cons "Enter feedback subject" "İstek konusu") (cons "Date" "Tarih") (cons "Current URL" "URL") (cons "Browser" "İstemci yazılımı") (cons "Name" "İsim") (cons "Subject" "Konu") (cons "Feedback" "Geri Bildirim") (cons "Send" "Kaydet") (cons "Please fill the form below." "Lütfen aşağıdaki formu doldurun.") (cons "Thank you for your patience and cooperation." "Yardımlarınız ve işbiriliğiniz için teşekkür ederiz.") (cons "Please enter your feedback, question, or problem and please be descriptive." "Lütfen istek ve/veya probleminizi açıklayıcı olarak giriniz.") (cons "Remember that we read all inquiries and it takes time to resolve an issue." "Her iletiyi büyük bir titizlikle değerlendiriyoruz. Unutmayınız ki, değerlendirme süreci zaman alıyor. ") ;; Page Plugin ;; Plugin (cons "Page %1 is loaded." "%1 sayfası yüklendi.") (cons "Sorry, page %1 is not found." "Üzgünüm, %1 sayfası bulunamadı.") (cons "Configure Template" "Şablonu Düzenle") (cons "Configure common widgets" "Şablon ayaları, genel widgetlar") (cons "Page %1 is not found." "%1 sayfası bulunamadı.") (cons "Do you want to create?" "Yenisini oluşturmak ister misiniz?") (cons "new page" "yeni sayfa") (cons "Please enter a name for the new page:" "Yeni sayfanın ismini girin:") (cons "New Page" "Yeni Sayfa") (cons "Create a new page" "Yeni sayfalar oluşturun") (cons "Pages" "Sayfalar") (cons "Open a page on this site" "Sitedeki tüm sayfalar") ;; Page (cons "Last modified on" "Son değişiklik") (cons "Page" "Sayfa") (cons "copy" "kopya") (cons "Please enter a new name for this page:" "Sayfanın yeni ismini girin:") (cons "Page %1 is renamed to %2." "%1 sayfası, %2 olarak adlandırıldı.") (cons "delete" "sil") (cons "Do you really want to delete page %1?" "%1 sayfasını silmek üzeresiniz. Devam etmek istiyor musunuz?") (cons "Page %1 is deleted." "%1 sayfası silindi.") (cons "Please enter a name for the copy of this page:" "Sayfanın kopyası için yeni isim girin:") (cons "Page %1 is copied to %2." "%1 sayfası %2 sayfası olarak kopyalandı.") (cons "This page is" "Bu sayfa") (cons "published" "yayımda") (cons "not published" "yayımda değil") (cons "Rename Page" "Yeniden Adlandır") (cons "Rename this page" "Bu sayfayı yeniden adlandırın") (cons "Copy Page" "Kopyala") (cons "Make a new copy of this page" "Sayfanın kopyasını oluşturun") (cons "Delete Page" "Sayfayı Sil") (cons "Delete this page" "Bu sayfayı tümüyle kaldırın") (cons "Page %1 is published now." "%1 sayfası şu an yayımda.") (cons "Page %1 is unpublished." "%1 sayfası yayımdan kaldırıldı.") (cons "Add Widget" "Widget Ekle") (cons "Add a widget to the current page" "Sayfaya uygulamalar ekleyin") (cons "Publish/Unpublish" "Yayıma Al/Kaldır") (cons "Publish or unpublish current page" "Sayfayı yayıma alın veya yayımdan kaldırın") (cons "All Revisions" "Tüm Revizyonlar") (cons "Revisions of this page" "Sayfaya ait revizyonların listesi") (cons "Published" "Yayımda") ;; Template (cons "Template" "Şablon") (cons "Add a widget to this template" "Şablona yeni uygulama ekleyin") (cons "Return back to page editing" "Sayfa görünümüne geri dönün") (cons "Revisions of this template" "Şablona ait tüm revizyonların listesi") ;; Widget Mapping (cons "Relocate" "Konumlandır") (cons "Change visual place of this widget" "Uygulamayı sayfada başka yere taşıyın") (cons "This widget is disabled temporarily" "Bu uygulama geçici olarak devre dışı") (cons "please relocate or remove." "uygulamayı yeniden konumlandırın veya kaldırın.") (cons "remove" "kaldır") (cons "Do you really want to remove this widget?" "Bu uygulamayı kaldırmak istiyor musunuz?") (cons "Remove" "Kaldır") (cons "Remove this widget from the current page" "Bu uygulamayı sayfadan kaldırın") (cons "Stick/Unstick" "Yapıştır/Sök") (cons "Make this widget global (template) or local (page)" "Bu uygulama tüm sayfalarda olsun yada olmasın") (cons "Security Configuration" "Güvenlik Yapılandırması") (cons "Configure security rules of this widget" "Bu uygulamanin güvenlik ayarlarını oluşturun") ;; Revision (cons "Revision" "Revizyon") (cons "revert" "geri al") (cons "Do you really want to revert to this revision?" "Bu sayfanın eski sürümüne dönem istiyor musunuz?") (cons "Warning: All data in the [Latest Revision] will be lost." "Uyarı: Son sürümdeki değişiklikler kaybolabilir.") (cons "Revert" "Geri Al") (cons "Revert page to this revision" "Sayfanin bu sürümüne geri dönün") (cons "Publish" "Yayımla") (cons "Publish a snapshot of this page" "Bu sayfanın yeni sürümünü yayıma alın") (cons "snapshot" "yeni revizyon") (cons "Please enter a name for the snapshot of this page." "Yeni revizyon için isim girin.") (cons "publish" "yayıma al") (cons "Publish a snapshot of this page" "Sayfanın yeni revizyonunu alıp yayımlayın") (cons "Snapshot" "Yeni Revizyon") (cons "Create a new snapshot" "Sayfanın anlık yeni revizyonunu oluşturun") (cons "Add a widget to this revision" "Bu revizyona yeni uygulamalar ekleyin") ;; Example (cons "Basic" "Temel") (cons "Basic example pages" "Temel sayfa örnekleri") (cons "Front Page" "Ana Sayfa") (cons "Front page examples for your site" "Sitenizin ana sayfası için örnekler") ;; Widget (cons "Basic Widgets" "Temel Widgetlar") (cons "Basic building blocks of a site" "Sitenizin temel yapıtaşları") (cons "Widgets for your front page" "Ana sayfanız için widgetlar") (cons "Navigation" "Navigasyon") (cons "Widgets designed for site navigation" "Site navigasyonu için geliştirilmiş widgetlar") (cons "Data Collection" "Veri Toplama") (cons "Widgets providing forms" "Formlar, oylama vb.") (cons "Social Networks" "Sosyal Medya") (cons "Integrate your site with social networks" "Sosyal medya ile entegre olun") (cons "Other" "Diğer") (cons "More Coretal.net widget" "Siteniz için geliştirilmiş diğer widgetlar") ;; UI/Widget Node Selector (cons "Widget Location" "Widget Konumu") (cons "Please select a location from below." "Lütfen aşağıdan widget için konum seçin.") ;; UI/Security (cons "Object Ownership" "Nesnenin Sahipliği") (cons "Owner" "Sahip") (cons "Group" "Grubu") (cons "Permissions" "Hak ve Hukuk") (cons "Owner Permissions" "Sahip Hakları") (cons "Group Permissions" "Grup Hakları") (cons "Other Permissions" "Kayıtlı Kullanıcı Hakları") (cons "Anonymous Permissions" "Anonim Kullanıcı Hakları") (cons "Save" "Kaydet") (cons "Object Security Configuration" "Güvenli Nesne Yapılandırması") (cons "Please select the options from below." "Lütfen aşağıdaki seçenekleri değerlendirin.") ;; UI/Widget Selector (cons "No screenshots are available." "Üzgünüm, bu widget'a ait ekran görüntüsü bulunmuyor.") (cons "Widget Documentation" "Widget Belgelendirmesi") (cons "Add this widget" "Bu widgetı ekle") (cons "Description" "Açıklama ve Tanımlar") (cons "Widgets" "Widgetlar") (cons "Popular Widgets" "Popüler Widgetlar") (cons "add widget" "widget ekle") (cons "Screenshots" "Ekran Görüntüleri") (cons "References" "İlgili Bağlantılar") ;; UI/New Page Dialog (cons "create a new page" "yeni sayfa oluşturun") (cons "Create this page" "Bu sayfadan oluştur") (cons "Examples" "Örnekler") (cons "A New Page" "Yeni Sayfalar Oluşturun") (cons "Hello" "Merhaba") (cons "In this section, you can create new page on your site." "Bu bölümde, sitenizde yeni sayfalar oluşturabilirsiniz.") (cons "We have prepared example pages for you to build your site quickly." "Sayfalarınızı kolayca oluşturabilmeniz için, çeşitli örnekler hazırladık.") (cons "They are listed on the left column of this dialog." "Hazırladığımız örnekler, sayfanın sol tarafında yer almakta.") (cons "Most of the example page that we have prepared for you, have built-in widgets for your sites specific needs." "Örneklerimiz, ihtiyaçlarınızı karşılamak amacıyla bir araya getirilmiş widgetlardan oluşmaktadır.") (cons "You can read more about them by clicking on the specific example." "Detaylara ulaşmak için sol kolondaki örneklere tıklayabilirsiniz.") (cons "Moreover, you will be able to add more widgets after you create a new page." "Unutmayınız ki, yeni sayfanızı örneklerden oluşturduktan sonra, kalan ihtiyaçlarınız için yeni widgetlar ekleyebilirsiniz.") (cons "If you are unfamiliar with managing pages on your site, please refer to " "Eğer sayfaları nasıl yönetebileceğinizden emin değiseniz, ilgili belgelere göz atabilirsiniz, ") (cons "Coretal.net Site Editor's Guide" "Coretal.net Site Editörü Klavuzu") ;; Page Plugin/Widgets/Content (cons "Content" "İçerik") (cons "Cancel preview" "Ön-izlemeyi kapat") (cons "Return back to editing" "Düzenlemeye geri dönün") (cons "Cancel Editing" "Düzenlemeleri iptal et") (cons "Cancel without saving changes" "Değişiklikleri göz ardı edin") (cons "Save Content" "İçeriği Kaydet") (cons "Save contents of this widget" "Değişiklikleri kaydedin") (cons "Preview Changes" "Önizle") (cons "Preview changes uptill now" "Değişiklikleri gözleyin") (cons "Edit Content" "İçeriği Düzenle") (cons "Edit contents of this widget" "İçeriği güncelleyin, değiştirin") ;; Page Plugin/Widgets/Comment (cons "Anonymous" "Anonim") (cons "Do you really want to delete this comment?" "Bu yorumu silmek istiyor musunuz?") (cons "( %1 ) said on %2" "( %1 ) %2 tarihinde demiş ki:") (cons "Delete" "Sil") (cons "Comment(s)" "Yorum") (cons "Thank you. Your post is waiting to be approved." "Teşekkürler, yorumunuz onay için bekliyor.") (cons "Thank you for your post." "Teşekkürler, yorumunuz kaydedildi.") (cons "Type your comment here." "Yorumunuzu buraya yazın.") (cons "Post Comment" "Yorum gönderin") (cons "or" "yada") (cons "Login with" "Sosyal medya ile bağlan:") (cons "Please login to subscribe" "Takip etmek için bağlanın") (cons "Thank you, you are now subscribed." "Teşekkürler, artık takip etmeye başladınız.") (cons "Thank you, you are now unsubscribed." "Teşekkürler, takip listesinden çıkarıldınız.") (cons "Subscribe by email" "Eposta ile takip edeyim") (cons "Unsubscribe" "Artık takip etmek istemiyorum") (cons "Thank you." "Teşekkürler.") (cons "Post" "Gönder") (cons "Configure Comments" "Yorumları yapılandır") (cons "Configure this comment widget" "Yorum ayarlarını, onayları düzenleyin") (cons "Comments Configuration" "Yorum Yapılandırması") (cons "Please configure the options from below." "Lütfen aşağıdaki yapılandırmaları düzenleyin.") (cons "Show comments by default" "Yorumları açılışta göster") (cons "Increases page load time" "Sayfa geç yüklenebilir") (cons "Only authenticated users can comment" "Sadece kayıtllı kullanıcılar yorumlasın") (cons "Otherwise, everybody can comment" "Aksi takdirde, herkes yorum yapabilir") (cons "Comments are moderated" "Yorumlar onaylansın") (cons "Editors need to approve them" "Editörlerin her yorumu onaylamasını gerektirir") ;; Plugin/Page/Widgets/Form (cons "Your form has been submitted, thank you." "İletiniz kaydedildi, teşekkür ederiz.") (cons "An error occured while completing your request. Sorry for inconvenience." "Özür dileriz, isteğinizi gerçekleştirirken bir hata oluştu.") (cons "Edit Validations" "Geçerlilik Yapılandırması") (cons "Edit form element validations" "Form alanlarının geçerliliğini kontrol edin") (cons "Form Actions" "Form İşlevleri") (cons "Configure form action" "Formun işlevini belirleyin") (cons "Email address" "Eposta adresi") (cons "Enter an email" "Eposta adresi girin") (cons "Action" "İşlev") (cons "No action" "İşlevsiz") (cons "Email this form" "Bu formu eposta ile ilet") (cons "Form Action Configuration" "Form İşlev Yapılandırması") (cons "Field Configuration" "Alan Yapılandırmaları") (cons "Validation" "Geçerlilik testi") (cons "none" "hiçbiri") (cons "email" "eposta") (cons "password" "parola") (cons "required" "zorunlu") (cons "Validation Configuration" "Geçerlilik Yapılandırmaları") (cons "Fields" "Alanlar") (cons "Click to configure a field." "Alanın geçerlilik testini yapılandırmak için üzerine tıklayın.") ;; Plugin/Page/Widgets/Filter (cons "Filters" "Filtreler") (cons "Configure filters" "Filtrelerini ayarlayın") (cons "Filter by" "Aşağıdaki kritere göre filtre uygula") (cons " none (all items)" "Filtre yok, hepsini göster") (cons " query strings" "Sadece bu kelimeleri içerenler") (cons "Filter Configuration" "Filtreler") ;; Plugin/Page/Widgets/List (cons "A %1 widget" "Bir %1 widgetı") (cons "No %1(s) found." "Hiç %1 bulunamadı.") (cons "More %1(s)" "Daha fazla %1 göster") (cons "List Configuration" "Liste Ayarları") (cons "Listing mode, max items etc." "Listeleme türü, eleman sayısı vb.") (cons "All list items" "Tüm liste") (cons "sep. by spaces" "boşluklarla ayrılmış") (cons "Number of items" "eleman sayısı") (cons "Continuous" "Devamı yüklenen") (cons "Page View" "Sayfalara bölünmüş halde") (cons "Number of items to show" "Bu kadar eleman göster") (cons "Listing mode" "Listeleme türü") ;; Plugin/Page/Widgets/Map ;; empty ;; Plugin/Page/Widgets/Menu (cons "Configure Navigation" "Menü Yapılandırması") (cons "Configure & order links on this navigation" "Bağlantıları düzenleyin, sıralayın") (cons "Link Configuration" "Yönlendirme Yapılandırması") (cons "Link text" "Bağlantı yazısı") (cons "Map to.." "Tıklandığında..") (cons " an existing document" " mevcut sayfaya yönlensin") (cons " a page on internet" " internetteki bir sayfaya yönlensin") (cons "Load.." "Tıklandığında..") (cons "in current page" "mevcut pencerede açılsın") (cons "in new page" "yeni pencerede açılsın") (cons "Remove this link" "Bu bağlantıyı kaldır") (cons "Please click a link to configure." "Yapılandırmak için bağlantıya tıklayın.") (cons "Page1" "Sayfa1") (cons "Page2" "Sayfa2") (cons "Menu Configuration" "Menü Yapılandırması") (cons "New Menu Item" "Yeni Bağlantı") (cons "Menu highlight class name" "Menü vurgu sınıfı ismi (Hilight className)") (cons "Drag and drop to re-order menu items." "Sıralamak için sürükleyip bırakmayı kullanın.") (cons "Click on a link to change properties." "Özelliklerini düzenlemek için üzerine tıklayın.") ;; Plugin/Page/Widgets/Picasa (cons "Picasa image gallery at %1 is loaded" "Picasa resim galerisi yüklendi. (%1)") (cons "Please configure to enable this image gallery." "Resim galerisini çalıştırmak için lütfen yapılandırın.") (cons "Configure" "Yapılandır") (cons "Configure this Picasa Image Gallery" "Picasa resim galerisini yapılandırın") (cons "Enter username" "Kullanıcı adı") (cons "Small" "Küçük") (cons "Medium" "Orta") (cons "Large" "Büyük") (cons "Picasa Configuration" "Picasa Yapılandırması") (cons "Picasa Username:" "Picasa Kullanıcı Adı:") (cons "Picasa Album:" "Picasa Albümü:") (cons "Thumbnail size:" "Ufak resim boyutu:") ;; Plugin/Page/Widgets/Picasa Carousel (cons "Carousel Configuration" "Carousel Yapılandırması") (cons "Configure carousel of this widget" "Bu carouseli yapılandırın") (cons "Configure Carousel" "Carousel Yapılandırması") (cons "# of items" "Resim adedi") (cons "# of scrolls" "Geçişlerdeki resim adedi") (cons "Number of items:" "Gösterilen resim adedi:") (cons "Number of scrolls:" "Geçişlerdeki resim adedi:") (cons "Scroll speed:" "Geçiş hızı:") (cons "Orientation:" "Yerleşim planı:") (cons "Top - Horizontal" "Tepede - Yatay") (cons "Bottom - Horizontal" "Altta - Yatay") (cons "Left - Vertical" "Solda - Dikey") (cons "Right - Vertical" "Sağda - Dikey") (cons "Fast" "Hızlı") (cons "Normal" "Normal") (cons "Slow" "Yavaş") ;; Plugin/Page/Widgets/Slider (cons "Configure this Orbit Slider" "Orbit slider widgetı yapılandırın") (cons "Orbit Configuration" "Orbit Yapılandırması") (cons "Animation type:" "Animasyon türü:") (cons "Animation speed:" "Animasyon hızı:") (cons "Advance speed:" "Geçiş hızı:") (cons "Pause on hover?" "Üzerine geldiğinde dursun") (cons "Directional navigation?" "Geçiş düğmeleri gözüksün") ;; Plugin/Page/Widgets/Social (cons "Configure this Facebook Share widget" "Facebook Paylaşım widgetını yapılandırın") (cons "Facebook Configuration" "Facebook Yapılandırması") (cons "Configure this Twitter Share widget" "Twitter Paylaşım widgetını yapılandırın") (cons "Twitter Configuration" "Twitter Yapılandırması") (cons "Social Configuration" "Sosyal Paylaşım Yapılandırması") (cons "When clicked.." "Tıklandığında..") (cons " share the current page" "buludunğu sayfayı paylaşsın") (cons " share the following page:" " işaret ettiğim sayfayı paylaşsın") (cons "Share this page on %1" "Bu sayfayı %1 üzerinde paylaş") (cons "Configure social sharing settings" "Sosyal paylaşım yapılandırmasını düzenleyin") (cons "Social Share Configuration" "Sosyal Paylaşım Yapılandırması") (cons "Widget title:" "Başlık yazısı:") (cons "Select networks from below." "Kullanmak istediğiniz sosyal ağları seçin.") ;; Plugin/Page/Widgets/Tab (cons "Configure this Tab Widget" "Tab widgetı yapılandırın") (cons "Tab Widget Configuration" "Tab Widget Yapılandırması") (cons "Tab position:" "Tab pozisyonu") (cons "Hilight class:" "Vurgu sınıfı ismi (Hilight className):") (cons "Switch event:" "Geçiş türü:") (cons "onmouseover" "üzerine gelindiğinde") (cons "onclick" "tıklandığında") (cons "on the left" "sağda") (cons "on the right" "solda") (cons "at the top" "tepede") (cons "at the bottom" "altta") ;; Plugin/Page/Widgets/Template (cons "An error occurred while saving." "Kaydederken hata oluştu.") (cons "Sorry, an error occurred." "Üzgünüm, hata oluştu.") (cons "Save Template" "Şablonu Kaydet") (cons "Save template of this widget" "Widget şablonunu kaydedin") (cons "Widget Template" "Widget Şablonu") (cons "Edit Widget Template" "Şablonu Düzenle") (cons "Edit HTML template of this widget" "HTML şablonu düzenleyin") ;; Plugin/Page/Widgets/Ticker (cons "Sorry, ticker does not have any ticks yet." "Üzgünüm, ticker şu anda boş.") (cons "Configure this Ticker widget" "Ticker widgetıni yapılandırın") (cons "Ticker Configuration" "Ticker Yapılandırması") (cons "Ticker Rate (ms):" "Hız (ms):") (cons "Start Delay (ms):" "Başlangıç Duraksaması (ms):") (cons "Loop Delay (ms):" "Turlar arası Duraksama (ms):") (cons "Place Holder 1:" "Yardımcı karakter 1:") (cons "Place Holder 2:" "Yarcımdı karakter 2:") ;; Plugin/Page/Widgets/Twitter (cons "Configure Twitter settings" "Twitter ayarlarini yapilandirin") (cons "Show All Twits" "Tüm Twit'leri Göster") (cons "Twitter Configuration" "Twitter Yapılandırması") (cons "Twitter Username:" "Twitter Kullanıcı Adı:") (cons "List:" "Liste:") (cons "Poll for new results" "Yeni sonuçları otomatik çeksin") (cons "Include scrollbar" "Kaydırma çubuğu gözüksün") (cons "Show Timestamps" "Tarihleri göstersin") (cons "Show Avatars" "Kişi resimlerini göstersin") (cons "Show Hash Tags" "Konuları göstersin (Hash Tags)") (cons "Shell background color" "Kutu arka plan rengi") (cons "Shell text color" "Kutu yazı rengi") (cons "Tweet background color" "Twit arka plan rengi") (cons "Tweet text color" "Twit yazı rengi") (cons "Link color" "Bağlantı yazı rengi") (cons "Height" "Yükseklik") (cons "Width" "Genişlik") ;; Plugin/Blog/Plugin (cons "Please enter a name for the new blog:" "Yeni blog isim girin") (cons "New Blog" "Yeni Blog") (cons "Blog" "Blog") (cons "Manage blogs, add a new one" "Yeni blog ekleyin, diğerlerini yönetin") (cons "Create a new blog" "Yeni Blog Ekle") ;; Plugin/Blog/Example (cons "Blog plugin examples" "Blog Plugin Örnekleri") (cons "A Blog Page" "Blog Sayfası") (cons "Blog Index Page" "Blog Ana Sayfası") (cons "An index page for your blog" "BLogunuz için ana sayfa") ;; Plugin/Blog/Archive (cons "Blog Archive" "Bloglar Arşivi") ;; Plugin/Blog/Blog (cons "Enter a title for this blog" "Bu blog için başlık girin") (cons "Enter tags seperated by spaces" "Etiketleri boşluklu yazın") (cons "Edit Blog" "Düzenle") (cons "Edit this blog" "Blog'u düzenleyin, güncelleyin") ;; !Plugin/Blog/List (cons "Blog List" "Bloglar") (cons "Configure list settings" "Liste yapılandırması") (cons "Filters, number of items, etc." "Filtreler, gösterilen sayısı vb.") (cons "Edit blog template" "Blog Şablonu") (cons "Make blogs look pretty or awesome" "Blogların görünümünü düzenleyin") (cons "Blog List Configuration" "Blog Listesi Ayarları") (cons "Enter tags sep. by spaces" "Etiketleri boşluklu yazın") (cons "Enter search string to query" "Arama terimi") ;; Plugin/Blog/Search (cons "Blog Search" "Blog Arama") (cons "Enter search string" "Arama kriterini girin") ;; PLugin/Blog/Stats (cons "Blog Stats" "Blog İst.") (cons "Serving %1 blogs from %2 authors." "%2 yazardan toplam %1 blog sunulmakta.") (cons "Latest" "Son") (cons "is written by %1 on %2." "%1 tarafindan %2 tarihinde yazıldı.") ;; Plugin/Blog/Tags (cons "Blog Tags" "Blog Etkiketleri") (cons "No tags found." "Hiç etiket yok.") ;; Plugin/Blog/Filter (cons "Blog Filter Configuration" "Blog Filtreleri") (cons "blog tags" "blog etiketleri") ;; Plugin/Profile/Picture (cons "Picture" "Resim") )) (defparameter +language-packs+ (list (<core:language-pack :name "en") (<core:language-pack :name "tr" :pack +tr-data+))) (defparameter +default-language-pack+ (car +language-packs+)) (defun find-language-pack (lang) (find lang +language-packs+ :test #'string= :key #'name))
27,804
Common Lisp
.lisp
605
41.401653
132
0.710825
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
93525113aeed8f76217c0f14426c70eaadbc847618fe1fa0a8a339ba0af69ec0
8,349
[ -1 ]
8,350
plugin.lisp
evrim_core-server/src/web/coretal/plugin.lisp
(in-package :Core-server) (defclass+ plugin+ (component+) ()) (defclass+ plugin () () (:metaclass plugin+)) (defmacro defplugin (name supers slots &rest rest) `(defcomponent ,name (plugin ,@supers) ((,(plugin-instance-slot-name name) :host remote) ,@slots) ,@rest (:metaclass plugin+))) (defmethod component.instance-id ((self plugin)) (setf (slot-value self (plugin-instance-slot-name (class-name (class-of self)))) (call-next-method self))) (eval-when (:compile-toplevel :load-toplevel) (defun plugin-instance-slot-name (name) (intern (format nil "~A-INSTANCE-ID" name) (symbol-package name))) (defmethod component+.local-funkall-morphism ((class plugin+) name self args) (let* ((metaclass (class-name (class-of class))) (morphism (component+.morphism-function-name class name)) (arg-names (extract-argument-names args :allow-specializers t)) (slot-name (plugin-instance-slot-name (class-name class)))) `(defmethod ,morphism ((self ,metaclass)) `(method ,',arg-names (with-slots (session-id ,',slot-name) self (funkall self (+ "?s:" session-id "$k:" ,',slot-name "$method:" ,',(symbol-name name)) (create ,@',(nreverse (reduce0 (lambda (acc arg) (cons arg (cons (make-keyword arg) acc))) arg-names))))))))))
1,354
Common Lisp
.lisp
35
33.571429
82
0.650419
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
3d6641ff94ab5b2d068df19441ff1ca0849145f115ca6e460476779fe9050657
8,350
[ -1 ]
8,351
console.lisp
evrim_core-server/src/web/coretal/console.lisp
(in-package :core-server) ;; ------------------------------------------------------------------------- ;; Coretal Console ;; ------------------------------------------------------------------------- (defcomponent <core:console (<:div callable-component) ((showing-p :host remote :initform nil) (console-div :host remote :initform nil) (console-css :host remote :initform +console.css+) (title :host remote :initform "Console"))) (defmethod/remote get-title ((self <core:console)) (slot-value self 'title)) (defmethod/remote show-component ((self <core:console)) (load-css (console-css self)) (append (slot-value document 'body) self) (setf (showing-p self) t)) (defmethod/remote hide-component ((self <core:console)) (.remove-child (slot-value document 'body) self) (remove-css (console-css self)) (setf (showing-p self) nil)) (defmethod/remote call-component ((self <core:console)) (show-component self) (call-next-method self)) (defmethod/remote answer-component ((self <core:console) arg) (hide-component self) (destroy self) (call-next-method self arg)) (defmethod/remote destroy ((self <core:console)) (remove-class self "core") (remove-class self "core-console") (mapcar (lambda (a) (.remove-child self a)) (reverse (slot-value self 'child-nodes))) (call-next-method self)) (defmethod/remote do-close ((self <core:console)) (hide-component self) (destroy self)) (defmethod/remote init ((self <core:console)) (add-class self "core") (add-class self "core-console") (append self (<:div :class "title" (<:div (<:div :class "left" (_ (title self))) (<:div :class "right close" (<:a :onclick (lifte (do-close self)) :class "close-button" :title "close this log" (_ "close"))) (<:div :class "clear")))) (let ((_div (<:div))) (append self (<:div :class "body pad5" (setf (console-div self) _div))))) ;; ------------------------------------------------------------------------- ;; Toaster Task ;; ------------------------------------------------------------------------- (defcomponent <core:toaster-task (<:div) ((max-messages :host remote :initform 10) (message-timeout :host remote :initform 2000) (toaster-css :host remote :initform +toaster.css+) (taskbar :host remote) (_log-div :host remote) (_log-baloon :host remote) (is-open :host remote :initform nil))) (defmethod/remote do-close ((self <core:toaster-task)) (setf (is-open self) nil) (hide self)) (defmethod/remote do-open ((self <core:toaster-task)) (setf (is-open self) t) (show self)) (defmethod/remote destroy ((self <core:toaster-task)) (let ((baloon (_log-baloon self))) (.remove-child (slot-value baloon 'parent-node) baloon)) (.remove-child (slot-value document 'body) self) (call-next-method self)) (defmethod/remote init ((self <core:toaster-task)) (load-css (toaster-css self)) (add-class self "core-toaster") (add-class self "core") (append self (<:div :class "title" (<:div (<:div :class "left" (_ "Log Console")) (<:div :class "right close" (<:a :onclick (lifte self.do-close) :class "close-button" :title "close this log" (_ "close"))) (<:div :class "clear")))) (let ((_div (<:div :class "log" (<:div :class "toast" " ")))) (setf (_log-div self) _div) (append self _div)) (let ((_baloon (<:div :class "core core-toaster-baloon"))) (setf (_log-baloon self) _baloon) (append (slot-value document 'body) _baloon)) (hide self) (append (slot-value document 'body) self)) (defmethod/remote toast-to-console ((self <core:toaster-task) message) (let ((_div (_log-div self))) (when (> (slot-value (slot-value _div 'child-nodes) 'length) (max-messages self)) (.remove-child _div (slot-value _div 'first-child))) (append _div (<:div :class "toast" (date-to-string (new (*date))) " - " message)))) (defmethod/remote toast ((self <core:toaster-task) message) (toast-to-console self message) (when (null (is-open self)) (let ((_div (<:div :class "toast" message)) (_baloon (_log-baloon self))) (append _baloon _div) (show _baloon) (window.set-timeout (event () (let ((_children (slot-value _baloon 'child-nodes))) (if (eq 1 (slot-value _children 'length)) (progn (.remove-child _baloon _div) (hide _baloon)) (.remove-child _baloon _div)))) (message-timeout self)))))
4,468
Common Lisp
.lisp
115
34.895652
76
0.608595
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
255ff73588d36e804f1645cd626b7fed481e08d71329776b8041656a765f9f29
8,351
[ -1 ]
8,352
controller.lisp
evrim_core-server/src/web/coretal/controller.lisp
(in-package :core-server) ;; +------------------------------------------------------------------------- ;; | Portal Controller ;; +------------------------------------------------------------------------- (defcomponent <core:portal-controller (<core:taskbar) ((core-css :host remote :initform +core.css+) (default-page :host both :initform "index") (plugins :host both :initform nil :type plugin*) (v2-compat-mode :host both :initform nil) (greeting :host both :initform "[Core-serveR] ready.") (language :host both :initform (name +default-language-pack+)) (session-id :host both :initform nil) (loaded-p :host remote :initform nil) (language-pack :host remote :initform +default-language-pack+) (session-variable :host remote :initform "core-session"))) (defmethod shared-initialize :after ((self <core:portal-controller) slots &rest rest) (declare (ignore rest)) (setf (language-pack self) (or (find-language-pack (language self)) +default-language-pack+))) (defmethod/remote destroy ((self <core:portal-controller)) (remove-css (core-css self)) (call-next-method self)) (defmethod/remote load-plugins ((self <core:portal-controller)) (mapcar-cc (lambda (plugin) (_debug (list "Loading plugin" plugin)) (call/cc plugin self)) (plugins self))) (defmethod/remote redirect-page ((self <core:portal-controller) redirect-to) (setf window.location redirect-to) (suspend)) (defmethod/remote make-about-menu ((self <core:portal-controller)) (<:a :href "http://labs.core.gen.tr/" :target "_blank" (_ "About [Core-serveR]") (<:span :class "subtitle" (_ "Learn more about our server")))) (defmethod/remote init ((self <core:portal-controller)) (when (session-id self) (set-cookie (session-variable self) (session-id self))) (load-css (core-css self)) (setf +default-language+ (language self) (language-pack self) (make-component (language-pack self))) (call-next-method self) (load-plugins self) (setf (loaded-p self) t) (add-menu self (make-about-menu self)) (add-menu self (<:a :onclick (lifte (hide-taskbar self)) (_ "Close") (<:span :class "subtitle" (_ "Hide this taskbar")))) (when (greeting self) (toast self (greeting self)))) ;; ------------------------------------------------------------------------- ;; Authorize ;; ------------------------------------------------------------------------- (defmethod authorize ((application application) (user t) (self <core:portal-controller)) (<core:portal-controller :plugins (authorize application user (plugins self)) :default-page (default-page self) :v2-compat-mode (v2-compat-mode self) :language (language self) :greeting (greeting self) :session-id (session-id self) :session-variable (session-variable self)))
2,835
Common Lisp
.lisp
59
44.067797
88
0.621876
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
38b24aaac1930dbd4655f5d5ec5e1fce3708121485b5bb24ef037a545499c454
8,352
[ -1 ]
8,353
editor.lisp
evrim_core-server/src/web/components/editor.lisp
;; +------------------------------------------------------------------------- ;; | HTML Editors ;; +------------------------------------------------------------------------- (in-package :core-server) (defvar +ckeditor-toolbar+ (list (list "Source" "-" "Save" ;; "NewPage" "Preview" "-" "Templates" ) (list "Cut" "Copy" "Paste" "PasteText" "PasteFromWord" "-" "Print" "SpellChecker" "Scayt") (list "Undo" "Redo" "-" "Find" "Replace" "-" "SelectAll" "RemoveFormat") (list "Form" "Checkbox" "Radio" "TextField" "Textarea" "Select" "Button" "ImageButton" "HiddenField") "/" (list "Bold" "Italic" "Underline" "Strike" "-" "Subscript" "Superscript") (list "NumberedList" "BulletedList" "-" "Outdent" "Indent" "Blockquote" "CreateDiv") (list "JustifyLeft" "JustifyCenter" "JustifyRight" "JustifyBlock") (list "BidiLtr" "BidiRtl") (list "Link" "Unlink" "Anchor") (list "Image" "Flash" "MediaEmbed" "Table" "HorizontalRule" "Smiley" "SpecialChar" "PageBreak" "Iframe") "/" (list "Styles" "Format" "Font" "FontSize") (list "TextColor" "BGColor") (list "Maximize" "ShowBlocks" "-" "About"))) (defparameter +ckeditor-simple-toolbar+ (list (list "Cut" "Copy" "Paste" "PasteText") (list "Undo" "Redo" "-" "") (list "Bold" "Italic" "Underline" "Strike") ;; "/" (list "NumberedList" "BulletedList" "-" "Outdent" "Indent" "Blockquote") (list "JustifyLeft" "JustifyCenter" "JustifyRight" "JustifyBlock") (list "Link" "Unlink") ;; (list "TextColor" "BGColor") )) (defparameter +ckeditor-config+ (jobject :base-path "/js/ckeditor/" :extra-plugins "autogrow,mediaembed" :remove-plugins "maximize,resize" :toolbar +ckeditor-toolbar+ :toolbar-can-collapse nil)) (defparameter +ckeditor-simple-config+ (jobject :base-path "/js/ckeditor/" :extra-plugins "autogrow,mediaembed" :remove-plugins "maximize,resize" :skin "office2003" :toolbar-can-collapse nil :startup-focus t :toolbar +ckeditor-simple-toolbar+)) ;; ------------------------------------------------------------------------- ;; Ck Editor Form Field ;; ------------------------------------------------------------------------- (defcomponent <core:ckeditor (<core:validating-input) ((ckeditor-uri :host remote :initform +ckeditor.js+) (ckeditor-css :host remote :initform +ckeditor.css+) (config :host remote :initform +ckeditor-config+) (instance :host remote)) (:tag . "textarea")) (defmethod/remote get-input-value ((self <core:ckeditor)) (let ((instance (instance self))) (.update-element instance) (let ((data (aif (.get-snapshot instance) it (.get-data instance)))) (_debug (list "editor-data" data)) data) ;; (with-slots (get-snapshot get-data update-element) instance ;; (let* ((value1 (.apply get-snapshot instance (list))) ;; (value2 (.apply get-data instance (list))) ;; (value (if (and (not (eq value2 "")) ;; (not (null value2))) ;; value2 ;; value1))) ;; (if (or (null value) (eq "" value)) ;; (throw (new (*error (+ "Editor " (slot-value self 'id) ;; "is empty.")))) ;; value))) )) ;; CKEDITOR.instances[i].on ('click', function () ;; {alert ('test 1 2 3') ;; }) (defmethod/remote validate ((self <core:ckeditor)) (let ((instance (instance self))) (.update-element instance) (if instance (progn (.update-element instance) (let ((value (.get-snapshot instance))) (if (or (null value) (eq "" value)) "This field is empty." t))) ;; (with-slots (get-snapshot get-data update-element) instance ;; (let* ((value1 (.apply get-snapshot instance (list))) ;; (value2 (.apply get-data instance (list))) ;; (value (if (and (not (eq value2 "")) ;; (not (null value2))) ;; value2 ;; value1) )) ;; (if (or (null value) (eq "" value)) ;; "This field is empty." ;; t))) "This field is empty."))) (defmethod/remote destroy ((self <core:ckeditor)) (remove-css (ckeditor-css self)) (with-slots (instance) self (if instance (.apply (slot-value instance 'destroy) instance (list)))) (delete-slots self 'ckeditor-uri 'ckeditor-css 'config 'instance) (call-next-method self)) (defmethod/remote load-ckeditor ((self <core:ckeditor)) (load-css (ckeditor-css self)) (load-javascript (ckeditor-uri self) (lambda () (and (not (null -c-k-e-d-i-t-o-r)) (not (null (slot-value -c-k-e-d-i-t-o-r 'replace))))))) (defmethod/remote onchange ((self <core:ckeditor) e) (if (instance self) (.update-element (instance self))) (run-validator self) t) (defmethod/remote bind-editor ((self <core:ckeditor)) (load-ckeditor self) (if (slot-value *c-k-e-d-i-t-o-r.instances (slot-value self 'id)) (setf (slot-value self 'id) (random-string 5))) (with-slots (parent-node) self (cond ((or (null parent-node) (null (slot-value parent-node 'tag-name))) (make-web-thread (lambda () (bind-editor self)))) (t (let ((instance (-c-k-e-d-i-t-o-r.replace self (config self)))) (setf (instance self) instance) (.on instance "key" (event (e) (onchange self e))) (.on instance "blur" (event (e) (onchange self e))) (with-slots (form) self (when form (let ((onsubmit (slot-value form 'onsubmit))) (+ " " onsubmit) (setf (slot-value form 'onsubmit) (event (e) (make-web-thread (lambda () (destroy self window.k))) (.apply onsubmit this (list e)))))))))))) (defmethod/remote init ((self <core:ckeditor)) (bind-editor self) (call-next-method self)) ;; ------------------------------------------------------------------------- ;; Lazy Ck Editor Form Field ;; ------------------------------------------------------------------------- (defcomponent <core:lazy-ckeditor (<core:ckeditor) ((default-value :host remote)) (:default-initargs :config +ckeditor-simple-config+)) (defmethod/remote onfocus ((self <core:lazy-ckeditor) e) (when (null (instance self)) (with-slots (default-value value) self (if (eq default-value value) (setf (slot-value self 'value) ""))) (bind-editor self))) (defmethod/remote init ((self <core:lazy-ckeditor)) (with-slots (default-value value) self (if (null default-value) (setf (slot-value self 'default-value) value)) (if (or (null value) (eq "" value)) (setf (slot-value self 'value) (slot-value self 'default-value)))) self) ;; -------------------------------------------------------------------------- ;; Ck Editor ;; -------------------------------------------------------------------------- ;; (defcomponent ckeditor-component (callable-component) ;; ((instance :host remote) ;; (target :host remote) ;; (ckeditor-uri :host remote :initform +ckeditor-uri+) ;; (ckeditor-css :host remote :initform +ckeditor-css+) ;; (config :host remote :initform +ckeditor-config+))) ;; (defmethod/remote get-data ((self ckeditor-component)) ;; (let ((instance (instance self))) ;; (if instance ;; (.apply (slot-value instance 'get-snapshot) instance (list))))) ;; (defmethod/remote call-component ((self ckeditor-component)) ;; (_debug (list "ckeditor-config" (config self))) ;; (let* ((textarea (target self)) ;; (editor (-c-k-e-d-i-t-o-r.replace textarea (config self))) ;; (form (slot-value textarea 'form))) ;; (setf (instance self) editor) ;; (setf (slot-value form 'submit) ;; (event (e) ;; (let ((data (.get-snapshot editor))) ;; (try (.destroy editor) (:catch (err) nil)) ;; (with-call/cc ;; (make-web-thread ;; (lambda () ;; (answer-component self (list "save" data)))))) ;; (return false))) ;; (call-next-method self))) ;; (defmethod/remote destroy ((self ckeditor-component)) ;; (let ((_foo (event (e) (try (.destroy e) (:catch (err) nil))))) ;; (_foo (instance self)) ;; (delete-slot self 'instance) ;; (remove-css "http://www.coretal.net/style/ckeditor.css") ;; (call-next-method self))) ;; (defmethod/remote init ((self ckeditor-component)) ;; (load-css (ckeditor-css self)) ;; (load-javascript (ckeditor-uri self) ;; (lambda () ;; (and (not (null -c-k-e-d-i-t-o-r)) ;; (not (null (slot-value -c-k-e-d-i-t-o-r 'replace))))))) ;; ;; ------------------------------------------------------------------------- ;; ;; Supply CkEditor Mixin ;; ;; ------------------------------------------------------------------------- ;; (defcomponent supply-ckeditor () ;; ()) ;; (defmethod/local make-ckeditor ((self supply-ckeditor)) ;; (ckeditor-component)) ;; (defvar +fck-image-extensions+ '("bmp" "gif" "jpeg" "jpg" "png" "psd" "tif" "tiff")) ;; (defvar +fck-flash-extensions+ '("swf" "fla")) ;; (defvar +fck-media-extensions+ ;; '("aiff" "asf" "avi" "bmp" "fla" "flv" "gif" "jpeg" "jpg" ;; "mid" "mov" "mp3" "mp4" "mpc" "mpeg" "mpg" "png" "qt" ;; "ram" "rm" "rmi" "rmvb" "swf" "tif" "tiff" "wav" "wma" "wmv")) ;; ;; TODO: fix this ;; (defun/cc handle-fck-browse (path publish-path) ;; (let ((stream (http-response.stream (context.response +context+)))) ;; (labels ((send-error (number &optional message) ;; (string! stream (format nil "<Error number=\"~A\"" number)) ;; (if message (format nil "text=\"~A\"" message)) ;; (string! stream (format nil "/>~%"))) ;; (folder-pathname (folder) ;; (merge-pathnames ;; (make-pathname :directory (list :relative folder)) ;; (make-pathname :directory (pathname-directory (pathname path))))) ;; (files-by-extensions (folder-pathname exts) ;; (reduce #'(lambda (acc atom) ;; (append ;; (directory ;; (pathname ;; (format nil "~A*.~A" folder-pathname atom))) ;; acc)) ;; exts :initial-value nil)) ;; (files (folder-pathname type) ;; (string! stream (format nil "<Files>~%")) ;; (mapcar #'(lambda (file) ;; (when (pathname-name file) ;; (string! stream ;; (concatenate 'string ;; "<File name=\"" ;; (pathname-name file) "." (pathname-type file) ;; "\" size=\"" (format nil "~D" ;; (round ;; (/ (sb-posix:stat-size (sb-posix:stat file)) ;; 1000))) ;; "\" url=\"" publish-path)) ;; (mapcar #'(lambda (path) ;; (string! stream (concatenate 'string path "/"))) ;; (reverse ;; (set-difference ;; (pathname-directory file) ;; (pathname-directory (pathname path)) ;; :test #'equal))) ;; (string! stream ;; (concatenate 'string (pathname-name file) "." (pathname-type file) "\"/>" ~%)))) ;; (cond ;; ((equal type "Flash") (files-by-extensions folder-pathname +fck-flash-extensions+)) ;; ((equal type "Image") (files-by-extensions folder-pathname +fck-image-extensions+)) ;; ((equal type "Media") (files-by-extensions folder-pathname +fck-media-extensions+)) ;; (t (directory (pathname (format nil "~A*.*" folder-pathname)))))) ;; (string! stream (concatenate 'string "</Files>" ~%))) ;; (folders (folder-pathname) ;; (string! stream (concatenate 'string "<Folders>" ~%)) ;; (mapcar #'(lambda (dir) ;; (string! stream (concatenate 'string "<Folder name=\"" ;; (car (reverse (pathname-directory dir))) "\"/>" ~%))) ;; (directory ;; (make-pathname :directory (pathname-directory folder-pathname) ;; :name :wild))) ;; (string! stream (concatenate 'string "</Folders>" ~%))) ;; (create-folder (folder new-folder) ;; (let ((new-folder (make-pathname :directory (append (pathname-directory folder) ;; (list new-folder))))) ;; (if (probe-file new-folder) ;; (send-error 101) ;; (progn ;; (ensure-directories-exist new-folder) ;; (if (not (probe-file new-folder)) ;; (send-error 102)))))) ;; (create-file (folder file) ;; ;; (setf (get-header (context.response *context*) "Content-Type") "text/html; charset=utf-8") ;; ;; (if (rfc2388:mime-part-p file) ;; ;; (progn ;; ;; (save-mime-file ;; ;; file ;; ;; (make-pathname :directory (pathname-directory folder) ;; ;; :name (pathname-name (pathname (get-mime-filename file))) ;; ;; :type (pathname-type (pathname (get-mime-filename file))))) ;; ;; (<:script ;; ;; (<:js `(window.parent.*on-upload-completed 0 "" ,(get-mime-filename file) "")))) ;; ;; (<:script ;; ;; (<:js `(window.parent.*on-upload-completed 1 "" "" "Error.")))) ;; ;; (flush-request-response *context*) ;; (format t "creating file:~A in folder:~A" file folder) ;; (return-from handle-fck-browse nil))) ;; (with-query ((command "Command") (type "Type")) (context.request +context+) ;; (if (equal command "FileUpload") ;; (with-query ((folder "CurrentFolder") (file "NewFile")) (context.request +context+) ;; (create-file (folder-pathname folder) file))) ;; (xml/suspend ;; (lambda (stream) ;; (string! stream (format nil "<?xml version=\"1.0\" encoding=\"utf-8\" ?>~% ;; <Connector command=\"~A\" resourceType=\"~A\">~%" command type)) ;; ;; (describe (context.request *context*)) ;; (with-query ((folder "CurrentFolder")) (context.request +context+) ;; (string! stream (format nil "<CurrentFolder path=\"~A\" url=\"\"/>~%" folder)) ;; (cond ;; ((equal command "GetFolders") ;; (folders (folder-pathname folder))) ;; ((equal command "GetFoldersAndFiles") ;; (folders (folder-pathname folder)) ;; (files (folder-pathname folder) type)) ;; ((equal command "CreateFolder") ;; (with-query ((new-folder "NewFolderName")) (context.request +context+) ;; (create-folder (folder-pathname folder) new-folder))) ;; (t (send-error 1 "Error."))) ;; (string! stream "</Connector>")))))))) ;; (defcomponent fckeditor-component () ;; ()) ;; (defmethod/local fck-editor-config-url ((self fckeditor-component)) ;; (action/url () ;; (javascript/suspend ;; (lambda (stream) ;; (let ((path (format nil "~Aeditor/skins/silver/" +fckeditor-path+))) ;; (with-js (path) stream ;; (setf (aref *f-c-k-config.*toolbar-sets "CoreDefault") ;; (array ;; (array "Save" "Undo" "Redo" "-") ;; (array "Cut" "Copy" "Paste" "PasteText" "PasteWord") ;; (array "Bold" "Italic" "Underline" "StrikeThrough") ;; (array "OrderedList" "UnorderedList" "-" "Outdent" "Indent" "Blockquote") ;; (array "JustifyLeft" "JustifyCenter" "JustifyRight" "JustifyFull") ;; (array "TextColor" "BGColor") ;; (array "Image" "Flash" "Table" "Rule") ;; (array "Link" "Unlink" "Anchor") ;; (array "SpecialChar" "ShowBlocks" "-" "Source") ;; "/" ;; (array "FontFormat" "Style" "FontName" "FontSize")) ;; *f-c-k-config.*skin-path path ;; *f-c-k-config.*toolbar-can-collapse false))))))) ;; (defmethod/local fck-editor-browser-url ((self fckeditor-component)) ;; (action/url () ;; (handle-fck-browse (format nil "/var/www/~A/" (web-application.fqdn (application self))) ;; (format nil "/~A/" (web-application.fqdn (application self)))))) ;; (defjsmacro fckeditor-path () ;; +fckeditor-path+) ;; (defjsmacro fckeditor-url () ;; `(+ ,+fckeditor-path+ "fckeditor.js")) ;; (defjsmacro fckeditor-browser-url () ;; `(+ ,+fckeditor-path+ "editor/filemanager/browser/default/browser.html?Connector=")) ;; (defmethod/remote create-fck-editor ((self fckeditor-component) id width height) ;; (if (= "undefined" (typeof *f-c-keditor)) ;; (dojo.xhr-get (create :url (fckeditor-url) ;; :sync t ;; :handle-as "javascript"))) ;; (if (= "undefined" (typeof *f-c-k-editor)) ;; (let ((script (document.create-element "script"))) ;; (setf script.src (fckeditor-url)) ;; (.append-child (aref (document.get-elements-by-tag-name "head") 0) script))) ;; (let ((fck (new (*f-c-keditor id width height))) ;; (config (slot-value fck '*config)) ;; (browse-path (+ (fckeditor-browser-url) ;; base-url ;; (.replace ;; (.replace (.replace (this.fck-editor-browser-url) "&" "%26") "&" "%26") ;; "?" "%3F")))) ;; (setf fck.*toolbar-set "CoreDefault" ;; fck.*base-path (fckeditor-path) ;; config.*custom-configurations-path (+ base-url (this.fck-editor-config-url)) ;; config.*link-browser-u-r-l browse-path ;; config.*image-browser-u-r-l browse-path ;; config.*flash-browser-r-u-l browse-path ;; config.*link-upload false ;; config.*image-upload false ;; config.*flash-upload false) ;; (return fck))) ;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
17,645
Common Lisp
.lisp
393
42.442748
104
0.582451
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
0932f062dcd755829fb23f07f9cdaeb185bd33fbd71ee034da2562f9a7866a63
8,353
[ -1 ]
8,354
crud.lisp
evrim_core-server/src/web/components/crud.lisp
(in-package :core-server) ;; ------------------------------------------------------------------------- ;; Crud Component ;; ------------------------------------------------------------------------- (defcomponent <core:crud (<:div callable-component cached-component slot-representations) ((instance :host remote) (template-class :host remote) (title :host remote :initform "Please set crud title") (deletable-p :host both :initform t) (editable-p :host both :initform t) (crud-css :host remote :initform +crud.css+) (slot-editors :host remote :initform nil) (default-slot-editor :host remote :initform (<core:required-value-input)) (yes-no-dialog-ctor :host remote :initform (<core:yes-no-dialog)) (_template :host remote) (_result :host remote :initform (jobject)))) (defmethod/remote get-title ((self <core:crud)) (slot-value self 'title)) (defmethod/remote get-template-class ((self <core:crud)) (or (slot-value self 'template-class) (and (instance self) (slot-value (instance self) 'core-class)))) (defmethod/remote make-yes-no-dialog ((self <core:crud)) (yes-no-dialog-ctor self)) (defmethod shared-initialize :after ((self <core:crud) slots &rest initargs) (declare (ignore initargs)) (awhen (template-class self) (flet ((beautify (lst) (uniq (sort lst #'string< :key #'car) :test #'string= :key #'car))) (let ((slots (beautify (mapcar (lambda (attribute) (if (typep attribute 'jobject) (let ((type (get-attribute attribute :remote-type))) (if (and (null (get-attribute attribute :read-only)) type) (cons type it))))) (jobject.attributes it))))) (setf (slot-editors self) (beautify (remove-if (lambda (a) (or (null (car a)) (null (cdr a)))) (mapcar (lambda (remote-type) (cons (car remote-type) (%get-slot-editor self (car remote-type)))) slots)))))))) (defmethod/remote _get-slot-editor ((self slot-representations) slot) (with-slots (slot-editors) self (with-slots (remote-type) slot (let ((editor (find (lambda (a) (equal (car a) remote-type)) (slot-editors self)))) (if editor (car (cdr editor)) (default-slot-editor self)))))) (defmethod/remote edit-me ((self <core:crud) slot) (with-slots (reader name remote-type options size min-length) slot (flet ((set-ret (val) (setf (slot-value (_result self) name) val) val)) (let ((slot-editor (_get-slot-editor self slot)) (_value (if reader (reader (instance self)) (slot-value (instance self) name)))) (_debug (list "crud" "name" name "value" _value "remote-type" remote-type)) (let* ((_id (random-string)) (_span (<:span :class "validation " :id _id))) (list (cond ((eq "password" remote-type) ;; Needs two fields to compare (let* ((_button (<:input :type "button" :value (_"Change password"))) (_view _button) (_edit (make-component slot-editor :value _value :min-length min-length :validation-span-id _id))) (with-slots (style) _button (setf (slot-value style 'width) "130px" (slot-value style 'min-width) "130px") (connect _button "onclick" (lifte (replace-node _view (set-ret _edit))))) _view)) ((member remote-type '("number" "email")) ;; OK (set-ret (make-component slot-editor :value _value :validation-span-id _id))) ((eq remote-type "timestamp") (set-ret (make-component slot-editor :value _value :validation-span-id _id))) ((eq remote-type "checkbox") (set-ret (make-component slot-editor :value _value))) ((eq remote-type "date") (set-ret (make-component slot-editor :value _value :show-time nil :validation-span-id _id))) ((eq "html" remote-type) ;; OK (let* ((value (cond ((null _value) "") ((slot-value _value 'tag-name) (let ((div (<:div _value))) (slot-value div 'inner-h-t-m-l))) (t _value))) (textarea (<:textarea :name name :id (random-string) value)) (editor (call/cc slot-editor textarea))) (set-ret editor))) ((eq "select" remote-type) ;; OK (let ((_editor (make-component slot-editor :current-value _value :option-values options))) (set-ret _editor))) ((or (eq "multipleSelect" remote-type) (eq "multiple-select" remote-type)) (let ((_editor (make-component slot-editor :current-value _value :option-values options :size (or size 5)))) (set-ret _editor))) ((or (eq "multiple-checkbox" remote-type) (eq "multipleCheckbox" remote-type)) (let ((_editor (make-component slot-editor :current-value _value :option-values options))) (set-ret _editor))) (t (set-ret (make-component (default-slot-editor self) :value _value :validation-span-id _id)))) _span)))))) (defmethod/remote view-me ((self <core:crud) slot) (let ((value (get-slot-view self slot (instance self)))) (<:span (or value "Not set")))) (defmethod/remote do-edit ((self <core:crud)) (let ((_template (_template self))) (setf (_template self) (replace-node _template (edit-template self))))) (defmethod/remote get-label ((self <core:crud) label) (if (eq "?" (car (reverse label))) label (+ label ":"))) (defmethod/remote view-buttons ((self <core:crud)) (let ((_edit (<:input :type "button" :value "Edit" :title "Edit this instance" :onclick (lifte (do-edit self)))) (_delete (<:input :type "button" :value "Delete" :title "Delete this instance" :onclick (lifte (do-delete1 self))))) (with-slots (editable-p deletable-p) self (cond ((and editable-p deletable-p) (list _edit _delete)) (editable-p (list _edit)) (deletable-p (list _delete)))))) (defmethod/remote view-template ((self <core:crud)) (<:div (<:form (mapcar-cc (lambda (slot) (with-slots (name label read-only) slot (with-field (get-label self label) (view-me self slot)))) (reverse (reverse (get-template-class self)))) (<:p :class "buttons" (view-buttons self))))) (defmethod/remote do-cancel ((self <core:crud)) (let ((_template (_template self))) (setf (_template self) (replace-node _template (view-template self))))) (defmethod/remote do-save1 ((self <core:crud)) ;; (_debug (list "result" (_result self))) (let ((_result (mapobject (lambda (k v) (get-input-value v)) (_result self)))) ;; (_debug (list "crud result" _result)) (answer-component self (list "update" _result)))) (defmethod/remote do-delete1 ((self <core:crud)) (if (call-component (make-component (make-yes-no-dialog self) :title "delete" :message (+ "Do you really want to" " delete this item?"))) (answer-component self (list "delete" (instance self))))) (defmethod/remote edit-template ((self <core:crud)) (<:div (<:form :onsubmit (lifte (do-save1 self)) (mapcar-cc (lambda (slot) (with-slots (name label read-only remote-type) slot (cond (read-only (with-field (get-label self label) (<:div :class "value-view" (view-me self slot)))) (t (destructuring-bind (editor span) (edit-me self slot) (with-field (<:div :class "label-edit" label ": ") (list editor span))))))) (reverse (reverse (get-template-class self)))) (<:p :class "buttons" (<:input :type "submit" :value "Save" ;; :disabled t ;; :onclick (lifte (do-save1 self)) ) (<:input :type "button" :value "Cancel" :onclick (lifte (do-cancel self))))))) (defmethod/remote remove-child-nodes ((self <core:crud)) (mapcar-cc (lambda (a) (.remove-child self a)) (reverse (slot-value self 'child-nodes)))) (defmethod/remote destroy ((self <core:crud)) (remove-css (crud-css self)) (remove-class self "crud") (remove-class self "core") (remove-child-nodes self) (call-next-method self)) (defmethod/remote init ((self <core:crud)) (load-css (crud-css self)) (add-class self "crud") (add-class self "core") (if (title self) (append self (<:h2 (title self)))) (let ((_instance (instance self))) (if (and _instance (typep _instance 'function)) (setf (instance self) (make-component _instance)))) (append self (setf (_template self) (view-template self)))) (defmacro defwebcrud (name supers slots &rest rest) `(defcomponent ,name (,@supers <core:crud) () (:default-initargs :template-class ,(%generate-template-class slots) ,@(cdr (flatten1 rest))))) ;; old edit-me ;; (flet ((default-onchange (name) ;; (event (e) ;; (with-slots (_result) self ;; (setf (slot-value _result name) this.value)))) ;; (multi-checkbox-onchange (name) ;; (event (e) ;; (let ((value this.value)) ;; (with-slots (_result) self ;; (if this.checked ;; (setf (slot-value _result name) ;; (cons value ;; (filter (lambda (a) (not (eq a value))) ;; (slot-value _result name)))) ;; (setf (slot-value _result name) ;; (filter (lambda (a) (not (eq a value))) ;; (slot-value _result name)))))) ;; t))) ;; (with-slots (reader name type options size) slot ;; (let ((value (if reader ;; (reader (instance self)) ;; (slot-value (instance self) name)))) ;; (cond ;; ((eq type "select") ;; (<:select :onchange (default-onchange name) ;; (mapcar-cc (lambda (option) ;; (if (eq option value) ;; (<:option :selected t option) ;; (<:option option))) ;; options))) ;; ((eq type "multiple-select") ;; (setf (slot-value (_result self) name) value) ;; (<:div ;; (mapcar ;; (lambda (option) ;; (<:div ;; (<:div :class "left pad5" ;; (if (member option value) ;; (<:input :type "checkbox" :value option ;; :checked t :name option ;; :onchange (multi-checkbox-onchange name)) ;; (<:input :type "checkbox" :value option ;; :name option ;; :onchange (multi-checkbox-onchange name)))) ;; (<:div :class "pad5" option))) ;; options))) ;; ((eq type "password") ;; (<:input :type "password" :name name :value "" ;; :onchange (default-onchange name))) ;; ((eq type "html") ;; (let* ((value (cond ;; ((null value) "") ;; ((not (null (slot-value value 'tag-name))) ;; (let ((div (<:div value))) ;; (slot-value div 'inner-h-t-m-l))) ;; (t value))) ;; (textarea (<:textarea :name name :id (random-string) value)) ;; (editor (call/cc (_ckeditor self) textarea))) ;; (setf (slot-value textarea 'onchange) ;; (compose-prog1 (slot-value textarea 'onchange) ;; (default-onchange name))) ;; editor)) ;; (t ;; (<:input :type "text" :name name :value value ;; :onchange (default-onchange name)))))))
10,999
Common Lisp
.lisp
284
34.190141
76
0.600094
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
2e092494618f48a80db1bd6f49abcd56dabfed86733eb4221efd09735170802a
8,354
[ -1 ]
8,355
picasa.lisp
evrim_core-server/src/web/components/picasa.lisp
(in-package :core-server) (defcomponent supply-picasa () ()) (defmethod %get-albums ((self supply-picasa) user) (awhen (http :url (format nil +picasa-user-format-string+ user)) (let* ((entity it) (albums (xml-search entity (lambda (a) (typep a '<atom:entry))))) (mapcar (lambda (album) (flet ((foo (a) (car (xml.children (car a))))) (cons (foo (xml-search album (make-xml-type-matcher '<atom:title))) (foo (xml-search album (make-xml-type-matcher '<gphoto:id)))))) albums)))) (defmethod/cc get-albums ((self supply-picasa) user) (%get-albums self user)) (defmethod %get-photos ((self supply-picasa) user album) (flet ((search-for (root type) (xml-search root (make-xml-type-matcher type)))) (flet ((get-url (photo) (slot-value (car (search-for photo '<media:content)) 'core-server::url)) (get-name (photo) (aif (car (search-for photo '<media:description)) (car (xml.children it)) (car (xml.children (car (search-for photo '<media:title)))))) (get-date (photo) (car (xml.children (car (search-for photo '<atom:published))))) (get-thumbnails (photo) (nreverse (mapcar (lambda (thumb) (jobject :width (slot-value thumb 'core-server::width) :height (slot-value thumb 'core-server::height) :url (slot-value thumb 'core-server::url))) (search-for photo '<media:thumbnail))))) (awhen (http :url (format nil +picasa-album-format-string+ user album) :cache-p t) (let* ((entity it) (photos (xml-search entity (make-xml-type-matcher '<atom:entry)))) (nreverse (mapcar (lambda (photo) (jobject :thumbnails (get-thumbnails photo) :url (get-url photo) :name (get-name photo) :date (get-date photo))) photos))))))) (defmethod/cc get-photos ((self supply-picasa) user album) (%get-photos self user album))
1,926
Common Lisp
.lisp
52
31.519231
69
0.631889
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
c29648ee0e8847f5bdef5fccff4f4b85e7e402ba5a5b59f19287ff384d545213
8,355
[ -1 ]
8,356
representations.lisp
evrim_core-server/src/web/components/representations.lisp
(in-package :core-server) ;; ------------------------------------------------------------------------- ;; Slot Representations ;; ------------------------------------------------------------------------- (defcomponent slot-representations () ()) (defmethod/remote get-slot-view ((self slot-representations) _slot _instance) (with-slots (name remote-type options size reader) _slot (let ((_value (if reader (reader _instance) (slot-value _instance name)))) (cond ((eq "password" remote-type) "********") ((or (eq "number" remote-type) (eq "email" remote-type)) _value) ((and _value (eq "date" remote-type)) (take 10 (date-to-string (lisp-date-to-javascript _value)))) ((and _value (eq "timestamp" remote-type)) (date-to-string (lisp-date-to-javascript _value))) ((eq remote-type "checkbox") (<:input :type "checkbox" :checked (if _value t nil) :disabled t)) ((eq "html" remote-type) (cond ((null _value) nil) ((not (null (slot-value _value 'tag-name))) _value) (t (let ((div (<:div))) (setf (slot-value div 'inner-h-t-m-l) _value) div)))) ((eq "select" remote-type) _value) ((or (eq "multiple-select" remote-type) (eq "multiple-checkbox" remote-type) (eq "multipleCheckbox" remote-type) (eq "multipleSelect" remote-type)) (reduce-cc (lambda (acc atom) (+ acc ", " atom)) (cdr _value) (car _value))) ((null _value) "Not set") (t _value))))) (defmethod %get-slot-editor ((self slot-representations) remote-type) (cond ((equal "password" remote-type) (<core:password-combo-input)) ((equal "number" remote-type) (<core:number-value-input)) ((equal "email" remote-type) (<core:email-input)) ((equal "checkbox" remote-type) (<core:checkbox)) ((or (equal "date" remote-type) (equal "timestamp" remote-type)) (<core:date-time-input)) ((equal "html" remote-type) (<core:ckeditor :config core-server::+ckeditor-simple-config+)) ((equal "select" remote-type) (<core:select-input)) ((or (equal "multiple-select" remote-type) (equal "multipleSelect" remote-type)) (<core:multiple-select-input)) ((or (equal "multiple-checkbox" remote-type) (equal "multipleCheckbox" remote-type)) (<core:multiple-checkbox)) (t nil))) ;; ------------------------------------------------------------------------- ;; Helper For Defwebcrud & Deftable Macros ;; ------------------------------------------------------------------------- (defparameter +remote-types+ '(nil password number email date timestamp html select multiple-select multiple-checkbox checkbox)) (eval-when (:compile-toplevel :execute :load-toplevel) (defun %generate-template-class (slots) (flet ((process-slot (&key name remote-type reader label read-only options size min-length) (assert (member remote-type +remote-types+ :test #'string=) nil "Remote-type ~A should be one of ~A" remote-type +remote-types+) (list :name (symbol-to-js name) :label label :remote-type (if (and remote-type (symbolp remote-type)) (symbol-to-js remote-type) remote-type) :reader reader :read-only read-only :options options :size (or size 5) :min-length (or min-length 6)))) `(jobject ,@(reduce (lambda (acc slot) (append acc `(,(make-keyword (car slot)) (jobject ,@(apply #'process-slot (cons :name slot)))))) slots :initial-value nil)))))
3,456
Common Lisp
.lisp
85
36.141176
77
0.595663
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
872625fcaee6a64389479f1740c74ad8fb918fbb12666ed15b54bda71e8fff1c
8,356
[ -1 ]
8,357
dialog.lisp
evrim_core-server/src/web/components/dialog.lisp
(in-package :core-server) ;; +------------------------------------------------------------------------- ;; | Dialog ;; +------------------------------------------------------------------------- (defcomponent <core:dialog (<:div callable-component cached-component) ((overlay :host remote :initform nil) (message :host remote :initform "This is a message dialog.") (title :host remote :initform "message") (dialog-css :host remote :initform +dialog.css+) (_scroll :host remote :initform (list 0 0))) (:default-initargs :class "core core-dialog")) (defmacro/js message (self) `(get-message ,self)) (defmethod/remote get-message ((self <core:dialog)) (slot-value self 'message)) (defmacro/js title (self) `(get-title ,self)) (defmethod/remote get-title ((self <core:dialog)) (slot-value self 'title)) (defmethod/remote destroy ((self <core:dialog)) (hide-component self) (delete-slots self 'overlay 'message 'title 'css-url '_scroll) (call-next-method self)) (defmethod/remote call-component ((self <core:dialog)) (show-component self) (call-next-method self)) (defmethod/remote answer-component ((self <core:dialog) arg) (destroy self) (call-next-method self arg)) (defmethod/cc call-component ((self <core:dialog)) (call-next-method self)) (defmethod/cc answer-component ((self <core:dialog) arg) (call-next-method self arg)) (defmethod/remote show-component ((self <core:dialog)) (load-css (dialog-css self)) (setf (_scroll self) (list (or document.document-element.scroll-left window.page-x-offset) (or document.document-element.scroll-top window.page-y-offset))) (window.scroll 0 0) (prepend document.body (overlay self)) (prepend document.body self) (setf document.body.style.overflow "hidden")) (defmethod/remote hide-component ((self <core:dialog)) (remove-css (dialog-css self)) (setf document.body.style.overflow "visible") (.remove-child document.body self) (.remove-child document.body (overlay self)) (let ((scroll (_scroll self))) (window.scroll (car scroll) (car (cdr scroll))))) (defmethod/remote template ((self <core:dialog)) (<:div :class "center text-center" (<:div :class "left left-bg" (<:a :href "http://www.coretal.net/" "")) (<:div :class "right right-bg" (<:div :class "title" (title self)) (<:div :class "message" (message self)) (<:form :action "#" (<:input :type "button" :class "button" :value "OK" :onclick (lifte (answer-component self t))))))) (defmethod/remote init ((self <core:dialog)) (.append-child self (template self)) (setf (overlay self) (<:div :class "core-dialog-overlay"))) ;; ------------------------------------------------------------------------- ;; Supply Dialog Mixin ;; ------------------------------------------------------------------------- (defcomponent supply-dialog () ()) (defmethod/local make-dialog ((self supply-dialog)) (<core:dialog)) ;; +------------------------------------------------------------------------- ;; | Prompt Dialog ;; +------------------------------------------------------------------------- (defcomponent <core:prompt-dialog (<core:dialog) ()) (defmethod/remote template ((self <core:prompt-dialog)) (let ((_prompt (<:input :type "text" :name "prompt" :class "text"))) (<:div :class "center text-center" (<:div :class "left left-bg" (<:a :href "http://www.coretal.net/" "")) (<:div :class "right right-bg" (<:div :class "title" (title self)) (<:div :class "message" (message self)) (<:form :action "#" _prompt (<:div :class "buttons" (<:input :type "submit" :class "button" :value (_"OK") :onclick (lifte (answer-component self (slot-value _prompt 'value)))) (<:input :type "button" :class "button" :value (_"Cancel") :onclick (lifte (hide-component self))))))))) ;; ------------------------------------------------------------------------- ;; Supply Prompt Dialog Mixin ;; ------------------------------------------------------------------------- (defcomponent supply-prompt-dialog () ()) (defmethod/local make-prompt-dialog ((self supply-prompt-dialog)) (<core:prompt-dialog)) ;; +------------------------------------------------------------------------- ;; | Yes-No Dialog ;; +------------------------------------------------------------------------- (defcomponent <core:yes-no-dialog (<core:dialog) () (:default-initargs :title "yes/no" :message "Do you want to answer Yes?")) (defmethod/remote template ((self <core:yes-no-dialog)) (<:div :class "center text-center" (<:div :class "left left-bg" (<:a :href "http://www.coretal.net/" "")) (<:div :class "right right-bg" (<:div :class "title" (title self)) (<:div :class "message" (message self)) (<:form :action "#" (<:div :class "buttons" (<:input :type "button" :class "button" :value (_"Yes") :onclick (lifte (answer-component self t))) (<:input :type "button" :class "button" :value (_"No") :onclick (lifte (answer-component self nil)))))))) ;; ------------------------------------------------------------------------- ;; Supply Yes-no-dialog Mixin ;; ------------------------------------------------------------------------- (defcomponent supply-yes-no-dialog () ()) (defmethod/local make-yes-no-dialog ((self supply-yes-no-dialog)) (<core:yes-no-dialog)) ;; +------------------------------------------------------------------------- ;; | Login Dialog ;; +------------------------------------------------------------------------- (defcomponent <core:login-dialog (<core:dialog) ((default-email :host remote :initform "Email") (email-input :host remote :initform (<core:email-input)) (password-input :host remote :initform (<core:password-input))) (:default-initargs :title "login")) (defmethod/remote template ((self <core:login-dialog)) (let ((_email (call/cc (email-input self) (jobject :class-name "text" :type "text" :value (default-email self) :name "email" :validation-span-id "email-validation" :default-value "Email"))) (_password (call/cc (password-input self) (jobject :class-name "text" :default-value "password" :type "password" :name "password" :validation-span-id "password-validation")))) (<:div :class "center text-center" (<:div :class "left left-bg" (<:a :href "http://www.coretal.net/" "")) (<:div :class "right right-bg" (<:div :class "title" (title self)) (<:form :action "#" :onsubmit (event (e) (let ((password (slot-value _password 'value))) (with-call/cc (setf (slot-value _password 'value) nil) (answer-component self (cons (slot-value _email 'value) password)))) false) (with-field (<:span :class "validation" :id "email-validation" "Enter your email address") _email) (with-field (<:span :class "validation" :id "password-validation" "Enter your password") _password) (with-field "" (<:div (<:input :type "submit" :class "button" :value "login" :disabled t) (<:input :type "button" :class "button" :value "cancel" :onclick (lifte (hide-component self)))))))))) ;; +------------------------------------------------------------------------- ;; | Registration Dialog ;; +------------------------------------------------------------------------- (defcomponent <core:registration-dialog (<core:dialog) ((email-input :host remote :initform (<core:email-input))) (:default-initargs :title "register")) (defmethod/remote template ((self <core:registration-dialog)) (let ((_email (call/cc (email-input self) (jobject :class-name "text" :type "text" :name "email" :validation-span-id "email-validation" :default-value "Email")))) (<:div :class "center text-center" (<:div :class "left left-bg" (<:a :href "http://www.coretal.net/" "")) (<:div :class "right right-bg" (<:div :class "title" (title self)) (<:form :action "#" :onsubmit (lifte (answer-component self (slot-value _email 'value))) (with-field (<:span :class "validation" :id "email-validation" "Enter your email address") _email) (with-field "" (<:input :type "submit" :class "button" :value "login or register" :disabled t))))))) ;; ------------------------------------------------------------------------- ;; Forgot Password ;; ------------------------------------------------------------------------- (defcomponent <core:forgot-password-dialog (<core:dialog) ((email-input :host remote :initform (<core:email-input))) (:default-initargs :title "password")) (defmethod/remote template ((self <core:forgot-password-dialog)) (let ((_email (call/cc (email-input self) (jobject :class-name "text" :type "text" :name "email" :validation-span-id "email-validation" :default-value "Email")))) (<:div :class "center text-center" (<:div :class "left left-bg" (<:a :href "http://www.coretal.net/" "")) (<:div :class "right right-bg" (<:div :class "title" (title self)) (<:form :action "#" :onsubmit (lifte (answer-component self (slot-value _email 'value))) (with-field (<:span :class "validation" :id "email-validation" "Enter your email address") _email) (with-field "" (<:input :type "submit" :class "button" :value "send my password" :disabled t))))))) ;; ------------------------------------------------------------------------- ;; Big Dialog ;; ------------------------------------------------------------------------- (defcomponent <core:big-dialog (<core:dialog) () (:default-initargs :class "core core-big-dialog core-dialog" :title "Dialog")) (defmethod/remote dialog-buttons ((self <core:big-dialog)) (<:div :class "buttons right pad10" (<:input :type "button" :value "Close" :onclick (lifte (hide-component self))))) (defmethod/remote template ((self <core:big-dialog)) (<:div :class "center text-center" (<:div :class "left left-bg" (<:a :href "http://www.coretal.net/" "")) (<:div :class "right right-bg2" (<:div :class "title" (title self)) (<:div :class "bg-pad-top center text-center") (<:div :class "center content bg-white pad10" (message self)) (<:div :class "clear bg-pad-bottom center text-center") (dialog-buttons self)))) ;; ------------------------------------------------------------------------- ;; Full Screen Dialog ;; ------------------------------------------------------------------------- (defcomponent <core:fullscreen-dialog (<core:dialog) () (:default-initargs :class "core core-fullscreen-dialog" :title "")) (defmethod/remote template ((self <core:fullscreen-dialog)) (<:div :class "center text-center" (<:h1 "I am a fullscreen dialog") (<:p "Lorem ipsum .."))) (defmethod/remote init ((self <core:fullscreen-dialog)) (call-next-method self) (append self (<:a :onclick (lifte (hide-component self)) :title (_"Close") :class "close-button" (<:img :src (+ "http://www.coretal.net/" "style/images/close.jpg")))))
11,322
Common Lisp
.lisp
270
37.362963
80
0.545512
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
ad6ca048e0293b29197b85a579c1d9f3d525294a197b15f40ee86ad336ecc287
8,357
[ -1 ]
8,358
image.lisp
evrim_core-server/src/web/components/image.lisp
;; +---------------------------------------------------------------------------- ;; | Image Related ;; +---------------------------------------------------------------------------- (in-package :core-server) ;; ---------------------------------------------------------------------------- ;; Hedee Image Gallery ;; ---------------------------------------------------------------------------- (defun name-images-in-folder (pathname &optional (starting-from 0)) (mapcar #'(lambda (path seq) (shell :cmd (whereis "mv") :args (list path (make-pathname :directory (pathname-directory path) :type (string-downcase (pathname-type path)) :name (format nil "~2,'0D" seq))))) (sort (cl-fad:list-directory pathname) #'string< :key (compose #'string-downcase #'namestring)) (mapcar (curry #'+ starting-from) (seq (length (cl-fad:list-directory pathname)))))) (defun create-thumbnails (pathname &optional (height 150) (width 150)) (let ((thumbs-path (merge-pathnames #P"thumbs/" pathname))) (ensure-directories-exist thumbs-path) (mapcar #'(lambda (path) (when (or (equal (pathname-type path) "jpg") (equal (pathname-type path) "png") (equal (pathname-type path) "gif")) (shell :cmd (whereis "convert") :args (list "-thumbnail" (format nil "~Dx~D>" width height) path (make-pathname :name (pathname-name path) :type "jpg" :directory (pathname-directory thumbs-path) :defaults path))))) (cl-fad:list-directory pathname)))) (defcomponent hedee-component (toaster-component) ((root :host local :accessor hedee.root :initform (error "please specify hedee path") :initarg :root) (content-id :host remote :initform (error "please specify content id") :initarg :content-id) (offset :host remote :initform 0 :initarg :offset) (len :host remote :initform -1 :initarg :len))) (defmethod images-pathname ((self hedee-component)) (merge-pathnames (hedee.root self) (apache-web-application.docroot-pathname (application self)))) (defmethod filtered-list-directory ((self hedee-component)) (reduce (lambda (acc atom) (if (or (equal (string-downcase (pathname-type atom)) "jpg") (equal (string-downcase (pathname-type atom)) "jpeg") (equal (string-downcase (pathname-type atom)) "png") (equal (string-downcase (pathname-type atom)) "gif")) (cons atom acc) acc)) (cl-fad:list-directory (images-pathname self)) :initial-value nil)) (defmethod/local get-total ((self hedee-component)) (length (filtered-list-directory self))) (defmethod list-directory ((self hedee-component) offset length) (mapcar (lambda (atom seq) (cons seq atom)) (nthcdr offset (filtered-list-directory self)) (seq length))) ;; (defmethod/local template ((self hedee-component) offset length) ;; (flet ((image-src (path) ;; (let ((absolute-path (merge-pathnames ;; (make-pathname ;; :directory (cons :absolute ;; (cdr ;; (pathname-directory ;; (pathname (hedee.root self)))))) ;; path))) ;; (namestring (make-pathname :directory (cons :relative (nreverse (cons "thumbs" (nreverse (cdr (pathname-directory absolute-path)))))) ;; :name (pathname-name absolute-path) ;; :type (pathname-type absolute-path)))))) ;; (apply (curry #'<:div :class "hedee-images") ;; (reduce (lambda (acc atom) ;; (let ((seq (car atom)) ;; (path (cdr atom))) ;; (cons (<:div :id (format nil "hedee-div-~D" (+ offset seq)) ;; :class "hedee-div" ;; (<:a :id (format nil "hedee-a-~D" (+ offset seq)) ;; :class "hedee-a" ;; (<:img :id (format nil "~A/~A.~A" (hedee.root self) ;; (pathname-name (cdr atom)) ;; (pathname-type (cdr atom))) ;;(format nil "hedee-img-~D" (+ offset seq)) ;; :src (image-src (cdr atom)) ;; :class "hedee-img"))) ;; acc))) ;; (list-directory self offset length) ;; :initial-value nil)))) (defmethod/remote hide-image ((self hedee-component)) (let ((d (dijit.by-id "hedee-dialog"))) (if d (.hide d))) (return false)) (defmethod/remote show-image ((self hedee-component) image-source) (this.toast "Image loading, please hold...") (dojo.require "dijit.Dialog") (let ((div (document.create-element "DIV")) (img (document.create-element "IMG"))) (setf div.id "hedee-dialog" img.src image-source img.onclick (dojo.hitch this (lambda (e) (return (this.hide-image)))) img.title image-source img.onload (lambda (e) (if (dijit.by-id "hedee-dialog") (.destroy (dijit.by-id "hedee-dialog"))) (.show (new (dijit.*dialog (create :title "Hedee Image Gallery") div))) (return false))) (div.append-child img)) (return false)) (defmethod/remote setup ((self hedee-component)) (if (= "undefined" (typeof ($ this.content-id))) (return (this.toast (+ "Sorry, " this.content-id " not found, aborting hedee...")))) (.append-child ($ this.content-id) (this.template this.offset (if (> 0 this.len) (this.get-total) this.len))) (dolist (a (dojo.query (+ "#" this.content-id " a.hedee-a"))) (dojo.connect a "onclick" this (lambda (e) (return (this.show-image e.target.id))))) (return t)) (defun make-hedee (path id) (lambda (context) (with-context context (javascript/suspend (lambda (stream) (ctor! stream (make-instance 'hedee-component :root path :content-id id)) (with-js () stream (setf hedee (new (hedee-component))) (dojo.add-on-load (lambda () (hedee.setup))))))))) ;; ---------------------------------------------------------------------------- ;; Flickr ;; ---------------------------------------------------------------------------- ;; FIXME: Fix flickr component ;; Ref: http://www.flickr.com/services/api/request.rest.html ;; ;; The REST Endpoint URL is http://api.flickr.com/services/rest/ ;; ;; http://api.flickr.com/services/rest/?method=flickr.test.echo&name=value ;; ;; To return an API response in JSON format, send a parameter "format" ;; in the request with a value of "json". ;; (defparameter +flickr-auth-url+ "http://flickr.com/services/auth/?") ;; (defparameter +flickr-rest-url+ "http://api.flickr.com/services/rest/?") ;; (defparameter +flickr-static-url-part+ "static.flickr.com/") ;; (defcomponent flicr (ajax-mixin) ;; ((key :host local :initform "" :initarg :key ;; :documentation "api key") ;; (secret :host local :initform "" :initarg :secret ;; :document "secret") ;; (format :host remote :initform "json" :initarg :format ;; :documentation "response format"))) ;; ;; here implement them as javascript. ;; ;; (define (foldr f z xs) ;; ;; (if (null? xs) ;; ;; z ;; ;; (f (car xs) (foldr f z (cdr xs))))) ;; ;; (define (foldl f z xs) ;; ;; (if (null? xs) ;; ;; z ;; ;; (foldl f (f z (car xs)) (cdr xs)))) ;; (defmethod/remote send-query ((self flickr) method params) ;; (let ((url (+ +flickr-rest-url+ ;; "&method=" method ;; "&api_key=" (key self) ;; "&format=" (format self) ;; (if (equal (format self) "json") "&nojsoncallback=1") ;; (foldr (lambda (acc key) ;; (+ acc "&" key "=" (aref params key))) ;; "" ;; params))) ;; (req (make-request self))) ;; (let ((resp ((send-request self) req url))) ;; (return ;; (if (eql (format self) "json") ;; (eval (+ "(" resp.response-text ")")) ;; resp.response-x-m-l))))) ;; (defmethod/remote nsid ((self flickr) username) ;; (send-query "flickr.people.findByUsername" (+ "username=" username))) ;; (defmethod/remote search ((self flickr) nsid tags) ;; (send-query "flickr.photos.search" (+ "nsid=" nsid "&tags=" tags))) ;; (defmethod/remote get-photo-url ((self flickr) photo size type) ;; (return (+ "http://farm" photo.farm "." +flickr-static-url-part+ photo.server "/" photo.id "_" photo.secret "_" size ".jpg"))) ;; (defmethod/remote get-photo-url-original ((self flickr) photo type) ;; (return (+ "http://farm" photo.farm "." +flickr-static-url-part+ photo.server "/" photo.id "_o-" photo.secret "_o." type))) ;; "http://api.flickr.com/services/rest/?api_key=~A&format=~A&method=~A" ;; http://api.flickr.com/services/rest/?method=flickr.people.findByUsername&api_key=9d8b5b16b8b7ae6d0060f3cc24c6868f&username=c0r3&format=json ;; bir kullanıcının resimleri için önce o kullanıcının nsid'sini almamız lazım: ;; http://api.flickr.com/services/rest/?api_key=9d8b5b16b8b7ae6d0060f3cc24c6868f&format=json&method=flickr.people.findByUsername&username=~A& ;;; jsonFlickrApi({"user":{"id":"26659297@N03", "nsid":"26659297@N03", "username":{"_content":"c0r3"}}, "stat":"ok"}) ;; daha sonra bu nsid'yi kaydedeceğiz ve bununla bir arama sorgusu yapacağız. ;; http://api.flickr.com/services/rest/?api_key=9d8b5b16b8b7ae6d0060f3cc24c6868f&format=json&method=flickr.photos.search&user_id=8714164@N03 ;; jsonFlickrApi({"photos":{"page":1, "pages":1, "perpage":100, "total":"27", "photo":[{"id":"1607497377", "owner":"8714164@N03", "secret":"e86b25917f", "server":"2005", "farm":3, "title":"6649235-Full", "ispublic":1, "isfriend":0, "isfamily":0}, ;; {"id":"1607496947", "owner":"8714164@N03", "secret":"efacb636b9", "server":"2209", "farm":3, "title":"See ;; You in Hell (postcard)", "ispublic":1, "isfriend":0, "isfamily":0}, ;; {"id":"1607927086", "owner":"8714164@N03", "secret":"d5167dde4a", "server":"2264", "farm":3, "title":"6318226-Full", "ispublic":1, "isfriend":0, "isfamily":0}, ;; {"id":"1591179736", "owner":"8714164@N03", "secret":"063f6ceb5c", "server":"2008", "farm":3, "title":"6140418-Full", "ispublic":1, "isfriend":0, "isfamily":0}, ;; ...]}, "stat":"ok"}) ;; daha sonra bunları resim url'lerine çeviricez ;; http://www.flickr.com/services/api/misc.urls.html ;; http://farm1.static.flickr.com/2/1418878_1e92283336_m.jpg ;; farm-id: 1 ;; server-id: 2 ;; photo-id: 1418878 ;; secret: 1e92283336 ;; size: m ;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
10,899
Common Lisp
.lisp
210
48.185714
246
0.615602
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
e6443d1a4a72f7ee1767096c5b18b7fbeae64a1959b5ee6468c72baf26d765db
8,358
[ -1 ]
8,359
table-with-crud.lisp
evrim_core-server/src/web/components/table-with-crud.lisp
(in-package :core-server) ;; ------------------------------------------------------------------------- ;; Table w/ Crud Component ;; ------------------------------------------------------------------------- (defcomponent <core:table-with-crud (<:div) ((table :host remote :initform (error "Provide :table")) (crud :host remote :initform (error "Provide :crud")) (input-element :host remote :initform (<core:default-value-input :default-value "Enter key value (ie a key-value)")) (table-title :host remote :initform "Items") (_crud :host remote) (_table :host remote))) (defmethod/local get-instances ((self <core:table-with-crud)) (error "Please implement get-instances method.")) (defmethod/cc get-instances :around ((self <core:table-with-crud)) (authorize (component.application self) (query-session :user) (call-next-method self))) (defmethod/local add-instance ((self <core:table-with-crud) key) (error "Please implement add-instance method.")) (defmethod/cc add-instance :around ((self <core:table-with-crud) key) (authorize (component.application self) (query-session :user) (call-next-method self key))) (defmethod/local delete-instance ((self <core:table-with-crud) (instance remote-reference)) (error "Please implement delete-instance method.")) (defmethod/cc delete-instance :around ((self <core:table-with-crud) (instance remote-reference)) (authorize (component.application self) (query-session :user) (call-next-method self instance))) (defmethod/local update-instance ((self <core:table-with-crud) (instance remote-reference) args) (error "Please implement update-instance method.")) (defmethod/cc update-instance :around ((self <core:table-with-crud) (instance remote-reference) args) (authorize (component.application self) (query-session :user) (call-next-method self instance args))) (defmethod/remote make-table ((self <core:table-with-crud)) (let ((_instances (mapcar-cc (lambda (a) (if (typep a 'function) (make-component a) a)) (get-instances self)))) (make-component (table self) :instances _instances))) (defmethod/remote do-add-instance ((self <core:table-with-crud) key) (let ((_instance (add-instance self key))) (if _instance (add-instance (_table self) (make-component _instance))))) (defmethod/remote make-form ((self <core:table-with-crud)) (let* ((_id (random-string)) (_span (<:span :id _id :class "validation")) (val (make-component (input-element self) :validation-span-id _id))) (add-class val "width-250px") (add-class val "pad5") (<:form :onsubmit (lifte (progn (do-add-instance self (get-input-value val)) (reset-input-value val))) _span val (<:input :type "submit" :disabled t :value "Add")))) (defmethod/remote destroy ((self <core:table-with-crud)) (remove-class self "core") (if (and (_crud self) (slot-value (_crud self) 'destroy)) (destroy (_crud self))) (if (and (_table self) (slot-value (_table self) 'destroy)) (destroy (_table self))) (call-next-method self)) (defmethod/remote handle-crud ((self <core:table-with-crud) instance action args) (cond ((eq "delete" action) (when (delete-instance self instance) (with-slots (_crud) self (destroy _crud) (setf (_crud self) (replace-node _crud (<:div))) (remove-instance (_table self) instance)))) ((eq "update" action) (let ((updates (update-instance self instance args))) (cond ((typep updates 'function) (remove-instance (_table self) instance) (add-instance (_table self) (make-component updates))) (t (remove-instance (_table self) instance) (extend updates instance) (add-instance (_table self) instance))))) (t (_debug (list "crud" "action" action "args" args))))) (defmethod/remote _make-crud-component ((self <core:table-with-crud) instance) (make-component (crud self) :instance instance)) (defmethod/remote init ((self <core:table-with-crud)) (add-class self "core") (call-next-method self) (let ((form (make-form self)) (table (setf (_table self) (make-table self))) (crud (setf (_crud self) (<:div)))) (append self (<:div :class "heading" (<:h2 :class "left" (table-title self)) (<:div :class "right" form))) (append self table) (append self crud) (make-web-thread (lambda () (let* ((instance (call-component table)) (new-crud (_make-crud-component self instance))) (if (and (_crud self) (slot-value (_crud self) 'destroy)) (destroy (_crud self))) (setf (_crud self) (replace-node (_crud self) new-crud)) (make-web-thread (lambda () (destructuring-bind (action &rest args) (call-component new-crud) (handle-crud self instance action args)))))))))
4,845
Common Lisp
.lisp
110
39.5
76
0.654572
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
b8aeb6b47c1074901b08289647fac6793a314f8718920fe3625e1e730a2ff671
8,359
[ -1 ]
8,360
tab.lisp
evrim_core-server/src/web/components/tab.lisp
(in-package :core-server) ;; ------------------------------------------------------------------------- ;; Tab Component ;; ------------------------------------------------------------------------- (defcomponent <core:tab (<:div) ((tabs :host remote) (hilight-class :host remote :initform "hilight") (tab-title :host remote :initform "Tab Title") (nav-alignment :host remote :initform "right") (tab-css :host remote :initform +tab.css+) (default-tab :host remote :initform nil) (_content :host remote) (_nav :host remote) (_height :host remote :initform 0) (_offset :host remote :initform 0))) (defmethod/remote hilight-tab ((self <core:tab) tab) (mapcar (lambda (li) (let ((a (car (slot-value li 'child-nodes)))) (cond ((eq tab (slot-value a 'inner-text)) (add-class a (hilight-class self)) (add-class li (hilight-class self))) (t (remove-class a (hilight-class self)) (remove-class li (hilight-class self)))))) (slot-value (_nav self) 'child-nodes))) (defmethod/remote make-tab ((self <core:tab) tab) (reduce0-cc (lambda (acc a) (if (and (listp a) (eq tab (car a))) (let ((tab (car (cdr a)))) (if (typep tab 'function) (make-component tab) tab)) acc)) (tabs self))) (defmethod/remote maintain-height ((self <core:tab)) (with-slots (_offset style) self (with-slots (overflow) (get-style self) (when (not (equal overflow "hidden")) ;; don't do when overflow:hidden; (when (eq _offset 0) (setf (_offset self) (- (parse-int (slot-value (get-style self) 'height)) (parse-int (slot-value (get-style (_content self)) 'height))))) (let* ((content (_content self)) (height (parse-int (slot-value (get-style content) 'height))) (max-height (*math.max (_height self) height))) ;; (_debug (list "foo" height (_height self) max-height (_offset self))) (setf (slot-value (slot-value self 'style) 'min-height) (+ (+ max-height (_offset self)) "px") (_height self) max-height)))))) (defmethod/remote show-tab ((self <core:tab) tab) (hilight-tab self tab) (aif (make-tab self tab) (progn (describe (list "foo" it)) (setf (_content self) (replace-node (_content self) it)))) (maintain-height self)) (defmethod/remote navigation ((self <core:tab)) (let ((nav (<:ul :class "block" (mapcar-cc (lambda (tab) (<:li (<:a :onclick (lifte (show-tab self tab)) tab))) (mapcar (lambda (a) (if (atom a) a (car a))) (tabs self))))) (title (<:div (<:h2 (tab-title self))))) (add-class nav (nav-alignment self)) (setf (_nav self) nav) (if (equal (nav-alignment self) "right") (progn (add-class title "left") (<:div :class "core-tab-navigation" title nav (<:div :class "clear"))) (progn (add-class title "right") (<:div :class "core-tab-navigation" nav title (<:div :class "clear")))))) (defmethod/remote destroy ((self <core:tab)) (remove-class self "core-tab") (remove-class self "core") (call-next-method self)) (defmethod/remote init ((self <core:tab)) (call-next-method self) (load-css (tab-css self)) (add-class self "core-tab") (add-class self "core") (append self (navigation self)) (append self (<:div :class "clear")) (append self (setf (_content self) (<:p :class "pad10" "Please select an option from above."))) (if (default-tab self) (show-tab self (default-tab self))))
3,523
Common Lisp
.lisp
89
34.41573
81
0.590657
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
9b9db6bf1e72e6be96d1cafa9d3ed5641cebba79efda58e8f6d3897e80530cbc
8,360
[ -1 ]
8,361
extra.lisp
evrim_core-server/src/web/components/extra.lisp
;; +------------------------------------------------------------------------- ;; | Extra Components ;; +------------------------------------------------------------------------- (in-package :core-server) ;; ------------------------------------------------------------------------- ;; HTML Redirect ;; ------------------------------------------------------------------------- (defun <core:redirect (&key href (seconds 0)) (<:html (<:head (<:meta :http--equiv "Refresh" :content (format nil "~D; ~A" seconds href))) (<:body))) ;; ------------------------------------------------------------------------- ;; Simple Digital Clock ;; ------------------------------------------------------------------------- (defcomponent <core:simple-clock (<:div cached-component) ((_update-thread :host remote))) (defmethod/remote update-me ((self <core:simple-clock)) (setf (slot-value self 'inner-h-t-m-l) "") (let ((str (date-to-string (new (*date))))) (append self (<:p (take 10 str))) (append self (<:p (drop 13 str))))) (defmethod/remote destroy ((self <core:simple-clock)) (clear-timeout (_update-thread self)) (delete-slot self '_update-thread) (remove-class self "core-clock-widget") (call-next-method self)) (defmethod/remote init ((self <core:simple-clock)) (update-me self) (add-class self "core-clock-widget") (setf (_update-thread self) (set-interval (event () (update-me self window.k)) 1000))) ;; -------------------------------------------------------------------------- ;; Hilighter ;; -------------------------------------------------------------------------- (defcomponent hilighter () ((menu-query :host remote :accessor menu-query :initarg :menu-query :initform ".menu a") (active-class :host remote :initarg :active-class :initform "active") (passive-class :host remote :initarg :passive-class :initform ""))) (defmethod/remote hilight ((self hilighter) anchor) (dolist (item (dojo.query this.menu-query)) (if (= anchor (item.hash.substr 1)) (setf item.parent-node.class-name this.active-class item.class-name this.active-class) (setf item.parent-node.class-name this.passive-class item.class-name this.passive-class)))) ;; ------------------------------------------------------------------------- ;; Button Set ;; ------------------------------------------------------------------------- (defcomponent button-set (<:div) ((buttons :host remote :initform nil))) (defmethod/remote template ((self button-set)) (<:form (<:ul :class "inline" (mapcar (lambda (button) (<:li (<:input :type "button" :onclick (lambda (e) (make-web-thread (lambda () (answer-component self button))) false) :value (.to-string button)))) (buttons self))))) (defmethod/remote init ((self button-set)) (add-class self "button-set") (setf (slot-value self 'inner-h-t-m-l) nil) (.append-child self (template self)) self) ;; -------------------------------------------------------------------------- ;; Toaster Component ;; -------------------------------------------------------------------------- (defcomponent toaster-component (<:div) ()) (defmethod/remote template ((self toaster-component)) (list (<:img :src "style/login/loading.gif"))) (defmethod/remote init ((self toaster-component)) ;; (mapcar (lambda (e) (.append-child self e)) (template self)) (.append-child document.body self)) (defmethod/remote toast ((self toaster-component) msg) (let ((node (<:div :class "toast" msg))) (.append-child self node) msg)) ;; ------------------------------------------------------------------------- ;; History Component ;; ------------------------------------------------------------------------- (defcomponent history-component () ((timeout-id :host remote :initform 0) (listeners :host remote :initform nil) (current-hash :host remote :initform nil))) (defmethod/remote register-history-observer ((self history-component) thunk) (setf (listeners self) (cons thunk (listeners self)))) (defmethod/remote start-history-timeout ((self history-component)) (setf (current-hash self) window.location.hash) (setf (timeout-id self) (window.set-interval (event () (with-call/cc (when (not (eq (current-hash self) window.location.hash)) (setf (current-hash self) window.location.hash) (mapcar-cc (lambda (observer) (observer)) (listeners self))))) 400))) (defmethod/remote stop-history-timeout ((self history-component)) (window.clear-interval (timeout-id self))) (defmethod/remote init ((self history-component)) (call-next-method self) (start-history-timeout self)) ;; ------------------------------------------------------------------------- ;; History Change Mixin ;; ------------------------------------------------------------------------- (defcomponent history-mixin () ((running-p :host remote :initform nil) (current-hash :host remote :initform nil) (interval :host remote :initform 100) (history-observers :host remote :initform nil) (timeout-id :host remote :initform 0))) (defmethod/remote destroy ((self history-mixin)) (stop-history-timeout self) (call-next-method self)) (defmethod/remote register-history-observer ((self history-mixin) thunk) (setf (history-observers self) (cons thunk (history-observers self)))) (defmethod/remote unregister-history-observer ((self history-mixin) thunk) (setf (history-observers self) (remove thunk (history-observers self)))) (defmethod/remote on-history-change ((self history-mixin)) ;;(_debug (list "history-change" (current-hash self) window.location.hash)) (mapcar (lambda (observer) (call/cc observer window.location.hash)) (reverse (history-observers self)))) (defmethod/remote start-history-timeout ((self history-mixin)) (setf (current-hash self) window.location.hash) (labels ((timeout-loop () (when (slot-value self 'running-p) (when (not (= (current-hash self) window.location.hash)) (setf (current-hash self) window.location.hash) (on-history-change self)) (setf (timeout-id self) (window.set-timeout (event () (with-call/cc (call/cc timeout-loop))) (interval self)))))) (setf (running-p self) t) (call/cc timeout-loop))) (defmethod/remote stop-history-timeout ((self history-mixin)) (setf (running-p self) nil) (clear-timeout (timeout-id self)) (setf (timeout-id self) 0)) (defmethod/remote destroy ((self history-mixin)) (stop-history-timeout self) (delete-slots self 'running-p 'current-hash 'interval 'history-observers) (call-next-method self)) ;; ;; ------------------------------------------------------------------------- ;; ;; Orderable List ;; ;; ------------------------------------------------------------------------- ;; (defcomponent sortable-list-component (<:ul) ;; ()) ;; ;; function mouseCoords (ev) ;; ;; { ;; ;; if (ev.pageX || ev.pageY) ;; ;; { ;; ;; return {x:ev.pageX, y:ev.pageY}; ;; ;; } ;; ;; return { ;; ;; x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, ;; ;; y:ev.clientY + document.body.scrollTop - document.body.clientTop ;; ;; }; ;; ;;} ;; (defmethod/remote mouse-coordinates ((self sortable-list-component) event) ;; (cond ;; ((or (slot-value event 'page-x) (slot-value event 'page-y)) ;; (jobject :x (slot-value event 'page-x) ;; :y (slot-value event 'page-y))) ;; (t ;; (with-slots (scroll-left client-left scroll-top client-top) document.body ;; (jobject :x (- (+ (slot-value event 'client-x) scroll-left) ;; client-left) ;; :y (- (+ (slot-value event 'client-y) scroll-top) ;; client-top)))))) ;; ;; function getPosition (e) ;; ;; { ;; ;; 16 var left = 0; ;; ;; 17 var top = 0; ;; ;; 18 ;; ;; 19 while (e.offsetParent) ;; ;; { ;; ;; 20 left += e.offsetLeft; ;; ;; 21 top += e.offsetTop; ;; ;; 22 e = e.offsetParent; ;; ;; 23 } ;; ;; 24 ;; ;; 25 left += e.offsetLeft; ;; ;; 26 top += e.offsetTop; ;; ;; 27 ;; ;; 28 return {x:left, y:top}; ;; ;; 29} ;; (defmethod/remote node-coordinates ((self sortable-list-component) node) ;; (with-slots (offset-left offset-top offset-parent ;; offset-width offset-height child-nodes) node ;; (jobject :x (+ offset-left (if offset-parent ;; (slot-value offset-parent 'offset-left) ;; 0)) ;; :y (+ offset-top (if offset-parent ;; (slot-value offset-parent 'offset-top) ;; 0)) ;; :height offset-height ;; :width offset-width))) ;; (defmethod/remote get-drop-target ((self sortable-list-component) coords) ;; (car ;; (filter-cc (lambda (child) ;; (let ((target-coords (node-coordinates self child))) ;; (with-slots (x y height width) target-coords ;; (_debug (+ "x:" x ",y:" y ",height:" height ;; ",width:" width)) ;; (and (> (slot-value coords 'x) x) ;; (< (slot-value coords 'x) (+ x width)) ;; (> (slot-value coords 'y) y) ;; (< (slot-value coords 'y) (+ y height)))))) ;; (.get-elements-by-tag-name self "LI")))) ;; (defmethod/remote init ((self sortable-list-component)) ;; (let ((draggables (.get-elements-by-tag-name self "LI"))) ;; (mapcar-cc (lambda (draggable) ;; (setf (slot-value draggable 'onmousedown) ;; (lambda (e) ;; (_debug e) ;; (_debug this) ;; (let ((coord (mouse-coordinates self ;; (or e (extend window.event ;; (jobject)))))) ;; (_debug (+ " x:" (slot-value coord 'x) ;; " y:" (slot-value coord 'y)))))) ;; (setf (slot-value draggable 'onmouseup) ;; (lambda (e) ;; (_debug "up!") ;; (_debug (get-drop-target self ;; (mouse-coordinates self ;; (or e (extend window.event ;; (jobject))))))))) ;; draggables))) ;; ---------------------------------------------------------------------------- ;; Form ;; ---------------------------------------------------------------------------- ;; form component (defcomponent web-form-component (toaster-component) ((form-id :host remote :initarg :form-id :initform "feedback" :documentation "id of the form element"))) ;; return form element (defmethod/remote current-form ((self web-form-component)) (return ($ this.form-id))) ;; send form as html (defmethod/local sendform ((self web-form-component) form) (let ((f (format nil "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"></head><body><div id=\"form\">~A</div></body></html>" (cl-ppcre::regex-replace-all "\\\\n" form "")))) (sendmail (application.server (application self)) ;; mail-sender (format nil "noreply@~A" (web-application.fqdn (application self))) ;; from (web-application.admin-email (application self)) ;; to "A form has been submitted." ;; subject f ;; html-message ))) ;; add value attributes with current input values (defmethod/remote setformvals ((self web-form-component)) (.for-each (dojo.query "*" (this.get-form-id)) (lambda (i) (case (i.tag-name.to-lower-case) ("textarea" (i.append-child (document.create-text-node i.value))) ("input" (case i.node-type ("checkbox" false) ("radio" (when i.checked (i.set-attribute "checked" "true"))) (t (i.set-attribute "value" i.value)))))))) ;; initialize component, hook form's onsubmit (defmethod/remote initialize ((self web-form-component) obj) (if (= null (this.current-form)) (this.toast "Feedback div not found, aborting feedback component.") (let ((form (this.current-form))) (setf form.onsubmit (lambda () (let ((orig (.clone-node (obj.form) "deep"))) (.for-each (.filter (dojo.query "[type=radio]" (obj.get-form-id)) (lambda (e) (return e.checked))) (lambda (e) (e.parent-node.replace-child (document.create-text-node "X") e))) (obj.setformvals) (obj.sendform form.inner-h-t-m-l) (.parent-node.replace-child (obj.form) orig (obj.form)) (obj.toast "Form successfuly sent. Thank you.") (return false))))))) ;; (defurl *test* "forms.can" () ;; (javascript/suspend ;; (lambda () ;; (dojo "forms.can") ;; (mapcar #'send/component (list (make-instance 'web-form-component))) ;; (<:js ;; `(progn ;; (setf form (new (web-form-component))) ;; (dojo.add-on-load (lambda () ;; (form.initialize form)))))))) ;; ---------------------------------------------------------------------------- ;; Social Share ;; ---------------------------------------------------------------------------- (defcomponent socialshare-component (toaster-component) ((socialshare-id :host remote :initarg :socialshare-id :initform "socialshare" :documentation "id of the socialshare div element"))) (defmethod/remote make-link ((self socialshare-component) href text icon-url) (let ((a (document.create-element "A")) (img (document.create-element "IMG"))) (a.set-attribute "href" href) (a.set-attribute "title" text) (img.set-attribute "src" icon-url) (img.set-attribute "alt" text) (setf img.border "0") (a.append-child img) (return a))) ;; reddit, delicious, stumbleupon, digg, dzone (defmethod/remote make-type1-link ((self socialshare-component) base text icon url title) (return (this.make-link (+ base "?url=" (encode-u-r-i-component url) "&title=" title) text icon))) ;; yahoo, facebook (defmethod/remote make-type2-link ((self socialshare-component) base text icon url title) (return (this.make-link (+ base "?u=" (encode-u-r-i-component url) "&t=" title) text icon))) ;; google (defmethod/remote make-type3-link ((self socialshare-component) base text icon url title) (return (this.make-link (+ base "?op=edit&bkmk=" (encode-u-r-i-component url) "&title=" title) text icon))) ;; http://reddit.com/submit?url=...&title=... (defmethod/remote make-reddit-link ((self socialshare-component) url title) (return (this.make-type1-link "http://reddit.com/submit" "reddit" "http://www.core.gen.tr/images/sociallinks/reddit.gif" url title))) ;; http://www.google.com/bookmarks/mark?op=edit&bkmk=<url>&title=<title> (defmethod/remote make-google-link ((self socialshare-component) url title) (return (this.make-type3-link "http://www.google.com/bookmarks/mark" "google" "http://www.core.gen.tr/images/sociallinks/google.jpg" url title))) ;; http://del.icio.us/post?url=...&title=... (defmethod/remote make-delicious-link ((self socialshare-component) url title) (return (this.make-type1-link "http://del.icio.us/post" "del.icio.us" "http://www.core.gen.tr/images/sociallinks/delicious.gif" url title))) ;; http://www.stumbleupon.com/submit?url=...&title=... (defmethod/remote make-stumbleupon-link ((self socialshare-component) url title) (return (this.make-type1-link "http://www.stumbleupon.com/submit" "stumbleupon" "http://www.core.gen.tr/images/sociallinks/stumbleupon.gif" url title))) ;; http://digg.com/submit?url=...&title=... (defmethod/remote make-digg-link ((self socialshare-component) url title) (return (this.make-type1-link "http://digg.com/submit" "digg" "http://l.yimg.com/us.yimg.com/i/us/pps/digg.png" url title))) ;; http://www.dzone.com/links/add.html?url=...&title=... (defmethod/remote make-dzone-link ((self socialshare-component) url title) (return (this.make-type1-link "http://www.dzone.com/links/add.html" "dzone" "http://l.yimg.com/us.yimg.com/i/us/pps/dzone.png" url title))) ;; http://www.facebook.com/sharer.php?u=... (defmethod/remote make-facebook-link ((self socialshare-component) url title) (return (this.make-type2-link "http://www.facebook.com/sharer.php" "facebook" "http://www.core.gen.tr/images/sociallinks/facebook.gif" url title))) ;; http://myweb2.search.yahoo.com/myresults/bookmarklet?&u=...&t=.... (defmethod/remote make-yahoo-link ((self socialshare-component) url title) (return (this.make-type2-link "http://myweb2.search.yahoo.com/myresults/bookmarklet" "yahoo" "http://www.core.gen.tr/images/sociallinks/yahoo.jpg" url title))) (defmethod/remote make-socialshare-box ((self socialshare-component)) (let ((div (document.create-element "DIV"))) (div.append-child (this.make-google-link window.location document.title)) (div.append-child (this.make-facebook-link window.location document.title)) (div.append-child (this.make-delicious-link window.location document.title)) (div.append-child (this.make-reddit-link window.location document.title)) (div.append-child (this.make-stumbleupon-link window.location document.title)) (div.append-child (this.make-digg-link window.location document.title)) (div.append-child (this.make-dzone-link window.location document.title)) (div.append-child (this.make-yahoo-link window.location document.title)) (return div))) (defmethod/remote initialize ((self socialshare-component) obj) (aif ($ this.socialshare-id) (it.append-child (obj.make-socialshare-box)) (obj.toast (+ "div id \"" obj.socialshare-id "\" not found.")))) ;; ---------------------------------------------------------------------------- ;; Feedback ;; ---------------------------------------------------------------------------- (defcomponent feedback-component (toaster-component) ((feedback-id :accessor feedback-id :host remote :initform "feedback") (greeting-text :accessor greeting-text :host remote :initarg :greeting-text :initform "Please give us feedback to improve our site. Click here to enter.") (thank-text :accessor thank-text :host remote :initform "Thank you for giving us feedback." :initarg :thank-text) (feedback-from :accessor feedback-from :host local :initform "[email protected]"))) (defmethod/remote get-div ((self feedback-component)) (return ($ (this.get-feedback-id)))) (defmethod/local feedback-form ((self feedback-component)) (<:form (<:input :type "text" :id "feedback-text" :name "feedback-text"))) (defmethod/local send-feedback ((self feedback-component) feedback url) (prog1 'true (sendmail (application.server (application self)) (feedback-from self) (web-application.admin-email (application self)) "Feedback" (with-core-stream/cc (s "") (with-html-output s (<:html (<:head (<:title "Feedback")) (<:body (<:p (format nil "We have got a feedback for ~A." (web-application.fqdn (application self)))) (<:table (<:tr (<:td "Date:") (<:td (time->string (get-universal-time) :long))) (<:tr (<:td "Url:") (<:td url)) (<:tr (<:td "Text:") (<:td feedback)))))) (return-stream s))))) (defmethod/remote setup ((self feedback-component)) (if (= "undefined" (typeof (this.get-div))) (this.toast "Feedback div not found, aborting feedback component.")) (setf (slot-value (this.get-div) 'inner-h-t-m-l) "") (let ((form (this.feedback-form))) (.append-child (this.get-div) form) (let ((input ($ "feedback-text"))) (setf form.onsubmit (dojo.hitch this (lambda () (this.toast "Sending...") (this.send-feedback (escape input.value) (+ "" window.location)) (this.setup) (this.toast (this.get-thank-text)) (return false)))) (setf input.value (this.get-greeting-text) input.onfocus (dojo.hitch this (lambda () (if (= (this.get-greeting-text) input.value) (setf input.value "")))))))) ;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20,459
Common Lisp
.lisp
459
41.104575
209
0.601205
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
8754ca2d2da7a97c73493beb895304168aeb11d4ca17c2296dd1abcc598029cb
8,361
[ -1 ]
8,362
auth.lisp
evrim_core-server/src/web/components/auth.lisp
;; +------------------------------------------------------------------------- ;; | Authentication Components ;; +------------------------------------------------------------------------- (in-package :core-server) ;; -------------------------------------------------------------------------- ;; Login Box ;; -------------------------------------------------------------------------- (defcomponent <core:login (<:div callable-component) ((_password-input :host remote :initform (<core:password-input :min-length 5 :name "password" :default-value "Password")) (_username-input :host remote :initform (<core:required-value-input :name "username" :default-value "Username"))) (:default-initargs :id "loginBox")) (defmethod/local login-with-credentials ((self <core:login) username password) (answer (list username password))) (defmethod/remote do-login-with-credentials ((self <core:login) username password) (login-with-credentials self username password)) (defmethod/remote buttons ((self <core:login)) (with-field "" (<:input :type "submit" :class "button" :value "login" :disabled t))) (defmethod/remote template ((self <core:login)) (let ((_username (make-component (_username-input self) ;; :class-name "text" :validation-span-id "username-validation")) (_password (make-component (_password-input self) ;; :class-name "text" :validation-span-id "password-validation"))) (<:form :onsubmit (lifte (do-login-with-credentials self (get-input-value _username) (get-input-value _password))) (with-field _username (<:span :class "validation" :id "username-validation" "Enter your username")) (with-field _password (<:span :class "validation" :id "password-validation" "Enter your password")) (buttons self)))) (defmethod/remote destroy ((self <core:login)) (remove-class self "core") (call-next-method self)) (defmethod/remote init ((self <core:login)) (add-class self "core") (append self (template self))) ;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
2,798
Common Lisp
.lisp
60
43
82
0.633761
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
3774c36d5f13a3bd86a6b1c4ce566043ca58b924dfb931a67c1b3afd2a43f144
8,362
[ -1 ]
8,363
form.lisp
evrim_core-server/src/web/components/form.lisp
(in-package :core-server) ;; +------------------------------------------------------------------------- ;; | Form/Input Components ;; +------------------------------------------------------------------------- ;; +------------------------------------------------------------------------- ;; | Validting HTML Input ;; +------------------------------------------------------------------------- (defcomponent <core:validating-input (<:input cached-component) ((validation-span-id :host remote :initform nil) (valid-class :host remote :initform "valid") (invalid-class :host remote :initform "invalid") (valid :host remote :initform nil)) (:default-initargs :value "" :type "text")) (defmethod/remote set-validation-message ((self <core:validating-input) result msg) (awhen (validation-span-id self) (awhen (document.get-element-by-id it) (cond (result (add-class it (valid-class self)) (remove-class it (invalid-class self))) (t (add-class it (invalid-class self)) (remove-class it (valid-class self)))) (setf (slot-value it 'inner-h-t-m-l) msg)))) (defmethod/remote enable-or-disable-form ((self <core:validating-input)) (awhen (slot-value self 'form) ;; not avail at first run-validate (let* ((form it) (valid (reduce-cc (lambda (acc input) (cond ((or (eq (typeof (slot-value input 'valid)) "undefined") (slot-value input 'disabled)) acc) (t (and acc (valid input))))) (append (reverse (.get-elements-by-tag-name form "INPUT")) (append (reverse (.get-elements-by-tag-name form "SELECT")) (append (reverse (.get-elements-by-tag-name form "TEXTAREA")) (reverse (.get-elements-by-tag-name form "SPAN"))))) t))) (mapcar (lambda (input) (when (and (slot-value input 'type) (eq "SUBMIT" (.to-upper-case (slot-value input 'type)))) (cond (valid (setf (slot-value input 'disabled) false) (remove-class input "disabled")) (t (setf (slot-value input 'disabled) true) (add-class input "disabled")))) nil) (self.form.get-elements-by-tag-name "INPUT"))))) (defmethod/remote validate ((self <core:validating-input)) t) (defmethod/remote _validate ((self <core:validating-input)) (validate self)) (defmethod/remote run-validator ((self <core:validating-input)) (let ((result (_validate self))) (cond ((typep result 'string) (setf (valid self) nil) (set-validation-message self nil result) (add-class self (invalid-class self)) (remove-class self (valid-class self)) (enable-or-disable-form self)) (t (setf (valid self) t) (set-validation-message self t "OK") (add-class self (valid-class self)) (remove-class self (invalid-class self)) (enable-or-disable-form self))))) (defmethod/remote onchange ((self <core:validating-input) e) (run-validator self) t) (defmethod/remote onkeydown ((self <core:validating-input) e) (run-validator self) t) (defmethod/remote onkeyup ((self <core:validating-input) e) (run-validator self) t) (defmethod/remote get-input-value ((self <core:validating-input)) (cond ((eq "string" (typeof (validate self))) (throw (new (*error (+ "get-input-value called although" " input is invalid. Value:" (slot-value self 'value)))))) (t (slot-value self 'value)))) (defmethod/remote init ((self <core:validating-input)) (flet ((do-validate (f) (if (slot-value self 'form) (run-validator self) (make-web-thread (lambda () (f f)))))) (do-validate do-validate)) (with-slots (type) self (if (or (null type) (eq "" type)) (setf (slot-value self 'type) "text") (setf (slot-value self 'type) (+ (slot-value self 'type) ""))))) ;; +------------------------------------------------------------------------- ;; | Default Value HTML Input ;; +------------------------------------------------------------------------- (defcomponent <core:default-value-input (<core:validating-input) ((default-value :host remote :initform nil))) (defmethod/remote adjust-default-value ((self <core:default-value-input)) (cond ((equal self.default-value self.value) (setf self.value "")) ((equal "" self.value) (setf self.value self.default-value)))) (defmethod/remote onfocus ((self <core:default-value-input) e) (adjust-default-value self)) (defmethod/remote onblur ((self <core:default-value-input) e) (adjust-default-value self)) (defmethod/remote validate ((self <core:default-value-input)) (if (and (or (and (eq "INPUT" (slot-value self 'tag-name)) (or (eq "" (slot-value self 'type)) (eq "TEXT" (.to-upper-case (slot-value self 'type))) (eq "PASSWORD" (.to-upper-case (slot-value self 'type))))) (eq "TEXTAREA" (slot-value self 'tag-name))) (eq (slot-value self 'default-value) (slot-value self 'value))) (_"This field is required.") (call-next-method self))) (defmethod/remote reset-input-value ((self <core:default-value-input)) (setf (slot-value self 'value) "") (run-validator self)) (defmethod/remote init ((self <core:default-value-input)) (setf (slot-value self 'default-value) (_ (slot-value self 'default-value))) (if (null (slot-value self 'default-value)) (setf (slot-value self 'default-value) (slot-value self 'value))) (if (or (null (slot-value self 'value)) (eq "" (slot-value self 'value))) (setf (slot-value self 'value) (slot-value self 'default-value))) (call-next-method self)) ;; +------------------------------------------------------------------------- ;; | Email HTML Component ;; +------------------------------------------------------------------------- (defcomponent <core:email-input (<core:default-value-input) () (:default-initargs :default-value "Enter email")) (defmethod/remote validate-email ((self <core:email-input)) (let ((expression (regex "/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/"))) (if (.test expression self.value) t (_"Your email is invalid.")))) (defmethod/remote validate ((self <core:email-input)) (let ((result (call-next-method self))) (if (typep result 'string) result (validate-email self)))) ;; +------------------------------------------------------------------------- ;; | FQDN Input ;; +------------------------------------------------------------------------- (defcomponent <core:fqdn-input (<core:default-value-input) () (:default-initargs :default-value "Enter FQDN")) (defmethod/remote validate-fqdn ((self <core:fqdn-input)) (let ((expression (regex "/^([a-zA-Z0-9-]+\.)+[a-zA-Z0-9-]{2,8}$/"))) (if (.test expression self.value) t (_"Your FQDN is invalid.")))) (defmethod/remote validate ((self <core:fqdn-input)) (let ((result (call-next-method self))) (if (typep result 'string) result (validate-fqdn self)))) ;; +------------------------------------------------------------------------- ;; | Password HTML Component ;; +------------------------------------------------------------------------- (defcomponent <core:password-input (<core:default-value-input) ((min-length :initform 6 :host remote)) (:default-initargs :type "password" :default-value "Enter password")) (defmethod/remote adjust-default-value ((self <core:password-input)) (cond ((equal self.default-value self.value) (setf (slot-value self 'value) "" (slot-value self 'type) "password")) ((equal "" (slot-value self 'value)) (setf (slot-value self 'value) (slot-value self 'default-value) (slot-value self 'type) "text")))) (defmethod/remote validate-password ((self <core:password-input)) (cond ((or (null self.value) (< self.value.length self.min-length)) (_"Your password is too short.")) (t t))) (defmethod/remote validate ((self <core:password-input)) (let ((result (call-next-method self))) (if (typep result 'string) result (validate-password self)))) (defmethod/remote init ((self <core:password-input)) (call-next-method self) (setf (slot-value self 'type) "text") self) ;; +------------------------------------------------------------------------- ;; | Required Input ;; +------------------------------------------------------------------------- (defcomponent <core:required-value-input (<core:default-value-input) ()) (defmethod/remote validate-required-value ((self <core:required-value-input)) (cond ((or (equal (slot-value self 'type) "checkbox") (equal (slot-value self 'type) "radio")) (if (slot-value self 'checked) t (_"This box must be checked."))) (t (let ((_val (slot-value self 'value))) (if (or (null _val) (eq _val "")) (_"This field is required.") t))))) (defmethod/remote validate ((self <core:required-value-input)) (let ((result (call-next-method self))) (if (typep result 'string) result (validate-required-value self)))) ;; +------------------------------------------------------------------------- ;; | Number Input ;; +------------------------------------------------------------------------- (defcomponent <core:number-value-input (<core:default-value-input) () (:default-initargs :default-value "Enter a number")) ;; FIXME: validate loses cc. (defmethod/remote get-input-value ((self <core:number-value-input)) ;; (if (not (eq "string" (typeof (validate self)))) ;; (parse-float (slot-value self 'value))) (parse-float (slot-value self 'value))) (defmethod/remote validate-number ((self <core:number-value-input)) (let ((_val (slot-value self 'value))) (try (if (eq (typeof (eval _val)) "number") t (_ "%1 is not a number." _val)) (:catch (e) (_"%1 is not a number." _val))))) (defmethod/remote validate ((self <core:number-value-input)) (let ((result (call-next-method self))) (if (typep result 'string) result (validate-number self)))) ;; ------------------------------------------------------------------------- ;; Date Input ;; ------------------------------------------------------------------------- (defcomponent <core:date-time-input (<core:validating-input supply-jquery-ui) ((jquery-date-time-picker-uri :host remote :initform +jquery-date-time-picker.js+) (jquery-date-time-picker-css :host remote :initform +jquery-date-time-picker.css+) (default-value :host remote) (show-time :host remote :initform t)) (:default-initargs :default-value "Enter a date")) (defmethod/remote get-input-value ((self <core:date-time-input)) (.datetimepicker (j-query self) "getDate")) (defmethod/remote init ((self <core:date-time-input)) (call-next-method self) (load-jquery-ui self) (load-css (jquery-date-time-picker-css self)) (load-javascript (jquery-date-time-picker-uri self) (lambda () (not (null j-query.fn.datetimepicker)))) (.datetimepicker (j-query self) (jobject :time-format "h:m" :separator " @ " :show-timepicker (if (show-time self) t false))) (.datetimepicker (j-query self) "setDate" (or (if (typep (default-value self) 'string) (setf (default-value self) (new (*date (default-value self)))) (default-value self)) (new (*date))))) ;; ------------------------------------------------------------------------- ;; Select Input ;; ------------------------------------------------------------------------- (defcomponent <core:select-input (<:select) ((current-value :host remote) (option-values :host remote) (item-equal-p :host remote :initform nil) (_value-cache :host remote :initform nil))) (defmethod/remote get-input-value ((self <core:select-input)) (slot-value (_value-cache self) (slot-value self 'value))) (defmethod/remote init ((self <core:select-input)) (setf (_value-cache self) (jobject)) (let ((equal-fun (or (item-equal-p self) (lambda (a b) (eq a b)))) (hash-list (mapcar (lambda (a) (random-string)) (seq (slot-value (option-values self) 'length))))) (mapcar (lambda (a) (append self a)) (mapcar (lambda (a) (destructuring-bind (hash data) a ;; (_debug (list "a" a "hash" hash "data" data)) (cond ((atom data) (setf (slot-value (_value-cache self) hash) data) (<:option :selected (call/cc equal-fun (current-value self) data) :value hash (_ data))) (t (destructuring-bind (name value) data ;; (_debug (list 2 "name" name "value" value)) (setf (slot-value (_value-cache self) hash) value) (<:option :selected (call/cc equal-fun (current-value self) value) :value hash (_ name))))))) (mapcar2 (lambda (a b) (list b a)) (option-values self) hash-list))))) ;; ------------------------------------------------------------------------- ;; Multiple Select Input ;; ------------------------------------------------------------------------- (defcomponent <core:multiple-select-input (<core:select-input) () (:default-initargs :size 5 :multiple "multiple")) (defmethod/remote get-input-value ((self <core:multiple-select-input)) (reverse-cc (reduce-cc (lambda (acc option) (if (slot-value option 'selected) (cons (slot-value (_value-cache self) (slot-value option 'value)) acc) acc)) (slot-value self 'options) nil))) (defmethod/remote init ((self <core:multiple-select-input)) (setf (slot-value self 'multiple) "multiple") (call-next-method self)) ;; ------------------------------------------------------------------------- ;; Checkbox ;; ------------------------------------------------------------------------- (defcomponent <core:checkbox (<:input) () (:default-initargs :type "checkbox")) (defmethod/remote get-input-value ((self <core:checkbox)) (if (slot-value self 'checked) t nil)) (defmethod/remote init ((self <core:checkbox)) (call-next-method self) (setf (slot-value self 'type) "password") self) ;; ------------------------------------------------------------------------- ;; Multiple Checkbox ;; ------------------------------------------------------------------------- (defcomponent <core:multiple-checkbox (<:div) ((current-value :host remote) (option-values :host remote) (item-equal-p :host remote :initform nil) (_value-cache :host remote :initform nil))) (defmethod/remote get-input-value ((self <core:multiple-checkbox)) (reverse-cc (reduce-cc (lambda (acc checkbox) (if (slot-value checkbox 'checked) (cons (slot-value (_value-cache self) (slot-value checkbox 'value)) acc) acc)) (node-search (lambda (a) (with-slots (type) a (and type (eq "CHECKBOX" (.to-upper-case type))))) self) nil))) (defmethod/remote init ((self <core:multiple-checkbox)) (setf (_value-cache self) (jobject)) (let* ((equal-fun (or (item-equal-p self) (lambda (a b) (eq a b)))) (hash-list (mapcar (lambda (a) (random-string)) (seq (slot-value (option-values self) 'length))))) (flet ((checked-p (current-value data) (reduce0-cc (lambda (acc a) (if (call/cc equal-fun a data) t acc)) (if (atom current-value) (list current-value) current-value)))) (mapcar (lambda (a) (append self a)) (mapcar (lambda (a) (destructuring-bind (hash data) a ;; (_debug (list "a" a "hash" hash "data" data)) (cond ((atom data) (setf (slot-value (_value-cache self) hash) data) (<:label :class "block" :for hash (<:input :type "checkbox" :checked (call/cc checked-p (current-value self) data) :value hash :id hash) (_ data))) (t (destructuring-bind (name value) data ;; (_debug (list 2 "name" name "value" value)) (setf (slot-value (_value-cache self) hash) value) (<:label :for hash :class "block" (<:input :type "checkbox" :id hash :checked (call/cc checked-p (current-value self) value) :value hash) (_ name))))))) (mapcar2 (lambda (a b) (list b a)) (option-values self) hash-list)))))) ;; ------------------------------------------------------------------------- ;; Radio Group ;; ------------------------------------------------------------------------- ;; NOTE: Used in Coretal Sidebar (defcomponent <core:radio-group (<:div) ((items :host remote) (_result :host remote))) (defmethod/remote get-input-value ((self <core:radio-group)) (if (_result self) (.index-of (items self) (_result self)) (throw (new (*error (+ "get-input-value called although" " input is invalid. (radiogroup)")))))) (defmethod/remote init ((self <core:radio-group)) (let ((rnd (random-string))) (+ rnd "") (labels ((match (a) (with-slots (type tag-name) a (let ((type (and type (.to-upper-case type))) (tag-name (and tag-name (.to-upper-case tag-name)))) (and tag-name type (eq tag-name "INPUT") (or (eq type "TEXT") (eq type "SELECT")) (not (eq type "RADIO")))))) (input-nodes (a) (cond ((null a) nil) ((call/cc match a) (list a)) (t (node-search match a)))) (disable-inputs (a) (let ((inputs (call/cc input-nodes a))) (_debug (list "inputs" inputs a)) (mapcar (lambda (a) (setf (slot-value a 'disabled) t)) inputs) inputs)) (enable-input (a) (setf (slot-value a 'disabled) false)) (handle-event (item) (let ((payload (nth 1 item))) (_debug (list "payload"payload)) (setf (_result self) item) (mapcar-cc (lambda (a) (_debug (list "a1" a)) (mapcar-cc (lambda (a) (_debug (list "a2" a)) (setf (slot-value a 'disabled) t) (_debug (list "disabling" a))) (call/cc input-nodes a))) (mapcar-cc (lambda (a) (car (cdr a))) (items self))) (mapcar-cc (lambda (a) (_debug (list "a3" a)) (setf (slot-value a 'disabled) false) (_debug (list "enabling" a))) (call/cc input-nodes payload))))) (mapcar-cc (lambda (a) (append self a)) (mapcar-cc (lambda (item) (destructuring-bind (title payload checked) item (with-field (list (<:input :checked (and checked t) :type "radio" :name rnd :onclick (event (e) (let ((self this)) (with-call/cc (call/cc handle-event item))) true)) " " (_ title)) (progn (if (not checked) (disable-inputs payload)) payload)))) (items self)))))) ;; +------------------------------------------------------------------------- ;; | Password Combo Input ;; +------------------------------------------------------------------------- (defcomponent <core:password-combo-input (<core:default-value-input) ((min-length :initform 6 :host remote) (_password-input :host remote :initform (<core:password-input)) (_password1 :host remote) (_password2 :host remote)) (:default-initargs :default-value "Enter password") (:tag . "span")) (defmethod/remote get-input-value ((self <core:password-combo-input)) (get-input-value (_password2 self))) (defmethod/remote validate-password ((self <core:password-combo-input)) (with-slots (_password1 _password2) self (cond ((not (valid _password2)) (_ "Two passwords do not match.")) ((not (equal (get-input-value _password1) (get-input-value _password2))) (_ "Two passwords do not match.")) (t t)))) (defmethod/remote validate ((self <core:password-combo-input)) (with-slots (_password1 _password2) self (let ((result (validate _password1))) (if (typep result 'string) result (validate-password self))))) (defmethod/remote init ((self <core:password-combo-input)) (with-slots (min-length validation-span-id) self (let ((_password1 (setf (_password1 self) (make-component (_password-input self) :min-length min-length :validation-span-id validation-span-id))) (_password2 (setf (_password2 self) (make-component (_password-input self) :min-length min-length :validation-span-id validation-span-id)))) (append self _password1) (append self _password2) (call-next-method self)))) ;; ------------------------------------------------------------------------- ;; In Place Edit ;; ------------------------------------------------------------------------- (defcomponent <core:in-place-edit (<:a) ((current-value :host remote) (_input :host remote :initform (<core:required-value-input)))) (defmethod/remote onsave ((self <core:in-place-edit) value) (_debug (+ "Inplace edit: " value))) (defmethod/remote on-click1 ((self <core:in-place-edit) e) (let* ((input (make-component (_input self) :value (current-value self))) (form (<:form :class (slot-value self 'class-name) input)) (save-fun (event (e) (let ((v (slot-value input 'value))) (replace-node form self) (setf (current-value self) v) (setf (slot-value self 'inner-h-t-m-l) v) (onsave self v))))) (setf (slot-value form 'onsubmit) save-fun) (replace-node self form))) (defmethod/remote init ((self <core:in-place-edit)) (setf (slot-value self 'inner-h-t-m-l) (current-value self)) (setf (slot-value self 'onclick) (lifte self.on-click1)))
21,373
Common Lisp
.lisp
537
35.037244
89
0.566633
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
bef3cf2e7976e98b892043c693c802f74b6308cfce0b3358465ae022c5a5107a
8,363
[ -1 ]
8,364
jquery.lisp
evrim_core-server/src/web/components/jquery.lisp
(in-package :core-server) ;; ------------------------------------------------------------------------- ;; Supply JQuery ;; ------------------------------------------------------------------------- (defcomponent supply-jquery () ((jquery-uri :host remote :initform +jquery.js+))) (defmethod/remote load-jquery ((self supply-jquery)) (load-javascript (jquery-uri self) (lambda () (not (null j-query))))) ;; ------------------------------------------------------------------------- ;; Supply Jquery UI ;; ------------------------------------------------------------------------- (defcomponent supply-jquery-ui (supply-jquery) ((jquery-ui-uri :host remote :initform +jquery-ui.js+) (jquery-ui-css-uri :host remote :initform +jquery-ui.css+))) (defmethod/remote load-jquery-ui ((self supply-jquery-ui)) (load-jquery self) (load-css (jquery-ui-css-uri self)) (load-javascript (jquery-ui-uri self) (lambda () (not (null j-query.fn.accordion))))) ;; ------------------------------------------------------------------------- ;; Supply LightBox ;; ------------------------------------------------------------------------- (defvar +jquery-lightbox-config+ (jobject :image-loading "/js/lightbox/images/lightbox-ico-loading.gif" :image-btn-prev "/js/lightbox/images/lightbox-btn-prev.gif" :image-btn-next "/js/lightbox/images/lightbox-btn-next.gif" :image-btn-close "/js/lightbox/images/lightbox-btn-close.gif" :image-blank "/js/lightbox/images/lightbox-blank.gif")) (defcomponent supply-jquery-lightbox (supply-jquery) ((lightbox-uri :host remote :Initform +jquery-lightbox.js+) (lightbox-css-uri :host remote :initform +jquery-lightbox.css+) (lightbox-config :host remote :initform +jquery-lightbox-config+))) (defmethod/remote destroy ((self supply-jquery-lightbox)) (remove-css (lightbox-css-uri self)) (call-next-method self)) (defmethod/remote load-jquery-lightbox ((self supply-jquery-lightbox)) (load-jquery self) (load-javascript (lightbox-uri self) (lambda () (not (null j-query.fn.light-box)))) (load-css (lightbox-css-uri self))) ;; ------------------------------------------------------------------------- ;; Supply Jquery Carousel ;; ------------------------------------------------------------------------- (defvar +jquery-carousel-config+ (jobject)) (defcomponent supply-jquery-carousel (supply-jquery-ui) ((carousel-uri :host remote :Initform +jquery-carousel.js+) (carousel-css-uri :host remote :initform +jquery-carousel.css+) (carousel-config :host remote :initform +jquery-carousel-config+))) (defmethod/remote destroy ((self supply-jquery-carousel)) (remove-css (carousel-css-uri self)) (call-next-method self)) (defmethod/remote load-jquery-carousel ((self supply-jquery-carousel)) (load-jquery-ui self) (load-javascript (carousel-uri self) (lambda () (not (null j-query.fn.rcarousel)))) (load-css (carousel-css-uri self))) ;; ------------------------------------------------------------------------- ;; Supply Nested Sortable ;; ------------------------------------------------------------------------- (defcomponent supply-jquery-nested-sortable (supply-jquery-ui) ((nested-sortable-uri :host remote :initform +jquery-nested-sortable.js+))) (defmethod/remote load-jquery-nested-sortable ((self supply-jquery-nested-sortable)) (load-jquery-ui self) (load-javascript (nested-sortable-uri self) (lambda () (not (null j-query.ui.nested-sortable))))) ;; ------------------------------------------------------------------------- ;; Supply Newsticker ;; ------------------------------------------------------------------------- (defcomponent supply-jquery-newsticker (supply-jquery) ((newsticker-uri :host remote :initform +jquery-newsticker.js+))) (defmethod/remote load-jquery-newsticker ((self supply-jquery-newsticker)) (load-jquery self) (load-javascript (newsticker-uri self) (lambda () (not (null j-query.fn.news-ticker))))) ;; ------------------------------------------------------------------------- ;; Supply Slider ;; ------------------------------------------------------------------------- (defcomponent supply-jquery-slider (supply-jquery) ((slider-uri :host remote :initform +jquery-slider.js+) (slider-css :host remote :initform +jquery-slider.css+))) (defmethod/remote load-jquery-slider ((self supply-jquery-slider)) (load-jquery self) (load-css (slider-css self)) (load-javascript (slider-uri self) (lambda () (not (null j-query.fn.slider1))))) ;; ------------------------------------------------------------------------- ;; Supply Jquery Text Effects ;; ------------------------------------------------------------------------- (defcomponent supply-jquery-text-effects (supply-jquery) ((text-effects-uri :host remote :initform +jquery-text-effects.js+))) (defmethod/remote load-jquery-text-effects ((self supply-jquery-text-effects)) (load-jquery self) (load-javascript (text-effects-uri self) (lambda () (not (null j-query.fn.unscramble))))) ;; ------------------------------------------------------------------------- ;; Supply Jquery Tree ;; ------------------------------------------------------------------------- ;; https://github.com/pioz/jquery-tree (defcomponent supply-jquery-tree (supply-jquery) ((tree-uri :host remote :initform +jquery-tree.js+) (cookie-uri :host remote :initform +jquery-cookie.js+))) (defmethod/remote load-jquery-tree ((self supply-jquery-tree)) (load-jquery self) (load-javascript (cookie-uri self) (lambda () (not (null j-query.cookie)))) (load-javascript (tree-uri self) (lambda () (not (null j-query.fn.tree))))) ;; ;; +---------------------------------------------------------------------------- ;; ;; | Jquery Extension ;; ;; +---------------------------------------------------------------------------- ;; (defpackage :tr.gen.core.server.jquery ;; (:nicknames :jquery :<jquery) ;; (:use :common-lisp :core-server) ;; ;;; (:import-from #:core-server #:get-model #:set-model #:login) ;; (:export ;; #:jquery ;; #:+jquery+ ;; #:+jquery-ui+ ;; #:dialog)) ;; (in-package :jquery) ;; (defparameter +jquery+ "http://code.jquery.com/jquery-1.2.6.js") ;; (defparameter +jquery-ui+ "http://localhost/jquery/jquery-ui-personalized-1.6rc2.packed.js") ;; ;; ---------------------------------------------------------------------------- ;; ;; Jquery Stack ;; ;; ---------------------------------------------------------------------------- ;; (defcomponent jquery () ;; ()) ;; ;; (defmethod/remote to-json ((self jquery) object) ;; ;; object) ;; (defmethod/remote funkall ((self jquery) action arguments) ;; (let ((result) ;; (target this)) ;; (j-query.ajax (create :url action ;; :type "POST" ;; :data (mapobject (lambda (k v) ;; (target.to-json v)) ;; arguments) ;; :async false ;; :success (lambda (xhr status) ;; (setf result xhr)) ;; :error (lambda (xhr status e) ;; (throw e)))) ;; ;; (return (eval result)) ;; (try ;; (setf result (eval result)) ;; (:catch (e) (throw e))) ;; (return result))) ;; ;; ---------------------------------------------------------------------------- ;; ;; Jquery FlexiGrid Component ;; ;; ---------------------------------------------------------------------------- ;; (defcomponent flexi-grid (jquery) ;; ((instances :initarg :instances :initform nil) ;; (dom-id :host remote :initarg :id) ;; (grid :host remote :initform nil) ;; (slots :host none :initarg :slots :initform nil) ;; (col-model :host remote :initform nil) ;; (actions :host remote :initarg :actions :initform nil) ;; (height :host remote :initform 200) ;; (width :host remote :initform "auto") ;; (striped :host remote :initform t) ;; (novstripe :host remote :initform nil) ;; (min-width :host remote :initform 30) ;; (max-height :host remote :initform 80) ;; (resizable :host remote :initform t) ;; (use-pager :host remote :initform t) ;; (nowrap :host remote :initform t) ;; (rp :host remote :initform 15) ;; Results per page ;; (rp-options :host remote :initform (list 10 15 20 25 40)) ;; (title :host remote :initform nil) ;; (autoload :host remote :initform t) ;; (sortname :host remote :initform nil) ;; (sortorder :host remote :initform "asc"))) ;; (defmethod shared-initialize :after ((grid flexi-grid) slot-names ;; &key &allow-other-keys) ;; (setf (flexi-grid.col-model grid) ;; (mapcar (lambda (slot) ;; (let* ((slot (copy-list slot)) ;; (label (getf (cdr slot) :label))) ;; (remf (cdr slot) :label) ;; (setf (getf (cdr slot) :display) label ;; (getf (cdr slot) :name) (core-server::symbol-to-js (car slot))) ;; (remf (cdr slot) :reader) ;; (apply #'jobject (cdr slot)))) ;; (flexi-grid.slots grid)))) ;; (defcomponent-ctor flexi-grid) ;; ;; ---------------------------------------------------------------------------- ;; ;; Flexigrid Data Format ;; ;; ---------------------------------------------------------------------------- ;; ;; { ;; ;; page: 1, ;; ;; total: 239, ;; ;; rows: [ ;; ;; {id:'ZW',cell:['ZW','ZIMBABWE','Zimbabwe','ZWE','716']}, ;; ;; {id:'VE',cell:['VE','VENEZUELA','Venezuela','VEN','862']}, ;; ;; {id:'VU',cell:['VU','VANUATU','Vanuatu','VUT','548']}] ;; ;; } ;; (defmethod flexi-grid.find-slot ((self flexi-grid) slot-namestring) ;; (find (string-upcase slot-namestring) (flexi-grid.slots self) ;; :test #'string= ;; :key (arnesi::compose #'symbol-name #'car))) ;; (defmethod flexi-grid.sort ((self flexi-grid) data sortname sortorder) ;; (let ((slot (flexi-grid.find-slot self sortname))) ;; (if slot ;; (sort (copy-list data) ;; (lambda (a b) ;; (cond ;; ((equal sortorder "asc") ;; (typecase a ;; (number ;; (< (or a 0) (or b 0))) ;; (string ;; (string< a b)) ;; (t t))) ;; ((equal sortorder "desc") ;; (typecase a ;; (number ;; (> (or a 0) (or b 0))) ;; (string ;; (string> a b)) ;; (t t))) ;; (t t))) ;; :key (getf (cdr slot) :reader)) ;; data))) ;; (defmethod flexi-grid.query ((self flexi-grid) query slot) ;; (let* ((slot (flexi-grid.find-slot self slot)) ;; (reader (getf (cdr slot) :reader))) ;; (when reader ;; (labels ((predicate (instance) ;; (let ((value (funcall reader instance))) ;; (equal value query)))) ;; (core-server::filter #'predicate (flexi-grid.instances self)))))) ;; (defmethod/local grid-data ((self flexi-grid) page rp sortname sortorder query qtype) ;; (let ((data (flexi-grid.sort self ;; (if (and query qtype) ;; (flexi-grid.query self query qtype) ;; (flexi-grid.instances self)) ;; sortname sortorder))) ;; (describe (list page rp sortname sortorder query qtype)) ;; (jobject :page page ;; :total (length data) ;; :rows (or (mapcar (lambda (instance) ;; (jobject :id (core-server::get-id instance) ;; :cell (mapcar (lambda (slot) ;; (funcall (getf (cdr slot) :reader) instance)) ;; (flexi-grid.slots self)))) ;; (take rp (drop (* page rp) data))) ;; (jobject))))) ;; (defmethod/local handler ((self flexi-grid)) ;; (action/url ((page "page") (rp "rp") (sortname "sortname") ;; (sortorder "sortorder") (query "query") (qtype "qtype")) ;; (json/suspend ;; (core-server::json! ;; (http-response.stream (context.response +context+)) ;; (apply 'grid-data (cons self ;; (mapcar 'core-server::json-deserialize ;; (list page rp sortname sortorder query qtype)))))))) ;; (core-server::defctor (self flexi-grid) ;; (let ((target this)) ;; (.flexigrid ($ (+ "#" (this.get-dom-id))) ;; (create ;; :url (this.handler) ;; :data-type "json" ;; :col-model (this.get-col-model) ;; :sortname "name" ;; :sortorder "asc" ;; :height (this.get-height) ;; :width (this.get-width) ;; :striped (this.get-striped) ;; :novstripe (this.get-novstripe) ;; :minwidth (this.get-min-width) ;; :maxheight (this.get-max-height) ;; :resizable (this.get-resizable) ;; :usepager (this.get-use-pager) ;; :nowrap (this.get-nowrap) ;; :rp (this.get-rp) ;; :rp-options (this.get-rp-options) ;; :title (this.get-title) ;; :autoload (this.get-autoload) ;; :searchitems (filter (lambda (item) ;; (if (aref item "searchable") ;; true ;; nil)) ;; (this.get-col-model)) ;; :buttons (mapcar (lambda (action) ;; (let ((object (new (*object action))) ;; (onpress (aref action "onpress"))) ;; (setf (slot-value object 'onpress) ;; (lambda (com grid) ;; (let ((fun (aref target onpress))) ;; (if fun ;; (fun.call target grid) ;; (alert (+ "Sorry, " onpress " is undefined.")))))) ;; object)) ;; (this.get-actions))))) ;; (this.set-grid (slot-value (aref ($ (+ "#" (this.get-dom-id))) 0) 'grid))) ;; ;; ---------------------------------------------------------------------------- ;; ;; defflexi-grid Macro: Define a table view ;; ;; ---------------------------------------------------------------------------- ;; (defmacro defflexi-grid (name supers slots &rest rest) ;; `(progn ;; (defcomponent ,name (flexi-grid ,@supers) ;; () ;; (:default-initargs :slots ',slots ,@(flatten1 rest))))) ;; ;; ---------------------------------------------------------------------------- ;; ;; Jquery CRUD ;; ;; ---------------------------------------------------------------------------- ;; (defcomponent jquery-crud (jquery) ;; ((fields :initarg :fields :host local :initform nil) ;; (dom-id :initarg :id :host remote :initform "crud") ;; (instance :initarg :instance :host local :initform nil) ;; (model :host remote :initform nil) ;; (view-title :initarg :view-title :initform nil) ;; (edit-title :initarg :edit-title :initform nil) ;; (new-title :initarg :new-title :initform nil))) ;; (defmethod shared-initialize :after ((crud jquery-crud) slot-names ;; &key &allow-other-keys) ;; (setf (jquery-crud.model crud) ;; (mapcar (lambda (field) ;; (let ((field (copy-list field))) ;; (remf (cdr field) :reader) ;; (remf (cdr field) :type) ;; (apply #'jobject (cons :name ;; (cons (symbol-name (car field)) ;; (cdr field)))))) ;; (jquery-crud.fields crud)))) ;; (defmethod/local crud-template ((crud jquery-crud)) ;; (<:form :action "#" ;; (mapcar (lambda (field) ;; (<:div :class "field" ;; (<:div :class "name" (getf (cdr field) :label)) ;; (<:div :class "value" ;; (case (getf (cdr field) :type) ;; (t ;; (<:input :type "text" :name (symbol-name (car field)) ;; :value (funcall ;; (getf (cdr field) :reader) ;; (jquery-crud.instance crud)))))))) ;; (jquery-crud.fields crud)) ;; (<:div :class "field" ;; (<:div :class "name") ;; (<:div :class "value" ;; (<:input :type "submit" :value "Save"))))) ;; (defmethod/local save-instance ((crud jquery-crud) values) ;; ;; (break values) ;; ;; (mapcar #'describe values) ;; (describe values) ;; ) ;; (defmethod/remote save ((crud jquery-crud) e) ;; (let* ((model (this.get-model)) ;; (form e.target) ;; (values (mapcar (lambda (m) ;; (cons (slot-value m 'name) ;; (slot-value (slot-value form (slot-value m 'name)) ;; 'value))) ;; model))) ;; ;; (this.save-instance.apply values) ;; (this.save-instance values))) ;; (core-server::defctor (component jquery-crud) ;; (let ((div (aref ($ (+ "#" (this.get-dom-id))) 0)) ;; (form (this.crud-template)) ;; (self this)) ;; (setf div.inner-h-t-m-l "") ;; (div.append-child form) ;; (setf form.onsubmit (lambda (e) ;; (self.save.call self e))))) ;; (defcomponent-ctor jquery-crud) ;; ;; ---------------------------------------------------------------------------- ;; ;; defjquery-crud Macro: Define a form view ;; ;; ---------------------------------------------------------------------------- ;; (defmacro defjquery-crud (name supers slots &rest rest) ;; `(progn ;; (defcomponent ,name (jquery-crud ,@supers) ;; () ;; (:default-initargs :fields ',slots ;; ,@(flatten1 rest))))) ;; ;; +---------------------------------------------------------------------------- ;; ;; | Jquery Dialog ;; ;; +---------------------------------------------------------------------------- ;; (defhtml-component dialog (<:div) ;; ((showp :initarg :showp :initform nil :host local) ;; (eben :initarg :eben :host remote :initform "eben"))) ;; (defmethod/remote template ((self dialog)) ;; (<:div :class "flora":title "eben" ;; "I am Jquery Dialog, override my template method.")) ;; (defmethod/remote showingp ((self dialog)) ;; (.dialog ($ (+ "#" self.id)) "isOpen")) ;; (defmethod/remote show ((self dialog)) ;; (unless (showingp self) ;; ;;; (let ((template (template self))) ;; ;;; ;;; (.hide ($ template)) ;; ;;; ;;; (document.body.append-child template) ;; ;;; (.dialog ($ template)) ;; ;;; (.show ($ template))) ;; (.dialog ($ self)) ;; )) ;; (defmethod/remote init ((self dialog)) ;; (set-eben self "test") ;; (if (get-showp self) ;; (show self))) ;; (core-server::defhtmlcomponent-ctor dialog) ;; ;; +---------------------------------------------------------------------------- ;; ;; | Jquery Login Link & Dialog ;; ;; +---------------------------------------------------------------------------- ;; (defhtml-component login-dialog (<:a) ;; ()) ;; (defmethod/local auth ((self login-dialog) username password) ;; (answer/dispatch 'login username password)) ;; (defmethod/remote template ((self login-dialog)) ;; (<:div :class "gee" ;; (<:form ;; :action "#" ;; :onsubmit (lambda (e) ;; (let ((form e.target)) ;; (self.auth form.username.value form.password.value))) ;; (with-field "Username:" (<:input :type "text" :name "username")) ;; (with-field "Password:" (<:input :type "password" :name "password")) ;; (with-field "" (<:input :type "submit" :value "Login"))))) ;; (defmethod/remote init ((self login-dialog)) ;; (setf this.onclick (lambda (e) ;; (.dialog ($ (template self))) ;; (return false)))) ;; (core-server::defhtmlcomponent-ctor login-dialog) ;; ;; ---------------------------------------------------------------------------- ;; ;; Jquery Macros ;; ;; ---------------------------------------------------------------------------- ;; ;; ---------------------------------------------------------------------------- ;; ;; Jquery Stack ;; ;; ---------------------------------------------------------------------------- ;; ;; ;;;; ;; ;; ;;;; Interface for remote services ;; ;; ;;;; ;; ;; (defcomponent ajax-mixin () ;; ;; ()) ;; ;; ;; TODO: first create activexobject, catch exception then create xmlhttprequest. ;; ;; (defmethod/remote make-request ((self ajax-mixin)) ;; ;; ;; (cond ;; ;; ;; (window.*x-m-l-http-request ;; Gecko ;; ;; ;; (setf request (new (*x-m-l-http-request)))) ;; ;; ;; (window.*active-x-object ;; Internettin Explorer ;; ;; ;; (setf request (new (*active-x-object "Microsoft.XMLHTTP"))))) ;; ;; ;; (if (= null request) ;; ;; ;; (throw (new (*error "Exception: Cannot find usable XmlHttpRequest method, -core-server 1.0"))) ;; ;; ;; (return request)) ;; ;; (let ((req null)) ;; ;; (try (setf req (new (*active-x-object "Msxml2.XMLHTTP"))) ;; ;; (:catch (e1) ;; ;; (try (setf req (new (*active-x-object "Microsoft.XMLHTTP"))) ;; ;; (:catch (e2) ;; ;; (setf req null))))) ;; ;; (if (and (not req) (not (= (typeof *x-m-l-http-request) "undefined"))) ;; ;; (setf req (new (*x-m-l-http-request)))) ;; ;; (return req))) ;; ;; ;; return response directly, don't eval (text? xml?). ;; ;; (defmethod/remote send-request ((self ajax-mixin) request url) ;; ;; (request.open "GET" url false) ;; ;; (request.send null) ;; ;; (if (= 200 request.status) ;; ;; (return request) ;; ;; (throw (new (*error (+ "Exception: Cannot send XmlHttpRequest: " url " -core-server 1.0")))))) ;; ;; (defcomponent jqueryapi (ajax-mixin) ;; ;; ((script-location :host remote ;; ;; :initform "jquery-latest.min.js" ;; ;; :initarg :script-location ;; ;; :documentation "jQuery script location as url"))) ;; ;; (defmethod/remote init ((self jqueryapi)) ;; ;; (when (= "undefined" (typeof j-query)) ;; ;; (let ((req (this.make-request)) ;; ;; (resp (this.send-request req this.script-location))) ;; ;; (return (eval (+ "{" resp.response-text "}")))))) ;; ;; ;; TODO: implement retrycount, possibly using $.ajax. ;; ;; (defmethod/remote jqueryfuncall ((self jqueryapi) url parameters retry-count) ;; ;; (let (result) ;; ;; (debug "server.funcall " url) ;; ;; ($.post url ;; ;; parameters ;; ;; (lambda (data textstatus) ;; ;; (setf result (eval (+ "{" data "}")))) ;; ;; "json") ;; ;; (return result))) ;; ;; (defun/cc jquery (&optional scriptlocation) ;; ;; (send/component (make-instance 'jqueryapi :script-location scriptlocation)) ;; ;; ;; (<:js ;; ;; ;; `(progn ;; ;; ;; (setf jqueryapi (new (jqueryapi))) ;; ;; ;; (defun funcall (url parameters retry-count) ;; ;; ;; (return (jqueryapi.jqueryfuncall url parameters retry-count))) ;; ;; ;; (jqueryapi.init))) ;; ;; (error "fix jquery") ;; ;; )
21,658
Common Lisp
.lisp
490
42.706122
106
0.522798
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
10c6eac45c5f431a8c0a5ab51f5dcb01938f3936ab4c8ec0b359d9c21d5d6aad
8,364
[ -1 ]
8,365
table.lisp
evrim_core-server/src/web/components/table.lisp
(in-package :core-server) ;; ------------------------------------------------------------------------- ;; Table Component (Single Select) ;; ------------------------------------------------------------------------- (defcomponent <core:table (<:table cached-component slot-representations callable-component) ((instances :host remote :initarg :instances :initform nil) (primary-field :host remote :initform "name") (template-class :initform nil :host remote) (hilight-class :initform "hilighted" :host remote) (hover-class :initform "hover" :host remote) (selected-class :initform "selected" :host remote) (table-css :host remote :initform +table.css+) (selected :initform nil :host remote) (_sorted-slot :host remote) (_head :host remote) (_foot :host remote) (_resize-thread :host remote))) (defmethod/remote get-template-class ((self <core:table)) (with-slots (instances) self (if (and instances (null (template-class self))) (setf (template-class self) (slot-value (car instances) 'core-class)))) (slot-value self 'template-class)) (defmethod/remote column-span ((self <core:table)) (aif (object-to-list (template-class self)) (slot-value it 'length) 1)) (defmethod/remote sort-table ((self <core:table) slot) (with-slots (name) slot (cond ((and (_sorted-slot self) (eq slot (_sorted-slot self))) (setf (instances self) (sort (lambda (a b) (> (slot-value a name) (slot-value b name))) (instances self))) (setf (_sorted-slot self) nil)) (t (setf (instances self) (sort (lambda (a b) (< (slot-value a name) (slot-value b name))) (instances self))) (setf (_sorted-slot self) slot))) (replace-node (aref (self.get-elements-by-tag-name "TBODY") 0) (tbody self)) ;; Give emphasis on selected again (awhen (selected self) (awhen (find (lambda (a) (eq a it)) (instances self)) (_on-select self it))))) (defmethod/remote _on-select ((self <core:table) instance) (mapcar-cc (lambda (instance) (awhen (slot-value instance '_table-row) (remove-class it (selected-class self)))) (instances self)) (flet ((first-child (node) (slot-value node 'first-child))) (awhen (slot-value instance '_table-row) (add-class it (selected-class self)) (setf (slot-value (call/cc first-child (call/cc first-child it)) 'checked) t (selected self) instance)))) (defmethod/remote on-select ((self <core:table) instance) (_on-select self instance) (answer-component self instance)) (defmethod/remote thead ((self <core:table)) (<:table :class (slot-value self 'class-name) (<:thead (<:tr (<:th :class "first-column" " ") (mapcar (lambda (slot) (with-slots (name label) slot (<:th :class name (<:a :onclick (lifte (sort-table self slot)) (or label name))))) (template-class self)))))) (defmethod/remote make-row ((self <core:table) instance) (let* ((radio (<:input :type "radio" :name "table-object" :onclick (lifte2 (on-select self instance)))) (row (<:tr :onmouseover (event (e) (add-class this (hover-class self))) :onmouseout (event (e) (remove-class this (hover-class self))) :onclick (lifte (on-select self (slot-value this 'instance))) (cons (<:td :class "first-column" radio) (mapcar (lambda (slot) (<:td :class (slot-value slot 'name) (get-slot-view self slot instance))) (template-class self)))))) (setf (slot-value instance '_table-row) row (slot-value row 'instance) instance) row)) (defmethod/remote tbody ((self <core:table)) (aif (instances self) (<:tbody (mapcar2-cc (lambda (instance index) (let ((row (make-row self instance))) (if (eq 0 (mod index 2)) (add-class row (hilight-class self))) row)) it (seq (slot-value it 'length)))) (<:tbody (<:tr (<:td :colspan (column-span self) "Table has no elements."))))) (defmethod/remote tfoot ((self <core:table)) (<:table :class (slot-value self 'class-name) (<:tfoot (<:tr (<:td :class "text-right" :colspan (column-span self) (aif (instances self) (+ (slot-value it 'length) " item(s).") "No items.")))))) (defmethod/remote update-tfoot ((self <core:table)) (setf (_foot self) (replace-node (_foot self) (tfoot self)))) ;; function ResizeWidths(div) { ;; var headerCells = $(div).find('.headerTable thead').find('th'); ;; var contentCells = $(div).find('.contentTable thead').find('th'); ;; for(var i =0, ii = headerCells.length;i<ii;i++) ;; { ;; if($(headerCells[i]).width()!=$(contentCells[i]).width()) ;; $(headerCells[i]).width($(contentCells[i]).width()); ;; } ;; } (defmethod/remote resize-thead ((self <core:table)) (with-slots (instances) self (when (and instances (> (slot-value instances 'length) 0)) (flet ((get-width (element) (slot-value element 'offset-width)) (by-tag-name (root tag-name) (node-search (lambda (a) (and (slot-value a 'tag-name) (eq (slot-value a 'tag-name) tag-name))) root))) (setf (slot-value (slot-value (_head self) 'style) 'width) (+ (get-width self) "px")) (mapcar2 (lambda (head-cell body-cell) (setf (slot-value (slot-value head-cell 'style) 'width) (+ (- (get-width body-cell) 10) "px"))) (by-tag-name (car (by-tag-name (_head self) "TR")) "TH") (by-tag-name self "TD")))))) (defmethod/remote remove-child-nodes ((self <core:table)) (mapcar-cc (lambda (a) (.remove-child self a)) (slot-value self 'child-nodes))) (defmethod/remote destroy ((self <core:table)) (clear-interval (_resize-thread self)) (with-slots (parent-node) self (with-slots (parent-node) parent-node (.remove-child parent-node (_head self)) (.remove-child parent-node (_foot self))) (replace-node parent-node self)) (call-next-method self)) (defmethod/remote init ((self <core:table)) (add-class self "core-table") (load-css (table-css self)) (remove-child-nodes self) (let ((head (setf (_head self) (thead self))) (foot (setf (_foot self) (tfoot self)))) (append self (tbody self)) (labels ((do-when-parent (f) (if (slot-value self 'parent-node) (call/cc f) (make-web-thread (lambda () (do-when-parent f))))) (wrap-me (head foot) (let ((parent-node (slot-value self 'parent-node))) (let ((div (<:div :class "core-table-wrapper"))) (if (has-class parent-node "core-table-overflow") (replace-node (slot-value parent-node 'parent-node) div) (replace-node self div)) (append div head) (append div (<:div :class "core-table-overflow" self)) (append div foot) (setf (_resize-thread self) (set-interval (event () (resize-thead self window.k)) 300)))))) (do-when-parent (lambda () (wrap-me head foot)))))) (defmethod/remote add-instance ((self <core:table) instance) (with-slots (instances) self (let ((tbody (aref (.get-elements-by-tag-name self "TBODY") 0)) (row (make-row self instance))) (if (null instances) (.remove-child tbody (slot-value tbody 'first-child))) (setf (instances self) (cons instance instances)) (update-tfoot self) (if (eq 1 (mod (slot-value (instances self) 'length) 2)) (add-class row (hilight-class self))) (prepend tbody row) (setf (slot-value (slot-value self 'parent-node) 'scroll-top) "0") (resize-thead self) (make-web-thread (lambda () (on-select self instance))) instance))) (defmethod/remote remove-instance ((self <core:table) instance) (with-slots (instances) self (setf (instances self) (filter-cc (lambda (a) (not (eq instance a))) instances)) (with-slots (_table-row) instance (if _table-row (.remove-child (slot-value _table-row 'parent-node) _table-row)) (delete-slot instance '_table-row) (if (eq (selected self) instance) (setf (selected self) nil)) (update-tfoot self) (if (null (instances self)) (replace-node (aref (.get-elements-by-tag-name self "TBODY") 0) (tbody self))) (resize-thead self)) ;; (setf (slot-value (slot-value self 'parent-node) 'scroll-top) "0") instance)) (defmacro deftable (name supers slots &rest rest) `(defcomponent ,name (,@supers <core:table) () (:default-initargs :template-class ,(%generate-template-class slots) ,@(cdr (flatten1 rest))))) ;; +---------------------------------------------------------------------------- ;; | Table Component ;; +---------------------------------------------------------------------------- ;; (defcomponent <core:table (<:table) ;; ((instances :host remote :initarg :instances :initform nil) ;; (hilight-class :initform "hilighted" :host remote) ;; (selected-class :initform "selected" :host remote) ;; (selected :initform nil :host remote) ;; (primary-field :initform "name" :host remote) ;; (template-class :initform nil :host none) ;; (local-cache :initform (make-hash-table :weakness :value :test #'equal) ;; :host none))) ;; (defmethod/local get-instances ((self <core:table)) ;; (mapcar (lambda (jobject instance) ;; (describe jobject) ;; (setf (slot-value jobject 'attributes) ;; (cons :ref-id ;; (cons (let ((str (random-string 5))) ;; (setf (gethash str (local-cache self)) instance) ;; str) ;; (slot-value jobject 'attributes)))) ;; jobject) ;; (mapcar (rcurry #'object->jobject ;; (or (template-class self) ;; (class-of (car (instances self))))) ;; (instances self)) ;; (instances self))) ;; (defmethod/remote add-selected ((component <core:table) selection) ;; (let ((node (slot-value (slot-value (slot-value selection 'checkbox) 'parent-node) 'parent-node))) ;; (add-class node (selected-class self)) ;; (remove-class node (hilight-class self)) ;; (set-selected component (cons selection ;; (remove-selected component selection))))) ;; (defmethod/remote remove-selected ((component <core:table) selection) ;; (let ((node (slot-value (slot-value (slot-value selection 'checkbox) 'parent-node) 'parent-node))) ;; (remove-class node (selected-class component)) ;; (set-selected component (filter (lambda (a) (not (eq a selection))) ;; (get-selected component))))) ;; (defmethod/remote thead ((component <core:table)) ;; (<:thead ;; (<:tr ;; (<:th :class "checkbox" ;; (<:input :type "checkbox" ;; :onchange (event (e) ;; (let ((checked this.checked)) ;; (with-call/cc ;; (mapcar (lambda (object) ;; (setf (slot-value (slot-value object 'checkbox) 'checked) ;; checked)) ;; (get-instances component)) ;; (if checked ;; (set-selected component (get-instances component)) ;; (set-selected component nil)))) ;; false))) ;; (mapcar (lambda (slot) ;; (with-slots (name label) slot ;; (<:th :class name (or label name)))) ;; (slot-value (car (instances self)) 'class))))) ;; (defmethod/local _set-selected ((self <core:table) ref-id) ;; (setf (slot-value self 'selected) (gethash ref-id (local-cache self))) ;; t) ;; (defmethod/remote on-select ((self <core:table) object) ;; (_set-selected self (slot-value object 'ref-id)) ;; (answer-component self object)) ;; (defmethod/remote tbody ((component <core:table)) ;; (let ((instances (get-instances component))) ;; (if (null instances) ;; (<:tbody (<:tr (<:th "Table has no elements."))) ;; (<:tbody ;; (mapcar2 ;; (lambda (object index) ;; (let ((checkbox ;; (<:input :type "checkbox" ;; :onchange (event (e) ;; (let ((checked this.checked)) ;; (with-call/cc ;; (if checked ;; (add-selected component object) ;; (remove-selected component object)))) ;; false)))) ;; (setf (slot-value object "checkbox") checkbox) ;; (<:tr :class (if (eq 0 (mod index 2)) (get-hilight-class component)) ;; (<:td :class "checkbox" checkbox) ;; (mapcar (lambda (slot) ;; (let ((name (slot-value slot 'name)) ;; (value (slot-value object (slot-value slot 'name)))) ;; (<:td :class name ;; (if (equal name (primary-field self)) ;; (<:a :onclick (event (e) ;; (with-call/cc (on-select component object)) ;; false) ;; (or value (slot-value slot 'initform))) ;; (or value (slot-value slot 'initform)))))) ;; (slot-value object 'class))))) ;; (get-instances component) (seq (slot-value instances 'length))))))) ;; (defmethod/remote tfoot ((component <core:table)) ;; (<:tfoot)) ;; (defmethod/remote init ((component <core:table)) ;; (add-class component "grid") ;; (setf (slot-value component 'inner-h-t-m-l) nil) ;; (mapcar (lambda (i) (.append-child component i)) ;; (list (thead component) (tbody component) (tfoot component)))) ;; (defmacro deftable (name supers slots &rest rest) ;; `(progn ;; (defcomponent ,name (,@supers <core:table) ;; () ;; (:default-initargs ;; :slots (jobject ;; :class ;; ,@(mapcar ;; (lambda (slot) ;; `(core-server::jobject ;; :name ',(symbol-to-js (car slot)) ,@(cdr slot))) ;; slots)) ;; ,@(flatten1 rest))))) ;; (defmacro deftable (name class slots) ;; `(defun/cc ,name (instances ;; &key (table-class "table-class")) ;; (<:table :class table-class ;; (<:thead (<:tr ,@(mapcar (lambda (slot) ;; `(<:th ,(getf (cdr slot) :label))) ;; slots))) ;; (<:tbody ;; (mapcar (lambda (instance) ;; (<:tr ;; ,@(mapcar (lambda (slot) ;; `(<:td (funcall ,(getf (cdr slot) :reader) instance))) ;; slots))) ;; instances))))) ;; (defmacro deftable-template (name) ;; (let ((class+ (find-class+ name))) ;; `(defmethod/local core-server::abuzer ((self ,name)) ;; (flet ((get-key (name key) ;; (getf (cdr (assoc name (slot-value self 'slots))) key))) ;; (list ;; (<:thead ;; (<:tr ;; ,@(mapcar (lambda (slot) ;; (with-slotdef (name) slot ;; `(<:th (get-key ',name :label)))) ;; (class+.local-slots class+)))) ;; (<:tbody ;; (mapcar (lambda (instance) ;; (<:tr ;; (mapcar (lambda (slot) ;; ) ;; ))) ;; (slot-value self 'instances)))))))) ;; (defmacro deftable (name supers slots &rest rest) ;; `(progn ;; (defhtml-component ,name (<:table ,@supers) ;; ((slots :initarg :slots :initform ',slots) ;; (instances :initarg :instances :initform nil)) ;; ,@rest) ;; (deftable-template ,name) ;; )) ;; (defmethod shared-initialize :after ((component <core:table) slot-names ;; &key &allow-other-keys) ;; ;; (setf (table.objects component) ;; ;; (mapcar (lambda (instance) ;; ;; (apply #'jobject ;; ;; (nreverse ;; ;; (reduce (lambda (acc slot) ;; ;; (cons (make-keyword (car slot)) ;; ;; (cons (funcall (let ((reader (getf (cdr slot) :reader))) ;; ;; (if (and (listp reader) (eq 'lambda (car reader))) ;; ;; (setf reader (eval reader) ;; ;; (getf (cdr slot) :reader) reader)) ;; ;; (or reader (slot-value instance (car slot)))) ;; ;; instance) ;; ;; acc))) ;; ;; (table.slots component) ;; ;; :initial-value `(:id ,(get-id instance)))))) ;; ;; (table.instances component)) ;; ;; (table.table-slots component) ;; ;; (mapcar (lambda (slot) ;; ;; (jobject :name (symbol-to-js (car slot)) ;; ;; :type (symbol-to-js (getf (cdr slot) :type)) ;; ;; :label (getf (cdr slot) :label))) ;; ;; (table.slots component))) ;; ) ;; (defmethod/remote column-span ((self <core:table)) ;; (call/cc ;; (event (c) ;; (apply self.get-template-class self ;; (list ;; (lambda (_class) ;; (let ((a 1)) ;; (mapobject (lambda (k v) (setq a (+ 1 a))) _class) ;; (c a))))))))
16,185
Common Lisp
.lisp
398
37.369347
103
0.592077
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
474e6e8e49eaab821c0de6c1ea89559af5769db2088e7fd99d5a2487001d7f95
8,365
[ -1 ]
8,366
config.lisp
evrim_core-server/src/install/config.lisp
(in-package :core-server) (defvar +target-directory+ "/opt/core-server/") (defparameter *layout* (if (zerop (sb-posix:geteuid)) (make-server-layout +target-directory+) (make-layout +target-directory+))) (install *layout*)
235
Common Lisp
.lisp
6
36
53
0.70614
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
34b515bf5a189a0d4905f76fb70ee1eb954446685054b09fe7e065fc9f02eb6e
8,366
[ -1 ]
8,367
install.lisp
evrim_core-server/src/install/install.lisp
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. ;; ---------------------------------------------------------------------------- ;; Installation Script for Core Server Project at http://www.core.gen.tr ;; Author: Evrim Ulu <[email protected]> ;; ;; Trademarks for the externals systems do belong to their owners. ;; Use Google(tm) Search (http://www.google.com) to contact the owners ;; of that specific trademark. ;; ---------------------------------------------------------------------------- ;;----------------------------------------------------------------------------- ;; Functions that installer needs starts here ;; There are not loaded during normal Core-Server Startup ;;----------------------------------------------------------------------------- #-core-server (progn (in-package :cl-user) (require :sb-posix) (eval-when (:compile-toplevel :load-toplevel :execute) (if (null (find-package :core-server)) (defpackage :tr.gen.core.server (:use :cl) (:nicknames :core-server) (:export #:command #:shell ; #:darcs #:svn #:tarball #:defcommand #:find-file #:ln #:chmod #:cvs #:useradd))))) (in-package :core-server) ;; Add distribution based features #-core-server (eval-when (:compile-toplevel :load-toplevel :execute) (cond ((probe-file "/etc/pardus-release") (pushnew :pardus *features*)) ((probe-file "/etc/gentoo-release") (pushnew :gentoo *features*)) ((probe-file "/etc/debian_version") (pushnew :debian *features*)))) #-core-server (progn (defun ensure-list (atom-or-list) (if (atom atom-or-list) (list atom-or-list) atom-or-list)) (defun extract-argument-names (lambda-list) "Returns a list of symbols representing the names of the variables bound by the lambda list LAMBDA-LIST." (nreverse (reduce #'(lambda (acc atom) (if (eq #\& (aref (symbol-name atom) 0)) acc (cons atom acc))) lambda-list :initial-value nil))) (defmacro deftrace (name methods) "Defines +name-methods+ variable, trace-name, untrace-name functions for traceing a closed system" (let ((var-symbol (intern (string-upcase (format nil "+~A-methods+" name)))) (trace-symbol (intern (string-upcase (format nil "trace-~A" name)))) (untrace-symbol (intern (string-upcase (format nil "untrace-~A" name))))) `(progn (defparameter ,var-symbol ,methods) (defun ,trace-symbol (&optional (methods ,var-symbol)) (mapcar (lambda (e) (eval `(trace ,e))) methods)) (defun ,untrace-symbol (&optional (methods ,var-symbol)) (mapcar (lambda (e) (eval `(untrace ,e))) methods))))) (defmacro aif (consequent then &optional else) "Special if that binds 'consequent' to 'it'" `(let ((it ,consequent)) (if it ,then ,(if else else)))) (defmacro awhen (consequent &body body) "Special when that binds 'consequent' to 'it'" `(let ((it ,consequent)) (when it ,@body))) (eval-when (:compile-toplevel :load-toplevel :execute) (defmethod make-keyword ((str string)) "Returns keyword for the string 'str'" (intern (string-upcase str) :keyword)) (defmethod make-keyword ((sym symbol)) "Returns keyword for the symbol 'sym'" (intern (symbol-name sym) :keyword))) (defun plist-to-alist (plist) "Transforms a plist to an alist, keywords are transformed into symbols" (let (key) (nreverse (reduce #'(lambda (acc atom) (if (and (null key) (keywordp atom)) (prog1 acc (setf key atom)) (prog1 (cons (cons (intern (symbol-name key)) atom) acc) (setf key nil)))) plist :initial-value nil)))) (defun alist-to-plist (alist) "Transforms an alist to a plist, key symbols are transformed into keywords" (reduce #'(lambda (acc atom) (nreverse (cons (cdr atom) (cons (make-keyword (car atom)) (nreverse acc))))) alist :initial-value nil)) (defmacro s-v (slot-name) "Expands to (slot-value self slot-name)" `(slot-value self ,slot-name)) (defmacro with-current-directory (directory &body body) "Executes body while setting current directory to 'directory'" `(unwind-protect (progn (sb-posix:chdir ,directory) (let ((*default-pathname-defaults* ,directory)) ,@body)) (sb-posix:chdir *default-pathname-defaults*)))) #-core-server (mapc #'(lambda (lisp) (format t "Loading file ~A.~%" lisp) (if (null (load lisp)) (error "Failed to load ~A" lisp))) '("bootstrap.lisp" "search.lisp" "mop.lisp" "class+.lisp" "command.lisp")) ;;----------------------------------------------------------------------------- ;; Functions that installer needs ends here ;;----------------------------------------------------------------------------- ;;----------------------------------------------------------------------------- ;; System Definition ;;----------------------------------------------------------------------------- (defclass sys () ((name :accessor name :initarg :name) (repo-type :accessor repo-type :initarg :repo-type :initform (error "specify repo-type")) (repo :accessor repo :initarg :repo) (homepage :accessor homepage :initarg :homepage) (module :accessor module :initarg :module :initform nil)) (:documentation "Represents an undivisible part of a layout. It can be library, or a bunch of static files or other external system.")) (defmethod print-object ((self sys) stream) (print-unreadable-object (self stream :type t :identity t) (format stream "~A is a ~A sys." (name self) (repo-type self)))) ;;----------------------------------------------------------------------------- ;; System Constructor ;;----------------------------------------------------------------------------- (defun make-system (name type repo &key homepage module) "Return a new system having 'name', 'type' and 'repo' location. 'Homepage' and 'module' for systems are optional. 'module' is needed in some systems like CVS" (make-instance 'sys :name (if (stringp name) (intern (string-upcase name)) name) :repo-type (if (stringp type) (intern (string-upcase type)) type) :repo repo :homepage homepage :module module)) ;;----------------------------------------------------------------------------- ;; System Protocol ;;----------------------------------------------------------------------------- (defgeneric target-directory (sys) (:documentation "Getter for target-directory of this system")) (defgeneric fetch (sys &optional path) (:documentation "Fetchs this system from its 'repository'/'module'")) (defmethod target-directory ((self sys)) (make-pathname :directory (list :relative (string-downcase (symbol-name (name self)))))) (defmethod fetch :around ((sys sys) &optional path) (with-current-directory (or path *default-pathname-defaults*) (call-next-method))) (defmethod fetch ((self sys) &optional path) (declare (ignorable path)) (format t "+-------------------------------------------------+~%") (format t "| Checking out system: ~A~3,50@T|~%" (name self)) (format t "+-------------------------------------------------+~%") (ecase (repo-type self) (cvs (cvs :repo (repo self) :module (module self) :target (name self))) (darcs (darcs :repo (repo self) :target (target-directory self) :lazy t)) (git (git :repo (repo self) :target (target-directory self))) (svn (svn :repo (repo self) :target (target-directory self))) (tar (tarball :repo (repo self) :target (target-directory self))))) ;;----------------------------------------------------------------------------- ;; System Layout ;;----------------------------------------------------------------------------- (defclass layout () ((bin :accessor layout.bin :initarg :bin :initform #P"bin/") (etc :accessor layout.etc :initarg :etc :initform #P"etc/") (projects :accessor layout.projects :initarg :projects :initform #P"projects/") (lib :accessor layout.lib :initarg :lib :initform #P"lib/") (systems :accessor layout.systems :initarg :systems :initform #P"systems/") (lib.conf :accessor layout.lib.conf :initarg :lib.conf :initform #P"lib.conf") (var :accessor layout.var :initarg :var :initform #P"var/") (log :accessor layout.log :initarg :log :initform #P"var/log/") (doc :accessor layout.doc :initarg :doc :initform #P"doc/") (server-type :accessor layout.server-type :initform :httpd :initarg :server-type) (server-address :accessor layout.server-address :initform "0.0.0.0" :initarg :server-address) (server-port :accessor layout.server-port :initform 8080 :initarg :server-port) (swank-port :accessor layout.swank-port :initform 4005 :initarg :swank-port) (swank-encoding :accessor layout.swank-encoding :initform "utf-8-unix" :initarg :swank-encoding) (start.lisp :accessor layout.start.lisp :initarg :start.lisp :initform #P"start.lisp") (end.lisp :accessor layout.end.lisp :initarg :end.lisp :initform #P"end.lisp") (core-server.sh :accessor layout.core-server.sh :initarg :core-server.sh :initform #P"core-server") (registry :initform '() :documentation "Systems registry.") (root :initarg :root :initform (error "One must specify a root directory"))) (:documentation "Represents a Core Server layout")) (defun normalize-target-directory (dir) "Return a normalized version of 'dir' for example: #P\"/home/gee -> #P\"/home/gee/" (let ((dir (pathname dir))) (cond ((and (null (pathname-name dir)) (not (null (pathname-directory dir)))) dir) (t (make-pathname :directory (append (pathname-directory dir) (if (pathname-type dir) (list (format nil "~A.~A" (pathname-name dir) (pathname-type dir))) (list (pathname-name dir))))))))) ;;----------------------------------------------------------------------------- ;; System Layout Constructor ;;----------------------------------------------------------------------------- (defun make-layout (root) (make-instance 'layout :root (normalize-target-directory root))) ;;----------------------------------------------------------------------------- ;; System Layout Accessors ;;----------------------------------------------------------------------------- (defmethod layout.root ((self layout)) (aif (handler-bind ((error #'(lambda (c) (declare (ignore c)) (invoke-restart 'bootstrap:use-nil)))) (bootstrap:home)) (pathname it) (s-v 'root))) (defmethod layout.lib.conf ((self layout)) (aif (handler-bind ((error #'(lambda (c) (declare (ignore c)) (invoke-restart 'bootstrap:use-nil)))) (bootstrap:home)) (merge-pathnames (s-v 'lib.conf) (layout.root self)) (s-v 'lib.conf))) (defmethod layout.etc ((self layout)) (merge-pathnames (s-v 'etc) (layout.root self))) (defmethod layout.bin ((self layout)) (merge-pathnames (s-v 'bin) (layout.root self))) (defmethod layout.lib ((self layout)) (merge-pathnames (s-v 'lib) (layout.root self))) (defmethod layout.start.lisp ((self layout)) (merge-pathnames (s-v 'start.lisp) (layout.etc self))) (defmethod layout.end.lisp ((self layout)) (merge-pathnames (s-v 'end.lisp) (layout.etc self))) (defmethod layout.core-server.sh ((self layout)) (merge-pathnames (s-v 'core-server.sh) (layout.bin self))) (defmethod layout.systems ((self layout)) (merge-pathnames (s-v 'systems) (layout.lib self))) ;;----------------------------------------------------------------------------- ;; System Layout Protocol ;;----------------------------------------------------------------------------- (defgeneric unregister-system (layout system) (:documentation "Unregisters a 'system' from a 'layout'")) (defgeneric register-system (layout system) (:documentation "Registers a 'system' to a 'layout'")) (defgeneric find-system (layout system-name) (:documentation "Returns the system associated with 'system-name' in 'layout'")) (defgeneric read-systems (layout) (:documentation "Reads system definitions from '(layout.lib.conf layout)'")) (defgeneric write-systems (layout) (:documentation "Writes current system definitions to '(layout.lib.conf layout)'")) (defgeneric checkout-system (layout system) (:documentation "Checks out 'system' of 'layout'")) (defgeneric checkout-systems (layout) (:documentation "Checks out all systems in the registry of 'layout'")) (defgeneric link-systems (layout) (:documentation "Creates links for every system in the registry of this 'layout' to '(layout.systems self)'")) ;;----------------------------------------------------------------------------- ;; System Layout Protocol Implementation ;;----------------------------------------------------------------------------- (defmethod unregister-system ((self layout) (sys sys)) (setf (s-v 'registry) (delete sys (s-v 'registry) :key #'name :test #'equal))) (defmethod register-system ((self layout) (sys sys)) (unregister-system self sys) (pushnew sys (s-v 'registry) :key #'name)) (defmethod find-system ((self layout) sysname) (find-if #'(lambda (s) (string= (name s) sysname)) (s-v 'registry))) (defun tokenize (string) (let ((pos (min (or (position #\Space string) (1- (length string))) (or (position #\Tab string) (1- (length string)))))) (cond ((zerop (length string)) nil) ((or (char= #\Space (aref string 0)) (char= #\Tab (aref string 0))) (tokenize (subseq string 1))) ((and (numberp pos) (plusp pos)) (cons (string-trim '(#\Space #\Tab) (subseq string 0 (1+ pos))) (tokenize (subseq string (1+ pos))))) (t (list (string-trim '(#\Space #\Tab) string)))))) (defmethod read-systems ((self layout)) (with-open-file (stream (layout.lib.conf self)) (loop for line = (read-line stream nil nil) while line when (not (char= #\# (aref line 0))) do (let ((tokens (tokenize line))) (register-system self (apply #'make-system tokens)))))) (defmethod write-systems ((self layout)) (with-open-file (stream (layout.lib.conf self) :direction :output :if-exists :supersede :if-does-not-exist :create) (format stream "# Core-server 1.0 Dependencies~%") (loop for sys in (reverse (s-v 'registry)) do (format stream "~A~0,18@T~A~0,8@T~A~%" (string-downcase (name sys)) (string-downcase (repo-type sys)) (repo sys))))) (defmethod checkout-system ((self layout) (sys sys)) (fetch sys (layout.lib self))) (defmethod checkout-systems ((self layout)) (mapcar #'(lambda (r) (checkout-system self r)) (s-v 'registry))) (defmethod link-systems ((self layout)) (with-current-directory (layout.lib self) (let ((systems (find-file :pattern "*.asd"))) (mapcar #'(lambda (sys) (unless (search "_darcs" sys) (with-current-directory (layout.systems self) (ln :source (merge-pathnames (pathname sys) (make-pathname :directory '(:relative :up))) :target (layout.systems self))))) systems)))) ;;----------------------------------------------------------------------------- ;; System Layout Template Helpers ;;----------------------------------------------------------------------------- (defun write-template-sexp (template pathname) "Writes sexp (cdr 'template') to 'pathname'" (with-open-file (s pathname :direction :output :if-exists :supersede :if-does-not-exist :create) (mapcar #'(lambda (line) (format s "~W~%" line)) (cdr template)))) (defun write-template-string (template pathname) "Writes string 'template' to 'pathname'" (with-open-file (s pathname :direction :output :if-exists :supersede :if-does-not-exist :create) (format s "~A~%" template))) ;;----------------------------------------------------------------------------- ;; System Layout Template Protocol ;;----------------------------------------------------------------------------- (defgeneric end.lisp (layout) (:documentation "Returns etc/end.lisp sexp")) (defgeneric start.lisp (layout) (:documentation "Returns etc/start.lisp sexp")) (defgeneric core-server.sh (layout) (:documentation "Returns contents of bin/core-server.sh")) (defgeneric emacs.sh (layout) (:documentation "Returns contents of bin/emacs.sh")) (defgeneric make-installer.sh (layout) (:documentation "Returns contents of bin/make-installer.sh")) (defgeneric write-templates (layout) (:documentation "Writes all templates to associated pathnames")) (defgeneric create-directories (layout) (:documentation "Creates all directories that this 'layout' needs")) (defgeneric install (layout) (:documentation "Installs this 'layout' to '(layout.target-directory layout)'")) ;;----------------------------------------------------------------------------- ;; System Layout Template Implementation ;;----------------------------------------------------------------------------- (defmethod end.lisp ((self layout)) `(progn (in-package :core-server) (stop *server*) (quit 0))) (defmethod start.lisp ((self layout)) `(progn (in-package :cl-user) (require :sb-posix) (require :asdf) (load (merge-pathnames (make-pathname :directory '(:relative :up "src") :name "bootstrap" :type "lisp") (make-pathname :directory (pathname-directory *load-pathname*)))) (bootstrap:register-libs ,(merge-pathnames (s-v 'systems) (s-v 'lib))) (bootstrap:register-projects ,(s-v 'projects)) ;; (require :asdf-binary-locations) (require :core-server) ;; (setf asdf:*source-to-target-mappings* '((#p"/opt/sbcl/lib/sbcl/" nil))) ;; /usr/share/sbcl-source/-> debian ;; (setf (symbol-value (find-symbol "*CODING-SYSTEM*" (find-package 'swank))) ;; ,(layout.swank-encoding self)) (funcall (find-symbol "CREATE-SERVER" (find-package 'swank)) :port ,(layout.swank-port self) :dont-close t) (in-package :core-server) (defclass+ core-server ,(if (eq (layout.server-type self) :mod-lisp) `(apache-server http-server) `(http-server)) () (:default-initargs :name "Core-serveR" :port 8080)) (defvar *server* (make-instance 'core-server)) (start *server*) (if (status *server*) (progn (terpri) (describe *server*) (show-license-to-repl) (write-line "Server started!") (terpri)) (progn (terpri) (write-line "Unable to start server.") (terpri))) ;; start core server manager webapp (require :manager) (in-package :manager) (register-me) (in-package :core-server))) (defmethod core-server.sh ((self layout)) (format nil "#!/bin/bash # Core Server: Web Application Server # # Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. help () { cat <<EOF Usage: $0 command Commands: start Start core server stop Shutdown core server status Query for existence attach Attach to screen instance EOF } # lookup utility using which, exit if not found lookup () { local ret=`which $1` if [ -z $ret ]; then echo \"I couldn't find the utility: $1. Exiting...\" exit 1 else echo $ret fi } # run utility using lookup runX () { `lookup $1` } unset CORESERVER_HOME CORESERVER_HOME=\"~A\" MEMSIZE=\"1024\" CONFIGFILE=\"~A\" PID=\"~Avar/core-server.pid\" ## go to home directory OLDPWD=`pwd` cd ~~ case \"$1\" in start) echo -n \"[ Core-serveR ] starting \" export LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 export CORESERVER_HOME=\"$CORESERVER_HOME\" sleep 1 echo \"now!\" if [ -z ${STY+1} ]; then $(lookup screen) -c /dev/null -dmS core-server \\ $(lookup sbcl) --dynamic-space-size $MEMSIZE \\ --load $CONFIGFILE else $(lookup sbcl) --dynamic-space-size $MEMSIZE \\ --load $CONFIGFILE fi ;; stop) echo \"[ Core-serveR ] stopping \" kill `cat $PID` ;; attach) screen -x core-server ;; status) PP=`cat $PID` if [ ! -f /proc/$PP/status ]; then echo \"[ Core-server ] *not* running\" exit 1 else echo \"[ Core-server ] running\" exit 0 fi ;; *) help ;; esac cd $OLDPWD exit 0 " (layout.root self) (layout.start.lisp self) (layout.root self))) (defmethod emacs.sh ((self layout)) (format nil " #!/bin/sh if [ -z $CORESERVER_HOME ]; then export CORESERVER_HOME=\"~A\" fi emacs -q -l $CORESERVER_HOME/etc/emacs/core-server.el " (layout.root self))) (defmethod make-installer.sh ((self layout)) (format nil " #!/bin/sh if [ -z $CORESERVER_HOME ]; then export CORESERVER_HOME=\"~A\" fi TAR=`which tar` TEMP=`which mktemp` MKDIR=`which mkdir` CP=`which cp` DIR=`$TEMP -d` TARBALL=\"core-server-installer-`date +\"%Y-%m-%d\"`.tar.gz\" $MKDIR -p $DIR/core-server-installer; cd $DIR; $CP $CORESERVER_HOME/src/bootstrap.lisp core-server-installer; $CP $CORESERVER_HOME/src/util/search.lisp core-server-installer; $CP $CORESERVER_HOME/src/util/mop.lisp core-server-installer; $CP $CORESERVER_HOME/src/util/class+.lisp core-server-installer; $CP $CORESERVER_HOME/src/install/* core-server-installer; $CP $CORESERVER_HOME/src/commands/command.lisp core-server-installer; $CP $CORESERVER_HOME/doc/README core-server-installer; $TAR zcf $TARBALL --exclude='*~~' * mv $TARBALL /tmp/ echo \"[Core serveR] Installer tarball is ready: /tmp/$TARBALL \" " (layout.root self))) (defmethod write-templates ((self layout)) (write-template-sexp (start.lisp self) (layout.start.lisp self)) (write-template-sexp (end.lisp self) (layout.end.lisp self)) (write-template-string (core-server.sh self) (layout.core-server.sh self)) (write-template-string (emacs.sh self) (merge-pathnames #P"emacs.sh" (layout.bin self))) (write-template-string (make-installer.sh self) (merge-pathnames #P"make-installer.sh" (layout.bin self)))) (defmethod create-directories ((self layout)) (mapcar #'(lambda (slot) (ensure-directories-exist (merge-pathnames (s-v slot) (layout.root self)))) '(bin projects lib var log)) (ensure-directories-exist (layout.systems self))) (defvar +cp+ (whereis "cp")) (defmethod install ((self layout)) (create-directories self) (read-systems self) (checkout-systems self) (link-systems self) (with-current-directory (layout.root self) (ln :source (merge-pathnames (merge-pathnames (s-v 'etc) #P"core-server/") (s-v 'lib)) :target (layout.root self)) (ln :source (merge-pathnames (merge-pathnames (s-v 'doc) #P"core-server/") (s-v 'lib)) :target (layout.root self))) (write-templates self) (chmod :mode "+x" :path (layout.core-server.sh self)) (shell :cmd +cp+ :args (list "lib.conf" (layout.etc self))) (with-current-directory (layout.root self) (ln :source (merge-pathnames (merge-pathnames #P"src/" #P"core-server/") (s-v 'lib)) :target (layout.root self)) (ln :source (merge-pathnames (merge-pathnames #P"t" #P"core-server/") (s-v 'lib)) :target (layout.root self)) (ln :source (merge-pathnames (merge-pathnames #P"examples" #P"core-server/") (s-v 'lib)) :target (layout.root self))) ;; symlink to the core server manager (with-current-directory (merge-pathnames (s-v 'projects) (layout.root self)) (ln :source (merge-pathnames #P"src/manager/" (layout.root self)) :target (merge-pathnames (s-v 'projects) (layout.root self))))) ;;----------------------------------------------------------------------------- ;; Server System Layout ;;----------------------------------------------------------------------------- ;; ;; This layout is used to install/manage Core Server and severeal unix servers ;; (defclass server-layout (layout) () (:default-initargs :server-type :mod-lisp :server-port 3001 :server-address "127.0.0.1")) ;;----------------------------------------------------------------------------- ;; Server System Layout Constructor ;;----------------------------------------------------------------------------- (defun make-server-layout (root) (make-instance 'server-layout :root (normalize-target-directory root))) ;;----------------------------------------------------------------------------- ;; Server System Layout Implementation ;;----------------------------------------------------------------------------- (defmethod core-server.sh ((self server-layout)) (format nil "#!/bin/bash help () { cat <<EOF Usage: $0 command Commands: start Start core server stop Shutdown core server status Query for existence attach Attach to screen instance EOF } # lookup utility using which, exit if not found lookup () { local ret=`which $1` if [ -z $ret ]; then echo \"I couldn't find the utility: $1. Exiting...\" exit 1 else echo $ret fi } # run utility using lookup runX () { `lookup $1` } # Indefinitely try to run as core. # Recursive. CORE=`id core 2&> /dev/null` CORESERVER_HOME=\"~A\" # if the current user is NOT core and the core id IS present if [ ! $(runX whoami) = \"core\" ] && [ -n \"$CORE\"]; then $(lookup chmod) g+rw $(runX tty) $(lookup su) core -c \"$0 $@\" exit $? fi unset CORESERVER_HOME CORESERVER_HOME=\"~A\" MEMSIZE=\"1024\" CONFIGFILE=\"~A\" PID=\"~Avar/core-server.pid\" ## go to home directory OLDPWD=`pwd` cd ~~ case \"$1\" in start) echo -n \"[ Core-serveR ] starting \" export LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 export CORESERVER_HOME=\"$CORESERVER_HOME\" sleep 1 echo \"now!\" if [ -z ${STY+1} ]; then $(lookup screen) -c /dev/null -dmS core-server \\ $(lookup sbcl) --dynamic-space-size $MEMSIZE \\ --load $CONFIGFILE else $(lookup sbcl) --dynamic-space-size $MEMSIZE \\ --load $CONFIGFILE fi ;; stop) echo \"[ Core-serveR ] stopping \" kill `cat $PID` ;; attach) screen -x core-server ;; status) PP=`cat $PID` if [ -z \"`/bin/cat /proc/$PP/status 2&> /dev/null`\" ]; then echo \"[ Core-server ] *not* running\" exit 1 else echo \"[ Core-server ] running\" exit 0 fi ;; *) help ;; esac cd $OLDPWD exit 0 " (layout.root self) (layout.root self) (layout.start.lisp self) (layout.root self))) (defmethod start.lisp ((self server-layout)) `(progn (in-package :cl-user) (require :sb-posix) (require :asdf) (load (merge-pathnames (make-pathname :directory '(:relative :up "src") :name "bootstrap" :type "lisp") (make-pathname :directory (pathname-directory *load-pathname*)))) (bootstrap:register-libs ,(merge-pathnames (s-v 'systems) (s-v 'lib))) (bootstrap:register-projects ,(s-v 'projects)) ;; (require :asdf-binary-locations) (require :core-server) ;; (setf asdf:*source-to-target-mappings* '((#p"/opt/sbcl/lib/sbcl/" nil))) ;; /usr/share/sbcl-source/-> debian (setf (symbol-value (find-symbol "*CODING-SYSTEM*" (find-package 'swank))) ,(layout.swank-encoding self)) (funcall (find-symbol "CREATE-SERVER" (find-package 'swank)) :port ,(layout.swank-port self) :dont-close t) (in-package :core-server) (defclass+ core-server ,(if (eq (layout.server-type self) :mod-lisp) `(apache-server http-server) `(http-server)) () (:default-initargs :name "Core-serveR")) (defvar *server* (make-instance 'core-server)) (start *server*) (if (status *server*) (progn (terpri) (describe *server*) (show-license-to-repl) (write-line "Server started!") (terpri)) (progn (terpri) (write-line "Unable to start server.") (terpri))) )) ;; chown :apache /var/www ;; chmod g+w /var/www ;; chown :apache /etc/apache2/vhosts.d ;; chmod g+w /etc/apache2/vhosts.d (defvar +sudoers+ "core ALL= NOPASSWD: /usr/sbin/apache2ctl, /etc/init.d/apache2, /etc/init.d/postfix, /etc/init.d/svscan, /usr/bin/find, /bin/chmod, /bin/chown") (defmethod write-templates ((self server-layout)) (write-template-sexp (start.lisp self) (layout.start.lisp self)) (write-template-sexp (end.lisp self) (layout.end.lisp self)) (write-template-string (core-server.sh self) (layout.core-server.sh self)) (write-template-string (emacs.sh self) (merge-pathnames #P"emacs.sh" (layout.bin self))) (write-template-string (make-installer.sh self) (merge-pathnames #P"make-installer.sh" (layout.bin self)))) (defmethod configure-debian-apache ((self server-layout)) (with-open-file (s #P"/etc/apache2/mods-enabled/mod_lisp2.load" :direction :output :if-exists :supersede) (format s "LoadModule lisp_module /usr/lib/apache2/modules/mod_lisp2.so")) (with-open-file (s #P"/etc/apache2/mods-enabled/mod_lisp2.conf" :direction :output :if-exists :supersede) (format s " <LocationMatch \"\\.core$\"> LispServer 127.0.0.1 3001 \"core-server\" SetHandler lisp-handler </LocationMatch>")) (with-current-directory #P"/etc/apache2/mods-enabled/" (mapcar #'(lambda (atom) (let ((load-file (format nil "../mods-available/~A.load" atom)) (conf-file (format nil "../mods-available/~A.conf" atom))) (if (probe-file load-file) (ln :source load-file :target ".")) (if (probe-file conf-file) (ln :source conf-file :target ".")))) '("dav" "dav_fs" "proxy" "proxy_http")))) (defvar +gentoo-apache-config+ " <IfDefine LISP> <IfModule !mod_lisp2.c> LoadModule lisp_module modules/mod_lisp2.so </IfModule> </IfDefine> <IfModule mod_lisp2.c> <LocationMatch \"\\.core$\"> LispServer 127.0.0.1 3001 \"core-server\" SetHandler lisp-handler </LocationMatch> </IfModule> ") (defvar +gentoo-apache-options+ "-D PROXY -D DAV -D DAV_FS -D LISP -D SSL") (defmethod configure-gentoo-apache ((self server-layout)) (with-open-file (s #P"/etc/conf.d/apache2" :direction :output :if-exists :append) (format s "APACHE2_OPTS+=\" ~A\"~%" +gentoo-apache-options+)) (with-open-file (s #P"/etc/apache2/modules.d/666_mod_lisp.conf" :direction :output :if-exists :supersede) (format s "~A~%" +gentoo-apache-config+))) (defvar +pardus-mod-proxy-config+ " <IfDefine PROXY_HTML> <IfModule !mod_proxy_html.c> LoadFile /usr/lib/libxml2.so LoadModule proxy_html_module modules/mod_proxy_html.so </IfModule> </IfDefine> <IfModule mod_proxy_html.c> # See http://apache.webthing.com/mod_proxy_html/ for now :/ </IfModule> ") (defmethod configure-pardus-apache ((self server-layout)) (with-open-file (s #P"/etc/conf.d/apache2" :direction :output :if-exists :append) (format s "APACHE2_OPTS+=\" ~A\"~%" +gentoo-apache-options+)) (with-open-file (s #P"/etc/apache2/modules.d/666_mod_lisp.conf" :direction :output :if-exists :supersede) (format s "~A~%" +gentoo-apache-config+)) (with-open-file (s #P"/etc/apache2/modules.d/27_mod_proxy_html.conf" :direction :output :if-exists :supersede) (format s "~A~%" +pardus-mod-proxy-config+))) ;; FIXME: this does add more lines to sudoers when re-run. (defmethod install ((self server-layout)) (let ((apache-group #+debian "www-data" #+(or gentoo pardus) "apache") (apache-vhosts (merge-pathnames #+debian #P"sites-enabled/" #+(or gentoo pardus) #P"vhosts.d/" #P"/etc/apache2/"))) (unless (zerop (shell :cmd (whereis "id") :args '("core") :errorp nil)) (groupadd :groupname "core") (useradd :username "core" :extra-groups apache-group :group "core" :create-home t)) (ensure-directories-exist (layout.root self)) (chown :user "core" :group "core" :path (layout.root self) :recursive t) (chown :group apache-group :path "/var/www" :recursive t) (chmod :mode "g+w" :path "/var/www" :recursive t) (chown :group apache-group :path apache-vhosts :recursive t) (chmod :mode "g+w" :path apache-vhosts :recursive t) (shell :cmd (whereis "apxs2") :args '("-i" "-c" "mod_lisp2.c")) (handler-bind ((error #'(lambda (e) (declare (ignorable e)) (shell :cmd (whereis "rm") :args '("/etc/apache2/.core-server"))))) (unless (probe-file #P"/etc/apache2/.core-server") (shell :cmd (whereis "touch") :args '("/etc/apache2/.core-server")) #+debian (configure-debian-apache self) #+gentoo (configure-gentoo-apache self) #+pardus (configure-pardus-apache self))) (with-open-file (s #P"/etc/sudoers" :direction :output :if-exists :append) (format s "~A~%" +sudoers+))) (call-next-method) (chown :user "core" :group "core" :recursive t :path (layout.root self)))
34,215
Common Lisp
.lisp
831
36.931408
164
0.612187
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
135f015be60c4b228c543edb8b488eacacc33af050a11438ce1697cefe3c9a1b
8,367
[ -1 ]
8,368
mod_lisp2.c
evrim_core-server/src/install/mod_lisp2.c
/* -*-C-*- ==================================================================== mod_lisp2 is a rewrite of mod_lisp for Apache2. It is based on mod_lisp and the example module from the apache distribution. It is distributed under a BSD style license Copyright 2000-2005 Marc Battyani. Copyright 2003,2004 Massachusetts Institute of Technology Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ==================================================================== */ /* ==================================================================== This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. Portions of this software are based upon public domain software originally written at the National Center for Supercomputing Applications, University of Illinois, Urbana-Champaign. ==================================================================== */ /* Change log: If request contains chunked data, send chunks (length word plus data) to backend lisp. Also eliminated a gcc warning. -- Hugh Winkler 2006-12-05 Fixed the APR 1.2.2 detection. -- sent by several people 2006-1203 Fixed u bug that made mod_lisp send all twice to the lisp process. -- Lars Rune Nøstdal 2006-03-14 Fixes for Apache Portable Runtie (APR) v1.2.2. Should be backward compatible at compile time. Must be recompiled to upgrade or downgrade your APR library, though. -- Nash Foster <[email protected]> 2006-02-27 Update for Apache 2.2.0 Compatability -- Nikola Vouk 2006-02-24 fix r->mtime -- Zach Beane 2006-01-04 Handle Lisp data correctly if there's no Content-Length header -- Dr. Edmund Weitz <[email protected]> 2005-12-24 ML_LOG_DEBUG uses the APLOG_DEBUG level, defaults to on, and hence the LogLevel directive now controls mod_lisp2 logging. Those wishing to squeeze the last iota of performance can use: apxs2 -ic -DENABLE_DEBUG=0 mod_lisp2.c This eliminates debug calls to the logging API entirely. -- Nash Foster <[email protected]> 2005-12-24 Fixed a declaration for some versions of gcc -- Marc Battyani 2005-08-26 Set r->mtime directly -- Dr. Edmund Weitz <[email protected]> 2005-06-07 Read data from Lisp even if it's a HEAD request Added "Lisp-Content-Length" header (send after "Content-Length" header to overwrite its value) -- Dr. Edmund Weitz <[email protected]> 2004-12-27 Fixed lisp_handler to allow for no Content-Length header -- Tim Howe <[email protected]> 2004-11-15 Thread safe socket reuse. -- Marc Battyani <[email protected]> 2004-11-11 Some minor additions for TBNL. -- Dr. Edmund Weitz <[email protected]> 2004-11-09 Initial rewrite of mod_lisp for Apache2 -- Chris Hanson <[email protected]> 2003-12-02 */ #define VERSION_STRING "1.3.1" #define READ_TIMEOUT 200000000 /* Enable debug logging by default so it can be controller with Apache's LogLevel directive. */ #if !defined ( ENABLE_DEBUG ) # define ENABLE_DEBUG 1 #endif #include "httpd.h" #include "http_config.h" #include "http_core.h" #include "http_log.h" #include "http_main.h" #include "http_protocol.h" #include "http_request.h" #include "util_script.h" #include "apr_date.h" #include "apr_strings.h" #include "apr_version.h" #include "apr_errno.h" #include <stdio.h> #include <stdlib.h> #include <string.h> module AP_MODULE_DECLARE_DATA lisp_module; /* Work out the version of the apache portable runtime (APR) we're * compiling against... with version 1.2.2 some of the interfaces * changed a bit. */ #if (APR_MAJOR_VERSION==1 && APR_MINOR_VERSION==2 && APR_PATCH_VERSION>=2) #define HAVE_APR_1_2_2 1 #endif #define RELAY_ERROR(expr) do \ { \ while (1) \ { \ apr_status_t RELAY_ERROR_status = (expr); \ if (APR_SUCCESS == RELAY_ERROR_status) \ break; \ if (!APR_STATUS_IS_EINTR (RELAY_ERROR_status)) \ return (RELAY_ERROR_status); \ } \ } while (0) #define ML_LOG_ERROR(status, r, msg) \ (ap_log_error (APLOG_MARK, APLOG_ERR, (status), \ ((r) -> server), (msg))) #define ML_LOG_PERROR(r, msg) \ ML_LOG_ERROR ((APR_FROM_OS_ERROR (apr_get_os_error ())), (r), (msg)) #define RELAY_HTTP_ERROR(expr) do \ { \ int RELAY_HTTP_ERROR_value = (expr); \ if (RELAY_HTTP_ERROR_value != OK) \ return (RELAY_HTTP_ERROR_value); \ } while (0) #if ENABLE_DEBUG # define ML_LOG_DEBUG(r, msg) \ (ap_log_error (APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, \ ((r) -> server), (msg))) #else # define ML_LOG_DEBUG(r, msg) #endif typedef struct lisp_cfg { const char * server_address; apr_port_t server_port; const char * server_id; apr_socket_t * server_socket; unsigned int server_specified_p : 1, server_socket_safe_p : 1; } lisp_cfg_t; #define CFG(c) ((lisp_cfg_t *) (c)) #define CFG_REF(c, f) ((c) -> f) #define SERVER_ADDRESS(c) CFG_REF (c, server_address) #define SERVER_PORT(c) CFG_REF (c, server_port) #define SERVER_ID(c) CFG_REF (c, server_id) #define SERVER_SPECIFIED_P(c) CFG_REF (c, server_specified_p) #define SERVER_SOCKET(c) CFG_REF (c, server_socket) #define SERVER_SOCKET_SAFE_P(c) CFG_REF (c, server_socket_safe_p) typedef struct input_buffer { char data [4096]; const char * start; const char * end; } input_buffer_t; typedef const char * header_map_t (const char *); /* Global variables */ static apr_pool_t * socket_pool = 0; /* Forward references */ static apr_status_t close_lisp_socket (lisp_cfg_t * cfg); static apr_status_t copy_headers (apr_table_t * table, header_map_t * map_name, apr_socket_t * socket); static header_map_t map_env_var_to_lisp_header; static header_map_t map_header_to_lisp_header; static int write_client_data (request_rec * r, const char * data, unsigned int n_bytes); /* Configuration data */ static lisp_cfg_t * make_lisp_cfg (apr_pool_t * pool) { return (apr_pcalloc (pool, (sizeof (lisp_cfg_t)))); } static lisp_cfg_t * default_lisp_cfg (apr_pool_t * pool) { lisp_cfg_t * cfg = (make_lisp_cfg (pool)); (SERVER_ADDRESS (cfg)) = (apr_pstrdup (pool, "127.0.0.1")); (SERVER_PORT (cfg)) = 3000; (SERVER_ID (cfg)) = (apr_pstrdup (pool, "apache")); (SERVER_SPECIFIED_P (cfg)) = 0; (SERVER_SOCKET (cfg)) = 0; (SERVER_SOCKET_SAFE_P (cfg)) = 0; return (cfg); } static lisp_cfg_t * copy_lisp_cfg (apr_pool_t * pool, lisp_cfg_t * cfg) { lisp_cfg_t * copy = (make_lisp_cfg (pool)); (SERVER_ADDRESS (copy)) = (SERVER_ADDRESS (cfg)); (SERVER_PORT (copy)) = (SERVER_PORT (cfg)); (SERVER_ID (copy)) = (SERVER_ID (cfg)); (SERVER_SPECIFIED_P (copy)) = (SERVER_SPECIFIED_P (cfg)); return (copy); } void check_cfg_for_reuse(lisp_cfg_t *local_cfg, lisp_cfg_t *cfg) { if (strcmp((SERVER_ADDRESS (local_cfg)), (SERVER_ADDRESS (cfg))) || (SERVER_PORT (local_cfg)) != (SERVER_PORT (cfg)) || strcmp((SERVER_ID (local_cfg)), (SERVER_ID (cfg)))) { (SERVER_ADDRESS (local_cfg)) = (SERVER_ADDRESS (cfg)); (SERVER_PORT (local_cfg)) = (SERVER_PORT (cfg)); (SERVER_ID (local_cfg)) = (SERVER_ID (cfg)); (SERVER_SPECIFIED_P (local_cfg)) = (SERVER_SPECIFIED_P (cfg)); (SERVER_SOCKET_SAFE_P (local_cfg)) = 0; } } #if APR_HAS_THREADS static apr_threadkey_t *cfg_key; static lisp_cfg_t * local_lisp_cfg (lisp_cfg_t *cfg) { void *local_cfg = NULL; apr_threadkey_private_get(&local_cfg, cfg_key); if (local_cfg == NULL) { local_cfg = copy_lisp_cfg (socket_pool, cfg); apr_threadkey_private_set(local_cfg, cfg_key); return local_cfg; } check_cfg_for_reuse(local_cfg, cfg); return (lisp_cfg_t*) local_cfg; } #else lisp_cfg_t *local_cfg; local_lisp_cfg (lisp_cfg_t *cfg) { if (!local_cfg) local_cfg = copy_lisp_cfg (socket_pool, cfg); check_cfg_for_reuse(local_cfg, cfg); return local_cfg; } #endif static void * lisp_create_dir_config (apr_pool_t * pool, char * directory) { return (default_lisp_cfg (pool)); } static void * lisp_create_server_config (apr_pool_t * pool, server_rec * s) { return (default_lisp_cfg (pool)); } static void * lisp_merge_config (apr_pool_t * pool, void * base_cfg, void * add_cfg) { return ((SERVER_SPECIFIED_P (CFG (add_cfg))) ? (copy_lisp_cfg (pool, add_cfg)) : (SERVER_SPECIFIED_P (CFG (base_cfg))) ? (copy_lisp_cfg (pool, base_cfg)) : (default_lisp_cfg (pool))); } static const char * lisp_set_server (cmd_parms * cmd, void * cfg_void, const char * server_address, const char * server_port, const char * server_id) { lisp_cfg_t * cfg = cfg_void; long port; { char * end; port = (strtol (server_port, (&end), 0)); if (((*end) != '\0') || (port < 0)) return ("malformed server port"); } (SERVER_ADDRESS (cfg)) = (apr_pstrdup ((cmd->pool), server_address)); (SERVER_PORT (cfg)) = port; (SERVER_ID (cfg)) = (apr_pstrdup ((cmd->pool), server_id)); (SERVER_SPECIFIED_P (cfg)) = 1; close_lisp_socket (cfg); return (0); } /* Socket to Lisp process */ static apr_status_t open_lisp_socket (lisp_cfg_t * cfg) { apr_sockaddr_t * addr; apr_socket_t * socket; if ((SERVER_SOCKET (cfg)) != 0) { if (SERVER_SOCKET_SAFE_P (cfg)) return (APR_SUCCESS); RELAY_ERROR (close_lisp_socket (cfg)); } RELAY_ERROR (apr_sockaddr_info_get ((&addr), (cfg->server_address), APR_UNSPEC, (cfg->server_port), 0, socket_pool)); #if (HAVE_APR_1_2_2) RELAY_ERROR (apr_socket_create ((&socket), AF_INET, SOCK_STREAM, APR_PROTO_TCP, socket_pool)); #else RELAY_ERROR (apr_socket_create ((&socket), AF_INET, SOCK_STREAM, socket_pool)); #endif #if (HAVE_APR_1_2_2) RELAY_ERROR (apr_socket_connect (socket, addr)); #else RELAY_ERROR (apr_connect (socket, addr)); #endif { input_buffer_t * buffer = (apr_palloc (socket_pool, (sizeof (input_buffer_t)))); (buffer -> start) = (buffer -> data); (buffer -> end) = (buffer -> data); RELAY_ERROR (apr_socket_data_set (socket, buffer, "input-buffer", 0)); } (SERVER_SOCKET (cfg)) = socket; (SERVER_SOCKET_SAFE_P (cfg)) = 0; return (APR_SUCCESS); } static apr_status_t close_lisp_socket (lisp_cfg_t * cfg) { if (SERVER_SOCKET (cfg)) { RELAY_ERROR (apr_socket_close (SERVER_SOCKET (cfg))); (SERVER_SOCKET (cfg)) = 0; } return (APR_SUCCESS); } static apr_status_t write_lisp_data (apr_socket_t * socket, const char * data, unsigned int n_bytes) { const char * p = data; apr_size_t n1 = n_bytes; while (1) { apr_size_t n2 = n1; #if (HAVE_APR_1_2_2) RELAY_ERROR (apr_socket_send (socket, p, (&n2))); #else RELAY_ERROR (apr_send (socket, p, &n2)); #endif if (n2 == n1) return (APR_SUCCESS); p += n2; n1 -= n2; } } static apr_status_t write_lisp_data_chunk (apr_socket_t * socket, const char * data, unsigned int n_bytes) { char crlf[2] = {0xd, 0xa}; char length[16]; snprintf(length, 16, "%x", n_bytes); apr_status_t status = write_lisp_data (socket, length, strlen(length)); if ( status == APR_SUCCESS) { status = write_lisp_data (socket, crlf, 2); if ( status == APR_SUCCESS && n_bytes) status = write_lisp_data (socket, data, n_bytes); if ( status == APR_SUCCESS) status = write_lisp_data (socket, crlf, 2); } return status; } static apr_status_t write_lisp_line (apr_socket_t * socket, const char * data) { RELAY_ERROR (write_lisp_data (socket, data, (strlen (data)))); RELAY_ERROR (write_lisp_data (socket, "\n", 1)); return (APR_SUCCESS); } static apr_status_t write_lisp_header (apr_socket_t * socket, const char * name, const char * value) { RELAY_ERROR (write_lisp_line (socket, name)); RELAY_ERROR (write_lisp_line (socket, value)); return (APR_SUCCESS); } static apr_status_t get_input_buffer (apr_socket_t * socket, input_buffer_t ** buffer_r) { return (apr_socket_data_get (((void **) buffer_r), "input-buffer", socket)); } static apr_status_t fill_input_buffer (apr_socket_t * socket) { input_buffer_t * buffer; apr_size_t length; RELAY_ERROR (get_input_buffer (socket, (&buffer))); #if (HAVE_APR_1_2_2) RELAY_ERROR (((length = (sizeof (buffer->data))), (apr_socket_recv (socket, (buffer->data), (&length))))); #else RELAY_ERROR (((length = (sizeof (buffer->data))), (apr_recv (socket, (buffer->data), (&length))))); #endif (buffer->start) = (buffer->data); (buffer->end) = ((buffer->data) + length); if (length == 0) (buffer->start) += 1; return (APR_SUCCESS); } static apr_status_t read_lisp_line (apr_socket_t * socket, char * s, unsigned int len) { input_buffer_t * buffer; char * scan_output = s; char * end_output = (scan_output + (len - 1)); unsigned int n_pending_returns = 0; RELAY_ERROR (get_input_buffer (socket, (&buffer))); while (1) { if ((buffer->start) == (buffer->end)) RELAY_ERROR (fill_input_buffer (socket)); if ((buffer->start) > (buffer->end)) { if (scan_output == s) return (APR_EOF); goto done; } while (((buffer->start) < (buffer->end)) && (scan_output < end_output)) { char c = (*(buffer->start)++); if (c == '\n') { if (n_pending_returns > 0) n_pending_returns -= 1; goto done; } if (c == '\r') n_pending_returns += 1; else { while ((n_pending_returns > 0) && (scan_output < end_output)) { (*scan_output++) = '\r'; n_pending_returns -= 1; } if (scan_output == end_output) goto done; (*scan_output++) = c; } } } done: while ((n_pending_returns > 0) && (scan_output < end_output)) { (*scan_output++) = '\r'; n_pending_returns -= 1; } (*scan_output) = '\0'; return (APR_SUCCESS); } /* Request handler */ #define CVT_ERROR(expr, msg) do \ { \ apr_status_t CVT_ERROR_status = (expr); \ if (APR_SUCCESS != CVT_ERROR_status) \ { \ ap_log_error (APLOG_MARK, APLOG_ERR, CVT_ERROR_status, \ (r->server), "error %s", msg); \ close_lisp_socket (cfg); \ return (HTTP_INTERNAL_SERVER_ERROR); \ } \ } while (0) static int lisp_handler (request_rec * r) { lisp_cfg_t * cfg = (ap_get_module_config ((r->per_dir_config), (&lisp_module))); int content_length = (-1); int keep_socket_p = 0; apr_socket_t * socket; const char * request_content_length = 0; cfg = local_lisp_cfg(cfg); if ((strcmp ((r->handler), "lisp-handler")) != 0) return (DECLINED); /* Open a connection to the Lisp process. */ ML_LOG_DEBUG (r, "open lisp connection"); CVT_ERROR ((open_lisp_socket (cfg)), "opening connection to Lisp"); (SERVER_SOCKET_SAFE_P (cfg)) = 0; socket = (SERVER_SOCKET (cfg)); /* Remove any timeout that might be left over from earlier. */ ML_LOG_DEBUG (r, "clear socket timeout"); CVT_ERROR ((apr_socket_timeout_set (socket, (-1))), "clearing read timeout"); /* Convert environment variables to headers and send them. */ ML_LOG_DEBUG (r, "write env-var headers"); ap_add_cgi_vars (r); ap_add_common_vars (r); if ((r->subprocess_env) != 0) CVT_ERROR ((copy_headers ((r->subprocess_env), map_env_var_to_lisp_header, socket)), "writing to Lisp"); /* Send this before client headers so ASSOC can be used to grab it without worrying about some joker sending a server-id header of his own. (Robert Macomber) */ ML_LOG_DEBUG (r, "write headers"); /* CVT_ERROR ((write_lisp_header (socket, "server-id", (cfg->server_id))), */ /* "writing to Lisp, server-id"); */ /* CVT_ERROR ((write_lisp_header (socket, "server-baseversion", AP_SERVER_BASEVERSION)), */ /* "writing to Lisp, server-baseversion"); */ /* CVT_ERROR ((write_lisp_header (socket, "modlisp-version", VERSION_STRING)), */ /* "writing to Lisp, modlisp-version"); */ /* CVT_ERROR ((write_lisp_header (socket, "modlisp-major-version", "2")), */ /* "writing to Lisp, modlisp-major-version"); */ /* Send all the remaining headers. */ if ((r->headers_in) != 0) CVT_ERROR ((copy_headers ((r->headers_in), map_header_to_lisp_header, socket)), "writing to Lisp"); request_content_length = apr_table_get(r->headers_in, "Content-Length"); /* Send the end-of-headers marker. */ ML_LOG_DEBUG (r, "write end-of-headers"); CVT_ERROR ((write_lisp_line (socket, "end")), "writing to Lisp"); /* Send the request entity. */ RELAY_HTTP_ERROR (ap_setup_client_block (r, REQUEST_CHUNKED_DECHUNK)); if (ap_should_client_block (r)) { char buffer [4096]; ML_LOG_DEBUG (r, "write entity"); while (1) { long n_read = (ap_get_client_block (r, buffer, (sizeof (buffer)))); if (n_read < 0) { ML_LOG_PERROR (r, "error reading from client"); close_lisp_socket (cfg); return (HTTP_INTERNAL_SERVER_ERROR); } /* for chunked case, when nread == 0, we will write * a terminating 0.*/ { apr_status_t status = APR_SUCCESS; /* if there's no Content-Type header, the data must be chunked */ if (request_content_length == NULL) status = write_lisp_data_chunk (socket, buffer, n_read); else if (n_read != 0) status = write_lisp_data (socket, buffer, n_read); if (APR_SUCCESS != status) { while ((ap_get_client_block (r, buffer, sizeof(buffer))) > 0) ; ML_LOG_ERROR (status, r, "writing to Lisp"); close_lisp_socket (cfg); return (HTTP_INTERNAL_SERVER_ERROR); } } if( n_read == 0) break; } } /* Set up read timeout so we don't hang forever if Lisp is wedged. */ /* ML_LOG_DEBUG (r, "set socket timeout"); */ /* CVT_ERROR ((apr_socket_timeout_set (socket, READ_TIMEOUT)), */ /* "setting read timeout"); */ /* Read the headers and process them. */ ML_LOG_DEBUG (r, "read headers"); while (1) { char header_name [4096]; char header_value [MAX_STRING_LEN]; ML_LOG_DEBUG (r, "set socket timeout"); CVT_ERROR ((apr_socket_timeout_set (socket, READ_TIMEOUT)), "setting read timeout"); CVT_ERROR ((read_lisp_line (socket, header_name, (sizeof (header_name)))), "reading from Lisp"); if ((strcasecmp (header_name, "end")) == 0) break; CVT_ERROR ((read_lisp_line (socket, header_value, (sizeof (header_value)))), "reading from Lisp"); if ((strcasecmp (header_name, "content-type")) == 0) { char * tmp = (apr_pstrdup ((r->pool), header_value)); ap_content_type_tolower (tmp); (r->content_type) = tmp; } else if ((strcasecmp (header_name, "status")) == 0) { (r->status) = (atoi (header_value)); (r->status_line) = (apr_pstrdup ((r->pool), header_value)); } else if ((strcasecmp (header_name, "location")) == 0) apr_table_set ((r->headers_out), header_name, header_value); else if ((strcasecmp (header_name, "content-length")) == 0) { apr_table_set ((r->headers_out), header_name, header_value); content_length = (atoi (header_value)); } else if ((strcasecmp (header_name, "lisp-content-length")) == 0) { content_length = (atoi (header_value)); } else if ((strcasecmp (header_name, "last-modified")) == 0) { apr_time_t mtime = (apr_date_parse_http (header_value)); r->mtime = mtime; ap_set_last_modified (r); } else if ((strcasecmp (header_name, "keep-socket")) == 0) keep_socket_p = (atoi (header_value)); else if ((strcasecmp (header_name, "log-emerg")) == 0) ap_log_error (APLOG_MARK, APLOG_EMERG, APR_SUCCESS, (r->server), "%s", header_value); else if ((strcasecmp (header_name, "log-alert")) == 0) ap_log_error (APLOG_MARK, APLOG_ALERT, APR_SUCCESS, (r->server), "%s", header_value); else if ((strcasecmp (header_name, "log-crit")) == 0) ap_log_error (APLOG_MARK, APLOG_CRIT, APR_SUCCESS, (r->server), "%s", header_value); else if ((strcasecmp (header_name, "log-error")) == 0) ap_log_error (APLOG_MARK, APLOG_ERR, APR_SUCCESS, (r->server), "%s", header_value); else if ((strcasecmp (header_name, "log-warning")) == 0) ap_log_error (APLOG_MARK, APLOG_WARNING, APR_SUCCESS, (r->server), "%s", header_value); else if ((strcasecmp (header_name, "log-notice")) == 0) ap_log_error (APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, (r->server), "%s", header_value); else if ((strcasecmp (header_name, "log-info")) == 0) ap_log_error (APLOG_MARK, APLOG_INFO, APR_SUCCESS, (r->server), "%s", header_value); else if ((strcasecmp (header_name, "log-debug")) == 0) ap_log_error (APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, (r->server), "%s", header_value); else if ((strcasecmp (header_name, "log")) == 0) ap_log_error (APLOG_MARK, APLOG_ERR, APR_SUCCESS, (r->server), "%s", header_value); else if ((strcasecmp (header_name, "note")) == 0) { char * p = (strchr (header_value, ' ')); if (p != 0) { (*p++) = '\0'; apr_table_setn ((r->notes), (apr_pstrdup ((r->pool), header_value)), (apr_pstrdup ((r->pool), p))); } } else if ((strcasecmp (header_name, "set-cookie")) == 0) { apr_table_add ((r->headers_out), header_name, header_value); } else apr_table_set ((r->headers_out), header_name, header_value); } /* Copy the reply entity from Lisp to the client... */ // if (content_length > 0) { unsigned int n_read = 0; input_buffer_t * buffer; ML_LOG_DEBUG (r, "read entity"); CVT_ERROR ((get_input_buffer (socket, (&buffer))), "reading from Lisp"); while ((buffer->start) <= (buffer->end)) { apr_status_t fill_status; unsigned int n_bytes = ((buffer->end) - (buffer->start)); n_read += n_bytes; if ((content_length >= 0) && (n_read > content_length)) { n_bytes -= (n_read - content_length); n_read -= (n_read - content_length); } /* ...unless it's a HEAD request. */ if (!r->header_only && !write_client_data (r, (buffer->start), n_bytes)) { close_lisp_socket (cfg); return (HTTP_INTERNAL_SERVER_ERROR); } (buffer->start) += n_bytes; if (n_read == content_length) break; fill_status = fill_input_buffer (socket); if ((fill_status == APR_EOF) && (content_length < 0)) break; else CVT_ERROR (fill_status, "reading from Lisp"); } } if ((content_length < 0) || (!keep_socket_p)) CVT_ERROR ((close_lisp_socket (cfg)), "closing connection to Lisp"); else (SERVER_SOCKET_SAFE_P (cfg)) = 1; ML_LOG_DEBUG (r, "request finished"); return (OK); } static apr_status_t copy_headers (apr_table_t * table, header_map_t * map_name, apr_socket_t * socket) { const apr_array_header_t * h = (apr_table_elts (table)); const apr_table_entry_t * scan = ((apr_table_entry_t *) (h->elts)); const apr_table_entry_t * end = (scan + (h->nelts)); while (scan < end) { const char * name = ((*map_name) (scan->key)); if (name != 0) RELAY_ERROR (write_lisp_header (socket, name, (scan->val))); scan += 1; } return (APR_SUCCESS); } static const char * map_env_var_to_lisp_header (const char * var) { const char * plist [] = { "REQUEST_URI", "url", "CONTENT_TYPE", "content-type", "CONTENT_LENGTH", "content-length", "REQUEST_METHOD", "method", "REMOTE_ADDR", "remote-ip-addr", "REMOTE_PORT", "remote-ip-port", "SERVER_ADDR", "server-ip-addr", "SERVER_PORT", "server-ip-port", "SERVER_PROTOCOL", "server-protocol", "SCRIPT_FILENAME", "script-filename", "SSL_SESSION_ID", "ssl-session-id", 0 }; const char ** p = plist; if ((var == 0) || ((strncmp (var, "HTTP_", 5)) == 0)) return (0); while (1) { const char * v = (*p++); if (v == 0) return (0); if ((strcmp (v, var)) == 0) return (*p); p += 1; } } static const char * map_header_to_lisp_header (const char * name) { return (((name != 0) && ((strcasecmp (name, "end")) == 0)) ? "end-header" : name); } static int write_client_data (request_rec * r, const char * data, unsigned int n_bytes) { while (n_bytes > 0) { int n = (ap_rwrite (data, n_bytes, r)); if (n < 0) { ML_LOG_PERROR (r, "error writing to client"); return (0); } n_bytes -= n; data += n; } return (1); } /* Module setup */ static int lisp_post_config (apr_pool_t * cfg_pool, apr_pool_t * log_pool, apr_pool_t * temp_pool, server_rec * s) { ap_add_version_component (cfg_pool, "mod_lisp2/" VERSION_STRING); return (OK); } static apr_status_t destroy_socket_pool (void * dummy) { #if APR_HAS_THREADS apr_threadkey_private_delete(cfg_key); #endif apr_pool_destroy (socket_pool); socket_pool = 0; return (APR_SUCCESS); } static void lisp_child_init (apr_pool_t * pool, server_rec * s) { if (APR_SUCCESS == apr_pool_create ((&socket_pool), 0)) { apr_pool_cleanup_register (pool, 0, destroy_socket_pool, destroy_socket_pool); #if APR_HAS_THREADS apr_threadkey_private_create(&cfg_key, NULL, socket_pool); #endif } } static const command_rec lisp_command_handlers [] = { AP_INIT_TAKE3 ("LispServer", lisp_set_server, 0, OR_ALL, "The Lisp server name, port and ID string." " Example: LispServer 127.0.0.1 3000 \"apache\""), {0} }; static void register_hooks (apr_pool_t * pool) { ap_hook_post_config (lisp_post_config, 0, 0, APR_HOOK_MIDDLE); ap_hook_child_init (lisp_child_init, 0, 0, APR_HOOK_MIDDLE); ap_hook_handler (lisp_handler, 0, 0, APR_HOOK_MIDDLE); } module AP_MODULE_DECLARE_DATA lisp_module = { STANDARD20_MODULE_STUFF, lisp_create_dir_config, /* create per-directory config structures */ lisp_merge_config, /* merge per-directory config structures */ lisp_create_server_config, /* create per-server config structures */ lisp_merge_config, /* merge per-server config structures */ lisp_command_handlers, register_hooks };
28,007
Common Lisp
.lisp
839
29.213349
97
0.626689
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
e0ff90b609875762bcc7e23f362db72f0d3dc85f6029446b17bc4db0c76ba262
8,368
[ -1 ]
8,369
crud.lisp
evrim_core-server/src/database/crud.lisp
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :core-server) ;; +---------------------------------------------------------------------------- ;; | CRUD Boilerplate ;; +---------------------------------------------------------------------------- (defmacro redeftransaction (name args &body body) `(progn (fmakunbound ',name) (deftransaction ,name ,args ,@body))) (defmacro defcrud (class &optional prefix) (let ((class+ (find-class+ class))) (destructuring-bind (all find query add update delete) (class+.crud-functions class+ prefix) (let (;; (lambda-list1 (class+.ctor-lambda-list class+ t)) (lambda-list2 (class+.ctor-lambda-list class+ nil)) (lambda-list3 (class+.ctor-query-lambda-list class+ t))) (with-unique-names (server) (let ((server (intern (symbol-name server)))) `(progn (redefmethod ,all ((,server abstract-database)) (find-all-objects ,server ',class)) (redefmethod ,query ((,server abstract-database) &key ,@lambda-list3) (flet ((find-object (slot value) (find-objects-with-slot ,server ',class slot value))) (let ((set (reduce (lambda (acc atom) (if (car atom) (cons (cdr atom) acc) acc)) (list ,@(mapcar (lambda (slot) `(if ,(caddr slot) (cons ,(caddr slot) (find-object ',(car slot) ,(car slot))) (cons nil nil))) lambda-list3)) :initial-value nil))) (nreverse (reduce (lambda (set1 set2) (intersection (ensure-list set2) (ensure-list set1))) (cdr set) :initial-value (car set)))))) (redefmethod ,find ((,server abstract-database) &key ,@lambda-list3) (let ((args (reduce (lambda (acc slot) (if (caddr slot) (cons (make-keyword (car slot)) (cons (cadr slot) acc)) acc)) (list ,@(mapcar (lambda (a) `(list ',(car a) ,(car a) ,(caddr a))) lambda-list3)) :initial-value nil))) (car (apply #',query ,server args)))) (redefmethod ,add ((,server abstract-database) &key ,@lambda-list2) (add-object ,server ',class ,@(mapcar (lambda (slot) `(cons ',(car slot) ,(car slot))) lambda-list2))) (redefmethod ,update ((,server abstract-database) (instance ,class) &key ,@lambda-list3) (apply #'update-object ,server instance (filter (lambda (a) (not (null a))) (list ,@(reduce (lambda (acc slot) (cons `(if ,(caddr slot) (cons ',(car slot) ,(car slot))) acc)) lambda-list3 :initial-value nil))))) (redefmethod ,delete ((,server abstract-database) (instance ,class)) (delete-object ,server instance)) (defmethod database.clone ((,server abstract-database) (instance ,class)) (,add ,server ,@(reduce0 (lambda (acc slot) (with-slotdef (initarg reader leaf) slot (cons initarg (cons (if leaf `(database.clone ,server (,reader instance)) `(,reader instance)) acc)))) (remove 'database-id (class+.local-slots class+) :key #'slot-definition-name))))))))))) (defmacro defcrud/lift (target-class source-class &optional prefix) (let ((source+ (find-class+ source-class))) (let ((delete (class+.delete-function source+ prefix)) (update (class+.update-function source+ prefix))) `(progn (defmethod/lift ,update ((server abstract-database) (instance ,target-class) &key ,@(class+.ctor-query-lambda-list source+ t))) (defmethod/lift ,delete ((server abstract-database) (instance ,target-class)))))))
4,340
Common Lisp
.lisp
100
36.94
84
0.609168
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
8f4653db086159bf707333ee24863d65d2a681ee86166c2305d4eca5efc8e08f
8,369
[ -1 ]
8,370
object.lisp
evrim_core-server/src/database/object.lisp
;; +---------------------------------------------------------------------------- ;; | Object Database Interface ;; +---------------------------------------------------------------------------- (in-package :core-server) ;; ---------------------------------------------------------------------------- ;; Protocol ;; ---------------------------------------------------------------------------- (defgeneric find-all-objects (server class) (:documentation "Returns all objects that are member of class")) (defmethod find-all-objects ((server database) (class symbol)) (find-all-objects server (find-class class))) (defgeneric find-object-with-slot (server class slot value) (:documentation "Returns object that is a member of class having slot 'value'")) (defmethod find-object-with-slot ((server database) (class symbol) (slot symbol) value) (find-object-with-slot server (find-class class) slot value)) (defmethod find-objects-with-slot ((server database) (class symbol) (slot symbol) value) (find-objects-with-slot server (find-class class) slot value)) (defgeneric add-object (server class &rest slots-and-values) (:documentation "Creates a new instances of class having slots-and-values")) (defmethod add-object ((server database) (class symbol) &rest slots-and-values) (apply #'add-object server (find-class class) slots-and-values)) (defgeneric update-object (server instance &rest slots-and-values) (:documentation "Updates instance with slots-and-values")) (defgeneric delete-object (server instance) (:documentation "Removes instance")) ;; +---------------------------------------------------------------------------- ;; | Simple Object Database (no slot index, only class indexes) ;; +---------------------------------------------------------------------------- (defmethod class-index-name ((server database) (class standard-class)) (class-name class)) (defmethod class-index ((server database) (class standard-class)) (gethash (class-index-name server class) (database.root server))) (defmethod (setf class-index) (value (server database) (class standard-class)) (setf (gethash (class-index-name server class) (database.root server)) value)) (defmethod add-to-class-index ((server database) object) (mapcar (lambda (class) (setf (class-index server class) (cons object (class-index server class)))) (cons (class-of object) (remove (class-of object) (class+.superclasses (class-of object)))))) (defmethod delete-from-class-index ((server database) object) (mapcar (lambda (class) (setf (class-index server class) (delete object (class-index server class)))) (cons (class-of object) (remove (class-of object) (class+.superclasses (class-of object)))))) (defmethod find-all-objects ((server database) (class standard-class)) (class-index server class)) (defmethod find-objects-with-slot ((server database) (class standard-class) (slot symbol) value) (nreverse (reduce0 (lambda (acc object) (if (equal value (slot-value object slot)) (cons object acc) acc)) (find-all-objects server class)))) (defmethod find-object-with-slot ((server database) (class standard-class) (slot symbol) value) (car (find-objects-with-slot server class slot value))) (deftransaction update-object ((server database) (object standard-object) &rest slots-and-values) (reduce (lambda (object slot-val) (if (slot-exists-p object (car slot-val)) (setf (slot-value object (car slot-val)) (cdr slot-val)) (warn "Slot ~A not found in ~A" (car slot-val) object)) object) slots-and-values :initial-value object)) (deftransaction add-object ((server database) (class standard-class) &rest slots-and-values) (let ((object (apply #'allocate-instance class (class-default-initarg-values class))) (initargs (reduce0 #'append (uniq (filter (lambda (a) (not (member (car a) slots-and-values :key #'car :test #'string=))) (mapcar (lambda (a) (list (car a) (cadr a))) (class-default-initarg-values class))) :key #'car)))) (apply #'update-object server object slots-and-values) (apply #'initialize-instance object initargs) (add-to-class-index server object) ;; ------------------------------------------------------------------------- ;; Add this object to cache so that it wont be serialized again. -evrim. ;; ------------------------------------------------------------------------- (with-slots (cache counter) (slot-value server 'database-cache) (let ((counter (incf counter))) (setf (gethash counter cache) object) (setf (gethash object cache) counter))) object)) ;; ------------------------------------------------------------------------- ;; We cannot remove an object from cache since logging will take place ;; after this execution. -evrim. ;; ------------------------------------------------------------------------- (deftransaction delete-object ((server database) (object standard-object)) (prog1 object (delete-from-class-index server object) ;; (with-slots (cache) (slot-value server 'database-cache) ;; (let ((counter (gethash object cache))) ;; (remhash counter cache) ;; (remhash object cache))) )) ;; +---------------------------------------------------------------------------- ;; | Extended Object Database (class+, slot indexes, relations) ;; +---------------------------------------------------------------------------- (defmethod database.serialize ((self abstract-database) (object class+-instance) &optional (k (curry #'database.serialize self))) (assert (null (any (lambda (slot) (eq 'lift (slot-definition-host slot))) (class+.slots (class-of object)))) nil "Lifted objects cant go into db: ~A" object) (with-slots (cache counter) (slot-value self 'database-cache) (multiple-value-bind (id foundp) (gethash object cache) (if foundp (<db:ref :id (format nil "~D" id)) (let ((counter (incf counter))) (setf (gethash object cache) counter) (<db:instance :id counter (funcall k (class-of object) k) (mapcar (lambda (slot) (let ((slot (slot-definition-name slot))) (<db:slot :name (symbol->string slot) (funcall k (slot-value object slot) k)))) (class+.local-slots (class-of object))))))))) (defmethod database.serialize ((self abstract-database) (object html-element) &optional (k (curry #'database.serialize self) )) (if (typep object 'component) (call-next-method self object k) object)) (deftransaction next-id ((server database)) (let ((current (database.get server :id-counter))) (if current (setf (database.get server :id-counter) (1+ current)) (setf (database.get server :id-counter) 1)))) (defmethod slot-index-name ((server database) (class standard-class) slot) (any (lambda (class) (aif (member slot (mapcar #'slot-definition-name (mopp::class-direct-slots class))) (intern (concat (symbol-name (class-name class)) "-" (symbol-name slot)) (symbol-package (class-name class))))) (reverse (class-superclasses class)))) (defmethod slot-index-name ((server database) (object standard-object) slot) (slot-index-name server (class-of object) slot)) (defmethod slot-index-name ((server database) (class symbol) slot) (slot-index-name server (find-class class) slot)) (defmethod (setf slot-index) (value (server database) object slot) (setf (gethash (slot-index-name server object slot) (database.root server)) value)) (defmethod slot-index ((server database) object slot) (or (gethash (slot-index-name server object slot) (database.root server)) (setf (slot-index server object slot) (make-hash-table :test #'equal)))) (defmethod add-to-slot-index ((server database) object slot) (when (class+.slot-boundp object slot) (setf (gethash (slot-value object slot) (slot-index server object slot)) (cons object (gethash (slot-value object slot) (slot-index server object slot))))) object) (defmethod delete-from-slot-index ((server database) object slot) (when (class+.slot-boundp object slot) (if (null (setf (gethash (slot-value object slot) (slot-index server object slot)) (cdr (gethash (slot-value object slot) (slot-index server object slot))))) (remhash (slot-value object slot) (slot-index server object slot)))) object) (defmethod regenerate-slot-indexes ((server database)) (maphash (lambda (k v) (when (and (find-class k nil) (member (find-class 'class+-instance) (class+.superclasses (find-class k)))) (mapcar (lambda (object) (reduce (lambda (object slot) (delete-from-slot-index server object (slot-definition-name slot)) (add-to-slot-index server object (slot-definition-name slot)) object) (class+.indexes (find-class k)) :initial-value object)) v))) (database.root server))) (defmethod find-objects-with-slot ((server database) (class class+) (slot symbol) value) (let ((slot (class+.find-slot class slot))) (if (slot-definition-index slot) (gethash value (slot-index server class (slot-definition-name slot))) (call-next-method)))) (defmethod find-object-with-slot ((server database) (class class+) (slot symbol) value) (car (find-objects-with-slot server class slot value))) (defmethod find-object-with-id ((server database) id) (find-object-with-slot server (find-class+ 'object-with-id) 'database-id id)) (deftransaction change-class-of ((server database) (object class+-instance) (class class+)) (delete-from-class-index server object) (change-class object class) (add-to-class-index server object) object) (deftransaction update-object ((server database) (object class+-instance) &rest slots-and-values) (reduce (lambda (object slot-val) (destructuring-bind (name . new-value) slot-val (let ((old-value (and (class+.slot-boundp object name) (slot-value object name)))) (let ((slot (class+.find-slot (class-of object) name))) (when slot (with-slotdef (name index relation) slot (cond ((and relation old-value) (multiple-value-bind (relation-type relational-slot) (slot-definition-relation-type slot) (case relation-type (:n-to-one (setf (slot-value old-value (slot-definition-name relational-slot)) (remove object (slot-value old-value (slot-definition-name relational-slot))))) (:one-to-n (reduce (lambda (object old-value) (setf (slot-value old-value (slot-definition-name relational-slot)) object) object) (ensure-list old-value) :initial-value object)) (:n-to-n (reduce (lambda (object target) (setf (slot-value target (slot-definition-name relational-slot)) (remove object (slot-value target (slot-definition-name relational-slot)))) object) old-value :initial-value object)) (:one-to-one (setf (slot-value old-value (slot-definition-name relational-slot)) nil))))) ((and (null relation) index) (delete-from-slot-index server object name))) (setf (slot-value object name) new-value) (cond ((and (null relation) index) (add-to-slot-index server object name)) ((and relation new-value) (multiple-value-bind (relation-type relational-slot) (slot-definition-relation-type slot) (case relation-type (:n-to-one (setf (slot-value new-value (slot-definition-name relational-slot)) (cons object (remove object (slot-value new-value (slot-definition-name relational-slot)))))) (:one-to-n (reduce (lambda (object new-value) (setf (slot-value new-value (slot-definition-name relational-slot)) object) object) (ensure-list new-value) :initial-value object)) (:n-to-n (reduce (lambda (object target) (setf (slot-value target (slot-definition-name relational-slot)) (cons object (slot-value target (slot-definition-name relational-slot)))) object) new-value :initial-value object)) (:one-to-one (setf (slot-value new-value (slot-definition-name relational-slot)) object))))))))))) object) slots-and-values :initial-value object)) (deftransaction add-object ((server database) (class class+) &rest slots-and-values) (let ((lifted (any (lambda (slot) (eq (slot-definition-host slot) 'lift)) (class+.slots class)))) (assert (null lifted) nil "This is lifted, should not go into db ~A" class)) (if (member (find-class+ 'object-with-id) (class+.superclasses class)) (setf slots-and-values (cons (cons 'database-id (next-id server)) (remove 'database-id slots-and-values :key #'car)))) (let ((object (allocate-instance class)) (initargs (reduce0 #'append (uniq (filter (lambda (a) (not (member (car a) slots-and-values :key #'car :test #'string=))) (mapcar (lambda (a) (list (car a) (cadr a))) (class-default-initarg-values class))) :key #'car)))) (apply #'update-object server object slots-and-values) (apply #'initialize-instance object initargs) (add-to-class-index server object) ;; ------------------------------------------------------------------------- ;; Add this object to cache so that it wont be serialized again. -evrim. ;; ------------------------------------------------------------------------- (with-slots (cache counter) (slot-value server 'database-cache) (let ((counter (incf counter))) (setf (gethash counter cache) object) (setf (gethash object cache) counter))) object)) (deftransaction delete-object ((server database) (object class+-instance)) ;; Remove From Class Index (delete-from-class-index server object) ;; Remove From Slot Indexes (reduce (lambda (object slot) (delete-from-slot-index server object (slot-definition-name slot)) object) (class+.indexes (class-of object)) :initial-value object) ;; Remove From Relational Objects (reduce (lambda (object slot) (let ((old-value (and (class+.slot-boundp object (slot-definition-name slot)) (slot-value object (slot-definition-name slot))))) (when old-value (multiple-value-bind (relation-type relational-slot) (slot-definition-relation-type slot) (case relation-type (:n-to-one (setf (slot-value old-value (slot-definition-name relational-slot)) (remove object (slot-value old-value (slot-definition-name relational-slot))))) (:one-to-n (reduce (lambda (object old-value) (setf (slot-value old-value (slot-definition-name relational-slot)) nil) object) (ensure-list old-value) :initial-value object)) (:n-to-n (reduce (lambda (object target) (setf (slot-value target (slot-definition-name relational-slot)) (remove object (slot-value target (slot-definition-name relational-slot)))) object) old-value :initial-value object)) (:one-to-one (setf (slot-value old-value (slot-definition-name relational-slot)) nil))))) object)) (class+.relations (class-of object)) :initial-value object) ;; Process Leafs ;; FIXME: do typesafe version of the below ie. clos dispatch -evrim. (reduce (lambda (object slot) (let ((value (and (class+.slot-boundp object (slot-definition-name slot)) (slot-value object (slot-definition-name slot))))) (prog1 object (when (slot-definition-leaf slot) (typecase value (class+-instance (delete-object server value)) (list (mapcar (lambda (value) (if (typep value 'class+-instance) (delete-object server value))) value)) (t ;; do nothing )))))) (class+.slots (class-of object)) :initial-value object) object) (deftrace object-database '(add-object delete-object update-object find-all-objects find-object-with-slot)) ;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
16,862
Common Lisp
.lisp
357
41.941176
97
0.641532
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
6f578c02e28a90ce8f4caa9c9adbf451e96c559ae95d802c21b99b96eae8a2e7
8,370
[ -1 ]
8,371
serialize.lisp
evrim_core-server/src/database/serialize.lisp
;; ---------------------------------------------------------------------------- ;; Prevalence Isomorphism ;; ---------------------------------------------------------------------------- (in-package :core-server) ;; -------------------------------------------------------------------------- ;; Lisp->XML ;; -------------------------------------------------------------------------- (defmethod xml-serialize ((object t) &optional (k #'xml-serialize)) (declare (ignore k)) (error "Cannot serialize ~A" object)) ;; -------------------------------------------------------------------------- ;; XML->Lisp ;; -------------------------------------------------------------------------- (defmethod xml-deserialize ((xml t) &optional (k #'xml-deserialize)) (declare (ignore k)) (error "Cannot deserialize ~A" xml)) (defxml <db:object-with-id id) ;; ------------------------------------------------------------------------- ;; HTML Elements ;; ------------------------------------------------------------------------- (defmethod xml-deserialize ((xml html-element) &optional (k #'xml-deserialize)) (declare (ignore k)) xml) ;; -------------------------------------------------------------------------- ;; Null ;; -------------------------------------------------------------------------- (defxml <db:null) (defmethod xml-deserialize ((xml <db:null) &optional (k #'xml-deserialize)) (declare (ignore k)) nil) (defmethod xml-serialize ((object null) &optional (k #'xml-serialize)) (declare (ignore k)) (<db:null)) ;; -------------------------------------------------------------------------- ;; True ;; -------------------------------------------------------------------------- (defxml <db:true) (defmethod xml-deserialize ((xml <db:true) &optional (k #'xml-deserialize)) (declare (ignore k)) t) (defmethod xml-serialize ((object (eql 't)) &optional (k #'xml-serialize)) (declare (ignore k)) (<db:true)) ;; ---------------------------------------------------------------------------- ;; Symbol ;; ---------------------------------------------------------------------------- (defxml <db:symbol) (defmethod xml-deserialize ((xml <db:symbol) &optional (k #'xml-deserialize)) (declare (ignore k)) (read-from-string (car (slot-value xml 'children)))) (defmethod xml-serialize ((object symbol) &optional (k #'xml-serialize)) (declare (ignore k)) (<db:symbol (symbol->string object))) ;; ---------------------------------------------------------------------------- ;; Character ;; ---------------------------------------------------------------------------- (defxml <db:character) (defmethod xml-deserialize ((xml <db:character) &optional (k #'xml-deserialize)) (declare (ignore k)) (aref (read-from-string (car (slot-value xml 'children))) 0)) (defmethod xml-serialize ((object character) &optional (k #'xml-serialize)) (declare (ignore k)) (<db:character (format nil "\"~C\"" object))) ;; ---------------------------------------------------------------------------- ;; Integer ;; ---------------------------------------------------------------------------- (defxml <db:integer) (defmethod xml-deserialize ((xml <db:integer) &optional (k #'xml-deserialize)) (declare (ignore k)) (read-from-string (car (slot-value xml 'children)))) (defmethod xml-serialize ((object integer) &optional (k #'xml-serialize)) (declare (ignore k)) (<db:integer (format nil "~D" object))) ;; ---------------------------------------------------------------------------- ;; Ratio ;; ---------------------------------------------------------------------------- (defxml <db:ratio) (defmethod xml-deserialize ((xml <db:ratio) &optional (k #'xml-deserialize)) (declare (ignore k)) (read-from-string (car (slot-value xml 'children)))) (defmethod xml-serialize ((object ratio) &optional (k #'xml-serialize)) (declare (ignore k)) (<db:ratio (format nil "~A" object))) ;; ---------------------------------------------------------------------------- ;; Complex ;; ---------------------------------------------------------------------------- (defxml <db:complex) (defmethod xml-deserialize ((xml <db:complex) &optional (k #'xml-deserialize)) (declare (ignore k)) (read-from-string (car (slot-value xml 'children)))) (defmethod xml-serialize ((object complex) &optional (k #'xml-serialize)) (declare (ignore k)) (<db:complex (format nil "~A" object))) ;; ---------------------------------------------------------------------------- ;; Float ;; ---------------------------------------------------------------------------- (defxml <db:float) (defmethod xml-deserialize ((xml <db:float) &optional (k #'xml-deserialize)) (declare (ignore k)) (read-from-string (car (slot-value xml 'children)))) (defmethod xml-serialize ((object float) &optional (k #'xml-serialize)) (declare (ignore k)) (<db:float (format nil "~A" object))) ;; ---------------------------------------------------------------------------- ;; String ;; ---------------------------------------------------------------------------- (defxml <db:string) (defmethod xml-deserialize ((xml <db:string) &optional (k #'xml-deserialize)) (declare (ignore k)) (read-from-string (car (slot-value xml 'children)))) (defmethod xml-serialize ((object string) &optional (k #'xml-serialize)) (declare (ignore k)) (<db:string (format nil "~S" object))) ;; ---------------------------------------------------------------------------- ;; Vector ;; ---------------------------------------------------------------------------- (defxml <db:vector length id) (defmethod xml-deserialize ((xml <db:vector) &optional (k #'xml-deserialize)) (declare (ignore k)) (with-slots (length) xml (let ((object (read-from-string (car (slot-value xml 'children))))) (assert (= length (length object))) object))) (defmethod xml-serialize ((object vector) &optional (k #'xml-serialize)) (declare (ignore k)) (<db:vector :length (length object) (format nil "~A" object))) ;; ---------------------------------------------------------------------------- ;; Cons ;; ---------------------------------------------------------------------------- (defxml <db:cons consp length id) (defmethod xml-deserialize ((xml <db:cons) &optional (k #'xml-deserialize)) (with-slots (consp length) xml (let ((object (apply (if consp #'cons #'list) (mapcar (rcurry k k) (slot-value xml 'children))))) (if (null consp) (assert (= (parse-integer length) (length object)))) object))) (defmethod xml-serialize ((object list) &optional (k #'xml-serialize)) (if (atom (cdr object)) (<db:cons :consp t (funcall k (car object) k) (funcall k (cdr object) k)) (<db:cons :length (length object) (mapcar (rcurry k k) object)))) ;; ---------------------------------------------------------------------------- ;; Hash Table ;; ---------------------------------------------------------------------------- (defxml <db:hash-table-key) (defmethod xml-deserialize ((xml <db:hash-table-key) &optional (k #'xml-deserialize)) (funcall k (car (slot-value xml 'children)) k)) (defxml <db:hash-table-value) (defmethod xml-deserialize ((xml <db:hash-table-value) &optional (k #'xml-deserialize)) (funcall k (car (slot-value xml 'children)) k)) (defxml <db:hash-table-entry) (defmethod xml-deserialize ((xml <db:hash-table-entry) &optional (k #'xml-deserialize)) (with-slots (children) xml (values (funcall k (car children) k) (funcall k (cadr children) k)))) (defxml <db:hash-table test size id) (defmethod xml-deserialize ((xml <db:hash-table) &optional (k #'xml-deserialize)) (with-slots (test size) xml (let ((table (make-hash-table :test (read-from-string test)))) (reduce (lambda (table entry) (multiple-value-bind (key value) (funcall k entry k) (setf (gethash key table) value) table)) (slot-value xml 'children) :initial-value table)))) (defmethod xml-serialize ((object hash-table) &optional (k #'xml-serialize)) (<db:hash-table :test (symbol->string (hash-table-test object)) :size (hash-table-size object) (let ((result)) (maphash (lambda (key value) (push (<db:hash-table-entry (<db:hash-table-key (funcall k key k)) (<db:hash-table-value (funcall k value k))) result)) object) (nreverse result)))) ;; ---------------------------------------------------------------------------- ;; Object/Structure Slot ;; ---------------------------------------------------------------------------- (defxml <db:slot name) (defmethod xml-deserialize ((xml <db:slot) &optional (k #'xml-deserialize)) (values (read-from-string (slot-value xml 'name)) (funcall k (car (slot-value xml 'children)) k))) ;; ---------------------------------------------------------------------------- ;; Structure Object ;; ---------------------------------------------------------------------------- (defxml <db:struct class id) (defmethod xml-deserialize ((xml <db:struct) &optional (k #'xml-deserialize)) (with-slots (class) xml (let* ((class (read-from-string class))) (reduce (lambda (object slot) (multiple-value-bind (name value) (funcall k slot k) (setf (slot-value object name) value) object)) (slot-value xml 'children) :initial-value (funcall (intern (format nil "MAKE-~A" (symbol-name class)) (symbol-package class))))))) (defmethod xml-serialize ((object structure-object) &optional (k #'xml-serialize)) (<db:struct :class (symbol->string (class-name (class-of object))) (mapcar (lambda (slot) (<db:slot :name (symbol->string slot) (funcall k (slot-value object slot) k))) (slots-of object)))) ;; ---------------------------------------------------------------------------- ;; Class ;; ---------------------------------------------------------------------------- (defxml <db:class id) (defmethod xml-deserialize ((xml <db:class) &optional (k #'xml-deserialize)) (declare (ignore k)) (find-class (read-from-string (car (slot-value xml 'children))))) (defmethod xml-serialize ((object standard-class) &optional (k #'xml-serialize)) (declare (ignore k)) (<db:class (symbol->string (class-name object)))) (defxml <db:dynamic-class class id name) (defmethod xml-deserialize ((xml <db:dynamic-class) &optional (k #'xml-deserialize)) (with-slots (name class children) xml (let* ((supers (mapcar (rcurry k k) (filter (lambda (a) (typep a '<db:class)) children)))) (make-instance (find-class (read-from-string class)) :name (read-from-string name) :direct-superclasses (cons (find-class (read-from-string name)) supers))))) (defmethod xml-serialize ((object dynamic-class+) &optional (k #'xml-serialize)) (<db:dynamic-class :name (symbol->string (class-name object)) :class (symbol->string (class-name (class-of object))) (mapcar (rcurry k (curry #'funcall k)) (filter (lambda (a) (not (typep a 'dynamic-class+))) (class+.direct-superclasses object))))) ;; ---------------------------------------------------------------------------- ;; Standard Object ;; ---------------------------------------------------------------------------- (defxml <db:instance id class) (defmethod xml-find-class ((xml <db:instance) &optional (k #'xml-deserialize)) (with-slots (class children) xml (or (and class (find-class (read-from-string class))) (aif (any (lambda (a) (if (or (typep a '<db:class) (typep a '<db:dynamic-class)) a)) children) (funcall k it k) (error "Class not found ~A" xml))))) (defmethod xml-deserialize ((xml <db:instance) &optional (k #'xml-deserialize)) (with-slots (class children) xml (let* ((class (xml-find-class xml k)) (instance (allocate-instance class))) (initialize-instance (reduce (lambda (instance slot) (multiple-value-bind (name value) (funcall k slot k) (setf (slot-value instance name) value) instance)) (filter (lambda (a) (typep a '<db:slot)) children) :initial-value instance))))) (defmethod xml-serialize ((object standard-object) &optional (k #'xml-serialize)) (<db:instance (funcall k (class-of object) k) (mapcar (lambda (slot) (<db:slot :name (symbol->string slot) (funcall k (slot-value object slot) k))) (slots-of object)))) ;; +------------------------------------------------------------------------- ;; | Pathname ;; +------------------------------------------------------------------------- (defxml <db:pathname id name type) (defmethod xml-deserialize ((xml <db:pathname) &optional (k #'xml-deserialize)) (with-slots (children name type) xml (make-pathname :directory (mapcar (lambda (c) (funcall k c k)) children) :name name :type type))) (defmethod xml-serialize ((object pathname) &optional (k #'xml-serialize)) (<db:pathname :name (pathname-name object) :type (pathname-type object) (mapcar (lambda (directory) (funcall k directory k)) (pathname-directory object)))) ;; TODO: serialize hashtable rehash size -evrim. ;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
13,852
Common Lisp
.lisp
293
44.006826
87
0.517413
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
b2b23e3ae4acb5e38b43713e32481fa17a194ff20db287bb1f67f249f15756c5
8,371
[ -1 ]
8,372
turkiye.lisp
evrim_core-server/src/util/turkiye.lisp
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :core-server) ;;+---------------------------------------------------------------------------- ;;| Utilities for Turkish Locale ;;+---------------------------------------------------------------------------- ;; ;; These utilities are disabled by default. Remove #+nil if you need them. #+nil (progn (defvar +tr-alphabet+ "ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZabcçdefgğhıijklmnoöpqrsştuüvwxyz") (defun tr2en (str) "Convert a turkish string to corresponding ascii string." (nsubstitute #\s #\ş str) (nsubstitute #\S #\Ş str) (nsubstitute #\i #\ı str) (nsubstitute #\I #\İ str) (nsubstitute #\g #\ğ str) (nsubstitute #\G #\Ğ str) (nsubstitute #\c #\ç str) (nsubstitute #\C #\Ç str) (nsubstitute #\u #\ü str) (nsubstitute #\U #\Ü str) (nsubstitute #\o #\ö str) (nsubstitute #\O #\Ö str) str) (defun tr-char-upcase (a) (case a ((#\ı #\i) (aref +tr-alphabet+ (- (position a +tr-alphabet+) 32))) (otherwise (char-upcase a)))) (defun tr-char-downcase (a) (case a ((#\I #\İ) (aref +tr-alphabet+ (+ (position a +tr-alphabet+) 32))) (otherwise (char-downcase a)))) (defun tr-string-upcase (str) (reduce #'(lambda (acc item) (vector-push-extend (tr-char-upcase item) acc) acc) str :initial-value (make-array 0 :fill-pointer 0 :element-type 'character))) (defun tr-string-downcase (str) (reduce #'(lambda (acc item) (vector-push-extend (tr-char-downcase item) acc) acc) str :initial-value (make-array 0 :fill-pointer 0 :element-type 'character))) (defun tr-char< (a b) (if (eq a b) nil (let* ((posa (position a +tr-alphabet+)) (posb (position b +tr-alphabet+))) (if (and posa posb) (> posa posb) (char< a b))))) (defun tr-char> (a b) (if (eq a b) nil (not (tr-char< a b)))) ;; (and ;; (tr-string< "aycan" "AYCAN") ;; (tr-string< "aYcaN" "Aycan") ;; (tr-string< "aycan" "aycaN") ;; (equal (sort (list "ABC" "Abc" "abc" "aBC") #'string<) ;; (tr-sort (list "ABC" "Abc" "abc" "aBC") #'tr-string>))) (defun tr-string< (a b) (let ((len (min (length a) (length b))) (result nil)) (dotimes (i len) (if (tr-char< (aref a i) (aref b i)) (return-from tr-string< t)) (if (tr-char< (aref b i) (aref a i)) (return-from tr-string< nil))) nil)) (defun tr-string> (a b) (not (tr-string< a b))) (defun tr-sort (list test &key (key #'identity)) (sort (copy-list list) (lambda (a b) (funcall test a b)) :key key)) )
3,327
Common Lisp
.lisp
84
35.22619
86
0.605255
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
4dc8e62ece382a6af7465da7bb1863477a9bf3ec86f6a68c952e4cce32b4ddeb
8,372
[ -1 ]
8,373
mop.lisp
evrim_core-server/src/util/mop.lisp
; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :core-server) ;;+---------------------------------------------------------------------------- ;;| Utilities for meta-object-protocol (mop) ;;+---------------------------------------------------------------------------- ;;----------------------------------------------------------------------------- ;; SysV Method Combination ;;----------------------------------------------------------------------------- ;; ;; SysV method combination is used to define a server protocol for several ;; methods like start,stop,status. ;; ;; start and stop methods of an object are runned inside a 'progn' ;; status method is runned inside an 'and' ;; (define-method-combination sysv-standard (&key (type :start)) ((around (:around)) (primary () :required t)) (labels ((specializer (method) (car (sb-mop:method-specializers method))) (specializers (methods) (mapcar #'(lambda (m) (cons (specializer m) m)) methods)) (sort-by-specializers (methods) (mapcar #'cdr (specializers methods))) (status-method (method) (find-method #'status '() (list (specializer method)) nil)) (call-methods (methods) (mapcar #'(lambda (method) (aif (status-method method) (cond ((eq type :start) `(if (not (call-method ,it)) (call-method ,method) t)) ((eq type :stop) `(if (call-method ,it) (call-method ,method) t)) ((eq type :status) `(call-method ,method)) ((or (eq type :register) (eq type :unregister)) `(call-method ,method))) `(call-method ,method))) methods))) (let* ((around (nreverse around)) (primary (sort-by-specializers primary)) (primary (cond ((eq type :start) `(apply #'values (nreverse (list ,@(call-methods (nreverse primary)))))) ((eq type :stop) `(values ,@(call-methods primary))) ((eq type :status) `(and ,@(call-methods (nreverse primary)))) ((eq type :register) `(apply #'values (nreverse (list ,@(call-methods (nreverse primary)))))) ((eq type :unregister) `(values ,@(call-methods primary)))))) (if around `(call-method ,(first around) (,@(rest around) (make-method ,primary))) primary)))) (deftrace sysv '(start stop status)) ;;----------------------------------------------------------------------------- ;; Other MOP Utilities ;;----------------------------------------------------------------------------- (defun class-direct-superclasses (class) "Returns direct superclasses of the 'class'" (let ((class (if (symbolp class) (find-class class) class))) (sb-mop:class-direct-superclasses class))) ;; INSTALL> (class-superclasses 'c) ;; (#<STANDARD-CLASS C> #<STANDARD-CLASS B> #<STANDARD-CLASS A> ;; #<STANDARD-CLASS COMMAND>) (defun class-superclasses (class &aux lst) "Returns all superclasses of the given 'class'" (let ((class (if (symbolp class) (find-class class) class))) (core-search (list class) (lambda (atom) (pushnew atom lst) nil) #'class-direct-superclasses #'append) (nreverse lst))) (defun class-direct-subclasses (class) (let ((class (if (symbolp class) (find-class class) class))) (sb-mop::class-direct-subclasses class))) (defun class-subclasses (class &aux lst) (let ((class (if (symbolp class) (find-class class) class))) (core-search (list class) (lambda (class) (pushnew class lst) nil) #'class-direct-subclasses #'append) (cdr (nreverse lst)))) ;; INSTALL> (class-default-initargs 'c) ;; ((:ARG-B 'ARG-B-OVERRIDEN-BY-C #<FUNCTION {BC06125}>) ;; (:ARG-A 'ARG-A-OVERRIDEN-BY-C #<FUNCTION {BC06195}>)) (defun class-default-initargs (class &aux lst) "Returns default-initargs of the given 'class'" (let ((class (if (symbolp class) (find-class class) class))) (core-search (list class) #'(lambda (atom) (let ((args (copy-list (sb-mop:class-direct-default-initargs atom)))) (when args (setf lst (append args lst)))) nil) #'class-direct-superclasses #'append)) (uniq (nreverse lst) :key #'car) ;; (mapcar (lambda (a) (cons (car a) (cons (eval (cadr a)) (cddr a)))) ;; (uniq (nreverse lst) :key #'car)) ) (defun class-default-initarg-values (class) (mapcar (lambda (a) (cons (car a) (cons (eval (cadr a)) (cddr a)))) (class-default-initargs class))) (defmethod slots-of ((object standard-object)) #+openmcl (mapcar #'ccl:slot-definition-name (#-openmcl-native-threads ccl:class-instance-slots #+openmcl-native-threads ccl:class-slots (class-of object))) #+cmu (mapcar #'pcl:slot-definition-name (pcl:class-slots (class-of object))) #+sbcl (mapcar #'sb-pcl:slot-definition-name (sb-pcl:class-slots (class-of object))) #+lispworks (mapcar #'hcl:slot-definition-name (hcl:class-slots (class-of object))) #+allegro (mapcar #'mop:slot-definition-name (mop:class-slots (class-of object))) #+sbcl (mapcar #'sb-mop:slot-definition-name (sb-mop:class-slots (class-of object))) #-(or openmcl cmu lispworks allegro sbcl) (error "not yet implemented")) (defmethod slots-of ((object structure-object)) #+openmcl (let* ((sd (gethash (class-name (class-of object)) ccl::%defstructs%)) (slots (if sd (ccl::sd-slots sd)))) (mapcar #'car (if (symbolp (caar slots)) slots (cdr slots)))) #+cmu (mapcar #'pcl:slot-definition-name (pcl:class-slots (class-of object))) #+sbcl (mapcar #'sb-pcl:slot-definition-name (sb-pcl:class-slots (class-of object))) #+lispworks (structure:structure-class-slot-names (class-of object)) #+allegro (mapcar #'mop:slot-definition-name (mop:class-slots (class-of object))) #+sbcl (mapcar #'sb-mop:slot-definition-name (sb-mop:class-slots (class-of object))) #-(or openmcl cmu lispworks allegro sbcl) (error "not yet implemented")) (defmacro redefmethod (name args &body body) "Macro that makes method unbound before defining it." `(progn (fmakunbound ',name) (defmethod ,name ,args ,@body))) (defun copy-slots (source target slots) (reduce (lambda (target slot) (prog1 target (setf (slot-value target slot) (slot-value source slot)))) slots :initial-value target))
6,955
Common Lisp
.lisp
168
37.297619
81
0.624908
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
47c267bfdafc68cae5a145fba6b9d0d66cab79259525e710a2dd48aca3104a79
8,373
[ -1 ]
8,374
helper.lisp
evrim_core-server/src/util/helper.lisp
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :tr.gen.core.server) ;;+---------------------------------------------------------------------------- ;;| Utility functions, macros, etc. ;;+---------------------------------------------------------------------------- (eval-when (:compile-toplevel :load-toplevel :execute) (defmacro aif (consequent then &optional else) "Special if that binds 'consequent' to 'it'" `(let ((it ,consequent)) (if it ,then ,(if else else)))) (defmacro awhen (consequent &body body) "Special when that binds 'consequent' to 'it'" `(let ((it ,consequent)) (when it ,@body))) (defmethod make-keyword ((str string)) "Returns keyword for the string 'str'" (intern (string-upcase str) :keyword)) (defmethod make-keyword ((sym symbol)) "Returns keyword for the symbol 'sym'" (intern (symbol-name sym) :keyword)) (defun symbol->string (symbol) "Returns the string representation of the 'symbol'" (let* ((package (symbol-package symbol))) (if package (format nil "~A::~A" (package-name package) (symbol-name symbol)) (symbol-name symbol)))) (defun js->keyword (string) (make-keyword (reduce (lambda (acc atom) (cond ((typep atom 'upper-case?) (push-atom #\- acc) (push-atom atom acc)) ((eq #\- atom) (push-atom #\- acc) (push-atom #\- acc)) (t (push-atom atom acc))) acc) string :initial-value (make-accumulator)))) (defun reduce0 (lambda list) (reduce lambda list :initial-value nil)) (defun filter (lambda list) (nreverse (reduce0 (lambda (acc atom) (if (funcall lambda atom) (cons atom acc) acc)) list)))) (defmacro deftrace (name methods) "Defines +name-methods+ variable, trace-name, untrace-name functions for traceing a closed system" (let ((var-symbol (intern (string-upcase (format nil "+~A-methods+" name)))) (trace-symbol (intern (string-upcase (format nil "trace-~A" name)))) (untrace-symbol (intern (string-upcase (format nil "untrace-~A" name))))) `(progn (defparameter ,var-symbol ,methods) (defun ,trace-symbol (&optional (methods ,var-symbol)) (mapcar (lambda (e) (eval `(trace ,e))) methods)) (defun ,untrace-symbol (&optional (methods ,var-symbol)) (mapcar (lambda (e) (eval `(untrace ,e))) methods))))) ;; FIXME: he who wrote this below should be doomed! -evrim. (defun uniq (lst &key (test #'eq) (key #'identity)) (nreverse (reduce0 (lambda (acc atom) (pushnew atom acc :key key :test test) acc) (copy-list lst)))) (defun prepend (&rest lists) "Prepends lists to a single list" (cond ((eq 0 (length lists)) nil) ((eq 1 (length lists)) (car lists)) (t (let ((rev (reverse lists))) (apply #'append (cons (car rev) (prepend (cdr rev)))))))) (defun flatten (lst &optional (acc nil)) "Flatten a list tree into a plain list" (cond ((null lst) acc) ((atom lst) (cons lst acc)) ((listp lst) (flatten (car lst) (flatten (cdr lst) acc))))) (defun flatten1 (lst) (if (atom lst) (list lst) (reduce0 #'append lst))) (defun any (lambda list) "Returns any non-null result when lambda is applied to the any element of list" (reduce #'(lambda (acc atom) (aif (funcall lambda atom) (return-from any it) acc)) list :initial-value nil)) (defun make-type-matcher (type-name) (lambda (a) (and (typep a type-name) a))) (defun all (lambda &rest lists) "Return t if all elements of lists satisfies lambda" (apply #'mapc (lambda (&rest atoms) (if (not (apply lambda atoms)) (return-from all nil))) lists) t) (defun plist-to-alist (plist) "Transforms a plist to an alist, keywords are transformed into symbols" (let (key) (nreverse (reduce #'(lambda (acc atom) (if (and (null key) (keywordp atom)) (prog1 acc (setf key atom)) (prog1 (cons (cons (intern (symbol-name key)) atom) acc) (setf key nil)))) plist :initial-value nil)))) (defun alist-to-plist (alist) "Transforms an alist to a plist, key symbols are transformed into keywords" (reduce #'(lambda (acc atom) (nreverse (cons (cdr atom) (cons (make-keyword (car atom)) (nreverse acc))))) alist :initial-value nil)) (defmacro s-v (slot-name) "Expands to (slot-value self slot-name)" `(slot-value self ,slot-name)) (defmacro seq (how-many) "(seq how-many) => (0 1 2 .. how-many-1)" `(let ((result)) (dotimes (n ,how-many (nreverse result)) (push n result)))) (defun drop (n lst) "Drop n element from the head of lst and return rest" (let ((l (length lst))) (subseq lst (min l n)))) (defun take (n lst) "Take n elements from the head of lst and return" (let ((l (length lst))) (subseq lst 0 (min l n)))) (defun remove-if-member (members target &key (key #'identity) (test #'eq)) (nreverse (reduce (lambda (acc atom) (if (member (funcall key atom) members :test test) acc (cons atom acc))) target :initial-value nil))) (defmacro with-package (package &body body) "Executes body while setting current package to 'package'" `(let ((*package* (find-package ,package))) ,@body)) (defmacro with-current-directory (directory &body body) "Executes body while setting current directory to 'directory'" `(unwind-protect (progn (sb-posix:chdir ,directory) (let ((*default-pathname-defaults* ,directory)) ,@body)) (sb-posix:chdir *default-pathname-defaults*))) (defmacro make-project-path (system path) "Generates asdf-system relative directory pathname to the project source directory" `(merge-pathnames (make-pathname :directory '(:relative ,path)) (asdf:component-pathname (asdf:find-system ,system)))) (defparameter +day-names+ '((:tr "Pazartesi" "Salı" "Çarşamba" "Perşembe" "Cuma" "Cumartesi" "Pazar") (:en "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday")) "Day names in different languages in UTF-8") (defparameter +month-names+ '((:tr "Ocak" "Şubat" "Mart" "Nisan" "Mayıs" "Haziran" "Temmuz" "Ağustos" "Eylül" "Ekim" "Kasım" "Aralık") (:en "January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November" "December")) "Month names in different languages in UTF-8") (defun time->string (time &optional mode (lang :tr)) "Converts a timestamp to a human readable string. There are few modes: i) :date - 06. June, 2008 - Friday ii) :short - 06/06 17:30 iii):long - 06 June 2008 Friday, 17:30:38 iv) t - 06/06/2008 17:30" (multiple-value-bind (second minute hour day month year day-of-week dst-p tz) (decode-universal-time time) (declare (ignore tz dst-p)) (case mode (:date (format nil "~2,'0d. ~a, ~d - ~a" day (nth (decf month) (rest (assoc lang +month-names+))) year (nth day-of-week (rest (assoc lang +day-names+))))) (:short (format nil "~2,'0d/~2,'0d ~2,'0d:~2,'0d" month day hour minute)) (:long (format nil "~2,'0d ~a ~d ~a, ~2,'0d:~2,'0d:~2,'0d" day (nth (decf month) (rest (assoc lang +month-names+))) year (nth day-of-week (rest (assoc lang +day-names+))) hour minute second)) (:tag (format nil "~d-~2,'0d-~2,'0d-~2,'0d-~2,'0d-~2,'0d" year month day hour minute second)) (:log (format nil "~d/~2,'0d/~2,'0d ~2,'0d:~2,'0d:~2,'0d" year month day hour minute second)) (t (format nil "~2,'0d/~2,'0d/~d ~2,'0d:~2,'0d" day month year hour minute))))) (defun time->ymd (time) "Converts a timestamp to a human readable string, ie: '2005-06-21' (Year/month/Day)" (multiple-value-bind (second minute hour day month year day-of-week dst-p tz) (decode-universal-time time) (declare (ignore tz dst-p)) (format nil "~d-~2,'0d-~2,'0d" year month day))) (defun time->dmy (time) "Converts a timestamp to a human readable string, ie: '31-12-2005' (Day/month/Year)" (multiple-value-bind (second minute hour day month year day-of-week dst-p tz) (decode-universal-time time) (declare (ignore tz dst-p)) (format nil "~2,'0d-~2,'0d-~d" day month year))) (defun time->hm (time) "Converts a timestamp to a human readable string, ie: '13:55' (Hour:minute)" (multiple-value-bind (second minute hour day month year day-of-week dst-p tz) (decode-universal-time time) (declare (ignore tz dst-p)) (format nil "~2,'0d:~2,'0d" hour minute))) (defun hm->time (hm-str) "Returns a timestamp for the specified string in 'Hour:minute'" (cond ((null hm-str) nil) (t (let ((val (cl-ppcre:split #\: hm-str))) (apply #'encode-universal-time (append (cons 0 (reverse (loop for i from 0 upto 1 collect (parse-integer (nth i val) :junk-allowed t)))) (list 1 1 0))))))) (defun seconds->hours (seconds) "Given seconds, returns hours as string, DD/hh/mm" (let* ((second-minute 60) (second-hour (* second-minute 60)) (second-day (* second-hour 24)) (second-month (* second-day 30.4368499)) (second-year (* second-month 12)) (year (truncate seconds second-year)) (month (truncate (decf seconds (* year second-year)) second-month)) (day (truncate (decf seconds (* month second-month)) second-day)) (hour (truncate (decf seconds (* day second-day)) second-hour)) (minute (truncate (decf seconds (* hour second-hour)) second-minute)) (second (truncate (decf seconds (* minute second-minute)) 1))) (declare (ignorable second-minute) (ignorable second)) (format nil "~D:~D:~D" day hour minute))) (defun ymd->time (ymd) "Given YY-mm-dd, return corresponding timestamp" (cond ((null ymd) nil) (t (apply #'encode-universal-time (append (list 0 0 0) (mapcar #'(lambda (i) (parse-integer i :junk-allowed t)) (reverse (cl-ppcre:split #\- ymd)))))))) (defun combine-date-time (date time) "Combines two timestamps given, taking date values from 'date', time values from 'time'" (multiple-value-bind (s1 min1 h1 d1 m1 y1 day-of-week-1 dst1 tz1) (decode-universal-time date) (multiple-value-bind (s2 min2 h2 d2 m2 y2 day-of-week-2 dst2 tz2) (decode-universal-time time) (encode-universal-time s2 min2 h2 d1 m1 y1)))) (defun today+ (seconds) "Returns today 00:00:00 plus 'seconds'" (multiple-value-bind (second minute hour day month year day-of-week dst-p tz) (decode-universal-time (get-universal-time)) (declare (ignore second minute hour day-of-week dst-p)) (+ seconds (encode-universal-time 0 0 0 day month year tz)))) ;; http://lisptips.com/post/11649360174/the-common-lisp-and-unix-epochs (defvar +unix-epoch-difference+ (encode-universal-time 0 0 0 1 1 1970 0)) (defun universal-to-unix-time (universal-time) (- universal-time +unix-epoch-difference+)) (defun unix-to-universal-time (unix-time) (+ unix-time +unix-epoch-difference+)) (defun get-unix-time (&optional (universal-time (get-universal-time))) (universal-to-unix-time universal-time)) (defun concat (&rest args) (reduce0 (curry #'concatenate 'string) args)) (defun string-replace-all (old new big) "Replace all occurences of OLD string with NEW string in BIG string." (do ((newlen (length new)) (oldlen (length old)) (i (search old big) (search old big :start2 (+ i newlen)))) ((null i) big) (setq big (concatenate 'string (subseq big 0 i) new (subseq big (+ i oldlen)))))) ;; TODO: move below to where they belong. -evrim. (defun escape-parenscript (string) (core-server::return-stream (let ((input (make-core-stream string)) (output (make-core-stream ""))) (do ((peek (read-stream input) (read-stream input))) ((null peek) output) (cond ((> peek 127) (core-server::byte! output peek)) ((not (alpha-char-p (code-char peek))) (progn (core-server::char! output #\%) (core-server::hex-value! output peek))) (t (core-server::byte! output peek))))))) (defun javascript-date-to-lisp (universal-time) (let ((b 3155666400) (a 946677600000)) (+ b (/ (- universal-time a) 1000)))) ;; DNS aids (defun host-part (fqdn) (awhen (position #\. fqdn) (subseq fqdn 0 it))) (defun domain-part (fqdn) (awhen (position #\. fqdn) (subseq fqdn (+ 1 it)))) (defun fix-apache-permissions (pathname) (sb-ext:run-program +sudo+ (cons (namestring +chown+) (list (format nil "~A:~A" +apache-user+ +apache-group+) (namestring pathname)))) (sb-ext:run-program +sudo+ (cons (namestring +chmod+) (list "660" (namestring pathname))))) (defun show-license-warranty (&optional (stream t)) (format stream "THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.")) (defun show-license-conditions (&optional (stream t)) (format stream "Please see $CORESERVER_HOME/LICENSE document.")) (defun show-license-to-repl (&optional (stream t)) (format stream "Core Server Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN This program comes with ABSOLUTELY NO WARRANTY; for details type `(show-license-warranty)'. This is free software, and you are welcome to redistribute it under certain conditions; type `(show-license-conditions)' for details.~%~%")) ;;;; needs gc ;;;; ;; (defun make-rusg () ;; (let ((table (make-hash-table :test #'equal)) ;; (lock (make-lock))) ;; (lambda (len) ;; (labels ((genstring (len) ;; (with-recursive-lock-held (lock) ;; (let ((ns (random-string len))) ;; (if (gethash ns table) ;; (progn ;; (format t "non-unique found, recursing: ~A" ns) ;; (genstring len)) ;; (progn ;; (setf (gethash ns table) t) ;; ns)))))) ;; (genstring len))))) ;; generates len size random, appends unique sym (defun make-unique-random-string (len) (let ((sym (gensym (random-string len)))) (symbol-name sym))) ;; simple wrapper for openid signatures ;; a longer string probably need a core-hmac-stream -evrim. (defun hmac (key str &optional (algo :sha256) (encoding :utf-8)) (let* ((key (typecase key (string (string-to-octets key :us-ascii)) (t key))) (hash (crypto:make-hmac (make-array (length key) :element-type '(unsigned-byte 8) :initial-contents key) algo))) (crypto::update-hmac hash (string-to-octets str encoding)) (let ((digest (crypto:hmac-digest hash))) (values (crypto:byte-array-to-hex-string digest) digest)))) (defun md5 (str &optional (encoding :utf-8)) (let ((hash (crypto:make-digest :md5))) (crypto::update-digest hash (string-to-octets str encoding)) (crypto:byte-array-to-hex-string (crypto:produce-digest hash))))
15,900
Common Lisp
.lisp
374
38.302139
98
0.659097
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
3ac9bf5152eaa824577fd8e59c36a9700d11d3c093eacbff5c628bed41e16db3
8,374
[ -1 ]
8,375
persistent.lisp
evrim_core-server/src/servers/persistent.lisp
(in-package :core-server) ;; ------------------------------------------------------------------------- ;; Persistent Server ;; ------------------------------------------------------------------------- (defclass+ persistent-server (database-server) ()) ;; -------------------------------------------------------------------------- ;; Overriden get-directory method: This allows us to use default ;; database directory for database driven http server. ;; -------------------------------------------------------------------------- (defmethod database.directory ((server persistent-server)) (ensure-directories-exist (merge-pathnames (make-pathname :directory (list :relative "var" (format nil "core-server-~A:~A" (socket-server.host server) (socket-server.port server)) "db")) (bootstrap::home)))) (deftransaction persistent-server.register ((self persistent-server) (application web-application)) (setf (database.get self :applications) (cons application (persistent-server.unregister self application)))) (deftransaction persistent-server.unregister ((self persistent-server) (application web-application)) (setf (database.get self :applications) (remove (web-application.fqdn application) (database.get self :applications)))) (defmethod persistent-server.persistent-p ((self persistent-server) (app persistent-application)) (member app (database.get self :applications))) (defmethod register ((self persistent-server) (app persistent-application)) (when (not (persistent-server.persistent-p self app)) (persistent-server.register self app))) (defmethod unregister ((self persistent-server) (app persistent-application)) (when (persistent-server.persistent-p self app) (stop app) (persistent-server.unregister self app))) (defmethod start ((self persistent-server)) (mapcar (lambda (application) (start application) (register self application)) (database.get self :applications))) (defmethod stop ((self persistent-server)) ;; (mapcar (lambda (application) (unregister self application)) ;; (database.get self :applications)) ) ;; (defclass+ sample-persistent-application (http-application) ;; () ;; (:metaclass persistent-http-application+)) ;; (defparameter *persistent-application* ;; (make-instance 'sample-persistent-application ;; :fqdn "persistent-application" ;; :admin-email "[email protected]" ;; :persistent t))
2,466
Common Lisp
.lisp
53
43.150943
80
0.646545
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
394b7dfdd2afa393cf9f9e9f33a6b0c8cf4d0459268ce0a26b57c057487b7bec
8,375
[ -1 ]
8,376
http.lisp
evrim_core-server/src/servers/http.lisp
(in-package :core-server) ;; +------------------------------------------------------------------------- ;; | HTTP Server ;; +------------------------------------------------------------------------- (defclass+ http-server (web-server socket-server logger-server) ((applications :accessor server.applications :initform '()) (root-application :accessor server.root-application :initform nil)) (:default-initargs :port 3001 :peer-class '(http-unit))) ;;-------------------------------------------------------------------------- ;; Server Protocol Implementation ;;-------------------------------------------------------------------------- (defmethod find-application ((self http-server) fqdn) (find fqdn (server.applications self) :key #'web-application.fqdn :test #'equal)) (defmethod register ((self http-server) (app http-application)) (setf (server.applications self) (sort (cons app (remove (web-application.fqdn app) (server.applications self) :test #'equal :key #'web-application.fqdn)) #'> :key (lambda (app) (length (web-application.fqdn app))))) (setf (application.server app) self)) (defmethod unregister ((self http-server) (app http-application)) (setf (server.applications self) (remove (web-application.fqdn app) (server.applications self) :test #'equal :key #'web-application.fqdn))) (defmethod register ((self http-server) (app root-web-application-mixin)) (setf (slot-value self 'root-application) app)) (defmethod unregister ((self http-server) (app root-web-application-mixin)) (setf (slot-value self 'root-application) nil)) ;; ------------------------------------------------------------------------- ;; Parse Request ;; ------------------------------------------------------------------------- (defvar +default-encoding+ :utf-8 "NOTE: Browser should supply this but does not") (defmethod parse-request ((server http-server) (stream core-stream)) "Returns a fresh RFC 2616 HTTP Request object parsing from 'stream', nil if stream data is invalid" (multiple-value-bind (peer-type method uri version general-headers request-headers entity-headers unknown-headers) (http-request-headers? stream) (when (null method) (log-me server 'error (format nil "Request with null method ~A" uri)) (return-from parse-request nil)) (let ((request (make-http-request :stream stream :method method :uri uri :version version :general-headers general-headers :entity-headers entity-headers :unknown-headers unknown-headers :headers request-headers))) (let* ((content-type (http-request.content-type request)) (content-length (http-request.content-length request)) (stream (if (and content-length (> content-length 0)) (progn (lwsp? stream) (make-bounded-stream stream content-length)) stream))) (flet ((process-multipart () ;; content-type = '("multipart" "form-data") (let* ((boundary (cdr (assoc "boundary" (caddr content-type) :test #'string=))) (entities (rfc2388-mimes? stream boundary))) (setf (http-message.entities request) entities) (flet ((process-media (acc media) (cond ((mime.filename media) (cons (cons (mime.name media) media) acc)) ((mime.name media) (cons (cons (mime.name media) (octets-to-string (mime.data media) +default-encoding+)) acc)) (t (let ((message (format nil "Unkown media received, uri:~A, media:~A" uri media))) (log-me server 'warn message) acc))))) (let ((media (reduce0 #'process-media (filter (lambda (a) (typep a 'top-level-media)) entities)))) (setf (uri.queries uri) (append (uri.queries uri) media)))))) (process-json () (let ((hash-table (json? stream))) (if (typep hash-table 'hash-table) (let ((data (hash-to-alist hash-table))) (setf (uri.queries uri) (append (uri.queries uri) data)))))) (process-urlencoded () (let ((data (x-www-form-urlencoded? stream))) (setf (uri.queries uri) (append (uri.queries uri) data))))) (cond ;; content-type = '("multipart" "form-data") ((and (string-equal "multipart" (car content-type)) (string-equal "form-data" (cadr content-type)) (> content-length 0)) (process-multipart)) ;; content-type = '("application" "json") ((and (string-equal "text" (car content-type)) (string-equal "json" (cadr content-type))) (process-json)) ;; content-type = '("application" "x-www-form-urlencoded") ((and (string-equal "application" (car content-type)) (string-equal "x-www-form-urlencoded" (cadr content-type)) (> content-length 0)) (process-urlencoded))))) request))) ;; ------------------------------------------------------------------------- ;; Eval Request & Return Response ;; ------------------------------------------------------------------------- (defmethod eval-request ((server http-server) (request http-request)) (let* ((root-application (slot-value server 'root-application)) (host (car (http-request.header request 'host))) (app-name (caar (uri.paths (http-request.uri request)))) (application (if (and root-application host (equal (web-application.fqdn root-application) host)) (acond ((and app-name (not (equal app-name "")) (find-application server app-name)) (setf (http-request.relative-p request) t) (pop (uri.paths (http-request.uri request))) it) (t root-application)) (acond ((and host (find-application server host)) it) (t nil))))) (let ((response (if application (dispatch application request)))) (if response response (let ((m (format nil "request uri: ~A" (http-request.uri request)))) (log-me server 'eval-request m) (make-404-response)))))) ;; ------------------------------------------------------------------------- ;; Make Response ;; ------------------------------------------------------------------------- (defun make-response (&optional (stream (make-core-list-output-stream))) "Returns an empty HTTP Response object" (let ((response (make-http-response :stream stream))) (setf (http-message.general-headers response) (list (cons 'date (get-universal-time)) ;; (list 'pragma 'no-cache) (cons 'connection 'keep-alive)) (http-response.entity-headers response) (list (cons 'content-type (list "text" "html" (list "charset" "UTF-8")))) (http-response.response-headers response) (list (cons 'server "Core-serveR - www.core.gen.tr"))) response)) (defun make-404-response (&optional (stream (make-core-list-output-stream))) (let ((response (make-response stream))) (setf (http-response.status-code response) (make-status-code 404)) (with-html-output stream (<:html (<:body (<:h1 "URL Not found") (<:h2 "[Core-serveR]")))) response)) (defun make-401-response (&optional (stream (make-core-list-output-stream))) (let ((response (make-response stream))) (setf (http-response.status-code response) (make-status-code 401)) (with-html-output stream (<:html (<:body (<:h1 "Unauthorized.") (<:h2 "[Core-serveR]")))) response)) (defun make-403-response (&optional (stream (make-core-list-output-stream))) (let ((response (make-response stream))) (setf (http-response.status-code response) (make-status-code 403)) (with-html-output stream (<:html (<:body (<:h1 "Forbidden.") (<:h2 "[Core-serveR]")))) response)) (defun make-error-response (&optional (stream (make-core-list-output-stream))) (let ((response (make-response stream))) (setf (http-response.status-code response) (make-status-code 500)) (with-html-output stream (<:html (<:body (<:h1 "Sorry, an error occured ") (<:h2 "[Core-serveR]")))) response)) (defmethod render-response ((self http-server) (response http-response) (request http-request)) "Renders HTTP 'response' to 'stream'" (let ((stream (http-request.stream request)) (entities (http-response.entities response)) (compressed-p (and (member "gzip" (http-request.header request 'accept-encoding) :key #'car :test #'string=) t))) (assert (eq 0 (current-checkpoint stream))) (labels ((write-headers () (let ((stream (make-core-stream (slot-value stream '%stream)))) (checkpoint-stream stream) (http-response-headers! stream response) (char! stream #\Newline) (commit-stream stream))) (get-content () (let ((content-type (http-response.get-content-type response))) (if (and (cdr content-type) (string= "javascript" (cadr content-type))) (let* ((stream (make-core-stream (make-accumulator :byte))) (stream2 (if (server.debug self) (make-indented-stream stream) (make-compressed-stream stream)))) (serialize-to (http-response.stream response) stream2) (return-stream stream2)) (let ((stream (make-core-stream (make-accumulator :byte)))) (serialize-to (http-response.stream response) stream) (return-stream stream))))) (do-finish-compression (stream) (let ((content-length (length (slot-value stream '%write-buffer)))) (http-response.add-entity-header response 'content-length content-length) (write-headers) (commit-stream stream))) (compression-callback (stream) (lambda (buffer end) (write-stream stream (subseq buffer 0 end))))) (cond ((and compressed-p (pathnamep (car entities))) (let ((path (car entities)) (callback (compression-callback stream))) (with-input-from-file (input path :element-type '(unsigned-byte 8)) (http-response.set-content-type response (split "/" (mime-type path))) (http-response.add-entity-header response 'content-encoding 'gzip) (checkpoint-stream stream) (let ((seq (make-array 4096 :element-type '(unsigned-byte 8)))) (with-compressor (compressor 'gzip-compressor :callback callback) (do ((len (read-sequence seq input) (read-sequence seq input))) ((<= len 0) nil) (compress-octet-vector seq compressor :end len :start 0))) (do-finish-compression stream))))) ((pathnamep (car entities)) (let ((path (car entities))) (with-open-file (input path :element-type '(unsigned-byte 8) :direction :input) (http-response.add-entity-header response 'content-length (file-length input)) (http-response.set-content-type response (split "/" (mime-type path))) (write-headers) (let ((seq (make-array 4096 :element-type '(unsigned-byte 8)))) (do ((len (read-sequence seq input) (read-sequence seq input))) ((<= len 0) nil) (write-stream stream (subseq seq 0 len))))))) (compressed-p (http-response.add-entity-header response 'content-encoding 'gzip) (checkpoint-stream stream) (let ((content (get-content))) (with-compressor (compressor 'gzip-compressor :callback (compression-callback stream)) (compress-octet-vector (make-array (length content) :initial-contents content :element-type '(unsigned-byte 8)) compressor)) (do-finish-compression stream))) (t (let ((data (get-content))) (http-response.add-entity-header response 'content-length (length data)) (write-headers) (write-stream stream data)))) (close-stream stream)))) (defmethod render-error ((self http-server) (stream core-stream) error) (render-response self (make-error-response) (make-http-request :stream stream))) ;; +------------------------------------------------------------------------- ;; | HTTP Unit ;; +------------------------------------------------------------------------- (defclass http-unit (stream-peer) () (:default-initargs :name "Http Peer Handling Unit") (:documentation "HTTP Peer - This peer handles HTTP requests and evaulates to a HTTP response. Its' server is an instance of http-server")) (defmethod/unit handle-stream :async-no-return ((peer http-unit) (stream core-stream) address) (flet ((handle-error (condition) (if (typep condition 'sb-int::simple-stream-error) (return-from handle-stream nil)) (flet ((ignore-error (unit) (declare (ignore unit)) (log-me (peer.server peer) 'error (format nil "~A" condition)) (render-error (peer.server peer) stream condition) (close-stream stream)) (retry-error (unit) (do ((i (current-checkpoint stream) (current-checkpoint stream))) ((< (the fixnum i) 0) nil) (rewind-stream stream)) (handle-stream unit stream address))) (debug-condition (aif (slot-value peer '%debug-unit) it peer) condition (lambda () (send-message peer #'ignore-error)) (lambda () (send-message peer #'retry-error))) (return-from handle-stream nil)))) (handler-bind ((error #'handle-error)) (checkpoint-stream stream) (let ((request (parse-request (peer.server peer) stream))) (if request (let ((response (eval-request (peer.server peer) request))) (cond (response (render-response (peer.server peer) response request) (close-stream (http-response.stream response))) (t (close-stream stream)))) (progn (let* ((buffer (slot-value stream '%read-buffer)) (string (octets-to-string buffer :utf-8))) (format *standard-output* "Bogus request of length: ~A~%" (length buffer)) (format *standard-output* "~A~%" string)) (render-error (peer.server peer) stream nil) (close-stream stream))))))) (deftrace http-server '(handle-stream dispatch parse-request eval-request make-response render-response eval-request parse-request)) ;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. ;; ------------------------------------------------------------------------- ;; Garbage ;; ------------------------------------------------------------------------- ;; (defclass http-cps-unit (local-unit peer) ;; ((%max-events :initarg :max-events :initform 100) ;; (%timeout :initarg :timeout :initform 10) ;; (%continuations :initform (make-hash-table)) ;; (%epoll-fd :initform nil) ;; (%epoll-size :initarg :epoll-size :initform 131072) ;; (%stream :initform (make-instance 'core-cps-stream :stack (list))) ;; (%receive-messages :initform t))) ;; (defmethod start ((self http-cps-unit)) ;; (setf (s-v '%epoll-fd) (core-ffi::epoll-create (s-v '%epoll-size)))) ;; (defmethod start ((self http-server)) ;; ;; ;; (thread-kill (s-v '%socket-thread)) ;; ;; ;; (setf (s-v '%socket-thread) nil) ;; ;; (let ((listenfd (socket-file-descriptor (s-v '%socket)))) ;; ;; (core-ffi::set-nonblock listenfd) ;; ;; (handle-accept (car (s-v '%peers)) listenfd (s-v '%peers))) ;; ) ;; (defmethod/unit add-fd ((self http-cps-unit) fd modes k) ;; (setf (gethash fd (s-v '%continuations)) k) ;; (with-foreign-object (event 'core-ffi::epoll-event) ;; (core-ffi::bzero event core-ffi::size-of-epoll-event) ;; (with-foreign-slots ((core-ffi::events core-ffi::data) event core-ffi::epoll-event) ;; (setf core-ffi::events (apply #'logior (ensure-list modes)) ;; (foreign-slot-value ;; (foreign-slot-value event 'core-ffi::epoll-event 'core-ffi::data) ;; 'core-ffi::epoll-data 'core-ffi::fd) fd)) ;; (core-ffi::epoll-ctl (s-v '%epoll-fd) core-ffi::epoll-ctl-add fd event))) ;; (defmethod/unit del-fd ((self http-cps-unit) fd) ;; (core-ffi::epoll-ctl (s-v '%epoll-fd) core-ffi::epoll-ctl-del fd (null-pointer))) ;; (defmethod receive-messages ((self http-cps-unit)) ;; (let ((thread (or (s-v '%thread) (current-thread)))) ;; (let* ((mbox (thread-mailbox thread)) ;; (lock (mailbox.lock mbox))) ;; (with-lock-held (lock) ;; (loop ;; (let ((q (mailbox.queue mbox))) ;; (setf (mailbox.queue mbox) '()) ;; (return q))))))) ;; (defmethod receive-events ((self http-cps-unit)) ;; (when (s-v '%epoll-fd) ;; (with-foreign-object (events 'core-ffi::epoll-event (s-v '%max-events)) ;; (core-ffi::bzero events (* (s-v '%max-events) core-ffi::size-of-epoll-event)) ;; (labels ((collect (i &optional (acc nil)) ;; (if (< i 0) ;; acc ;; (collect (1- i) (cons ;; (foreign-slot-value ;; (foreign-slot-value ;; (mem-ref events 'core-ffi::epoll-event (1- i)) ;; 'core-ffi::epoll-event 'core-ffi::data) ;; 'core-ffi::epoll-data 'core-ffi::fd) acc))))) ;; (let ((n (core-ffi::epoll-wait (s-v '%epoll-fd) events (s-v '%max-events) ;; (if (s-v '%receive-messages) ;; (s-v '%timeout) ;; -1)))) ;; (if (> n 0) ;; (collect n) ;; nil)))))) ;; (defmethod run ((self http-cps-unit)) ;; (handler-bind ((error (lambda (condition) ;; (let ((swank::*sldb-quit-restart* 'ignore-error)) ;; (restart-case (swank:swank-debugger-hook condition nil) ;; (ignore-error () ;; :report "Ignore the error and return (values)") ;; (retry () ;; :report "Retry the funcall")))))) ;; (flet ((process-message (message) ;; (cond ;; ((eq message 'shutdown) (return-from run nil)) ;; ((functionp message) (funcall message self)) ;; (t (format *standard-output* "Uniw ~A got unkown message:~A~%" self message)))) ;; (process-event (fd) ;; (let ((k (gethash fd (s-v '%continuations)))) ;; (when k ;; (remhash k (s-v '%continuations)) ;; (let ((+stream+ (s-v '%stream))) ;; (setf (slot-value +stream+ '%stack) (list k)) ;; (run +stream+)))))) ;; (loop ;; (progn ;; (if (s-v '%receive-messages) (mapc #'process-message (receive-messages self))) ;; (mapc #'process-event (receive-events self))))))) ;; (defmethod/cc1 handle-stream4 ((peer http-cps-unit) (stream core-fd-nio-stream) address) ;; ;; (describe (current-checkpoint stream)) ;; ;; (checkpoint-stream stream) ;; (let ((time (get-universal-time))) ;; ;; (let ((request (parse-request (peer.server peer) stream))) ;; ;; ;; (if request ;; ;; ;; (let ((response (eval-request (peer.server peer) request))) ;; ;; ;; (if response ;; ;; ;; (render-response (peer.server peer) response request)))) ;; ;; (if request ;; ;; (render-response (peer.server peer) (make-response) request)) ;; ;; (close-stream stream) ;; ;; (push (- (get-universal-time) time) *timing*)) ;; (write-stream stream "HTTP/1.1 200 OK ;; DATE: Thu, 30 Nov 2008 17:58:12 GMT ;; CONNECTION: keep-alive ;; SERVER: Core-serveR - www.core.gen.tr ;; CONTENT-LENGTH: 5192 ;; CONTENT-TYPE: text/html ;; ") ;; ;; (write-stream stream *5k*) ;; (write-content stream) ;; (close-stream stream) ;; ;; (render-response (peer.server peer) (make-response) nil) ;; )) ;; (defmethod/unit handle-stream :async-no-return ((peer http-cps-unit) (stream core-stream) address) ;; (let ((fd (sb-sys::fd-stream-fd (slot-value stream '%stream)))) ;; (add-fd peer fd (list core-ffi::epollin #.(ash 1 31)) ;; (lambda (&rest values) ;; (declare (ignore values)) ;; (handle-stream4 peer ;; (make-instance 'core-fd-nio-stream ;; :stream fd ;; :unit peer) ;; address))))) ;; (defmethod/unit handle-stream :async-no-return ((peer http-cps-unit) (stream number) address) ;; (let ((fd stream)) ;; (add-fd peer fd (list core-ffi::epollin #.(ash 1 31)) ;; (lambda (&rest values) ;; (declare (ignore values)) ;; (handle-stream4 peer ;; (make-instance 'core-fd-nio-stream ;; :stream fd ;; :unit peer) ;; address))))) ;; (defmethod/unit handle-accept :async-no-return ((self http-cps-unit) listenfd peers) ;; (let* ((peers (copy-list peers)) ;; (peers2 (copy-list peers))) ;; (labels ((kont (&rest values) ;; (declare (ignore values)) ;; (multiple-value-bind (fd address) (core-ffi::accept listenfd) ;; (handle-stream self fd address) ;; ;; (if (car peers) ;; ;; (progn ;; ;; (handle-stream (car peers) fd address) ;; ;; (setq peers (cdr peers)) ;; ;; ;; reschedule ;; ;; (setf (gethash listenfd (s-v '%continuations)) #'kont)) ;; ;; (progn ;; ;; (setq peers peers2) ;; ;; (kont values))) ;; ))) ;; (add-fd (car peers) listenfd (list core-ffi::epollin #.(ash 1 31)) #'kont) ;; (setf (s-v '%receive-messages) nil)))) ;;; (mapcar #'(lambda (mime) ;;; (describe mime) ;;; (when (and (mime.filename mime) (mime.data mime)) ;;; (with-core-stream (stream (pathname (concatenate 'string "/tmp/" (mime.filename mime)))) ;;; (describe (length (mime.data mime))) ;;; (reduce #'(lambda (s a) ;;; (prog1 s (write-stream s a))) ;;; (mime.data mime) :initial-value stream)))) ;;; (http-message.entities request)) ;; (describe (mime-part.data (nth 3 (http-message.entities request)))) ;; ) ;; (describe (list 'pos ;; (sb-impl::fd-stream-get-file-position ;; (slot-value (http-request.stream request) ;; '%stream)) ;; (slot-value (http-request.stream request) ;; '%stream))) ;; ;; (commit-stream stream) ;; (describe (list 'pos ;; (sb-impl::fd-stream-get-file-position ;; (slot-value (http-request.stream request) ;; '%stream)))) ;; ;; (describe stream) ;; ;; (commit-stream stream) ;; ;; (if (not (eq 'head (http-request.method request))) ;; ;; (commit-stream (http-response.stream response))) ;; ;; (write-stream stream "HTTP/1.1 200 OK ;; ;; DATE: Thu, 30 Nov 2008 17:58:12 GMT ;; ;; CONNECTION: keep-alive ;; ;; SERVER: Core-serveR - www.core.gen.tr ;; ;; CONTENT-LENGTH: 5192 ;; ;; CONTENT-TYPE: text/html ;; ;; ") ;; ;; (write-stream stream *5k*) ;; ;; (when (not (eq 'head (http-request.method request))) ;; ;; (commit-stream stream) ;; ;; ;; (write-stream stream (slot-value (http-response.stream response) '%buffer)) ;; ;; ) ;; ;; (describe stream) ;; )) ;; (defclass nio-custom-http-peer (nio-http-peer-mixin custom-http-peer) ;; ()) ;; (defclass+ nio-http-server (web-server nio-socket-server logger-server) ;; () ;; (:default-initargs :peer-class '(nio-custom-http-peer))) ;; (defmethod render-404 ((server http-server) (request http-request) (response http-response)) ;; (setf (http-response.status-code response) (make-status-code 404)) ;; (rewind-stream (http-response.stream response)) ;; (checkpoint-stream (http-response.stream response)) ;; (with-html-output (http-response.stream response) ;; (<:html ;; (<:body ;; "Core-serveR - URL Not Found"))) ;; response) ;; (defmethod/cc2 render-error ((self http-server) stream) ;; "Renders a generic server error response to 'stream'" ;; (let ((response (make-response stream))) ;; (checkpoint-stream stream) ;; (setf (http-response.status-code response) (make-status-code 500)) ;; (http-response-headers! stream response) ;; (char! stream #\Newline) ;; (with-html-output stream (<:html (<:body "An error condition occured and ignored."))) ;; (commit-stream stream))) ;; (defmethod/cc2 render-response ((self http-server) response request) ;; "Renders HTTP 'response' to 'stream'" ;; (let ((accept-encoding (http-request.header request 'accept-encoding)) ;; (stream (http-response.stream response))) ;; (assert (eq 0 (current-checkpoint stream))) ;; (flet ((write-headers () ;; (let ((header-stream ;; (make-core-stream ;; (slot-value (http-request.stream request) '%stream)))) ;; (checkpoint-stream header-stream) ;; (http-response-headers! header-stream response) ;; (char! header-stream #\Newline) ;; (commit-stream header-stream)))) ;; (cond ;; ((member "gzip" accept-encoding :key #'car :test #'string=) ;; (let* ((content (slot-value stream '%write-buffer)) ;; (content-length (length content))) ;; (rewind-stream stream) ;; (labels ((do-finish () ;; (let ((content-length (length (slot-value stream '%write-buffer)))) ;; (http-response.add-entity-header response 'content-length ;; content-length)) ;; (http-response.add-entity-header response 'content-encoding 'gzip) ;; (write-headers) ;; (commit-stream stream)) ;; (callback (stream) ;; (lambda (buffer end) ;; (cond ;; ((< end (length buffer)) ;; (write-stream stream (subseq buffer 0 end)) ;; (do-finish)) ;; (t ;; (write-stream stream buffer)))))) ;; (with-compressor (compressor 'gzip-compressor :callback (callback stream)) ;; (checkpoint-stream stream) ;; (compress-octet-vector (make-array content-length ;; :initial-contents content ;; :element-type '(unsigned-byte 8)) ;; compressor))))) ;; (t ;; (http-response.add-entity-header response 'content-length ;; (length ;; (slot-value stream '%write-buffer))) ;; (write-headers) ;; (commit-stream stream))))))
26,062
Common Lisp
.lisp
584
41.005137
101
0.607971
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
a865e8e6f19b82d6ca381179a542b9e217912a4fe77d27cc1940b40ffa02165f
8,376
[ -1 ]
8,377
socket.lisp
evrim_core-server/src/servers/socket.lisp
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :tr.gen.core.server) ;;+---------------------------------------------------------------------------- ;;| Socket Server ;;+---------------------------------------------------------------------------- (defclass+ socket-server (server) ((host :initarg :host :initform "0.0.0.0" :documentation "IP address that this server binds to") (port :initarg :port :initform 3009 :documentation "Port that this server binds to") (protocol :initarg :protocol :initform :tcp :documentation "Network Protocol, can be :udp, :tcp") (reuse-address :initarg :reuse-address :initform t :documentation "TCP reuse address option") (backlog :initarg :backlog :initform 1 :documentation "TCP backlog option") (peers-max :initarg :peers-max :initform 8 :documentation "Number of peers that this server manages") (element-type :initarg :element-type :initform '(unsigned-byte 8) :documentation "Data type for socket stream") (external-format :initarg :external-format :initform :utf-8 :documentation "External format for stream") (peer-class :initarg :peer-class :initform 'stream-peer :documentation "Class to instantiate as peer thread.") ;; (request-timeout-length :initarg :request-timeout-length :initform 90) (%socket :initform nil) (%peers :initform nil) (%socket-thread :initform nil) (%debug-unit :initform nil)) (:documentation "Socket Server Class")) (defmethod socket-server.run ((self socket-server)) "Run method of Socket Server" (loop (progn (mapc #'(lambda (peer) (multiple-value-bind (stream address) (accept (s-v '%socket)) (when stream (if (not (status peer)) (start peer)) (handle-stream peer stream address)))) (s-v '%peers))))) ;;----------------------------------------------------------------------------- ;; Server Procotol Implementation ;;----------------------------------------------------------------------------- (defmethod make-bind-socket ((self socket-server)) (make-server :host (s-v 'host) :port (s-v 'port) :reuse-address (s-v 'reuse-address) :backlog (s-v 'backlog) :protocol (s-v 'protocol))) (defmethod start ((self socket-server)) (when (not (socket-server.status self)) (when (null (s-v 'debug)) (setf (s-v '%debug-unit) (make-instance 'local-unit :name "Http Server Debugging Unit")) (start (s-v '%debug-unit))) (setf (s-v '%socket) (make-bind-socket self) (s-v '%peers) (mapcar #'(lambda (n) (declare (ignore n)) (let ((p (if (listp (s-v 'peer-class)) (apply #'make-instance (car (s-v 'peer-class)) (cons :debug-unit (cons (if (null (s-v 'debug)) (s-v '%debug-unit) nil) (cdr (s-v 'peer-class))))) (make-instance (s-v 'peer-class) :debug-unit (if (null (s-v 'debug)) (s-v '%debug-unit) nil))))) (start p) (setf (peer.server p) self) p)) (seq (s-v 'peers-max))) (s-v '%socket-thread) (thread-spawn #'(lambda () (socket-server.run self)) :name (format nil "Socket Server at ~A:~A" (s-v 'host) (s-v 'port)))))) (defmethod stop ((self socket-server)) (when (socket-server.status self) (and (s-v '%socket-thread) (thread-kill (s-v '%socket-thread))) (and (s-v '%socket) (close-server (s-v '%socket))) (mapc #'stop (s-v '%peers)) (stop (s-v '%debug-unit)) (setf (s-v '%socket) nil (s-v '%socket-thread) nil (s-v '%peers) nil))) (defmethod socket-server.status ((self socket-server)) (and (threadp (s-v '%socket-thread)) (thread-alive-p (s-v '%socket-thread)))) (defmethod status ((self socket-server)) (socket-server.status self)) ;; +---------------------------------------------------------------------------- ;; | Non Blocking Socket IO Server ;; +---------------------------------------------------------------------------- ;; (defclass nio-socket-server (local-unit) ;; ((host :initarg :host :initform "0.0.0.0" ;; :documentation "IP address that this server binds to") ;; (port :initarg :port :initform 3009 ;; :documentation "Port that this server binds to") ;; (protocol :initarg :protocol :initform :tcp ;; :documentation "Network Protocol, can be :udp, :tcp") ;; (reuse-address :initarg :reuse-address :initform t ;; :documentation "TCP reuse address option") ;; (backlog :initarg :backlog :initform 1 ;; :documentation "TCP backlog option") ;; (peers-max :initarg :peers-max :initform 6 ;; :documentation "Number of peers that this server manages") ;; (element-type :initarg :element-type :initform '(unsigned-byte 8) ;; :documentation "Data type for socket stream") ;; (external-format :initarg :external-format :initform :utf-8 ;; :documentation "External format for stream") ;; (peer-class :initarg :peer-class :initform 'stream-peer ;; :documentation "Class to instantiate as peer thread.") ;; ;; (request-timeout-length :initarg :request-timeout-length :initform 90) ;; (%socket :initform nil) (%peers :initform nil) ;; (%debug-unit :initform nil)) ;; (:documentation "Non blocking socket server")) ;; (defmethod start ((self nio-socket-server)) ;; (when (null (s-v 'debug)) ;; (setf (s-v '%debug-unit) (make-instance 'local-unit :name "Http Server Debugging Unit")) ;; (start (s-v '%debug-unit))) ;; (setf (s-v '%socket) (core-ffi::bind (s-v '%host) (s-v '%port)) ;; (s-v '%peers) (mapcar ;; #'(lambda (n) ;; (declare (ignore n)) ;; (let ((p (if (listp (s-v 'peer-class)) ;; (apply #'make-instance ;; (car (s-v 'peer-class)) ;; (cons :debug-unit ;; (cons (if (null (s-v 'debug)) ;; (s-v '%debug-unit) ;; nil) ;; (cdr (s-v 'peer-class))))) ;; (make-instance (s-v 'peer-class) ;; :debug-unit (if (null (s-v 'debug)) ;; (s-v '%debug-unit) ;; nil))))) ;; (start p) ;; (setf (peer.server p) self) ;; p)) ;; (seq (s-v 'peers-max))) ;; (s-v '%socket-thread) (thread-spawn #'(lambda () (socket-server.run self)) ;; :name (format nil "Socket Server at ~A:~A" ;; (s-v 'host) (s-v 'port))))) ;; (defmethod stop ((self socket-server)) ;; (when (socket-server.status self) ;; (thread-kill (s-v '%socket-thread)) ;; (and (s-v '%socket) (close-server (s-v '%socket))) ;; (mapc #'stop (s-v '%peers)) ;; (stop (s-v '%debug-unit)) ;; (setf (s-v '%socket) nil ;; (s-v '%socket-thread) nil ;; (s-v '%peers) nil))) ;; (defmethod run ((self nio-socket-server)) ;; ) ;; (defmethod make-bind-socket ((self nio-socket-server)) ;; (nio-make-server :host (s-v 'host) ;; :port (s-v 'port) ;; :reuse-address (s-v 'reuse-address) ;; :backlog (s-v 'backlog) ;; :protocol (s-v 'protocol))) ;; (defmethod socket-server.run ((self nio-socket-server)) ;; "Run method of Socket Server" ;; (loop ;; (progn ;; (mapc #'(lambda (peer) ;; (multiple-value-bind (stream address) (nio-accept (s-v '%socket)) ;; (when stream ;; (if (not (status peer)) (start peer)) ;; (handle-stream peer stream address)))) ;; (s-v '%peers)))))
8,046
Common Lisp
.lisp
180
41.511111
95
0.586968
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
5f52a18d5ebaddc313df1c65f918f9a18ce44bbb31956c7e7361becf945ade04
8,377
[ -1 ]
8,378
tinydns.lisp
evrim_core-server/src/servers/tinydns.lisp
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :tr.gen.core.server) ;;+---------------------------------------------------------------------------- ;;| TinyDNS Server ;;+---------------------------------------------------------------------------- ;; ;; This file contains implementation of control server of TinyDNS ;; ;; DNS RFC's: ;; http://www.ietf.org/rfc/rfc1035.txt ;; http://www.ietf.org/rfc/rfc1034.txt ;;----------------------------------------------------------------------------- ;; Data File Parsers ;;----------------------------------------------------------------------------- (defatom domainname-type? () (or (alphanum? c) (= c #.(char-code #\-)))) (defrule nameserver-domainname? (res (acc (make-accumulator)) c) (:oom (:oom (:type domainname-type? c) (:collect c acc)) (:do (setq res (cons acc res) acc (make-accumulator))) #\.) (:return (nreverse res))) (defrule nameserver-hostname? ((acc (make-accumulator)) c) (:oom (:type domainname-type? c) (:collect c acc)) (:return acc)) (defrule tinydns-ns? (domain ip host timestamp) #\. (:nameserver-domainname? domain) #\: (:ipv4address? ip) #\: (:nameserver-hostname? host) #\: (:fixnum? timestamp) (:return (list 'ns (cons host domain) ip timestamp))) (defrule tinydns-a? (fqdn ip timestamp) #\= (:nameserver-domainname? fqdn) #\: (:ipv4address? ip) #\: (:fixnum? timestamp) (:return (list 'a fqdn ip timestamp))) (defrule tinydns-alias? (fqdn ip timestamp) #\+ (:nameserver-domainname? fqdn) #\: (:ipv4address? ip) #\: (:fixnum? timestamp) (:return (list 'alias fqdn ip timestamp))) (defrule tinydns-mx? (domain ip host timestamp) #\@ (:nameserver-domainname? domain) #\: (:ipv4address? ip) #\: (:nameserver-hostname? host) #\: #\: (:fixnum? timestamp) (:return (list 'mx (cons host domain) ip timestamp))) (defrule tinydns-comment? ((acc (make-accumulator)) c) #\# (:zom (:type (or visible-char? space?) c) (:collect c acc)) (:return (list 'comment acc))) (defrule tinydns-txt? ((acc (make-accumulator)) c) #\' (:zom (:type (or visible-char? space?) c) (:collect c acc)) (:return (list 'txt acc))) (defrule tinydns-data? (acc (data '())) (:oom (:or (:tinydns-ns? acc) (:tinydns-a? acc) (:tinydns-alias? acc) (:tinydns-mx? acc) (:tinydns-comment? acc) (:tinydns-txt? acc)) (:do (push acc data)) (:lwsp?)) (:return (nreverse data))) ;;----------------------------------------------------------------------------- ;; Svstat Command ;;----------------------------------------------------------------------------- (defcommand svstat (shell) ((svstat-pathname :host local :initform (whereis "svstat"))) (:default-initargs :cmd +sudo+ :verbose nil)) (defrule svstat? () (:oom (:not #\:) (:type octet?)) (:lwsp?) (:seq "up") (:return t)) (defmethod render-arguments ((self svstat)) (list (s-v 'svstat-pathname))) (defmethod run ((self svstat)) (call-next-method) (svstat? (make-core-stream (command.output-stream self)))) ;;----------------------------------------------------------------------------- ;; Server Implementation ;;----------------------------------------------------------------------------- (defclass+ tinydns-server (server) ((svc-pathname :accessor tinydns-server.svc-pathname :initarg :svc-pathame :initform (whereis "svc")) (svstat-pathname :accessor tinydns-server.svstat-pathname :initarg :svscan-pathname :initform (whereis "svstat")) (root-pathname :accessor tinydns-server.root-pathname :initarg :root-pathname :initform (make-pathname :directory '(:absolute "service" "tinydns"))) (compiler-pathname :accessor tinydns-server.compiler-pathname :initarg :compiler-pathname :initform (whereis "tinydns-data")) (domains :accessor tinydns-server.domains :initform nil) (%timestamp :initform (get-universal-time))) (:default-initargs :name "TinyDNS Server - Mix this class with your server to manage TinyDNS server. See src/servers/tinydns.lisp for implementation")) (defmethod tinydns-server.data-pathname ((self tinydns-server)) (merge-pathnames (make-pathname :directory '(:relative "root") :name "data") (s-v 'root-pathname))) (defun walk-tinydns-data-1 (data) (sort (reduce (lambda (acc atom) (if (listp (cadr atom)) (cons (append (list (reverse (cadr atom)) (car atom)) (cddr atom)) acc))) data :initial-value nil) #'string< :key (lambda (a) (apply #'concatenate 'string (car a))))) (defmethod tinydns-server.data ((self tinydns-server)) (with-server-lock (self) (walk-tinydns-data-1 (tinydns-data? (make-core-file-input-stream (tinydns-server.data-pathname self)))))) (defmethod tinydns-server.domains ((self tinydns-server)) ;; TODO: Fix cacheing, it doesnt work. ;; (if (or (null (s-v '%timestamp)) ;; (> (sb-posix:stat-mtime (sb-posix::stat (tinydns-server.data-pathname self))) ;; (s-v '%timestamp))) ;; (setf (s-v '%timestamp) (sb-posix:stat-mtime ;; (sb-posix::stat (tinydns-server.data-pathname self))) ;; (s-v 'domains) (tinydns-server.data self)) ;; (s-v 'domains)) (tinydns-server.data self)) ;;----------------------------------------------------------------------------- ;; Record Finders ;;----------------------------------------------------------------------------- (defmethod find-record ((self tinydns-server) fqdn) (let ((fqdn (nreverse (nameserver-domainname? (make-core-stream fqdn))))) (reverse (reduce (lambda (acc atom) (if (reduce (lambda (acc1 atom1) (if (and acc1 (equal (car atom1) (cdr atom1))) t nil)) (mapcar #'cons (car atom) fqdn) :initial-value t) (cons (cons (cadr atom) (cons (car atom) (cddr atom))) acc) acc)) (tinydns-server.domains self) :initial-value nil)))) (defmacro defrecord-finder (type) `(defmethod ,(intern (format nil "FIND-~A" type)) ((self tinydns-server) fqdn) (reduce (lambda (acc atom) (if (eq (car atom) ',type) (cons (cdr atom) acc) acc)) (find-record self fqdn) :initial-value nil))) (defrecord-finder a) (defrecord-finder alias) (defrecord-finder ns) (defrecord-finder mx) ;;----------------------------------------------------------------------------- ;; TinyDNS Management Commands ;;----------------------------------------------------------------------------- (defcommand tinydns-add-mixin () ((root :initform #P"/service/tinydns/root/"))) (defmethod render-arguments ((self tinydns-add-mixin)) (list (slot-value self 'add-pathname))) (defmethod run ((self tinydns-add-mixin)) (with-current-directory (slot-value self 'root) (call-next-method))) (defcommand tinydns.add-mx (tinydns-add-mixin shell) ((add-pathname :host local :initform #P"/service/tinydns/root/add-mx")) (:default-initargs :cmd +sudo+ :verbose nil)) (defcommand tinydns.add-host (tinydns-add-mixin shell) ((add-pathname :host local :initform #P"/service/tinydns/root/add-host")) (:default-initargs :cmd +sudo+ :verbose nil)) (defcommand tinydns.add-alias (tinydns-add-mixin shell) ((add-pathname :host local :initform #P"/service/tinydns/root/add-alias")) (:default-initargs :cmd +sudo+ :verbose nil)) (defcommand tinydns.add-ns (tinydns-add-mixin shell) ((add-pathname :host local :initform #P"/service/tinydns/root/add-ns")) (:default-initargs :cmd +sudo+ :verbose t)) ;;----------------------------------------------------------------------------- ;; Implementation of Name-server Protocol ;;----------------------------------------------------------------------------- (defmethod add-mx ((self tinydns-server) fqdn &optional ip) (with-server-lock (self) (tinydns.add-mx :add-pathname (merge-pathnames #P"root/add-mx" (tinydns-server.root-pathname self)) :args (list fqdn ip)))) (defmethod add-host ((self tinydns-server) fqdn ip) (with-server-lock (self) (tinydns.add-host :add-pathname (merge-pathnames #P"root/add-host" (tinydns-server.root-pathname self)) :args (list fqdn ip)))) (defmethod add-alias ((self tinydns-server) fqdn ip) (with-server-lock (self) (tinydns.add-alias :add-pathname (merge-pathnames #P"root/add-alias" (tinydns-server.root-pathname self)) :args (list fqdn ip)))) (defmethod add-ns ((self tinydns-server) fqdn ip) (with-server-lock (self) (tinydns.add-ns :add-pathname (merge-pathnames #P"root/add-ns" (tinydns-server.root-pathname self)) :args (list fqdn ip)))) ;;----------------------------------------------------------------------------- ;; Implementation of Server Protocol ;;----------------------------------------------------------------------------- (defmethod start ((self tinydns-server)) (if (not (probe-file (tinydns-server.data-pathname self))) (error "Cannot access tinydns data file ~A" (tinydns-server.data-pathname self))) (shell :cmd +sudo+ :args (list (s-v 'svc-pathname) "-u" (s-v 'root-pathname))) t) (defmethod stop ((self tinydns-server)) (shell :cmd +sudo+ :args (list (s-v 'svc-pathname) "-d" (s-v 'root-pathname))) (setf (s-v '%timestamp) nil (s-v 'domains) nil) t) (defmethod status ((self tinydns-server)) (svstat :svstat-pathname (s-v 'svstat-pathname) :args (list (s-v 'root-pathname)))) (deftrace tinydns-parsers '(fixnum? nameserver-domainname? ipv4address? nameserver-hostname? tinydns-ns? tinydns-a? tinydns-alias? tinydns-mx? tinydns-data?))
10,165
Common Lisp
.lisp
218
43.330275
92
0.600586
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
6bd56b23b2934fe946bb2d717c0c8638586f0da3cb200670d28781e62804f17c
8,378
[ -1 ]
8,379
logger.lisp
evrim_core-server/src/servers/logger.lisp
;;+---------------------------------------------------------------------------- ;;| Logger Server ;;+---------------------------------------------------------------------------- (in-package :tr.gen.core.server) (defclass logger-server (local-unit) ((log-directory :accessor log-directory :initarg :log-path :initform nil) (log-stream :accessor log-stream :initarg :log-stream :initform nil)) ;;*core-output* (:documentation "Log Server mixin class - Mix this class with your server to enable logging features. See src/servers/logger.lisp for implementation")) (defmethod log-directory ((self logger-server)) (or (slot-value self 'log-directory) (merge-pathnames (make-pathname :directory '(:relative "var" "log")) (bootstrap:home)))) (defmethod log-pathname ((self logger-server)) (merge-pathnames (log-directory self) (make-pathname :name "core-server" :type "log"))) (defmethod log! ((stream core-stream) (tag symbol) (message string)) (checkpoint-stream stream) (string! stream (time->string (get-universal-time) :log)) (char! stream #\Space) (string! stream (symbol-name tag)) (char! stream #\Space) (string! stream message) (char! stream #\Newline) (commit-stream stream)) (defmethod/unit logger-server.log :async-no-return ((self logger-server) (stream core-stream) (tag symbol) (message string)) (log! stream tag message)) (defmethod log-me ((self logger-server) (tag symbol) (message string)) (logger-server.log self (log-stream self) tag message)) ;;----------------------------------------------------------------------------- ;; Server Protocol Implementation ;;----------------------------------------------------------------------------- (defmethod start ((self logger-server)) (unless (log-stream self) (setf (log-stream self) (make-core-stream (open (log-pathname self) :direction :output :element-type '(unsigned-byte 8) :if-exists :append :if-does-not-exist :create :external-format :utf8))))) (defmethod stop ((self logger-server)) (when (log-stream self) (close-stream (log-stream self)) (setf (log-stream self) nil))) (defmethod logger-server.status ((self logger-server)) (if (log-stream self) t)) (defmethod status ((self logger-server)) (logger-server.status self)) ;; ------------------------------------------------------------------------- ;; Logger Application (client of Advanced Logger Server) ;; ------------------------------------------------------------------------- (defclass logger-application (application) ((log-pathname :accessor logger-application.log-pathname :initform nil :initarg :log-pathname) (log-stream :accessor logger-application.log-stream :initform nil))) (defmethod logger-application.log-pathname ((self logger-application)) (or (slot-value self 'log-pathname) (error "Please set (slot-value ~A 'log-pathname)" (class-name (class-of self))))) (defmethod start ((self logger-application)) (with-slots (log-stream) self (setf log-stream (make-core-stream (open (logger-application.log-pathname self) :direction :output :element-type '(unsigned-byte 8) :if-exists :append :if-does-not-exist :create :external-format :utf8))))) (defmethod stop ((self logger-application)) (with-slots (log-stream) self (close-stream log-stream) (setf log-stream nil))) (defmethod log-me ((self logger-application) (tag symbol) (message string)) (aif (application.server self) (logger-server.log it (logger-application.log-stream self) tag message) (log! (logger-application.log-stream self) tag message))) ;; ------------------------------------------------------------------------- ;; Logger Web Application Override ;; ------------------------------------------------------------------------- (defmethod logger-application.log-pathname ((self web-application)) (merge-pathnames (merge-pathnames (make-pathname :directory '(:relative "var" "log")) (bootstrap:home)) (make-pathname :name (web-application.fqdn self) :type "log"))) ;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
4,883
Common Lisp
.lisp
101
44.544554
88
0.625289
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
b67bf895a1624e15be28e9fa9f1b6984a2c32bd08848df70bdb07c2a28f04553
8,379
[ -1 ]
8,380
apache.lisp
evrim_core-server/src/servers/apache.lisp
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :tr.gen.core.server) ;;+---------------------------------------------------------------------------- ;;| Apache2 Web Server ;;+---------------------------------------------------------------------------- (defclass+ apache-server (web-server) ((apachectl-pathname :accessor apache-server.apachectl-pathname :initarg :apachectl-pathname :initform #+pardus (make-pathname :directory '(:absolute "usr" "sbin") :name "apache2ctl") #+debian (make-pathname :directory '(:absolute "usr" "sbin") :name "apache2ctl") #+(not (or pardus debian)) (make-pathname :directory '(:absolute "etc" "init.d") :name "apache2")) (htpasswd-pathname :accessor apache-server.htpasswd-pathname :initarg :htpasswd-pathname :initform #+debian (make-pathname :directory '(:absolute "usr" "bin") :name "htpasswd") #-debian (make-pathname :directory '(:absolute "usr" "sbin") :name "htpasswd2")) (vhosts.d-pathname :accessor apache-server.vhosts.d-pathname :initarg :vhosts.d-pathname :initform #+debian (make-pathname :directory '(:absolute "etc" "apache2" "sites-enabled")) #-debian (make-pathname :directory '(:absolute "etc" "apache2" "vhosts.d"))) (htdocs-pathname :accessor apache-server.htdocs-pathname :initarg :htdocs-pathname :initform (make-pathname :directory '(:absolute "var" "www")))) (:documentation "Apache2 Web Server Class - Mix this class with your server to manage Apache2 Web Server. See src/servers/apache for implementation") (:default-initargs :name "Apache2 Web Server"));; ;;----------------------------------------------------------------------------- ;; Apache2Ctl Command ;;----------------------------------------------------------------------------- (defmethod apachectl ((self apache-server) params) (sb-ext:run-program (namestring +sudo+) (cons (namestring (apache-server.apachectl-pathname self)) params ;; (cons "--nocolor" ;; (cons "--quiet" params)) ))) (defmethod validate-configuration ((self apache-server)) "Validates Apache2 configuration" (eq 0 (sb-impl::process-exit-code (apachectl self '("configtest"))))) ;;----------------------------------------------------------------------------- ;; Comar Command ;;----------------------------------------------------------------------------- #+pardus (defmethod comar ((self apache-server) command) (sb-ext:run-program +sudo+ (cons "/bin/service" (cons "apache" command)))) ;;----------------------------------------------------------------------------- ;; Configuration Helpers ;;----------------------------------------------------------------------------- (defmethod create-redirector ((self apache-server) (app apache-web-application)) "Creates an index.html file for 'app' which redirectory to 'default-entry-point' slot of 'app'" (when (apache-web-application.default-entry-point app) (let* ((redirector-pathname (merge-pathnames (make-pathname :name "index" :type "html" :directory (list :relative (web-application.fqdn app))) (apache-server.htdocs-pathname self))) (s (make-core-file-output-stream redirector-pathname))) (with-html-output s (<:html (<:head (<:meta :http--equiv "Refresh" :content (format nil "0;URL=~A" (apache-web-application.default-entry-point app)))))) (close-stream s) (fix-apache-permissions redirector-pathname)))) (defmethod create-vhost-config ((self apache-server) (app apache-web-application)) "Creates a vhost configuration file for 'app' and writes it to server config directory" (let* ((config-pathname (apache-web-application.config-pathname app)) (config-data (read-string-from-file (apache-web-application.vhost-template-pathname app)))) (with-open-file (s config-pathname :direction :output :if-exists :supersede :if-does-not-exist :create) (write-string (reduce #'(lambda (acc item) (cl-ppcre:regex-replace-all (car item) acc (cdr item))) (list (cons "\\$fqdn" (web-application.fqdn app)) (cons "\\$vhosts.d" (namestring (apache-server.vhosts.d-pathname self))) (cons "\\$admin-email" (web-application.admin-email app)) (cons "\\$htdocs" (namestring (apache-server.htdocs-pathname self)))) :initial-value config-data) s)) (fix-apache-permissions (namestring config-pathname)))) (defmethod create-docroot ((self apache-server) (app apache-web-application)) "Creates a document root directory for 'app' and adjustes permissions accordingly" (let* ((site (web-application.fqdn app)) (docroot-pathname (pathname (format nil "~A~A" (apache-server.htdocs-pathname self) site)))) (unless (probe-file docroot-pathname) (if (apache-web-application.skel-pathname app) (sb-ext:run-program (namestring +cp+) (list "-a" (namestring (apache-web-application.skel-pathname app)) (namestring docroot-pathname))) (sb-ext:run-program +sudo+ (cons +mkdir+ (list "-p" (namestring docroot-pathname))))) (fix-apache-permissions (namestring docroot-pathname)) (sb-ext:run-program +sudo+ (cons (namestring +find+) (list (namestring docroot-pathname) "-type" "d" "-exec" (namestring +chmod+) "770" "{}" "\;")))))) ;;----------------------------------------------------------------------------- ;; Server Protocol Implementation ;;----------------------------------------------------------------------------- (defmethod start ((self apache-server)) (when (validate-configuration self) (eq 0 (#+pardus comar #-pardus apachectl self '("start")))) t) (defmethod stop ((self apache-server)) (when (validate-configuration self) (eq 0 (#+pardus comar #-pardus apachectl self '("stop"))))) (defmethod graceful ((self apache-server)) (when (validate-configuration self) (with-server-mutex (self) (eq 0 (sb-impl::process-exit-code (#+pardus comar #-pardus apachectl self '("graceful"))))))) (defmethod status ((self apache-server)) #+debian (and (probe-file #P"/var/run/apache2.pid") t) #-debian (eq 0 (sb-impl::process-exit-code (#+pardus comar #-pardus apachectl self '("status"))))) (defmethod register ((self apache-server) (app apache-web-application)) (setf (application.server app) self) (create-docroot self app) (apache-server.refresh self app)) (defmethod unregister ((self apache-server) (app apache-web-application)) (let* ((config-pathname (apache-web-application.config-pathname app))) (when (probe-file config-pathname) (delete-file config-pathname)) (graceful self))) (defmethod apache-server.refresh ((self apache-server) (app apache-web-application)) (create-redirector self app) (create-vhost-config self app) (graceful self)) (defmethod apache-server.destroy ((self apache-server) (app apache-web-application)) (unregister self app) (sb-ext:run-program +rm+ (list "-r" (namestring (apache-web-application.docroot-pathname app self)))))
7,725
Common Lisp
.lisp
144
49.479167
108
0.633514
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
5c51451a29a3c14d10a84aaa818ef6985e1b2c6430e7c2621fe452705903d946
8,380
[ -1 ]
8,381
qmail.lisp
evrim_core-server/src/servers/qmail.lisp
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :core-server) (defclass qmail-server (email-server) ((qmail-script-pathname :accessor qmail-server.qmail-script-pathname :initarg qmail-script-pathname :initform (make-pathname :directory '(:absolute "etc" "init.d") :name "svscan")) (vpopmail-pathname :accessor qmail-server.vpopmail-pathname :initarg vpopmail-pathname :initform (make-pathname :directory '(:absolute "var" "vpopmail")))) (:default-initargs :name "Qmail mail Server")) (defmethod run-qmail-sysv-script ((self qmail-server) params) (unwind-protect (sb-impl::process-exit-code (sb-ext:run-program +sudo+ (cons (namestring (qmail-server.qmail-script-pathname self)) params))))) (defmethod qmail-server.vpopmail-bin-pathname ((self qmail-server)) (merge-pathnames (make-pathname :directory '(:relative "bin")) (qmail-server.vpopmail-pathname self))) (defmethod run-vpopmail-script ((self qmail-server) cmd params) (unwind-protect (sb-ext:run-program +sudo+ (cons (namestring (merge-pathnames (make-pathname :name cmd) (qmail-server.vpopmail-bin-pathname self))) params)))) (defmethod start ((self qmail-server)) (eq 0 (run-qmail-sysv-script self '("start")))) (defmethod stop ((self qmail-server)) (eq 0 (run-qmail-sysv-script self '("stop")))) (defmethod status ((self qmail-server)) (eq 0 (run-qmail-sysv-script self '("status")))) (defmethod add-domain ((self qmail-server) domain) (run-vpopmail-script self "vadddomain" (list "-r10" domain))) (defmethod remove-domain ((self qmail-server)) )
2,320
Common Lisp
.lisp
45
48.066667
101
0.730327
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
90299d39f5eaa014763a3cd4ee5ec362c47e6b98e887ab00e8b42c1bedb0de44
8,381
[ -1 ]
8,382
ticket.lisp
evrim_core-server/src/servers/ticket.lisp
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :tr.gen.core.server) ;; +------------------------------------------------------------------------- ;; | Warning, this server is outdated and not loaded. ;; +------------------------------------------------------------------------- ;;+---------------------------------------------------------------------------- ;;| Ticker Server ;;+---------------------------------------------------------------------------- (defclass ticket-model () ((tickets :accessor ticket-model.tickets :initarg :tickets :initform (make-hash-table :test #'equal) :documentation "A list that holds tickets")) (:documentation "Model class for Ticket server")) (defclass ticket () ((hash :accessor ticket.hash :initarg :hash :initform (error "No hash given.") :documentation "A random string") (type :accessor ticket.type :initarg :type :initform nil :documentation "Type of this ticket") (used :accessor ticket.used :initarg :used :initform nil :documentation "t if this ticket is already used")) (:documentation "A Ticket that can be sent to people over the net to give them temporary or permanent access to a resource")) (defun create-unique-hash (table) "Creates a unique random hash string to be used with ticket server" (let ((hash (arnesi::random-string 10))) (cond ((null (cadr (multiple-value-list (gethash hash table)))) hash) (t (create-unique-hash table))))) (defclass ticket-server (server) ((db :accessor ticket-server.db :initarg :db :initform (error "Ticket database not found! Please use :db argument.") :documentation "Database server of this ticker server") (hash-fun :accessor ticket-server.hash-fun :initarg :hash-fun :initform #'(lambda (oldhashlist) (create-unique-hash oldhashlist)) :documentation "Customizable hash function for ticket.hash")) (:default-initargs :name "Ticket Server")) (defun make-ticket-server (path &key (auto-start nil)) "Returns a new ticket server instance, if 'auto-start' is t, server is started" (make-instance 'ticket-server :db (make-instance 'database-server :db-auto-start auto-start :model-class 'ticket-model :directory path))) (defmethod tickets ((self ticket-server)) "Returns list of tickets that this server owns" (ticket-model.tickets (model (ticket-server.db self)))) (defun tx-add-ticket (system hash type &optional (used nil)) "Transactional function used to add tickets" (let* ((model (model system)) (ticket (make-instance 'ticket :hash hash :type type :used used))) (setf (gethash hash (ticket-model.tickets model)) ticket) ticket)) ;;----------------------------------------------------------------------------- ;; Ticket Server Procotol Implementation ;;----------------------------------------------------------------------------- (defmethod add-ticket ((server ticket-server) hash type &optional used) (if (null (cadr (multiple-value-list (gethash hash (tickets server))))) (execute (ticket-server.db server) (make-transaction 'tx-add-ticket hash type used)) (error "Ticket with this hash already exists!"))) (defmethod generate-tickets ((server ticket-server) amount type) (dotimes (i amount) (let ((hash (funcall (ticket-server.hash-fun server) (ticket-model.tickets (model (ticket-server.db server)))))) (execute (ticket-server.db server) (make-transaction 'tx-add-ticket hash type))))) ;;----------------------------------------------------------------------------- ;; Server Protocol Implementation ;;----------------------------------------------------------------------------- (defmethod start ((self ticket-server)) (start (ticket-server.db self))) (defmethod stop ((self ticket-server)) (stop (ticket-server.db self))) (defmethod ticket-server.status ((self ticket-server)) (status (ticket-server.db self))) (defmethod status ((self ticket-server)) (ticket-server.status self))
4,677
Common Lisp
.lisp
88
49.886364
90
0.632086
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
34919078cb95a672432a2a4402356db521b1166bb0e3d470f517fe95994d0bf4
8,382
[ -1 ]
8,383
mail.lisp
evrim_core-server/src/servers/mail.lisp
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. (in-package :tr.gen.core.server) ;; +------------------------------------------------------------------------- ;; | Email Server ;; +------------------------------------------------------------------------- (defclass+ mail-server (server) () (:documentation "Base class for an email server"))
1,040
Common Lisp
.lisp
19
53.210526
77
0.64532
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
a0ca2314ccc36f4e687897c00940f3984c74f5dbb08ef0a328b1b17306bd1844
8,383
[ -1 ]
8,384
units.lisp
evrim_core-server/t/units.lisp
(in-package :tr.gen.core.server.test) (defclass test-unit (local-unit) ()) (defmethod/unit add-two ((self test-unit) no1 no2) (+ no1 no2)) (deftest test-unit1 (let ((unit (make-instance 'test-unit))) (add-two unit 4 3)) 7) (deftest test-unit2 (let ((unit (make-instance 'test-unit))) (start unit) (and (status unit) (prog1 (add-two unit 4 3) (stop unit)))) 7) ;; (defparameter *u (make-instance 'test-unit)) ;; (defmethod/unit show-me-cps ((self test-unit) arg1) ;; (funcall +ret+ arg1) ;; 'default-return-value) ;; (assert (= 7 (add-two *u 4 3))) ;; (assert (null (remove nil ;; (loop for i from 1 upto 1000 ;; collect (if (eq i (show-me-cps *u i)) ;; nil ;; i))))) ;; (start *u) ;; (assert (= 7 (add-two *u 4 3))) ;; (assert (null (remove nil ;; (loop for i from 1 upto 1000 ;; collect (if (eq i (show-me-cps *u i)) ;; nil ;; i))))) (defun clean-local-units () (mapcar #'(lambda (thread) (if (equal "Core-serveR Local Unit" (sb-thread::thread-name thread)) (thread-kill thread))) (core-server::all-threads))) ;; (defmethod/unit add-numbers ((self test-unit) &rest numbers) ;; ;; (apply #'+ numbers) ;; numbers) ;;(assert (= 6 (add-numbers *u 1 2 3))) ;; (defmethod/unit lightning :async-no-return ((test-unit test-unit) abc def) ;; (list test-unit abc def)) ;; (defun fast-lightning (test) ;; (typecase test ;; (core-string-io-stream nil) ;; (core-vector-io-stream nil) ;; (core-fd-io-stream nil) ;; (core-file-io-stream nil) ;; (core-stream nil) ;; (database-server nil) ;; (t nil))) ;; (defun speed-of-light (&optional (n 1000)) ;; (let ((unit (make-instance 'test-unit))) ;; (start unit) ;; (unwind-protect (time ;; (loop for i from 1 upto n ;; do (lightning unit 'gee 33))) ;; (stop unit) ;; ) ;; ;; (time (loop for i from 1 upto n ;; ;; do (fast-lightning unit))) ;; )) ;; (defclass debug-unit (local-unit) ;; ()) ;; (defmethod/unit debug-me :async-no-return ((self unit) (remote unit) caller ;; (condition condition) (lambda function)) ;; (if +debug-units-on-error+ ;; (restart-case (swank:swank-debugger-hook condition nil) ;; (ignore-error () ;; :report "Ignore the error and continue processing.") ;; (retry () ;; :report "Retry the funcall" ;; (send-message remote (slot-value remote '%thread) lambda) ;; (funcall #'(lambda () ;; (apply #'values (funcall (thread-receive))))))) ;; (thread-send caller #'(lambda () (values))))) ;; (defparameter *y (make-instance 'debug-unit)) ;; (start *y) ;; (defclass my-unit (local-unit) ;; ()) ;; (defmethod run ((self local-unit)) ;; (flet ((l00p () ;; (let ((message (receive-message self))) ;; (cond ;; ((eq message 'shutdown) (return-from run (values))) ;; ((and (listp message) (functionp (cdr message))) ;; (handler-bind ((error ;; #'(lambda (condition) ;; (debug-me (if (s-v '%debug-unit) ;; (s-v '%debug-unit) ;; self) ;; (current-thread) ;; condition (cdr message)) ;; ;;; (let ((l #'(lambda () ;; ;;; (format *standard-output* "gee i'm in lambda~%") ;; ;;; (if +debug-units-on-error+ ;; ;;; (restart-case (swank:swank-debugger-hook condition nil) ;; ;;; (ignore-error () ;; ;;; :report "Ignore the error and continue processing.") ;; ;;; (retry () ;; ;;; :report "Retry the funcall" ;; ;;; (send-message self (current-thread) (cdr message)) ;; ;;; (funcall #'(lambda () ;; ;;; (apply #'values (funcall (thread-receive))))))))))) ;; ;;; (if (s-v '%debug-unit) ;; ;;; (send-message (s-v '%debug-unit) (current-thread) l) ;; ;;; (thread-send (car message) l))) ;; (return-from l00p nil)))) ;; (funcall (cdr message) self))) ;; (t (format t "Got unknown message:~A~%" message)))))) ;; (loop (l00p)))) ;; (defun gee () ;; (restart-case ;; (handler-bind ((error #'(lambda (condition) ;; (if +debug-units-on-error+ ;; (swank:swank-debugger-hook condition nil) ;; (invoke-restart 'my-restart 7))))) ;; (error "Foo.")) ;; (my-restart (&optional v) (format t "ab~%") v))) ;; (defmethod/unit valid ((self my-unit)) ;; 1) ;; (defmethod/unit bogus ((self my-unit)) ;; (error "I'm gee the error")) ;; (defparameter *x (make-instance 'my-unit :debug-unit *y)) ;; (start *x) ;; (defparameter *z (make-instance 'my-unit :debug-unit nil)) ;; (start *z) ;; (progn ;; (stop *y) ;; (stop *x) ;; (stop *z) ;; (start *y) ;; (start *x) ;; (start *z)) ;; (defparameter *u1 (make-instance 'local-unit)) ;; (start *u1) ;; (defmethod/unit valid ((self local-unit)) ;; 1) ;; (defmethod/unit bogus ((self local-unit)) ;; (error "there is a horror occurred.")) ;; (defmethod/unit bogus2 :async ((self local-unit)) ;; (error "there is a horror occured.")) ;; (stop *u1) ;; (defparameter *debug-unit* (make-instance 'local-unit :name "Debug Unit")) ;; (defparameter *u1 (make-instance 'local-unit :debug-unit *debug-unit*)) ;; (progn ;; (stop *debug-unit*) ;; (stop *u1) ;; (start *debug-unit*) ;; (start *u1))
5,346
Common Lisp
.lisp
152
33.513158
78
0.567416
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
a8194eb6f460a544ce4721fb5b87b75fb2578a8b8cb230586e1f86e56731144a
8,384
[ -1 ]
8,385
markup.lisp
evrim_core-server/t/markup.lisp
(in-package :core-server.test) ;;----------------------------------------------------------------------------- ;; Html markup tests ;;----------------------------------------------------------------------------- (defparameter *html1* "<html><head><title>Test Title</title></head><body><div id=\"XX\">XX Content</div></body></html>") (deftest html-parse-1 (with-core-stream (s *html1*) (let ((html (html? s))) (car (dom.children (car (dom.children (car (dom.children html)))))))) "Test Title") (deftest html-parse-2 (with-core-stream (s *html1*) (let ((html (html? s))) (block nil (core-search (list (html? (make-core-stream *html1*))) (lambda (a) (if (and (typep a 'dom-element) (equal "XX" (cdr (assoc "id" (dom.attributes a) :test #'equal)))) (return (car (dom.children a))))) #'core-server::dom-successor #'append)))) "XX Content") (deftest html-render-1 (with-core-stream (s "") (html! s (html? (make-core-stream *html1*))) (return-stream s)) "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\"> <html> <head> <title>Test Title</title></head> <body> <div id=\"XX\">XX Content</div></body> </html>") ;;----------------------------------------------------------------------------- ;; RSS markup tests (Thanks to Fazlamesai.net for RSS Feed) ;;----------------------------------------------------------------------------- (defvar *rss* "<?xml version=\"1.0\" encoding=\"ISO-8859-9\"?> <!DOCTYPE rss PUBLIC \"-//Netscape Communications//DTD RSS 0.91//EN\" \"http://my.netscape.com/publish/formats/rss-0.91.dtd\"> <rss version=\"0.91\"> <channel> <title>Fazlamesai.net</title> <link>http://www.fazlamesai.net</link> <description>fazlamesai.net</description> <language>tr</language> <item> <title>e-bergi Temmuz Sayısı Çıktı!</title> <link>http://www.fazlamesai.net/index.php?a=article&amp;sid=5046</link> <description>ODTÜ Bilgisayar Topluluğu olarak, bilgisayar bilimi alanındaki Türkçe kaynak sıkıntısını gidermek amacıyla yayınlamakta olduğumuz elektronik dergi &lt;a href='http://e-bergi.com'&gt;e-bergi &lt;/a&gt;, Temmuz 2008 sayısıyla bu ay da sizlerle...</description> </item> <item> <title>KOffice 2.0 Windows, Linux ve MacOSX'de çalışıyor</title> <link>http://www.fazlamesai.net/index.php?a=article&amp;sid=5045</link> <description>Yeni duyurulan son alpha8 sürümü ile bütün işletim sistemleri için hazır kurulum araçları geliyor. KOffice2.0'ın çıkmasını sabırsızlıkla bekliyoruz. &lt;br&gt;&lt;br&gt; &lt;a href=http://www.koffice.org/announcements/announce-2.0alpha8.php&gt;http://www.koffice.org/announcements/&lt;/a&gt; </description> </item> </channel> </rss> ") (deftest rss-parse-1 (with-core-stream (s "") (type-of (rss? (make-core-stream *rss*)))) <rss:rss) (deftest rss-render-1 (with-core-stream (s "") (rss! s (rss? (make-core-stream *rss*))) (return-stream s)) "<rss version=\"0.91\"> <channel> <title>Fazlamesai.net</title> <link>http://www.fazlamesai.net</link> <description>fazlamesai.net</description> <language>tr</language> <item> <title>e-bergi Temmuz Sayısı Çıktı!</title> <link>http://www.fazlamesai.net/index.php?a=article&amp;sid=5046</link> <description>ODTÜ Bilgisayar Topluluğu olarak, bilgisayar bilimi alanındaki Türkçe kaynak sıkıntısını gidermek amacıyla yayınlamakta olduğumuz elektronik dergi &lt;a href='http://e-bergi.com'&gt;e-bergi &lt;/a&gt;, Temmuz 2008 sayısıyla bu ay da sizlerle...</description> </item> <item> <title>KOffice 2.0 Windows, Linux ve MacOSX'de çalışıyor</title> <link>http://www.fazlamesai.net/index.php?a=article&amp;sid=5045</link> <description>Yeni duyurulan son alpha8 sürümü ile bütün işletim sistemleri için hazır kurulum araçları geliyor. KOffice2.0'ın çıkmasını sabırsızlıkla bekliyoruz. &lt;br&gt;&lt;br&gt; &lt;a href=http://www.koffice.org/announcements/announce-2.0alpha8.php&gt;http://www.koffice.org/announcements/&lt;/a&gt; </description> </item> </channel></rss>") ;;----------------------------------------------------------------------------- ;; CSS Tests ;;----------------------------------------------------------------------------- ;; (deftest css-render-1 ;; (with-core-stream (s "") ;; (css! s (css "html" :background-color "#000" :color "#FFF")) ;; (return-stream s)) ;; "html { ;; background-color: #000; ;; color: #FFF; ;; }; ;; ") ;; (defmacro defcss-test (name fun string &body result) ;; `(deftest ,(intern (format nil "CSS-~A" name)) ;; (funcall (function ,(intern (symbol-name fun) :core-server)) ;; (make-core-stream ,string)) ;; ,@result)) ;; (defcss-test value-1 css-value? "moo#gee" "moo") ;; (defcss-test value-2 css-value? "-gee_" "-gee") ;; (defcss-test universal-selector css-universal-selector? ;; "*" (core-server::universal-selector)) ;; (defcss-test type-selector css-type-selector? "div#moo" ;; (core-server::type-selector "div")) ;; (defcss-test descendant-selector css-descendant-selector? "div span" ;; (core-server::descendant-selector (core-server::type-selector "div") ;; (core-server::type-selector "span"))) ;; (defcss-test child-selector css-child-selector? "div > span" ;; (core-server::child-selector (core-server::type-selector "div") ;; (core-server::type-selector "span"))) ;; (defcss-test first-child-selector css-first-child-selector? "div:first-child" ;; (core-server::first-child-selector (core-server::type-selector "div"))) ;; (defcss-test link-selector-1 css-link-selector? "a:link" ;; (core-server::link-selector (core-server::type-selector "a") core-server::link)) ;; (defcss-test link-selector-2 css-link-selector? "a:visited" ;; (core-server::link-selector (core-server::type-selector "a") core-server::visited)) ;; (defcss-test dynamic-selector css-dynamic-selector? "a:active" ;; (core-server::dynamic-selector (core-server::type-selector "a"))) ;; (defcss-test lang-selector css-lang-selector? "div:lang(turkish)" ;; (core-server::lang-selector (core-server::type-selector "div") "turkish")) ;; (defcss-test adjacent-selector css-adjacent-selector? "div + span" ;; (core-server::adjacent-selector (core-server::type-selector "div") ;; (core-server::type-selector "span"))) ;; (defcss-test attribute-selector-1 css-attribute-selector? "div[foo]" ;; (core-server::attribute-selector (core-server::type-selector "div") ;; ((core-server::exists "foo" nil)))) ;; (defcss-test attribute-selector-2 css-attribute-selector? "div[foo|=\"oof\"][moo=\"zoo\"][poo~=\"oop\"]" ;; (core-server::attribute-selector (core-server::type-selector "div") ;; ((core-server::hypen-member "foo" "oof") ;; (core-server::equal "moo" "zoo") ;; (core-server::space-member "poo" "oop")))) ;; (defcss-test class-selector css-class-selector? "moo.warning" ;; (core-server::attribute-selector (core-server::type-selector "moo") ;; ((equal "class" "warning")))) ;; (defcss-test id-selector css-id-selector? "div#gee" ;; (core-server::id-selector (core-server::type-selector "div") "gee"))
7,652
Common Lisp
.lisp
146
47.910959
322
0.628567
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
f3640489d982e91ec7fe514f5f49685cc13d8303539573e2b5b1d8566d555740
8,385
[ -1 ]
8,386
speed.lisp
evrim_core-server/t/speed.lisp
(in-package :Core-server) (defun speed-test1 () (time (let ((s (make-core-stream ""))) (dotimes (i 10000) (checkpoint-stream s) (write-stream (make-html-stream s) (<:html (<:body "foo"))) (commit-stream s)) (length (return-stream s))))) (defun speed-test2 () (time (let ((s (make-core-list-output-stream))) (dotimes (i 10000) (checkpoint-stream s) (write-stream (make-html-stream s) (<:html (<:body "foo"))) (commit-stream s)) (length (return-stream2 s))))) (defun speed-test3 () (time (let ((s (make-core-stream ""))) (dotimes (i 100000) (checkpoint-stream s) (with-js () s (let ((a (<:html (<:body a)))) (append document.body a))) (commit-stream s)) (length (return-stream s))))) (defun speed-test4 () (time (let ((s (make-core-list-output-stream))) (dotimes (i 100000) (checkpoint-stream s) (with-js () s (let ((a (<:html (<:body a)))) (append document.body a))) (commit-stream s)) (length (return-stream2 s)))))
1,082
Common Lisp
.lisp
37
23.756757
66
0.567179
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
034fe35a6807353616780ec8706cfb2c1be10bbc14879537dc0a23f818d1d4f7
8,386
[ -1 ]
8,387
aycan.lisp
evrim_core-server/t/aycan.lisp
;; This buffer is for notes you don't want to save, and for Lisp evaluation. ;; If you want to create a file, visit that file with C-x C-f, ;; then enter the text in that file's own buffer. (defclass trinode-application (apache-web-application modular-application apax-application-module cookie-session-module) ()) () (defentry-point "trinode.core" ... () (call 'make-instance 'coretal :configuration (call 'get-coretal-config))) (defclass server-listener (server) ()) (defgeneric find-free-node (servers) (:documentation "Finds most empty server.")) (defclass node () ()) (defun current-node () *node1*) ;; send from socket (defmethod send ((node node) expr) (write expr)) (defmacro with-node ((var node) &body body) `(send ,(funcall node) '(let ((,var ,(funcall node))) ,body))) (defparameter *node1* (make-instance 'node)) (with-node (find-free-node (*servers*)) (defparameter *core-server* (make-instance 'core-server))) ( (cl-prevalence::serialize-sexp '(lambda () (format t "asd")) out) (cl-prevalence::deserialize-sexp out)) (defparameter *trk* nil) (time (loop for i from 1 to 25000000 do (push i *trk*))) ;;fantaazi (defun create-servers (num) (loop for n from 1 to num collect (make-instance 'ucw-server :backend (ucw::make-backend :mod-lisp :host "127.0.0.1" :port (+ n 3010))))) (defun test-servers (container) (reduce #'(lambda (a b) (and a b)) (mapcar #'(lambda (server) (status server)) container))) (defun stop-servers (servers) (mapcar #'(lambda (server) (stop server)) servers)) (let ((servers (create-servers 10))) (if (test-servers) (stop-servers servers) 'failed))
1,705
Common Lisp
.lisp
52
29.5
120
0.682987
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
011fe8e9fb9f4b2a25c0f520fec193e5c31dd989e5db2cd48eb4836f43f60bc4
8,387
[ -1 ]
8,388
ucw.lisp
evrim_core-server/t/ucw.lisp
(in-package :core-server.test) (defparameter *ucw-server* (make-instance 'ucw-server :backend (ucw::make-backend :httpd :host "127.0.0.1" :port 8080))) (describe *ucw-server*) (start *ucw-server*) (status *ucw-server*) (stop *ucw-server*) (defclass my-web-app (ucw-web-application apache-web-application) ()) (defparameter *app* (make-instance 'my-web-app :fqdn "www.core.gen.tr" :admin-email "abc" :url-prefix "/www/")) (defparameter *app2* (make-instance 'my-web-app :fqdn "labs.core.gen.tr" :admin-email "[email protected]" :url-prefix "/labs/")) (describe *app*) (describe *app2*) (register *ucw-server* *app*) (register *ucw-server* *app2*)
699
Common Lisp
.lisp
21
29.761905
95
0.669139
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
234dd67651e0773133862dcffc9bf724650569584aa0880b3daa05d8692a861c
8,388
[ -1 ]
8,389
sockets.lisp
evrim_core-server/t/sockets.lisp
(in-package :tr.gen.core.server.test) (defparameter *listen-ip* "0.0.0.0") (defparameter *listen-port* 5555) (deftest resolv-hostname (let ((h #(139 179 139 251)) (result (resolve-hostname "www.core.gen.tr"))) (reduce #'(lambda (x y) (if x y nil)) (map 'list #'equal h result) :initial-value t)) t) (deftest server (let ((server (make-server :host *listen-ip* :port *listen-port*))) (handler-case (unwind-protect (let* ((stream (connect *listen-ip* *listen-port*))) ;; should listen on 5555 (and server stream t)) (close-server server)) (condition (c) (close-server server)))) t)
653
Common Lisp
.lisp
22
25.363636
71
0.631161
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
f2721c122c2034ff2acc72f8d9b0c5295ae93769a072a1c3efd52efe8142e67e
8,389
[ -1 ]
8,390
method.lisp
evrim_core-server/t/method.lisp
(in-package :core-server.test) ;; sysv-standard method combination (defclass a-server (server) ((a-server.status :initform nil))) (defmethod start ((self a-server)) (format t "Starting server a~%") (setf (slot-value self 'a-server.status) t) 'a-server-start) (defmethod stop ((self a-server)) (format t "Stopping server a~%") (setf (slot-value self 'a-server.status) nil) 'a-server-stop) (defmethod status ((self a-server)) (slot-value self 'a-server.status)) (defclass b-server (server) ((b-server.status :initform nil))) (defmethod start ((self b-server)) (format t "Starting server b~%") 'b-server-start) (defmethod stop ((self b-server)) (format t "Stopping server b~%") (setf (slot-value self 'b-server.status) nil) 'b-server-stop) (defclass c-server (a-server) ()) (defmethod start ((self c-server)) (format t "Starting server c~%") 'c-server-start) (defclass test-server (c-server b-server a-server) ()) (defmethod start ((self test-server)) (format t "starting server test-server~%") 'test-server-start) (deftest sysv-1 (let ((s (make-instance 'test-server))) (multiple-value-list (start s))) (test-server-start c-server-start b-server-start a-server-start t)) (deftest sysv-2 (let ((s (make-instance 'test-server))) (start s) (multiple-value-list (start s))) (test-server-start c-server-start b-server-start t t)) (deftest sysv-3 (let ((s (make-instance 'test-server))) (start s) (multiple-value-list (stop s))) (b-server-stop a-server-stop t)) (deftest sysv-4 (let ((s (make-instance 'test-server))) (start s) (stop s) (multiple-value-list (stop s))) (b-server-stop t t)) ;; TEST> (start (make-instance 'core-server::core-server)) ;; c-server init-instance ;; core-server init-instance ;; around start core-server ;; starting ucw-server ;; starting b-server ;; starting a-server ;; starting c-server ;; starting core-server ;; NIL ;; TEST> (stop (make-instance 'core-server::core-server)) ;; c-server init-instance ;; core-server init-instance ;; around stop core-server ;; stopping core-server ;; stopping c-server ;; stopping a-server ;; stopping b-server ;; stopping ucw-server ;; T
2,224
Common Lisp
.lisp
73
27.712329
69
0.69274
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
02410aba69f1171ce7613b4f52874ab59e9ab3444d0257b8abd6bf0193717f33
8,390
[ -1 ]
8,391
http.lisp
evrim_core-server/t/http.lisp
(in-package :core-server) (defvar *dojo-url* "/dojo/dojo.js") (eval-always (defclass test-application (http-application) ())) (unregister core-server::*server* *app*) (eval-always (defparameter *app* (make-instance 'test-application :fqdn "test" :admin-email "[email protected]"))) (register core-server::*server* *app*) (defun/cc header () (<:div "I'm a header, jo!")) (defun/cc greeting () (<:div "Greeting, lets do it!")) (defun/cc footer () (<:div "say, don't make me foot, i'll make you a footer.")) (defun/cc navigation () (<:ul (<:li (<:a :href (action/url () (answer :menu1)) "menu1")) (<:li (<:a :href (action/url () (answer :menu2)) "menu2")))) (defun/cc settings (name) (<:div "Here is the settings:") (<:form :action "index.core" :method "GET" :onsubmit (js:js* `(progn (dojo.io.bind (create :url ,(function/url ((dekst "dekst") (mekst "mekst")) (answer dekst)) :mimetype "text/javascript" :form-node this)) (return false))) (<:ah "Neym:") (<:input :type "text" :value name :name "dekst") (<:input :type "submit" :value "kaydit"))) (defun/cc window (&optional (b0dy #'greeting)) (format t "into the window~%") (prog1 (send/suspend (<:html (<:head (<:script :src *dojo-url* :type "text/javascript")) (<:body (<:div :class "container" (header) (navigation) (<:div :id "body" :class "wrapper" (funcall b0dy)) (footer))))) (format t "out to window~%"))) (defun/cc coretal (app &optional (b0dy #'greeting)) (let ((it (window b0dy))) (format t "window ret:~A~%" it) (cond ((eq it :menu1) (format t "Do menu1~%") (let ((r (window (lambda () (settings "neym"))))) (format t "r:~A" r) (javascript (lambda () (format t "Javascript~%") (<:js `(setf (slot-value ($ "body") 'inner-h-t-m-l) (+ "Result:" ,r))))))) ((eq it :menu2) (format t "Do menu2~%") (coretal app (lambda () (<:ah "menu2")))) (t (break it))))) (defurl *app* "index.core" ((command "cmd")) ;; (describe command) ;; (describe *context*) (loop (progn (format t "looping~%") (coretal *app*)))) (defun/cc get-number () (send/suspend (<:html ;; (<:head (<:script :src *dojo-url* :type "text/javascript")) (<:body (<:form :action "number.core" :method "GET" (<:input :type "hidden" :name "k" :value (function/hash ((number "number")) (answer (parse-integer number :junk-allowed t)))) (<:input :type "hidden" :name "s" :value (id (session +context+))) (<:ah "Enter Number:") (<:input :type "text" :name "number") (<:input :type "submit" :value "Tamam")))))) (defun/cc print-number (number) (send/suspend (<:html ; (<:head (<:script :src *dojo-url* :type "text/javascript")) (<:body (<:div (<:p (<:ah number))))))) (defun add-numbers (num1 num2) (print (+ num1 num2))) (defurl *app* "number.core" () (print-number (+ (get-number) (get-number)))) (defun/cc test-fun (acc) (send/suspend (<:html (<:head) (<:body (<:a :href (action/url () (test-fun (1+ acc))) (<:ah "Acc(action):" acc)) (<:br) (<:a :href (function/url () (test-fun (1+ acc))) (<:ah "Acc(function):" acc)))))) (defurl *app* "gee.core" () (test-fun 0)) (defun/cc render-node (name) (send/suspend (<:html (<:body (dotimes (i 3) (<:a :href (let ((i i)) (function/url () (render-node (format nil "~A.~D" name i)))) (format nil "~A.~D" name i)) (<:br)))))) (defurl *app* "tree.core" () (render-node "ahmet")) (defun/cc render-graph-node (name) (send/suspend (<:html (<:body (<:p (format nil "~A" name)) (dotimes (i 3) (<:a :href (let ((i i)) (function/url () (render-graph-node (format nil "~A.~D" name i)))) (format nil "~A.~D" name i)) (<:br)) (<:a :href (action/url () (ana-sayfa)) "Ana Sayfa"))))) (defun/cc ana-sayfa () (<:html (<:body (render-graph-node "mehmet")))) (defurl *app* "graph.core" () (ana-sayfa)) (defurl *app* "form.core" () (send/suspend (<:html (<:head) (<:body (<:form :action (action/url ((f1 "f1") (f2 "f2")) (setf *a (request +context+)) (break (request +context+)) (break (list f1 f2))) :method "POST" :enctype "multipart/form-data" (<:input :type "text" :name "f1" :value "f1-value") (<:input :type "file" :name "f2") (<:input :type "submit" :value "Gonder Bakalim")))))) (defurl *app* "gee.core" () (labels ((abc () (send/suspend (<:div "eben") (<:a :href (action/url () (abc)) "Continue")))) (abc))) (defurl *app* "omed.core" () (labels ((gee (a) (cond ((eq a 1) (gee 2)) (t (<:p (format nil "~D" (+ a (send/suspend (<:a :href (function/url () (answer (+ a 1))) "Return"))))))))) (gee 1))) (defurl *app* "demo.core" () (labels ((gee (a b) (describe (list a b)) (cond ((> b a) (gee a 0)) (t (gee a (send/suspend (<:div "START" (format nil "~A" a) (format nil " ~A~%" b)) (<:a :href (action/url () (gee 1 2)) "Link1") (<:a :href (action/url ((var "gee")) (answer (parse-integer "5"))) "Link2"))))))) (gee 10 0))) (defurl *app* "demo.core" () (labels ((gee (a b) (cond ((> a b) (gee 0 b)) (t (gee (send/suspend (<:div "START" (format nil "~A" a) (format nil " ~A~%" b)) (<:a :href (action/url () (gee 1 2)) "Link1") (<:a :href (action/url () (answer 3)) "Link2")) b))))) (gee 0 0))) (defurl *app* "demo.core" () (labels ((gee (a b) (let ((result (send/suspend (<:div "START" (format nil "~A" a) (format nil " ~A~%" b)) (<:a :href (action/url () (gee 1 2)) "Link1") (<:a :href (action/url () (answer (cons 3 4))) "Link2")))) (gee (car result) (cdr result))))) (gee nil nil))) (defurl *app* "crud.core" () (let ((result (send/suspend (<:h1 "View of First User") (user/view (car *users*)) (<:h1 "Edit of Second User") (user/edit (cadr *users*))))) (send/suspend (<:h1 "User is:" (format nil "~A" result)) (let ((result (send/suspend (user/edit (car *users*) (action/url ((name "NAME") (pass "PASS")) (answer 'eben name pass)))))) (send/suspend (<:h1 "test!" (format nil "~A" result)))))))
6,732
Common Lisp
.lisp
235
23
82
0.519641
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
1c1c348ac417914607478ed9b0bd6fbf0ae3ebed3f9324041f8ed644fd50fa6b
8,391
[ -1 ]
8,392
test-harness.lisp
evrim_core-server/t/test-harness.lisp
(in-package :tr.gen.core.server.test) (defmacro deftest-parser (test-name test-function string result) `(deftest ,test-name (let ((cs (make-core-stream ,string))) (equal ,result (funcall (function ,test-function) cs))) t)) (defmacro deftest-render (test-name test-function value result) `(deftest ,test-name (let ((cs (make-core-stream ""))) (funcall (function ,test-function) cs ,value) (equal ,result (return-stream cs))) t))
468
Common Lisp
.lisp
14
29.571429
64
0.681416
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
7ec5e2f2c6ffb9db9f213d73b110082db4802e168e94de51a094dc28d15199c2
8,392
[ -1 ]
8,393
json.lisp
evrim_core-server/t/json.lisp
(in-package :tr.gen.core.server.test) ;; JSON String (deftest-parser json-string?-plain core-server::json-string? "hobaa" "hobaa") (deftest-parser json-string?-quoted core-server::json-string? "\"hobaa\"" "hobaa") (deftest-render json-string!-plain core-server::json-string! "hobaa" "\"hobaa\"") ;; JSON Number (deftest-parser json-number?-integer core-server::json-number? "123" 123) (deftest-parser json-number?-integer core-server::json-number? "37.3000" 37) (deftest-parser json-number?-integer core-server::json-number? "-37.3000" -37) (deftest-parser json-number?-integer core-server::json-number? "123" 123) (deftest-parser json-number?-integer core-server::json-number? "123" 123) (deftest-render json-number!-integer core-server::json-number! 123 "123") (deftest-render json-number!-float core-server::json-number! 123.2222e10 "1.232222e12") ;;; ;; JSON Boolean (deftest-parser json-boolean?-true core-server::json-boolean? "true" 'true) (deftest-parser json-boolean?-false core-server::json-boolean? "false" 'false) (deftest-render json-boolean!-t core-server::json-boolean! t "true") (deftest-render json-boolean!-true core-server::json-boolean! 'true "true") (deftest-render json-boolean!-false core-server::json-boolean! 'false "false") ;;; ;; JSON Array (deftest-parser json-array?-nums core-server::json-array? "[1,2,3]" '(1 2 3)) (deftest-parser json-array?-strings core-server::json-array? "[\"core\", \"gen\", \"tr\"]" '("core" "gen" "tr")) (deftest-parser json-array?-bools core-server::json-array? "[true, false, undefined]" '(true false undefined)) (deftest-render json-array!-nums core-server::json-array! '(1 2 3) "[ 1 , 2 , 3 ]") (deftest-render json-array!-strings core-server::json-array! '("core" "gen" "tr") "[ \"core\" , \"gen\" , \"tr\" ]") (deftest-render json-array!-bools core-server::json-array! '(undefined true false) "[ undefined , true , false ]") ;;; ;; JSON Object (deftest-parser json-object?-proplist (lambda (stream) (hash-to-alist (core-server::json-object? stream))) "{ a: 1, b:2, c: 3 }" '(("a" . 1) ("b" . 2) ("c" . 3))) (deftest-render json-object!-proplist core-server::json-object! (arnesi::build-hash-table '(:test equal) '(("abc" 1) ("def" 2) ("hij" 3))) "{ \"abc\": 1, \"def\": 2, \"hij\": 3 }") ;;; ;; RFC Test Data (defvar +json-test1+ " { \"Image\": { \"Width\": 800, \"Height\": 600, \"Title\": \"View from 15th Floor\", \"Thumbnail\": { \"Url\": \"http://www.example.com/image/481989943\", \"Height\": 125, \"Width\": \"100\" }, \"IDs\": [116, 943, 234, 38793] } } ") (deftest-parser json-rfc-test1? (lambda (stream) (caar (hash-to-alist (core-server::json-object? stream)))) +json-test1+ "Image") (defvar +json-test2+ " [ { \"precision\": \"zip\", \"Latitude\": 37.7668, \"Longitude\": -122.3959, \"Address\": \"\", \"City\": \"SAN FRANCISCO\", \"State\": \"CA\", \"Zip\": \"94107\", \"Country\": \"US\" }, { \"precision\": \"zip\", \"Latitude\": 37.371991, \"Longitude\": -122.026020, \"Address\": \"\", \"City\": \"SUNNYVALE\", \"State\": \"CA\", \"Zip\": \"94085\", \"Country\": \"US\" } ]") (deftest-parser json-rfc-test2? (lambda (stream) (mapcar #'hash-to-alist (core-server::json-array? stream))) +json-test2+ '((("precision" . "zip") ("Latitude" . 37) ("Longitude" . 122) ("Address" . NULL) ("City" . "SAN FRANCISCO") ("State" . "CA") ("Zip" . "94107") ("Country" . "US")) (("precision" . "zip") ("Latitude" . 37) ("Longitude" . 122) ("Address" . NULL) ("City" . "SUNNYVALE") ("State" . "CA") ("Zip" . "94085") ("Country" . "US")))) (deftest json-dom2js! (with-core-stream (s "") (html! s (<:div :id "5" "GEE")) (return-stream s)) "<DIV id=\"5\">GEE</DIV>")
4,256
Common Lisp
.lisp
101
35.316832
162
0.55518
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
e8fcb4e84f397f5969b2d46064957a01b2a4a8f2677281052fb6b79f57c9cf6d
8,393
[ -1 ]
8,394
tinydns.lisp
evrim_core-server/t/tinydns.lisp
(in-package :core-server.test) (defparameter *tinydns-data* ".core.gen.tr:139.179.139.251:a:259200 .core.gen.tr:212.175.40.11:b:259200 =node1.core.gen.tr:139.179.139.251:86400 =node2.core.gen.tr:212.175.40.11:86400 =node3.core.gen.tr:212.175.40.12:86400 +www.core.gen.tr:139.179.139.251:86400 +imap.core.gen.tr:212.175.40.11:86400 +smtp.core.gen.tr:212.175.40.11:86400 =zpam.core.gen.tr:212.175.40.55:86400 @core.gen.tr:212.175.40.55:a::86400 'core.gen.tr:v=spf1 a mx a\072node2.core.gen.tr a\072office1.core.gen.tr ~all:3600 +coretal.core.gen.tr:212.175.40.11:86400 +ns1.core.gen.tr:139.179.139.251:86400 +ns2.core.gen.tr:212.175.40.11:86400 +irc.core.gen.tr:139.179.139.251:86400 +wiki.core.gen.tr:212.175.40.12:86400 +priwiki.core.gen.tr:212.175.40.12:86400 +svn.core.gen.tr:139.179.139.251:86400 +cvs.core.gen.tr:139.179.139.251:86400 =zen.core.gen.tr:195.174.145.244:86400 +people.core.gen.tr:139.179.139.251:86400 +blogs.core.gen.tr:139.179.139.251:86400 +evrimulu.core.gen.tr:139.179.139.251:86400 +paketler.core.gen.tr:212.175.40.11:86400 .aytek.org:139.179.139.251:a:259200 .aytek.org:212.175.40.11:b:259200 +www.aytek.org:139.179.139.251:86400 .hackatronix.com:139.179.139.251:a:259200 .hackatronix.com:212.175.40.11:b:259200 +www.hackatronix.com:139.179.139.251:86400 .arslankardesler.com.tr:139.179.139.251:a:259200 .arslankardesler.com.tr:212.175.40.11:b:259200 .teargas.org:139.179.139.251:a:259200 .teargas.org:212.175.40.11:b:259200 =www.teargas.org:212.175.40.11:86400 +www.arslankardesler.com.tr:212.175.40.36:86400 +mail.arslankardesler.com.tr:212.175.40.36:86400 @arslankardesler.com.tr:212.175.40.36:a::86400 +mail.core.gen.tr:212.175.40.11:86400 @hackatronix.com:212.175.40.11:a::86400 #.karacadil.com.tr:139.179.139.251:a:259200 #.karacadil.com.tr:212.175.40.11:b:259200 #+www.karacadil.com.tr:212.175.40.11:86400 #@karacadil.com.tr:212.175.40.36:a::86400 #+mail.karacadil.com.tr:212.175.40.36:86400 .kulogluahsap.com:139.179.139.251:a:259200 .kulogluahsap.com:212.175.40.11:b:259200 @kulogluahsap.com:212.175.40.36:a::86400 +www.kulogluahsap.com:212.175.40.36:86400 +mail.kulogluahsap.com:212.175.40.36:86400 .meptasarim.net:139.179.139.251:a:259200 .meptasarim.net:212.175.40.11:b:259200 .cadilar.com:212.175.40.11:a:259200 .cadilar.com:139.179.139.251:b:259200 @meptasarim.net:212.175.40.36:a::86400 +www.meptasarim.net:212.175.40.36:86400 @cadilar.com:212.175.40.36:a::86400 +www.cadilar.com:212.175.40.36:86400 .hedee.com:139.179.139.251:a:259200 .hedee.com:212.175.40.11:b:259200 @hedee.com:212.175.40.11:a::86400 +www.hedee.com:212.175.40.11:86400 .dervisozer.com:139.179.139.251:a:259200 .dervisozer.com:212.175.40.11:b:259200 +www.dervisozer.com:212.175.40.11:86400 @dervisozer.com:212.175.40.11:a::86400 +ebooks.core.gen.tr:139.179.139.251:86400 +core.gen.tr:212.175.40.11:86400 =heechee.core.gen.tr:195.174.145.186:86400 +labs.core.gen.tr:139.179.139.251:86400 .ersoyemlak.com.tr:139.179.139.251:a:259200 .ersoyemlak.com.tr:212.175.40.11:b:259200 .ersoyinsaat.com.tr:139.179.139.251:a:259200 .ersoyinsaat.com.tr:212.175.40.11:b:259200 +www.ersoyemlak.com.tr:139.179.139.251:86400 +www.ersoyinsaat.com.tr:139.179.139.251:86400 .grafturk.com:139.179.139.251:a:259200 .grafturk.com:212.175.40.11:b:259200 +mail.grafturk.com:212.175.40.36:86400 +www.grafturk.com:212.175.40.36:86400 @grafturk.com:212.175.40.36:a::86400 +ederslik.com:212.175.40.12:86400 .ederslik.com:139.179.139.251:a:259200 .ederslik.com:212.175.40.11:b:259200 +www.ederslik.com:212.175.40.12:86400 .ebrualbayrak.com:139.179.139.251:a:259200 .ebrualbayrak.com:212.175.40.11:b:259200 .atilalbayrak.com:139.179.139.251:a:259200 .atilalbayrak.com:212.175.40.11:b:259200 +www.ebrualbayrak.com:212.175.40.36:86400 +www.atilalbayrak.com:212.175.40.36:86400 @ebrualbayrak.com:212.175.40.36:a::86400 @atilalbayrak.com:212.175.40.36:a::86400 .sentezarastirma.com:212.175.40.11:a:259200 .sentezarastirma.com:139.179.139.251:b:259200 +www.sentezarastirma.com:212.175.40.36:86400 @sentezarastirma.com:212.175.40.36:a::86400 +mail.sentezarastirma.com:212.175.40.36:86400 .biyoart.com.tr:139.179.139.251:a:259200 .biyoart.com.tr:212.175.40.11:b:259200 +www.biyoart.com.tr:212.175.40.36:86400 +mail.biyoart.com.tr:212.175.40.36:86400 @biyoart.com.tr:212.175.40.36:a::86400 =psyche.core.gen.tr:212.156.217.235:86400 =office1.core.gen.tr:88.249.13.201:86400 .caveti.com:139.179.139.251:a:259200 .caveti.com:212.175.40.11:b:259200 +www.caveti.com:212.175.40.11:86400 .kocademirler.com:139.179.139.251:a:259200 .kocademirler.com:212.175.40.11:b:259200 @kocademirler.com:212.175.40.36:a::86400 +www.kocademirler.com:212.175.40.36:86400 +mail.kocademirler.com:212.175.40.36:86400 .guzincanan.com:139.179.139.251:a:259200 .guzincanan.com:212.175.40.11:b:259200 @guzincanan.com:212.175.40.36:a::86400 +www.guzincanan.com:212.175.40.36:86400 +mail.guzincanan.com:212.175.40.36:86400 .adamsaat.com:139.179.139.251:a:259200 .adamsaat.com:212.175.40.11:b:259200 @adamsaat.com:212.175.40.55:a::86400 +www.adamsaat.com:212.175.40.11:86400 +mail.adamsaat.com:212.175.40.11:86400 .ozcanlarticaret.com:139.179.139.251:a:259200 .ozcanlarticaret.com:212.175.40.11:b:259200 @ozcanlarticaret.com:212.175.40.36:a::86400 +www.ozcanlarticaret.com:212.175.40.36:86400 +mail.ozcanlarticaret.com:212.175.40.36:86400 .barutrock.com:139.179.139.251:a:259200 .barutrock.com:212.175.40.11:b:259200 @barutrock.com:212.175.40.36:a::86400 +www.barutrock.com:212.175.40.36:86400 +mail.barutrock.com:212.175.40.36:86400 =node4.core.gen.tr:212.175.40.56:86400 .dokay.info.tr:139.179.139.251:a:259200 .dokay.info.tr:212.175.40.11:b:259200 @dokay.info.tr:212.175.40.55:a::86400 +mail.dokay.info.tr:212.175.40.11:86400 +www.dokay.info.tr:139.179.139.251:86400 +www-tr.dokay.info.tr:139.179.139.251:86400 +www-en.dokay.info.tr:139.179.139.251:86400 .hasankazdagli.com:139.179.139.251:a:259200 .hasankazdagli.com:212.175.40.11:b:259200 @hasankazdagli.com:212.175.40.55:a::86400 +www.hasankazdagli.com:212.175.40.11:86400 +mail.hasankazdagli.com:212.175.40.11:86400 .par.com.tr:139.179.139.251:a:259200 .par.com.tr:212.175.40.11:b:259200 @par.com.tr:89.106.12.72:a::86400 +www.par.com.tr:89.106.12.109:86400 +mail.par.com.tr:89.106.12.72:86400 .itir.net:139.179.139.251:a:259200 .itir.net:212.175.40.11:b:259200 @itir.net:212.175.40.11:a::86400 +www.itir.net:212.175.40.11:86400 +mail.itir.net:212.175.40.11:86400 +webmail.core.gen.tr:212.175.40.12:86400 .toppareresearch.com:139.179.139.251:a:259200 .toppareresearch.com:212.175.40.11:b:259200 @toppareresearch.com:212.175.40.11:a::86400 +www.toppareresearch.com:139.179.139.251:86400 +mail.toppareresearch.com:212.175.40.11:86400 .turkiyelizbongundemi.org:139.179.139.251:a:259200 .turkiyelizbongundemi.org:212.175.40.11:b:259200 @turkiyelizbongundemi.org:212.175.40.11:a::86400 +www.turkiyelizbongundemi.org:212.175.40.11:86400 +www-en.turkiyelizbongundemi.org:212.175.40.11:86400 +www-tr.turkiyelizbongundemi.org:212.175.40.11:86400 +mail.turkiyelizbongundemi.org:212.175.40.11:86400 .meditate-eu.org:139.179.139.251:a:259200 .meditate-eu.org:212.175.40.11:b:259200 @meditate-eu.org:212.175.40.11:a::86400 +www.meditate-eu.org:139.179.139.251:86400 +mail.meditate-eu.org:212.175.40.11:86400 .turital.com:139.179.139.251:a:259200 .turital.com:212.175.40.11:b:259200 @turital.com:89.106.12.82:a::86400 +www.turital.com:139.179.139.251:86400 +mail.turital.com:89.106.12.82:86400 .italygas.com:139.179.139.251:a:259200 .italygas.com:212.175.40.11:b:259200 @italygas.com:84.51.26.206:a::86400 +www.italygas.com:139.179.139.25:86400 +mail.italygas.com:84.51.26.206:86400 ") (defparameter *name-server* (make-instance 'name-server)) (describe *name-server*) (start *name-server*) (status *name-server*) (stop *name-server*) (find-domain-records *name-server* "core.gen.tr") (name-server.refresh *name-server*) (add-ns *name-server* "ns1.core.gen.tr" "1.2.3.4") (add-mx *name-server* "mx.core.gen.tr" "1.2.3.5")
7,906
Common Lisp
.lisp
196
39.30102
82
0.779104
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
02b6ceec67690fe221080f715146752a877fb10a2d195b68b0506d55f6621935
8,394
[ -1 ]
8,395
class+.lisp
evrim_core-server/t/class+.lisp
(in-package :core-server.test) (deftest class+0 (cdr (multiple-value-list (class+.register (class+ 'classX '() '((slotX :host local)) '((:default-initargs :slotX 1) (:documentation "doc") (:ctor (&optional slotX)) (:metaclass moo)))))) (((slotx :accessor classx.slotx :initarg :slotx :initform 1)) ((:default-initargs :slotx 1) (:documentation "doc") (:metaclass moo)))) (defclass+ classA () ((slotA1 :host local :initform 'slotA1) (slotA2 :host local)) (:default-initargs :slotA1 'zoo) (:ctor (slotA1 &rest slotA2))) (deftest class+1 (not (null (find-class+ 'classA))) t) (deftest class+2 (class+.slots (find-class+ 'classA)) ((slotA1 :client-type primitive :accessor classa.slota1 :initarg :slota1 :host local :initform 'zoo) (slotA2 :client-type primitive :accessor classa.slota2 :initarg :slota2 :initform nil :host local))) (deftest class+3 (class+.default-initargs (find-class+ 'classA)) (:slotA1 'zoo)) (deftest class+4 (fboundp 'classA) t) (deftest class+5 (let ((class+ (classA 'slotA1X 'slotA21 'slotA22))) (list (classa.slotA1 class+) (classa.slotA2 class+))) (slotA1X (slotA21 slotA22))) (deftest class+6 (let ((class+ (make-instance 'classA))) (list (classa.slotA1 class+) (classa.slotA2 class+))) (zoo nil)) (defclass+ classB (classA) ((slotB1 :host local) (slotB2 :host remote)) (:default-initargs :slotB1 'slotB1 :slotA1 'slotA1-overriden-by-B)) (deftest class+7 (class+.slots (find-class+ 'classB)) ((slotB1 :client-type primitive :accessor classb.slotb1 :initarg :slotb1 :initform 'slotb1 :host local) (slotB2 :client-type primitive :accessor classb.slotb2 :initarg :slotb2 :initform nil :host remote) (slotA1 :client-type primitive :accessor classa.slota1 :initarg :slota1 :host local :initform 'slotA1-overriden-by-B) (slotA2 :client-type primitive :accessor classa.slota2 :initarg :slota2 :initform nil :host local))) (defclass+ classC (classB) ((slotC1 :host local) (slotC2 :host remote))) (deftest class+8 (class+.local-slots (find-class+ 'classc)) ((slotc1 :client-type primitive :accessor classc.slotc1 :initarg :slotc1 :initform nil :host local) (slotb1 :client-type primitive :accessor classb.slotb1 :initarg :slotb1 :initform 'slotb1 :host local) (slota1 :client-type primitive :accessor classa.slota1 :initarg :slota1 :host local :initform 'slota1-overriden-by-b) (slota2 :client-type primitive :accessor classa.slota2 :initarg :slota2 :initform nil :host local))) (deftest class+9 (class+.remote-slots (find-class+ 'classc)) ((slotc2 :client-type primitive :accessor classc.slotc2 :initarg :slotc2 :initform nil :host remote) (slotb2 :client-type primitive :accessor classb.slotb2 :initarg :slotb2 :initform nil :host remote)))
2,844
Common Lisp
.lisp
64
40.53125
120
0.707264
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
5b710395bd94a2d93b4d9c24911f29148a5facc76edcb9e914886a1e195db0ce
8,395
[ -1 ]
8,396
xml.lisp
evrim_core-server/t/xml.lisp
(in-package :tr.gen.core.server.test) ;; http://www.oasis-open.org/committees/xml-conformance/suite-v1se/xmlconf-20010315.htm ;; test types are :valid :invalid :not-wf (defun parse-xml (error "Not implemented yet!")) (defun file-contents (pathname) (with-open-file (stream pathname) (let ((seq (make-array (file-length stream) :element-type 'character :fill-pointer t))) (setf (fill-pointer seq) (read-sequence seq stream)) seq)))
459
Common Lisp
.lisp
10
42.1
92
0.713004
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
24601453b3058b3a2b6b444f7166c673c858c69950c8bd67d523ef681148ab5c
8,396
[ -1 ]
8,397
call-cc.lisp
evrim_core-server/t/call-cc.lisp
(in-package :core-server.test) (defvar +special-var+ t) (defun/cc handle-special (arg) (list arg +special-var+)) (deftest call/cc-1 (with-call/cc (handle-special 1)) (1 t)) (deftest call/cc-2 (with-call/cc +special-var+) t) (deftest call/cc-3 (with-call/cc (let ((+special-var+ 1)) (handle-special 2))) (2 1)) (defun/cc override-special (arg) (let ((+special-var+ 3)) (list arg +special-var+))) (deftest call/cc-4 (with-call/cc (override-special 1)) (1 3))
524
Common Lisp
.lisp
24
18.041667
32
0.625255
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
ff1ae4ea6dd1aad40847737bbd9fd5c255d640c159698a07710de6c305c09117
8,397
[ -1 ]
8,398
logger.lisp
evrim_core-server/t/logger.lisp
(in-package :core-server) (defparameter *logger* (make-instance 'logger-server)) (defclass my-worker (local-unit) ((id :accessor id :initarg :id))) (defmethod/unit logmeup :async-no-return ((self my-worker)) (log-me *logger* (format nil "I'm here as number ~D" (id self)))) (defparameter *loggerz* (loop for i from 1 to 40 collect (make-instance 'my-worker :id i))) (defun setup-loggerz () (start *logger*) (mapcar #'start *loggerz*) (mapcar #'logmeup *loggerz*) (mapcar #'stop *loggerz*) (sleep 5) (stop *logger*))
548
Common Lisp
.lisp
16
31.25
67
0.67803
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
4ea203c159303c7209363e241aea46f646a66aed9535a53c4102e20bff194a42
8,398
[ -1 ]
8,399
parser.lisp
evrim_core-server/t/parser.lisp
(in-package :tr.gen.core.server.test) (deftest-parser crlf? core-server::crlf? (format nil "~%") t) (deftest-parser lwsp? core-server::lwsp? (format nil "~t") t) (deftest-parser hex-value? core-server::hex-value? "FA" 250) (deftest-parser escaped? core-server::escaped? "%fa" 250) (deftest-parser digit-value? core-server::digit-value? "4" 4) (deftest-parser fixnum? core-server::fixnum? "424142" 424142) (deftest-parser version? core-server::version? "1.2.3.4" '(1 2 3 4)) (deftest-parser quoted? core-server::quoted? "\"Here we go\"" "Here we go") (deftest-render char! core-server::char! #\A "A") (deftest-render string! core-server::string! "Hello, world!" "Hello, world!") (deftest-render fixnum! core-server::fixnum! 343 "343") (deftest-render quoted! core-server::quoted! "Hello, world!" "\"Hello, world!\"") (deftest-render quoted-fixnum! core-server::quoted-fixnum! 343 "\"343\"")
892
Common Lisp
.lisp
14
62.571429
81
0.710046
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
cf8cae9c5acb79b454c71fe3171049d6365f1592f1d873f9a8114cf041001b3d
8,399
[ -1 ]
8,400
javascript.lisp
evrim_core-server/t/javascript.lisp
(in-package :core-server.test) (defmacro test-js (name statement result) `(deftest ,(intern (format nil "JS-~A" name)) (core-server::js ,statement) ,result)) (test-js evrim-1 (unless (blorg.is-correct) (alert "gee")) "if (!blorg.isCorrect()) { alert('gee'); }") (test-js evrim-2 (when (blorg.is-correct) (carry-on) (return i)) "if (blorg.isCorrect()) { carryOn(); return i; }") (test-js evrim-3 (if (blorg.is-correct) (carry-on) (return i)) "if (blorg.isCorrect()) { carryOn(); } else { return i; }") (test-js evrim-4 (+ i (if (blorg.add-one) 1 2)) "i + (blorg.addOne() ? 1 : 2)") (test-js evrim-5 (if (= (typeof blorg) *string) (alert (+ "blorg is a string: " blorg)) (alert "blorg is not a string")) "if (typeof blorg == String) { alert('blorg is a string: ' + blorg); } else { alert('blorg is not a string'); }") (test-js evrim-6 (* 3 5 (+ 1 2)) "3 * 5 * (1 + 2)") (test-js symbol-conversion-1 !?#@% "bangwhathashatpercent") (test-js symbol-conversion-2 bla-foo-bar "blaFooBar") (test-js symbol-conversion-3 *array "Array") (test-js symbol-conversion-4 *global-array* "GLOBALARRAY") (test-js symbol-conversion-5 *global-array*.length "GLOBALARRAY.length") (test-js number-literals-1 1 "1") (test-js number-literals-2 123.123 "123.123") (test-js number-literals-3 #x10 "16") (test-js string-literals-1 "foobar" "'foobar'") (test-js string-literals-2 "bratzel bub" "'bratzel bub'") (test-js operator-expressions-1 (* 1 2 3) "1 * 2 * 3") (test-js operator-expressions-2 (= 1 2) "1 == 2") (test-js operator-expressions-3 (eql 1 2) "1 === 2") (test-js operator-expressions-5 (* 1 (+ 2 3 4) 4 (/ 6 7)) "1 * (2 + 3 + 4) * 4 * (6 / 7)") (test-js operator-expressions-8 (incf i) "++i") (test-js operator-expressions-9 (decf i) "--i") ;; (test-js operator-expressions-6 ;; (++ i) ;; "i++") ;; (test-js operator-expressions-7 ;; (-- i) ;; "i--") ;; (test-js operator-expressions-10 ;; (1- i) ;; "i - 1") ;; (test-js operator-expressions-11 ;; (1+ i) ;; "i + 1") (test-js operator-expressions-12 (not (< i 2)) "!(i < 2)") (test-js operator-expressions-13 (not (eql i 2)) "!(i === 2)") (test-js literal-symbols-1 T "true") ;; (test-js literal-symbols-2 ;; FALSE ;; "false") (test-js literal-symbols-3 NIL "null") ;; (test-js literal-symbols-4 ;; UNDEFINED ;; "undefined") ;; (test-js literal-symbols-5 ;; THIS ;; "this") (test-js variables-1 variable "variable") (test-js variables-2 a-variable "aVariable") (test-js variables-3 *math "Math") (test-js variables-4 *math.floor "Math.floor") (test-js assignment-1 (setq a 1) "a = 1") ;; complete, no optimization though. (test-js assignment-2 (setf a 2 b 3 c 4 x (+ a b c)) "a = 2; b = 3; c = 4; x = a + b + c;") (test-js assignment-3 (setq a (1+ a)) "a = a + 1") (test-js assignment-4 (setq a (+ a 2 3 4 a)) "a = a + 2 + 3 + 4 + a") (test-js assignment-5 (setq a (- 1 a)) "a = 1 - a") (test-js single-argument-statements-1 (return 1) "return 1") (test-js single-argument-expression-2 (if (= (typeof blorg) *string) (alert (+ "blorg is a string: " blorg)) (alert "blorg is not a string")) "if (typeof blorg == String) { alert('blorg is a string: ' + blorg); } else { alert('blorg is not a string'); }") (test-js conditional-statements-2 (+ i (if (blorg.add-one) 1 2)) "i + (blorg.addOne() ? 1 : 2)") (test-js conditional-statements-3 (when (blorg.is-correct) (carry-on) (return i)) "if (blorg.isCorrect()) { carryOn(); return i; }") (test-js conditional-statements-4 (unless (blorg.is-correct) (alert "blorg is not correct!")) "if (!blorg.isCorrect()) { alert('blorg is not correct!'); }") (test-js conditional-statements-5 (cond ((eq a 1) (log-me 'gee)) (t (log-me 'zee))) "if(a === 1) { logMe(gee); } else { logMe(zee); }") (test-js function-definition-2 (lambda (a b) (return (+ a b))) "function (a, b) { return a + b; }") (test-js conditional-statements-1 (if (blorg.is-correct) (progn (carry-on) (return i)) (alert "blorg is not correct!")) "if (blorg.isCorrect()) { carryOn(); return i; } else { alert('blorg is not correct!'); }") (test-js variable-declaration-3 (if (= i 1) (let ((blorg "hallo")) (alert blorg)) (let ((blorg "blitzel")) (alert blorg))) "if (i == 1) { var blorg = 'hallo'; alert(blorg); } else { var blorg = 'blitzel'; alert(blorg); }") ;; if sorunlu (test-js variable-declaration-2 (if (= i 1) (progn (defvar blorg "hallo") (alert blorg)) (progn (defvar blorg "blitzel") (alert blorg))) "if (i == 1) { var blorg = 'hallo'; alert(blorg); } else { var blorg = 'blitzel'; alert(blorg); }") (test-js iteration-constructs-5 (while (film.is-not-finished) (this.eat (new (*popcorn)))) "while (film.isNotFinished()) { this.eat(new Popcorn()); }") (test-js regular-expression-literals-2 (regex "/foobar/i") "/foobar/i") (test-js function-calls-and-method-calls-1 (blorg 1 2) "blorg(1, 2)") (test-js object-literals-4 an-object.foo "anObject.foo") ;; can't happen in lisp2 ;; (test-js function-calls-and-method-calls-3 ;; ((aref foo i) 1 2) ;; "foo[i](1, 2)") (test-js variable-declaration-1 (defvar *a* (array 1 2 3)) "var A = [ 1, 2, 3 ]") (test-js statements-and-expressions-1 (+ i (if 1 2 3)) "i + (1 ? 2 : 3)") (test-js statements-and-expressions-2 (if 1 2 3) "if (1) { 2; } else { 3; }") (test-js array-literals-1 (array) "[ ]") (test-js array-literals-2 (array 1 2 3) "[ 1, 2, 3 ]") (test-js body-forms-1 (progn (blorg i) (blafoo i)) "blorg(i); blafoo(i);") (test-js body-forms-2 (+ i (progn (blorg i) (blafoo i))) "i + (blorg(i), blafoo(i))") (test-js function-calls-and-method-calls-2 (foobar (blorg 1 2) (blabla 3 4) (array 2 3 4)) "foobar(blorg(1, 2), blabla(3, 4), [ 2, 3, 4 ])") (test-js object-literals-1 (create :foo "bar" :blorg 1) "{ foo: 'bar', blorg: 1 }") (test-js object-literals-2 (create :foo "hihi" :blorg (array 1 2 3) :another-object (create :schtrunz 1)) "{ foo: 'hihi', blorg: [ 1, 2, 3 ], anotherObject: { schtrunz: 1 } }") (test-js single-argument-expression-1 (delete (new (*foobar 2 3 4))) "delete new Foobar(2, 3, 4)") (test-js array-literals-4 (make-array) "new Array()") (test-js array-literals-5 (make-array 1 2 3) "new Array(1, 2, 3)") (test-js array-literals-6 (make-array (make-array 2 3) (make-array "foobar" "bratzel bub")) "new Array(new Array(2, 3), new Array('foobar', 'bratzel bub'))") (test-js single-argument-statements-2 (throw "foobar") "throw 'foobar'") (test-js object-literals-3 (slot-value an-object 'foo) "anObject.foo") (test-js the-with-statement-1 (with (create :foo "foo" :i "i") (alert (+ "i is now intermediary scoped: " i)) (alert "zoo")) "with ({ foo: 'foo', i: 'i' }) { alert('i is now intermediary scoped: ' + i); alert('zoo'); }") (test-js iteration-constructs-4 (doeach (i object) (document.write (+ i " is " (aref object i)))) "for (var i in object) { document.write(i + ' is ' + object[i]); }") (test-js iteration-constructs-2 (dotimes (i blorg.length) (document.write (+ "L is " (aref blorg i))) (alert "zoo")) "for (var i = 0; i < blorg.length; i = i + 1) { document.write('L is ' + blorg[i]); alert('zoo'); }") ;; Could not test dolist since i consists tmp vars. ;; (test-js iteration-constructs-3 ;; (dolist (l blorg) ;; (document.write (+ "L is " l)) ;; (alert "zoo")) ;; "for (var l = 0; l < blorg.length; l = l + 1) { ;; document.write('L is ' + l); ;; alert('zoo'); ;; }" ;; ;;; "{ ;; ;;; var tmpArr1 = blorg; ;; ;;; for (var tmpI2 = 0; tmpI2 < tmpArr1.length; ;; ;;; tmpI2 = tmpI2 + 1) { ;; ;;; var l = tmpArr1[tmpI2]; ;; ;;; document.write('L is ' + l); ;; ;;; }; ;; ;;; }" ;; ) (test-js iteration-constructs-4 (do ((i 0 (+ 1 i))) ((> i 5) i) (print i)) "for (var i=0; !(i > 5); i=1 + i) { print(i); }") (test-js slot-val-1 (slot-value a "abc") "a['abc']") (test-js slot-val-2 (slot-value a 'abc) "a.abc") (test-js slot-val-3 (slot-value a abc) "a[abc]") (test-js the-try-statement-1 (try (throw "i") (:catch (error) (alert (+ "an error happened: " error))) (:finally (alert "Leaving the try form"))) "try { throw 'i' } catch (error) { alert('an error happened: ' + error); } finally { alert('Leaving the try form'); }") (test-js regular-expression-literals-1 (regex "/foobar/") "/foobar/") (test-js function-definition-1 (defun a-function (a b) (return (+ a b))) "function aFunction(a, b) { return a + b; }") (test-js function-calls-and-method-calls-6 (.blorg (aref foobar 1) NIL T) "foobar[1].blorg(null, true)") (test-js function-calls-and-method-calls-4 (.blorg this 1 2) "this.blorg(1, 2)") (test-js function-calls-and-method-calls-5 (this.blorg 1 2) "this.blorg(1, 2)") (test-js iteration-constructs-1 (do ((i 0 (1+ i)) (l (aref blorg i) (aref blorg i))) ((or (= i blorg.length) (eql l "Fumitastic"))) (document.write (+ "L is " l))) "for (var i=0, l=blorg[i]; !((i == blorg.length) || (l === 'Fumitastic')); i=i + 1, l=blorg[i]) { document.write('L is ' + l); }") (test-js the-case-statement-2 (switch (aref blorg i) (1 (alert "If I get here")) (2 (alert "I also get here")) (default (alert "I always get here"))) "switch (blorg[i]) { case 1: alert('If I get here'); case 2: alert('I also get here'); default: alert('I always get here'); }") (test-js the-case-statement-1 (case (aref blorg i) ((1 "one") (alert "one")) (2 (alert "two")) (t (alert "default clause"))) "switch (blorg[i]) { case 1: case 'one': alert('one'); break; case 2: alert('two'); break; default: alert('default clause'); }") (test-js object-literals-5 (with-slots (a b c) this (+ a b c)) "var a = this.a; var b = this.b; var c = this.c; a + b + c") ;; "this.a + this.b + this.c;" (test-js array-literals-3 (array (array 2 3) (array "foobar" "bratzel bub")) "[ [ 2, 3 ], [ 'foobar', 'bratzel bub' ] ]") ;; Speed Results ;; Case 1: With Core Server Renderer as Indented ;; SERVER> (let ((s (make-indented-stream "" 2))) ;; (time ;; (dotimes (i 10000) ;; (dojo s)))) ;; Evaluation took: ;; 41.749 seconds of real time ;; 41.870616 seconds of total run time (41.174573 user, 0.696043 system) ;; [ Run times consist of 3.480 seconds GC time, and 38.391 seconds non-GC time. ] ;; 100.29% CPU ;; 100,205,266,725 processor cycles ;; 1 page fault <- ???? ;; 4,602,467,504 bytes consed ;; NIL ;; Case 2: With Parenscript Indented ;; SERVER> (time ;; (dotimes (i 10000) ;; (dojo-old))) ;; Evaluation took: ;; 56.669 seconds of real time ;; 56.555535 seconds of total run time (55.123445 user, 1.432090 system) ;; [ Run times consist of 6.396 seconds GC time, and 50.160 seconds non-GC time. ] ;; 99.80% CPU ;; 136,017,920,106 processor cycles ;; 9,494,900,816 bytes consed ;; NIL ;; Case 3: Core Streams Overhead With Parenscript ;; SERVER> (let ((s (make-core-stream ""))) ;; (time ;; (dotimes (i 10000) ;; (string! s (dojo-old))))) ;; Evaluation took: ;; 68.424 seconds of real time ;; 68.764297 seconds of total run time (67.336208 user, 1.428089 system) ;; [ Run times consist of 7.472 seconds GC time, and 61.293 seconds non-GC time. ] ;; 100.50% CPU ;; 164,231,866,818 processor cycles ;; 9,688,441,856 bytes consed ;; NIL ;; Case 4: Stream Overhead with Cached Response ;; SERVER> (defvar *g (dojo-old)) ;; *G ;; SERVER> (let ((s (make-core-stream ""))) ;; (time ;; (dotimes (i 10000) ;; (string! s *g)))) ;; Evaluation took: ;; 11.012 seconds of real time ;; 11.016689 seconds of total run time (10.952685 user, 0.064004 system) ;; [ Run times consist of 0.072 seconds GC time, and 10.945 seconds non-GC time. ] ;; 100.05% CPU ;; 26,430,148,782 processor cycles ;; 175,730,464 bytes consed ;; NIL ;; Case 5: Compressed Renderer without indentation ;; SERVER> (let ((s (make-compressed-stream ""))) ;; (time ;; (dotimes (i 10000) ;; (dojo s)))) ;; Evaluation took: ;; 36.728 seconds of real time ;; 36.946308 seconds of total run time (36.330270 user, 0.616038 system) ;; [ Run times consist of 2.340 seconds GC time, and 34.607 seconds non-GC time. ] ;; 100.59% CPU ;; 88,156,341,468 processor cycles ;; 4,240,289,552 bytes consed ;; NIL ;; Case 6: After aggressive optimization (optimize-render-1) ;; SERVER> (let ((s (make-indented-stream "" 2))) ;; (time ;; (dotimes (i 10000) ;; (dojo s)))) ;; Evaluation took: ;; 40.387 seconds of real time ;; 40.546534 seconds of total run time (39.778486 user, 0.768048 system) ;; [ Run times consist of 3.896 seconds GC time, and 36.651 seconds non-GC time. ] ;; 100.40% CPU ;; 96,936,993,369 processor cycles ;; 4,381,989,984 bytes consed ;; NIL ;; Case 7: After aggressive optimization (optimize-render-1) ;; SERVER> (let ((s (make-compressed-stream ""))) ;; (time ;; (dotimes (i 10000) ;; (dojo s)))) ;; Evaluation took: ;; 36.379 seconds of real time ;; 36.046253 seconds of total run time (35.602225 user, 0.444028 system) ;; [ Run times consist of 3.641 seconds GC time, and 32.406 seconds non-GC time. ] ;; 99.08% CPU ;; 87,315,012,855 processor cycles ;; 4,019,826,784 bytes consed ;; NIL ;; (defrender/js moo (&optional base-url (debug nil) (back 'false)) ;; (list base-url debug back) ;; (lambda () ;; (list 1 2 3))) ;; (defun/javascript fun1 (a) ;; (let ((b (lambda (b c) ;; (list b c)))) ;; (return (b)))) ;; (defmacro defun/parenscript (name params &body body) ;; `(prog1 ;; (defun ,name ,params ,@body) ;; (defun ,(intern (string-upcase (format nil "~A!" name))) (s) ;; (write-stream s ;; ,(js:js* `(lambda ,params ;; ,@body)))))) ;; (defun/parenscript fun2 (a) ;; (let ((a (lambda (a b c) ;; (list a b c)))) ;; (return a))) ;; (js+ ;; (+ 1 1) ;; (+ 2 2)) ;; (defun <:js (&rest body) ;; "Convert body to javascript and return it as a string, this is an ucw+ ;; backward compatiblity macro, and should not be used." ;; (with-unique-names (output) ;; (eval ;; `(let ((,output (if +context+ ;; (http-response.stream (response +context+)) ;; *core-output*))) ;; (funcall (lambda () ;; (block rule-block ;; ,(expand-render ;; (walk-grammar ;; `(:and ,@(mapcar (rcurry #'expand-javascript #'expand-javascript) ;; (mapcar #'walk-form-no-expand body)) ;; #\Newline)) ;; #'expand-render output) ;; nil)))))))
14,983
Common Lisp
.lisp
590
22.977966
99
0.60605
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
e4d7966e5ff8643b33e01dd0da080e28d77d0d4d5a68261486149ae39c7a55b5
8,400
[ -1 ]
8,401
webcrud.lisp
evrim_core-server/t/webcrud.lisp
(in-package :core-server.test) ;; ;; ------------------------------------------------------------------------- ;; ;; Manager Users Table ;; ;; ------------------------------------------------------------------------- ;; (deftable manager-users-table () ;; ((name :label "Name") ;; (username :label "Username") ;; (creation-timestamp :label "Creation Timestamp" :remote-type timestamp))) ;; ;; ------------------------------------------------------------------------- ;; ;; Manager Users Crud ;; ;; ------------------------------------------------------------------------- ;; (defwebcrud manager-user-crud () ;; ((name :label "Name") ;; (username :label "Username" :read-only t) ;; (password :label "Password" :remote-type password) ;; (creation-timestamp :label "Creation Timestamp" :remote-type date ;; timestamp ;; ) ;; (select-text :label "Select Text" :options '("Text1" "Text2") ;; :remote-type select) ;; (multiselect-text :label "MultiSelect Text" :options '("Text1" "Text2") ;; :remote-type multiple-select) ;; (multicheckbox-text :label "MultiCheckbox" :options '("Text1" "Text2") ;; :remote-type multiple-checkbox) ;; (number-value :label "A Number" :remote-type number) ;; (email-value :label "Email" :remote-type email) ;; (html-value :label "HTML Value" :remote-type html)) ;; (:default-initargs :title "Administrative Account" :editable-p t :deletable-p t)) ;; ;; ------------------------------------------------------------------------- ;; ;; Sites Component ;; ;; ------------------------------------------------------------------------- ;; (defcomponent manager-users-component (<core:table-with-crud <widget:simple-widget) ;; () ;; (:default-initargs :table (manager-users-table) :crud (manager-user-crud) ;; :input-element (<core:required-value-input ;; :default-value "Enter username (ie root)") ;; :table-title "Users")) ;; (defmethod/local get-instances ((self manager-users-component)) ;; (manager-user.list application)) ;; (defmethod/local add-instance ((self manager-users-component) username) ;; (manager-user.add application :username username)) ;; (defmethod/local delete-instance ((self manager-users-component) username) ;; (aif (manager-user.find application :username username) ;; (prog1 t (manager-user.delete application it)))) ;; (defmethod/local update-instance ((self manager-users-component) ;; (user manager-user) updates) ;; (prog1 updates ;; (apply #'manager-user.update application (cons user (jobject.attributes updates)))))
2,598
Common Lisp
.lisp
47
54.042553
91
0.556211
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
8eed6c3257c2ab976cf27c0bf8e8ca3d25e49c49954ba62f66eb6bd0b4e32d70
8,401
[ -1 ]
8,402
postfix.lisp
evrim_core-server/t/postfix.lisp
(in-package :core-server.test) ;; (def-suite postfix :in :core-server) ;; (in-suite postfix) (defparameter *postfix* (make-instance 'postfix-server :virtual-mailbox-maps (make-pathname :directory '(:absolute "tmp") :name "vmailbox"))) ;; (test me ;; (is (eq t t))) ;; (describe *m*) ;; (start *m*) ;; (status *m*) ;; (stop *m*) ;; (add-email *m* "[email protected]" "/home/aycan/eposta/") ;; (del-email *m* "[email protected]")
441
Common Lisp
.lisp
14
29.714286
89
0.64133
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
9badc3260d6aaeb6ebcf55ea5a990ae9bd5f9de54d9d21796b98bda5d4c08dc6
8,402
[ -1 ]
8,403
component.lisp
evrim_core-server/t/component.lisp
(in-package :core-server.test) (defun test-component-ctor (class) (let ((s (make-indented-stream (make-core-stream "")))) (with-call/cc (ctor! s (make-instance class))) (return-stream s))) ;; (defcomponent componentA () ;; ()) ;; (deftest component0 (not (null (find-class+ 'componentA))) ;; t) ;; (deftest component1 (mapcar #'class+.name (class+.superclasses (find-class+ 'componentA))) ;; (component componentA)) ;; (deftest component2 (test-component-ctor 'componentA) ;; "componenta = function () { ;; this.prototype = {}; ;; return this.prototype; ;; };") ;; (defcomponent componentB (componentA) ;; ((slotA) ;; (slotB :host remote :initform (list 1 2 3)))) ;; (deftest component3 (test-component-ctor 'componentB) ;; "componentb = function (slotb) { ;; this.prototype = { ;; slotb: ('undefined' == typeof slotb ? [ 1 , 2 , 3 ] : slotb), ;; getSlotb: function () { ;; return this.slotb; ;; }, ;; setSlotb: function (value) { ;; return this.slotb = value; ;; } ;; }; ;; return this.prototype; ;; };") ;; (defcomponent componentC (componentB) ;; ((slotC :host local :initform 1))) ;; (deftest component4 (test-component-ctor 'componentC) ;; "componentc = function (slotb) { ;; this.prototype = { ;; slotb: ('undefined' == typeof slotb ? null : slotb), ;; getSlotc: function () { ;; return funcall(\"?s:invalid-session-id$k:invalid-function-hash\", {}); ;; }, ;; setSlotc: function (value) { ;; return funcall(\"?s:invalid-session-id$k:invalid-function-hash\", { ;; value: value ;; }); ;; }, ;; getSlotb: function () { ;; return this.slotb; ;; }, ;; setSlotb: function (value) { ;; return this.slotb = value; ;; } ;; }; ;; return this.prototype; ;; };") ;; (defcomponent componentD () ;; ()) ;; (defmethod/remote componentD.remote-method ((self componentD) a b c) ;; (list a b c)) ;; (deftest component5 (test-component-ctor 'componentD) ;; "componentd = function () { ;; this.prototype = { ;; componentd.remoteMethod: function (a, b, c) { ;; return new Array(a, b, c); ;; } ;; }; ;; return this.prototype; ;; };") ;; (defcomponent componentE () ;; ()) ;; (defmethod/local componentE.local-method ((self componentE) a b c) ;; (list a b c)) ;; (deftest component6 (test-component-ctor 'componentE) ;; "componente = function () { ;; this.prototype = { ;; componente.localMethod: function (a, b, c) { ;; return funcall(\"?s:invalid-session-id$k:invalid-function-hash\", { ;; a: a, ;; b: b, ;; c: c ;; }); ;; } ;; }; ;; return this.prototype; ;; };") ;; (eval-always ;; (defclass test-application (http-application) ;; ()) ;; (when (boundp '*app1*) ;; (unregister core-server::*server* *app1*)) ;; (defparameter *app1* ;; (make-instance 'test-application ;; :fqdn "test" ;; :admin-email "[email protected]")) ;; (register core-server::*server* *app1*)) ;; (defcomponent test-component () ;; ((local-slot :host local :client-type array) ;; (remote-slot :host remote :initform (list "value0" "value1" "value2") :client-type array)) ;; (:default-initargs :local-slot nil)) ;; (defmethod/local local-method ((self test-component) local-arg1) ;; (list "local-method-result" local-arg1)) ;; (defmethod/remote remote-method ((self test-component) remote-arg1) ;; (return (list "remote-method-result" remote-arg1))) ;; (defurl *app1* "test.core" () ;; (send/suspend ;; (<:html ;; (<:head ;; (<:script :src "/dojo/dojo/dojo.js" :type "text/javascript") ;; (<:script :type "text/javascript" ;; (dojo-1.0 "test.core") ;; (send/component (make-instance 'test-component ;; :local-slot (list 1 2 3))))) ;; (<:body ;; (<:div :id "hobaa" ;; (<:script :type "text/javascript" ;; (<:js ;; `(progn ;; (dojo.add-on-load ;; (lambda () ;; (debug "Starting.." this) ;; (let ((component (new (test-component)))) ;; (debug (+ "Result of local-method:" (component.local-method "local-method-arg1"))) ;; (debug (+ "Result of remote-method:" (component.remote-method "remote-method-arg1")))))))))))))) ;; (defcomponent test1 () ;; ()) ;; (defmethod/local test1-local-method ((self test1) arg) ;; (list arg)) ;; (defmethod/remote test1-remote-method ((self test1) arg) ;; (list arg)) ;; (defcomponent-ctor test1) ;; SERVER> (with-test-context (+context+ "blog" blog::*app*) ;; (with-call/cc ;; (ctor! *core-output* (make-instance 'test1)))) ;; TEST1-LOCAL-METHOD is ;; an internal symbol ;; in #<PACKAGE "TR.GEN.CORE.SERVER">. ;; #<STANDARD-GENERIC-FUNCTION TEST1-LOCAL-METHOD (1)> is a generic function. ;; Its lambda-list is: ;; (SELF ARG) ;; Its method-combination is: ;; #<SB-PCL::LONG-METHOD-COMBINATION IT.BESE.ARNESI::CC-STANDARD NIL {1005292A21}> ;; Its methods are: ;; (TEST1-LOCAL-METHOD :PRIMARY (TEST1 T)) ;; test1 = function () { ;; this.prototype = { ;; test1LocalMethod: function (arg) { ;; return funcall("?s=QrpaIBkJ&k=act-ZpaMVnll"); ;; } ;; }; ;; return this.prototype; ;; };#<CORE-STANDARD-OUTPUT {1003575FB1}>
5,224
Common Lisp
.lisp
152
33.085526
103
0.610307
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
6c1d8ae7bf124c089963da0ce5db78fd29ce465d70aa21ac8b0c39d7b81c53db
8,403
[ -1 ]
8,404
apache.lisp
evrim_core-server/t/apache.lisp
(in-package :core-server.test) (defparameter *apache-server* (make-instance 'apache-server)) (describe *apache-server*) (if (status *apache-server*) (progn (stop *apache-server*) (start *apache-server*) (unless (status *apache-server*) (error "Error occured while starting apache server."))) (progn (start *apache-server*) (unless (status *apache-server*) (error "Error occured while starting apache server.")))) (defparameter *apache-application* (make-instance 'apache-web-application :fqdn "www.test123.com" :admin-email "[email protected]")) (describe *apache-application*) (register *apache-server* *apache-application*) (unregister *apache-server* *apache-application*)
727
Common Lisp
.lisp
20
32.8
61
0.71875
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
84346902dd5d82dc729f5e3dd63371b65438986624200f2d0f6ee09660c30977
8,404
[ -1 ]
8,405
streams.lisp
evrim_core-server/t/streams.lisp
(in-package :tr.gen.core.server.test) (defun trace-core-streams () (trace commit-stream rewind-stream read-stream peek-stream write-stream checkpoint-stream)) (defun untrace-core-streams () (untrace commit-stream rewind-stream read-stream peek-stream write-stream checkpoint-stream)) ;; test basic stream operations with a scenario (deftest string-stream (with-core-stream (s "ABCDEF") (and (equal (peek-stream s) #.(char-code #\A)) (equal (peek-stream s) #.(char-code #\A)) (equal (read-stream s) #.(char-code #\A)) (equal (read-stream s) #.(char-code #\B)) (equal (checkpoint-stream s) 0) ;; first checkpoint (equal (read-stream s) #.(char-code #\C)) (equal (checkpoint-stream s) 1) ;; second checkpoint (equal (read-stream s) #.(char-code #\D)) (equal (rewind-stream s) 1) ;; rewind to second checkpoint (equal (peek-stream s) #.(char-code #\D)) (equal (rewind-stream s) 0) ;; rewind to first checkpoint (equal (peek-stream s) #.(char-code #\C)) (equal (checkpoint-stream s) 0) ;; first checkpoint (equal (read-stream s) #.(char-code #\C)) (equal (commit-stream s) 0) ;; discard first checkpoint and resume (equal (read-stream s) #.(char-code #\D)))) t) (deftest init-file-test (let ((file-data "ABCDEFGHIJKL") (file-name (format nil "/tmp/~A" (symbol-name (gensym "stream-test-"))))) (write-string-to-file file-data file-name :if-exists :supersede :if-does-not-exist :create) (and (equal file-data (read-string-from-file file-name)) (let ((s (make-core-stream (pathname file-name)))) (and (equal (checkpoint-stream s) 0) (equal (read-stream s) #.(char-code #\A)) (equal (rewind-stream s) 0) (equal (read-stream s) #.(char-code #\A)) (equal (checkpoint-stream s) 0) (equal (checkpoint-stream s) 1) (equal (read-stream s) #.(char-code #\B)) (equal (rewind-stream s) 1) (equal (read-stream s) #.(char-code #\B)) (equal (rewind-stream s) 0) (equal (read-stream s) #.(char-code #\B)))))) t) (deftest list-stream-test (let ((s (make-core-stream '(1 (2 3) (4 5))))) (list (checkpoint-stream s) (read-stream s) (rewind-stream s) (checkpoint-stream s) (read-stream s) (progn (write-stream s 6) (commit-stream s)) (read-stream s) (progn (write-stream s '(7 8)) (return-stream s)))) (0 1 0 0 1 0 (4 5) (1 6 (4 5) (7 8)))) (deftest indented-stream-test (let ((s (make-indented-stream (make-core-stream "")))) (write-stream s #\a) (increase-indent s) (write-stream s #\Newline) (write-stream s #\b) (return-stream s)) "a b") (deftest compressed-stream-test (let ((s (make-compressed-stream (make-core-stream "")))) (write-stream s #\a) (increase-indent s) (write-stream s #\Newline) (write-stream s #\b) (return-stream s)) "ab") ;; (deftest test-cps-stream ;; (with-call/cc ;; (let ((s (core-server::make-core-cps-stream "")) ;; (a 0)) ;; (checkpoint-stream/cc s) ;; (if (zerop a) ;; (progn (setq a 1) (rewind-stream/cc s)) ;; (progn (core-server::string! s "test1") (commit-stream/cc s))) ;; (core-server::return-stream s))) ;; "test1") ;; (defun test-cps-stream () ;; (let* ((ret1 123) ;; (ret0 321) ;; (s (with-call/cc ;; (let ((s (make-instance 'core-cps-stream))) ;; (if (not (eq ret0 (let/cc k ;; (checkpoint-stream/cc s k) ;; (if (not (eq ret1 (let/cc k ;; (checkpoint-stream/cc s k) ;; (describe s) ;; (commit-stream/cc s s)))) ;; (error "failed cps stream") ;; (commit-stream/cc s s))))) ;; (error "failed cps stream") ;; s))))) ;; (describe (with-call/cc (rewind-stream/cc s ret1))) ;; (describe (with-call/cc (rewind-stream/cc s ret0))))) (defclass abc () (gee eeg moo)) ;; SERVER> (with-core-stream (s (make-instance 'standard-object)) ;; (render-object! s) ;; (return-stream s)) ;; #<ABC {10030A8021}> ;; SERVER> (describe *) ;; #<ABC {10030A8021}> is an instance of class #<STANDARD-CLASS ABC>. ;; The following slots have :INSTANCE allocation: ;; GEE 1 ;; EEG 2 ;; MOO 3 (defrender render-object! () (:class! 'abc) (:slot! 'gee 1) (:slot! 'eeg 2) (:slot! 'moo 3)) ;; SERVER> (describe *abc) ;; #<ABC {100520E1C1}> is an instance of class #<STANDARD-CLASS ABC>. ;; The following slots have :INSTANCE allocation: ;; GEE 1 ;; EEG 2 ;; MOO 3 ;; SERVER> (parse-object? (make-core-stream *abc)) ;; (1 2 3) (defparser parse-object? (gee eeg moo) (:slot? 'gee gee) (:slot? 'eeg eeg) (:slot? 'moo moo) (:return (list gee eeg moo)))
4,724
Common Lisp
.lisp
133
32.097744
97
0.605459
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
86c61ae4f7d659de13b49a1963691bf9a09ad8a568ea855b95f0f73163250423
8,405
[ -1 ]
8,406
core.lisp
evrim_core-server/t/core.lisp
(in-package :core-server.test) (defparameter *core-server* (make-instance 'core-server)) (describe *core-server*) (start *core-server*) (setf ucw::*default-server* core-server.test::*core-server*) (defclass my-app2 (ucw-web-application apache-web-application) () (:default-initargs :fqdn "www.myweb.com" :admin-email "[email protected]")) (defparameter *app* (make-instance 'my-app2)) (describe *app*) (register *core-server* *app*) (defparameter *core-web-server* (make-instance 'core-web-server)) (describe *core-web-server*) (start *core-web-server*) (status *core-web-server*) (setf ucw::*default-server* *core-web-server*) (setf *core-server* *core-web-server*)
682
Common Lisp
.lisp
19
34.105263
65
0.730303
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
4b9ed9de4aa0864c8e4c4e5511f3511e15e05e88909a8e14de786a3f6bd1ac25
8,406
[ -1 ]
8,407
threads.lisp
evrim_core-server/t/threads.lisp
(in-package :tr.gen.core.server.test) (defparameter *msg* nil) (deftest thread-messaging (let ((master (thread-spawn #'(lambda () (let* ((message '(1 2.0 "abc")) (self (core-server::current-thread)) (peer (thread-spawn #'(lambda () (thread-send self (thread-receive)))))) (thread-send peer message) (setf *msg* (thread-receive))))))) (sleep 1) (and (listp *msg*) (eq 3 (length *msg*)))) t)
469
Common Lisp
.lisp
14
26.857143
50
0.563877
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
02ec802ad8147004ef29285be5d99cb6ea0aba5d3e49a5736cdfe3bb0bf5b1d4
8,407
[ -1 ]
8,408
jquery.lisp
evrim_core-server/t/jquery.lisp
(in-package :core-server.test) (defpackage :jquery.test (:use :common-lisp :core-server :jquery)) (in-package :jquery.test) (defclass jquery-test-application (database-server apache-web-application http-application) () (:default-initargs :directory #P"/tmp/jquery-test/" :fqdn "jquery" :admin-email "[email protected]" :auto-start t)) (defparameter *app* (make-instance 'jquery-test-application)) (register *server* *app*) (defcomponent jquery-table (jquery) ()) (defurl *app* "index.core" () (<:html (<:head) (<:body (<:))))
573
Common Lisp
.lisp
19
26.684211
91
0.684307
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
5b8a791b94ca92a739003ff765490ffc4550f290798d854fe38ce567a3f6ed3a
8,408
[ -1 ]
8,409
packages.lisp
evrim_core-server/t/packages.lisp
(in-package :cl-user) (defpackage :tr.gen.core.server.test (:nicknames :core-server.test) (:use :common-lisp ;; :cl-prevalence :core-server :arnesi :rt ;; :cl-store :5am :iterate ) (:shadowing-import-from #:arnesi #:name)) ;;(in-package :core-server.test) ;;(def-suite :core-server)
293
Common Lisp
.lisp
10
27.3
43
0.698582
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
9f89dc036bcf8c78af7939657e30b79315ef3af11db3c62c292c12e3e1207016
8,409
[ -1 ]
8,410
2109.lisp
evrim_core-server/t/rfc/2109.lisp
(in-package :tr.gen.core.server.test) (deftest test-cookie-to-stream (let ((cookie-o (make-cookie "neym" "valyu" :version 2 :comment "coment" :domain "domeyn" :max-age 0 :path "/acme" :secure t)) (cookie-s "neym=\"valyu\"; Version=\"2\"; Comment=\"coment\"; Domain=\"domeyn\"; Max-age=\"0\"; Path=\"/acme\"; Secure") (cstream (make-core-stream ""))) ;; write to stream (cookie! cstream cookie-o) ;; read from stream and compare (string= (return-stream cstream) cookie-s)) ;; expected result t) (deftest test-cookie-from-stream (let* ((cstream (make-core-stream "$Version=\"1\"; Customer=\"WILE_E_COYOTE\"; $Path=\"/acme\"; $Domain=\"gee\"; Part_Number=\"Rocket_Launcher_0001\"; $Path=\"/acme\"; Shipping=\"FedEx\"; $Path=/acme;")) (cookies (cookie? cstream))) (and (equal 3 (length cookies)) ;; check some slots (equal (cookie.name (car cookies)) "Customer") (equal (cookie.value (car cookies)) "WILE_E_COYOTE") (equal (cookie.domain (car cookies)) "gee") (equal (cookie.path (caddr cookies)) "/acme"))) t)
1,100
Common Lisp
.lisp
27
36.296296
123
0.627451
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
85f463437a3ebd81b00cae1617978817012399f29646e24752e73b0a72d525b2
8,410
[ -1 ]
8,411
2616.lisp
evrim_core-server/t/rfc/2616.lisp
(in-package :tr.gen.core.server.test) (deftest http-media-range? (with-core-stream (s "text/html; q=0.8; a=test;level=2") (multiple-value-list (core-server::http-media-range? s))) ("text" "html" (("level" . "2") ("a" . "test") ("q" . 0.8)))) ;;; ;;; test request headers ;;; ;; ACCEPT (deftest http-accept? (with-core-stream (s "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5") (http-accept? s)) (("*" "*" (("q" . 0.5))) ("text" "html" (("q" . 0.4) ("level" . "2"))) ("text" "html" (("level" . "1"))) ("text" "html" (("q" . 0.7))) ("text" "*" (("q" . 0.3))))) ;; ACCEPT-CHARSET (deftest http-accept-charset? (with-core-stream (s "iso-8859-5, unicode-1-1;q=0.8") (http-accept-charset? s)) (("iso-8859-5" . 1.0) ("unicode-1-1" . 0.8))) ;; ACCEPT-ENCODING (deftest http-accept-encoding? (with-core-stream (s "gzip;q=1.0, identity; q=0.5, *;q=0") (http-accept-encoding? s)) (("gzip" . 1.0) ("identity" . 0.5) ("*" . 0.0))) ;; ACCEPT-LANGUAGE (deftest http-accept-language? (with-core-stream (s "tr, en-us;q=0.1, en;q=0.7") (http-accept-language? s)) (("tr" . 1.0) ("en-us" . 0.1) ("en" . 0.7))) ;; AUTHORIZATION (deftest http-authorization? (with-core-stream (s "Digest mac=\"asd\", cam=\"dsa\"") (http-authorization? s)) ("Digest" ("cam" . "dsa") ("mac" . "asd"))) ;; EXPECT (deftest http-expect? (with-core-stream (s "asd=asd;q=324") (http-expect? s)) (("asd" . "asd") ("q" . "324"))) (deftest http-expect-100-continue? (with-core-stream (s "100-continue") (http-expect? s)) core-server::100-continue) ;; FROM (deftest http-from? (with-core-stream (s "<[email protected]>") (slot-value (http-from? s) 'core-server::addr)) "[email protected]") (deftest http-host? (with-core-stream (s "www.core.gen.tr:80") (http-host? s)) ("www.core.gen.tr" . 80)) ;; IF-MATCH (deftest http-etag? (and (with-core-stream (s "W/\"testmeup\"") (equal (core-server::http-etag? s) '("testmeup" . t))) (with-core-stream (s "\"testmeup\"") (equal (core-server::http-etag? s) '("testmeup")))) t) (deftest http-if-match? (and (with-core-stream (s "*") (equal (http-if-match? s) '(*))) (with-core-stream (s "W/\"test\"") (equal (http-if-match? s) '(("test" . t)))) (with-core-stream (s "\"test\", W/\"me\", W/\"up\"") (equal (http-if-match? s) '(("test") ("me" . T) ("up" . T))))) t) ;; IF-MODIFIED-SINCE (deftest http-if-modified-since? (with-core-stream (s "Sat, 29 Oct 1994 19:43:31 GMT") (http-if-modified-since? s)) 2992448611) ;; IF-NONE-MATCH (deftest http-if-none-match? (and (with-core-stream (s "*") (equal (http-if-none-match? s) '(*))) (with-core-stream (s "\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\"") (equal (http-if-none-match? s) '(("xyzzy") ("r2d2xxxx") ("c3piozzzz")))) (with-core-stream (s "W/\"test\",W/\"meplease\"") (equal (http-if-none-match? s) '(("test" . t) ("meplease" . t)))) (with-core-stream (s "\"test\", W/\"me\", W/\"up\"") (equal (http-if-none-match? s) '(("test") ("me" . T) ("up" . T))))) t) ;; IF-RANGE (deftest http-if-range? (with-core-stream (s "Tue, 01 Feb 2008 04:20:00 GMT") (http-if-range? s)) 3410828400) (deftest http-if-range2? (with-core-stream (s "W/\"ranger\"") (http-if-range? s)) ("ranger" . t)) ;; IF-UNMODIFIED-SINCE (deftest http-if-unmodified-since (with-core-stream (s "Tue, 01 Feb 2008 04:20:00 GMT") (http-if-unmodified-since? s)) 3410828400) ;; MAX-FORWARDS (deftest http-max-forwards? (with-core-stream (s "414") (equal (http-max-forwards? s) 414)) t) ;; PROXY-AUTHORIZATION (deftest http-proxy-authorization? (with-core-stream (s "digest mac=\"0E:F0:FF:FF:FF:00\", cam=\"foo\"") (equal (http-proxy-authorization? s) '("digest" . ("mac" . "0E:F0:FF:FF:FF:00")))) t) ;; RANGE (deftest http-range? (with-core-stream (s "bytes=300-400,-300,300-") (equal (http-range? s) '("bytes" (300) (NIL . 300) (300 . 400)))) t) ;; REFERER (deftest http-referer? (with-core-stream (s "http://www.w3.org/hypertext/DataSources/Overview.html") (let ((uri (http-referer? s))) (and (equal (uri.scheme uri) "http") (equal (uri.server uri) "www.w3.org") (equal (uri.paths uri) '(("hypertext") ("DataSources") ("Overview.html")))))) t) ;; TE (deftest http-te? (with-core-stream (s "trailers, deflate;q=0.3;asd=\"val\"") (equal (http-te? s) '(("trailers") ("deflate" ("asd" . "val") ("q" . "0.3"))))) t) ;; USER-AGENT (deftest http-user-agent-opera? (with-core-stream (s "Opera/9.21 (X11; Linux i686; U; en)") (http-user-agent? s)) ((BROWSER . OPERA) (VERSION (9 21)) (OS . ("X11" "Linux i686")) (LANG . "en"))) (deftest http-user-agent-seamonkey? (with-core-stream (s "Mozilla/5.0 (X11; U; Linux i686; tr-TR; rv:1.8.1.2) Gecko/20070511 SeaMonkey/1.1.1") (http-user-agent? s)) ((BROWSER . SEAMONKEY) (MOZ-VER (5 0)) (OS . "Linux i686") (REVISION (1 8 1 2)) (VERSION (1 1 1)))) (deftest http-user-agent-ie? (with-core-stream (s "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)") (http-user-agent? s)) ((BROWSER . IE) (MOZ-VER (4 0)) (VERSION (6 0)) (OS . "Windows NT 5.1"))) (deftest http-user-agent-ie7? (with-core-stream (s "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; OfficeLiveConnector.1.3; OfficeLivePatch.0.0) Host") (http-user-agent? s)) ((BROWSER . IE) (MOZ-VER (4 0)) (VERSION (7 0)) (OS . "Windows NT 5.1"))) ;;; ;;; test response headers ;;; ;; ACCEPT-RANGES (deftest http-accept-ranges! (with-core-stream (s "") (http-accept-ranges! s "bytes") (equal (return-stream s) "bytes")) t) ;; AGE (deftest http-age! (with-core-stream (s "") (http-age! s 12) (equal (return-stream s) "12")) t) ;; ETAG (deftest http-etag! (and (with-core-stream (s "") (http-etag! s '("test" . t)) (equal (return-stream s) "W/\"test\"")) (with-core-stream (s "") (http-etag! s '("wotest")) (equal (return-stream s) "\"wotest\""))) t) ;; LOCATION (deftest http-location! (with-core-stream (s "") (http-location! s (make-uri :scheme "http" :username "john" :password "foo" :server "127.0.0.1" :port 8080 :paths '(("test") ("me") ("up.html")))) (equal (return-stream s) "http://john:[email protected]:8080/test/me/up.html")) t) ;; PROXY-AUTHENTICATE (deftest http-proxy-authenticate! (with-core-stream (s "") (http-proxy-authenticate! s '("Digest" . (("attribute1" . "value1") ("attr2" . "val2")))) (equal (return-stream s) "Digest attribute1=\"value1\", attr2=\"val2\"")) t) ;; RETRY-AFTER (deftest http-retry-after! (with-core-stream (s "") (http-retry-after! s (encode-universal-time 0 20 6 1 1 2008)) (equal (return-stream s) "Tue, 01 Feb 2008 04:20:00 GMT")) t) ;; SERVER (deftest http-server! (with-core-stream (s "") (http-server! s "(CORE-SERVER . (0 2))") (equal (return-stream s) "(CORE-SERVER . (0 2))")) t) ;; VARY (deftest http-vary! (and (with-core-stream (s "") (http-vary! s '()) (equal (return-stream s) "*")) (with-core-stream (s "") (http-vary! s '("Free" "Software")) (equal (return-stream s) "Free,Software"))) t) ;; WWW-AUTHENTICATE (deftest http-www-authenticate! (with-core-stream (s "") (http-www-authenticate! s '("digest" . (("mac" . "0E:F0:FF:FF:FF:00") ("cam" . "foo")))) (equal (return-stream s) "digest mac=\"0E:F0:FF:FF:FF:00\", cam=\"foo\"")) t) ;;; ;;; test general-headers ;;; ;; CACHE-CONTROL (deftest http-cache-control-no-cache? (with-core-stream (s "no-cache") (http-cache-control? s)) ((NO-CACHE))) (deftest http-cache-control-max-age? (with-core-stream (s "max-age=3600") (http-cache-control? s)) ((MAX-AGE . 3600))) (deftest http-cache-control-no-store? (with-core-stream (s "no-store") (http-cache-control? s)) ((NO-STORE))) (deftest http-cache-control-public! (with-core-stream (s "") (http-cache-control! s 'PUBLIC) (return-stream s)) "public") (deftest http-cache-control-no-cache! (with-core-stream (s "") (http-cache-control! s '((NO-CACHE . ("extension" . "value")))) (return-stream s)) "no-cache,extension=\"value\"") (deftest http-cache-control-private! (with-core-stream (s "") (http-cache-control! s '((PRIVATE . ("here" . "Iam")))) (return-stream s)) "private,here=\"Iam\"") ;; CONNECTION (deftest http-connection? (with-core-stream (s "close") (http-connection? s)) ("close")) (deftest http-connection! (with-core-stream (s "") (http-connection! s 'CLOSE) (return-stream s)) "close") ;; DATE (deftest http-date? (with-core-stream (s "Tue, 01 Feb 2008 04:20:00 GMT") (http-date? s)) 3410828400) (deftest http-date! (with-core-stream (s "") (http-date! s (encode-universal-time 0 20 6 1 1 2008)) (return-stream s)) "Tue, 01 Feb 2008 04:20:00 GMT") ;; PRAGMA (deftest http-pragma-no-cache? (with-core-stream (s "no-cache") (http-pragma? s)) (NO-CACHE)) (deftest http-pragma-key-val? (with-core-stream (s "name=val") (http-pragma? s)) ("name" . "val")) (deftest http-pragma? (with-core-stream (s "name=\"quoted\"") (http-pragma? s)) ("name" . "quoted")) (deftest http-pragma-no-cache! (with-core-stream (s "") (http-pragma! s '(NO-CACHE)) (return-stream s)) "no-cache") (deftest http-pragma-key-val! (with-core-stream (s "") (http-pragma! s '("name" . "val")) (return-stream s)) "name=val") ;; TRAILER (deftest http-trailer? (with-core-stream (s "Content-Type, Cache-Control, Server") (equal (http-trailer? s) '("Server" "Cache-Control" "Content-Type"))) t) (deftest http-trailer! (with-core-stream (s "") (http-trailer! s '("Content-Type, Cache-Control, Server")) (equal (return-stream s) "Content-Type, Cache-Control, Server")) t) ;; TRANSFER-ENCODING (deftest http-transfer-encoding? (and (with-core-stream (s "chunked") (equal (http-transfer-encoding? s) '(("chunked")))) (with-core-stream (s "token;attribute=\"value\"") (equal (http-transfer-encoding? s) '(("token" ("attribute" . "value")))))) t) (deftest http-transfer-encoding! (and (with-core-stream (s "") (http-transfer-encoding! s '((CHUNKED))) (equal (return-stream s) "chunked")) (with-core-stream (s "") (http-transfer-encoding! s '(("token" . (("attr" . "val") ("attr2" . "val2"))))) (equal (return-stream s) "token;attr=\"val\";attr2=\"val2\""))) t) ;; UPGRADE (deftest http-upgrade? (with-core-stream (s "HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11") (equal (http-upgrade? s) '(("RTA" . "x11") ("IRC" . "6.9") ("SHTTP" . "1.3") ("HTTP" . "2.0")))) t) (deftest http-upgrade! (with-core-stream (s "") (http-upgrade! s '(("RTA" . "x11") ("IRC" . "6.9") ("SHTTP" . "1.3") ("HTTP" . "2.0"))) (equal (return-stream s) "RTA/x11, IRC/6.9, SHTTP/1.3, HTTP/2.0")) t) ;; VIA (deftest http-via? (with-core-stream (s "HTTP/1.1 core.gen.tr:80 (core server site), 1.1 nasa, 1.0 cgrid (asd)") (http-via? s)) ((("HTTP" . "1.1") ("core.gen.tr" . 80) "core server site") ((nil . "1.1") ("nasa") NIL) ((nil . "1.0") ("cgrid") "asd"))) (deftest http-via! (with-core-stream (s "") (http-via! s '((("HTTP" . "1.1") ("core.gen.tr" . 80) "core server site") ((NIL . "1.1") ("nasa") NIL) ((NIL . "1.0") ("cgrid") "asd"))) (equal (return-stream s) "HTTP/1.1 core.gen.tr:80 (core server site), 1.1 nasa , 1.0 cgrid (asd)")) t) ;; WARNING (deftest http-warning? (with-core-stream (s "199 www.core.gen.tr:80 \"warn text\" \"Tue, 01 Feb 2008 04:20:00 GMT\"") (http-warning? s)) ((199 ("www.core.gen.tr" . 80) "warn text" 3410828400))) (deftest http-warning! (with-core-stream (s "") (http-warning! s '((199 ("www.core.gen.tr" . 80) "warn text" 3408142800))) (equal (return-stream s) "199 www.core.gen.tr:80 \"warn text\" \"Tue, 01 Feb 2008 02:20:00 GMT\"")) t) (deftest http-response-render! (let ((date (encode-universal-time 0 20 6 1 1 2008)) (response (make-instance 'http-response))) (with-core-stream (s "") (setf (http-message.general-headers response) `((CACHE-CONTROL . "private") (DATE . ,date) (CONNECTION . CLOSE))) (setf (http-response.response-headers response) `((SERVER . "(CORE-SERVER . (0 2))"))) (setf (http-response.entity-headers response) `((CONTENT-TYPE . ("text" "html" . (("charset" . "UTF-8")))))) (core-server::http-response-headers! s response) (return-stream s))) "HTTP/1.1 200 OK CACHE-CONTROL: private DATE: Tue, 01 Feb 2008 04:20:00 GMT CONNECTION: close SERVER: (CORE-SERVER . (0 2)) CONTENT-TYPE: text/html;charset=UTF-8 ") (deftest x-www-form-urlencoded? (with-core-stream (s "username=kazim&password=sananelazim&email=kazim%40patates.com&Sent=sent") (core-server::x-www-form-urlencoded? s)) (("username" . "kazim") ("password" . "sananelazim") ("email" . "[email protected]") ("Sent" . "sent"))) (defparameter *http-request* "POST /ee.gee HTTP/1.0 Host: localhost:3010 Accept: text/html, text/plain, application/vnd.sun.xml.writer, application/vnd.sun.xml.writer.global, application/vnd.stardivision.writer Accept: application/msword, application/vnd.sun.xml.calc, application/vnd.stardivision.calc, application/x-starcalc Accept: application/vnd.sun.xml.impress, application/vnd.stardivision.impress, application/vnd.stardivision.impress-packed Accept: application/vnd.ms-powerpoint, application/x-mspowerpoint, application/vnd.sun.xml.draw, application/vnd.stardivision.draw Accept: application/vnd.stardivision.math, application/x-starmath, text/sgml, */*;q=0.01 Accept-Encoding: gzip, compress Accept-Language: en Pragma: no-cache Cache-Control: no-cache User-Agent: Lynx/2.8.5rel.5 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7j Content-type: multipart/form-data; boundary=LYNX Content-length: 395 --LYNX ") (defparameter *req-data* "gee=gee123&abuzer1=bas+bakalim&abuzer2=&abuzer3=&notparsed=gee&") (defparameter *mod-lisp-req2* "server-protocol HTTP/1.1 method POST url /%C4%B1gee.gee content-type application/x-www-form-urlencoded content-length 48 server-ip-addr 127.0.0.1 server-ip-port 80 remote-ip-addr 127.0.0.1 script-filename /var/www/localhost/htdocs/gee.gee remote-ip-port 50692 server-id evrim User-Agent Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0 Host localhost Accept text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language tr,en;q=0.7,en-us;q=0.3 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-9,utf-8;q=0.7,*;q=0.7 Keep-Alive 300 Connection keep-alive Cache-Control max-age=0 Content-Type application/x-www-form-urlencoded Content-Length 48 end gee=gee123&abuzer1=bas+bakalim&abuzer2=&abuzer3=") (defparameter *mod-lisp-req* "server-protocol HTTP/1.1 method POST url /%C4%B1gee.gee content-type application/x-www-form-urlencoded content-length 48 server-ip-addr 127.0.0.1 server-ip-port 80 remote-ip-addr 127.0.0.1 script-filename /var/www/localhost/htdocs/gee.gee remote-ip-port 50692 server-id evrim server-baseversion Apache/2.0.58 modlisp-version 1.3.1 modlisp-major-version 2 User-Agent Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0 Host localhost Accept text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language tr,en;q=0.7,en-us;q=0.3 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-9,utf-8;q=0.7,*;q=0.7 Keep-Alive 300 Connection keep-alive Cache-Control max-age=0 Content-Type application/x-www-form-urlencoded Content-Length 48 end gee=gee123&abuzer1=bas+bakalim&abuzer2=&abuzer3=") (defparameter *multipart/form-data* "-----------------------------180841493794515451098915474 Content-Disposition: form-data; name=\"ıgee\" gee123ýþi -----------------------------180841493794515451098915474 Content-Disposition: form-data; name=\"abuzer1\" bas bakalim -----------------------------180841493794515451098915474 Content-Disposition: form-data; name=\"abuzer2\"; filename=\"a.html\" Content-Type: text/html <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> <html ><body ><form action=\"http://localhost/ıgee.gee\" method=\"POST\" enctype=\"multipart/form-data\" ><input name=\"ıgee\" type=\"text\" value=\"gee123\" /><input type=\"submit\" name=\"abuzer1\" value=\"bas bakalim\"> <input type=\"file\" name=\"abuzer2\"> <input type=\"file\" name=\"abuzer3\"> </form ></body ></html > -----------------------------180841493794515451098915474 Content-Disposition: form-data; name=\"abuzer3\"; filename=\"\" Content-Type: application/octet-stream -----------------------------180841493794515451098915474-- ") (defparameter *ie-mod-lisp-headers* "server-protocol HTTP/1.1 method GET url /eben.gee server-ip-addr 10.0.0.10 server-ip-port 80 remote-ip-addr 10.0.0.11 script-filename /var/www/localhost/htdocs/eben.gee remote-ip-port 1035 server-id evrim server-baseversion Apache/2.0.58 modlisp-version 1.3.1 modlisp-major-version 2 Accept image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */* Accept-Language tr Accept-Encoding gzip, deflate Accept-Charset iso-8859-5, unicode-1-1;q=0.8 Accept-Ranges bytes Age 341274938794237 Allow GET, HEAD, PUT User-Agent Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) Host 10.0.0.10 Connection Keep-Alive end ") (defvar *ie-modlisp-urlencoded* "server-protocol HTTP/1.1 method POST url /coretal/js.core?s=dGLvrnRW&k=act-sGcKrhFB content-type application/x-www-form-urlencoded content-length 43 server-ip-addr 10.0.0.1 server-ip-port 80 remote-ip-addr 10.0.0.103 script-filename /var/www/coretal/js.core remote-ip-port 1117 server-id core-server server-baseversion Apache/2.2.6 modlisp-version 1.3.1 modlisp-major-version 2 Accept */* Accept-Language tr Referer http://10.0.0.1/coretal/# Content-Type application/x-www-form-urlencoded UA-CPU x86 Accept-Encoding gzip, deflate User-Agent Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30) Host 10.0.0.1 Content-Length 43 Connection Keep-Alive Cache-Control no-cache end username=%22admin%22&password=%22c0r3t4l%22") (defvar *ie-http-headers* "GET / HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */* Accept-Language: tr Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) Host: 10.0.0.10:3011 Connection: Keep-Alive ") (defvar *ie7-http-mod-lisp* "server-protocol HTTP/1.1 method GET url /coretal.core server-ip-addr 213.232.33.242 server-ip-port 80 remote-ip-addr 94.54.32.65 script-filename /var/www/www.coretal.net/coretal.core remote-ip-port 3467 Accept application/x-silverlight, application/x-shockwave-flash, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */* Accept-Language tr-TR UA-CPU x86 Accept-Encoding gzip, deflate User-Agent Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; OfficeLiveConnector.1.3; OfficeLivePatch.0.0) Host www.coretal.net Connection Keep-Alive end ") (defparameter *ie-http-form* "POST /ee.gee HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */* Referer: http://10.0.0.10/a.html Accept-Language: tr Content-Type: multipart/form-data; boundary=---------------------------7d728030200f0 Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) Host: 10.0.0.10:3010 Content-Length: 646 Connection: Keep-Alive Cache-Control: no-cache -----------------------------7d728030200f0 Content-Disposition: form-data; name=\"gee\" gee123 -----------------------------7d728030200f0 Content-Disposition: form-data; name=\"abuzer1\" bas bakalim -----------------------------7d728030200f0 Content-Disposition: form-data; name=\"abuzer2\"; filename=\"C:\Documents and Settings\Administrator\Desktop\a.txt\" Content-Type: text/plain ayim ben -----------------------------7d728030200f0 Content-Disposition: form-data; name=\"abuzer3\"; filename=\"C:\Documents and Settings\Administrator\Desktop\b.txt\" Content-Type: text/plain beyim ben -----------------------------7d728030200f0-- ") (defvar *ie-modlisp-form* "server-protocol HTTP/1.1 method POST url /eeg.gee content-type multipart/form-data; boundary=---------------------------7d72ec11200f0 content-length 644 server-ip-addr 10.0.0.10 server-ip-port 80 remote-ip-addr 10.0.0.11 script-filename /var/www/localhost/htdocs/eeg.gee remote-ip-port 1056 server-id evrim server-baseversion Apache/2.0.58 modlisp-version 1.3.1 modlisp-major-version 2 Accept image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */* Referer http://10.0.0.10/a.html Accept-Language tr Content-Type multipart/form-data; boundary=---------------------------7d72ec11200f0 Accept-Encoding gzip, deflate User-Agent Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) Host 10.0.0.10 Content-Length 644 Connection Keep-Alive Cache-Control no-cache end -----------------------------7d72ec11200f0 Content-Disposition: form-data; name=\"gee\" gee123 -----------------------------7d72ec11200f0 Content-Disposition: form-data; name=\"abuzer1\" bas bakalim -----------------------------7d72ec11200f0 Content-Disposition: form-data; name=\"abuzer2\"; filename=\"C:\Documents and Settings\Administrator\Desktop\a.txt\" Content-Type: text/plain ayim ben -----------------------------7d72ec11200f0 Content-Disposition: form-data; name=\"abuzer3\"; filename=\"C:\Documents and Settings\Administrator\Desktop\b.txt\" Content-Type: text/plain beyim ben -----------------------------7d72ec11200f0-- ")
23,179
Common Lisp
.lisp
792
25.996212
298
0.650613
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
a12dc5e361a51883dafe804b9a8d500ebc1e9ccfe30f0537daf2b392914ca904
8,411
[ -1 ]
8,412
2388.lisp
evrim_core-server/t/rfc/2388.lisp
(in-package :tr.gen.core.server.test) (defvar *a-mime-part* "--AaB03x content-disposition: form-data; name=\"field1\" content-type: text/plain;charset=windows-1250 content-transfer-encoding: quoted-printable Joe owes =80100. -- --AaB03x") (defparameter *b-mime-part* "-----------------------------180841493794515451098915474 Content-Disposition: form-data; name=\"gee\" gee123 -----------------------------180841493794515451098915474 Content-Disposition: form-data; name=\"abuzer1\" bas bakalim -----------------------------180841493794515451098915474 Content-Disposition: form-data; name=\"abuzer2\"; filename=\"a.html\" Content-Type: text/html <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> <html ><body ><form action=\"http://localhost/gee.gee\" method=\"POST\" enctype=\"multipart/form-data\" ><input name=\"gee\" type=\"text\" value=\"gee123\" /><input type=\"submit\" name=\"abuzer1\" value=\"bas bakalim\"> <input type=\"file\" name=\"abuzer2\"> <input type=\"file\" name=\"abuzer3\"> </form ></body ></html > -----------------------------180841493794515451098915474 ") (defvar *c-mime-part* "----AaB03x Content-Disposition: form-data; name=\"submit-name\" Larry ----AaB03x Content-Disposition: form-data; name=\"files\"; filename=\"file1.txt\" Content-Type: text/plain file1.txt ----AaB03x-- ") (defparameter *d-mime-part* "--AaB03x Content-Disposition: form-data; name=\"gee-name\" Lari balki --AaB03x Content-Disposition: form-data; name=\"files\" Content-Type: multipart/mixed; boundary=BbC04y --BbC04y Content-Disposition: file; filename=\"file1.txt\" Content-Type: text/plain file1.txt --BbC04y Content-Disposition: file; filename=\"file2.gif\" Content-Type: image/gif Content-Transfer-Encoding: binary file2.gif --BbC04y-- --AaB03x Content-Disposition: form-data; name=\"submit-name\" Larry --AaB03x-- a") (defparameter *e-mime-part* "--AaB03x Content-Disposition: form-data; name=\"files\" ----AaB03 --AaB03x-- ") ;; A mime that has only one part (deftest mime-part-from-stream (let* ((cstream (make-core-stream *a-mime-part*)) (mime (rfc2388-mimes? cstream))) (and (equal 1 (length mime)) (equal (mime.header (car mime) 'disposition) `("form-data" (("name" . "field1")))) (equal (mime.header (car mime) 'content-type) `("text" "plain" (("charset" . "windows-1250")))) (equal (mime.header (car mime) 'transfer-encoding) 'quoted-printable))) t) (deftest mime-parts-from-stream (equal (list 3 2 3 1) (list (let* ((cstream (make-core-stream *b-mime-part*)) (mps (mimes? cstream))) (length mps)) (let* ((cstream (make-core-stream *c-mime-part*)) (mps (mimes? cstream))) (length mps)) (let* ((cstream (make-core-stream *d-mime-part*)) (mps (mimes? cstream))) (length mps)) (let* ((cstream (make-core-stream *e-mime-part*)) (mps (mimes? cstream))) (length mps)))) t) (defun vector= (v1 v2) (reduce #'(lambda (x y) (and x y)) (map 'vector #'eq v1 v2))) (deftest exampleb-mime-part (let* ((cstream (make-core-stream *b-mime-part*)) (mps (rfc2388-mimes? cstream))) (and ;; first part (let ((mime (car mps))) (and (equal (mime.header mime 'disposition) '("form-data" (("name" . "gee")))) (vector= (mime.data mime) #(103 101 101 49 50 51)))) ;; third part (let ((mime (caddr mps))) (and (equal (mime.header mime 'content-type) '("text" "html")) (equal (mime.header mime "disposition") '("form-data" (("name" . "abuzer2") ("filename" . "a.html")))) (vector= (mime.data mime) #(60 33 68 79 67 84 89 80 69 32 104 116 109 108 32 80 85 66 76 73 67 32 34 45 47 47 87 51 67 47 47 68 84 68 32 88 72 84 77 76 32 49 46 48 32 83 116 114 105 99 116 47 47 69 78 34 32 34 104 116 116 112 58 47 47 119 119 119 46 119 51 46 111 114 103 47 84 82 47 120 104 116 109 108 49 47 68 84 68 47 120 104 116 109 108 49 45 115 116 114 105 99 116 46 100 116 100 34 62 10 60 104 116 109 108 10 32 32 62 60 98 111 100 121 10 32 32 32 32 32 32 62 60 102 111 114 109 32 97 99 116 105 111 110 61 34 104 116 116 112 58 47 47 108 111 99 97 108 104 111 115 116 47 103 101 101 46 103 101 101 34 32 109 101 116 104 111 100 61 34 80 79 83 84 34 10 9 32 32 101 110 99 116 121 112 101 61 34 109 117 108 116 105 112 97 114 116 47 102 111 114 109 45 100 97 116 97 34 32 10 9 32 32 32 32 32 32 32 32 62 60 105 110 112 117 116 32 110 97 109 101 61 34 103 101 101 34 32 116 121 112 101 61 34 116 101 120 116 34 32 118 97 108 117 101 61 34 103 101 101 49 50 51 34 10 9 9 9 32 32 32 32 32 32 47 62 60 105 110 112 117 116 32 116 121 112 101 61 34 115 117 98 109 105 116 34 32 110 97 109 101 61 34 97 98 117 122 101 114 49 34 32 118 97 108 117 101 61 34 98 97 115 32 98 97 107 97 108 105 109 34 62 10 9 9 9 9 32 32 60 105 110 112 117 116 32 116 121 112 101 61 34 102 105 108 101 34 32 110 97 109 101 61 34 97 98 117 122 101 114 50 34 62 10 9 9 9 9 32 32 60 105 110 112 117 116 32 116 121 112 101 61 34 102 105 108 101 34 32 110 97 109 101 61 34 97 98 117 122 101 114 51 34 62 10 9 9 9 9 32 32 60 47 102 111 114 109 10 9 9 9 9 32 32 32 32 32 32 62 60 47 98 111 100 121 10 9 9 9 9 9 32 32 32 32 62 60 47 104 116 109 108 10 9 9 9 9 9 9 62 10)))))) t)
5,723
Common Lisp
.lisp
147
33.482993
113
0.617822
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
a4a5a54ca7b5add43de2b1f49f3054e73090451e8def9b4278766d2cc1118677
8,412
[ -1 ]
8,413
2045.lisp
evrim_core-server/t/rfc/2045.lisp
(in-package :tr.gen.core.server.test) (deftest quoted-printable-reader (let ((qptext1 "A\"=3D0A=3D=2043&%##430xF00F=0A=20A=20AAAAAAAAAAAAAAAAABBB")) (equal (octets-to-string (quoted-printable? (make-core-stream qptext1)) :utf-8) "A\"=0A= 43&%##430xF00F A AAAAAAAAAAAAAAAAABBB") ) t) (deftest quoted-printable-writer (let ((cstream (make-core-stream ""))) (quoted-printable! cstream "A\"=0A= 43&%##430xF00F A AAAAAAAAAAAAAAAAABBB") (equal (return-stream cstream) "A\"=3D0A=3D=2043&%##430xF00F=0A=20A=20AAAAAAAAAAAAAAAAABBB") ) t)
590
Common Lisp
.lisp
16
32.0625
85
0.671902
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
06235f4dc876ed31439a4fc8df0e7475994bc8ba04aa9a3476629ff3dddd5591
8,413
[ -1 ]
8,414
2396.lisp
evrim_core-server/t/rfc/2396.lisp
(in-package :tr.gen.core.server.test) (deftest uri-to-stream (let ((uri-s "http://evrim:[email protected]:80/a/b/c?a:1;b:2#x:1;y:2") (uri-o (make-uri :scheme "http" :username "evrim" :password "password" :server "nodeN.core.gen.tr" :port 80 :paths '(("a") ("b") ("c")) :queries (list (cons "a" "1") (cons "b" "2")) :fragments (list (cons "x" "1") (cons "y" "2")))) (cstream (make-core-stream ""))) (uri! cstream uri-o) (equal uri-s (return-stream cstream))) t) (deftest stream-to-uri (let* ((uri-s "http://evrim:[email protected]:80/a/b/c?a:1;b:2#x:1;y:2") (uri-o (uri? (make-core-stream uri-s)))) (and (equal (uri.scheme uri-o) "http") (equal (uri.username uri-o) "evrim") (equal (uri.password uri-o) "password") (equal (uri.server uri-o) "nodeN.core.gen.tr") (eq (uri.port uri-o) 80) (equal (uri.paths uri-o) '(("a") ("b") ("c"))) (equal (uri.queries uri-o) (list (cons "a" "1") (cons "b" "2"))) (equal (uri.fragments uri-o) (list (cons "x" "1") (cons "y" "2"))))) t)
1,118
Common Lisp
.lisp
28
34.321429
85
0.555556
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
69ac84bd7d2703574e918546be89963b0614ab8722b2f77c4b1769bd184bee67
8,414
[ -1 ]
8,415
serialization.lisp
evrim_core-server/t/database/serialization.lisp
(in-package :core-server.test) (defmacro defserialization-test (name lisp-element db-element &optional (equal 'equalp)) `(deftest ,name (and (xml.equal (xml-serialize ,lisp-element) ,db-element) (,equal (xml-deserialize ,db-element) ,lisp-element)) t)) (defserialization-test serialize-null nil (<db:null)) (defserialization-test serialize-true t (<db:true)) (defserialization-test serialize-symbol 'my-symbol? (<db:symbol "TR.GEN.CORE.SERVER.TEST::MY-SYMBOL?")) (defserialization-test serialize-character #\A (<db:character "\"A\"")) (defserialization-test serialize-int 100000 (<db:integer "100000")) (defserialization-test serialize-ratio (/ 1 2) (<db:ratio "1/2")) (defserialization-test serialize-complex #C(3 4) (<db:complex "#C(3 4)")) (defserialization-test serialize-float (float (/ 1 2)) (<db:float "0.5")) (defserialization-test serialize-string "mooo 1 2 3>" (<db:string "\"mooo 1 2 3>\"")) (defserialization-test serialize-cons (cons 1 2) (<db:cons :consp t (<db:integer "1") (<db:integer "2"))) (defserialization-test serialize-list (list 3 4 5 6) (<db:cons :length 4 (<db:integer "3") (<db:integer "4") (<db:integer "5") (<db:integer "6"))) (defun serialization-hash-table () (let ((table (make-hash-table :test #'equal))) (setf (gethash "test1" table) "test1-value" (gethash "test2" table) "test2-value") table)) (defun hash-table-equalp (a b) (and (equal (hash-table-keys a) (hash-table-keys b)) (equal (hash-table-values a) (hash-table-values b)))) (defserialization-test serialize-hash-table (serialization-hash-table) (<db:hash-table :test "COMMON-LISP::EQUAL" :size "16" (<db:hash-table-entry (<db:hash-table-key (<db:string "\"test1\"")) (<db:hash-table-value (<db:string "\"test1-value\""))) (<db:hash-table-entry (<db:hash-table-key (<db:string "\"test2\"")) (<db:hash-table-value (<db:string "\"test2-value\"")))) hash-table-equalp) (defstruct (my-structure) (slot1)) (defun serialization-structure () (make-my-structure :slot1 "test")) (defserialization-test serialize-structure (serialization-structure) (<db:struct :class "TR.GEN.CORE.SERVER.TEST::MY-STRUCTURE" (<db:slot :name "TR.GEN.CORE.SERVER.TEST::SLOT1" (<db:string "\"test\"")))) (defclass my-class () ((slot1 :initarg :slot1))) (defun serialization-object () (make-instance 'my-class :slot1 "slot1")) (defun my-object-equalp (a b) (and (equal (class-of a) (class-of b)) (equal (slot-value a 'slot1) (slot-value b 'slot1)))) (defserialization-test serialize-object (serialization-object) (<db:instance :class "TR.GEN.CORE.SERVER.TEST::MY-CLASS" (<db:slot :name "TR.GEN.CORE.SERVER.TEST::SLOT1" (<db:string "\"slot1\""))) my-object-equalp) (defclass+ my-class+ () ((slot1 :initarg :slot1) (slot2 :host remote))) (defserialization-test serialize-class+ (my-class+ :slot1 "slot1") (<db:instance :class "TR.GEN.CORE.SERVER.TEST::MY-CLASS+" (<db:slot :name "TR.GEN.CORE.SERVER.TEST::SLOT1" (<db:string "\"slot1\""))) my-object-equalp) ;; Generate unique filename for temporary usage (sb-alien:define-alien-routine "tmpnam" sb-alien:c-string (dest (* sb-alien:c-string))) (defparameter *dbpath* (pathname (format nil "~A/" (tmpnam nil)))) (defvar *db* nil) (defun test-db () (setf *dB* (make-instance 'database :database-directory *dbpath*)) (start *db*) *db*) (deftest db-serialize-object (let ((db (test-db))) (and (= 123 (database.deserialize db (database.serialize db 123))))) t)
3,577
Common Lisp
.lisp
85
38.576471
103
0.678952
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
ea80e80b3fe5d0456da43618ae5a7db1f070fa337b29d3e4536aefceff20cf76
8,415
[ -1 ]
8,416
database.lisp
evrim_core-server/t/database/database.lisp
;; +---------------------------------------------------------------------------- ;; | Basic Database Tests ;; +---------------------------------------------------------------------------- (in-package :core-server.test) ;; Generate unique filename for temporary usage (sb-alien:define-alien-routine "tmpnam" sb-alien:c-string (dest (* sb-alien:c-string))) (defparameter *dbpath* #P"/tmp/core-server-test/") (defvar *db* nil) (defun test-db () (setf *dB* (make-instance 'database :database-directory *dbpath*)) (purge *db*) (start *db*) *db*) (deftest database-1 (let ((db (test-db))) (setf (database.get db 'key) 'value) (stop db) (start db) (prog1 (database.get db 'key) (stop db))) value) (deftest database-2 (let ((db (test-db))) (setf (database.get db 'foo) 'bar) (snapshot db) (stop db) (start db) (prog1 (database.get db 'foo) (stop db))) bar) (defclass test-db-class () ((slot1 :initform "slot1"))) (deftest database-3 (let ((db (test-db)) (str (random-string))) (let ((object (add-object db 'test-db-class))) (update-object db object (cons 'slot1 str))) (stop db) (start db) (let ((object (find-object-with-slot db 'test-db-class 'slot1 str))) (prog1 (and object t) (if object (delete-object db object)) (stop db)))) t) (defclass+ persistent-class (object-with-id) ((slot1 :initform "slot1" :print t))) (deftest database-4 (let ((db (test-db)) (id)) (let ((object (add-object db 'persistent-class))) (update-object db object (cons 'slot1 "test1-slotval")) (setq id (slot-value object 'database-id))) (stop db) (start db) (let ((object (find-object-with-slot db 'persistent-class 'database-id id))) (prog1 (slot-value object 'slot1) (delete-object db object) (stop db)))) "test1-slotval") (defclass+ user (object-with-id) ((name :initform "name" :print t :host local) (blogs :type blog* :relation user) (domains :type domain* :relation users))) (defclass+ blog (object-with-id) ((title :initform "title" :print t) (user :type user :relation blogs))) (defclass+ domain (object-with-id) ((fqdn :initform "fqdn") (users :type user* :relation domains))) ;; Testing Basic 1-N, N-1 (deftest database-5 (let ((db (test-db))) (let* ((user (add-object db 'user (cons 'name "evrim"))) (blog (add-object db 'blog (cons 'title "myblog1") (cons 'user user)))) (and (eq (blog.user blog) user) (member blog (user.blogs user)) (progn (delete-object db blog) (not (member blog (user.blogs user)))) (progn (update-object db user (cons 'blogs (list blog))) (and (member blog (user.blogs user)) (eq (blog.user blog) user)))))) t) ;; Testing 1-N, N-1 (deftest database-6 (let ((db (test-db))) (let ((u1 (add-object db 'user (cons 'name (random-string)))) (u2 (add-object db 'user (cons 'name (random-string))))) (let ((blog (add-object db 'blog (cons 'title (random-string)) (cons 'user u1)))) (update-object db blog (cons 'user u2)) (and (not (member blog (user.blogs u1))) (member blog (user.blogs u2)) (eq u2 (blog.user blog)) (progn (delete-object db blog) (not (member blog (user.blogs u2)))))))) t) ;; Testing N-N (deftest database-7 (let* ((db (test-db)) (u1 (add-object db 'user (cons 'name (random-string)))) (d1 (add-object db 'domain (cons 'fqdn (random-string)) (cons 'users (list u1))))) (and (member u1 (domain.users d1)) (member d1 (user.domains u1)) (progn (delete-object db d1) (not (member d1 (user.domains u1)))))) t) ;; Crud (defcrud user) (defcrud blog) (deftest database-8 (let* ((db (test-db)) (u1 (user.add db :name "foo"))) (user.update db u1 :name "bar") (prog1 (user.name u1) (user.delete db u1))) "bar") ;; More Crud Tests (defun db-value (a) (format nil "test-~A" a)) (defclass+ test-class1 () ((transient :host none :initarg :transient :initform (db-value "transient")) (persistent :host local :initarg :persistent :initform (db-value "persistent")))) (defcrud test-class1) (deftest database-9 (let* ((db (test-db)) (t1 (test-class1.add db))) (snapshot db) (slot-value (car (test-class1.list db)) 'transient)) "test-transient") (deftest database-10 (let* ((db (test-db)) (t1 (test-class1.add db))) (snapshot db) (stop db) (start db) (let ((obj (car (test-class1.list db)))) (describe obj) (slot-value obj 'persistent))) "test-persistent") (defcomponent a-component (object-with-id) ((name :host local :index t) (one-B :host local :type b-component :relation list-of-A))) (defcomponent b-component (object-with-id) ((name :host local :index t) (list-of-A :host local :type a-component* :relation one-B))) (defcrud a-component) (defcrud b-component) (deftest database-11 (let* ((db (test-db)) (a1 (a-component.add db :name "a1")) (a2 (a-component.add db :name "a2")) (b1 (b-component.add db :name "b1" :list-of-a (list a1 a2)))) (stop db) (start db) (let ((a1 (a-component.find db :name "a1")) (a2 (a-component.find db :name "a2")) (b1 (b-component.find db :name "b1"))) (describe a1) (describe a2) (describe b1) (and (member a1 (list-of-a b1)) (member a2 (list-of-a b1)) (eq b1 (one-B a1)) (eq b1 (one-B a2))))) t) (defclass+ a-class1 (object-with-id) ((name :host local :index t) (one-B :host local :type b-class1 :relation list-of-A) (foo-a :host remote :initform "foo-of-a"))) (defclass+ b-class1 (object-with-id) ((name :host local :index t) (list-of-A :host local :type a-class1* :relation one-B) (foo-b :host remote :initform "foo-of-b"))) (defcrud a-class1) (defcrud b-class1) (deftest database-12 (let* ((db (test-db)) (a1 (a-class1.add db :name "a1")) (a2 (a-class1.add db :name "a2")) (b1 (b-class1.add db :name "b1" :list-of-a (list a1 a2)))) (stop db) (start db) (let ((a1 (a-class1.find db :name "a1")) (a2 (a-class1.find db :name "a2")) (b1 (b-class1.find db :name "b1"))) (describe a1) (describe a2) (describe b1) (and (member a1 (slot-value b1 'list-of-a)) (member a2 (slot-value b1 'list-of-a)) (eq b1 (slot-value a1 'one-B)) (eq b1 (slot-value a2 'one-B))))) t) (deftest database-13 (let ((db (test-db))) (setf (database.get db 'key) "ğüşiöçıĞÜŞİÖÇI") (stop db) (start db) (prog1 (database.get db 'key) (stop db))) "ğüşiöçıĞÜŞİÖÇI") (defcomponent a-component (<:div) ((foo :host remote :initform "foo-of-a"))) (defcomponent b-component (a-component) ((a-slot :host local)) (:default-initargs :foo "foo-of-b")) (defcrud a-component) (defcrud b-component) (deftest database-14 (let* ((db (test-db)) (a1 (a-component.add db)) (b1 (b-component.add db :a-slot a1))) (describe db) (snapshot db) (stop db) (start db) (describe a1) (describe b1) (let ((a2 (cadr (a-component.list db))) (b2 (car (b-component.list db)))) (describe a2) (describe b2)) (stop db) t) t) ;; ;; http://www.cs.vu.nl/boilerplate/ ;; ;; ;; ;; Scrap Your Boilerplate: A Practical Design Pattern for Generic Programming ;; ;; Ralf Lammel Simon Peyton Jones ;; ;; Vrije Universiteit, Amsterdam Microsoft Research, Cambridge ;; ;; data Company = C [Dept] ;; ;; data Dept = D Name Manager [SubUnit] ;; ;; data SubUnit = PU Employee | DU Dept ;; ;; data Employee = E Person Salary ;; ;; data Person = P Name Address ;; ;; data Salary = S Float ;; ;; type Manager = Employee ;; ;; type Name = String ;; ;; type Address = String ;; (defclass+ Person () ;; ((Name :type string) ;; (Address :type string))) ;; (defclass+ Employee (Person) ;; ((Salary :type float))) ;; (defclass+ Manager (Employee) ;; ((Departments :type Departments :relation (1-N Department)))) ;; (defclass+ Company () ;; ((Depts :type Dept :relation (1-N Department)))) ;; (defclass+ Department () ;; ((Name :type string) ;; (Manager :type Employee :relation (N-1 Employee)) ;; (SubUnits :type list :relation (1-N (or Department Employee))))) ;; (defun genCom () ;; (let ((ralf (make-instance 'Employee ;; :Person (make-instance 'Person :Name "Ralf" :Address "Amsterdam") ;; :Salary 8000)) ;; (joost (make-instance 'Employee ;; :Person (make-instance 'Person :Name "Joost" :Address "Amsterdam") ;; :Salary 1000)) ;; (marlow (make-instance 'Employee ;; :Person (make-instance 'Person :Name "Marlow" :Address "Cambridge") ;; :Salary 2000)) ;; (blair (make-instance 'Employee ;; :Person (make-instance 'Person :Name "Blair" :Address "London") ;; :Salary 100000))) ;; (make-instance 'Company ;; :Depts (list (make-instance 'Dept ;; :Name "Research" ;; :Manager ralf ;; :SubUnits (list joost marlow)) ;; (make-instance 'Dept ;; :Name "Strategy" ;; :Manager blair))))) ;; Let's implement a function increase of type Float -> Company -> ;; Company so that (increase 0.1 genCom) will be just like genCom ;; except that everyone's salary is incread by 10%. ;; (defclass db-model () ;; ((abc :initform "abcdef"))) ;; (defparameter *db* ;; (make-instance 'database-server ;; :db-auto-start nil ;; :directory #P"/tmp/ceek/" ;; :model-class 'db-model)) ;; (describe *db*) ;; (start *db*) ;; (status *db*) ;; (stop *db*) ;; (defun tx-set-abc (server abc) ;; (let ((model (model server))) ;; (setf (slot-value model 'abc) abc))) ;; (defun set-abc (abc) ;; (execute *db* (make-transaction 'tx-set-abc abc))) ;; (set-abc "789") ;; (describe (model *db*)) ;; (snapshot *db*) ;; (set-abc "91011")
9,979
Common Lisp
.lisp
299
29.692308
86
0.605938
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
75a2f746e2bd5a5ccf3b50aa5029e5baf263650e9f68206fc41087a5596d0274
8,416
[ -1 ]
8,417
boilerplate.lisp
evrim_core-server/t/database/boilerplate.lisp
(in-package :core-server.test) (defclass+ object-with-id () ((id :reader get-id :initarg :id))) (defclass+ object-with-timestamp () ((timestamp :reader get-timestamp :initarg :timestamp))) (defclass+ tree-node () ((parent) (children))) (defclass+ folder (tree-node object-with-timestamp) ((pathname) (parent :accessor folder.parent :type folder) (children :accessor folder.files :type (* file)))) (defclass+ file (folder) ()) (defclass+ image (file) ((user :type user))) (defclass+ blog (file) ((user :type user) (title :type string) (comments :type (* comment)))) (defclass+ user (folder) ((name :type string) (password :type string) (email :type string))) (defclass+ comment (tree-node object-with-timestamp) ((user :type user) (text :type string))) (defclass+ model () ((users :type user :index t) (blogs :type blogs :index t) (images :type :index t))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defclass+ user () ((name) (password) (blogs :type blog* :relation user))) (defclass+ blog () ((user :type user :relation blogs) (title) (text))) (defclass+ model () ((users) (blogs))) (defcrud user) (defcrud blog) (defmethod find-user ((self database) &key name password) (with-transaction (self) (reduce0 (lambda (acc atom) (pushnew atom acc) acc) (append (find-object-with-slot self 'user 'name name) (find-object-with-slot self 'user 'password password))))) (defmethod user-add ((self database) &key (name (error "specify name")) (password nil) (blogs nil)) (with-transaction (self) (let* ((id (next-id self)) (object (make-instance 'user :id id :name name :password password))) (push object (get-object-index self 'user)) object))) (defmethod user-delete ((self database) (user user)) (let ((id (get-id user))) (with-transaction (self) (let ((object (find-object-with-id self id))) (delete object (get-object-index self 'user)) object)))) (defmethod user-update ((self database) (user user) name) (let ((id (get-id user))) (with-transaction (self) (let ((object (find-object-with-id self id))) (update-slots object (list :name name)) object)))) (defmethod blog-add ((self database) (user user) &key (title (error "specify title")) (text (error "specify text"))) (let ((user-id (get-id user))) (with-transaction (self) (let* ((id (next-id self)) (object (make-instance 'blog :title title :text text :user (find-object-with-id self id)))) (push object (get-object-index self 'blog)) (push object (blogs.user user)) object)))) (defmethod blog-delete ((self database) (blog blog)) (let ((id (get-id blog))) (with-transaction (self) (let ((object (find-object-with-id self id))) (delete object (get-object-index self 'blog)) object)))) (defmethod blog-update ((self database) (blog blog) &key title text) (let ((id (get-id blog))) (with-transaction (self) (let ((object (find-object-with-id self id))) (update-slots object (lsit :title title :text text)) object)))) (blogs *user*) (blogs-of-user *app* *user*) (user *blog*) => 10 => (find-user *app* 10) (defmethod find-user ((self blog-application) ..) (call-next-method)..)
3,272
Common Lisp
.lisp
98
29.816327
99
0.652809
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
8cda171b172c303b27ccb4500548e55f567347886f6d20a2b41257e58d367ebc
8,417
[ -1 ]
8,418
core-server.asd
evrim_core-server/core-server.asd
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. ;;;; -*- Mode: lisp; indent-tabs-mode: nil; outline-regexp: ";;;;;*"; -*- (in-package :asdf) ;; CFFI-Grovel is needed (cl:eval-when (:load-toplevel :execute) (asdf:operate 'asdf:load-op 'cffi-grovel)) ;; Add distribution based features (eval-when (:compile-toplevel :load-toplevel :execute) (pushnew :core-server *features*) (cond ((probe-file "/etc/pardus-release") (pushnew :pardus *features*)) ((probe-file "/etc/gentoo-release") (pushnew :gentoo *features*)) ((probe-file "/etc/debian_version") (pushnew :debian *features*)))) (defsystem :core-server :description "Core Server" :version "0.1" :author "Evrim Ulu <[email protected]>" :licence "MIT License" :components ((:static-file "core-server.asd") (:module :src :serial t :components ((:file "core-server") (:file "bootstrap") (:module :util :serial t :components ((:file "helper") (:file "turkiye") (:file "mop"))) (:module :class+ :serial t :components ((:file "protocol") (:file "class+") (:file "lift") (:file "dyna") (:file "command"))) (:module :compat :serial t :components ((:file "sockets") (:file "threads") ;; (:file "prevalence") )) (:module :units :serial t :components ((:file "units"))) ;;; (:module :gss ;;; :serial t ;;; :components ;;; ((cffi-grovel:grovel-file "grovel") ;;; (:file "gss") ;;; (:file "interface"))) ;; (:module :io ;; :serial t ;; :components ;; ((cffi-grovel:grovel-file "grovel") ;; (:file "errno") ;; (:file "bsd") ;; (:file "uuid") ;; (:file "interface") ;; (:file "events") ;; ;; (:module :libevent ;; ;; :serial t ;; ;; :components ;; ;; ((:file "libevent-lib") ;; ;; (cffi-grovel:grovel-file "grovel") ;; ;; (:file "libevent"))) ;; (:module :libev ;; :serial t ;; :components ;; ((:file "libev-lib") ;; (cffi-grovel:grovel-file "grovel") ;; (:file "libev") ;; (:file "interface"))) ;; )) (:module :lisp :serial t :components ((:file "successors") (:file "cps"))) (:module :streams :serial t :components ((:file "streams") (:file "faster") (:file "grammar") (:file "util") (:file "parser") (:file "render"))) (:module :commands :serial t :components ((:file "shell") (:file "admin") (:file "scm") ;; (:file "hxpath") (:file "image"))) (:module :install :serial t :components ((:file "install"))) (:file "vars") ;; (:file "classes") (:file "protocol") (:file "application") (:file "server") (:file "peer") (:module :javascript :serial t :components ((:file "util") (:file "render") (:file "transform") (:file "interface") (:file "cps") (:file "macro") (:file "library"))) (:module :rfc :serial t :components ((:file "2109") ;;cookie (:file "2396") ;;uri (:file "2822") ;;text messages (:file "mime-types") ;; mime types (:file "2617") ;;http auth (:file "2616") ;;http (:file "2045") ;;mime-part1 (:file "2046") ;;mime-part2 (:file "2388") ;;multpart/form-data (:file "2821"))) ;;smtp (:module :markup :serial t :components ((:file "xml") (:file "dom") (:file "html") (:file "json") (:file "schema") (:file "wsdl") (:file "css") ;; (:file "json") (:file "core-server") ;; (:file "rss") (:file "atom") (:file "gphoto") (:file "media") (:file "open-search") (:file "wordpress") (:file "content") (:file "dc") (:file "excerpt"))) (:module :database :serial t :components ((:file "serialize") (:file "database") (:file "object") (:file "crud"))) (:module :applications :components ((:file "web") (:file "mail") (:file "dns") (:file "serializable-application") (:file "darcs" :depends-on ("serializable-application")) (:file "git" :depends-on ("serializable-application")) (:file "apache" :depends-on ("web")) (:file "http") (:file "persistent") (:file "postfix" :depends-on ("mail")))) (:module :servers :components ((:file "tinydns") (:file "apache") (:file "mail") (:file "postfix" :depends-on ("mail")) (:file "logger") ;; (:file "ticket") (:file "socket") (:file "http" :depends-on ("socket" "logger")) (:file "persistent" :depends-on ("http")))) (:module :services :components ((:file "whois") (:file "mail") (:file "filesystem"))) (:module :security :components ((:file "class") (:file "authorize") (:file "authenticate")) :serial t) (:module :clients :serial t :components ((:file "http") (:file "openid") (:file "oauth-v1") (:file "oauth-v2") (:file "facebook") (:file "google") (:file "twitter") (:file "yahoo") (:file "paypal"))) (:module :web :serial t :components ((:file "component") (:file "rest") (:module :components :serial t :components ((:file "jquery") (:file "form") (:file "dialog") (:file "editor") (:file "representations") (:file "table") (:file "crud") (:file "table-with-crud") (:file "tab") (:file "extra") (:file "auth") (:file "image") (:file "picasa"))) (:module :framework :serial t :components ((:file "map") (:file "page") (:file "widget") (:file "controller"))) (:module :coretal :serial t :components ((:file "i18n") (:file "taskbar") (:file "console") (:file "plugin") (:file "controller"))) (:module :plugins :serial t :components ((:file "page"))) (:module :widgets :serial t :components ((:file "menu") (:file "content") (:file "tab")))))))) :depends-on (:swank :bordeaux-threads :sb-bsd-sockets :arnesi+ :cl-ppcre :cl-fad :cffi :salza2 :ironclad) :serial t) (defmethod perform :after ((o load-op) (c (eql (find-system :core-server)))) (in-package :core-server)) (defsystem :core-server.examples :components ((:module :examples :serial t :components ((:file "hello") (:file "websum") (:file "quiz"))))) (defsystem :core-server.test :components ((:module :t :serial t :components ((:file "packages") (:file "test-harness") (:file "method") (:file "class+") (:file "postfix") (:file "parser") (:file "streams") (:file "sockets") (:file "markup") (:file "json") (:file "units") (:module :rfc :components ((:file "2109") (:file "2396") (:file "2045") (:file "2388") (:file "2616")) :serial t) (:module :database :components ((:file "serialization") (:file "database"))) ;; (:file "database") ;; (:file "dns") ;; (:file "apache") ;; (:file "ucw") ;; (:file "core") (:file "javascript") (:file "component")))) :depends-on (:core-server :rt)) ;; (defmethod perform ((op asdf::load-op) (system (eql (find-system :core-server.test)))) ;; (core-server::with-package (find-package :core-server.test) ;; (rt:do-tests))) ;; (defmethod perform ((op asdf:test-op) (system (eql (find-system :core-server)))) ;; (asdf:oos 'asdf:load-op :core-server.test) ;; (funcall (intern (string :run!) (string :it.bese.FiveAM)) :core-server))
10,830
Common Lisp
.asd
317
22.280757
91
0.433063
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
136b159b97ae3425d47c4ef2d50fdba01334ed71380fa811bbca812b59df56c0
8,418
[ -1 ]
8,419
manager.asd
evrim_core-server/src/manager/manager.asd
(in-package :asdf) ;; ------------------------------------------------------------------------- ;; Manager ASDefinition ;; Author: Evrim Ulu <[email protected]> ;; Date: 2011 ;; ------------------------------------------------------------------------- (defsystem :manager :description "core template application" :version "1" :author "Evrim Ulu <[email protected]>" :maintainer "Evrim Ulu <[email protected]>" :licence "lgpl v2" :components ((:static-file "manager.asd") (:module :src :serial t :components ((:file "packages") (:file "model" :depends-on ("packages")) (:file "application" :depends-on ("packages" "model")) (:module :auth :serial t :components ((:file "interface") (:file "anonymous") (:file "user") (:file "controller"))) (:module :api :serial t :components ((:file "markup") (:file "api"))) (:file "dynamic" :depends-on ("application")) (:module :mixin :serial t :components ((:file "application") (:file "plugin") (:file "widget"))) (:module :ui :serial t :components ((:file "info") (:file "server") (:module :servers :serial t :components ((:file "socket") (:file "database") (:file "mail-sender"))) (:module :applications :serial t :components ((:file "web") (:file "dynamic") (:file "http"))) (:file "application") (:file "settings") ;; (:file "sites") (:file "admin") (:file "controller"))) (:file "init")))) :depends-on (:arnesi+ :core-server) :serial t) (defsystem :manager.test :components ((:module :t :components ((:file "packages")))) :depends-on (:manager :core-server :rt)) (defmethod perform ((op asdf:test-op) (system (eql (asdf:find-system :manager)))) (asdf:oos 'asdf:load-op :manager.test))
2,021
Common Lisp
.asd
72
21.611111
76
0.505913
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
1d59f2746d4bd12d368e2a1b42d0c42525fd4ec313b4d52182650d6d8c8b6bc4
8,419
[ -1 ]
8,422
make_installer.sh
evrim_core-server/bin/make_installer.sh
#!/bin/sh # [ Core-serveR ] installer 2 # Episode: Generate from repo TAR=`which tar` MKTEMP=`which mktemp` MKDIR=`which mkdir` CP=`which cp` DIR=`$MKTEMP -d` TARBALL="core-server-installer-`date +\"%Y-%m-%d\"`.tar.gz" CORESERVER_HOME=`cat src/install/install.sh 2> /dev/null` if [ -z $CORESERVER_HOME ]; then CORESERVER_HOME=`cat ../src/install/install.sh 2> /dev/null`; if [ -z $CORESERVER_HOME ]; then echo "Where am i?"; exit 1; else CORESERVER_HOME="$(pwd)/../"; fi else CORESERVER_HOME="$(pwd)/"; fi echo $CORESERVER_HOME $MKDIR -p $DIR/core-server-installer; cd $DIR; $CP $CORESERVER_HOME/src/util/search.lisp core-server-installer; $CP $CORESERVER_HOME/src/util/mop.lisp core-server-installer; $CP $CORESERVER_HOME/src/util/class+.lisp core-server-installer; $CP $CORESERVER_HOME/src/install/* core-server-installer; $CP $CORESERVER_HOME/src/commands/command.lisp core-server-installer; $CP $CORESERVER_HOME/doc/README core-server-installer; $TAR zcf $TARBALL * mv $TARBALL /tmp/ echo "[Core serveR] Installer tarball is ready: /tmp/$TARBALL"
1,078
Common Lisp
.l
33
30.848485
69
0.729885
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
bc9597c5ae4ef68374dffe8822a2870c63e5821766bf09f9b4df9639f4864461
8,422
[ -1 ]
8,423
paredit-7.0b4.el
evrim_core-server/etc/emacs/paredit-7.0b4.el
;;; -*- mode: emacs-lisp -*- ;;;;;; paredit: Parenthesis editing minor mode ;;;;;; Version 15 ;;; This code is written by Taylor Campbell (except where explicitly ;;; noted) and placed in the Public Domain. All warranties are ;;; disclaimed. ;;; Add this to your .emacs after adding paredit.el to /path/to/elisp/: ;;; ;;; (add-to-list 'load-path "/path/to/elisp/") ;;; (autoload 'enable-paredit-mode "paredit" ;;; "Turns on pseudo-structural editing of Lisp code." ;;; t) ;;; (add-hook '...-mode-hook 'enable-paredit-mode) ;;; ;;; Usually the ... will be lisp or scheme or both. Alternatively, you ;;; can manually turn on this mode with M-x enable-paredit-mode and ;;; turn it off with M-x disable-paredit-mode. ;;; ;;; This is written for GNU Emacs. It is known not to work in XEmacs. ;;; The author wrote it with GNU Emacs 22.0.50; it may work in ;;; slightly earlier versions, but not older than 21 or so. An ;;; alternative minor mode, PAREDIT-TERMINAL-MODE, is provided that ;;; works in Emacs under Unix terminals (i.e. `emacs -nw'). ;;; ;;; This mode changes the keybindings for a number of simple keys, ;;; notably (, ), ", \, and ;. The round bracket keys are defined to ;;; insert parenthesis pairs and move past the close, respectively; ;;; the double-quote key is multiplexed to do both, and also insert an ;;; escape if within a string; backslashes prompt the user for the ;;; next character to input, because a lone backslash can break ;;; structure inadvertently; and semicolons ensure that they do not ;;; accidentally comment valid structure. (Use M-; to comment an ;;; expression.) These all have their ordinary behaviour when inside ;;; comments, and, outside comments, if truly necessary, you can insert ;;; them literally with C-q. ;;; ;;; It also changes several standard editing keybindings including ;;; RET, C-j, C-d, DEL, & C-k. RET & C-j are transposed from their ;;; usual paired meaning, where RET inserts a newline and C-j fancily ;;; adds a new line with indentation &c., but I find the transposition ;;; more convenient. (You are free to change this, of course.) C-d, ;;; DEL, & C-k are instrumented to respect the S-expression structure. ;;; You can, however, pass a prefix argument to them to get their ;;; usual behaviour if necessary; e.g., C-u C-k will kill the whole ;;; line, regardless of what S-expression structure there is on it. ;;; ;;; Automatic reindentation is performed as locally as possible, to ;;; ensure that Emacs does not interfere with custom indentation used ;;; elsewhere in some S-expression. It is performed only by the ;;; advanced S-expression frobnication commands, and only on the forms ;;; that were immediately operated upon (& their subforms). ;;; ;;; This code is written for clarity, not efficiency. S-expressions ;;; are frequently walked over redundantly. If you have problems with ;;; some of the commands taking too long to execute, tell me, but first ;;; make sure that what you're doing is reasonable: it is stylistically ;;; bad to have huge, long, hideously nested code anyway. ;;; ;;; Questions, bug reports, comments, feature suggestions, &c., can be ;;; addressed to the author via mail on the host mumble.net to campbell ;;; or via IRC on irc.freenode.net in #emacs, #scheme, or #lisp, under ;;; the nick Riastradh. ;;; This assumes Unix-style LF line endings. (defconst paredit-version 15) ;;; Minor mode definition ;;; Pretend that this were organized in the natural manner, with the ;;; most important bit first -- the minor mode definitions --, and then ;;; the keymaps. DEFINE-MINOR-MODE doesn't seem to like this, however. (defvar paredit-mode-map (let ((keymap (make-sparse-keymap))) (define-key keymap "(" 'paredit-open-list) (define-key keymap ")" 'paredit-close-list-and-newline) (define-key keymap (kbd "M-)") 'paredit-close-list) (define-key keymap (kbd "M-\"") 'paredit-close-string-and-newline) (define-key keymap "\"" 'paredit-doublequote) (define-key keymap "\\" 'paredit-backslash) (define-key keymap ";" 'paredit-semicolon) (define-key keymap (kbd "M-;") 'paredit-comment-dwim) ;; This defies ordinary conventions, but I believe it is justified ;; and more convenient this way, to have RET be fancy and C-j ;; insert a vanilla newline. You can always change this in your ;; .emacs if you want the conventional configuration, however. (define-key keymap (kbd "RET") 'paredit-newline) (define-key keymap (kbd "C-j") 'newline) (define-key keymap (kbd "C-d") 'paredit-forward-delete) (define-key keymap (kbd "<deletechar>") 'paredit-forward-delete) (define-key keymap (kbd "DEL") 'paredit-backward-delete) (define-key keymap (kbd "C-k") 'paredit-kill) (define-key keymap (kbd "C-M-f") 'paredit-forward) (define-key keymap (kbd "C-M-b") 'paredit-backward) (define-key keymap (kbd "C-c C-M-l") 'paredit-recentre-on-sexp) ;; The default keybindings in this area are: ;; C-up forward-paragraph ;; C-down backward-paragraph ;; C-M-up backward-up-list ;; C-M-down down-list ;; C-right M-right forward-word ;; C-left M-left backward-word ;; This all seems rather inconsistent to me. I'm not worried about ;; overriding C-up & C-down here, because paragraph commands are ;; not very useful in Lisp code, and C-left & C-right, because they ;; already have aliases with meta instead of control. ;; ;; Chosen here is for C-{up,down} to ascend a list, where C-up goes ;; in a direction usually upward with respect to the window (it ;; will often end up in a line above the current one), i.e. it will ;; use BACKWARD-UP-LIST, and where the converse is true of C-down. ;; C-M-{up,down}, then, descends in a similar manner. (define-key keymap (kbd "<C-up>") 'backward-up-list) (define-key keymap (kbd "<C-down>") 'up-list) (define-key keymap (kbd "<C-M-up>") 'backward-down-list) (define-key keymap (kbd "<C-M-down>") 'down-list) (define-key keymap (kbd "<C-right>") 'paredit-forward) (define-key keymap (kbd "<C-left>") 'paredit-backward) (define-key keymap (kbd "M-(") 'paredit-wrap-sexp) (define-key keymap (kbd "M-s") 'paredit-splice-sexp) (define-key keymap (kbd "<M-up>") 'paredit-splice-sexp-killing-backward) (define-key keymap (kbd "<M-down>") 'paredit-splice-sexp-killing-forward) (define-key keymap (kbd "M-r") 'paredit-raise-sexp) (define-key keymap (kbd "C-)") 'paredit-forward-slurp-sexp) (define-key keymap (kbd "C-}") 'paredit-forward-barf-sexp) (define-key keymap (kbd "C-(") 'paredit-backward-slurp-sexp) (define-key keymap (kbd "C-{") 'paredit-backward-barf-sexp) keymap) "Keymap for the paredit minor mode. Does not work in `emacs -nw' running under Unix terminals, only in Emacs with a window system.") (defvar paredit-terminal-mode-map (let ((keymap (make-sparse-keymap))) (set-keymap-parent keymap paredit-mode-map) ;; Bizarre terminal sequences for M-right, M-left, C-M-right, & ;; C-M-left, respectively. (define-key keymap (kbd "ESC <right>") 'paredit-forward-slurp-sexp) (define-key keymap (kbd "ESC <left>") 'paredit-forward-barf-sexp) (define-key keymap (kbd "ESC M-O d") 'paredit-backward-slurp-sexp) (define-key keymap (kbd "ESC M-O c") 'paredit-backward-barf-sexp) ;; These are the same as in the regular mode map, except that Emacs ;; doesn't recognize the correlation between what the terminal ;; sends it and what KBD gives for "<C-up>" &c.) (define-key keymap (kbd "ESC O a") 'backward-up-list) (define-key keymap (kbd "ESC O b") 'down-list) (define-key keymap (kbd "ESC M-O a") 'up-list) (define-key keymap (kbd "ESC M-O b") 'backward-down-list) (define-key keymap (kbd "ESC M-O c") 'paredit-forward) (define-key keymap (kbd "ESC M-O d") 'paredit-backward) (define-key keymap (kbd "ESC M-O A") 'paredit-splice-sexp-killing-backward) (define-key keymap (kbd "ESC M-O B") 'paredit-splice-sexp-killing-forward) keymap) "Keymap for the paredit minor mode. Works in `emacs -nw' running under Unix terminals.") ;++ Two separate minor modes here is a bit of a kludge. It would be ;++ nice if DEFINE-MINOR-MODE had an option for dynamically choosing a ;++ keymap when the mode is enabled. (define-minor-mode paredit-mode "Minor mode for pseudo-structurally editing Lisp code. Uses keybindings that will not work under a Unix terminal; see `paredit-terminal-mode' for an alternative set of keybindings that will work in `emacs -nw' running under a Unix terminal. \\{paredit-mode-map}" :lighter " Paredit") (define-minor-mode paredit-terminal-mode "Minor mode for pseudo-structurally editing Lisp code. Uses alternative keybindings that work in `emacs -nw' running under Unix terminals. \\{paredit-terminal-mode-map}" :lighter " Paredit(nw)") (defun enable-paredit-mode () "Turns on pseudo-structural editing of Lisp code. Uses `paredit-terminal-mode' if `window-system' is nil and `paredit-mode' if not." (interactive) (if window-system (paredit-mode 1) (paredit-terminal-mode 1))) (defun disable-paredit-mode () "Turns off pseudo-structural editing of Lisp code. Disables whichever of `paredit-mode' and `paredit-terminal-mode' is active in the current buffer, if either." (interactive) (paredit-mode -1) (paredit-terminal-mode -1)) ;;; ---------------- ;;; Basic editing commands (defun paredit-open-list (&optional n) "Inserts a balanced parenthesis pair. With a prefix argument N, puts the closing parentheses after N S-expressions forward. If in string or comment, inserts a single opening parenthesis. If in a character literal, does nothing. This prevents accidentally changing what was in the character literal to a meaningful delimiter unintentionally." (interactive "P") (cond ((or (paredit-in-string-p) (paredit-in-comment-p)) (insert "(")) ((not (paredit-in-char-p)) (insert-parentheses (or n 0))))) (defun paredit-close-list () "Moves past one closing parenthesis and reindents. If in a string or comment, inserts a single closing parenthesis. If in a character literal, does nothing. This prevents accidentally changing what was in the character literal to a meaningful delimiter unintentionally." (interactive) (cond ((or (paredit-in-string-p) (paredit-in-comment-p)) (insert ")")) ((not (paredit-in-char-p)) (paredit-move-past-close-and-reindent) (paredit-blink-paren-match nil)))) (defun paredit-close-list-and-newline () "Moves past one closing delimiter, adds a newline, and reindents. If there was a margin comment after the closing delimiter, preserves the margin comment on the same line." (interactive) (cond ((or (paredit-in-string-p) (paredit-in-comment-p)) (insert ")")) (t (if (paredit-in-char-p) (forward-char)) (paredit-move-past-close-and-reindent) (let ((comment.point (paredit-find-comment-on-line))) (newline) (if comment.point (save-excursion (forward-line -1) (end-of-line) (indent-to (cdr comment.point)) (insert (car comment.point))))) (lisp-indent-line) (condition-case () (indent-sexp) (scan-error nil)) (paredit-blink-paren-match t)))) (defun paredit-find-comment-on-line () "Finds a margin comment on the current line. If a comment exists, deletes the comment (including all leading whitespace) and returns a cons whose car is the comment as a string and whose cdr is the point of the comment's initial semicolon, relative to the start of the line." (save-excursion (catch 'return (while t (if (search-forward ";" (point-at-eol) t) (if (not (or (paredit-in-string-p) (paredit-in-char-p))) (let* ((start (progn (backward-char) ;before semicolon (point))) (comment (buffer-substring start (point-at-eol)))) (paredit-skip-whitespace nil (point-at-bol)) (delete-region (point) (point-at-eol)) (throw 'return (cons comment (- start (point-at-bol)))))) (throw 'return nil)))))) (defun paredit-move-past-close-and-reindent () "Moves one character past the next closing parenthesis. Deletes extraneous whitespace before the closing parenthesis. Comments are not deleted, however; if there is a comment between the point and the next closing parenthesis, the closing parenthesis is moved to the line after the comment and indented appropriately." (interactive) (let ((orig (point))) (up-list) (if (catch 'return ; This CATCH returns T if it (while t ; should delete leading spaces (save-excursion ; and NIL if not. (let ((before-paren (1- (point)))) (back-to-indentation) (cond ((not (eq (point) before-paren)) ;; Can't call PAREDIT-DELETE-LEADING-WHITESPACE ;; here -- we must return from SAVE-EXCURSION ;; first. (throw 'return t)) ((save-excursion (forward-line -1) (end-of-line) (paredit-in-comment-p)) ;; Moving the closing parenthesis any further ;; would put it into a comment, so we just ;; indent the closing parenthesis where it is ;; and abort the loop, telling its continuation ;; that no leading whitespace should be deleted. (lisp-indent-line) (throw 'return nil)) (t (delete-indentation))))))) (paredit-delete-leading-whitespace)))) (defun paredit-delete-leading-whitespace () ;; This assumes that we're on the closing parenthesis already. (save-excursion (backward-char) (while (let ((syn (char-syntax (char-before)))) (and (or (eq syn ?\ ) (eq syn ?-)) ; whitespace syntax ;; The above line is a perfect example of why the ;; following test is necessary. (not (paredit-in-char-p (1- (point)))))) (backward-delete-char 1)))) (defun paredit-blink-paren-match (absolutely-p) (if (or absolutely-p blink-matching-paren) (condition-case () (save-excursion (backward-sexp) (forward-sexp) (let ((blink-matching-paren-on-screen t)) (blink-matching-open))) (scan-error nil)))) (defun paredit-close-string-and-newline () "Moves to the end of the string, inserts a newline, and indents. If not in a string, acts as `paredit-doublequote'." (interactive) (if (not (paredit-in-string-p)) (paredit-doublequote) (let ((start+end (paredit-string-start+end-points))) (goto-char (1+ (cdr start+end))) (newline) (lisp-indent-line) (condition-case () (indent-sexp) (scan-error nil))))) (defun paredit-doublequote () "Inserts a pair of double-quotes. Inside a comment, inserts a literal double-quote. At the end of a string, moves past the closing double-quote. In the middle of a string, inserts a backslash-escaped double-quote. If in a character literal, does nothing. This prevents accidentally changing a what was in the character literal to a meaningful delimiter unintentionally." (interactive) (cond ((paredit-in-string-p) (if (eq (cdr (paredit-string-start+end-points)) (point)) (forward-char) ; We're on the closing quote. (insert ?\\ ?\" ))) ((paredit-in-comment-p) (insert ?\" )) ((not (paredit-in-char-p)) (let ((insert-space (lambda (endp delim-syn) (if (and (not (if endp (eobp) (bobp))) (memq (char-syntax (if endp (char-after) (char-before))) (list ?w ?_ ?\" delim-syn))) (insert " "))))) (funcall insert-space nil ?\) ) (insert ?\" ) (save-excursion (insert ?\" ) (funcall insert-space t ?\( )))))) (defun paredit-backslash () "Inserts a backslash followed by a character to escape." (interactive) (insert ?\\ ) ;; This funny conditional is necessary because PAREDIT-IN-COMMENT-P ;; assumes that PAREDIT-IN-STRING-P already returned false; otherwise ;; it may give erroneous answers. (if (or (paredit-in-string-p) (not (paredit-in-comment-p))) (let ((delp t)) (unwind-protect (setq delp (call-interactively #'paredit-escape)) ;; We need this in an UNWIND-PROTECT so that the backlash is ;; left in there *only* if PAREDIT-ESCAPE return NIL normally ;; -- in any other case, such as the user hitting C-g or an ;; error occurring, we must delete the backslash to avoid ;; leaving a dangling escape. (This control structure is a ;; crock. (if delp (backward-delete-char 1)))))) ;;; This auxiliary interactive function returns true if the backslash ;;; should be deleted and false if not. (defun paredit-escape (char) ;; I'm too lazy to figure out how to do this without a separate ;; interactive function. (interactive "cEscaping character...") (if (eq char 127) ; The backslash was a typo, so t ; the luser wants to delete it. (insert char) ; (Is there a better way to nil)) ; express the rubout char? ; ?\^? works, but ugh...) (defun paredit-semicolon (&optional arg) "Insert a comment beginning, moving other items on the line. If in a string, comment, or character literal, or with a prefix argument, inserts just a literal semicolon and does not move anything to the next line." (interactive "P") (if (not (or (paredit-in-string-p) (paredit-in-comment-p) (paredit-in-char-p) arg ;; No more code on the line after the point. (save-excursion (paredit-skip-whitespace t (point-at-eol)) (eq (point) (point-at-eol))))) ;; Don't use NEWLINE-AND-INDENT, because that will delete all of ;; the horizontal whitespace first, but we just want to move the ;; code following the point onto the next line while preserving ;; the point on this line. (save-excursion (newline) (lisp-indent-line))) (insert ";")) (defun paredit-comment-dwim (&optional arg) "Calls the Lisp comment command you want (Do What I Mean). This is like `comment-dwim', but it is specialized for Lisp editing. If transient mark mode is enabled and the mark is active, comments or uncomments the selected region, depending on whether it was entirely commented not not already. If there is already a comment on the current line, with no prefix argument, indents to that comment; with a prefix argument, kills that comment. Otherwise, inserts a comment appropriate for the context and ensures that any code following the comment is moved to the next line. At the top level, where indentation is calculated to be at column 0, this inserts a triple-semicolon comment; within code, where the indentation is calculated to be non-zero, and there is either no code on the line or code after the point on the line, inserts a double- semicolon comment; and if the point is after all code on the line, inserts a single-semicolon margin comment at `comment-column'." (interactive "*P") (comment-normalize-vars) (cond ((and mark-active transient-mark-mode) (comment-or-uncomment-region (region-beginning) (region-end) arg)) ((paredit-comment-on-line-p) (if arg (comment-kill (if (integerp arg) arg nil)) (comment-indent))) (t (paredit-insert-comment)))) (defun paredit-comment-on-line-p () (save-excursion (goto-char (point-at-bol)) (let ((comment-p nil)) ;; Search forward for a comment beginning. If there is one, set ;; COMMENT-P to true; if not, it will be nil. (while (progn (setq comment-p (search-forward ";" (point-at-eol) ;; t -> no error t)) (and comment-p (or (paredit-in-string-p) (paredit-in-char-p (1- (point)))))) (forward-char)) comment-p))) (defun paredit-insert-comment () (let ((code-after-p (save-excursion (paredit-skip-whitespace t (point-at-eol)) (not (eq (point) (point-at-eol))))) (code-before-p (save-excursion (paredit-skip-whitespace nil (point-at-bol)) (not (eq (point) (point-at-bol)))))) ;; We have to use EQ 0 here and not ZEROP because ZEROP signals an ;; error if its argument is non-numeric, but CALCULATE-LISP-INDENT ;; may return nil. (if (eq (let ((indent (calculate-lisp-indent))) (if (consp indent) (car indent) indent)) 0) ;; Top-level comment (progn (if code-after-p (save-excursion (newline))) (insert ";;; ")) (if code-after-p ;; Code comment (progn (if code-before-p (newline-and-indent)) (lisp-indent-line) (insert ";; ") ;; Move the following code. (NEWLINE-AND-INDENT will ;; delete whitespace after the comment, though, so use ;; NEWLINE & LISP-INDENT-LINE manually here.) (save-excursion (newline) (lisp-indent-line))) ;; Margin comment (progn (indent-to comment-column 1) ; 1 -> force one space after (insert "; ")))))) (defun paredit-newline () "Inserts a newline and indents it. This is like `newline-and-indent', but it not only indents the line that the point is on but also the S-expression following the point, if there is one. Moves forward one character first if on an escaped character. If in a string, just inserts a literal newline." (interactive) (if (paredit-in-string-p) (newline) (if (and (not (paredit-in-comment-p)) (paredit-in-char-p)) (forward-char)) (newline-and-indent) ;; Indent the following S-expression, but don't signal an error if ;; there's only a closing parenthesis after the point. (condition-case () (indent-sexp) (scan-error nil)))) (defun paredit-forward-delete (&optional arg) "Deletes a character forward or moves forward over a delimiter. If on an opening S-expression delimiter, moves forward into the S-expression. If on a closing S-expression delimiter, refuses to delete unless the S-expression is empty, in which case the whole S-expression is deleted. With a prefix argument, simply deletes a character forward, without regard for delimiter balancing." (interactive "P") (cond ((or arg (eobp)) (delete-char 1)) ((paredit-in-string-p) (paredit-forward-delete-in-string)) ((paredit-in-comment-p) ;++ What to do here? This could move a partial S-expression ;++ into a comment and thereby invalidate the file's form, ;++ or move random text out of a comment. (delete-char 1)) ((paredit-in-char-p) ; Escape -- delete both chars. (backward-delete-char 1) (delete-char 1)) ((eq (char-after) ?\\ ) ; ditto (delete-char 2)) ((let ((syn (char-syntax (char-after)))) (or (eq syn ?\( ) (eq syn ?\" ))) (forward-char)) ((and (not (paredit-in-char-p (1- (point)))) (eq (char-syntax (char-after)) ?\) ) (eq (char-before) (matching-paren (char-after)))) (backward-delete-char 1) ; Empty list -- delete both (delete-char 1)) ; delimiters. ;; Just delete a single character, if it's not a closing ;; parenthesis. (The character literal case is already ;; handled by now.) ((not (eq (char-syntax (char-after)) ?\) )) (delete-char 1)))) (defun paredit-forward-delete-in-string () (let ((start+end (paredit-string-start+end-points))) (cond ((not (eq (point) (cdr start+end))) ;; If it's not the close-quote, it's safe to delete. But ;; first handle the case that we're in a string escape. (cond ((paredit-in-string-escape-p) ;; We're right after the backslash, so backward ;; delete it before deleting the escaped character. (backward-delete-char 1)) ((eq (char-after) ?\\ ) ;; If we're not in a string escape, but we are on a ;; backslash, it must start the escape for the next ;; character, so delete the backslash before deleting ;; the next character. (delete-char 1))) (delete-char 1)) ((eq (1- (point)) (cdr start+end)) ;; If it is the close-quote, delete only if we're also right ;; past the open-quote (i.e. it's empty), and then delete ;; both quotes. Otherwise we refuse to delete it. (backward-delete-char 1) (delete-char 1))))) (defun paredit-backward-delete (&optional arg) "Deletes a character backward or moves backward over a delimiter. If on a closing S-expression delimiter, moves backward into the S-expression. If on an opening S-expression delimiter, refuses to delete unless the S-expression is empty, in which case the whole S-expression is deleted. With a prefix argument, simply deletes a character backward, without regard for delimiter balancing." (interactive "P") (cond ((or arg (bobp)) (backward-delete-char 1)) ;++ should this untabify? ((paredit-in-string-p) (paredit-backward-delete-in-string)) ((paredit-in-comment-p) (backward-delete-char 1)) ((paredit-in-char-p) ; Escape -- delete both chars. (backward-delete-char 1) (delete-char 1)) ((paredit-in-char-p (1- (point))) (backward-delete-char 2)) ; ditto ((let ((syn (char-syntax (char-before)))) (or (eq syn ?\) ) (eq syn ?\" ))) (backward-char)) ((and (eq (char-syntax (char-before)) ?\( ) (eq (char-after) (matching-paren (char-before)))) (backward-delete-char 1) ; Empty list -- delete both (delete-char 1)) ; delimiters. ;; Delete it, unless it's an opening parenthesis. The case ;; of character literals is already handled by now. ((not (eq (char-syntax (char-before)) ?\( )) (backward-delete-char-untabify 1)))) (defun paredit-backward-delete-in-string () (let ((start+end (paredit-string-start+end-points))) (cond ((not (eq (1- (point)) (car start+end))) ;; If it's not the open-quote, it's safe to delete. (if (paredit-in-string-escape-p) ;; If we're on a string escape, since we're about to ;; delete the backslash, we must first delete the ;; escaped char. (delete-char 1)) (backward-delete-char 1) (if (paredit-in-string-escape-p) ;; If, after deleting a character, we find ourselves in ;; a string escape, we must have deleted the escaped ;; character, and the backslash is behind the point, so ;; backward delete it. (backward-delete-char 1))) ((eq (point) (cdr start+end)) ;; If it is the open-quote, delete only if we're also right ;; past the close-quote (i.e. it's empty), and then delete ;; both quotes. Otherwise we refuse to delete it. (backward-delete-char 1) (delete-char 1))))) (defun paredit-kill (&optional arg) "Kills a line as if with `kill-line', but respecting delimiters. In a string, acts exactly as `kill-line' but will not kill past the closing string delimiter. On a line with no S-expressions on it starting after the point or within a comment, acts exactly as `kill-line'. Otherwise, kills all S-expressions that start after the point." (interactive "P") (cond (arg (kill-line)) ((paredit-in-string-p) (paredit-kill-line-in-string)) ((or (paredit-in-comment-p) (save-excursion (paredit-skip-whitespace t (point-at-eol)) (or (eq (char-after) ?\; ) (eolp)))) ;** Be careful about trailing backslashes. (kill-line)) (t (paredit-kill-sexps-on-line)))) (defun paredit-kill-line-in-string () (if (save-excursion (paredit-skip-whitespace t (point-at-eol)) (eolp)) (kill-line) (save-excursion ;; Be careful not to split an escape sequence. (if (paredit-in-string-escape-p) (backward-char)) (let ((beg (point))) (while (not (or (eolp) (eq (char-after) ?\" ))) (forward-char) ;; Skip past escaped characters. (if (eq (char-before) ?\\ ) (forward-char))) (kill-region beg (point)))))) (defun paredit-kill-sexps-on-line () (if (paredit-in-char-p) ; Move past the \ and prefix. (backward-char 2)) ; (# in Scheme/CL, ? in elisp) (let ((beg (point)) (eol (point-at-eol)) (end-of-list-p (paredit-forward-sexps-to-kill))) ;; If we got to the end of the list and it's on the same line, ;; move backward past the closing delimiter before killing. (This ;; allows something like killing the whitespace in ( ).) (if end-of-list-p (progn (up-list) (backward-char))) (if kill-whole-line (paredit-kill-sexps-on-whole-line beg) (kill-region beg ;; If all of the S-expressions were on one line, ;; i.e. we're still on that line after moving past ;; the last one, kill the whole line, including ;; any comments; otherwise just kill to the end of ;; the last S-expression we found. Be sure, ;; though, not to kill any closing parentheses. (if (and (not end-of-list-p) (eq (point-at-eol) eol)) eol (point)))))) (defun paredit-forward-sexps-to-kill () (let ((beg (point)) (eol (point-at-eol)) (end-of-list-p nil)) ;; Move to the end of the last S-expression that started on this ;; line, or to the closing delimiter if the last S-expression in ;; this list is on the line. (catch 'return (while (and (not (eobp)) (save-excursion (condition-case () (forward-sexp) (scan-error (up-list) (setq end-of-list-p (eq (point-at-eol) eol)) (throw 'return nil))) ;; We have to deal with a weird special case here ;; of kill (and (condition-case () (progn (backward-sexp) t) (scan-error nil)) (eq (point-at-eol) eol)))) (forward-sexp))) end-of-list-p)) (defun paredit-kill-sexps-on-whole-line (beg) (kill-region beg (or (save-excursion ; Delete trailing indentation... (paredit-skip-whitespace t) (and (not (eq (char-after) ?\; )) (point))) ;; ...or just use the point past the newline, if ;; we encounter a comment. (point-at-eol))) (cond ((save-excursion (paredit-skip-whitespace nil (point-at-bol)) (bolp)) ;; Nothing but indentation before the point, so indent it. (lisp-indent-line)) ((eobp) nil) ; Protect the CHAR-SYNTAX below against NIL. ;; Insert a space to avoid invalid joining if necessary. ((let ((syn-before (char-syntax (char-before))) (syn-after (char-syntax (char-after)))) (or (and (eq syn-before ?\) ) ; Separate opposing (eq syn-after ?\( )) ; parentheses, (and (eq syn-before ?\" ) ; string delimiter (eq syn-after ?\" )) ; pairs, (and (memq syn-before '(?_ ?w)) ; or word or symbol (memq syn-after '(?_ ?w))))) ; constituents. (insert " ")))) ;;; ---------------- ;;; Cursor and screen movement (defun paredit-forward () "Moves forward an S-expression, or up an S-expression forward. If there are no more S-expressions in this one before the closing delimiter, will move past that closing delimiter; otherwise, will move forward past the S-expression following the point." (interactive) (condition-case () (forward-sexp) (scan-error (if (paredit-in-string-p) (forward-char) (up-list))))) (defun paredit-backward () "Moves backward an S-expression, or up an S-expression backward. If there are no more S-expressions in this one before the opening delimiter, will move past that opening delimiter backward; otherwise, will move backward past the S-expression preceding the point." (interactive) (condition-case () (backward-sexp) (scan-error (if (paredit-in-string-p) (backward-char) (backward-up-list))))) ;;; Why is this not in lisp.el? (defun backward-down-list (&optional arg) "Move backward and descend into one level of parentheses. With ARG, do this that many times. A negative argument means move forward but still descend a level." (interactive "p") (down-list (- (or arg 1)))) ;;; Thanks to Marco Baringer for suggesting & writing this function. (defun paredit-recentre-on-sexp (&optional n) "Recentres the screen on the S-expression following the point. With a prefix argument N, encompasses all N S-expressions forward." (interactive "P") (forward-sexp n) (let ((end-point (point))) (backward-sexp n) (let* ((start-point (point)) (start-line (count-lines (point-min) (point))) (lines-on-sexps (count-lines start-point end-point))) (goto-line (+ start-line (/ lines-on-sexps 2))) (recenter)))) ;;; ---------------- ;;; Wrappage, splicage, & raisage (defun paredit-wrap-sexp (&optional n) "Wraps the following S-expression in a list. If a prefix argument N is given, N S-expressions are wrapped. Automatically indents the newly wrapped S-expression. As a special case, if at the end of a list, will simply insert a pair of parentheses, rather than insert a lone opening parenthesis and then signal an error, in the interest of preserving structural validity." (interactive "p") (condition-case () (insert-parentheses (or n 1)) (scan-error (insert ?\) ) (backward-char))) (save-excursion (backward-up-list) (indent-sexp))) ;;; Thanks to Marco Baringer for the suggestion of a prefix argument ;;; for PAREDIT-SPLICE-SEXP. (I, Taylor Campbell, however, still ;;; implemented it, in case any of you lawyer-folk get confused by the ;;; remark in the top of the file about explicitly noting code written ;;; by other people.) (defun paredit-splice-sexp (&optional arg) "Splices the list that the point is on by removing its delimiters. With a prefix argument as in `C-u', kills all S-expressions backward in the current list before splicing all S-expressions forward into the enclosing list. With two prefix arguments as in `C-u C-u', kills all S-expressions forward in the current list before splicing all S-expressions backward into the enclosing list. With a numerical prefix argument N, kills N S-expressions backward in the current list before splicing the remaining S-expressions into the enclosing list. If N is negative, kills forward." (interactive "P") (save-excursion (paredit-kill-surrounding-sexps-for-splice arg) (backward-up-list) ; Go up to the beginning... (save-excursion (forward-sexp) ; Go forward an expression, to (backward-delete-char 1)) ; delete the end delimiter. (delete-char 1) ; ...to delete the open char. (condition-case () (progn (backward-up-list) ; Reindent, now that the (indent-sexp)) ; structure has changed. (scan-error nil)))) (defun paredit-kill-surrounding-sexps-for-splice (arg) (if (and arg (not (eq arg 0))) (cond ((numberp arg) ;; Kill ARG S-expressions before/after the point by saving ;; the point, moving across them, and killing the region. (let ((saved (point))) (condition-case () (backward-sexp arg) (scan-error nil)) (if (< arg 0) (kill-region saved (point)) (kill-region (point) saved)))) ((consp arg) (let ((v (car arg))) (if (= v 4) ; one prefix argument ;; Move backward until we hit the open paren; then ;; kill that selected region. (let ((end (point))) (condition-case () (while (not (bobp)) (backward-sexp)) (scan-error nil)) (kill-region (point) end)) ;; Move forward until we hit the close paren; then ;; kill that selected region. (let ((beg (point))) (condition-case () (while (not (eobp)) (forward-sexp)) (scan-error nil)) (kill-region beg (point)))))) (t (error "Bizarre prefix argument: %s" arg))))) (defun paredit-splice-sexp-killing-backward (&optional n) "Splices the list the point is on by removing its delimiters, and also kills all S-expressions before the point in the current list. With a prefix argument N, kills only the preceding N S-expressions." (interactive "P") (paredit-splice-sexp (if n (prefix-numeric-value n) '(4)))) (defun paredit-splice-sexp-killing-forward (&optional n) "Splices the list the point is on by removing its delimiters, and also kills all S-expressions after the point in the current list. With a prefix argument N, kills only the following N S-expressions." (interactive "P") (paredit-splice-sexp (if n (- (prefix-numeric-value n)) '(16)))) (defun paredit-raise-sexp (&optional n) "Raises the following S-expression in a tree, deleting its siblings. With a prefix argument N, raises the following N S-expressions. If N is negative, raises the preceding N S-expressions." (interactive "p") ;; Select the S-expressions we want to raise in a buffer substring. (let* ((bound (save-excursion (forward-sexp n) (point))) (sexps (if (and n (< n 0)) ;; We backward & forward over one S-expression in ;; order to get to the exact beginning or exact end ;; of it, not wherever the point happened to be. (buffer-substring bound (save-excursion (backward-sexp) (forward-sexp) (point))) (buffer-substring (save-excursion (forward-sexp) (backward-sexp) (point)) bound)))) ;; Move up to the list we're raising those S-expressions out of and ;; delete it. (backward-up-list) (delete-region (point) (save-excursion (forward-sexp) (point))) (save-excursion (insert sexps)) ; Insert & reindent the sexps. (save-excursion (let ((n (abs (or n 1)))) (while (> n 0) (paredit-forward-and-indent) (setq n (1- n))))))) ;;; ---------------- ;;; Slurpage & barfage (defun paredit-forward-slurp-sexp () "Adds the S-expression following the current list into that list by moving the closing delimiter. Automatically reindents the newly slurped S-expressions with respect to their new enclosing form." (interactive) (save-excursion (up-list) ; Up to the end of the list to (let ((close (char-before))) ; save and delete the closing (backward-delete-char 1) ; delimiter. (catch 'return ; Go to the end of the desired (while t ; S-expression, going up a (condition-case () ; list if it's not in this, (progn (paredit-forward-and-indent) (throw 'return nil)) (scan-error (up-list))))) (insert close)))) ; to insert that delimiter. (defun paredit-forward-barf-sexp () "Removes the last S-expression in the current list from that list by moving the closing delimiter. Automatically reindents all of the newly barfed S-expressions with respect to their new enclosing form." (interactive) (save-excursion (up-list) ; Up to the end of the list to (let ((close (char-before))) ; save and delete the closing (backward-delete-char 1) ; delimiter. (condition-case () ; Go back to where we want to (backward-sexp) ; insert the delimiter. (scan-error nil)) ; Ignore scan errors, and (paredit-skip-whitespace nil) ; skip leading whitespace. (cond ((bobp) (error "Barfing all subexpressions with no open-paren?")) ((paredit-in-comment-p) ; Don't put the close-paren in (newline-and-indent))) ; a comment. (insert close)) ;; Reindent all of the newly barfed S-expressions. (paredit-forward-and-indent))) (defun paredit-backward-slurp-sexp () "Adds the S-expression preceding the current list into that list by moving the closing delimiter. Automatically reindents the whole form into which new S-expression was slurped." (interactive) (save-excursion (backward-up-list) (let ((open (char-after))) (delete-char 1) (catch 'return (while t (condition-case () (progn (backward-sexp) (throw 'return nil)) (scan-error (backward-up-list))))) (insert open)) ;; Reindent the line at the beginning of wherever we inserted the ;; opening parenthesis, and then indent the whole S-expression. (backward-up-list) (lisp-indent-line) (indent-sexp))) (defun paredit-backward-barf-sexp () "Removes the first S-expression in the current list from that list by moving the closing delimiter. Automatically reindents the barfed S-expression and the form from which it was barfed." (interactive) ;; SAVE-EXCURSION here does the wrong thing, but manually saving and ;; restoring the point does the right thing. Here's an example of ;; how SAVE-EXCURSION breaks: ;; (foo|) C-{ ;; foo|() ;; It should be: ;; foo(|) (let ((beg (point))) (unwind-protect (progn (backward-up-list) (let ((open (char-after))) (delete-char 1) (condition-case () (paredit-forward-and-indent) (scan-error nil)) (while (progn (paredit-skip-whitespace t) (eq (char-after) ?\; )) (goto-char (1+ (point-at-eol)))) (if (eobp) (error "Barfing all subexpressions with no close-paren?")) (insert open)) (backward-up-list) (lisp-indent-line) (indent-sexp)) (goto-char beg)))) ;;; ---------------- ;;; Several utility functions (defun paredit-in-string-p () "True if the point is within a double-quote-delimited string." (save-excursion (let ((orig (point))) (beginning-of-defun) ;; Item 3 of the list PARSE-PARTIAL-SEXP returns is true if the ;; point at the second argument is in a string, otherwise false. (nth 3 (parse-partial-sexp (point) orig))))) (defun paredit-string-start+end-points () "Returns a cons of the points of the open and quotes of this string. This assumes that `paredit-in-string-p' has already returned true, i.e. that the point is already within a string." (save-excursion (let ((orig (point))) (beginning-of-defun) (let* ((state (parse-partial-sexp (point) orig)) (start (nth 8 state))) (goto-char start) (forward-sexp) (cons start (1- (point))))))) (defun paredit-in-string-escape-p () "True if the point is on a character escape of a string. This is true only if the character is preceded by an odd number of backslashes. This assumes that `paredit-in-string-p' has already returned true." (let ((oddp nil)) (save-excursion (while (eq (char-before) ?\\ ) (setq oddp (not oddp)) (backward-char))) oddp)) (defun paredit-in-comment-p () "True if the point is within a Lisp line comment. This assumes that `paredit-in-string-p' has already returned false." ;++ Make this work on block comments? (save-excursion (let ((orig (point)) (res nil)) (goto-char (point-at-bol)) ;; The second T argument to SEARCH-FORWARD says to return NIL, ;; not to signal an error, if no match is found. (while (progn (setq res (search-forward ";" orig t)) (and res (or (paredit-in-string-p) (paredit-in-char-p (1- (point)))))) (forward-char)) (and res (<= res orig))))) (defun paredit-in-char-p (&optional arg) "True if the point is immediately after a character literal. A preceding escape character, not preceded by another escape character, is considered a character literal prefix. (This works for elisp, Common Lisp, and Scheme.) Assumes that `paredit-in-string-p' is false, so that it need not handle long sequences of preceding backslashes in string escapes. (This assumes some other leading character token -- ? in elisp, # in Scheme and Common Lisp.)" (let ((arg (or arg (point)))) (and (eq (char-before arg) ?\\ ) (not (eq (char-before (1- arg)) ?\\ ))))) (defun paredit-forward-and-indent () "Moves forward an S-expression, indenting it fully. Indents with `lisp-indent-line' and then `indent-sexp'." (forward-sexp) ; Go forward, and then find the (save-excursion ; beginning of this next (backward-sexp) ; S-expression. (lisp-indent-line) ; Indent its opening line, and (indent-sexp))) ; the rest of it. (defun paredit-skip-whitespace (trailing-p &optional limit) "Skips past any whitespace, or until the point LIMIT is reached. If TRAILING-P is nil, skips leading whitespace; otherwise, skips trailing whitespace." (funcall (if trailing-p #'skip-chars-forward #'skip-chars-backward) " \t\n " ; This should skip using the syntax table, but LF limit)) ; is a comment end, not newline, in Lisp mode. (provide 'paredit)
49,044
Common Lisp
.l
1,038
38.876686
72
0.609582
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
f1ffd843237d01a077bd41cf68082ef27e41253a43d5a41caa8a156c6ec8e44d
8,423
[ -1 ]
8,424
top-mode.el
evrim_core-server/etc/emacs/top-mode.el
;;; top-mode.el --- run "top" from emacs ;; Author: Benjamin Rutt ;; Created: Jul 18, 2004 ;; Keywords: extensions, processes ;; top-mode.el is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; top-mode.el 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 General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; This code runs top from within emacs (using top's batch mode), and ;; provides functionality to operate on processes. ;; In order to run it, just execute M-x top. Unlike real top, the ;; resulting buffer doesn't refresh automatically (yet, it's a feature ;; I'd like to add someday). You can refresh the buffer manually by ;; pressing 'g'. If you'd like to mark processes for later actions, ;; use 'm' to mark or 'u' to unmark. If no processes are marked, the ;; default action will apply to the process at the current line. At ;; the time of this writing, the valid actions are: ;; ;; -strace a process ;; -kill processes ;; -renice processes ;; You can also toggle showing processes of a specific user by ;; pressing 'U'. ;; ;; NOTE: tested only on Debian GNU/Linux unstable and solaris 8. ;; ;; Should work out of the box for Debian's version of 'top', however ;; for solaris 8's version of top, I found the following settings to ;; be useful: ;; ;; (defun top-mode-solaris-generate-top-command (user) ;; (if (not user) ;; "top -b" ;; (format "top -b -U%s" user))) ;; (setq top-mode-generate-top-command-function ;; 'top-mode-solaris-generate-top-command) ;; (setq top-mode-strace-command "truss") ;;; Code: (defgroup top-mode nil "Emacs frontend to the top command, which monitors system processes." :group 'processes) (defcustom top-mode-generate-top-command-function 'top-mode-generate-top-command-default "*Which function to be called to produce the command line for running top on your machine. The function will be called with one argument, USER, which will either be a string specifying that the processes owned by USER should be shown, or nil, meaning that all processes should be shown." :type 'function :group 'top-mode) (defcustom top-mode-column-header-regexp "^\\s-+PID\\s-+USER.*COMMAND\\s-*$" "*Regexp to match the column header line, which helps this package to identify where the list of processes begins." :type 'regexp :group 'top-mode) (defcustom top-mode-mark-face 'highlight "*Face with which to mark lines." :type 'face :group 'top-mode) (defcustom top-mode-strace-command "strace" "*System call tracer (probably set this to \"truss\" on Solaris, etc)." :type 'string :group 'top-mode) ;; internals (defvar top-mode-specific-user nil) (defvar top-mode-overlay-list nil) (defvar top-mode-generate-top-command-default-user-arg 'unknown) (defun top-mode-generate-top-command-default (user) (if (not user) "top -b -n 1" ;; try "-u" argument, and set cache variable based on result (if (eq top-mode-generate-top-command-default-user-arg 'unknown) (let ((result (shell-command (format "top -b -n 1 -u %s >/dev/null" user-login-name)))) (if (= result 0) (setq top-mode-generate-top-command-default-user-arg 'yes) (setq top-mode-generate-top-command-default-user-arg 'no)))) (cond ((eq top-mode-generate-top-command-default-user-arg 'yes) (format "top -b -n 1 -u %s" user)) ;; fall back on "awk"ward manual removal of commands not owned by ;; the user ((eq top-mode-generate-top-command-default-user-arg 'no) (format "top -b -n 1 | awk 'BEGIN { seenColumnLine=0; } { if (seenColumnLine==0) { print } else if ($2 == \"%s\") { print }; if ($0 ~ /PID.*USER.*COMMAND/) { seenColumnLine=1; } }'" user))))) (defvar top-mode-map nil ; Create a mode-specific keymap. "Keymap for Top mode.") (if top-mode-map () ; Do not change the keymap if it is already set up. (setq top-mode-map (make-sparse-keymap)) (define-key top-mode-map "n" 'top-mode-next-line) (define-key top-mode-map "p" 'top-mode-previous-line) (define-key top-mode-map "g" 'top) (define-key top-mode-map "q" 'quit-window) (define-key top-mode-map "k" 'top-mode-kill) (define-key top-mode-map "K" 'top-mode-kill-noconfirm) (define-key top-mode-map "s" 'top-mode-strace) (define-key top-mode-map "S" 'top-mode-strace-noconfirm) (define-key top-mode-map "r" 'top-mode-renice) (define-key top-mode-map "R" 'top-mode-renice-noconfirm) (define-key top-mode-map "m" 'top-mode-mark) (define-key top-mode-map "u" 'top-mode-unmark) (define-key top-mode-map "U" 'top-mode-show-specific-user)) (defun top-mode () "Major mode for running top and interacting with processes." (interactive) (kill-all-local-variables) (use-local-map top-mode-map) (setq mode-name "Top") (setq major-mode 'top-mode) ;; the following two expressions don't work in concert with ;; global-auto-revert-mode, maybe someone can help? ;; (set (make-local-variable 'revert-buffer-function) ;; 'top-mode-revert-buffer-function) ;; (set (make-local-variable 'buffer-stale-function) ;; 'top-mode-buffer-stale-function) ;; fix for too long lines (when (not window-system) (setq truncate-lines t))) (defun top-mode-revert-buffer-function (&optional ignore-auto noconfirm) (when (or noconfirm (y-or-n-p "Revert *top* buffer? ")) (top))) (defun top-mode-buffer-stale-function (&optional noconfirm) t) ;; line-at-pos is in emacs CVS as of 21.3.50 but define it for older ;; emacsen (when (not (fboundp 'line-at-pos)) (defun line-at-pos (&optional pos) "Return (narrowed) buffer line number at position POS. If POS is nil, use current buffer location." (let ((opoint (or pos (point))) start) (save-excursion (goto-char (point-min)) (setq start (point)) (goto-char opoint) (forward-line 0) (1+ (count-lines start (point))))))) (defun top-mode-next-line () (interactive) (next-line 1)) (defun top-mode-previous-line () (interactive) (previous-line 1)) (defun top-mode-fill-buffer (goto-first-process) (switch-to-buffer (get-buffer-create "*top*")) (setq buffer-read-only nil) (erase-buffer) (let ((old-term-env (getenv "TERM")) (output nil)) (unwind-protect (progn (setenv "TERM" "dumb") (setq output (shell-command-to-string (funcall top-mode-generate-top-command-function top-mode-specific-user)))) (setenv "TERM" old-term-env)) (if (not output) (kill-buffer (get-buffer-create "*top*")) (insert output) (when goto-first-process (goto-char (point-min)) (re-search-forward top-mode-column-header-regexp nil t) (next-line 1) (top-mode-goto-pid)) (setq buffer-read-only t) (top-mode)))) (defun top () "Runs 'top' in an emacs buffer." (interactive) (let* ((already-in-top (equal major-mode 'top-mode)) (preserved-line (if already-in-top (line-at-pos) nil)) (preserved-col (if already-in-top (current-column) nil)) (preserved-window-start (window-start))) (if already-in-top (progn (top-mode-fill-buffer nil) (set-window-start (selected-window) preserved-window-start) (goto-line preserved-line) (move-to-column preserved-col)) (top-mode-fill-buffer t)))) (defsubst top-mode-string-trim (string) "Lose leading and trailing whitespace. Also remove all properties from string." (if (string-match "\\`[ \t\n]+" string) (setq string (substring string (match-end 0)))) (if (string-match "[ \t\n]+\\'" string) (setq string (substring string 0 (match-beginning 0)))) (set-text-properties 0 (length string) nil string) string) (defun top-mode-on-pid-line () (when (save-excursion (beginning-of-line) (let ((orig-line (line-at-pos))) (while (and (equal (line-at-pos) orig-line) (looking-at "\\s-")) (forward-char 1)) (and (equal (line-at-pos) orig-line) (looking-at "[0-9]+\\s-")))) (let ((after-pid-line-column-header t) (done nil)) (save-excursion (while (not done) (forward-line 1) (if (= (point) (point-max)) (setq done t) (if (looking-at top-mode-column-header-regexp) (progn (setq done t) (setq after-pid-line-column-header nil))))) after-pid-line-column-header)))) (defun top-mode-goto-pid () (interactive) (when (top-mode-on-pid-line) (beginning-of-line) (while (looking-at "\\s-") (forward-char 1)) (while (looking-at "[0-9]") (forward-char 1)) (forward-char -1))) (defun top-mode-get-pid-from-line () (save-excursion (beginning-of-line) (re-search-forward "\\s-*\\([0-9]+\\)\\s-+" (line-end-position)) (string-to-int (match-string 1)))) (defun top-mode-show-specific-user () (interactive) (let ((response (read-from-minibuffer "Which user (blank for all): ") )) (if (string= response "") (setq top-mode-specific-user nil) (setq top-mode-specific-user response)) (top))) (defun top-mode-get-target-pids () (or (sort (delq nil (mapcar (lambda (ov) (let ((os (overlay-start ov)) (oe (overlay-end ov)) (str nil)) (when (and os oe) (setq str (buffer-substring (overlay-start ov) (overlay-end ov))) (string-match "^\\s-*\\([0-9]+\\)" str) (string-to-int (top-mode-string-trim (substring str 0 (match-end 0))))))) top-mode-overlay-list)) '<) (list (top-mode-get-pid-from-line)))) (defun top-mode-member-at-least-one (ls1 ls2) (if (or (null ls1) (null ls2)) nil (or (member (car ls1) ls2) (top-mode-member-at-least-one (cdr ls1) ls2)))) (defun top-mode-unmark () (interactive) (if (not (top-mode-on-pid-line)) (message "Not on a process line") (let (existing-overlay) (mapc (lambda (ov) (if (member ov top-mode-overlay-list) (setq existing-overlay ov))) (overlays-at (point))) (when existing-overlay (setq top-mode-overlay-list (delq existing-overlay top-mode-overlay-list)) (delete-overlay existing-overlay)) (next-line 1)))) (defun top-mode-mark () (interactive) (if (not (top-mode-on-pid-line)) (message "Not on a process line") (when (not (top-mode-member-at-least-one (overlays-at (point)) top-mode-overlay-list)) (let (o) (setq o (make-overlay (line-beginning-position) (line-end-position) nil nil t)) (overlay-put o (quote face) top-mode-mark-face) (overlay-put o (quote evaporate) t) (setq top-mode-overlay-list (cons o top-mode-overlay-list)))) (next-line 1))) (defun top-mode-confirm-action (action-name pids) (y-or-n-p (format "Really %s pids %s? " action-name (mapconcat (lambda (num) (format "%d" num)) pids " ")))) (defun top-mode-renice (&optional noconfirm) (interactive) (if (not (top-mode-on-pid-line)) (message "Not on a process line") (let ((pids (top-mode-get-target-pids))) (when (or noconfirm (top-mode-confirm-action "renice" pids)) (shell-command (format "renice +10 %s" (mapconcat (lambda (num) (format "%d" num)) pids " "))) (top))))) (defun top-mode-renice-noconfirm () (interactive) (top-mode-renice t)) (defun top-mode-strace (&optional noconfirm) (interactive) (if (not (top-mode-on-pid-line)) (message "Not on a process line") (let ((pids (top-mode-get-target-pids))) (if (> (length pids) 1) (message "Cannot strace more than 1 process") (when (or noconfirm (top-mode-confirm-action top-mode-strace-command pids)) (shell-command (format "%s -p %d &" top-mode-strace-command (car pids)))))))) (defun top-mode-strace-noconfirm () (interactive) (top-mode-strace t)) (defun top-mode-kill (&optional noconfirm) (interactive) (if (not (top-mode-on-pid-line)) (message "Not on a process line") (let ((pids (top-mode-get-target-pids))) (when (or noconfirm (top-mode-confirm-action "kill" pids)) (shell-command (format "kill -9 %s" (mapconcat (lambda (num) (format "%d" num)) pids " "))) (top))))) (defun top-mode-kill-noconfirm () (interactive) (top-mode-kill t)) (provide 'top-mode)
13,399
Common Lisp
.l
342
33.435673
197
0.634778
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
a39af681df3d6141a6a6e3b6a11a7eb007c94a3d26b2458b23cd9c3f32ae7e5a
8,424
[ -1 ]
8,425
core-server.el
evrim_core-server/etc/emacs/core-server.el
;; Core Server: Web Application Server ;; Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. (if (null (getenv "CORESERVER_HOME")) (error "Environment variable CORESERVER_HOME is not set.")) (defun load-el (str) "Load the el file in the core-server base directory" (let ((file (concat (concat (getenv "CORESERVER_HOME") "etc/emacs/") str))) (load file))) ; IBUFFER (autoload 'ibuffer "ibuffer" "List buffers." t) (global-set-key (kbd "C-x C-b") 'ibuffer) (column-number-mode) ;; Transient Mark mode (transient-mark-mode t) ;; PAREDIT ;;(load-el "paredit-beta.el") (load-el "paredit-7.0b4.el") (load-el "php-mode.el") (autoload 'enable-paredit-mode "paredit" "Minor mode for pseudo-structurally editing Lisp code." t) (add-hook 'lisp-mode-hook 'enable-paredit-mode) ;; Top Mode (load-el "top-mode.el") ;; (top) ;; Highlights Parenthesis (show-paren-mode t) ;; SLIME (add-to-list 'load-path (concat (getenv "CORESERVER_HOME") "lib/slime/")) (add-to-list 'load-path (concat (getenv "CORESERVER_HOME") "lib/slime/contrib/")) (setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol) (require 'slime-autoloads) (slime-setup '(slime-fancy slime-asdf slime-repl slime-xref-browser slime-indentation slime-sbcl-exts)) (global-set-key "\C-cs" 'slime-selector) (defun slime-run-rt-test () (interactive) (slime-display-output-buffer) (slime-interactive-eval (format "%s" `(rt:do-test ',(cadr (read (slime-last-expression))))))) (defun add-macro-font-face (name) (font-lock-add-keywords 'lisp-mode `((,(concat "(\\(" name "\\)[ ]+\\(\\sw+\\)") (1 font-lock-keyword-face) (2 font-lock-function-name-face))))) (add-macro-font-face "deftransaction") (add-macro-font-face "defcrud") ;; "(\\(name\\)/\\(suffix\\)[ ]*\\(\\sw+\\)?" (defun add-macro-with-suffix-font-face (name suffix) (font-lock-add-keywords 'lisp-mode `((,(concat "(\\(" name "\\)/\\(" suffix "\\)[ ]*\\(\\sw+\\)") (1 font-lock-keyword-face) (2 font-lock-constant-face) (3 font-lock-function-name-face))))) (add-macro-with-suffix-font-face "defmethod" "remote") (add-macro-with-suffix-font-face "defmethod" "local") (add-macro-with-suffix-font-face "defcrud" "lift") (add-macro-with-suffix-font-face "defmethod" "lift") (add-macro-with-suffix-font-face "defmethod" "cc") (defun add-class-font-face (name) (font-lock-add-keywords 'lisp-mode `((,(concat "(\\(" name "\\)[ ]+\\(\\sw+\\)") (1 font-lock-keyword-face) (2 font-lock-type-face))))) (add-class-font-face "defclass\\+") (add-class-font-face "defcomponent") (add-class-font-face "defplugin") (add-class-font-face "defrest") (add-class-font-face "defcommand") ;; DARCSUM (load-el "darcsum.el") (defun core () (interactive) (slime-connect "127.0.0.1" 4005) (slime-sync-to-top-level 8) (slime-repl-set-package "core-server")) (setq speedbar-track-mouse-flag t) ; MOUSE SCROLL (mouse-wheel-mode 1) ; SLOPPY FOCUS (setq mouse-autoselect-window t) ;; proper indentation (setq slime-enable-evaluate-in-emacs t) (defun tag-indent-function (path state indent-point sexp-column normal-indent) (let* ((pos (car path)) (start (elt state 1)) (attrs (tag-indent-count-attributes start (point)))) (cond ((> pos attrs) (+ sexp-column 1)) (t normal-indent)))) (defun tag-indent-count-attributes (start end) (save-excursion (goto-char start) (save-restriction (narrow-to-region (point) end) (down-list) (forward-sexp 1) (let ((count 0)) (while (progn (skip-chars-forward " \t\n") (looking-at "[^() \n]")) (incf count) (forward-sexp 1)) count)))) (put 'mapcar 'common-lisp-indent-function 0) (define-skeleton skeleton-comment-1 "Insert a Comment Header" "Header Text: " ";; +------------------------------------------------------------------------- ;; | " str " ;; +-------------------------------------------------------------------------") (define-skeleton skeleton-comment-2 "Insert a Comment Header" "Header Text: " ";; ------------------------------------------------------------------------- ;; " str " ;; -------------------------------------------------------------------------" ) ;; irc.core.gen.tr developer connection (when (locate-library "erc") (require 'erc) (defun core-irc () (interactive) (if (fboundp #'erc-tls) (erc-tls :server "irc.core.gen.tr" :port 8994) (erc :server "irc.core.gen.tr" :port 7000))) ;; timestamp on left etc... (setq erc-insert-timestamp-function 'erc-insert-timestamp-left erc-timestamp-format "%H:%M " erc-timestamp-only-if-changed-flag nil erc-hide-timestamps nil erc-interpret-mirc-color t erc-interpret-controls-p 'remove) (custom-set-variables '(erc-prompt-for-nickserv-password nil) '(erc-auto-query (quote window-noselect)) '(erc-track-mode t) '(erc-log-mode t) '(erc-server-auto-reconnect nil) '(erc-timestamp-mode t) '(erc-echo-timestamps t) '(erc-auto-discard-away t) '(erc-autoaway-idle-seconds 3600) '(erc-auto-set-away t) '(erc-enable-logging (quote erc-log-all-but-server-buffers)) '(erc-log-insert-log-on-open nil) '(erc-dcc-get-default-directory "~/dcc/") '(erc-log-channels-directory "~/.irclogs/") '(erc-modules '(autoaway autojoin button capab-identify completion fill irccontrols log match netsplit stamp notify page ring scrolltobottom services stamp track truncate)) '(erc-kill-queries-on-quit t) '(erc-kill-server-buffer-on-quit t))) ;; (core-irc) ;; Old Garbage below. ;; (setf *core-server-methods* '(defmethod/cc ;; defmethod/unit ;; defmethod/local ;; defmethod/remote ;; redefmethod)) ;; (setf *core-server-functions* '(defun/cc <:)) ;; (setq *core-server-macro* '(defhandler)) ;; (defun cl-indent (sym indent) ;; by Pierpaolo Bernardi ;; (put sym 'common-lisp-indent-function ;; (if (symbolp indent) ;; (get indent 'common-lisp-indent-function) ;; indent))) ;; (dolist (i *core-server-methods*) ;; (cl-indent i 'defmethod)) ;; (dolist (i *core-server-functions*) ;; (cl-indent i 'defun)) ;; (cl-indent 'event 'lambda) ;; ; Function to run Tidy HTML parser on buffer ;; ; NOTE: this requires external Tidy program ;; (defun tidy-buffer () ;; "Run Tidy HTML parser on current buffer." ;; (interactive) ;; (if (get-buffer "tidy-errs") (kill-buffer "tidy-errs")) ;; (shell-command-on-region (point-min) (point-max) ;; ;;"tidy -f /tmp/tidy-errs -asxhtml -q -utf8 -i -wrap 72 -c" ;; "tidy -f /tmp/tidy-errs -asxhtml --doctype transitional --char-encoding utf8 --output-encoding utf8 --add-xml-decl y --indent-attributes y --gnu-emacs y --tidy-mark n -q -utf8 -i -w 0" t) ;; (find-file-other-window "/tmp/tidy-errs") ;; (other-window 1) ;; (delete-file "/tmp/tidy-errs") ;; (message "buffer tidy'ed")) ;; (add-hook 'slime-load-hook (lambda () ;; (require 'slime-fuzzy) ;; (slime-fuzzy-init))) ;; (setq inferior-lisp-program "/usr/bin/sbcl --dynamic-space-size 1024" ;; lisp-indent-function 'common-lisp-indent-function ;; slime-complete-symbol-function 'slime-fuzzy-complete-symbol ;; slime-startup-animation nil ;; slime-net-coding-system 'utf-8-unix ;; slime-multiprocessing t) ;; (defun save-and-load-and-compile () ;; (interactive) (save-buffer) ;; (interactive) (slime-compile-and-load-file)) ;; (add-hook 'slime-mode-hook ;; (lambda () ;; (slime-define-key "\C-c\C-k" ;; 'save-and-load-and-compile))) ;; (add-hook 'slime-mode-hook ;; (lambda () ;; (slime-define-key "\C-x\C-a" ;; 'slime-run-rt-test))) ;;(setq (get 'defmethod/cc 'common-lisp-indent-function) 'lisp-indent-defmethod ;; (get 'defmethod/unit 'common-lisp-indent-function) 'lisp-indent-defmethod) ;; (defun make-backup-file-name (file) ;; "Create the non-numeric backup file name for FILE. ;; Normally this will just be the file's name with `~' appended. ;; Customization hooks are provided as follows. ;; If the variable `make-backup-file-name-function' is non-nil, its value ;; should be a function which will be called with FILE as its argument; ;; the resulting name is used. ;; Otherwise a match for FILE is sought in `backup-directory-alist'; see ;; the documentation of that variable. If the directory for the backup ;; doesn't exist, it is created." ;; (if make-backup-file-name-function ;; (funcall make-backup-file-name-function file) ;; (if (and (eq system-type 'ms-dos) (not (msdos-long-file-names))) ;; (let ((fn (file-name-nondirectory file))) ;; (concat (file-name-directory file) ;; "." ;; (or (and (string-match "\\`[^.]+\\'" fn) ;; (concat (match-string 0 fn) ".~")) ;; (and (string-match "\\`[^.]+\\.\\(..?\\)?" fn) ;; (concat (match-string 0 fn) "~"))))) ;; (let ((fname (make-backup-file-name-1 file))) ;; (concat (file-name-directory fname) "." (file-name-nondirectory fname) "~")))))
9,800
Common Lisp
.l
237
38.481013
217
0.641918
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
c8d80c7ecb4536f307447ea2983b46631960d1f62dbfffca7f694a017d825a19
8,425
[ -1 ]
8,426
php-mode.el
evrim_core-server/etc/emacs/php-mode.el
;;; php-mode.el --- major mode for editing PHP code ;; Copyright (C) 1999, 2000, 2001, 2003, 2004 Turadg Aleahmad ;; 2008 Aaron S. Hawley ;; Maintainer: Aaron S. Hawley <ashawley at users.sourceforge.net> ;; Author: Turadg Aleahmad, 1999-2004 ;; Keywords: php languages oop ;; Created: 1999-05-17 ;; Modified: 2008-11-04 ;; X-URL: http://php-mode.sourceforge.net/ (defconst php-mode-version-number "1.5.0" "PHP Mode version number.") ;;; License ;; This file is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License ;; as published by the Free Software Foundation; either version 3 ;; of the License, or (at your option) any later version. ;; This 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 General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this file; if not, write to the Free Software ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ;; 02110-1301, USA. ;;; Usage ;; Put this file in your Emacs lisp path (eg. site-lisp) and add to ;; your .emacs file: ;; ;; (require 'php-mode) ;; To use abbrev-mode, add lines like this: ;; (add-hook 'php-mode-hook ;; '(lambda () (define-abbrev php-mode-abbrev-table "ex" "extends"))) ;; To make php-mode compatible with html-mode, see http://php-mode.sf.net ;; Many options available under Help:Customize ;; Options specific to php-mode are in ;; Programming/Languages/Php ;; Since it inherits much functionality from c-mode, look there too ;; Programming/Languages/C ;;; Commentary: ;; PHP mode is a major mode for editing PHP 3 and 4 source code. It's ;; an extension of C mode; thus it inherits all C mode's navigation ;; functionality. But it colors according to the PHP grammar and indents ;; according to the PEAR coding guidelines. It also includes a couple ;; handy IDE-type features such as documentation search and a source ;; and class browser. ;;; Contributors: (in chronological order) ;; Juanjo, Torsten Martinsen, Vinai Kopp, Sean Champ, Doug Marcey, ;; Kevin Blake, Rex McMaster, Mathias Meyer, Boris Folgmann, Roland ;; Rosenfeld, Fred Yankowski, Craig Andrews, John Keller, Ryan ;; Sammartino, ppercot, Valentin Funk, Stig Bakken, Gregory Stark, ;; Chris Morris, Nils Rennebarth, Gerrit Riessen, Eric Mc Sween, ;; Ville Skytta, Giacomo Tesio, Lennart Borgman, Stefan Monnier, ;; Aaron S. Hawley, Ian Eure, Bill Lovett, Dias Badekas, David House ;;; Changelog: ;; 1.5 ;; Support function keywords like public, private and the ampersand ;; character for function-based commands. Support abstract, final, ;; static, public, private and protected keywords in Imenu. Fix ;; reversed order of Imenu entries. Use font-lock-preprocessor-face ;; for PHP and ASP tags. Make php-mode-modified a literal value ;; rather than a computed string. Add date and time constants of ;; PHP. (Dias Badekas) Fix false syntax highlighting of keywords ;; because of underscore character. Change HTML indentation warning ;; to match only HTML at the beginning of the line. Fix ;; byte-compiler warnings. Clean-up whitespace and audited style ;; consistency of code. Remove conditional bindings and XEmacs code ;; that likely does nothing. ;; ;; 1.4 ;; Updated GNU GPL to version 3. Ported to Emacs 22 (CC mode ;; 5.31). M-x php-mode-version shows version. Provide end-of-defun ;; beginning-of-defun functionality. Support add-log library. ;; Fix __CLASS__ constant (Ian Eure). Allow imenu to see visibility ;; declarations -- "private", "public", "protected". (Bill Lovett) ;; ;; 1.3 ;; Changed the definition of # using a tip from Stefan ;; Monnier to correct highlighting and indentation. (Lennart Borgman) ;; Changed the highlighting of the HTML part. (Lennart Borgman) ;; ;; See the ChangeLog file included with the source package. ;;; Code: (require 'speedbar) (require 'font-lock) (require 'cc-mode) (require 'cc-langs) (require 'custom) (require 'etags) (eval-when-compile (require 'regexp-opt)) ;; Local variables (defgroup php nil "Major mode `php-mode' for editing PHP code." :prefix "php-" :group 'languages) (defcustom php-default-face 'default "Default face in `php-mode' buffers." :type 'face :group 'php) (defcustom php-speedbar-config t "When set to true automatically configures Speedbar to observe PHP files. Ignores php-file patterns option; fixed to expression \"\\.\\(inc\\|php[s34]?\\)\"" :type 'boolean :set (lambda (sym val) (set-default sym val) (if (and val (boundp 'speedbar)) (speedbar-add-supported-extension "\\.\\(inc\\|php[s34]?\\|phtml\\)"))) :group 'php) (defcustom php-mode-speedbar-open nil "Normally `php-mode' starts with the speedbar closed. Turning this on will open it whenever `php-mode' is loaded." :type 'boolean :set (lambda (sym val) (set-default sym val) (when val (speedbar 1))) :group 'php) (defvar php-imenu-generic-expression '( ("Private Methods" "^\\s-*\\(?:\\(?:abstract\\|final\\)\\s-+\\)?private\\s-+\\(?:static\\s-+\\)?function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1) ("Protected Methods" "^\\s-*\\(?:\\(?:abstract\\|final\\)\\s-+\\)?protected\\s-+\\(?:static\\s-+\\)?function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1) ("Public Methods" "^\\s-*\\(?:\\(?:abstract\\|final\\)\\s-+\\)?public\\s-+\\(?:static\\s-+\\)?function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1) ("Classes" "^\\s-*class\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*" 1) ("All Functions" "^\\s-*\\(?:\\(?:abstract\\|final\\|private\\|protected\\|public\\|static\\)\\s-+\\)*function\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1) ) "Imenu generic expression for PHP Mode. See `imenu-generic-expression'." ) (defcustom php-manual-url "http://www.php.net/manual/en/" "URL at which to find PHP manual. You can replace \"en\" with your ISO language code." :type 'string :group 'php) (defcustom php-search-url "http://www.php.net/" "URL at which to search for documentation on a word." :type 'string :group 'php) (defcustom php-completion-file "" "Path to the file which contains the function names known to PHP." :type 'string :group 'php) (defcustom php-manual-path "" "Path to the directory which contains the PHP manual." :type 'string :group 'php) ;;;###autoload (defcustom php-file-patterns '("\\.php[s34]?\\'" "\\.phtml\\'" "\\.inc\\'") "List of file patterns for which to automatically invoke `php-mode'." :type '(repeat (regexp :tag "Pattern")) :set (lambda (sym val) (set-default sym val) (let ((php-file-patterns-temp val)) (while php-file-patterns-temp (add-to-list 'auto-mode-alist (cons (car php-file-patterns-temp) 'php-mode)) (setq php-file-patterns-temp (cdr php-file-patterns-temp))))) :group 'php) (defcustom php-mode-hook nil "List of functions to be executed on entry to `php-mode'." :type 'hook :group 'php) (defcustom php-mode-pear-hook nil "Hook called when a PHP PEAR file is opened with `php-mode'." :type 'hook :group 'php) (defcustom php-mode-force-pear nil "Normally PEAR coding rules are enforced only when the filename contains \"PEAR.\" Turning this on will force PEAR rules on all PHP files." :type 'boolean :group 'php) (defconst php-mode-modified "2008-11-04" "PHP Mode build date.") (defun php-mode-version () "Display string describing the version of PHP mode." (interactive) (message "PHP mode %s of %s" php-mode-version-number php-mode-modified)) (defconst php-beginning-of-defun-regexp "^\\s-*\\(?:\\(?:abstract\\|final\\|private\\|protected\\|public\\|static\\)\\s-+\\)*function\\s-+&?\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" "Regular expression for a PHP function.") (defun php-beginning-of-defun (&optional arg) "Move to the beginning of the ARGth PHP function from point. Implements PHP version of `beginning-of-defun-function'." (interactive "p") (let ((arg (or arg 1))) (while (> arg 0) (re-search-backward php-beginning-of-defun-regexp nil 'noerror) (setq arg (1- arg))) (while (< arg 0) (end-of-line 1) (let ((opoint (point))) (beginning-of-defun 1) (forward-list 2) (forward-line 1) (if (eq opoint (point)) (re-search-forward php-beginning-of-defun-regexp nil 'noerror)) (setq arg (1+ arg)))))) (defun php-end-of-defun (&optional arg) "Move the end of the ARGth PHP function from point. Implements PHP befsion of `end-of-defun-function' See `php-beginning-of-defun'." (interactive "p") (php-beginning-of-defun (- (or arg 1)))) (defvar php-warned-bad-indent nil) (make-variable-buffer-local 'php-warned-bad-indent) ;; Do it but tell it is not good if html tags in buffer. (defun php-check-html-for-indentation () (let ((html-tag-re "^\\s-*</?\\sw+.*?>") (here (point))) (if (not (or (re-search-forward html-tag-re (line-end-position) t) (re-search-backward html-tag-re (line-beginning-position) t))) t (goto-char here) (setq php-warned-bad-indent t) (lwarn 'php-indent :warning "\n\t%s\n\t%s\n\t%s\n" "Indentation fails badly with mixed HTML and PHP." "Look for an Emacs Lisp library that supports \"multiple" "major modes\" like mumamo, mmm-mode or multi-mode.") nil))) (defun php-cautious-indent-region (start end &optional quiet) (if (or php-warned-bad-indent (php-check-html-for-indentation)) (funcall 'c-indent-region start end quiet))) (defun php-cautious-indent-line () (if (or php-warned-bad-indent (php-check-html-for-indentation)) (funcall 'c-indent-line))) (defconst php-tags '("<?php" "?>" "<?" "<?=")) (defconst php-tags-key (regexp-opt php-tags)) (defconst php-block-stmt-1-kwds '("do" "else" "finally" "try")) (defconst php-block-stmt-2-kwds '("for" "if" "while" "switch" "foreach" "elseif" "catch all")) (defconst php-block-stmt-1-key (regexp-opt php-block-stmt-1-kwds)) (defconst php-block-stmt-2-key (regexp-opt php-block-stmt-2-kwds)) (defconst php-class-decl-kwds '("class" "interface")) (defconst php-class-key (concat "\\(" (regexp-opt php-class-decl-kwds) "\\)\\s-+" (c-lang-const c-symbol-key c) ;; Class name. "\\(\\s-+extends\\s-+" (c-lang-const c-symbol-key c) "\\)?" ;; Name of superclass. "\\(\\s-+implements\\s-+[^{]+{\\)?")) ;; List of any adopted protocols. ;;;###autoload (define-derived-mode php-mode c-mode "PHP" "Major mode for editing PHP code.\n\n\\{php-mode-map}" (c-add-language 'php-mode 'c-mode) ;; PHP doesn't have C-style macros. ;; HACK: Overwrite this syntax with rules to match <?php and others. ;; (c-lang-defconst c-opt-cpp-start php php-tags-key) ;; (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start)) (set (make-local-variable 'c-opt-cpp-start) php-tags-key) ;; (c-lang-defconst c-opt-cpp-start php php-tags-key) ;; (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start)) (set (make-local-variable 'c-opt-cpp-prefix) php-tags-key) (c-set-offset 'cpp-macro 0) ;; (c-lang-defconst c-block-stmt-1-kwds php php-block-stmt-1-kwds) ;; (c-lang-defvar c-block-stmt-1-kwds (c-lang-const c-block-stmt-1-kwds)) (set (make-local-variable 'c-block-stmt-1-key) php-block-stmt-1-key) ;; (c-lang-defconst c-block-stmt-2-kwds php php-block-stmt-2-kwds) ;; (c-lang-defvar c-block-stmt-2-kwds (c-lang-const c-block-stmt-2-kwds)) (set (make-local-variable 'c-block-stmt-2-key) php-block-stmt-2-key) ;; Specify that cc-mode recognize Javadoc comment style (set (make-local-variable 'c-doc-comment-style) '((php-mode . javadoc))) ;; (c-lang-defconst c-class-decl-kwds ;; php php-class-decl-kwds) (set (make-local-variable 'c-class-key) php-class-key) (make-local-variable 'font-lock-defaults) (setq font-lock-defaults '((php-font-lock-keywords-1 php-font-lock-keywords-2 ;; Comment-out the next line if the font-coloring is too ;; extreme/ugly for you. php-font-lock-keywords-3) nil ; KEYWORDS-ONLY t ; CASE-FOLD (("_" . "w")) ; SYNTAX-ALIST nil)) ; SYNTAX-BEGIN ;; Electric behaviour must be turned off, they do not work since ;; they can not find the correct syntax in embedded PHP. ;; ;; Seems to work with narrowing so let it be on if the user prefers it. ;;(setq c-electric-flag nil) (setq font-lock-maximum-decoration t case-fold-search t ; PHP vars are case-sensitive imenu-generic-expression php-imenu-generic-expression) ;; Do not force newline at end of file. Such newlines can cause ;; trouble if the PHP file is included in another file before calls ;; to header() or cookie(). (set (make-local-variable 'require-final-newline) nil) (set (make-local-variable 'next-line-add-newlines) nil) ;; PEAR coding standards (add-hook 'php-mode-pear-hook (lambda () (set (make-local-variable 'tab-width) 4) (set (make-local-variable 'c-basic-offset) 4) (set (make-local-variable 'indent-tabs-mode) nil) (c-set-offset 'block-open' - ) (c-set-offset 'block-close' 0 )) nil t) (if (or php-mode-force-pear (and (stringp buffer-file-name) (string-match "PEAR\\|pear" (buffer-file-name)) (string-match "\\.php$" (buffer-file-name)))) (run-hooks 'php-mode-pear-hook)) (setq indent-line-function 'php-cautious-indent-line) (setq indent-region-function 'php-cautious-indent-region) (setq c-special-indent-hook nil) (set (make-local-variable 'beginning-of-defun-function) 'php-beginning-of-defun) (set (make-local-variable 'end-of-defun-function) 'php-end-of-defun) (set (make-local-variable 'open-paren-in-column-0-is-defun-start) nil) (set (make-local-variable 'defun-prompt-regexp) "^\\s-*function\\s-+&?\\s-*\\(\\(\\sw\\|\\s_\\)+\\)\\s-*") (set (make-local-variable 'add-log-current-defun-header-regexp) php-beginning-of-defun-regexp) (run-hooks 'php-mode-hook)) ;; Make a menu keymap (with a prompt string) ;; and make it the menu bar item's definition. (define-key php-mode-map [menu-bar] (make-sparse-keymap)) (define-key php-mode-map [menu-bar php] (cons "PHP" (make-sparse-keymap "PHP"))) ;; Define specific subcommands in this menu. (define-key php-mode-map [menu-bar php complete-function] '("Complete function name" . php-complete-function)) (define-key php-mode-map [menu-bar php browse-manual] '("Browse manual" . php-browse-manual)) (define-key php-mode-map [menu-bar php search-documentation] '("Search documentation" . php-search-documentation)) ;; Define function name completion function (defvar php-completion-table nil "Obarray of tag names defined in current tags table and functions known to PHP.") (defun php-complete-function () "Perform function completion on the text around point. Completes to the set of names listed in the current tags table and the standard php functions. The string to complete is chosen in the same way as the default for \\[find-tag] (which see)." (interactive) (let ((pattern (php-get-pattern)) beg completion (php-functions (php-completion-table))) (if (not pattern) (message "Nothing to complete") (search-backward pattern) (setq beg (point)) (forward-char (length pattern)) (setq completion (try-completion pattern php-functions nil)) (cond ((eq completion t)) ((null completion) (message "Can't find completion for \"%s\"" pattern) (ding)) ((not (string= pattern completion)) (delete-region beg (point)) (insert completion)) (t (message "Making completion list...") (with-output-to-temp-buffer "*Completions*" (display-completion-list (all-completions pattern php-functions))) (message "Making completion list...%s" "done")))))) (defun php-completion-table () "Build variable `php-completion-table' on demand. The table includes the PHP functions and the tags from the current `tags-file-name'." (or (and tags-file-name (save-excursion (tags-verify-table tags-file-name)) php-completion-table) (let ((tags-table (if (and tags-file-name (functionp 'etags-tags-completion-table)) (with-current-buffer (get-file-buffer tags-file-name) (etags-tags-completion-table)) nil)) (php-table (cond ((and (not (string= "" php-completion-file)) (file-readable-p php-completion-file)) (php-build-table-from-file php-completion-file)) (php-manual-path (php-build-table-from-path php-manual-path)) (t nil)))) (unless (or php-table tags-table) (error (concat "No TAGS file active nor are " "`php-completion-file' or `php-manual-path' set"))) (when tags-table ;; Combine the tables. (mapatoms (lambda (sym) (intern (symbol-name sym) php-table)) tags-table)) (setq php-completion-table php-table)))) (defun php-build-table-from-file (filename) (let ((table (make-vector 1022 0)) (buf (find-file-noselect filename))) (save-excursion (set-buffer buf) (goto-char (point-min)) (while (re-search-forward "^\\([-a-zA-Z0-9_.]+\\)\n" nil t) (intern (buffer-substring (match-beginning 1) (match-end 1)) table))) (kill-buffer buf) table)) (defun php-build-table-from-path (path) (let ((table (make-vector 1022 0)) (files (directory-files path nil "^function\\..+\\.html$"))) (mapc (lambda (file) (string-match "\\.\\([-a-zA-Z_0-9]+\\)\\.html$" file) (intern (replace-regexp-in-string "-" "_" (substring file (match-beginning 1) (match-end 1)) t) table)) files) table)) ;; Find the pattern we want to complete ;; find-tag-default from GNU Emacs etags.el (defun php-get-pattern () (save-excursion (while (looking-at "\\sw\\|\\s_") (forward-char 1)) (if (or (re-search-backward "\\sw\\|\\s_" (save-excursion (beginning-of-line) (point)) t) (re-search-forward "\\(\\sw\\|\\s_\\)+" (save-excursion (end-of-line) (point)) t)) (progn (goto-char (match-end 0)) (buffer-substring-no-properties (point) (progn (forward-sexp -1) (while (looking-at "\\s'") (forward-char 1)) (point)))) nil))) (defun php-show-arglist () (interactive) (let* ((tagname (php-get-pattern)) (buf (find-tag-noselect tagname nil nil)) arglist) (save-excursion (set-buffer buf) (goto-char (point-min)) (when (re-search-forward (format "function\\s-+%s\\s-*(\\([^{]*\\))" tagname) nil t) (setq arglist (buffer-substring-no-properties (match-beginning 1) (match-end 1))))) (if arglist (message "Arglist for %s: %s" tagname arglist) (message "Unknown function: %s" tagname)))) ;; Define function documentation function (defun php-search-documentation () "Search PHP documentation for the word at point." (interactive) (browse-url (concat php-search-url (current-word t)))) ;; Define function for browsing manual (defun php-browse-manual () "Bring up manual for PHP." (interactive) (browse-url php-manual-url)) ;; Define shortcut (define-key php-mode-map "\C-c\C-f" 'php-search-documentation) ;; Define shortcut (define-key php-mode-map [(meta tab)] 'php-complete-function) ;; Define shortcut (define-key php-mode-map "\C-c\C-m" 'php-browse-manual) ;; Define shortcut (define-key php-mode-map '[(control .)] 'php-show-arglist) (defconst php-constants (eval-when-compile (regexp-opt '(;; core constants "__LINE__" "__FILE__" "__FUNCTION__" "__CLASS__" "__METHOD__" "PHP_OS" "PHP_VERSION" "TRUE" "FALSE" "NULL" "E_ERROR" "E_NOTICE" "E_PARSE" "E_WARNING" "E_ALL" "E_STRICT" "E_USER_ERROR" "E_USER_WARNING" "E_USER_NOTICE" "DEFAULT_INCLUDE_PATH" "PEAR_INSTALL_DIR" "PEAR_EXTENSION_DIR" "PHP_BINDIR" "PHP_LIBDIR" "PHP_DATADIR" "PHP_SYSCONFDIR" "PHP_LOCALSTATEDIR" "PHP_CONFIG_FILE_PATH" "PHP_EOL" ;; date and time constants "DATE_ATOM" "DATE_COOKIE" "DATE_ISO8601" "DATE_RFC822" "DATE_RFC850" "DATE_RFC1036" "DATE_RFC1123" "DATE_RFC2822" "DATE_RFC3339" "DATE_RSS" "DATE_W3C" ;; from ext/standard: "EXTR_OVERWRITE" "EXTR_SKIP" "EXTR_PREFIX_SAME" "EXTR_PREFIX_ALL" "EXTR_PREFIX_INVALID" "SORT_ASC" "SORT_DESC" "SORT_REGULAR" "SORT_NUMERIC" "SORT_STRING" "ASSERT_ACTIVE" "ASSERT_CALLBACK" "ASSERT_BAIL" "ASSERT_WARNING" "ASSERT_QUIET_EVAL" "CONNECTION_ABORTED" "CONNECTION_NORMAL" "CONNECTION_TIMEOUT" "M_E" "M_LOG2E" "M_LOG10E" "M_LN2" "M_LN10" "M_PI" "M_PI_2" "M_PI_4" "M_1_PI" "M_2_PI" "M_2_SQRTPI" "M_SQRT2" "M_SQRT1_2" "CRYPT_SALT_LENGTH" "CRYPT_STD_DES" "CRYPT_EXT_DES" "CRYPT_MD5" "CRYPT_BLOWFISH" "DIRECTORY_SEPARATOR" "SEEK_SET" "SEEK_CUR" "SEEK_END" "LOCK_SH" "LOCK_EX" "LOCK_UN" "LOCK_NB" "HTML_SPECIALCHARS" "HTML_ENTITIES" "ENT_COMPAT" "ENT_QUOTES" "ENT_NOQUOTES" "INFO_GENERAL" "INFO_CREDITS" "INFO_CONFIGURATION" "INFO_ENVIRONMENT" "INFO_VARIABLES" "INFO_LICENSE" "INFO_ALL" "CREDITS_GROUP" "CREDITS_GENERAL" "CREDITS_SAPI" "CREDITS_MODULES" "CREDITS_DOCS" "CREDITS_FULLPAGE" "CREDITS_QA" "CREDITS_ALL" "PHP_OUTPUT_HANDLER_START" "PHP_OUTPUT_HANDLER_CONT" "PHP_OUTPUT_HANDLER_END" "STR_PAD_LEFT" "STR_PAD_RIGHT" "STR_PAD_BOTH" "PATHINFO_DIRNAME" "PATHINFO_BASENAME" "PATHINFO_EXTENSION" "CHAR_MAX" "LC_CTYPE" "LC_NUMERIC" "LC_TIME" "LC_COLLATE" "LC_MONETARY" "LC_ALL" "LC_MESSAGES" "LOG_EMERG" "LOG_ALERT" "LOG_CRIT" "LOG_ERR" "LOG_WARNING" "LOG_NOTICE" "LOG_INFO" "LOG_DEBUG" "LOG_KERN" "LOG_USER" "LOG_MAIL" "LOG_DAEMON" "LOG_AUTH" "LOG_SYSLOG" "LOG_LPR" "LOG_NEWS" "LOG_UUCP" "LOG_CRON" "LOG_AUTHPRIV" "LOG_LOCAL0" "LOG_LOCAL1" "LOG_LOCAL2" "LOG_LOCAL3" "LOG_LOCAL4" "LOG_LOCAL5" "LOG_LOCAL6" "LOG_LOCAL7" "LOG_PID" "LOG_CONS" "LOG_ODELAY" "LOG_NDELAY" "LOG_NOWAIT" "LOG_PERROR" ;; Disabled by default because they slow buffer loading ;; If you have use for them, uncomment the strings ;; that you want colored. ;; To compile, you may have to increase 'max-specpdl-size' ;; from other bundled extensions: ; "CAL_EASTER_TO_xxx" "VT_NULL" "VT_EMPTY" "VT_UI1" "VT_I2" ; "VT_I4" "VT_R4" "VT_R8" "VT_BOOL" "VT_ERROR" "VT_CY" "VT_DATE" ; "VT_BSTR" "VT_DECIMAL" "VT_UNKNOWN" "VT_DISPATCH" "VT_VARIANT" ; "VT_I1" "VT_UI2" "VT_UI4" "VT_INT" "VT_UINT" "VT_ARRAY" ; "VT_BYREF" "CP_ACP" "CP_MACCP" "CP_OEMCP" "CP_SYMBOL" ; "CP_THREAD_ACP" "CP_UTF7" "CP_UTF8" "CPDF_PM_NONE" ; "CPDF_PM_OUTLINES" "CPDF_PM_THUMBS" "CPDF_PM_FULLSCREEN" ; "CPDF_PL_SINGLE" "CPDF_PL_1COLUMN" "CPDF_PL_2LCOLUMN" ; "CPDF_PL_2RCOLUMN" "CURLOPT_PORT" "CURLOPT_FILE" ; "CURLOPT_INFILE" "CURLOPT_INFILESIZE" "CURLOPT_URL" ; "CURLOPT_PROXY" "CURLOPT_VERBOSE" "CURLOPT_HEADER" ; "CURLOPT_HTTPHEADER" "CURLOPT_NOPROGRESS" "CURLOPT_NOBODY" ; "CURLOPT_FAILONERROR" "CURLOPT_UPLOAD" "CURLOPT_POST" ; "CURLOPT_FTPLISTONLY" "CURLOPT_FTPAPPEND" "CURLOPT_NETRC" ; "CURLOPT_FOLLOWLOCATION" "CURLOPT_FTPASCII" "CURLOPT_PUT" ; "CURLOPT_MUTE" "CURLOPT_USERPWD" "CURLOPT_PROXYUSERPWD" ; "CURLOPT_RANGE" "CURLOPT_TIMEOUT" "CURLOPT_POSTFIELDS" ; "CURLOPT_REFERER" "CURLOPT_USERAGENT" "CURLOPT_FTPPORT" ; "CURLOPT_LOW_SPEED_LIMIT" "CURLOPT_LOW_SPEED_TIME" ; "CURLOPT_RESUME_FROM" "CURLOPT_COOKIE" "CURLOPT_SSLCERT" ; "CURLOPT_SSLCERTPASSWD" "CURLOPT_WRITEHEADER" ; "CURLOPT_COOKIEFILE" "CURLOPT_SSLVERSION" ; "CURLOPT_TIMECONDITION" "CURLOPT_TIMEVALUE" ; "CURLOPT_CUSTOMREQUEST" "CURLOPT_STDERR" "CURLOPT_TRANSFERTEXT" ; "CURLOPT_RETURNTRANSFER" "CURLOPT_QUOTE" "CURLOPT_POSTQUOTE" ; "CURLOPT_INTERFACE" "CURLOPT_KRB4LEVEL" ; "CURLOPT_HTTPPROXYTUNNEL" "CURLOPT_FILETIME" ; "CURLOPT_WRITEFUNCTION" "CURLOPT_READFUNCTION" ; "CURLOPT_PASSWDFUNCTION" "CURLOPT_HEADERFUNCTION" ; "CURLOPT_MAXREDIRS" "CURLOPT_MAXCONNECTS" "CURLOPT_CLOSEPOLICY" ; "CURLOPT_FRESH_CONNECT" "CURLOPT_FORBID_REUSE" ; "CURLOPT_RANDOM_FILE" "CURLOPT_EGDSOCKET" ; "CURLOPT_CONNECTTIMEOUT" "CURLOPT_SSL_VERIFYPEER" ; "CURLOPT_CAINFO" "CURLOPT_BINARYTRANSER" ; "CURLCLOSEPOLICY_LEAST_RECENTLY_USED" "CURLCLOSEPOLICY_OLDEST" ; "CURLINFO_EFFECTIVE_URL" "CURLINFO_HTTP_CODE" ; "CURLINFO_HEADER_SIZE" "CURLINFO_REQUEST_SIZE" ; "CURLINFO_TOTAL_TIME" "CURLINFO_NAMELOOKUP_TIME" ; "CURLINFO_CONNECT_TIME" "CURLINFO_PRETRANSFER_TIME" ; "CURLINFO_SIZE_UPLOAD" "CURLINFO_SIZE_DOWNLOAD" ; "CURLINFO_SPEED_DOWNLOAD" "CURLINFO_SPEED_UPLOAD" ; "CURLINFO_FILETIME" "CURLE_OK" "CURLE_UNSUPPORTED_PROTOCOL" ; "CURLE_FAILED_INIT" "CURLE_URL_MALFORMAT" ; "CURLE_URL_MALFORMAT_USER" "CURLE_COULDNT_RESOLVE_PROXY" ; "CURLE_COULDNT_RESOLVE_HOST" "CURLE_COULDNT_CONNECT" ; "CURLE_FTP_WEIRD_SERVER_REPLY" "CURLE_FTP_ACCESS_DENIED" ; "CURLE_FTP_USER_PASSWORD_INCORRECT" ; "CURLE_FTP_WEIRD_PASS_REPLY" "CURLE_FTP_WEIRD_USER_REPLY" ; "CURLE_FTP_WEIRD_PASV_REPLY" "CURLE_FTP_WEIRD_227_FORMAT" ; "CURLE_FTP_CANT_GET_HOST" "CURLE_FTP_CANT_RECONNECT" ; "CURLE_FTP_COULDNT_SET_BINARY" "CURLE_PARTIAL_FILE" ; "CURLE_FTP_COULDNT_RETR_FILE" "CURLE_FTP_WRITE_ERROR" ; "CURLE_FTP_QUOTE_ERROR" "CURLE_HTTP_NOT_FOUND" ; "CURLE_WRITE_ERROR" "CURLE_MALFORMAT_USER" ; "CURLE_FTP_COULDNT_STOR_FILE" "CURLE_READ_ERROR" ; "CURLE_OUT_OF_MEMORY" "CURLE_OPERATION_TIMEOUTED" ; "CURLE_FTP_COULDNT_SET_ASCII" "CURLE_FTP_PORT_FAILED" ; "CURLE_FTP_COULDNT_USE_REST" "CURLE_FTP_COULDNT_GET_SIZE" ; "CURLE_HTTP_RANGE_ERROR" "CURLE_HTTP_POST_ERROR" ; "CURLE_SSL_CONNECT_ERROR" "CURLE_FTP_BAD_DOWNLOAD_RESUME" ; "CURLE_FILE_COULDNT_READ_FILE" "CURLE_LDAP_CANNOT_BIND" ; "CURLE_LDAP_SEARCH_FAILED" "CURLE_LIBRARY_NOT_FOUND" ; "CURLE_FUNCTION_NOT_FOUND" "CURLE_ABORTED_BY_CALLBACK" ; "CURLE_BAD_FUNCTION_ARGUMENT" "CURLE_BAD_CALLING_ORDER" ; "CURLE_HTTP_PORT_FAILED" "CURLE_BAD_PASSWORD_ENTERED" ; "CURLE_TOO_MANY_REDIRECTS" "CURLE_UNKOWN_TELNET_OPTION" ; "CURLE_TELNET_OPTION_SYNTAX" "CURLE_ALREADY_COMPLETE" ; "DBX_MYSQL" "DBX_ODBC" "DBX_PGSQL" "DBX_MSSQL" "DBX_PERSISTENT" ; "DBX_RESULT_INFO" "DBX_RESULT_INDEX" "DBX_RESULT_ASSOC" ; "DBX_CMP_TEXT" "DBX_CMP_NUMBER" "XML_ELEMENT_NODE" ; "XML_ATTRIBUTE_NODE" "XML_TEXT_NODE" "XML_CDATA_SECTION_NODE" ; "XML_ENTITY_REF_NODE" "XML_ENTITY_NODE" "XML_PI_NODE" ; "XML_COMMENT_NODE" "XML_DOCUMENT_NODE" "XML_DOCUMENT_TYPE_NODE" ; "XML_DOCUMENT_FRAG_NODE" "XML_NOTATION_NODE" ; "XML_HTML_DOCUMENT_NODE" "XML_DTD_NODE" "XML_ELEMENT_DECL_NODE" ; "XML_ATTRIBUTE_DECL_NODE" "XML_ENTITY_DECL_NODE" ; "XML_NAMESPACE_DECL_NODE" "XML_GLOBAL_NAMESPACE" ; "XML_LOCAL_NAMESPACE" "XML_ATTRIBUTE_CDATA" "XML_ATTRIBUTE_ID" ; "XML_ATTRIBUTE_IDREF" "XML_ATTRIBUTE_IDREFS" ; "XML_ATTRIBUTE_ENTITY" "XML_ATTRIBUTE_NMTOKEN" ; "XML_ATTRIBUTE_NMTOKENS" "XML_ATTRIBUTE_ENUMERATION" ; "XML_ATTRIBUTE_NOTATION" "XPATH_UNDEFINED" "XPATH_NODESET" ; "XPATH_BOOLEAN" "XPATH_NUMBER" "XPATH_STRING" "XPATH_POINT" ; "XPATH_RANGE" "XPATH_LOCATIONSET" "XPATH_USERS" "FBSQL_ASSOC" ; "FBSQL_NUM" "FBSQL_BOTH" "FDFValue" "FDFStatus" "FDFFile" ; "FDFID" "FDFFf" "FDFSetFf" "FDFClearFf" "FDFFlags" "FDFSetF" ; "FDFClrF" "FDFAP" "FDFAS" "FDFAction" "FDFAA" "FDFAPRef" ; "FDFIF" "FDFEnter" "FDFExit" "FDFDown" "FDFUp" "FDFFormat" ; "FDFValidate" "FDFKeystroke" "FDFCalculate" ; "FRIBIDI_CHARSET_UTF8" "FRIBIDI_CHARSET_8859_6" ; "FRIBIDI_CHARSET_8859_8" "FRIBIDI_CHARSET_CP1255" ; "FRIBIDI_CHARSET_CP1256" "FRIBIDI_CHARSET_ISIRI_3342" ; "FTP_ASCII" "FTP_BINARY" "FTP_IMAGE" "FTP_TEXT" "IMG_GIF" ; "IMG_JPG" "IMG_JPEG" "IMG_PNG" "IMG_WBMP" "IMG_COLOR_TILED" ; "IMG_COLOR_STYLED" "IMG_COLOR_BRUSHED" ; "IMG_COLOR_STYLEDBRUSHED" "IMG_COLOR_TRANSPARENT" ; "IMG_ARC_ROUNDED" "IMG_ARC_PIE" "IMG_ARC_CHORD" ; "IMG_ARC_NOFILL" "IMG_ARC_EDGED" "GMP_ROUND_ZERO" ; "GMP_ROUND_PLUSINF" "GMP_ROUND_MINUSINF" "HW_ATTR_LANG" ; "HW_ATTR_NR" "HW_ATTR_NONE" "IIS_READ" "IIS_WRITE" ; "IIS_EXECUTE" "IIS_SCRIPT" "IIS_ANONYMOUS" "IIS_BASIC" ; "IIS_NTLM" "NIL" "OP_DEBUG" "OP_READONLY" "OP_ANONYMOUS" ; "OP_SHORTCACHE" "OP_SILENT" "OP_PROTOTYPE" "OP_HALFOPEN" ; "OP_EXPUNGE" "OP_SECURE" "CL_EXPUNGE" "FT_UID" "FT_PEEK" ; "FT_NOT" "FT_INTERNAL" "FT_PREFETCHTEXT" "ST_UID" "ST_SILENT" ; "ST_SET" "CP_UID" "CP_MOVE" "SE_UID" "SE_FREE" "SE_NOPREFETCH" ; "SO_FREE" "SO_NOSERVER" "SA_MESSAGES" "SA_RECENT" "SA_UNSEEN" ; "SA_UIDNEXT" "SA_UIDVALIDITY" "SA_ALL" "LATT_NOINFERIORS" ; "LATT_NOSELECT" "LATT_MARKED" "LATT_UNMARKED" "SORTDATE" ; "SORTARRIVAL" "SORTFROM" "SORTSUBJECT" "SORTTO" "SORTCC" ; "SORTSIZE" "TYPETEXT" "TYPEMULTIPART" "TYPEMESSAGE" ; "TYPEAPPLICATION" "TYPEAUDIO" "TYPEIMAGE" "TYPEVIDEO" ; "TYPEOTHER" "ENC7BIT" "ENC8BIT" "ENCBINARY" "ENCBASE64" ; "ENCQUOTEDPRINTABLE" "ENCOTHER" "INGRES_ASSOC" "INGRES_NUM" ; "INGRES_BOTH" "IBASE_DEFAULT" "IBASE_TEXT" "IBASE_UNIXTIME" ; "IBASE_READ" "IBASE_COMMITTED" "IBASE_CONSISTENCY" ; "IBASE_NOWAIT" "IBASE_TIMESTAMP" "IBASE_DATE" "IBASE_TIME" ; "LDAP_DEREF_NEVER" "LDAP_DEREF_SEARCHING" "LDAP_DEREF_FINDING" ; "LDAP_DEREF_ALWAYS" "LDAP_OPT_DEREF" "LDAP_OPT_SIZELIMIT" ; "LDAP_OPT_TIMELIMIT" "LDAP_OPT_PROTOCOL_VERSION" ; "LDAP_OPT_ERROR_NUMBER" "LDAP_OPT_REFERRALS" "LDAP_OPT_RESTART" ; "LDAP_OPT_HOST_NAME" "LDAP_OPT_ERROR_STRING" ; "LDAP_OPT_MATCHED_DN" "LDAP_OPT_SERVER_CONTROLS" ; "LDAP_OPT_CLIENT_CONTROLS" "GSLC_SSL_NO_AUTH" ; "GSLC_SSL_ONEWAY_AUTH" "GSLC_SSL_TWOWAY_AUTH" "MCAL_SUNDAY" ; "MCAL_MONDAY" "MCAL_TUESDAY" "MCAL_WEDNESDAY" "MCAL_THURSDAY" ; "MCAL_FRIDAY" "MCAL_SATURDAY" "MCAL_JANUARY" "MCAL_FEBRUARY" ; "MCAL_MARCH" "MCAL_APRIL" "MCAL_MAY" "MCAL_JUNE" "MCAL_JULY" ; "MCAL_AUGUST" "MCAL_SEPTEMBER" "MCAL_OCTOBER" "MCAL_NOVEMBER" ; "MCAL_RECUR_NONE" "MCAL_RECUR_DAILY" "MCAL_RECUR_WEEKLY" ; "MCAL_RECUR_MONTHLY_MDAY" "MCAL_RECUR_MONTHLY_WDAY" ; "MCAL_RECUR_YEARLY" "MCAL_M_SUNDAY" "MCAL_M_MONDAY" ; "MCAL_M_TUESDAY" "MCAL_M_WEDNESDAY" "MCAL_M_THURSDAY" ; "MCAL_M_FRIDAY" "MCAL_M_SATURDAY" "MCAL_M_WEEKDAYS" ; "MCAL_M_WEEKEND" "MCAL_M_ALLDAYS" "MCRYPT_" "MCRYPT_" ; "MCRYPT_ENCRYPT" "MCRYPT_DECRYPT" "MCRYPT_DEV_RANDOM" ; "MCRYPT_DEV_URANDOM" "MCRYPT_RAND" "SWFBUTTON_HIT" ; "SUNFUNCS_RET_STRING" "SUNFUNCS_RET_DOUBLE" ; "SWFBUTTON_DOWN" "SWFBUTTON_OVER" "SWFBUTTON_UP" ; "SWFBUTTON_MOUSEUPOUTSIDE" "SWFBUTTON_DRAGOVER" ; "SWFBUTTON_DRAGOUT" "SWFBUTTON_MOUSEUP" "SWFBUTTON_MOUSEDOWN" ; "SWFBUTTON_MOUSEOUT" "SWFBUTTON_MOUSEOVER" ; "SWFFILL_RADIAL_GRADIENT" "SWFFILL_LINEAR_GRADIENT" ; "SWFFILL_TILED_BITMAP" "SWFFILL_CLIPPED_BITMAP" ; "SWFTEXTFIELD_HASLENGTH" "SWFTEXTFIELD_NOEDIT" ; "SWFTEXTFIELD_PASSWORD" "SWFTEXTFIELD_MULTILINE" ; "SWFTEXTFIELD_WORDWRAP" "SWFTEXTFIELD_DRAWBOX" ; "SWFTEXTFIELD_NOSELECT" "SWFTEXTFIELD_HTML" ; "SWFTEXTFIELD_ALIGN_LEFT" "SWFTEXTFIELD_ALIGN_RIGHT" ; "SWFTEXTFIELD_ALIGN_CENTER" "SWFTEXTFIELD_ALIGN_JUSTIFY" ; "UDM_FIELD_URLID" "UDM_FIELD_URL" "UDM_FIELD_CONTENT" ; "UDM_FIELD_TITLE" "UDM_FIELD_KEYWORDS" "UDM_FIELD_DESC" ; "UDM_FIELD_DESCRIPTION" "UDM_FIELD_TEXT" "UDM_FIELD_SIZE" ; "UDM_FIELD_RATING" "UDM_FIELD_SCORE" "UDM_FIELD_MODIFIED" ; "UDM_FIELD_ORDER" "UDM_FIELD_CRC" "UDM_FIELD_CATEGORY" ; "UDM_PARAM_PAGE_SIZE" "UDM_PARAM_PAGE_NUM" ; "UDM_PARAM_SEARCH_MODE" "UDM_PARAM_CACHE_MODE" ; "UDM_PARAM_TRACK_MODE" "UDM_PARAM_PHRASE_MODE" ; "UDM_PARAM_CHARSET" "UDM_PARAM_STOPTABLE" ; "UDM_PARAM_STOP_TABLE" "UDM_PARAM_STOPFILE" ; "UDM_PARAM_STOP_FILE" "UDM_PARAM_WEIGHT_FACTOR" ; "UDM_PARAM_WORD_MATCH" "UDM_PARAM_MAX_WORD_LEN" ; "UDM_PARAM_MAX_WORDLEN" "UDM_PARAM_MIN_WORD_LEN" ; "UDM_PARAM_MIN_WORDLEN" "UDM_PARAM_ISPELL_PREFIXES" ; "UDM_PARAM_ISPELL_PREFIX" "UDM_PARAM_PREFIXES" ; "UDM_PARAM_PREFIX" "UDM_PARAM_CROSS_WORDS" ; "UDM_PARAM_CROSSWORDS" "UDM_LIMIT_CAT" "UDM_LIMIT_URL" ; "UDM_LIMIT_TAG" "UDM_LIMIT_LANG" "UDM_LIMIT_DATE" ; "UDM_PARAM_FOUND" "UDM_PARAM_NUM_ROWS" "UDM_PARAM_WORDINFO" ; "UDM_PARAM_WORD_INFO" "UDM_PARAM_SEARCHTIME" ; "UDM_PARAM_SEARCH_TIME" "UDM_PARAM_FIRST_DOC" ; "UDM_PARAM_LAST_DOC" "UDM_MODE_ALL" "UDM_MODE_ANY" ; "UDM_MODE_BOOL" "UDM_MODE_PHRASE" "UDM_CACHE_ENABLED" ; "UDM_CACHE_DISABLED" "UDM_TRACK_ENABLED" "UDM_TRACK_DISABLED" ; "UDM_PHRASE_ENABLED" "UDM_PHRASE_DISABLED" ; "UDM_CROSS_WORDS_ENABLED" "UDM_CROSSWORDS_ENABLED" ; "UDM_CROSS_WORDS_DISABLED" "UDM_CROSSWORDS_DISABLED" ; "UDM_PREFIXES_ENABLED" "UDM_PREFIX_ENABLED" ; "UDM_ISPELL_PREFIXES_ENABLED" "UDM_ISPELL_PREFIX_ENABLED" ; "UDM_PREFIXES_DISABLED" "UDM_PREFIX_DISABLED" ; "UDM_ISPELL_PREFIXES_DISABLED" "UDM_ISPELL_PREFIX_DISABLED" ; "UDM_ISPELL_TYPE_AFFIX" "UDM_ISPELL_TYPE_SPELL" ; "UDM_ISPELL_TYPE_DB" "UDM_ISPELL_TYPE_SERVER" "UDM_MATCH_WORD" ; "UDM_MATCH_BEGIN" "UDM_MATCH_SUBSTR" "UDM_MATCH_END" ; "MSQL_ASSOC" "MSQL_NUM" "MSQL_BOTH" "MYSQL_ASSOC" "MYSQL_NUM" ; "MYSQL_BOTH" "MYSQL_USE_RESULT" "MYSQL_STORE_RESULT" ; "OCI_DEFAULT" "OCI_DESCRIBE_ONLY" "OCI_COMMIT_ON_SUCCESS" ; "OCI_EXACT_FETCH" "SQLT_BFILEE" "SQLT_CFILEE" "SQLT_CLOB" ; "SQLT_BLOB" "SQLT_RDD" "OCI_B_SQLT_NTY" "OCI_SYSDATE" ; "OCI_B_BFILE" "OCI_B_CFILEE" "OCI_B_CLOB" "OCI_B_BLOB" ; "OCI_B_ROWID" "OCI_B_CURSOR" "OCI_B_BIN" "OCI_ASSOC" "OCI_NUM" ; "OCI_BOTH" "OCI_RETURN_NULLS" "OCI_RETURN_LOBS" ; "OCI_DTYPE_FILE" "OCI_DTYPE_LOB" "OCI_DTYPE_ROWID" "OCI_D_FILE" ; "OCI_D_LOB" "OCI_D_ROWID" "ODBC_TYPE" "ODBC_BINMODE_PASSTHRU" ; "ODBC_BINMODE_RETURN" "ODBC_BINMODE_CONVERT" "SQL_ODBC_CURSORS" ; "SQL_CUR_USE_DRIVER" "SQL_CUR_USE_IF_NEEDED" "SQL_CUR_USE_ODBC" ; "SQL_CONCURRENCY" "SQL_CONCUR_READ_ONLY" "SQL_CONCUR_LOCK" ; "SQL_CONCUR_ROWVER" "SQL_CONCUR_VALUES" "SQL_CURSOR_TYPE" ; "SQL_CURSOR_FORWARD_ONLY" "SQL_CURSOR_KEYSET_DRIVEN" ; "SQL_CURSOR_DYNAMIC" "SQL_CURSOR_STATIC" "SQL_KEYSET_SIZE" ; "SQL_CHAR" "SQL_VARCHAR" "SQL_LONGVARCHAR" "SQL_DECIMAL" ; "SQL_NUMERIC" "SQL_BIT" "SQL_TINYINT" "SQL_SMALLINT" ; "SQL_INTEGER" "SQL_BIGINT" "SQL_REAL" "SQL_FLOAT" "SQL_DOUBLE" ; "SQL_BINARY" "SQL_VARBINARY" "SQL_LONGVARBINARY" "SQL_DATE" ; "SQL_TIME" "SQL_TIMESTAMP" "SQL_TYPE_DATE" "SQL_TYPE_TIME" ; "SQL_TYPE_TIMESTAMP" "SQL_BEST_ROWID" "SQL_ROWVER" ; "SQL_SCOPE_CURROW" "SQL_SCOPE_TRANSACTION" "SQL_SCOPE_SESSION" ; "SQL_NO_NULLS" "SQL_NULLABLE" "SQL_INDEX_UNIQUE" ; "SQL_INDEX_ALL" "SQL_ENSURE" "SQL_QUICK" ; "X509_PURPOSE_SSL_CLIENT" "X509_PURPOSE_SSL_SERVER" ; "X509_PURPOSE_NS_SSL_SERVER" "X509_PURPOSE_SMIME_SIGN" ; "X509_PURPOSE_SMIME_ENCRYPT" "X509_PURPOSE_CRL_SIGN" ; "X509_PURPOSE_ANY" "PKCS7_DETACHED" "PKCS7_TEXT" ; "PKCS7_NOINTERN" "PKCS7_NOVERIFY" "PKCS7_NOCHAIN" ; "PKCS7_NOCERTS" "PKCS7_NOATTR" "PKCS7_BINARY" "PKCS7_NOSIGS" ; "OPENSSL_PKCS1_PADDING" "OPENSSL_SSLV23_PADDING" ; "OPENSSL_NO_PADDING" "OPENSSL_PKCS1_OAEP_PADDING" ; "ORA_BIND_INOUT" "ORA_BIND_IN" "ORA_BIND_OUT" ; "ORA_FETCHINTO_ASSOC" "ORA_FETCHINTO_NULLS" ; "PREG_PATTERN_ORDER" "PREG_SET_ORDER" "PREG_SPLIT_NO_EMPTY" ; "PREG_SPLIT_DELIM_CAPTURE" ; "PGSQL_ASSOC" "PGSQL_NUM" "PGSQL_BOTH" ; "PRINTER_COPIES" "PRINTER_MODE" "PRINTER_TITLE" ; "PRINTER_DEVICENAME" "PRINTER_DRIVERVERSION" ; "PRINTER_RESOLUTION_Y" "PRINTER_RESOLUTION_X" "PRINTER_SCALE" ; "PRINTER_BACKGROUND_COLOR" "PRINTER_PAPER_LENGTH" ; "PRINTER_PAPER_WIDTH" "PRINTER_PAPER_FORMAT" ; "PRINTER_FORMAT_CUSTOM" "PRINTER_FORMAT_LETTER" ; "PRINTER_FORMAT_LEGAL" "PRINTER_FORMAT_A3" "PRINTER_FORMAT_A4" ; "PRINTER_FORMAT_A5" "PRINTER_FORMAT_B4" "PRINTER_FORMAT_B5" ; "PRINTER_FORMAT_FOLIO" "PRINTER_ORIENTATION" ; "PRINTER_ORIENTATION_PORTRAIT" "PRINTER_ORIENTATION_LANDSCAPE" ; "PRINTER_TEXT_COLOR" "PRINTER_TEXT_ALIGN" "PRINTER_TA_BASELINE" ; "PRINTER_TA_BOTTOM" "PRINTER_TA_TOP" "PRINTER_TA_CENTER" ; "PRINTER_TA_LEFT" "PRINTER_TA_RIGHT" "PRINTER_PEN_SOLID" ; "PRINTER_PEN_DASH" "PRINTER_PEN_DOT" "PRINTER_PEN_DASHDOT" ; "PRINTER_PEN_DASHDOTDOT" "PRINTER_PEN_INVISIBLE" ; "PRINTER_BRUSH_SOLID" "PRINTER_BRUSH_CUSTOM" ; "PRINTER_BRUSH_DIAGONAL" "PRINTER_BRUSH_CROSS" ; "PRINTER_BRUSH_DIAGCROSS" "PRINTER_BRUSH_FDIAGONAL" ; "PRINTER_BRUSH_HORIZONTAL" "PRINTER_BRUSH_VERTICAL" ; "PRINTER_FW_THIN" "PRINTER_FW_ULTRALIGHT" "PRINTER_FW_LIGHT" ; "PRINTER_FW_NORMAL" "PRINTER_FW_MEDIUM" "PRINTER_FW_BOLD" ; "PRINTER_FW_ULTRABOLD" "PRINTER_FW_HEAVY" "PRINTER_ENUM_LOCAL" ; "PRINTER_ENUM_NAME" "PRINTER_ENUM_SHARED" ; "PRINTER_ENUM_DEFAULT" "PRINTER_ENUM_CONNECTIONS" ; "PRINTER_ENUM_NETWORK" "PRINTER_ENUM_REMOTE" "PSPELL_FAST" ; "PSPELL_NORMAL" "PSPELL_BAD_SPELLERS" "PSPELL_RUN_TOGETHER" ; "SID" "SID" "AF_UNIX" "AF_INET" "SOCK_STREAM" "SOCK_DGRAM" ; "SOCK_RAW" "SOCK_SEQPACKET" "SOCK_RDM" "MSG_OOB" "MSG_WAITALL" ; "MSG_PEEK" "MSG_DONTROUTE" "SO_DEBUG" "SO_REUSEADDR" ; "SO_KEEPALIVE" "SO_DONTROUTE" "SO_LINGER" "SO_BROADCAST" ; "SO_OOBINLINE" "SO_SNDBUF" "SO_RCVBUF" "SO_SNDLOWAT" ; "SO_RCVLOWAT" "SO_SNDTIMEO" "SO_RCVTIMEO" "SO_TYPE" "SO_ERROR" ; "SOL_SOCKET" "PHP_NORMAL_READ" "PHP_BINARY_READ" ; "PHP_SYSTEM_READ" "SOL_TCP" "SOL_UDP" "MOD_COLOR" "MOD_MATRIX" ; "TYPE_PUSHBUTTON" "TYPE_MENUBUTTON" "BSHitTest" "BSDown" ; "BSOver" "BSUp" "OverDowntoIdle" "IdletoOverDown" ; "OutDowntoIdle" "OutDowntoOverDown" "OverDowntoOutDown" ; "OverUptoOverDown" "OverUptoIdle" "IdletoOverUp" "ButtonEnter" ; "ButtonExit" "MenuEnter" "MenuExit" "XML_ERROR_NONE" ; "XML_ERROR_NO_MEMORY" "XML_ERROR_SYNTAX" ; "XML_ERROR_NO_ELEMENTS" "XML_ERROR_INVALID_TOKEN" ; "XML_ERROR_UNCLOSED_TOKEN" "XML_ERROR_PARTIAL_CHAR" ; "XML_ERROR_TAG_MISMATCH" "XML_ERROR_DUPLICATE_ATTRIBUTE" ; "XML_ERROR_JUNK_AFTER_DOC_ELEMENT" "XML_ERROR_PARAM_ENTITY_REF" ; "XML_ERROR_UNDEFINED_ENTITY" "XML_ERROR_RECURSIVE_ENTITY_REF" ; "XML_ERROR_ASYNC_ENTITY" "XML_ERROR_BAD_CHAR_REF" ; "XML_ERROR_BINARY_ENTITY_REF" ; "XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF" ; "XML_ERROR_MISPLACED_XML_PI" "XML_ERROR_UNKNOWN_ENCODING" ; "XML_ERROR_INCORRECT_ENCODING" ; "XML_ERROR_UNCLOSED_CDATA_SECTION" ; "XML_ERROR_EXTERNAL_ENTITY_HANDLING" "XML_OPTION_CASE_FOLDING" ; "XML_OPTION_TARGET_ENCODING" "XML_OPTION_SKIP_TAGSTART" ; "XML_OPTION_SKIP_WHITE" "YPERR_BADARGS" "YPERR_BADDB" ; "YPERR_BUSY" "YPERR_DOMAIN" "YPERR_KEY" "YPERR_MAP" ; "YPERR_NODOM" "YPERR_NOMORE" "YPERR_PMAP" "YPERR_RESRC" ; "YPERR_RPC" "YPERR_YPBIND" "YPERR_YPERR" "YPERR_YPSERV" ; "YPERR_VERS" "FORCE_GZIP" "FORCE_DEFLATE" ;; PEAR constants ; "PEAR_ERROR_RETURN" "PEAR_ERROR_PRINT" "PEAR_ERROR_TRIGGER" ; "PEAR_ERROR_DIE" "PEAR_ERROR_CALLBACK" "OS_WINDOWS" "OS_UNIX" ; "PEAR_OS" "DB_OK" "DB_ERROR" "DB_ERROR_SYNTAX" ; "DB_ERROR_CONSTRAINT" "DB_ERROR_NOT_FOUND" ; "DB_ERROR_ALREADY_EXISTS" "DB_ERROR_UNSUPPORTED" ; "DB_ERROR_MISMATCH" "DB_ERROR_INVALID" "DB_ERROR_NOT_CAPABLE" ; "DB_ERROR_TRUNCATED" "DB_ERROR_INVALID_NUMBER" ; "DB_ERROR_INVALID_DATE" "DB_ERROR_DIVZERO" ; "DB_ERROR_NODBSELECTED" "DB_ERROR_CANNOT_CREATE" ; "DB_ERROR_CANNOT_DELETE" "DB_ERROR_CANNOT_DROP" ; "DB_ERROR_NOSUCHTABLE" "DB_ERROR_NOSUCHFIELD" ; "DB_ERROR_NEED_MORE_DATA" "DB_ERROR_NOT_LOCKED" ; "DB_ERROR_VALUE_COUNT_ON_ROW" "DB_ERROR_INVALID_DSN" ; "DB_ERROR_CONNECT_FAILED" "DB_WARNING" "DB_WARNING_READ_ONLY" ; "DB_PARAM_SCALAR" "DB_PARAM_OPAQUE" "DB_BINMODE_PASSTHRU" ; "DB_BINMODE_RETURN" "DB_BINMODE_CONVERT" "DB_FETCHMODE_DEFAULT" ; "DB_FETCHMODE_ORDERED" "DB_FETCHMODE_ASSOC" ; "DB_FETCHMODE_FLIPPED" "DB_GETMODE_ORDERED" "DB_GETMODE_ASSOC" ; "DB_GETMODE_FLIPPED" "DB_TABLEINFO_ORDER" ; "DB_TABLEINFO_ORDERTABLE" "DB_TABLEINFO_FULL" ))) "PHP constants.") (defconst php-keywords (eval-when-compile (regexp-opt ;; "class", "new" and "extends" get special treatment ;; "case" and "default" get special treatment elsewhere '("and" "as" "break" "continue" "declare" "do" "echo" "else" "elseif" "endfor" "endforeach" "endif" "endswitch" "endwhile" "exit" "extends" "for" "foreach" "global" "if" "include" "include_once" "next" "or" "require" "require_once" "return" "static" "switch" "then" "var" "while" "xor" "throw" "catch" "try" "instanceof" "catch all" "finally"))) "PHP keywords.") (defconst php-identifier (eval-when-compile '"[a-zA-Z\_\x7f-\xff][a-zA-Z0-9\_\x7f-\xff]*") "Characters in a PHP identifier.") (defconst php-types (eval-when-compile (regexp-opt '("array" "bool" "boolean" "char" "const" "double" "float" "int" "integer" "long" "mixed" "object" "real" "string"))) "PHP types.") (defconst php-superglobals (eval-when-compile (regexp-opt '("_GET" "_POST" "_COOKIE" "_SESSION" "_ENV" "GLOBALS" "_SERVER" "_FILES" "_REQUEST"))) "PHP superglobal variables.") ;; Set up font locking (defconst php-font-lock-keywords-1 (list ;; Fontify constants (cons (concat "[^_$]?\\<\\(" php-constants "\\)\\>[^_]?") '(1 font-lock-constant-face)) ;; Fontify keywords (cons (concat "[^_$]?\\<\\(" php-keywords "\\)\\>[^_]?") '(1 font-lock-keyword-face)) ;; Fontify keywords and targets, and case default tags. (list "\\<\\(break\\|case\\|continue\\)\\>\\s-+\\(-?\\sw+\\)?" '(1 font-lock-keyword-face) '(2 font-lock-constant-face t t)) ;; This must come after the one for keywords and targets. '(":" ("^\\s-+\\(\\sw+\\)\\s-+\\s-+$" (beginning-of-line) (end-of-line) (1 font-lock-constant-face))) ;; treat 'print' as keyword only when not used like a function name '("\\<print\\s-*(" . php-default-face) '("\\<print\\>" . font-lock-keyword-face) ;; Fontify PHP tag (cons php-tags-key font-lock-preprocessor-face) ;; Fontify ASP-style tag '("<\\%\\(=\\)?" . font-lock-preprocessor-face) '("\\%>" . font-lock-preprocessor-face) ) "Subdued level highlighting for PHP mode.") (defconst php-font-lock-keywords-2 (append php-font-lock-keywords-1 (list ;; class declaration '("\\<\\(class\\|interface\\)\\s-+\\(\\sw+\\)?" (1 font-lock-keyword-face) (2 font-lock-type-face nil t)) ;; handle several words specially, to include following word, ;; thereby excluding it from unknown-symbol checks later ;; FIX to handle implementing multiple ;; currently breaks on "class Foo implements Bar, Baz" '("\\<\\(new\\|extends\\|implements\\)\\s-+\\$?\\(\\sw+\\)" (1 font-lock-keyword-face) (2 font-lock-type-face)) ;; function declaration '("\\<\\(function\\)\\s-+&?\\(\\sw+\\)\\s-*(" (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)) ;; class hierarchy '("\\<\\(self\\|parent\\)\\>" (1 font-lock-constant-face nil nil)) ;; method and variable features '("\\<\\(private\\|protected\\|public\\)\\s-+\\$?\\sw+" (1 font-lock-keyword-face)) ;; method features '("^\\s-*\\(abstract\\|static\\|final\\)\\s-+\\$?\\sw+" (1 font-lock-keyword-face)) ;; variable features '("^\\s-*\\(static\\|const\\)\\s-+\\$?\\sw+" (1 font-lock-keyword-face)) )) "Medium level highlighting for PHP mode.") (defconst php-font-lock-keywords-3 (append php-font-lock-keywords-2 (list ;; <word> or </word> for HTML ;;'("</?\\sw+[^> ]*>" . font-lock-constant-face) ;;'("</?\\sw+[^>]*" . font-lock-constant-face) ;;'("<!DOCTYPE" . font-lock-constant-face) '("</?[a-z!:]+" . font-lock-constant-face) ;; HTML > '("<[^>]*\\(>\\)" (1 font-lock-constant-face)) ;; HTML tags '("\\(<[a-z]+\\)[[:space:]]+\\([a-z:]+=\\)[^>]*?" (1 font-lock-constant-face) (2 font-lock-constant-face) ) '("\"[[:space:]]+\\([a-z:]+=\\)" (1 font-lock-constant-face)) ;; HTML entities ;;'("&\\w+;" . font-lock-variable-name-face) ;; warn about '$' immediately after -> '("\\$\\sw+->\\s-*\\(\\$\\)\\(\\sw+\\)" (1 font-lock-warning-face) (2 php-default-face)) ;; warn about $word.word -- it could be a valid concatenation, ;; but without any spaces we'll assume $word->word was meant. '("\\$\\sw+\\(\\.\\)\\sw" 1 font-lock-warning-face) ;; Warn about ==> instead of => '("==+>" . font-lock-warning-face) ;; exclude casts from bare-word treatment (may contain spaces) `(,(concat "(\\s-*\\(" php-types "\\)\\s-*)") 1 font-lock-type-face) ;; PHP5: function declarations may contain classes as parameters type `(,(concat "[(,]\\s-*\\(\\sw+\\)\\s-+&?\\$\\sw+\\>") 1 font-lock-type-face) ;; Fontify variables and function calls '("\\$\\(this\\|that\\)\\W" (1 font-lock-constant-face nil nil)) `(,(concat "\\$\\(" php-superglobals "\\)\\W") (1 font-lock-constant-face nil nil)) ;; $_GET & co '("\\$\\(\\sw+\\)" (1 font-lock-variable-name-face)) ;; $variable '("->\\(\\sw+\\)" (1 font-lock-variable-name-face t t)) ;; ->variable '("->\\(\\sw+\\)\\s-*(" . (1 php-default-face t t)) ;; ->function_call '("\\(\\sw+\\)::\\sw+\\s-*(?" . (1 font-lock-type-face)) ;; class::member '("::\\(\\sw+\\>[^(]\\)" . (1 php-default-face)) ;; class::constant '("\\<\\sw+\\s-*[[(]" . php-default-face) ;; word( or word[ '("\\<[0-9]+" . php-default-face) ;; number (also matches word) ;; Warn on any words not already fontified '("\\<\\sw+\\>" . font-lock-warning-face) )) "Gauchy level highlighting for PHP mode.") (provide 'php-mode) ;;; php-mode.el ends here
48,285
Common Lisp
.l
982
44.786151
139
0.631927
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
10abcf99b7571dc0591ac18ec9e3455c40e9e4f899d44cc0b00f0ee6a216727a
8,426
[ -1 ]
8,427
darcsum.el
evrim_core-server/etc/emacs/darcsum.el
;;; darcsum.el --- a pcl-cvs like interface for managing darcs patches ;; Copyright (C) 2004 John Wiegley ;; Copyright (C) 2005 Christian Neukirchen ;; Copyright (C) 2005 Free Software Foundation, Inc. ;; Author: John Wiegley <[email protected]> ;; Maintainer: Of this fork: Christian Neukirchen <[email protected]> ;; Keywords: completion convenience tools vc ;; Version: 1.10-chris ;; location: http://www.newartisans.com/johnw/emacs.html ;; http://chneukirchen.org/repos/darcsum ;; This file is not yet part of GNU Emacs. ;; This module is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published ;; by the Free Software Foundation; either version 2, or (at your ;; option) any later version. ;; This module 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 ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; Load this file and run M-x darcsum-whatsnew. This will display a ;; pcl-cvs like buffer showing modified files. RET on a file reveals ;; changes; RET on a directory reveals changes to its files. ;; ;; Displayed changes may be recorded with "c", which offers a buffer ;; for inputing the change name (first line) and long description ;; (subsequent lines). C-c C-c records the patch. ;; ;; If you only want to record a part of your changes, you need to mark ;; those. If a change is "marked" in the summary buffer with "m" ;; (done on the change, the file (all changes) or the directory (all ;; changes in all files)), only marked changes are recorded, ;; regardless of point. ;; ;; Changes can be removed with "r". Move changes between buffers with ;; "M", which prompts for a darcsum buffer to move to (creating one if ;; the buffer doesn't exist). ;; ;; "g" forgets everything and resubmits the "whatsnew" command. ;; Collapsing a file forgets all marks for that file. Only displayed ;; changes are ever recorded! ;; ;; "n" and "p" move among files. "q" kills the buffer. ;; TODO (Patches are welcome!): ;; - When merging changesets, check the content of change text too ;; - Better support for moving files ;; - use --interactive with apply, for applying patches from e-mail ;; via darcsum ;; - Warn users of empty changesets before darcs does ;; - Better logfile handling ;; - Interface to darcs changes ;; - Changes from "replace" aren't shown ;; - Interface to darcs replace ;;; Code: (eval-when-compile (require 'cl) (require 'add-log)) ;; Attempt to handle older/other emacs in XEmacs way. ;; If `line-beginning-position' isn't available, use point-at-bol. (unless (fboundp 'line-beginning-position) (defalias 'line-beginning-position 'point-at-bol)) (defgroup darcsum nil "Special support for the Darcs versioning system." ;; :version "21.4" :group 'tools :prefix "darcsum-") (defvar darcsum-data nil) (defvar darcsum-look-for-adds nil) (defface darcsum-header-face '((((class color) (background dark)) (:foreground "lightyellow" :bold t)) (((class color) (background light)) (:foreground "blue4" :bold t)) (t (:bold t))) "Face used to highlight directory changes." :group 'darcsum) (defface darcsum-marked-face '((t (:bold t))) "Face used to highlight marked changes." :group 'darcsum) (defface darcsum-need-action-face '((((class color) (background dark)) (:foreground "orange")) (((class color) (background light)) (:foreground "orange")) (t (:italic t))) "" :group 'darcsum) (defface darcsum-need-action-marked-face '((((class color) (background dark)) (:foreground "orange" :bold t)) (((class color) (background light)) (:foreground "orange" :bold t)) (t (:italic t :bold t))) "" :group 'darcsum) (defface darcsum-filename-face '((((class color) (background dark)) (:foreground "lightblue")) (((class color) (background light)) (:foreground "blue4")) (t ())) "Face used to highlight file names." :group 'darcsum) (defface darcsum-change-line-face '((((class color) (background dark)) (:foreground "grey75" :background "grey25")) (((class color) (background light)) (:foreground "grey25" :background "grey75")) (t (:bold t))) "Face used to highlight file names." :group 'darcsum) (defun darcsum-add-props (str &rest props) (add-text-properties 0 (1- (length str)) (list* props) str) str) (defun darcsum-add-face (str face &optional keymap &rest props) (when keymap (when (keymapp keymap) (setq props (list* 'keymap keymap props))) (setq props (list* 'mouse-face 'highlight props))) (add-text-properties 0 (length str) (list* 'face face props) str) str) ;;; Code to work with changesets ;; A changeset is an alist of the following form: ;; ;; ((DIR (FILE (LINE CHANGE...)))) ;; ;; Where DIR and FILE are plain strings, but LINE is of the following ;; possible formats: ;; ;; LINE An integer giving the first line of the change ;; -LINE Integer line of change, but change is not "visible" ;; (LINE) Integer line of change, but change is "marked" ;; ;; Each CHANGE is a string which represent a modification to make to ;; the file after the starting LINE. It begins with either a "+" or ;; "-" to indicate if the line should be removed or added to the file. ;; ;; So, for example, in a buffer with no changes visible yet: ;; ;; (("." ;; ("TODO" addfile) ;; ("report.cc" ;; (-606 "- blah" "+ blah" "+ blah") ;; (-620 "- blah" "+ blah" "+ blah") ;; (-629 "- blah" "+ blah" "+ blah") ;; (-634 "- blah" "+ blah" "+ blah") ;; (-641 "- blah" "+ blah" "+ blah") ;; (-652 "- blah" "+ blah" "+ blah") ;; (-664 "- blah" "+ blah" "+ blah")) ;; ("report.h" ;; (-115 "- blah" "+ blah" "+ blah") ;; (-126 "+")))) (eval-and-compile (if (fboundp 'make-temp-file) (defalias 'darcsum-make-temp-file 'make-temp-file) ;; make-temp-name generates a unique name when it is called, but ;; takes no provisions to ensure that it will remain unique. Thus, ;; there is a race condition before we use the name. This is ;; probably a bad thing. (defalias 'darcsum-make-temp-file 'make-temp-name))) (defsubst darcsum-change-item (change) (if (listp (car change)) (caar change) (car change))) (defsubst darcsum-change-line (change) (let ((ch (darcsum-change-item change))) (if (symbolp ch) 1 ch))) (defun darcsum-applicable-p (data predicate) (catch 'exit (ignore (let (dir file change) (dolist (dir data) (dolist (file (cdr dir)) (dolist (change (cdr file)) (if (funcall predicate (car dir) (car file) change) (throw 'exit t))))))))) (defsubst darcsum-marked-p (data) (darcsum-applicable-p data (function (lambda (dir file change) (listp (car change)))))) (defsubst darcsum-changeset-has-change-p (data odir ofile start-line) (darcsum-applicable-p data (function (lambda (d f change) (and (equal odir d) (equal ofile f) (if (symbolp start-line) (eq start-line (darcsum-change-item change)) (equal start-line (abs (darcsum-change-line change))))))))) (defun darcsum-find-changeset (data predicate) (let (dir file change changeset) (dolist (dir data) (dolist (file (cdr dir)) (dolist (change (cdr file)) (if (funcall predicate (car dir) (car file) change) (setq changeset (darcsum-add-changeset changeset (list (list (car dir) (list (car file) change))))))))) changeset)) (defun darcsum-apply-to-changeset (data func) (let (dir file change) (dolist (dir data) (dolist (file (cdr dir)) (dolist (change (cdr file)) (funcall func (car dir) (car file) change)))))) (defun darcsum-remove-changeset (data changeset) "Remove DATA from the current CHANGESET." (let (dir file change) (dolist (dir changeset) (dolist (file (cdr dir)) (dolist (change (cdr file)) (let* ((dentry (assoc (car dir) data)) (fentry (assoc (car file) (cdr dentry)))) (setcdr fentry (delete (assoc (car change) (cdr fentry)) (cdr fentry))) (unless (cdr fentry) (setcdr dentry (delete fentry (cdr dentry)))) (unless (cdr dentry) (setq data (delete dentry data)))))))) data) (defun darcsum-add-changeset (data changeset) "Add DATA to the current CHANGESET." (let (dir file change) (dolist (dir changeset) (dolist (file (cdr dir)) (dolist (change (cdr file)) (let ((dentry (assoc (car dir) data))) (if dentry (let ((fentry (assoc (car file) dentry))) (if fentry (unless (member change (cdr fentry)) (nconc fentry (list change)) (setcdr fentry (sort (cdr fentry) (function (lambda (l r) (< (abs (darcsum-change-line l)) (abs (darcsum-change-line r)))))))) (nconc dentry (list (list (car file) change))))) (setq data (cons (list (car dir) (list (car file) change)) data)))))))) data) (defun darcsum-merge-changeset (data changeset) "Merge DATA into the current CHANGESET." (let (dir file change final-data) (dolist (dir changeset) (dolist (file (cdr dir)) (dolist (change (cdr file)) (let ((dentry (assoc (car dir) data))) (if dentry (let ((fentry (assoc (car file) dentry)) (item (darcsum-change-item change))) (if fentry (unless (if (integerp item) (or (assoc item (cdr fentry)) (assoc (- item) (cdr fentry)) (assoc (list item) (cdr fentry))) (or (assoc item (cdr fentry)) (assoc (list item) (cdr fentry)))) (nconc fentry (list change)) (setcdr fentry (sort (cdr fentry) (function (lambda (l r) (< (abs (darcsum-change-line l)) (abs (darcsum-change-line r)))))))) (nconc dentry (list (list (car file) change))))) (setq data (cons (list (car dir) (list (car file) change)) data))))))) (dolist (dir data) (dolist (file (cdr dir)) (dolist (change (cdr file)) (let* ((dentry (assoc (car dir) changeset)) (fentry (assoc (car file) dentry)) (item (darcsum-change-item change)) final-dentry final-fentry) (when (and dentry fentry (if (integerp item) (or (assoc item (cdr fentry)) (assoc (- item) (cdr fentry)) (assoc (list item) (cdr fentry))) (or (assoc item (cdr fentry)) (assoc (list item) (cdr fentry))))) (unless (setq final-dentry (assoc (car dir) final-data)) (setq final-data (cons (list (car dir)) final-data) final-dentry (assoc (car dir) final-data))) (unless (setq final-fentry (assoc (car file) final-dentry)) (nconc final-dentry (list (list (car file)))) (setq final-fentry (assoc (car file) final-dentry))) (nconc final-fentry (list change))))))) (nreverse final-data))) (defun darcsum-parse-changeset (&optional pending visible) "Return the patch in the current buffer as a Lisp changeset." (forward-line) (let ((limit (* 10 (count-lines (point-min) (point-max)))) data entries) (while (and (not (or (eobp) (looking-at "^}"))) (> limit 0)) (setq limit (1- limit)) (cond ((looking-at "^adddir\\s-+\\(.+?\\)$") (forward-line)) ((looking-at "^rmdir\\s-+\\(.+?\\)$") (forward-line)) ((looking-at "^move\\s-+\\(.+?\\)$") (forward-line)) ((looking-at "^\\(old\\|new\\)hex$") (forward-line) (while (looking-at "^\\*") (forward-line))) ((looking-at "^\\(addfile\\|binary\\|rmfile\\|hunk\\)\\s-+\\(.+?\\)\\(\\s-+\\([0-9]+\\)\\)?$") (let* ((kind (match-string 1)) (file (match-string 2)) (dir (directory-file-name (file-name-directory file))) (base (file-name-nondirectory file)) (start-line (match-string 4)) lines) (forward-line) (when start-line (while (looking-at "^\\([+ -].*\\)") (setq lines (cons (match-string 1) lines)) (forward-line))) (cond ((string= kind "addfile") (let ((add-dir dir) (add-file base)) (if (or (eq pending t) (and pending (darcsum-find-changeset pending (function (lambda (pdir pfile pchange) (and (string= add-dir pdir) (string= add-file pfile))))))) (setq entries (list 'addfile)) (setq entries (list 'newfile))))) ((string= kind "rmfile") (setq entries (list 'rmfile))) ((string= kind "binary") (setq entries (list 'binary))) (t (assert (string= kind "hunk")) (setq entries (cons (if visible (string-to-number start-line) (- (string-to-number start-line))) (nreverse lines))))) (let ((entry (assoc dir data))) (if (null entry) (setq data (cons (cons dir (list (cons base (list entries)))) data)) (if entry (let ((item (assoc base entry))) (if item (nconc item (list entries)) (nconc entry (list (cons base (list entries))))))))))))) (assert (>= limit 0)) (nreverse data))) (defun darcsum-read-changeset (&optional visible) (let ((pending (if (file-readable-p "_darcs/patches/pending") (with-temp-buffer (insert-file-contents "_darcs/patches/pending") (darcsum-parse-changeset t))))) (goto-char (point-min)) (when (looking-at "^What's new in \"\\([^\"]*\\)\":") (forward-line 2)) (if (looking-at "^{") (darcsum-parse-changeset pending visible)))) (defun darcsum-display-changeset (data) "Display the changeset DATA using a pcl-cvs-like buffer." (erase-buffer) ;;(when (file-readable-p "_darcs/prefs/lastrepo") ;; (insert "repository : ") ;; (insert-file-contents "_darcs/prefs/lastrepo") ;; (goto-char (point-max))) (insert "Working dir: " default-directory "\n\n\n") (unless data (insert "There are no changes to review.\n")) (let (dir file change line) (dolist (dir data) (insert (darcsum-add-props (concat "in directory " (darcsum-add-face (concat (car dir)) 'darcsum-header-face t) ":\n") 'darcsum-line-type 'dir 'darcsum-dir (car dir))) (dolist (file (cdr dir)) (let* ((all-changes (mapcar (function darcsum-change-item) (cdr file))) (all-marked (listp (car (cadr file)))) (status (cond ((memq 'newfile all-changes) "New") ((memq 'addfile all-changes) "Added") ((memq 'rmfile all-changes) "Removed") ((memq 'binary all-changes) "Modified binary") (t "Modified")))) (when (string= status "Modified") (setq all-marked t) (dolist (change (cdr file)) (if (and all-marked (not (listp (car change)))) (setq all-marked nil)))) (insert (darcsum-add-props (concat " " (darcsum-add-face (format "%-24s" status) (if all-marked 'darcsum-need-action-marked-face 'darcsum-need-action-face) t) (darcsum-add-face (concat (car file)) 'darcsum-filename-face t) "\n") 'darcsum-line-type 'file 'darcsum-dir (car dir) 'darcsum-file (car file)))) (dolist (change (cdr file)) (when (and (not (symbolp (darcsum-change-item change))) (> (darcsum-change-line change) 0)) (let ((beg (point))) (insert (darcsum-add-face (format "%-10d" (darcsum-change-line change)) 'darcsum-change-line-face t)) ;; Avoid trailing whitespace here, so that we could use ;; `show-trailing-whitespace' in Emacs, but make it ;; display as space. \000 is unlikely to be searched ;; for. NB "" as display property loses. (if (boundp 'show-trailing-whitespace) (if (fboundp 'propertize) (insert (propertize "\000" 'display " ")))) (insert ?\n) (dolist (line (cdr change)) (insert (if (not (listp (car change))) line (darcsum-add-face (concat line) 'darcsum-marked-face t)) ?\n)) (add-text-properties beg (point) (list 'darcsum-line-type 'change 'darcsum-dir (car dir) 'darcsum-file (car file) 'darcsum-change change)))))))) (insert " --------------------- End ---------------------\n")) ;;; Code to determine the current changeset in darcsum-mode (defun darcsum-changeset-at-point (&optional invisible-too) (let* ((type (get-text-property (point) 'darcsum-line-type)) (dir (get-text-property (point) 'darcsum-dir)) (dentry (and dir (assoc dir darcsum-data))) data) (cond ((eq type 'dir) (setq data (list dentry))) ((eq type 'file) (let* ((file (get-text-property (point) 'darcsum-file)) (fentry (assoc file dentry))) (setq data (list (list (car dentry) fentry))))) ((eq type 'change) (let* ((file (get-text-property (point) 'darcsum-file)) (fentry (assoc file dentry))) (setq data (list (list (car dentry) (list (car fentry) (get-text-property (point) 'darcsum-change)))))))) (if invisible-too data (darcsum-find-changeset data (function (lambda (dir file change) (setq change (darcsum-change-item change)) (or (symbolp change) (>= change 0)))))))) (defun darcsum-selected-changeset (&optional all-visible) "Return the currently selected changeset. If marks are active, always returned the marked changes. Otherwise, return the changes related to point, unless ALL-VISIBLE is non-nil, in which case return all visible changes." (cond ((darcsum-marked-p darcsum-data) (darcsum-find-changeset darcsum-data (function (lambda (dir file change) (listp (car change)))))) (all-visible (darcsum-find-changeset darcsum-data (function (lambda (dir file change) (and (numberp (car change)) (>= (car change) 0)))))) (t (darcsum-changeset-at-point)))) ;;; Code to record the current changeset ;; If there are any marked changes, these are what get recorded. ;; Otherwise, all *visible* changes are recorded. (defcustom darcsum-register ?S "The register in which the window configuration is stored." :type 'character :group 'darcsum) (defcustom darcsum-program "darcs" "*The program name which darcsum will use to invoke darcs." :type 'string :group 'darcsum) (defcustom darcsum-default-expanded nil "*Non-nil means the *darcsum* buffer will be expanded by default." :type 'boolean :group 'darcsum) (defvar darcsum-process-arg nil) (defvar darcsum-parent-buffer nil) (defvar darcsum-changeset-to-record nil) (defvar darcsum-logfile) (defsubst darcsum-changes-handled () (if (buffer-live-p darcsum-parent-buffer) (let ((changeset darcsum-changeset-to-record)) (with-current-buffer darcsum-parent-buffer (setq darcsum-data (darcsum-remove-changeset darcsum-data changeset)) (darcsum-refresh))))) (defun darcsum-start-process (subcommand args &optional name value &rest localize) "Start darcs process." (let* ((buf (generate-new-buffer (format " *darcs %s*" subcommand))) (process-environment ;; Use the environment variables to turn off highlighting. (You ;; could use `show-trailing-whitespace' in the buffer to highlight ;; trailing space in the diffs.) (append (list "DARCS_DONT_ESCAPE_TRAILING_SPACES=1" "DARCS_DONT_COLOR=1") process-environment)) (process-connection-type nil) (proc (apply 'start-process "darcs" buf darcsum-program subcommand args))) (set-process-sentinel proc 'darcsum-process-sentinel) (set-process-filter proc 'darcsum-process-filter) (with-current-buffer buf (while name (set (make-local-variable name) value) (setq name (car localize) value (cadr localize) localize (cddr localize)))) proc)) (defun darcsum-process-sentinel (proc string) (cond ((and (string-match "^exited abnormally" string) (process-buffer proc)) (message string)))) (defun darcsum-process-filter (proc string) (with-current-buffer (process-buffer proc) (let ((moving (= (point) (process-mark proc)))) (save-excursion ;; Insert the text, advancing the process marker. (goto-char (process-mark proc)) (insert string) (set-marker (process-mark proc) (point))) (if moving (goto-char (process-mark proc)))) (save-excursion (goto-char (point-min)) (cond ((looking-at "\n*Finished recording patch") (message "Changes recorded.") (darcsum-changes-handled) (delete-file darcsum-logfile) (kill-buffer (current-buffer))) ((looking-at "\n*Ok, if you don't want to record anything") (message "No changes recorded.") (delete-file darcsum-logfile) (kill-buffer (current-buffer))) ((looking-at "\n*What is the target email address") (process-send-string proc darcsum-process-arg) (delete-region (point-min) (point-max))) ((looking-at "\n*Successfully sent patch bundle") (message "Changes sent to `%s'." darcsum-process-arg) (kill-buffer (current-buffer))) ((looking-at "\n*You don't want to send any patches") (message "No changes sent.") (kill-buffer (current-buffer))) ((looking-at "\n*Do you really want to .+\\? ") (process-send-string proc "y\n") (delete-region (point-min) (point-max))) ((looking-at "\n*Finished reverting.") (message "Changes reverted.") (darcsum-changes-handled) (kill-buffer (current-buffer))) ((looking-at "\n*If you don't want to revert") (message "No changes reverted.") (kill-buffer (current-buffer))) ((looking-at "\n*\\(Waiting for lock.*\\)\n*") (let ((waiting (match-string 1))) (message waiting) (delete-region (point-min) (match-end 0)))) ((looking-at "\n*\\(Couldn't get lock.*\\)\n*") (let ((waiting (match-string 1))) (message waiting) (kill-buffer (current-buffer)))) ((looking-at "\n*Darcs needs to know what name") (let* ((default-mail (concat user-full-name " <" user-mail-address ">")) (enable-recursive-minibuffers t) (mail-address (read-string (format "What is your email address? (default %s) " default-mail) nil nil default-mail))) (process-send-string proc mail-address) (process-send-string proc "\n")) (re-search-forward "What is your email address\\?.*") (delete-region (point-min) (point))) ((looking-at "\n*\\(addfile\\|adddir\\|binary\\|rmfile\\|hunk\\)\\s-+\\(.+?\\)\\(\\s-+\\([0-9]+\\)\\)?$") (let* ((kind (match-string 1)) (file (match-string 2)) (dir (directory-file-name (file-name-directory file))) (base (file-name-nondirectory file)) (start-line (if (match-string 4) (string-to-number (match-string 4)) (intern kind)))) (goto-char (match-end 0)) (forward-line) (while (looking-at "^\\([+-].*\\)") (forward-line)) (when (looking-at "^Shall I \\(record\\|send\\|revert\\) this \\(patch\\|change\\)\\?.+[]:] ") (let ((end (match-end 0)) (record (darcsum-changeset-has-change-p darcsum-changeset-to-record dir base start-line))) (process-send-string proc (if record "y" "n")) (delete-region (point-min) end))))) ((looking-at "\n*\\(move\\).+") (goto-char (match-end 0)) (forward-line) (when (looking-at "^Shall I \\(record\\|send\\|revert\\) this patch\\?.+[]:] ") (let ((end (match-end 0))) (process-send-string proc "n") (delete-region (point-min) end)))))))) (defun darcsum-really-record () (interactive) (let ((tempfile (darcsum-make-temp-file "darcsum")) (parent-buf darcsum-parent-buffer) (changeset darcsum-changeset-to-record)) (save-excursion (goto-char (point-max)) (unless (bolp) (insert ?\n)) (goto-char (point-min)) (when (looking-at "^\\s-*$") (error "No record description entered"))) (write-region (point-min) (point-max) tempfile) (kill-buffer (current-buffer)) (jump-to-register darcsum-register) (message "Recording changes...") (darcsum-start-process "record" (list "--logfile" tempfile) 'darcsum-logfile tempfile 'darcsum-changeset-to-record changeset 'darcsum-parent-buffer parent-buf))) (defun darcsum-record () "Record selected changeset. Note that only changes displayed in the buffer (with \\<darcsum-mode-map>\\[darcsum-toggle]) are recorded." (interactive) (window-configuration-to-register darcsum-register) (let ((parent-buf (current-buffer)) (changeset (darcsum-selected-changeset t)) (buf (get-buffer-create "*darcs comment*"))) (switch-to-buffer-other-window buf) (darcsum-comment-mode) (set (make-local-variable 'darcsum-changeset-to-record) changeset) (set (make-local-variable 'darcsum-parent-buffer) parent-buf) (message "Title of change on first line, long comment after. C-c C-c to record."))) (defun darcsum-send (recipient) "Send selected changeset via email." (interactive "sSend changes to: ") (message "Sending changes...") (darcsum-start-process "send" (list) 'darcsum-changeset-to-record (darcsum-selected-changeset t) 'darcsum-parent-buffer (current-buffer) 'darcsum-process-arg recipient)) (defun darcsum-revert () "Revert selected changeset." (interactive) (when (yes-or-no-p "Really revert these changes? ") (message "Reverting changes...") (darcsum-start-process "revert" (list) 'darcsum-changeset-to-record (darcsum-selected-changeset t) 'darcsum-parent-buffer (current-buffer)))) (defvar darcsum-comment-mode-map (let ((map (make-sparse-keymap))) (define-key map "\C-x\C-s" 'darcsum-really-record) (define-key map "\C-c\C-c" 'darcsum-really-record) map)) (define-derived-mode darcsum-comment-mode indented-text-mode "Darcs Summary" "Major mode for output from \\<darcsum-mode-map>\\[darcsum-comment]. \\{darcsum-comment-mode-map}" :group 'darcsum (setq truncate-lines t)) ;;; Major Mode (defun darcsum-check-darcsum-mode () (unless (eq major-mode 'darcsum-mode) (error "Not in a darcsum-mode"))) (defun darcsum-reposition () (let ((type (get-text-property (point) 'darcsum-line-type))) (cond ((eq type 'dir) (goto-char (+ (line-beginning-position) 13))) ((eq type 'file) (goto-char (+ (line-beginning-position) 38))) ((eq type 'change) (goto-char (line-beginning-position)))))) (defsubst darcsum-other-buffer (other-buffer) (let ((buf (or other-buffer (generate-new-buffer "*darcs*")))) (with-current-buffer buf (unless (eq major-mode 'darcsum-mode) (darcsum-mode)) (current-buffer)))) (defun darcsum-move (other-buffer) "Move the selected changeset in another darcsum buffer. Changesets may be moved around in different buffers, to ease the collection of changes to record in a single darcs patch." (interactive "BMove change to (RET creates new patch): ") (let ((buf (darcsum-other-buffer other-buffer)) (changeset (darcsum-selected-changeset))) (setq darcsum-data (darcsum-remove-changeset darcsum-data changeset)) (with-current-buffer buf (let ((inhibit-redisplay t)) (darcsum-apply-to-changeset changeset (function (lambda (dir file change) (cond ((listp (car change)) (setcar change (caar change))) ((and (numberp (car change)) (< (car change) 0)) (setcar change (abs (car change)))))))) (setq darcsum-data (darcsum-add-changeset darcsum-data changeset)) (darcsum-refresh)))) (darcsum-refresh)) (defun darcsum-find-file (e &optional other view) "Open the selected entry. With a prefix OTHER, open the buffer in another window. VIEW non-nil means open in View mode." (interactive (list last-input-event current-prefix-arg)) (let* ((type (get-text-property (point) 'darcsum-line-type)) (file (if (eq 'type 'dir) (get-text-property (point) 'darcsum-dir) (darcsum-path (point))))) (cond ((eq type 'dir) (find-file (get-text-property (point) 'darcsum-dir))) ((eq type 'file) (cond ((eq other 'dont-select) (display-buffer (find-file-noselect file))) ((and other view) (view-file-other-window file)) (view (view-file file)) (other (find-file-other-window file)) (t (find-file file)))) ((eq type 'change) (let ((change-line (car (get-text-property (point) 'darcsum-change)))) (with-current-buffer (cond ((eq other 'dont-select) (display-buffer (find-file-noselect file))) ((and other view) (view-file-other-window file)) (view (view-file file)) (other (find-file-other-window file)) (t (find-file file))) (if (listp change-line) (setq change-line (car change-line))) (goto-line (abs change-line)))))))) (defun darcsum-find-file-other-window (e) "Select a buffer containing the file in another window." (interactive (list last-input-event)) (darcsum-find-file e t)) (defun darcsum-goto () "Open the selected entry, possibly moving point to the change's location." (interactive) (let ((type (get-text-property (point) 'darcsum-line-type))) (cond ((eq type 'dir) (find-file-other-window (get-text-property (point) 'darcsum-dir))) ((eq type 'file) (find-file-other-window (darcsum-path (point)))) ((eq type 'change) (let ((change-line (car (get-text-property (point) 'darcsum-change)))) (find-file-other-window (darcsum-path (point))) (if (listp change-line) (setq change-line (car change-line))) (goto-line (abs change-line))))))) (defun darcsum-toggle-context () (interactive) (darcsum-check-darcsum-mode) (setq darcsum-show-context (not darcsum-show-context)) (let ((dir default-directory) (darcsum-default-expanded t)) (message "Re-running darcsum-whatsnew") (let ((changes (darcsum-whatsnew dir nil t darcsum-show-context))) (setq darcsum-data changes)) (darcsum-refresh))) (defun darcsum-toggle-mark () "Toggle mark on current changeset. Marked changesets have priority over simply activated ones, regarding the selection of changesets to commit." (interactive) (darcsum-check-darcsum-mode) (let ((changeset (darcsum-changeset-at-point t))) (darcsum-apply-to-changeset changeset (function (lambda (dir file change) (if (listp (car change)) (setcar change (caar change)) (setcar change (list (car change)))))))) (darcsum-refresh)) (defun darcsum-toggle () "Toggle the activation of the current changeset. The activation of a changeset exposes the associated change, and selects it for later commit." (interactive) (darcsum-check-darcsum-mode) (let* ((changeset (darcsum-changeset-at-point t)) (add-or-remove (darcsum-applicable-p changeset (function (lambda (d f change) (or (eq (darcsum-change-item change) 'addfile) (eq (darcsum-change-item change) 'rmfile))))))) (unless add-or-remove (let ((any-visible (darcsum-applicable-p changeset (function (lambda (d f change) (let ((item (darcsum-change-item change))) (and (numberp item) (> item 0)))))))) (darcsum-apply-to-changeset changeset (function (lambda (dir file change) (let ((item (darcsum-change-item change))) (if (numberp item) (if any-visible (setcar change (- (abs item))) (if (listp (car change)) (setcar change (list (abs item))) (setcar change (abs item)))))))))))) (darcsum-refresh)) (defun darcsum-refresh () "Refresh the visualization of the changesets." (interactive) (darcsum-check-darcsum-mode) (let ((line (count-lines (point-min) (point))) (inhibit-redisplay t)) (if (/= (point) (line-beginning-position)) (setq line (1- line))) (darcsum-display-changeset darcsum-data) (goto-char (point-min)) (forward-line line) (darcsum-reposition))) (defun darcsum-line-is (sort) (save-excursion (beginning-of-line) (let ((type (get-text-property (point) 'darcsum-line-type))) (case sort ('new (and (eq 'file type) (looking-at " +New"))) ('modified (or (and (eq 'file type) (looking-at "\\s-+Modified")) (eq 'change type))) ('file (eq 'file type)) ('change (eq 'change type)) ('marked (memq (get-text-property (point) 'face) '(darcsum-marked-face darcsum-need-action-marked-face))))))) (defun darcsum-next-entity (&optional arg backward) "Move to the next file or change. With ARG, move that many times. BACKWARD non-nil means to go backwards." (interactive "p") (dotimes (i (or arg 1)) (forward-line (if backward -1)) (beginning-of-line) (while (and (not (if backward (bobp) (eobp))) (not (looking-at "[0-9]")) ; stop at line headers (darcsum-line-is 'change)) (forward-line (if backward -1 1))) (unless (get-text-property (point) 'darcsum-line-type) (goto-char (if backward (point-max) (point-min))) (forward-line (if backward -3 3))) (darcsum-reposition))) (defun darcsum-next-line (&optional arg) "Move to the next file or change. With ARG, move that many times." (interactive "p") (darcsum-next-entity arg)) (defun darcsum-previous-line (&optional arg) "Move to the previous file or change. With ARG, move that many times." (interactive "p") (darcsum-next-entity arg t)) (defun darcsum-original-path (pos) (let ((file (get-text-property pos 'darcsum-file)) (dir (get-text-property pos 'darcsum-dir))) (let ((path (expand-file-name ; new-style file (file-name-as-directory (expand-file-name dir "_darcs/pristine"))))) (if (file-readable-p path) path (let ((path (expand-file-name ; old-style file (file-name-as-directory (expand-file-name dir "_darcs/current"))))) (if (file-readable-p path) path)))))) (defun darcsum-path (pos) (expand-file-name (get-text-property pos 'darcsum-file) (file-name-as-directory (get-text-property pos 'darcsum-dir)))) (defcustom darcsum-diff-switches nil "*diff(1) switches used by `darcsum-diff'." :type 'string :group 'darcsum) (defun darcsum-diff () "Show the changes made to current selection." (interactive) (if (not (darcsum-original-path (point))) (error "No record of this file in darcs")) (let ((type (get-text-property (point) 'darcsum-line-type))) (cond ((eq type 'dir)) ((or (eq type 'file) (eq type 'change)) (require 'diff) ; for `diff-switches' (diff (darcsum-original-path (point)) (darcsum-path (point)) (or darcsum-diff-switches diff-switches)))))) (defun darcsum-delete () "Remove selected changeset from the view." (interactive) (setq darcsum-data (darcsum-remove-changeset darcsum-data (darcsum-selected-changeset))) (darcsum-refresh)) (defun darcsum-remove () "Remove a file from the repository." (interactive) (darcsum-check-darcsum-mode) (let ((type (get-text-property (point) 'darcsum-line-type))) (cond ((eq type 'dir) (error "Cannot remove whole directories yet; try file by file for now")) ((memq type '(file change)) (let* ((dir (get-text-property (point) 'darcsum-dir)) (dentry (and dir (assoc dir darcsum-data))) (file (get-text-property (point) 'darcsum-file)) (fentry (assoc file dentry)) (sym (darcsum-change-item (cadr fentry))) file-to-remove) (cond ((not (symbolp sym)) (when (yes-or-no-p (format "Really delete file with changes `%s'? " file)) (delete-file (expand-file-name file dir)) (setq file-to-remove file))) ((eq sym 'newfile) (delete-file (expand-file-name file dir))) ((eq sym 'addfile) (setq file-to-remove file) (delete-file (expand-file-name file dir))) (t (error "Removing makes no sense for that entry"))) (if file-to-remove (with-temp-buffer (cd (expand-file-name dir)) (if (/= 0 (call-process darcsum-program nil t nil "remove" file-to-remove)) (error "Error running `darcsum remove'")))))))) (darcsum-redo)) (defun darcsum-add () "Put new file or directory under Darcs control." (interactive) (darcsum-check-darcsum-mode) (dolist (dir (darcsum-selected-changeset)) (dolist (file (cdr dir)) (let ((item (darcsum-change-item (cadr file)))) (if (and (symbolp item) (eq item 'newfile)) (progn (setcar (cadr file) 'addfile) (with-temp-buffer (cd (expand-file-name (car dir))) (if (/= 0 (call-process darcsum-program nil t nil "add" (car file))) (error "Error running `darcsum add' for `%s' in dir `%s'" (car file) (car dir))))) (error "Can only add New entries for `%s' in dir `%s'" (car file) (car dir)))))) (darcsum-refresh)) (defun darcsum-add-to-boring (path) "Add current file or directory to the boring file. Propose the insertion of a regexp suitable to permanently ignore the file or the directory at point into the boring file." (interactive (let ((type (get-text-property (point) 'darcsum-line-type))) (cond ((eq type 'dir) (setq path (get-text-property (point) 'darcsum-dir)) (if (string-match "^\\./" path) (setq path (substring path 2))) (setq path (concat "(^|/)" (regexp-quote path) "($|/)"))) ((memq type '(file change)) (setq path (get-text-property (point) 'darcsum-file)) (setq path (concat "(^|/)" path "$")))) (list (read-string "Add to boring list: " path)))) (save-excursion (set-buffer (find-file-noselect "_darcs/prefs/boring")) (goto-char (point-max)) (insert path ?\n) (save-buffer) (kill-buffer (current-buffer))) (darcsum-redo)) (defun darcsum-add-change-log-entry () "Execute `add-change-log-entry' on the current file." (interactive) (let ((type (get-text-property (point) 'darcsum-line-type))) (cond ((eq type 'dir)) ((or (eq type 'file) (eq type 'change)) (darcsum-goto) (add-change-log-entry))))) (defun darcsum-ediff () "Like `darcsum-diff' but in an Ediff session." (interactive) (let ((type (get-text-property (point) 'darcsum-line-type))) (cond ((eq type 'dir)) ((or (eq type 'file) (eq type 'change)) (ediff (darcsum-original-path (point)) (darcsum-path (point))))))) (defun darcsum-ediff-merge () "Start an `ediff-merge' session on the current selection." (interactive) (let ((type (get-text-property (point) 'darcsum-line-type))) (cond ((eq type 'dir)) ((or (eq type 'file) (eq type 'change)) (ediff-merge (darcsum-original-path (point)) (darcsum-path (point))))))) (defun darcsum-redo (&optional arg) "Refresh the status, redoing `darcs whatsnew'." (interactive "P") (darcsum-check-darcsum-mode) (let ((dir default-directory) (look-for-adds (or arg darcsum-look-for-adds)) (darcsum-default-expanded t)) (message "Re-running darcsum-whatsnew") (let ((changes (darcsum-whatsnew dir look-for-adds t darcsum-show-context))) (setq darcsum-data (darcsum-merge-changeset darcsum-data changes))) (darcsum-refresh))) (defun darcsum-quit () "Close the darcsum buffer and quit." (interactive) (darcsum-check-darcsum-mode) (kill-buffer (current-buffer))) (defun darcsum-add-comment () "Similar to `add-change-log-entry'. Inserts the entry in the darcs comment file instead of the ChangeLog." ;; This is mostly copied from add-log.el and Xtla. Perhaps it would ;; be better to split add-change-log-entry into several functions ;; and then use them, but that wouldn't work with older versions of ;; Emacs. (interactive) (require 'add-log) (let* ((defun (add-log-current-defun)) (buf-file-name (if (and (boundp 'add-log-buffer-file-name-function) add-log-buffer-file-name-function) (funcall add-log-buffer-file-name-function) buffer-file-name)) (buffer-file (if buf-file-name (expand-file-name buf-file-name))) ; (file-name (tla-make-log)) ;; Set ENTRY to the file name to use in the new entry. (entry (add-log-file-name buffer-file default-directory)) beg bound narrowing) (switch-to-buffer-other-window (get-buffer-create "*darcs comment*")) (goto-char (point-min)) (forward-line 1) ; skip header ;; Now insert the new line for this entry. (cond ((re-search-forward "^\\s *\\*\\s *$" bound t) ;; Put this file name into the existing empty entry. (if entry (insert entry))) ((let (case-fold-search) (re-search-forward (concat (regexp-quote (concat "* " entry)) ;; Don't accept `foo.bar' when ;; looking for `foo': "\\(\\s \\|[(),:]\\)") bound t)) ;; Add to the existing entry for the same file. (re-search-forward "^\\s *$\\|^\\s \\*\\|\\'") (goto-char (match-beginning 0)) ;; Delete excess empty lines; make just 2. (while (and (not (eobp)) (looking-at "^\\s *$")) (delete-region (point) (line-beginning-position 2))) (insert-char ?\n 2) (forward-line -2) (indent-relative-maybe)) (t ;; Make a new entry. (goto-char (point-max)) (re-search-backward "^." nil t) (end-of-line) (insert "\n* ") (if entry (insert entry)))) ;; Now insert the function name, if we have one. ;; Point is at the entry for this file, ;; either at the end of the line or at the first blank line. (if defun (progn ;; Make it easy to get rid of the function name. (undo-boundary) (unless (save-excursion (beginning-of-line 1) (looking-at "\\s *$")) (insert ?\ )) ;; See if the prev function name has a message yet or not ;; If not, merge the two entries. (let ((pos (point-marker))) (if (and (skip-syntax-backward " ") (skip-chars-backward "):") (looking-at "):") (progn (delete-region (+ 1 (point)) (+ 2 (point))) t) (> fill-column (+ (current-column) (length defun) 3))) (progn (delete-region (point) pos) (insert ", ")) (goto-char pos) (insert "(")) (set-marker pos nil)) (insert defun "): ")) ;; No function name, so put in a colon unless we have just a star. (unless (save-excursion (beginning-of-line 1) (looking-at "\\s *\\(\\*\\s *\\)?$")) (insert ": "))))) (defvar darcsum-mode-abbrev-table nil "Abbrev table used while in darcsum-mode mode.") (define-abbrev-table 'darcsum-mode-abbrev-table ()) (global-set-key "\C-xD" 'darcsum-add-comment) (defvar darcsum-mode-map (let ((map (make-sparse-keymap))) (suppress-keymap map) (define-key map [return] 'darcsum-toggle) ; ?? (define-key map "\C-m" 'darcsum-toggle) (define-key map "\C-c\C-c" 'darcsum-goto) (define-key map "?" 'describe-mode) (define-key map "f" 'darcsum-find-file) (define-key map "=" 'darcsum-diff) (define-key map "e" 'darcsum-ediff) (define-key map "E" 'darcsum-ediff-merge) (define-key map "g" 'darcsum-redo) (define-key map "n" 'darcsum-next-line) (define-key map "p" 'darcsum-previous-line) (define-key map "a" 'darcsum-add) (define-key map "l" 'darcsum-add-change-log-entry) (define-key map "c" 'darcsum-record) (define-key map "R" 'darcsum-record) (define-key map "U" 'darcsum-revert) (define-key map "u" 'darcsum-toggle-context) (define-key map "d" 'darcsum-delete) ;; (define-key map "r" 'darcsum-remove) (define-key map "M" 'darcsum-move) (define-key map "m" 'darcsum-toggle-mark) (define-key map "i" 'darcsum-add-to-boring) (define-key map "B" 'darcsum-add-to-boring) (define-key map "q" 'darcsum-quit) map)) (easy-menu-define darcsum-menu darcsum-mode-map "Menu used in `darcsum-mode'." '("Darcs summary" ["Open file.." darcsum-find-file (or (darcsum-line-is 'file) (darcsum-line-is 'change))] [" ..other window" darcsum-find-file-other-window (or (darcsum-line-is 'file) (darcsum-line-is 'change))] ["Display in other window" darcsum-display-file t] ("Differences" ["Interactive diff" darcsum-ediff t] ["Current diff" darcsum-diff t] ["Interactive merge" darcsum-ediff-merge t]) ;; ["View log" darcsum-log t] "--" ["Re-examine" darcsum-redo t] ["Record changes" darcsum-record t] ; fixme: condition ;; ["Tag" darcsum-tag t] ["Undo changes" darcsum-revert t] ; fixme: condition ["Add" darcsum-add (darcsum-line-is 'new)] ["Remove" darcsum-remove (darcsum-line-is 'file)] ["Ignore" darcsum-add-to-boring (darcsum-line-is 'file)] ["Add ChangeLog" darcsum-add-change-log-entry t] ["Delete" darcsum-delete t] "--" ["(Un)activate change" darcsum-toggle t] ["(Un)mark change" darcsum-toggle-mark :style toggle :selected (darcsum-line-is 'marked)] ["Next file/change" darcsum-next-line t] ["Previous file/change" darcsum-previous-line t] ["Move changeset" darcsum-move t] ["Show change context" darcsum-toggle-context :style toggle :selected darcsum-show-context] "--" ["Quit" darcsum-quit t] )) (define-derived-mode darcsum-mode fundamental-mode "Darcs" "Darcs summary mode is for previewing changes to become part of a patch. \\{darcsum-mode-map}" :group 'darcsum (if (featurep 'xemacs) (easy-menu-add darcsum-menu darcsum-mode-map))) (put 'darcsum-mode 'mode-class 'special) (custom-add-option 'darcsum-mode-hook '(lambda () ; Should be a minor mode for this! "Show trailing whitespace in changes." (setq show-trailing-whitespace t))) ;;; This is the entry code, M-x darcsum (or M-x darcs-summary) (defun darcsum-display (data &optional look-for-adds) (with-current-buffer (generate-new-buffer "*darcs*") (darcsum-mode) (set (make-local-variable 'darcsum-data) data) (set (make-local-variable 'darcsum-look-for-adds) look-for-adds) (set (make-local-variable 'darcsum-show-context) nil) (darcsum-refresh) (goto-char (point-min)) (forward-line 3) (darcsum-reposition) (switch-to-buffer (current-buffer)))) (defun darcsum-repository-root (&optional start-directory) "Return the root of the repository, or nil if there isn't one." (let ((dir (or start-directory default-directory (error "No start directory given")))) (if (car (directory-files dir t "^_darcs$")) dir (let ((next-dir (file-name-directory (directory-file-name (file-truename dir))))) (unless (or (equal dir next-dir) (null next-dir)) (darcsum-repository-root next-dir)))))) (defcustom darcsum-whatsnew-switches nil "*Switches for `darcsum-whatsnew'." :type 'string :group 'darcsum) (defcustom darcsum-whatsnew-at-toplevel t "*Use top-level repository directory as default argument to darcsum-whatsnew." :type 'boolean :group 'darcsum) ;;;###autoload (defun darcsum-whatsnew (directory &optional look-for-adds no-display show-context) (interactive ; fancy "DDirectory: \nP" (let ((root (if darcsum-whatsnew-at-toplevel (darcsum-repository-root) default-directory))) (list (funcall (if (fboundp 'read-directory-name) 'read-directory-name 'read-file-name) "Directory: " root root) (or darcsum-look-for-adds current-prefix-arg)))) (with-temp-buffer (cd directory) (let ((repo (darcsum-repository-root))) (unless repo (error "Directory `%s' is not under darcs version control" directory)) (cd repo)) (let* ((process-environment (cons "DARCS_DONT_ESCAPE_TRAILING_SPACES=1" (cons "DARCS_DONT_COLOR=1" process-environment))) (args (append ;; Build a list of arguments for call-process (list darcsum-program nil t nil) (list "whatsnew" "--no-summary") (darcsum-fix-switches darcsum-whatsnew-switches) ; Arguments override user preferences (unless (null look-for-adds) (list "--look-for-adds")) (unless (null show-context) (list "--unified")) (unless (string= directory default-directory) (list (file-relative-name directory default-directory))) nil)) (result (apply 'call-process args))) (if (/= result 0) (if (= result 1) (progn (and (interactive-p) (message "No changes!")) nil) (progn (if (member "*darcs-output*" (mapcar (lambda (&rest x) (apply 'buffer-name x)) (buffer-list))) (kill-buffer "*darcs-output*")) (if (fboundp 'clone-buffer) (clone-buffer "*darcs-output*" t)) (error "Error running darcsum whatsnew"))) (let ((changes (darcsum-read-changeset darcsum-default-expanded))) (if (and changes (not no-display)) (darcsum-display changes look-for-adds)) changes))))) ; lifted from diff.el (defun darcsum-fix-switches (switch-spec) "Parse SWITCH-SPEC into a list of switches. Leave it be if it's not a string." (if (stringp switch-spec) (let (result (start 0)) (while (string-match "\\(\\S-+\\)" switch-spec start) (setq result (cons (substring switch-spec (match-beginning 1) (match-end 1)) result) start (match-end 0))) (nreverse result)) switch-spec)) ;;;###autoload (defun darcsum-view (directory) (interactive (list (funcall (if (fboundp 'read-directory-name) 'read-directory-name 'read-file-name) "Directory: " (darcsum-repository-root)))) (unless (file-directory-p (expand-file-name "_darcs" directory)) (error "Directory `%s' is not under darcs version control" directory)) (if (or (and (search-forward "{" nil t) (goto-char (1- (point)))) (search-backward "{" nil t)) (let ((changes (darcsum-parse-changeset)) (default-directory directory)) (darcsum-display changes)) (error "Cannot find a darcs patch in the current buffer"))) ;;; Gnus integration code, for viewing darcs patches in a changeset ;;; buffer. They cannot be recorded from there, however, since the ;;; changes have not been applied to the working tree. To do this, ;;; you must still pipe the message to "darcs apply". This code only ;;; works as a browser for now. (defvar darcsum-install-gnus-code nil) (when darcsum-install-gnus-code (defun mm-view-darcs-patch (handle) "View HANDLE as a darcs patch, using darcsum.el." (let* ((name (mail-content-type-get (mm-handle-type handle) 'name)) (directory (funcall (if (fboundp 'read-directory-name) 'read-directory-name 'read-file-name) "Apply patch to directory: "))) (mm-with-unibyte-buffer (mm-insert-part handle) (let ((coding-system-for-write 'binary)) (goto-char (point-min)) (darcsum-view directory) (delete-other-windows))))) (defun gnus-mime-view-darcs-patch () "Pipe the MIME part under point to a process." (interactive) (gnus-article-check-buffer) (let ((data (get-text-property (point) 'gnus-data))) (when data (mm-view-darcs-patch data)))) (defun gnus-article-view-darcs-patch (n) "Pipe MIME part N, which is the numerical prefix." (interactive "p") (gnus-article-part-wrapper n 'mm-view-darcs-patch)) (eval-after-load "gnus-art" '(progn (nconc gnus-mime-action-alist '(("apply darcs patch" . gnus-mime-view-darcs-patch))) (nconc gnus-mime-button-commands '((gnus-mime-view-darcs-patch "V" "Apply darcs patch..."))))) (defun gnus-summary-view-darcs-patch (directory) "Apply the current article as a darcs patch to DIRECTORY." (interactive "DApply patch to directory: ") (gnus-summary-select-article) (let ((mail-header-separator "")) (gnus-eval-in-buffer-window gnus-article-buffer (save-restriction (widen) (goto-char (point-min)) (darcsum-view directory))))) (eval-after-load "gnus-sum" '(progn (define-key gnus-summary-mime-map "V" 'gnus-article-view-darcs-patch) (define-key gnus-summary-article-map "V" 'gnus-summary-view-darcs-patch)))) (provide 'darcsum) ;;; darcsum.el ends here
52,728
Common Lisp
.l
1,404
32.539886
112
0.646664
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
cbdbb473f9c5b673aa38d73bb3b3d30f7a8b8422605e275e1b0e5c74df44ff1a
8,427
[ -1 ]
8,428
paredit-beta.el
evrim_core-server/etc/emacs/paredit-beta.el
;;; -*- Mode: Emacs-Lisp; outline-regexp: " \n;;;;+" -*- ;;;;;; Paredit: Parenthesis-Editing Minor Mode ;;;;;; Version 20 ;;; This code is written by Taylor R. Campbell (except where explicitly ;;; noted) and placed in the Public Domain. All warranties are ;;; disclaimed. ;;; Add this to your .emacs after adding paredit.el to /path/to/elisp/: ;;; ;;; (add-to-list 'load-path "/path/to/elisp/") ;;; (autoload 'paredit-mode "paredit" ;;; "Minor mode for pseudo-structurally editing Lisp code." ;;; t) ;;; (add-hook '...-mode-hook (lambda () (paredit-mode +1))) ;;; ;;; Usually the ... will be lisp or scheme or both. Alternatively, you ;;; can manually toggle this mode with M-x paredit-mode. Customization ;;; of paredit can be accomplished with `eval-after-load': ;;; ;;; (eval-after-load 'paredit ;;; '(progn ...redefine keys, &c....)) ;;; ;;; This should run in GNU Emacs 21 or later and XEmacs 21.5 or later. ;;; It is highly unlikely to work in earlier versions of GNU Emacs, and ;;; it may have obscure problems in earlier versions of XEmacs due to ;;; the way its syntax parser reports conditions, as a result of which ;;; the code that uses the syntax parser must mask *all* error ;;; conditions, not just those generated by the syntax parser. ;;; This mode changes the keybindings for a number of simple keys, ;;; notably (, ), ", \, and ;. The bracket keys (round or square) are ;;; defined to insert parenthesis pairs and move past the close, ;;; respectively; the double-quote key is multiplexed to do both, and ;;; also insert an escape if within a string; backslashes prompt the ;;; user for the next character to input, because a lone backslash can ;;; break structure inadvertently; and semicolons ensure that they do ;;; not accidentally comment valid structure. (Use M-; to comment an ;;; expression.) These all have their ordinary behaviour when inside ;;; comments, and, outside comments, if truly necessary, you can insert ;;; them literally with C-q. ;;; ;;; These keybindings are set up for my preference. One particular ;;; preference which I've seen vary greatly from person to person is ;;; whether the command to move past a closing delimiter ought to ;;; insert a newline. Since I find this behaviour to be more common ;;; than that which inserts no newline, I have ) bound to it, and the ;;; more involved M-) to perform the less common action. This bothers ;;; some users, though, and they prefer the other way around. This ;;; code, which you can use `eval-after-load' to put in your .emacs, ;;; will exchange the bindings: ;;; ;;; (define-key paredit-mode-map (kbd ")") ;;; 'paredit-close-parenthesis) ;;; (define-key paredit-mode-map (kbd "M-)") ;;; 'paredit-close-parenthesis-and-newline) ;;; ;;; Paredit also changes the bindings of keys for deleting and killing, ;;; so that they will not destroy any S-expression structure by killing ;;; or deleting only one side of a bracket or quote pair. If the point ;;; is on a closing bracket, DEL will move left over it; if it is on an ;;; opening bracket, C-d will move right over it. Only if the point is ;;; between a pair of brackets will C-d or DEL delete them, and in that ;;; case it will delete both simultaneously. M-d and M-DEL kill words, ;;; but skip over any S-expression structure. C-k kills from the start ;;; of the line, either to the line's end, if it contains only balanced ;;; expressions; to the first closing bracket, if the point is within a ;;; form that ends on the line; or up to the end of the last expression ;;; that starts on the line after the point. ;;; ;;; Automatic reindentation is performed as locally as possible, to ;;; ensure that Emacs does not interfere with custom indentation used ;;; elsewhere in some S-expression. It is performed only by the ;;; advanced S-expression frobnication commands, and only on the forms ;;; that were immediately operated upon (& their subforms). ;;; ;;; This code is written for clarity, not efficiency. S-expressions ;;; are frequently walked over redundantly. If you have problems with ;;; some of the commands taking too long to execute, tell me, but first ;;; make sure that what you're doing is reasonable: it is stylistically ;;; bad to have huge, long, hideously nested code anyway. ;;; ;;; Questions, bug reports, comments, feature suggestions, &c., can be ;;; addressed to the author via mail on the host mumble.net to campbell ;;; or via IRC on irc.freenode.net in the #paredit channel under the ;;; nickname Riastradh. ;;; This assumes Unix-style LF line endings. (defconst paredit-version 20) (eval-and-compile (defun paredit-xemacs-p () ;; No idea I got this definition from. Edward O'Connor (hober on ;; IRC) suggested the current definition. ;; (and (boundp 'running-xemacs) ;; running-xemacs) (featurep 'xemacs)) (defun paredit-gnu-emacs-p () (not (paredit-xemacs-p))) (defmacro xcond (&rest clauses) "Exhaustive COND. Signal an error if no clause matches." `(cond ,@clauses (t (error "XCOND lost.")))) (defalias 'paredit-warn (if (fboundp 'warn) 'warn 'message)) (defvar paredit-sexp-error-type (with-temp-buffer (insert "(") (condition-case condition (backward-sexp) (error (if (eq (car condition) 'error) (paredit-warn "%s%s%s%s" "Paredit is unable to discriminate" " S-expression parse errors from" " other errors. " " This may cause obscure problems. " " Please upgrade Emacs.")) (car condition))))) (defmacro paredit-handle-sexp-errors (body &rest handler) `(condition-case () ,body (,paredit-sexp-error-type ,@handler))) (put 'paredit-handle-sexp-errors 'lisp-indent-function 1) (defmacro paredit-ignore-sexp-errors (&rest body) `(paredit-handle-sexp-errors (progn ,@body) nil)) (put 'paredit-ignore-sexp-errors 'lisp-indent-function 0) nil) ;;;; Minor Mode Definition (defvar paredit-mode-map (make-sparse-keymap) "Keymap for the paredit minor mode.") (define-minor-mode paredit-mode "Minor mode for pseudo-structurally editing Lisp code. \\<paredit-mode-map>" :lighter " Paredit" ;; If we're enabling paredit-mode, the prefix to this code that ;; DEFINE-MINOR-MODE inserts will have already set PAREDIT-MODE to ;; true. If this is the case, then first check the parentheses, and ;; if there are any imbalanced ones we must inhibit the activation of ;; paredit mode. We skip the check, though, if the user supplied a ;; prefix argument interactively. (if (and paredit-mode (not current-prefix-arg)) (if (not (fboundp 'check-parens)) (paredit-warn "`check-parens' is not defined; %s" "be careful of malformed S-expressions.") (condition-case condition (check-parens) (error (setq paredit-mode nil) (signal (car condition) (cdr condition))))))) ;;; Old functions from when there was a different mode for emacs -nw. (defun enable-paredit-mode () "Turn on pseudo-structural editing of Lisp code. Deprecated: use `paredit-mode' instead." (interactive) (paredit-mode +1)) (defun disable-paredit-mode () "Turn off pseudo-structural editing of Lisp code. Deprecated: use `paredit-mode' instead." (interactive) (paredit-mode -1)) (defvar paredit-backward-delete-key (xcond ((paredit-xemacs-p) "BS") ((paredit-gnu-emacs-p) "DEL"))) (defvar paredit-forward-delete-keys (xcond ((paredit-xemacs-p) '("DEL")) ((paredit-gnu-emacs-p) '("<delete>" "<deletechar>")))) ;;;; Paredit Keys ;;; Separating the definition and initialization of this variable ;;; simplifies the development of paredit, since re-evaluating DEFVAR ;;; forms doesn't actually do anything. (defvar paredit-commands nil "List of paredit commands with their keys and examples.") ;;; Each specifier is of the form: ;;; (key[s] function (example-input example-output) ...) ;;; where key[s] is either a single string suitable for passing to KBD ;;; or a list of such strings. Entries in this list may also just be ;;; strings, in which case they are headings for the next entries. (progn (setq paredit-commands `( "Basic Insertion Commands" ("(" paredit-open-parenthesis ("(a b |c d)" "(a b (|) c d)") ("(foo \"bar |baz\" quux)" "(foo \"bar (|baz\" quux)")) (")" paredit-close-parenthesis-and-newline ("(defun f (x| ))" "(defun f (x)\n |)") ("; (Foo.|" "; (Foo.)|")) ("M-)" paredit-close-parenthesis ("(a b |c )" "(a b c)|") ("; Hello,| world!" "; Hello,)| world!")) ("[" paredit-open-bracket ("(a b |c d)" "(a b [|] c d)") ("(foo \"bar |baz\" quux)" "(foo \"bar [baz\" quux)")) ("]" paredit-close-bracket ("(define-key keymap [frob| ] 'frobnicate)" "(define-key keymap [frob]| 'frobnicate)") ("; [Bar.|" "; [Bar.]|")) ("\"" paredit-doublequote ("(frob grovel |full lexical)" "(frob grovel \"|\" full lexical)") ("(foo \"bar |baz\" quux)" "(foo \"bar \\\"|baz\" quux)")) ("M-\"" paredit-meta-doublequote ("(foo \"bar |baz\" quux)" "(foo \"bar baz\"\n |quux)") ("(foo |(bar #\\x \"baz \\\\ quux\") zot)" ,(concat "(foo \"|(bar #\\\\x \\\"baz \\\\" "\\\\ quux\\\")\" zot)"))) ("\\" paredit-backslash ("(string #|)\n ; Escaping character... (x)" "(string #\\x|)") ("\"foo|bar\"\n ; Escaping character... (\")" "\"foo\\\"|bar\"")) (";" paredit-semicolon ("|(frob grovel)" ";|\n(frob grovel)") ("(frob grovel) |" "(frob grovel) ;|")) ("M-;" paredit-comment-dwim ("(foo |bar) ; baz" "(foo bar) ; |baz") ("(frob grovel)|" "(frob grovel) ;|") (" (foo bar)\n|\n (baz quux)" " (foo bar)\n ;; |\n (baz quux)") (" (foo bar) |(baz quux)" " (foo bar)\n ;; |\n (baz quux)") ("|(defun hello-world ...)" ";;; |\n(defun hello-world ...)")) ("C-j" paredit-newline ("(let ((n (frobbotz))) |(display (+ n 1)\nport))" ,(concat "(let ((n (frobbotz)))" "\n |(display (+ n 1)" "\n port))"))) "Deleting & Killing" (("C-d" ,@paredit-forward-delete-keys) paredit-forward-delete ("(quu|x \"zot\")" "(quu| \"zot\")") ("(quux |\"zot\")" "(quux \"|zot\")" "(quux \"|ot\")") ("(foo (|) bar)" "(foo | bar)") ("|(foo bar)" "(|foo bar)")) (,paredit-backward-delete-key paredit-backward-delete ("(\"zot\" q|uux)" "(\"zot\" |uux)") ("(\"zot\"| quux)" "(\"zot|\" quux)" "(\"zo|\" quux)") ("(foo (|) bar)" "(foo | bar)") ("(foo bar)|" "(foo bar|)")) ("C-k" paredit-kill ("(foo bar)| ; Useless comment!" "(foo bar)|") ("(|foo bar) ; Useful comment!" "(|) ; Useful comment!") ("|(foo bar) ; Useless line!" "|") ("(foo \"|bar baz\"\n quux)" "(foo \"|\"\n quux)")) ("M-d" paredit-forward-kill-word ("|(foo bar) ; baz" "(| bar) ; baz" "(|) ; baz" "() ;|") (";;;| Frobnicate\n(defun frobnicate ...)" ";;;|\n(defun frobnicate ...)" ";;;\n(| frobnicate ...)")) (,(concat "M-" paredit-backward-delete-key) paredit-backward-kill-word ("(foo bar) ; baz\n(quux)|" "(foo bar) ; baz\n(|)" "(foo bar) ; |\n()" "(foo |) ; \n()" "(|) ; \n()")) "Movement & Navigation" ("C-M-f" paredit-forward ("(foo |(bar baz) quux)" "(foo (bar baz)| quux)") ("(foo (bar)|)" "(foo (bar))|")) ("C-M-b" paredit-backward ("(foo (bar baz)| quux)" "(foo |(bar baz) quux)") ("(|(foo) bar)" "|((foo) bar)")) ;;;("C-M-u" backward-up-list) ; These two are built-in. ;;;("C-M-d" down-list) ("C-M-p" backward-down-list) ; Built-in, these are FORWARD- ("C-M-n" up-list) ; & BACKWARD-LIST, which have ; no need given C-M-f & C-M-b. "Depth-Changing Commands" ("M-(" paredit-wrap-sexp ("(foo |bar baz)" "(foo (|bar) baz)")) ("M-s" paredit-splice-sexp ("(foo (bar| baz) quux)" "(foo bar| baz quux)")) (("M-<up>" "ESC <up>") paredit-splice-sexp-killing-backward ("(foo (let ((x 5)) |(sqrt n)) bar)" "(foo (sqrt n) bar)")) (("M-<down>" "ESC <down>") paredit-splice-sexp-killing-forward ("(a (b c| d e) f)" "(a b c f)")) ("M-r" paredit-raise-sexp ("(dynamic-wind in (lambda () |body) out)" "(dynamic-wind in |body out)" "|body")) "Barfage & Slurpage" (("C-)" "C-<right>") paredit-forward-slurp-sexp ("(foo (bar |baz) quux zot)" "(foo (bar |baz quux) zot)") ("(a b ((c| d)) e f)" "(a b ((c| d) e) f)")) (("C-}" "C-<left>") paredit-forward-barf-sexp ("(foo (bar |baz quux) zot)" "(foo (bar |baz) quux zot)")) (("C-(" "C-M-<left>" "ESC C-<left>") paredit-backward-slurp-sexp ("(foo bar (baz| quux) zot)" "(foo (bar baz| quux) zot)") ("(a b ((c| d)) e f)" "(a (b (c| d)) e f)")) (("C-{" "C-M-<right>" "ESC C-<right>") paredit-backward-barf-sexp ("(foo (bar baz |quux) zot)" "(foo bar (baz |quux) zot)")) "Miscellaneous Commands" ("M-S" paredit-split-sexp ("(hello| world)" "(hello)| (world)") ("\"Hello, |world!\"" "\"Hello, \"| \"world!\"")) ("M-J" paredit-join-sexps ("(hello)| (world)" "(hello| world)") ("\"Hello, \"| \"world!\"" "\"Hello, |world!\"") ("hello-\n| world" "hello-|world")) ("C-c C-M-l" paredit-recentre-on-sexp) )) nil) ; end of PROGN ;;;;; Command Examples (eval-and-compile (defmacro paredit-do-commands (vars string-case &rest body) (let ((spec (nth 0 vars)) (keys (nth 1 vars)) (fn (nth 2 vars)) (examples (nth 3 vars))) `(dolist (,spec paredit-commands) (if (stringp ,spec) ,string-case (let ((,keys (let ((k (car ,spec))) (cond ((stringp k) (list k)) ((listp k) k) (t (error "Invalid paredit command %s." ,spec))))) (,fn (cadr ,spec)) (,examples (cddr ,spec))) ,@body))))) (put 'paredit-do-commands 'lisp-indent-function 2)) (defun paredit-define-keys () (paredit-do-commands (spec keys fn examples) nil ; string case (dolist (key keys) (define-key paredit-mode-map (read-kbd-macro key) fn)))) (defun paredit-function-documentation (fn) (let ((original-doc (get fn 'paredit-original-documentation)) (doc (documentation fn 'function-documentation))) (or original-doc (progn (put fn 'paredit-original-documentation doc) doc)))) (defun paredit-annotate-mode-with-examples () (let ((contents (list (paredit-function-documentation 'paredit-mode)))) (paredit-do-commands (spec keys fn examples) (push (concat "\n \n" spec "\n") contents) (let ((name (symbol-name fn))) (if (string-match (symbol-name 'paredit-) name) (push (concat "\n\n\\[" name "]\t" name (if examples (mapconcat (lambda (example) (concat "\n" (mapconcat 'identity example "\n --->\n") "\n")) examples "") "\n (no examples)\n")) contents)))) (put 'paredit-mode 'function-documentation (apply 'concat (reverse contents)))) ;; PUT returns the huge string we just constructed, which we don't ;; want it to return. nil) (defun paredit-annotate-functions-with-examples () (paredit-do-commands (spec keys fn examples) nil ; string case (put fn 'function-documentation (concat (paredit-function-documentation fn) "\n\n\\<paredit-mode-map>\\[" (symbol-name fn) "]\n" (mapconcat (lambda (example) (concat "\n" (mapconcat 'identity example "\n ->\n") "\n")) examples ""))))) ;;;;; HTML Examples (defun paredit-insert-html-examples () "Insert HTML for a paredit quick reference table." (interactive) (let ((insert-lines (lambda (&rest lines) (mapc (lambda (line) (insert line) (newline)) lines))) (html-keys (lambda (keys) (mapconcat 'paredit-html-quote keys ", "))) (html-example (lambda (example) (concat "<table><tr><td><pre>" (mapconcat 'paredit-html-quote example (concat "</pre></td></tr><tr><td>" "&nbsp;&nbsp;&nbsp;&nbsp;---&gt;" "</td></tr><tr><td><pre>")) "</pre></td></tr></table>"))) (firstp t)) (paredit-do-commands (spec keys fn examples) (progn (if (not firstp) (insert "</table>\n") (setq firstp nil)) (funcall insert-lines (concat "<h3>" spec "</h3>") "<table border=\"1\" cellpadding=\"1\">" " <tr>" " <th>Command</th>" " <th>Keys</th>" " <th>Examples</th>" " </tr>")) (let ((name (symbol-name fn))) (if (string-match (symbol-name 'paredit-) name) (funcall insert-lines " <tr>" (concat " <td><tt>" name "</tt></td>") (concat " <td align=\"center\">" (funcall html-keys keys) "</td>") (concat " <td>" (if examples (mapconcat html-example examples "<hr>") "(no examples)") "</td>") " </tr>"))))) (insert "</table>\n")) (defun paredit-html-quote (string) (with-temp-buffer (dotimes (i (length string)) (insert (let ((c (elt string i))) (cond ((eq c ?\<) "&lt;") ((eq c ?\>) "&gt;") ((eq c ?\&) "&amp;") ((eq c ?\') "&apos;") ((eq c ?\") "&quot;") (t c))))) (buffer-string))) ;;;; Delimiter Insertion (eval-and-compile (defun paredit-conc-name (&rest strings) (intern (apply 'concat strings))) (defmacro define-paredit-pair (open close name) `(progn (defun ,(paredit-conc-name "paredit-open-" name) (&optional n) ,(concat "Insert a balanced " name " pair. With a prefix argument N, put the closing " name " after N S-expressions forward. If the region is active, `transient-mark-mode' is enabled, and the region's start and end fall in the same parenthesis depth, insert a " name " pair around the region. If in a string or a comment, insert a single " name ". If in a character literal, do nothing. This prevents changing what was in the character literal to a meaningful delimiter unintentionally.") (interactive "P") (cond ((or (paredit-in-string-p) (paredit-in-comment-p)) (insert ,open)) ((not (paredit-in-char-p)) (paredit-insert-pair n ,open ,close 'goto-char)))) (defun ,(paredit-conc-name "paredit-close-" name) () ,(concat "Move past one closing delimiter and reindent. \(Agnostic to the specific closing delimiter.) If in a string or comment, insert a single closing " name ". If in a character literal, do nothing. This prevents changing what was in the character literal to a meaningful delimiter unintentionally.") (interactive) (paredit-move-past-close ,close)) (defun ,(paredit-conc-name "paredit-close-" name "-and-newline") () ,(concat "Move past one closing delimiter, add a newline," " and reindent. If there was a margin comment after the closing delimiter, preserve it on the same line.") (interactive) (paredit-move-past-close-and-newline ,close))))) (define-paredit-pair ?\( ?\) "parenthesis") (define-paredit-pair ?\[ ?\] "bracket") (define-paredit-pair ?\{ ?\} "brace") (define-paredit-pair ?\< ?\> "brocket") (defun paredit-move-past-close (close) (cond ((or (paredit-in-string-p) (paredit-in-comment-p)) (insert close)) ((not (paredit-in-char-p)) (paredit-move-past-close-and-reindent) (paredit-blink-paren-match nil)))) (defun paredit-move-past-close-and-newline (close) (cond ((or (paredit-in-string-p) (paredit-in-comment-p)) (insert close)) (t (if (paredit-in-char-p) (forward-char)) (paredit-move-past-close-and-reindent) (let ((comment.point (paredit-find-comment-on-line))) (newline) (if comment.point (save-excursion (forward-line -1) (end-of-line) (indent-to (cdr comment.point)) (insert (car comment.point))))) (lisp-indent-line) (paredit-ignore-sexp-errors (indent-sexp)) (paredit-blink-paren-match t)))) (defun paredit-find-comment-on-line () "Find a margin comment on the current line. If such a comment exists, delete the comment (including all leading whitespace) and return a cons whose car is the comment as a string and whose cdr is the point of the comment's initial semicolon, relative to the start of the line." (save-excursion (catch 'return (while t (if (search-forward ";" (point-at-eol) t) (if (not (or (paredit-in-string-p) (paredit-in-char-p))) (let* ((start (progn (backward-char) ;before semicolon (point))) (comment (buffer-substring start (point-at-eol)))) (paredit-skip-whitespace nil (point-at-bol)) (delete-region (point) (point-at-eol)) (throw 'return (cons comment (- start (point-at-bol)))))) (throw 'return nil)))))) (defun paredit-insert-pair (n open close forward) (let* ((regionp (and (paredit-region-active-p) (paredit-region-safe-for-insert-p))) (end (and regionp (not n) (prog1 (region-end) (goto-char (region-beginning)))))) (let ((spacep (paredit-space-for-delimiter-p nil open))) (if spacep (insert " ")) (insert open) (save-excursion ;; Move past the desired region. (cond (n (funcall forward (save-excursion (forward-sexp (prefix-numeric-value n)) (point)))) (regionp (funcall forward (+ end (if spacep 2 1))))) (insert close) (if (paredit-space-for-delimiter-p t close) (insert " ")))))) (defun paredit-region-safe-for-insert-p () (save-excursion (let ((beginning (region-beginning)) (end (region-end))) (goto-char beginning) (let* ((beginning-state (paredit-current-parse-state)) (end-state (parse-partial-sexp beginning end nil nil beginning-state))) (and (= (nth 0 beginning-state) ; 0. depth in parens (nth 0 end-state)) (eq (nth 3 beginning-state) ; 3. non-nil if inside a (nth 3 end-state)) ; string (eq (nth 4 beginning-state) ; 4. comment status, yada (nth 4 end-state)) (eq (nth 5 beginning-state) ; 5. t if following char (nth 5 end-state))))))) ; quote (defun paredit-space-for-delimiter-p (endp delimiter) ;; If at the buffer limit, don't insert a space. If there is a word, ;; symbol, other quote, or non-matching parenthesis delimiter (i.e. a ;; close when want an open the string or an open when we want to ;; close the string), do insert a space. (and (not (if endp (eobp) (bobp))) (memq (char-syntax (if endp (char-after) (char-before))) (list ?w ?_ ?\" (let ((matching (matching-paren delimiter))) (and matching (char-syntax matching))))))) (defun paredit-move-past-close-and-reindent () (let ((orig (point))) (up-list) (if (catch 'return ; This CATCH returns T if it (while t ; should delete leading spaces (save-excursion ; and NIL if not. (let ((before-paren (1- (point)))) (back-to-indentation) (cond ((not (eq (point) before-paren)) ;; Can't call PAREDIT-DELETE-LEADING-WHITESPACE ;; here -- we must return from SAVE-EXCURSION ;; first. (throw 'return t)) ((save-excursion (forward-line -1) (end-of-line) (paredit-in-comment-p)) ;; Moving the closing parenthesis any further ;; would put it into a comment, so we just ;; indent the closing parenthesis where it is ;; and abort the loop, telling its continuation ;; that no leading whitespace should be deleted. (lisp-indent-line) (throw 'return nil)) (t (delete-indentation))))))) (paredit-delete-leading-whitespace)))) (defun paredit-delete-leading-whitespace () ;; This assumes that we're on the closing parenthesis already. (save-excursion (backward-char) (while (let ((syn (char-syntax (char-before)))) (and (or (eq syn ?\ ) (eq syn ?-)) ; whitespace syntax ;; The above line is a perfect example of why the ;; following test is necessary. (not (paredit-in-char-p (1- (point)))))) (backward-delete-char 1)))) (defun paredit-blink-paren-match (another-line-p) (if (and blink-matching-paren (or (not show-paren-mode) another-line-p)) (paredit-ignore-sexp-errors (save-excursion (backward-sexp) (forward-sexp) ;; SHOW-PAREN-MODE inhibits any blinking, so we disable it ;; locally here. (let ((show-paren-mode nil)) (blink-matching-open)))))) (defun paredit-doublequote (&optional n) "Insert a pair of double-quotes. With a prefix argument N, wrap the following N S-expressions in double-quotes, escaping intermediate characters if necessary. If the region is active, `transient-mark-mode' is enabled, and the region's start and end fall in the same parenthesis depth, insert a pair of double-quotes around the region, again escaping intermediate characters if necessary. Inside a comment, insert a literal double-quote. At the end of a string, move past the closing double-quote. In the middle of a string, insert a backslash-escaped double-quote. If in a character literal, do nothing. This prevents accidentally changing a what was in the character literal to become a meaningful delimiter unintentionally." (interactive "P") (cond ((paredit-in-string-p) (if (eq (cdr (paredit-string-start+end-points)) (point)) (forward-char) ; We're on the closing quote. (insert ?\\ ?\" ))) ((paredit-in-comment-p) (insert ?\" )) ((not (paredit-in-char-p)) (paredit-insert-pair n ?\" ?\" 'paredit-forward-for-quote)))) (defun paredit-meta-doublequote (&optional n) "Move to the end of the string, insert a newline, and indent. If not in a string, act as `paredit-doublequote'; if no prefix argument is specified and the region is not active or `transient-mark-mode' is disabled, the default is to wrap one S-expression, however, not zero." (interactive "P") (if (not (paredit-in-string-p)) (paredit-doublequote (or n (and (not (paredit-region-active-p)) 1))) (let ((start+end (paredit-string-start+end-points))) (goto-char (1+ (cdr start+end))) (newline) (lisp-indent-line) (paredit-ignore-sexp-errors (indent-sexp))))) (defun paredit-forward-for-quote (end) (let ((state (paredit-current-parse-state))) (while (< (point) end) (let ((new-state (parse-partial-sexp (point) (1+ (point)) nil nil state))) (if (paredit-in-string-p new-state) (if (not (paredit-in-string-escape-p)) (setq state new-state) ;; Escape character: turn it into an escaped escape ;; character by appending another backslash. (insert ?\\ ) ;; Now the point is after both escapes, and we want to ;; rescan from before the first one to after the second ;; one. (setq state (parse-partial-sexp (- (point) 2) (point) nil nil state)) ;; Advance the end point, since we just inserted a new ;; character. (setq end (1+ end))) ;; String: escape by inserting a backslash before the quote. (backward-char) (insert ?\\ ) ;; The point is now between the escape and the quote, and we ;; want to rescan from before the escape to after the quote. (setq state (parse-partial-sexp (1- (point)) (1+ (point)) nil nil state)) ;; Advance the end point for the same reason as above. (setq end (1+ end))))))) ;;;; Escape Insertion (defun paredit-backslash () "Insert a backslash followed by a character to escape." (interactive) (insert ?\\ ) ;; This funny conditional is necessary because PAREDIT-IN-COMMENT-P ;; assumes that PAREDIT-IN-STRING-P already returned false; otherwise ;; it may give erroneous answers. (if (or (paredit-in-string-p) (not (paredit-in-comment-p))) (let ((delp t)) (unwind-protect (setq delp (call-interactively 'paredit-escape)) ;; We need this in an UNWIND-PROTECT so that the backlash is ;; left in there *only* if PAREDIT-ESCAPE return NIL normally ;; -- in any other case, such as the user hitting C-g or an ;; error occurring, we must delete the backslash to avoid ;; leaving a dangling escape. (This control structure is a ;; crock.) (if delp (backward-delete-char 1)))))) ;;; This auxiliary interactive function returns true if the backslash ;;; should be deleted and false if not. (defun paredit-escape (char) ;; I'm too lazy to figure out how to do this without a separate ;; interactive function. (interactive "cEscaping character...") (if (eq char 127) ; The backslash was a typo, so t ; the luser wants to delete it. (insert char) ; (Is there a better way to nil)) ; express the rubout char? ; ?\^? works, but ugh...) ;;; The placement of this function in this file is totally random. (defun paredit-newline () "Insert a newline and indent it. This is like `newline-and-indent', but it not only indents the line that the point is on but also the S-expression following the point, if there is one. Move forward one character first if on an escaped character. If in a string, just insert a literal newline." (interactive) (if (paredit-in-string-p) (newline) (if (and (not (paredit-in-comment-p)) (paredit-in-char-p)) (forward-char)) (newline-and-indent) ;; Indent the following S-expression, but don't signal an error if ;; there's only a closing parenthesis after the point. (paredit-ignore-sexp-errors (indent-sexp)))) ;;;; Comment Insertion (defun paredit-semicolon (&optional n) "Insert a semicolon, moving any code after the point to a new line. If in a string, comment, or character literal, insert just a literal semicolon, and do not move anything to the next line. With a prefix argument N, insert N semicolons." (interactive "P") (if (not (or (paredit-in-string-p) (paredit-in-comment-p) (paredit-in-char-p) ;; No more code on the line after the point. (save-excursion (paredit-skip-whitespace t (point-at-eol)) (or (eolp) ;; Let the user prefix semicolons to existing ;; comments. (eq (char-after) ?\;))))) ;; Don't use NEWLINE-AND-INDENT, because that will delete all of ;; the horizontal whitespace first, but we just want to move the ;; code following the point onto the next line while preserving ;; the point on this line. ;++ Why indent only the line? (save-excursion (newline) (lisp-indent-line))) (insert (make-string (if n (prefix-numeric-value n) 1) ?\; ))) (defun paredit-comment-dwim (&optional arg) "Call the Lisp comment command you want (Do What I Mean). This is like `comment-dwim', but it is specialized for Lisp editing. If transient mark mode is enabled and the mark is active, comment or uncomment the selected region, depending on whether it was entirely commented not not already. If there is already a comment on the current line, with no prefix argument, indent to that comment; with a prefix argument, kill that comment. Otherwise, insert a comment appropriate for the context and ensure that any code following the comment is moved to the next line. At the top level, where indentation is calculated to be at column 0, insert a triple-semicolon comment; within code, where the indentation is calculated to be non-zero, and on the line there is either no code at all or code after the point, insert a double-semicolon comment; and if the point is after all code on the line, insert a single- semicolon margin comment at `comment-column'." (interactive "*P") (require 'newcomment) (comment-normalize-vars) (cond ((paredit-region-active-p) (comment-or-uncomment-region (region-beginning) (region-end) arg)) ((paredit-comment-on-line-p) (if arg (comment-kill (if (integerp arg) arg nil)) (comment-indent))) (t (paredit-insert-comment)))) (defun paredit-comment-on-line-p () (save-excursion (beginning-of-line) (let ((comment-p nil)) ;; Search forward for a comment beginning. If there is one, set ;; COMMENT-P to true; if not, it will be nil. (while (progn (setq comment-p (search-forward ";" (point-at-eol) ;; t -> no error t)) (and comment-p (or (paredit-in-string-p) (paredit-in-char-p (1- (point)))))) (forward-char)) comment-p))) (defun paredit-insert-comment () (let ((code-after-p (save-excursion (paredit-skip-whitespace t (point-at-eol)) (not (eolp)))) (code-before-p (save-excursion (paredit-skip-whitespace nil (point-at-bol)) (not (bolp))))) (if (and (bolp) ;; We have to use EQ 0 here and not ZEROP because ZEROP ;; signals an error if its argument is non-numeric, but ;; CALCULATE-LISP-INDENT may return nil. (eq (let ((indent (calculate-lisp-indent))) (if (consp indent) (car indent) indent)) 0)) ;; Top-level comment (progn (if code-after-p (save-excursion (newline))) (insert ";;; ")) (if code-after-p ;; Code comment (progn (if code-before-p ;++ Why NEWLINE-AND-INDENT here and not just ;++ NEWLINE, or PAREDIT-NEWLINE? (newline-and-indent)) (lisp-indent-line) (insert ";; ") ;; Move the following code. (NEWLINE-AND-INDENT will ;; delete whitespace after the comment, though, so use ;; NEWLINE & LISP-INDENT-LINE manually here.) (save-excursion (newline) (lisp-indent-line))) ;; Margin comment (progn (indent-to comment-column 1) ; 1 -> force one leading space (insert ?\; )))))) ;;;; Character Deletion (defun paredit-forward-delete (&optional arg) "Delete a character forward or move forward over a delimiter. If on an opening S-expression delimiter, move forward into the S-expression. If on a closing S-expression delimiter, refuse to delete unless the S-expression is empty, in which case delete the whole S-expression. With a prefix argument, simply delete a character forward, without regard for delimiter balancing." (interactive "P") (cond ((or arg (eobp)) (delete-char 1)) ((paredit-in-string-p) (paredit-forward-delete-in-string)) ((paredit-in-comment-p) ;++ What to do here? This could move a partial S-expression ;++ into a comment and thereby invalidate the file's form, ;++ or move random text out of a comment. (delete-char 1)) ((paredit-in-char-p) ; Escape -- delete both chars. (backward-delete-char 1) (delete-char 1)) ((eq (char-after) ?\\ ) ; ditto (delete-char 2)) ((let ((syn (char-syntax (char-after)))) (or (eq syn ?\( ) (eq syn ?\" ))) (forward-char)) ((and (not (paredit-in-char-p (1- (point)))) (eq (char-syntax (char-after)) ?\) ) (eq (char-before) (matching-paren (char-after)))) (backward-delete-char 1) ; Empty list -- delete both (delete-char 1)) ; delimiters. ;; Just delete a single character, if it's not a closing ;; parenthesis. (The character literal case is already ;; handled by now.) ((not (eq (char-syntax (char-after)) ?\) )) (delete-char 1)))) (defun paredit-forward-delete-in-string () (let ((start+end (paredit-string-start+end-points))) (cond ((not (eq (point) (cdr start+end))) ;; If it's not the close-quote, it's safe to delete. But ;; first handle the case that we're in a string escape. (cond ((paredit-in-string-escape-p) ;; We're right after the backslash, so backward ;; delete it before deleting the escaped character. (backward-delete-char 1)) ((eq (char-after) ?\\ ) ;; If we're not in a string escape, but we are on a ;; backslash, it must start the escape for the next ;; character, so delete the backslash before deleting ;; the next character. (delete-char 1))) (delete-char 1)) ((eq (1- (point)) (car start+end)) ;; If it is the close-quote, delete only if we're also right ;; past the open-quote (i.e. it's empty), and then delete ;; both quotes. Otherwise we refuse to delete it. (backward-delete-char 1) (delete-char 1))))) (defun paredit-backward-delete (&optional arg) "Delete a character backward or move backward over a delimiter. If on a closing S-expression delimiter, move backward into the S-expression. If on an opening S-expression delimiter, refuse to delete unless the S-expression is empty, in which case delete the whole S-expression. With a prefix argument, simply delete a character backward, without regard for delimiter balancing." (interactive "P") (cond ((or arg (bobp)) (backward-delete-char 1)) ;++ should this untabify? ((paredit-in-string-p) (paredit-backward-delete-in-string)) ((paredit-in-comment-p) (backward-delete-char 1)) ((paredit-in-char-p) ; Escape -- delete both chars. (backward-delete-char 1) (delete-char 1)) ((paredit-in-char-p (1- (point))) (backward-delete-char 2)) ; ditto ((let ((syn (char-syntax (char-before)))) (or (eq syn ?\) ) (eq syn ?\" ))) (backward-char)) ((and (eq (char-syntax (char-before)) ?\( ) (eq (char-after) (matching-paren (char-before)))) (backward-delete-char 1) ; Empty list -- delete both (delete-char 1)) ; delimiters. ;; Delete it, unless it's an opening parenthesis. The case ;; of character literals is already handled by now. ((not (eq (char-syntax (char-before)) ?\( )) (backward-delete-char-untabify 1)))) (defun paredit-backward-delete-in-string () (let ((start+end (paredit-string-start+end-points))) (cond ((not (eq (1- (point)) (car start+end))) ;; If it's not the open-quote, it's safe to delete. (if (paredit-in-string-escape-p) ;; If we're on a string escape, since we're about to ;; delete the backslash, we must first delete the ;; escaped char. (delete-char 1)) (backward-delete-char 1) (if (paredit-in-string-escape-p) ;; If, after deleting a character, we find ourselves in ;; a string escape, we must have deleted the escaped ;; character, and the backslash is behind the point, so ;; backward delete it. (backward-delete-char 1))) ((eq (point) (cdr start+end)) ;; If it is the open-quote, delete only if we're also right ;; past the close-quote (i.e. it's empty), and then delete ;; both quotes. Otherwise we refuse to delete it. (backward-delete-char 1) (delete-char 1))))) ;;;; Killing (defun paredit-kill (&optional arg) "Kill a line as if with `kill-line', but respecting delimiters. In a string, act exactly as `kill-line' but do not kill past the closing string delimiter. On a line with no S-expressions on it starting after the point or within a comment, act exactly as `kill-line'. Otherwise, kill all S-expressions that start after the point." (interactive "P") (cond (arg (kill-line)) ((paredit-in-string-p) (paredit-kill-line-in-string)) ((or (paredit-in-comment-p) (save-excursion (paredit-skip-whitespace t (point-at-eol)) (or (eq (char-after) ?\; ) (eolp)))) ;** Be careful about trailing backslashes. (kill-line)) (t (paredit-kill-sexps-on-line)))) (defun paredit-kill-line-in-string () (if (save-excursion (paredit-skip-whitespace t (point-at-eol)) (eolp)) (kill-line) (save-excursion ;; Be careful not to split an escape sequence. (if (paredit-in-string-escape-p) (backward-char)) (let ((beginning (point))) (while (not (or (eolp) (eq (char-after) ?\" ))) (forward-char) ;; Skip past escaped characters. (if (eq (char-before) ?\\ ) (forward-char))) (kill-region beginning (point)))))) (defun paredit-kill-sexps-on-line () (if (paredit-in-char-p) ; Move past the \ and prefix. (backward-char 2)) ; (# in Scheme/CL, ? in elisp) (let ((beginning (point)) (eol (point-at-eol))) (let ((end-of-list-p (paredit-forward-sexps-to-kill beginning eol))) ;; If we got to the end of the list and it's on the same line, ;; move backward past the closing delimiter before killing. (This ;; allows something like killing the whitespace in ( ).) (if end-of-list-p (progn (up-list) (backward-char))) (if kill-whole-line (paredit-kill-sexps-on-whole-line beginning) (kill-region beginning ;; If all of the S-expressions were on one line, ;; i.e. we're still on that line after moving past ;; the last one, kill the whole line, including ;; any comments; otherwise just kill to the end of ;; the last S-expression we found. Be sure, ;; though, not to kill any closing parentheses. (if (and (not end-of-list-p) (eq (point-at-eol) eol)) eol (point))))))) ;;; Please do not try to understand this code unless you have a VERY ;;; good reason to do so. I gave up trying to figure it out well ;;; enough to explain it, long ago. (defun paredit-forward-sexps-to-kill (beginning eol) (let ((end-of-list-p nil) (firstp t)) ;; Move to the end of the last S-expression that started on this ;; line, or to the closing delimiter if the last S-expression in ;; this list is on the line. (catch 'return (while t ;; This and the `kill-whole-line' business below fix a bug that ;; inhibited any S-expression at the very end of the buffer ;; (with no trailing newline) from being deleted. It's a ;; bizarre fix that I ought to document at some point, but I am ;; too busy at the moment to do so. (if (and kill-whole-line (eobp)) (throw 'return nil)) (save-excursion (paredit-handle-sexp-errors (forward-sexp) (up-list) (setq end-of-list-p (eq (point-at-eol) eol)) (throw 'return nil)) (if (or (and (not firstp) (not kill-whole-line) (eobp)) (paredit-handle-sexp-errors (progn (backward-sexp) nil) t) (not (eq (point-at-eol) eol))) (throw 'return nil))) (forward-sexp) (if (and firstp (not kill-whole-line) (eobp)) (throw 'return nil)) (setq firstp nil))) end-of-list-p)) (defun paredit-kill-sexps-on-whole-line (beginning) (kill-region beginning (or (save-excursion ; Delete trailing indentation... (paredit-skip-whitespace t) (and (not (eq (char-after) ?\; )) (point))) ;; ...or just use the point past the newline, if ;; we encounter a comment. (point-at-eol))) (cond ((save-excursion (paredit-skip-whitespace nil (point-at-bol)) (bolp)) ;; Nothing but indentation before the point, so indent it. (lisp-indent-line)) ((eobp) nil) ; Protect the CHAR-SYNTAX below against NIL. ;; Insert a space to avoid invalid joining if necessary. ((let ((syn-before (char-syntax (char-before))) (syn-after (char-syntax (char-after)))) (or (and (eq syn-before ?\) ) ; Separate opposing (eq syn-after ?\( )) ; parentheses, (and (eq syn-before ?\" ) ; string delimiter (eq syn-after ?\" )) ; pairs, (and (memq syn-before '(?_ ?w)) ; or word or symbol (memq syn-after '(?_ ?w))))) ; constituents. (insert " ")))) ;;;;; Killing Words ;;; This is tricky and asymmetrical because backward parsing is ;;; extraordinarily difficult or impossible, so we have to implement ;;; killing in both directions by parsing forward. (defun paredit-forward-kill-word () "Kill a word forward, skipping over intervening delimiters." (interactive) (let ((beginning (point))) (skip-syntax-forward " -") (let* ((parse-state (paredit-current-parse-state)) (state (paredit-kill-word-state parse-state 'char-after))) (while (not (or (eobp) (eq ?w (char-syntax (char-after))))) (setq parse-state (progn (forward-char 1) (paredit-current-parse-state)) ;; (parse-partial-sexp (point) (1+ (point)) ;; nil nil parse-state) ) (let* ((old-state state) (new-state (paredit-kill-word-state parse-state 'char-after))) (cond ((not (eq old-state new-state)) (setq parse-state (paredit-kill-word-hack old-state new-state parse-state)) (setq state (paredit-kill-word-state parse-state 'char-after)) (setq beginning (point))))))) (goto-char beginning) (kill-word 1))) (defun paredit-backward-kill-word () "Kill a word backward, skipping over any intervening delimiters." (interactive) (if (not (or (bobp) (eq (char-syntax (char-before)) ?w))) (let ((end (point))) (backward-word 1) (forward-word 1) (goto-char (min end (point))) (let* ((parse-state (paredit-current-parse-state)) (state (paredit-kill-word-state parse-state 'char-before))) (while (and (< (point) end) (progn (setq parse-state (parse-partial-sexp (point) (1+ (point)) nil nil parse-state)) (or (eq state (paredit-kill-word-state parse-state 'char-before)) (progn (backward-char 1) nil))))) (if (and (eq state 'comment) (eq ?\# (char-after (point))) (eq ?\| (char-before (point)))) (backward-char 1))))) (backward-kill-word 1)) ;;; Word-Killing Auxiliaries (defun paredit-kill-word-state (parse-state adjacent-char-fn) (cond ((paredit-in-comment-p parse-state) 'comment) ((paredit-in-string-p parse-state) 'string) ((memq (char-syntax (funcall adjacent-char-fn)) '(?\( ?\) )) 'delimiter) (t 'other))) ;;; This optionally advances the point past any comment delimiters that ;;; should probably not be touched, based on the last state change and ;;; the characters around the point. It returns a new parse state, ;;; starting from the PARSE-STATE parameter. (defun paredit-kill-word-hack (old-state new-state parse-state) (cond ((and (not (eq old-state 'comment)) (not (eq new-state 'comment)) (not (paredit-in-string-escape-p)) (eq ?\# (char-before)) (eq ?\| (char-after))) (forward-char 1) (paredit-current-parse-state) ;; (parse-partial-sexp (point) (1+ (point)) ;; nil nil parse-state) ) ((and (not (eq old-state 'comment)) (eq new-state 'comment) (eq ?\; (char-before))) (skip-chars-forward ";") (paredit-current-parse-state) ;; (parse-partial-sexp (point) (save-excursion ;; (skip-chars-forward ";")) ;; nil nil parse-state) ) (t parse-state))) ;;;; Cursor and Screen Movement (eval-and-compile (defmacro defun-saving-mark (name bvl doc &rest body) `(defun ,name ,bvl ,doc ,(xcond ((paredit-xemacs-p) '(interactive "_")) ((paredit-gnu-emacs-p) '(interactive))) ,@body))) (defun-saving-mark paredit-forward () "Move forward an S-expression, or up an S-expression forward. If there are no more S-expressions in this one before the closing delimiter, move past that closing delimiter; otherwise, move forward past the S-expression following the point." (paredit-handle-sexp-errors (forward-sexp) ;++ Is it necessary to use UP-LIST and not just FORWARD-CHAR? (if (paredit-in-string-p) (forward-char) (up-list)))) (defun-saving-mark paredit-backward () "Move backward an S-expression, or up an S-expression backward. If there are no more S-expressions in this one before the opening delimiter, move past that opening delimiter backward; otherwise, move move backward past the S-expression preceding the point." (paredit-handle-sexp-errors (backward-sexp) (if (paredit-in-string-p) (backward-char) (backward-up-list)))) ;;; Why is this not in lisp.el? (defun backward-down-list (&optional arg) "Move backward and descend into one level of parentheses. With ARG, do this that many times. A negative argument means move forward but still descend a level." (interactive "p") (down-list (- (or arg 1)))) ;;; Thanks to Marco Baringer for suggesting & writing this function. (defun paredit-recentre-on-sexp (&optional n) "Recentre the screen on the S-expression following the point. With a prefix argument N, encompass all N S-expressions forward." (interactive "P") (save-excursion (forward-sexp n) (let ((end-point (point))) (backward-sexp n) (let* ((start-point (point)) (start-line (count-lines (point-min) (point))) (lines-on-sexps (count-lines start-point end-point))) (goto-line (+ start-line (/ lines-on-sexps 2))) (recenter))))) ;;;; Depth-Changing Commands: Wrapping, Splicing, & Raising (defun paredit-wrap-sexp (&optional n) "Wrap the following S-expression in a list. If a prefix argument N is given, wrap N S-expressions. Automatically indent the newly wrapped S-expression. As a special case, if the point is at the end of a list, simply insert a pair of parentheses, rather than insert a lone opening parenthesis and then signal an error, in the interest of preserving structure." (interactive "P") (paredit-handle-sexp-errors (paredit-insert-pair (or n (and (not (paredit-region-active-p)) 1)) ?\( ?\) 'goto-char) (insert ?\) ) (backward-char)) (save-excursion (backward-up-list) (indent-sexp))) ;;; Thanks to Marco Baringer for the suggestion of a prefix argument ;;; for PAREDIT-SPLICE-SEXP. (I, Taylor R. Campbell, however, still ;;; implemented it, in case any of you lawyer-folk get confused by the ;;; remark in the top of the file about explicitly noting code written ;;; by other people.) (defun paredit-splice-sexp (&optional arg) "Splice the list that the point is on by removing its delimiters. With a prefix argument as in `C-u', kill all S-expressions backward in the current list before splicing all S-expressions forward into the enclosing list. With two prefix arguments as in `C-u C-u', kill all S-expressions forward in the current list before splicing all S-expressions backward into the enclosing list. With a numerical prefix argument N, kill N S-expressions backward in the current list before splicing the remaining S-expressions into the enclosing list. If N is negative, kill forward. This always creates a new entry on the kill ring." (interactive "P") (save-excursion (paredit-kill-surrounding-sexps-for-splice arg) (backward-up-list) ; Go up to the beginning... (save-excursion (forward-sexp) ; Go forward an expression, to (backward-delete-char 1)) ; delete the end delimiter. (delete-char 1) ; ...to delete the open char. (paredit-ignore-sexp-errors (backward-up-list) ; Reindent, now that the (indent-sexp)))) ; structure has changed. (defun paredit-kill-surrounding-sexps-for-splice (arg) (cond ((paredit-in-string-p) (error "Splicing illegal in strings.")) ((or (not arg) (eq arg 0)) nil) ((or (numberp arg) (eq arg '-)) ;; Kill ARG S-expressions before/after the point by saving ;; the point, moving across them, and killing the region. (let* ((arg (if (eq arg '-) -1 arg)) (saved (paredit-point-at-sexp-boundary (- arg)))) (paredit-ignore-sexp-errors (backward-sexp arg)) (kill-region-new saved (point)))) ((consp arg) (let ((v (car arg))) (if (= v 4) ; one prefix argument ;; Move backward until we hit the open paren; then ;; kill that selected region. (let ((end (paredit-point-at-sexp-start))) (paredit-ignore-sexp-errors (while (not (bobp)) (backward-sexp))) (kill-region-new (point) end)) ;; Move forward until we hit the close paren; then ;; kill that selected region. (let ((beginning (paredit-point-at-sexp-end))) (paredit-ignore-sexp-errors (while (not (eobp)) (forward-sexp))) (kill-region-new beginning (point)))))) (t (error "Bizarre prefix argument: %s" arg)))) (defun paredit-splice-sexp-killing-backward (&optional n) "Splice the list the point is on by removing its delimiters, and also kill all S-expressions before the point in the current list. With a prefix argument N, kill only the preceding N S-expressions." (interactive "P") (paredit-splice-sexp (if n (prefix-numeric-value n) '(4)))) (defun paredit-splice-sexp-killing-forward (&optional n) "Splice the list the point is on by removing its delimiters, and also kill all S-expressions after the point in the current list. With a prefix argument N, kill only the following N S-expressions." (interactive "P") (paredit-splice-sexp (if n (- (prefix-numeric-value n)) '(16)))) (defun paredit-raise-sexp (&optional n) "Raise the following S-expression in a tree, deleting its siblings. With a prefix argument N, raise the following N S-expressions. If N is negative, raise the preceding N S-expressions." (interactive "p") ;; Select the S-expressions we want to raise in a buffer substring. (let* ((bound (save-excursion (forward-sexp n) (point))) (sexps (save-excursion ;++ Is this necessary? (if (and n (< n 0)) (buffer-substring bound (paredit-point-at-sexp-end)) (buffer-substring (paredit-point-at-sexp-start) bound))))) ;; Move up to the list we're raising those S-expressions out of and ;; delete it. (backward-up-list) (delete-region (point) (save-excursion (forward-sexp) (point))) (save-excursion (insert sexps)) ; Insert & reindent the sexps. (save-excursion (let ((n (abs (or n 1)))) (while (> n 0) (paredit-forward-and-indent) (setq n (1- n))))))) ;;;; Slurpage & Barfage (defun paredit-forward-slurp-sexp () "Add the S-expression following the current list into that list by moving the closing delimiter. Automatically reindent the newly slurped S-expression with respect to its new enclosing form. If in a string, move the opening double-quote forward by one S-expression and escape any intervening characters as necessary, without altering any indentation or formatting." (interactive) (save-excursion (cond ((or (paredit-in-comment-p) (paredit-in-char-p)) (error "Invalid context for slurpage")) ((paredit-in-string-p) (paredit-forward-slurp-into-string)) (t (paredit-forward-slurp-into-list))))) (defun paredit-forward-slurp-into-list () (up-list) ; Up to the end of the list to (let ((close (char-before))) ; save and delete the closing (backward-delete-char 1) ; delimiter. (catch 'return ; Go to the end of the desired (while t ; S-expression, going up a (paredit-handle-sexp-errors ; list if it's not in this, (progn (paredit-forward-and-indent) (throw 'return nil)) (up-list)))) (insert close))) ; to insert that delimiter. (defun paredit-forward-slurp-into-string () (goto-char (1+ (cdr (paredit-string-start+end-points)))) ;; Signal any errors that we might get first, before mucking with the ;; buffer's contents. (save-excursion (forward-sexp)) (let ((close (char-before))) (backward-delete-char 1) (paredit-forward-for-quote (save-excursion (forward-sexp) (point))) (insert close))) (defun paredit-forward-barf-sexp () "Remove the last S-expression in the current list from that list by moving the closing delimiter. Automatically reindent the newly barfed S-expression with respect to its new enclosing form." (interactive) (save-excursion (up-list) ; Up to the end of the list to (let ((close (char-before))) ; save and delete the closing (backward-delete-char 1) ; delimiter. (paredit-ignore-sexp-errors ; Go back to where we want to (backward-sexp)) ; insert the delimiter. (paredit-skip-whitespace nil) ; Skip leading whitespace. (cond ((bobp) (error "Barfing all subexpressions with no open-paren?")) ((paredit-in-comment-p) ; Don't put the close-paren in (newline-and-indent))) ; a comment. (insert close)) ;; Reindent all of the newly barfed S-expressions. (paredit-forward-and-indent))) (defun paredit-backward-slurp-sexp () "Add the S-expression preceding the current list into that list by moving the closing delimiter. Automatically reindent the whole form into which new S-expression was slurped. If in a string, move the opening double-quote backward by one S-expression and escape any intervening characters as necessary, without altering any indentation or formatting." (interactive) (save-excursion (cond ((or (paredit-in-comment-p) (paredit-in-char-p)) (error "Invalid context for slurpage")) ((paredit-in-string-p) (paredit-backward-slurp-into-string)) (t (paredit-backward-slurp-into-list))))) (defun paredit-backward-slurp-into-list () (backward-up-list) (let ((open (char-after))) (delete-char 1) (catch 'return (while t (paredit-handle-sexp-errors (progn (backward-sexp) (throw 'return nil)) (backward-up-list)))) (insert open)) ;; Reindent the line at the beginning of wherever we inserted the ;; opening parenthesis, and then indent the whole S-expression. (backward-up-list) (lisp-indent-line) (indent-sexp)) (defun paredit-backward-slurp-into-string () (goto-char (car (paredit-string-start+end-points))) ;; Signal any errors that we might get first, before mucking with the ;; buffer's contents. (save-excursion (backward-sexp)) (let ((open (char-after)) (target (point))) (message "open = %S" open) (delete-char 1) (backward-sexp) (insert open) (paredit-forward-for-quote target))) (defun paredit-backward-barf-sexp () "Remove the first S-expression in the current list from that list by moving the closing delimiter. Automatically reindent the barfed S-expression and the form from which it was barfed." (interactive) (save-excursion (backward-up-list) (let ((open (char-after))) (delete-char 1) (paredit-ignore-sexp-errors (paredit-forward-and-indent)) (while (progn (paredit-skip-whitespace t) (eq (char-after) ?\; )) (forward-line 1)) (if (eobp) (error "Barfing all subexpressions with no close-paren?")) ;** Don't use `insert' here. Consider, e.g., barfing from ;** (foo|) ;** and how `save-excursion' works. (insert-before-markers open)) (backward-up-list) (lisp-indent-line) (indent-sexp))) ;;;; Splitting & Joining (defun paredit-split-sexp () "Split the list or string the point is on into two." (interactive) (cond ((paredit-in-string-p) (insert "\"") (save-excursion (insert " \""))) ((or (paredit-in-comment-p) (paredit-in-char-p)) (error "Invalid context for `paredit-split-sexp'")) (t (let ((open (save-excursion (backward-up-list) (char-after))) (close (save-excursion (up-list) (char-before)))) (delete-horizontal-space) (insert close) (save-excursion (insert ?\ ) (insert open) (backward-char) (indent-sexp)))))) (defun paredit-join-sexps () "Join the S-expressions adjacent on either side of the point. Both must be lists, strings, or atoms; error if there is a mismatch." (interactive) ;++ How ought this to handle comments intervening symbols or strings? (save-excursion (if (or (paredit-in-comment-p) (paredit-in-string-p) (paredit-in-char-p)) (error "Invalid context in which to join S-expressions.") (let ((left-point (save-excursion (paredit-point-at-sexp-end))) (right-point (save-excursion (paredit-point-at-sexp-start)))) (let ((left-char (char-before left-point)) (right-char (char-after right-point))) (let ((left-syntax (char-syntax left-char)) (right-syntax (char-syntax right-char))) (cond ((>= left-point right-point) (error "Can't join a datum with itself.")) ((and (eq left-syntax ?\) ) (eq right-syntax ?\( ) (eq left-char (matching-paren right-char)) (eq right-char (matching-paren left-char))) ;; Leave intermediate formatting alone. (goto-char right-point) (delete-char 1) (goto-char left-point) (backward-delete-char 1) (backward-up-list) (indent-sexp)) ((and (eq left-syntax ?\" ) (eq right-syntax ?\" )) ;; Delete any intermediate formatting. (delete-region (1- left-point) (1+ right-point))) ((and (memq left-syntax '(?w ?_)) ; Word or symbol (memq right-syntax '(?w ?_))) (delete-region left-point right-point)) (t (error "Mismatched S-expressions to join."))))))))) ;;;; Utilities (defun paredit-in-string-escape-p () "True if the point is on a character escape of a string. This is true only if the character is preceded by an odd number of backslashes. This assumes that `paredit-in-string-p' has already returned true." (let ((oddp nil)) (save-excursion (while (eq (char-before) ?\\ ) (setq oddp (not oddp)) (backward-char))) oddp)) (defun paredit-in-char-p (&optional arg) "True if the point is immediately after a character literal. A preceding escape character, not preceded by another escape character, is considered a character literal prefix. (This works for elisp, Common Lisp, and Scheme.) Assumes that `paredit-in-string-p' is false, so that it need not handle long sequences of preceding backslashes in string escapes. (This assumes some other leading character token -- ? in elisp, # in Scheme and Common Lisp.)" (let ((arg (or arg (point)))) (and (eq (char-before arg) ?\\ ) (not (eq (char-before (1- arg)) ?\\ ))))) (defun paredit-forward-and-indent () "Move forward an S-expression, indenting it fully. Indent with `lisp-indent-line' and then `indent-sexp'." (forward-sexp) ; Go forward, and then find the (save-excursion ; beginning of this next (backward-sexp) ; S-expression. (lisp-indent-line) ; Indent its opening line, and (indent-sexp))) ; the rest of it. (defun paredit-skip-whitespace (trailing-p &optional limit) "Skip past any whitespace, or until the point LIMIT is reached. If TRAILING-P is nil, skip leading whitespace; otherwise, skip trailing whitespace." (funcall (if trailing-p 'skip-chars-forward 'skip-chars-backward) " \t\n " ; This should skip using the syntax table, but LF limit)) ; is a comment end, not newline, in Lisp mode. (defalias 'paredit-region-active-p (xcond ((paredit-xemacs-p) 'region-active-p) ((paredit-gnu-emacs-p) (lambda () (and mark-active transient-mark-mode))))) (defun kill-region-new (start end) "Kill the region between START and END. Do not append to any current kill, and do not let the next kill append to this one." (interactive "r") ;Eh, why not? ;; KILL-REGION sets THIS-COMMAND to tell the next kill that the last ;; command was a kill. It also checks LAST-COMMAND to see whether it ;; should append. If we bind these locally, any modifications to ;; THIS-COMMAND will be masked, and it will not see LAST-COMMAND to ;; indicate that it should append. (let ((this-command nil) (last-command nil)) (kill-region start end))) ;;;;; S-expression Parsing Utilities ;++ These routines redundantly traverse S-expressions a great deal. ;++ If performance issues arise, this whole section will probably have ;++ to be refactored to preserve the state longer, like paredit.scm ;++ does, rather than to traverse the definition N times for every key ;++ stroke as it presently does. (defun paredit-current-parse-state () "Return parse state of point from beginning of defun." (let ((point (point))) (beginning-of-defun) ;; Calling PARSE-PARTIAL-SEXP will advance the point to its second ;; argument (unless parsing stops due to an error, but we assume it ;; won't in paredit-mode). (parse-partial-sexp (point) point))) (defun paredit-in-string-p (&optional state) "True if the parse state is within a double-quote-delimited string. If no parse state is supplied, compute one from the beginning of the defun to the point." ;; 3. non-nil if inside a string (the terminator character, really) (and (nth 3 (or state (paredit-current-parse-state))) t)) (defun paredit-string-start+end-points (&optional state) "Return a cons of the points of open and close quotes of the string. The string is determined from the parse state STATE, or the parse state from the beginning of the defun to the point. This assumes that `paredit-in-string-p' has already returned true, i.e. that the point is already within a string." (save-excursion ;; 8. character address of start of comment or string; nil if not ;; in one (let ((start (nth 8 (or state (paredit-current-parse-state))))) (goto-char start) (forward-sexp 1) (cons start (1- (point)))))) (defun paredit-in-comment-p (&optional state) "True if parse state STATE is within a comment. If no parse state is supplied, compute one from the beginning of the defun to the point." ;; 4. nil if outside a comment, t if inside a non-nestable comment, ;; else an integer (the current comment nesting) (and (nth 4 (or state (paredit-current-parse-state))) t)) (defun paredit-point-at-sexp-boundary (n) (cond ((< n 0) (paredit-point-at-sexp-start)) ((= n 0) (point)) ((> n 0) (paredit-point-at-sexp-end)))) (defun paredit-point-at-sexp-start () (forward-sexp) (backward-sexp) (point)) (defun paredit-point-at-sexp-end () (backward-sexp) (forward-sexp) (point)) ;;;; Initialization (paredit-define-keys) (paredit-annotate-mode-with-examples) (paredit-annotate-functions-with-examples) (provide 'paredit)
76,655
Common Lisp
.l
1,670
35.639521
74
0.562263
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
5f3ce83effdd369c997e59729f3ce0061369a80391604c51c4a90d4b2aaec5df
8,428
[ -1 ]
8,478
wsdl20.xsd
evrim_core-server/src/markup/wsdl20.xsd
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd"> <!-- W3C XML Schema defined in the Web Services Description (WSDL) Version 2.0 specification http://www.w3.org/TR/wsdl20 Copyright © 2007 World Wide Web Consortium, (Massachusetts Institute of Technology, European Research Consortium for Informatics and Mathematics, Keio University). All Rights Reserved. This work is distributed under the W3C® Software License [1] 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. [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 $Id: wsdl20.xsd,v 1.4 2008/03/31 19:12:51 plehegar Exp $ --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://www.w3.org/ns/wsdl" targetNamespace="http://www.w3.org/ns/wsdl" elementFormDefault="qualified" finalDefault="" blockDefault="" attributeFormDefault="unqualified"> <xs:element name="documentation" type="wsdl:DocumentationType"/> <xs:complexType name="DocumentationType" mixed="true"> <xs:sequence> <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" namespace="##any"/> </xs:sequence> <xs:anyAttribute namespace="##other" processContents="lax"/> </xs:complexType> <xs:complexType name="DocumentedType" mixed="false"> <xs:annotation> <xs:documentation> This type is extended by component types to allow them to be documented. </xs:documentation> </xs:annotation> <xs:sequence> <xs:element ref="wsdl:documentation" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="ExtensibleDocumentedType" abstract="true" mixed="false"> <xs:annotation> <xs:documentation> This type is extended by component types to allow attributes from other namespaces to be added. </xs:documentation> </xs:annotation> <xs:complexContent> <xs:extension base="wsdl:DocumentedType"> <xs:anyAttribute namespace="##other" processContents="lax"/> </xs:extension> </xs:complexContent> </xs:complexType> <!-- description element decl and type def --> <xs:element name="description" type="wsdl:DescriptionType"> <xs:unique name="interface"> <xs:selector xpath="wsdl:interface"/> <xs:field xpath="@name"/> </xs:unique> <xs:unique name="binding"> <xs:selector xpath="wsdl:binding"/> <xs:field xpath="@name"/> </xs:unique> <xs:unique name="service"> <xs:selector xpath="wsdl:service"/> <xs:field xpath="@name"/> </xs:unique> </xs:element> <xs:complexType name="DescriptionType" mixed="false"> <xs:annotation> <xs:documentation> Although correct, this type declaration does not capture all the constraints on the contents of the wsdl:description element as defined by the WSDL 2.0 specification. In particular, the ordering constraints wrt elements preceding and following the wsdl:types child element are not captured, as attempts to incorporate such restrictions in the schema ran afoul of the UPA (Unique Particle Attribution) rule in the XML Schema language. Please refer to the WSDL 2.0 specification for additional information on the contents of this type. </xs:documentation> </xs:annotation> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="wsdl:import"/> <xs:element ref="wsdl:include"/> <xs:element ref="wsdl:types"/> <xs:element ref="wsdl:interface"/> <xs:element ref="wsdl:binding"/> <xs:element ref="wsdl:service"/> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="targetNamespace" type="xs:anyURI" use="required"/> </xs:extension> </xs:complexContent> </xs:complexType> <!-- types for import and include elements --> <xs:element name="import" type="wsdl:ImportType"/> <xs:complexType name="ImportType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:sequence> <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="strict"/> </xs:sequence> <xs:attribute name="namespace" type="xs:anyURI" use="required"/> <xs:attribute name="location" type="xs:anyURI" use="optional"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:element name="include" type="wsdl:IncludeType"/> <xs:complexType name="IncludeType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:sequence> <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="strict"/> </xs:sequence> <xs:attribute name="location" type="xs:anyURI" use="required"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:element name="types" type="wsdl:TypesType"/> <xs:complexType name="TypesType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:sequence> <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="strict"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <!-- parts related to wsdl:interface --> <xs:element name="interface" type="wsdl:InterfaceType"> <xs:unique name="operation"> <xs:selector xpath="wsdl:operation"/> <xs:field xpath="@name"/> </xs:unique> <xs:unique name="fault"> <xs:selector xpath="wsdl:fault"/> <xs:field xpath="@name"/> </xs:unique> </xs:element> <xs:complexType name="InterfaceType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="operation" type="wsdl:InterfaceOperationType"/> <xs:element name="fault" type="wsdl:InterfaceFaultType"/> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="name" type="xs:NCName" use="required"/> <xs:attribute name="extends" use="optional"> <xs:simpleType> <xs:list itemType="xs:QName"/> </xs:simpleType> </xs:attribute> <xs:attribute name="styleDefault" use="optional"> <xs:simpleType> <xs:list itemType="xs:anyURI"/> </xs:simpleType> </xs:attribute> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="InterfaceOperationType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="input" type="wsdl:MessageRefType"/> <xs:element name="output" type="wsdl:MessageRefType"/> <xs:element name="infault" type="wsdl:MessageRefFaultType"/> <xs:element name="outfault" type="wsdl:MessageRefFaultType"/> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="name" type="xs:NCName" use="required"/> <xs:attribute name="pattern" type="xs:anyURI" use="optional"/> <xs:attribute name="safe" type="xs:boolean" use="optional"/> <xs:attribute name="style" type="xs:anyURI" use="optional"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="MessageRefType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="messageLabel" type="xs:NCName" use="optional"/> <xs:attribute name="element" type="wsdl:ElementReferenceType" use="optional"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:simpleType name="ElementReferenceType"> <xs:annotation> <xs:documentation> Use the QName of a GED that describes the content, #any for any content, #none for empty content, or #other for content described by some other extension attribute that references a declaration in a non-XML extension type system. </xs:documentation> </xs:annotation> <xs:union memberTypes="xs:QName"> <xs:simpleType> <xs:restriction base="xs:token"> <xs:enumeration value="#any"/> <xs:enumeration value="#none"/> <xs:enumeration value="#other"/> </xs:restriction> </xs:simpleType> </xs:union> </xs:simpleType> <xs:complexType name="MessageRefFaultType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="ref" type="xs:QName" use="required"/> <xs:attribute name="messageLabel" type="xs:NCName" use="optional"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="InterfaceFaultType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="name" type="xs:NCName" use="required"/> <xs:attribute name="element" type="wsdl:ElementReferenceType" use="optional"/> </xs:extension> </xs:complexContent> </xs:complexType> <!-- types related to wsdl:binding --> <xs:element name="binding" type="wsdl:BindingType"/> <xs:complexType name="BindingType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="operation" type="wsdl:BindingOperationType"/> <xs:element name="fault" type="wsdl:BindingFaultType"/> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="name" type="xs:NCName" use="required"/> <xs:attribute name="type" type="xs:anyURI" use="required"/> <xs:attribute name="interface" type="xs:QName" use="optional"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="BindingOperationType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="input" type="wsdl:BindingOperationMessageType"/> <xs:element name="output" type="wsdl:BindingOperationMessageType"/> <xs:element name="infault" type="wsdl:BindingOperationFaultType"/> <xs:element name="outfault" type="wsdl:BindingOperationFaultType"/> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="ref" type="xs:QName" use="required"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="BindingOperationMessageType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="messageLabel" type="xs:NCName" use="optional"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="BindingOperationFaultType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="ref" type="xs:QName" use="required"/> <xs:attribute name="messageLabel" type="xs:NCName" use="optional"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="BindingFaultType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="ref" type="xs:QName" use="required"/> </xs:extension> </xs:complexContent> </xs:complexType> <!-- types related to service --> <xs:element name="service" type="wsdl:ServiceType"> <xs:unique name="endpoint"> <xs:selector xpath="wsdl:endpoint"/> <xs:field xpath="@name"/> </xs:unique> </xs:element> <xs:complexType name="ServiceType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="1" maxOccurs="unbounded"> <xs:element ref="wsdl:endpoint"/> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="name" type="xs:NCName" use="required"/> <xs:attribute name="interface" type="xs:QName" use="required"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:element name="endpoint" type="wsdl:EndpointType"/> <xs:complexType name="EndpointType" mixed="false"> <xs:complexContent> <xs:extension base="wsdl:ExtensibleDocumentedType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:any namespace="##other" processContents="lax" minOccurs="1" maxOccurs="1"/> </xs:choice> <xs:attribute name="name" type="xs:NCName" use="required"/> <xs:attribute name="binding" type="xs:QName" use="required"/> <xs:attribute name="address" type="xs:anyURI" use="optional"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:attribute name="required" type="xs:boolean"/> <xs:complexType name="ExtensionElement" abstract="true" mixed="false"> <xs:annotation> <xs:documentation> This abstract type is intended to serve as the base type for extension elements. It includes the wsdl:required attribute which it is anticipated will be used by most extension elements </xs:documentation> </xs:annotation> <xs:attribute ref="wsdl:required" use="optional"/> </xs:complexType> </xs:schema>
14,943
Common Lisp
.l
332
38.638554
236
0.675859
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
684a6b6198396bafb089353c6a782c597fcf95473e31ac1b4f74944c0105815b
8,478
[ -1 ]
8,535
oauth.html
evrim_core-server/src/manager/wwwroot/oauth.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Core Server - http://labs.core.gen.tr/</title> <link rel="stylesheet" href="/style/reset.css"/> <link rel="stylesheet" href="/style/common.css"/> <link rel="stylesheet" href="/style/core.css"/> <link rel="stylesheet" href="/style/auth.css"/> <link rel="stylesheet" href="/style/auth-controller.css"/> <script src="library.core" type="text/javascript"></script> <script src="auth.core" type="text/javascript"></script> </head> <body> <div class="header max-width center text-left"> <div class="pad5 left"><img src="style/images/logo-black.png"/></div> <div id="top-right" class="right font-12"></div> </div> <div id="middle" class="max-width center text-center clear"> </div> <div class="center max-width clear"> <div id="bottom" class="left"></div> <div class="core right"> <input value="Close" type="button" onclick="window.close()" class="close"> </div> </div> </body> </html>
1,178
Common Lisp
.l
29
35.896552
75
0.641427
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
fb8ceeb16d0387e4d9bf7a6744bc5b14fb5bb9f5d550a23fc4c11be594852c02
8,535
[ -1 ]
8,536
manager.html
evrim_core-server/src/manager/wwwroot/manager.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <html> <head> <title>Core Server - http://labs.core.gen.tr/</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="style/reset.css"> <link rel="stylesheet" href="style/common.css"> <link rel="stylesheet" href="style/style.css"> <script type="text/javascript" src="library.core"></script> <script type="text/javascript" src="manager.core"></script> </head> <body class="text-center"> <div class="container"> <div class="center max-width text-left pad10 header"> <div class="left"> <h1>[Core-serveR]</h1> <h2>A Common Lisp Application Server</h2> </div> <div class="right text-right" style="padding-top:10px;margin-bottom:-10px;"> <div id="clock"></div></div> <div class="clear"></div> </div> <div class="text-left center max-width menu" id="menu"></div> <div class="text-left center max-width title" id="title"> <h1>Info</h1> <h2>Information regarding to the current server</h2> </div> <div class="center max-width text-left pad10"> <div id="content" class="content"> <!-- <div id="left-column" class="left"> --> <!-- <div id="left1"></div> --> <!-- <div id="left2"></div> --> <!-- <div id="left3"></div> --> <!-- </div> --> <!-- <div id="right-column" class="right"> --> <!-- <div id="right1"></div> --> <!-- <div id="right2"></div> --> <!-- <div id="right3"></div> --> <!-- </div> --> <div id="left1"></div> <div id="left2"></div> <!-- <div class="left" id="left3"></div> --> <div id="right1"></div> <div id="right2"></div> <div id="right3"></div> <!-- <div class="left width-50p" id="left1"></div> --> <!-- <div class="left width-50p" id="left2"></div> --> <!-- <\!-- <div class="left" id="left3"></div> -\-> --> <!-- <div class="left width-100p" id="right1"></div> --> <!-- <div class="left width-100p" id="right2"></div> --> <!-- <div class="left" id="right3"></div> --> </div> </div> <div class="clear"></div> </div> <div class="max-width center text-right footer"> <div class="left">&copy; 2006-2012, Kor Information Technologies Ltd.</div> <div class="right"><a href="http://www.core.gen.tr/">http://www.core.gen.tr</a> </div> </div> </body> </html>
2,455
Common Lisp
.l
65
33.246154
85
0.574432
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
8fe855628890d50ef2ff6b76da4280a004870b95ac3b0b23bd05d206c869db70
8,536
[ -1 ]
8,537
index.html
evrim_core-server/src/manager/wwwroot/index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <html> <head> <title>Core Server - http://labs.core.gen.tr/</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="style/reset.css"> <link rel="stylesheet" href="style/common.css"> <link rel="stylesheet" href="style/core.css"> <link rel="stylesheet" href="style/style.css"> <script type="text/javascript" src="library.core"></script> <script type="text/javascript" src="index.core"></script> <style type="text/css"> body {background-color:#eee;} .container { padding-top:65px; padding-bottom:35px; background:url(../images/index-bg.jpg); color:#fff; } .index-wrapper { color:#fff; padding-top:20px; } .index-wrapper h3 { font-size:18px; margin-bottom:20px; } .core-clock-widget { margin-top:15px; text-align:right; color:#000; } .footer {background:transparent;} .field .value span.validation { display:block; padding:5px 0; } .field .value span.invalid { color:#ce0000; } .field .value span.valid { color:#fff; } </style> </head> <body class="text-center"> <div class="container"> <div class="center max-width text-left header"> <div class="left"> <h1>[Core-serveR]</h1> <h2>A Common-Lisp Application Server</h2> </div> <div class="right"> <div id="clock"></div> </div> <div class="clear"></div> </div> <div class="pad10"></div> <div class="index-wrapper"> <div class="center max-width text-left"> <div id="login" class="text-left right"></div> <div class="left"> <h3>Welcome!</h3> <p>Server documentation is located at: </p> <p> <a target="_blank" href="http://labs.core.gen.tr/"> http://labs.core.gen.tr/ </a> </p> <br> <p>Follow us on Twitter!</p> <p> <a target="_blank" href="http://twitter.com/core_server"> http://twitter.com/core_server </a> </p> </div> </div> <div class="clear"></div> </div> </div> <div class="max-width center text-center footer clear"> <div class="left">&copy; 2006-2012, Kor Information Technologies Ltd.</div> <div class="right"> <a href="http://www.core.gen.tr/">http://www.core.gen.tr</a> </div> </div> </body> </html>
2,415
Common Lisp
.l
75
27.08
75
0.613675
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
e3ce747da4046795d4f1f45ef9896fbfb8e95aaeb83a0f8124dad90fbc23c924
8,537
[ -1 ]
8,538
console.css
evrim_core-server/src/manager/wwwroot/style/console.css
.core-console { position:fixed; bottom:0; left:0; width:100%; color:#000000; margin:0; background-color:#AAAAAA; border-bottom:2px solid #000000; } .core-console * { font-family: Arial,Helvetica,FreeSans,"Luxi-sans","Nimbus Sans L",sans-serif; } .core-console .title > div { color:#ffffff; padding:10px; font-size:1.0em; margin-left:10px; background:url(images/stripe.png); border-left:2px solid #333333; } .core-console .title > div > div { color:#ffffff; } .core-console .title { background-color:#222222; } .core-console a, .core-console a:visited, .core-console a:link, .core-console a:hover { color:#ffffff; cursor:hand; } .core-console .close { margin-right:10px; } .core-console a.close-button { display:block; cursor:pointer; } .core-console .body { background-color:#FFFFFF; margin-left:10px; border-left:2px solid #777777; } /* .feedback-console .field .label { */ /* float:left; */ /* padding:5px; */ /* width:100px; */ /* } */ /* .feedback-console .feedback-title { */ /* padding:10px; */ /* padding-left:5px; */ /* font-size:15px; */ /* margin-bottom:5px; */ /* } */
1,162
Common Lisp
.l
47
22.276596
88
0.665171
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
730a0081b280a2d22faecd343fcfb85b10ec59c1e7083a767a892cb0ba365466
8,538
[ -1 ]
8,539
table.css
evrim_core-server/src/manager/wwwroot/style/table.css
table.core-table { width:100%; border:0; background-color:#FFFFFF; border-spacing:2px; } table.core-table tr { margin:2px; } table.core-table tr.hover td { background:#646D7E !important; color:#fff; } table.core-table td, table.core-table th { border:0; } table.core-table th { padding:8px 5px; font-size:13px; background-color:#222222; color:#ffffff; text-align:center; } table.core-table th a { font-size:13px; font-weight:bold; color:#ffffff; text-decoration:none; } table.core-table th a:hover { text-decoration:underline; } table.core-table td { padding:5px; background-color:#EEEEEE; text-align:center; font-size:12px; border-top:1px solid #AAA; border-left:1px solid #AAA; border-bottom:1px solid #999; border-right:1px solid #999; } table.core-table tr.hilighted td { background-color:#CCCCCC; } table.core-table tr.selected td { background-color:#646D7E; color:#ffffff; } table.core-table tfoot tr td { background-color:#CCCCCC; color:#000000; padding:4px; text-align:right; } table.core-table th.first-column {width:20px;} table.core-table td.first-column {width:20px;} table.core-table th.name {width:130px;} table.core-table td.name { /* width:130px; */ /* font-size:1.1em; */ /* font-weight:bold; */ } div.core-table-overflow { max-height:260px; overflow:auto; overflow-x:hidden; }
1,388
Common Lisp
.l
68
18.220588
46
0.723485
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
d27e6913e81f3917f4e0b53bd66f2b51bb67511785f04650d4e3a6d33d3c5d87
8,539
[ -1 ]
8,540
style.css
evrim_core-server/src/manager/wwwroot/style/style.css
.max-width { width: 750px; } h1 { margin:20px 0; margin-bottom:10px; } p { margin:10px 0; } body { line-height:1.2em; } a, a:link, a:visited, a:hover { color:#646D7E; /* color:#7ADD33; */ font-weight:bold; } form { width:100%; } /* input[type=text], select, input[type=password], textarea { */ /* background-image:url(images/input-bg.png); */ /* font-size:15px; */ /* padding:5px; */ /* border:1px solid #cc0000; */ /* color:#000000; */ /* } */ /* .content input[type=submit] { */ /* padding:5px; */ /* text-align:center; */ /* margin:5px; */ /* } */ /* textarea {min-height:80px;} */ /* select {min-height:30px; width:150px;} */ /* input[type=text], input[type=password] { */ /* width:150px; */ /* min-height:16px; */ /* margin:2px; */ /* } */ /* input[type=submit], input[type=button], input[type=reset] { */ /* padding:5px; */ /* padding-right:10px; */ /* padding-left:10px; */ /* margin:0px 5px 0px 2px; */ /* font-size:14px; */ /* background: #EEEEEE; */ /* border-top:1px solid #EEEEEE; */ /* border-bottom:1px solid #000000; */ /* border-left:1px solid #EEEEEE; */ /* border-right:1px solid #000000; */ /* text-align:center; */ /* } */ /* .label {font-size:14px;} */ /* .field { margin-bottom:7px; } */ /* input.valid, textarea.valid { */ /* border:2px solid #000088 !important; */ /* } */ /* input.invalid, textarea.invalid { */ /* border:2px solid #cc0000 !important; */ /* } */ /* form input.text { */ /* background-image:url(images/input-bg.png); */ /* font-size:15px; */ /* width:220px; */ /* padding:5px; */ /* border:1px solid #cc0000; */ /* } */ /* form span.validation { */ /* font-size:13px; */ /* display:block; */ /* padding:2px 0px; */ /* /\* color:#770000; *\/ */ /* color:#DEDEDE; */ /* } */ .container { background:url(images/bg-gray.jpg); background-repeat:repeat-x; } .header h1 { color:#353535; } .header h2 { color:#777; font-size:11px; } .title { height:60px;} .title h1 { color:#fff; font-size:18px; margin-bottom:5px;} .title h2 { color:#bbb; font-size:11px; } .menu { height : 34px; padding-top:2px;} .menu li { list-style : none; display : inline; line-height : 34px; } .menu li a { text-decoration : none; margin : 0; padding : 9px 15px 10px 15px; font-weight : bold; color : #616161; } .menu li a:hover { color : #fff; /* background : #a7cc44; */ background: #646D7E; margin : 0; } .menu li a.hilight { /* background : #616161 url(images/trcorner.gif) no-repeat top right; */ /*background-color: #616161;*/ /* background:#2e384b url(images/trcorner-blue.gif) no-repeat top right; */ background:#404d65 url(images/trcorner-blue.gif) no-repeat top right; color : #fff; } .footer { background: white url(images/rlline.gif) no-repeat top right; padding:10px; color:#777; line-height:1.4em; } /* .content h2 { padding:10px; } */
3,005
Common Lisp
.l
106
26.311321
79
0.597232
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
3b8b8a455deed66c599b3a005a619cad0c74220011f37e5f47f231956a26821c
8,540
[ -1 ]
8,541
auth-controller.css
evrim_core-server/src/manager/wwwroot/style/auth-controller.css
body { background:url(images/auth-bg.png) repeat-x; } .max-width { width:550px; } .header {height:80px;} .header .right { font-size:1.1em; padding:10px; } .sign-in { padding:10px 0; margin:0; font-size:1.2em; } #top-right a { background:#eee; padding:5px 10px; color:#222; border-radius:2px; border:1px solid #c00; margin-left:10px; text-decoration:none; } #top-right a:hover { text-decoration:underline; background:#fff; } #top-right p { margin:15px; } input.close {margin-top:25px !important;} #middle {height:207px; overflow:hidden; } .auth-buttons { padding-top:65px; }
605
Common Lisp
.l
21
26.333333
66
0.699145
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
b7f44c05c1d1a52ffb5cdf75613cdb224a5c0619eda6b5466fbd050d956efb6f
8,541
[ -1 ]
8,542
dialog.css
evrim_core-server/src/manager/wwwroot/style/dialog/dialog.css
.core-dialog-overlay { background-image:url(stripe.png); position:absolute; display:block; top:0; left:0; z-index:102; width:100%; height:2000px; opacity:0.9; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="stripe.png", sizingMethod="scale"); } .core-dialog { margin:auto; position:absolute; top:100px; width:100%; display:block; z-index:103; left:0; padding-left:5px; height:240px; } .core-dialog > div {width:530px;} .core-dialog .left {float:left;} .core-dialog .left-bg { background-image:url(coretal-logo-transparent.png); background-repeat:no-repeat; background-position:center; width:260px; height:220px; } .core-dialog .left img { margin:auto; display:block; text-align:center; border:0; } .core-dialog .left a { display:block; margin:auto; width:100%; height:100%; } .core-dialog .right {float:right;} .core-dialog .right-bg { background-repeat:no-repeat; background-image:url(login-box.gif); background-position:top center; width:250px; height:210px; margin:5px; margin-top:20px; padding:0; padding-left:10px; } .core-dialog .title { height:25px; padding:5px; width:90px; text-align:center; float:right; padding-bottom:0px; color:#333333; font-size:17px; font-family: Trebuchet MS; margin-bottom: 5px; } .core-dialog .message { margin:5px; clear:both; /* margin-bottom:20px; */ line-height:1.5em; margin-left:0; padding:5px; text-align:left; } .core-dialog .buttons { padding:10px; padding-left:0px; } .core-dialog form { width:100%; text-align:left; } .core-dialog form div { /* clear:both; */ /* padding:1px; */ /* padding-top:5px; */ } .core-dialog form input.text { background-image:url(input-bg.png); font-size:14px; width:220px; padding:5px; /* margin-bottom:10px;*/ border:1px solid #cc0000; } .core-dialog form span.validation { font-size:12px; display:block; padding-top:2px; padding-bottom:2px; height:16px; color:#cc0000; } .core-dialog form input.valid {border:2px solid #330000;} .core-dialog form input.invalid {border:2px solid #cc0000; } .core-dialog .clear { clear:both; } .core-dialog .menu {margin-right:5px;} .core-dialog .menu ul { display:block; } .core-dialog .menu ul li { display:inline; } .core-dialog .menu ul li a { color:#ffffff; padding:6px 0 6px 0; width:100px; text-decoration:none; text-align:center; margin:0 2px 0 2px; background-image:url(menu.png); display:block; float:left; color:#000000; font-size:14px; } .core-dialog .bottom-bg { background-repeat:no-repeat; background-image:url(dialog-bg4.png); background-position:bottom center; height:10px; } .core-dialog .top-bg { background-repeat:no-repeat; background-image:url(dialog-bg4.png); background-position:top center; height:10px; } .core-dialog .width-260px {width:260px;} .core-dialog .menu a:hover { text-decoration:underline; } .core-big-dialog > div { width:930px; } .core-big-dialog div .title { background:url(big-dialog-title.png); background-repeat:no-repeat; text-align:left; padding:10px; width:612px; text-align:left; margin:auto; margin-bottom:-20px; } .core-big-dialog .bg-pad-top { background-image:url(coretal-bg.png); background-position:0 0; height:5px; padding:0 10px 0 10px; width:610px; } .core-big-dialog div .content { overflow:auto; height:300px; width:610px; } .core-big-dialog div .content ul { margin:0px; padding:0px; } .core-big-dialog div .content ul li { margin:0px; padding:0px; } .core-big-dialog div .content h1 { font-size:1.4em; margin:10px 0; padding:0; padding-bottom:5px; background-color:#ffffff; color:#000000; } .core-big-dialog .bg-pad-bottom { background-image:url(coretal-bg.png); background-position:0 10px; height:10px; padding: 0 10px 0 10px; width:610px; } .core-iframe-dialog { width:100%; height:100%; } .core-iframe-dialog iframe { position:absolute; z-index:103; top:0; left:0; width:100%; height:100%; border:0; } .core-fullscreen-dialog { position:fixed; top:0; left:0; display:block; width:100%; height:100%; margin:0; padding:0; z-index:103; overflow-y:scroll; margin:auto; } .core-fullscreen-dialog > div { height:100%; } .core-fullscreen-dialog a.close-button { position:absolute; right:10px; top:10px; } .core-fullscreen-dialog div.header h1 { border:0; padding-top:10px; } .core-fullscreen-dialog div.header h1 img { vertical-align:middle; } .core-fullscreen-dialog div.header { width:100%; height:40px; margin-bottom:10px; background:#fff; border-bottom:5px solid #222; } .core-fullscreen-dialog .max-width {width:930px;} .core-fullscreen-dialog .left-column {width:200px;} .core-fullscreen-dialog .left-column * { text-align:right; } .core-fullscreen-dialog .right-column { height:100%; width:725px; } .core-fullscreen-dialog .left-column h1 { border:0; padding:5px; background:#fff; color:#000 !important; margin:0; border-bottom:3px solid #cc0000; } .core-fullscreen-dialog .right-column h1 { margin:0; margin-bottom:5px; color:#000; background:#fff; border:0; padding:5px; border-bottom:3px solid #cc0000; } .core-fullscreen-dialog .corner-white-top { background-image:url(../images/coretal-bg.png); height:10px; } .core-fullscreen-dialog .corner-white-bottom { background-image:url(../images/coretal-bg.png); background-position:0 10px; height:10px; } .core-fullscreen-dialog .corner-222-top { background-image:url(../images/coretal-bg.png); background-position:right top; height:10px; } .core-fullscreen-dialog .corner-222-bottom { background-image:url(../images/coretal-bg.png); background-position:right bottom; height:10px; } .core-fullscreen-dialog .left-column ul { list-style:none; } .core-fullscreen-dialog .left-column a {display:block;} .core-fullscreen-dialog .left-column a span {display:block;} .core-fullscreen-dialog .left-column a.head { background-color:#222222; color:#ffffff; border:0; border-bottom:2px solid #A81109; padding:7px; font-size:13px; font-weight:bold; } .core-fullscreen-dialog .left-column a.head:hover { color:#000000; background-color:#eeeeee; } .core-fullscreen-dialog .left-column a.head span.subtitle { color:#AAA; font-size:11px;} .core-fullscreen-dialog .left-column a.head:hover span.subtitle { color:#222; } .core-fullscreen-dialog .left-column ul li a { /* height:40px; */ color:#000; background-color:#ffffff; margin:5px 0 5px 0; padding:7px; font-size:13px; border:1px solid #222222; border-left:5px solid #A81109; } .core-fullscreen-dialog .left-column a span.subtitle { color:#555; font-size:11px;} .core-fullscreen-dialog .left-column ul li a:hover { background-color:#eeeeee;; color:#000000; } .core-fullscreen-dialog .ui-accordion .ui-accordion-content { padding:0; background: transparent; border:0; } .widget-selection-dialog .border-top-black { border-top:1px solid #000; } .widget-selection-dialog .bg-stripe { background-image:url(stripe.png); } .widget-selection-dialog .right-column .description { margin-top:5px; padding:10px; } .widget-selection-dialog .right-column h2 { margin:0; padding-top:10px; padding-bottom:5px; } .widget-selection-dialog .right-column h2 span.subtitle { font-size:11px; float:right;} .widget-selection-dialog .right-column a { text-decoration:underline; } .widget-selection-dialog .right-column a:hover { color:#cc0000; } .widget-selection-dialog .right-column ul { list-style:disc; margin-top:20px; margin-bottom:20px;} .widget-selection-dialog .right-column ul li { margin-left:20px; } .widget-selection-dialog .popular-widget { margin-top:5px; margin-left:0; margin-right:0; padding:5px;} .widget-selection-dialog .popular-widget .title { font-size:13px; font-weight:bold; } .widget-selection-dialog .popular-widget .subtitle { font-size:11px; } .widget-selection-dialog .popular-widget input[type="button"] { font-size:11px; padding:3px; padding-left:10px; padding-right:10px; } #jquery-overlay { z-index:105 !important; } #jquery-lightbox { z-index:106 !important; } /* .core-fullscreen-dialog { */ /* position:fixed; */ /* display:block; */ /* width:100%; */ /* height:100%; */ /* margin:0; */ /* padding:0; */ /* z-index:103; */ /* /\* background-color:#ffffff; *\/ */ /* } */
8,743
Common Lisp
.l
328
23.362805
133
0.699524
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
0e7ce8949dd63af3549d771cd8af2b7361a7b1c8485de377ed0c93b3013860b9
8,542
[ -1 ]
8,611
install.sh
evrim_core-server/src/install/install.sh
#!/bin/bash # Core Serve Installation Script # Copyright (C) 2006-2008 Metin Evrim Ulu, Aycan iRiCAN # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # Author: Evrim Ulu <[email protected]> # www.core.gen.tr unset CORESERVER_HOME SBCL=`which sbcl 2> /dev/null` REQS="darcs wget tar mv rm ln find chmod chown screen su" FEATURES=":sb-thread :sb-unicode" SYSTEM_REQS="apache2ctl sudo useradd groupadd apxs2" check_sbcl() { if [ -z $SBCL ]; then echo "+----------------------------------------------------------+" echo "| SBCL is required for Core-Server installation |" echo "| Please install SBCL>1.0. |" echo "+----------------------------------------------------------+" echo echo "i.e for gentoo:" echo "# USE=\"threads unicode\" emerge sbcl" exit 1 fi } check_requirement() { if [ -z `which $1 2> /dev/null` ]; then echo "+----------------------------------------------------------+" echo "| $1 is required for Core-Server installation" echo "| Please install $1 and re-run this script. " echo "+----------------------------------------------------------+" exit 1 fi } check_feature() { e="(if (member $1 *features*) (quit :unix-status 0) (quit :unix-status 1))" $SBCL --noinform --no-sysinit --no-userinit --eval "$e" if [ $? -ne 0 ]; then echo "+----------------------------------------------------------+" echo "| $1 feature of SBCL is required for Core-Server. " echo "| Please install $1 feature and re-run this script. " echo "+----------------------------------------------------------+" exit 1 fi } banner() { echo "+-------------------------------------------------------------+" echo "| Welcome to [ - Core-serveR - ] Project |" echo "| http://www.core.gen.tr |" echo "+-------------------------------------------------------------+" echo } prologue() { banner; echo "This program will aid you to install the server base." echo "Please follow the instructions and report any problems to" echo "[email protected]" echo sleep 3 } usage() { banner; echo " Usage: $0 target-directory" exit 1 } epilogue() { echo "+---------- [ - Core-serveR - ] Installed successfully ---------+" echo "| |" echo "| Base directory: $1" echo "| Init script: $1/bin/core-server" echo "| Init lisp script: $1/etc/start.lisp" echo "| |" echo "| To start: $1/bin/core-server start" echo "| To attach: $1/bin/core-server attach" echo "+---------------------------------------------------------------+" } check_sbcl; for i in $REQS; do check_requirement $i; done; for i in $FEATURES; do check_feature $i; done; # Do system wide installation if [ "root" = `whoami` ]; then for i in $SYSTEM_REQS; do check_requirement $i; done; fi if [ ! 1 -eq $# ]; then usage fi prologue echo "+ Compiling installation script. Please wait..." echo TARGET="(defparameter core-server::+target-directory+ \"$1\")" $SBCL --noinform \ --noprint \ --no-sysinit \ --no-userinit \ --load install.lisp \ --eval "$TARGET" \ --load config.lisp \ --eval "(quit :unix-status 111)" if [ $? -eq 111 ]; then epilogue $1 exit 0 fi echo "-- Sorry there is an error occured." exit 1
4,038
Common Lisp
.l
111
33.603604
79
0.540707
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
95672c1442cf5525d3d09ebd0ce1a5a4a9768bfc65ca549ad50da770c3f21251
8,611
[ -1 ]
8,661
Makefile
evrim_core-server/contrib/Makefile
GHCFLAGS = -Wall -O2 GHC = ghc $(GHCFLAGS) $(PKGFLAGS) hxpath = ./HXPath xmltr = ./xmltr all : $(hxpath) $(xmltr) force : $(GHC) --make -o $(prog) $(prog).hs $(hxpath) : $(hxpath).hs $(GHC) --make -o $@ $< $(xmltr) : $(xmltr).hs $(GHC) --make -o $@ $< clean : rm -f $(prog) *.hi *.o $(hxpath) $(xmltr)
322
Common Lisp
.l
13
22.692308
43
0.537954
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
e0b41a14dee0c6cd597a6c33a070eba8a1fb79a9686951a21aa4df4aa3c42048
8,661
[ -1 ]
8,662
xmltr.hs
evrim_core-server/contrib/xmltr.hs
module Main where import Text.XML.HXT.Arrow import System.IO import System.Environment -- import System.Console.GetOpt import System.Exit --- --- Usage: xmltr <id> <input> <output> --- main :: IO () main = do hSetBuffering stdin NoBuffering argv <- getArgs text <- getContents (al, id, src, dst) <- cmdlineOpts argv [rc] <- runX (application al id src dst text) if rc >= c_err then exitWith (ExitFailure (0-1)) else exitWith ExitSuccess -- | the dummy for the boring stuff of option evaluation, -- usually done with 'System.Console.GetOpt' cmdlineOpts :: [String] -> IO (Attributes, String, String, String) cmdlineOpts argv = return ([(a_validate, v_0)], argv!!0, argv!!1, argv!!2) -- | the main arrow application:: Attributes -> String -> String -> String -> String -> IOSArrow b Int application al id src dst text = readDocument ([(a_parse_html, v_1)]) src >>> processChildren (addContent id text `when` isElem) >>> writeDocument [(a_output_html, v_1), (a_indent, v_1), (a_remove_whitespace, v_1), (a_output_encoding, utf8)] dst >>> getErrStatus -- | the dummy for the real processing: the identity filter addContent:: String -> String -> IOSArrow XmlTree XmlTree addContent id text = processTopDown (insertContent `when` isContent) where isContent = isElem >>> hasAttr "id" >>> getAttrValue "id" >>> isA (\x -> x == id) insertContent = replaceChildren (readString [(a_parse_html, v_1), (a_encoding, utf8), (a_validate, v_0)] text >>> getChildren >>> getChildren)
1,765
Common Lisp
.l
53
26.679245
118
0.607416
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
3810a4081f538effbbc53ddf519b09080d678a9862b807dedac6b68130c69ebc
8,662
[ -1 ]
8,663
rss.xslt
evrim_core-server/contrib/rss.xslt
<?xml version="1.0" encoding="utf-8"?> <!-- template for converting darcs' `changes` output from XML to RSS. This template expects the following external variables: cgi-url - full URL to the CGI executable, to place in links the input XML must have the following structure: <darcs repository=""> <changelog> <patch author="" date="" localdate="" inverted="" hash=""> <name></name> <comment></comment> </patch> </changelog> </darcs> --> <xsl:stylesheet version="1.0" exclude-result-prefixes="str" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:str="http://exslt.org/strings"> <xsl:variable name="repo" select="core-server"/> <xsl:variable name="cgi-url">http://labs.core.gen.tr/cgi-bin/darcs.cgi</xsl:variable> <xsl:variable name="command"> <xsl:value-of select="$cgi-url"/>/<xsl:value-of select="/darcs/@target"/> </xsl:variable> <xsl:template match="changelog"> <rss version="2.0"> <channel> <title>changes to <xsl:value-of select="$repo"/></title> <link><xsl:value-of select="$command"/></link> <description> Recent patches applied to the darcs repository named "<xsl:value-of select='$repo'/>". </description> <xsl:apply-templates> <xsl:sort select="@date"/> </xsl:apply-templates> </channel> </rss> </xsl:template> <xsl:template match="patch"> <xsl:variable name="hash" select="@hash"/> <xsl:variable name="created-as" select="/darcs/changelog/created_as"/> <xsl:variable name="creator-hash" select="$created-as/patch/@hash"/> <xsl:variable name="original-name" select="$created-as/@original_name"/> <xsl:variable name="annotate-href"> <xsl:value-of select="$command"/>?c=annotate&amp;p=<xsl:value-of select="$hash"/> <xsl:if test="$creator-hash">&amp;ch=<xsl:value-of select="$creator-hash"/></xsl:if> <xsl:if test="$original-name">&amp;o=<xsl:value-of select="$original-name"/></xsl:if> </xsl:variable> <xsl:variable name="date-nodes" select="str:tokenize(@local_date, ' ')"/> <xsl:variable name="rfc-date"> <xsl:value-of select="$date-nodes[1]"/> <xsl:value-of select="', '"/> <xsl:if test="$date-nodes[3] &lt; 10">0</xsl:if> <xsl:value-of select="$date-nodes[3]"/> <xsl:value-of select="' '"/> <xsl:value-of select="$date-nodes[2]"/> <xsl:value-of select="' '"/> <xsl:value-of select="$date-nodes[6]"/> <xsl:value-of select="' '"/> <xsl:value-of select="$date-nodes[4]"/> <xsl:value-of select="' '"/> <xsl:value-of select="$date-nodes[5]"/> </xsl:variable> <item> <title><xsl:value-of select="name"/></title> <link><xsl:value-of select="$annotate-href"/></link> <author><xsl:value-of select="@author"/></author> <description><xsl:value-of select="comment"/></description> <pubDate><xsl:value-of select="$rfc-date"/></pubDate> </item> </xsl:template> <!-- ignore <path> <created_as>, <name> and <comment> children of <patch> --> <xsl:template match="path"/> <xsl:template match="created_as"/> <xsl:template match="name"/> <xsl:template match="comment"/> </xsl:stylesheet>
3,289
Common Lisp
.l
78
36.141026
91
0.620895
evrim/core-server
16
3
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
0072904ab95ac547ebeff4fc9092d2c6c6fdbe6daf7e8600c30fecc01a976135
8,663
[ -1 ]
8,681
package.lisp
ailisp_simple-gui/package.lisp
;;;; package.lisp (in-package #:cl-user) (defpackage #:top.myfyb.utils (:use #:cl) (:export #:mkstr #:group #:mac #:macq #:join-str #:singlep #:memof)) (defpackage #:top.myfyb.simple-gui (:nicknames #:simple-gui) (:use #:cl #:top.myfyb.utils #:qt #:named-readtables #:ppcre #:alexandria #:iterate) (:export #:q-application #:gui #:q-new #:it #:q-connect #:q-connect*))
425
Common Lisp
.lisp
20
17.45
86
0.598015
ailisp/simple-gui
15
5
0
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
d270abd3059ac88bfe9bb050bda1598edf30d413e50e7ec2dbfe5ed5787b8d71
8,681
[ -1 ]
8,682
simple-gui.lisp
ailisp_simple-gui/simple-gui.lisp
;;;; simple-gui.lisp (in-package #:simple-gui) (generate-all-qt-class-macros) (generate-all-qt-methods) (generate-all-qt-enums) (defvar *q-objects* (make-hash-table) "Keep Tracking of all Qt GUI elements.") (defmacro q-application (&rest args) "Return or create the singleton Qt application object." `(make-qapplication ,@args))
340
Common Lisp
.lisp
10
31.9
57
0.747692
ailisp/simple-gui
15
5
0
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
69a45bdf27f565be1ff9ba3b3a7905bd72ece406d97862661ac76b8379c4d978
8,682
[ -1 ]
8,683
utils.lisp
ailisp_simple-gui/utils.lisp
(in-package #:top.myfyb.utils) (defun mkstr (&rest args) "Make a string from ARGS by princ." (with-output-to-string (s) (dolist (a args) (princ a s)))) (defun group (source n) "Group the list SOURCE to a new list with element as new list contains n elements of SOURCE. e.g. (group '(a b c d e) 2) => '((a b) (c d) (e))" (if (zerop n) (error "zero length")) (labels ((rec (source acc) (let ((rest (nthcdr n source))) (if (consp rest) (rec rest (cons (subseq source 0 n) acc)) (nreverse (cons source acc)))))) (if source (rec source nil) nil))) (defmacro macq (expr) "Display the macroexpand-1 of quote EXPR." `(pprint (macroexpand-1 ',expr))) (defmacro mac (expr) "Display the macroexpand-1 of EXPR." `(pprint (macroexpand-1 ,expr))) (defun singlep (lst) "Return T if LST is a list contains only one element." (and (consp lst) (not (cdr lst)))) (defun join-str (seprator lst) "Join a list of string LST into one str, with seprator SEPRATOR." (cond ((null lst) "") ((singlep lst) (string (car lst))) (t (mkstr (car lst) seprator (join-str seprator (cdr lst)))))) (defun memoize (fn) "Return a memoized version of function FN." (let ((cache (make-hash-table :test #'equal))) #'(lambda (&rest args) (multiple-value-bind (val win) (gethash args cache) (if win val (setf (gethash args cache) (apply fn args))))))) (defmacro _f (op place &rest args) "Set the PLACE to the result of (OP PLACE ,@ARGS)." (multiple-value-bind (vars forms var set access) (get-setf-expansion place) `(let* (,@(mapcar #'list vars forms) (,(car var) (,op ,access ,@args))) ,set))) (defmacro memof (fn-name) "Set the FN-NAME's function definition to its memoized version." `(_f memoize (fdefinition ',fn-name))) (defun array->vector (array) "Return a 1D version of ARRAY" (copy-array (make-array (array-total-size array) :element-type (array-element-type array) :displaced-to array)))
2,016
Common Lisp
.lisp
56
32.107143
94
0.651437
ailisp/simple-gui
15
5
0
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
532c66c45586d9e08a581335809ed695606f91328efcdf7ef51c35d3b64f26a2
8,683
[ -1 ]
8,684
qt-utils.lisp
ailisp_simple-gui/qt-utils.lisp
(in-package #:simple-gui) (defvar *qt-modules* '(:qtcore :qtgui :qtopengl :qtsvg :qtwebkit) "Qt Modules to load and generate GUI description macros.") ;;;; Some meta utils (defun all-qclasses () "List all qt classes, each is represented by a number." (let ((all-qclasses nil)) (qt::map-classes #'(lambda (qclass) (push qclass all-qclasses))) (nreverse all-qclasses))) (memof all-qclasses) (defun all-qsubclasses-of (qclass) "List all subclasses of given QCLASS. QCLASS is a number." (remove-if-not #'(lambda (qsubclass) (qt::qsubclassp qsubclass qclass)) (all-qclasses))) (memof all-qsubclasses-of) (defun qclass-names (qclass-list) "All qt class names of QCLASS-LIST contains a list of numbers." (mapcar #'qt::qclass-name qclass-list)) (defun all-qmethods () "List all qt methods, each is represented by a number." (let ((all-qmethods nil)) (qt::map-methods #'(lambda (qmethod) (unless (or (qt::qmethod-ctor-p qmethod) (qt::qmethod-dtor-p qmethod) (qt::qmethod-enum-p qmethod)) (push qmethod all-qmethods)))) all-qmethods)) (memof all-qmethods) (defun all-qenums () "List all qt enums, each is represented by a number." (let ((all-qenums nil)) (qt::map-methods #'(lambda (qmethod) (if (qt::qmethod-enum-p qmethod) (push qmethod all-qenums)))) all-qenums)) (memof all-qenums) (defvar *except-qmethod-names* '("drop_action" "setDrop_action" "default_action" "setDefault_action" "set_widget" "_deviceType" "set_deviceType" "_touchPointStates" "set_touchPointStates" "_touchPoints" "set_touchPoints" "_widget") "Excepted qt method names, which are actually not in qt doc but for internal use.") (defun except-qmethod-name-p (qmethod-name) "Return T if QMETHOD-NAME is an except method name, otherwise return NIL" (find qmethod-name *except-qmethod-names* :test #'string=)) (defun all-qmethod-names () "List all qt method names, duplicate name but different method are only count once." (let ((names (make-hash-table :test #'equal))) (mapcar #'(lambda (qmethod) (let ((qmethod-name (qt::qmethod-name qmethod))) (unless (except-qmethod-name-p qmethod-name) (setf (gethash qmethod-name names) t)))) (all-qmethods)) (hash-table-keys names))) (memof all-qmethod-names) (defvar *except-enum-names* '("Q_COMPLEX_TYPE" "Q_PRIMITIVE_TYPE" "Q_STATIC_TYPE" "Q_MOVABLE_TYPE" "Q_DUMMY_TYPE" "LicensedGui" "LicensedXml" "LicensedQt3SupportLight" "LicensedScript" "LicensedOpenVG" "LicensedDBus" "LicensedTest" "LicensedActiveQt" "LicensedScriptTools" "LicensedSvg" "LicensedDeclarative" "LicensedSql" "LicensedOpenGL" "LicensedCore" "QtDebugMsg" "QtWarningMsg" "QtCriticalMsg" "QtFatalMsg" "QtSystemMsg" "LicensedHelp" "LicensedMultimedia" "LicensedQt3Support" "LicensedXmlPatterns" "LicensedNetwork") "Except qt enum names, which are actually not implemented by CommonQt.") (defun except-qenum-name-p (enum-class-and-name) "Return T if ENUM-CLASS-AND-NAME is an except qt enum name, otherwise return NIL." (and (string= (car enum-class-and-name) "QGlobalSpace") (find (cdr enum-class-and-name) *except-enum-names* :test #'string=))) (defun all-qenum-names () "List all qt enum names, each of name is in a form (QCLASS-NAME . QENUM-NAME)." (let ((names nil)) (mapcar #'(lambda (qmethod) (let ((enum-class-and-name (cons (qt::qclass-name (qt::qmethod-class qmethod)) (qt::qmethod-name qmethod)))) (unless (except-qenum-name-p enum-class-and-name) (push enum-class-and-name names)))) (all-qenums)) names)) (memof all-qenum-names) ;;;; Name conversions (defun convert-to-qt-class-name (s) "Convert a string foo-bar to string FooBar" (let ((camel-case (convert-lisp-name-to-camel-case s))) (setf (aref camel-case 0) (char-upcase (aref camel-case 0))) camel-case)) (defun convert-to-lisp-name (s) "Convert a string QPushButton or qPush_button to string Q-PUSH-BUTTON." (let ((temp-name (ppcre:regex-replace-all "--" (ppcre:regex-replace-all "_" (string-upcase (ppcre:regex-replace-all "[A-Z]" s "-\\\&")) "-") "-"))) (if (eql (aref temp-name 0) #\-) (subseq temp-name 1) temp-name))) (defvar *convert-special-cases* '(("OPERATOR--" . "OPERATOR--") ("APPEND" . "QAPPEND") ("SUBSTITUTE" . "QSUBSTITUTE") ("SPACE" . "QSPACE") ("FIND" . "QFIND") ("POSITION" . "QPOSITION") ("LAST" . "QLAST") ("READLINE" . "QREAD-LINE") ("NUMBER" . "QNUMBER") ("WARNING" . "QWARNING") ("OPEN" . "QOPEN") ("OPTIMIZE" . "QOPTIMIZE") ("STRING" . "QSTRING") ("CONJUGATE" . "QCONJUGATE") ("LOAD" . "QLOAD") ("TYPE" . "QTYPE") ("WRITE" . "QWRITE") ("READ" . "QREAD") ("SECOND" . "QSECOND") ("CLASSNAME" . "Q-CLASS-NAME") ("CHECKTYPE" . "QCHECK-TYPE") ("FIRST" . "QFIRST") ("CLOSE" . "QCLOSE") ("MERGE" . "QMERGE") ("ABORT" . "QABORT") ("SEQUENCE" . "QSEQUENCE") ("SPEED" . "QSPEED") ("IGNORE" . "QIGNORE") ("REPLACE" . "QREPLACE") ("METHOD" . "Q-METHOD") ("SORT" . "QSORT") ("ERROR" . "QERROR") ("REMOVE" . "QREMOVE") ("SIGNAL" . "Q-SIGNAL") ("PUSH" . "QPUSH") ("MAP" . "QMAP") ("RESTART" . "QRESTART") ("DIRECTORY" . "QDIRECTORY") ("FILL" . "QFILL") ("T" . "Q-T") ("LOG" . "QLOG") ("PRINT" . "QPRINT") ("FORMAT" . "QFORMAT") ("LENGTH" . "QLENGTH") ("TIME" . "QTIME") ("BLOCK" . "QBLOCK") ("TRUNCATE" . "QTRUNCATE") ("VECTOR" . "QVECTOR") ("COUNT" . "QCOUNT") ("SHADOW" . "QSHADOW") ("PROFILE" . "QPROFILE") ("RESET" . "QRESET") ("TIMEOUT" . "QTIMEOUT") ("ExIT" . "QEXIT") ("QUIT" . "QQuit") ("DEREF" . "QDEREF") ("CAST" . "QCAST")) "Special cases where name conversions to lisp is manually specified.") (defun convert-qt-method-name-to-lisp-name (s) "Do the conversion by CONVERT-TO-LISP-NAME, but with some special-case." (let ((special (assoc s *convert-special-cases* :test #'string-equal))) (if special (cdr special) (convert-to-lisp-name s)))) (defun convert-to-qt-method-name (s) "Convert a string foo-bar to string fooBar" (convert-lisp-name-to-camel-case s)) (defun convert-lisp-name-to-camel-case (s) "Convert a string designator foo-bar to string fooBar" (let ((s (string-downcase (string s)))) (do ((i 0 (1+ i))) ((>= i (length s))) (when (eql (aref s i) #\-) (incf i) (when (< i (length s)) (setf (aref s i) (char-upcase (aref s i)))))) (delete #\- s))) (defun convert-to-cpp-basic-type (s) "Convert a symbol or string S to the string indicating a C++ basic type." (string-downcase (string s))) (defun convert-to-cpp-basic-type-or-qt-class (s) "Convert a symbol or string s to the string indicating a C++ basic type or a qt class." (if (find #\- (string s)) (convert-to-qt-class-name s) (convert-to-cpp-basic-type s))) (defun convert-to-qt-signal-name (sig &rest args) "Convert a list like (:clicked :int :q-push-button) to corresponding qt signal name." (mkstr (convert-to-qt-method-name sig) "(" (join-str "," (mapcar #'convert-to-cpp-basic-type-or-qt-class args)) ")")) ;;;; Translation for simple descriptive GUI definition. (defun expand-qt-method-call (method-name &rest args) "Expand to a CommonQt method call." `(optimized-call t ,(car args) ,method-name ,@(cdr args))) (defun translate-set (obj prop) "Translate a set specification to a qt setter method." (let ((setter (car prop)) (vals (cdr prop))) (apply #'expand-qt-method-call (convert-to-qt-method-name (mkstr "set-" setter)) obj vals))) (defun translate-add (obj to-add) "Translate an add specification to the q-add wrapper." `(q-add ,obj ,to-add)) (defun q-add (parent child) "A wrapper that will determine to call addWidget or addLayout depends on type of child." (let ((child-class (slot-value child 'class))) (cond ((qt::qsubclassp child-class (qt::find-qclass "QWidget")) (optimized-call t parent "addWidget" child)) ((qt::qsubclassp child-class (qt::find-qclass "QLayout")) (optimized-call t parent "addLayout" child)) (t (error "Illegal object ~a to add." child))))) (defun translate-connect (sender sig-and-fn) "Translate a qt signal connect specification." (let ((sig (butlast sig-and-fn)) (fn (lastcar sig-and-fn))) (expand-qt-connect-signal sender sig fn))) (defun translate-connect* (sender sig-fn-data) "Translate a more detailed connect specification, which can pass an additional data argument to the connected function." (let* ((sig-fn (butlast sig-fn-data)) (sig (butlast sig-fn)) (fn (lastcar sig-fn)) (data (lastcar sig-fn-data)) (gargs (gensym))) (expand-qt-connect-signal sender sig `#'(lambda (&rest ,gargs) (apply ,fn ,data ,gargs))))) (defun expand-qt-connect-signal (sender sig fn) "Common parts for expand connect and connect* specification." `(connect ,sender ,(apply #'convert-to-qt-signal-name sig) ,fn)) (defun translate-spec (spec-opr obj spec) "Translate a specification according to the SPEC-OPR." (ecase spec-opr (:add (translate-add obj spec)) (:set (translate-set obj spec)) ((:con :connect) (translate-connect obj spec)) ((:con* :connect*) (translate-connect* obj spec)))) (defun translate-specs (name specs) "Translate a group of specifications of same type." (if (keywordp (car specs)) (mapcar #'(lambda (spec) (translate-spec (car specs) name spec)) (cdr specs)) (mapcar #'(lambda (spec) (translate-set name spec)) specs))) (defun translate-body (name body) "Translate a GUI element body, contains groups of specifications." (mapcan #'(lambda (specs) (translate-specs name specs)) body)) ;;;; Generate macros for GUI element description. (defmacro generate-all-qt-class-macros () "Generate all macros for GUI element description." `(progn ,@(mapcar #'expand-qt-class-macro (qclass-names (remove-duplicates (append (all-qsubclasses-of (qt::find-qclass "QWidget")) (all-qsubclasses-of (qt::find-qclass "QLayout")))))))) (defun expand-qt-class-macro (qclass-name) "Gernerate a single GUI element description." (let* ((qclass-lisp-name (convert-to-lisp-name qclass-name)) (qclass-symbol (intern qclass-lisp-name :simple-gui))) `(progn (export ',qclass-symbol :simple-gui) (defmacro ,qclass-symbol (name &body body) (if (or (null name) (string= (symbol-name name) "-")) (setf name (gensym))) `(let* ((,name (optimized-new ,,qclass-name)) (it ,name)) (declare (ignorable it)) (setf (gethash ',name *q-objects*) ,name) ,@ (translate-body name body) ,name))))) (eval-when (:load-toplevel :compile-toplevel :execute) (defun load-qt-stage1 () "Load qt modules and switch to CommonQt's readtable." (named-readtables:in-readtable :qt) (mapcar #'ensure-smoke *qt-modules*))) (load-qt-stage1) (defmacro gui (name) "Macro for access gui elements." `(gethash ',name *q-objects*)) ;;;; Generate all qt methods in a lisp like way to reprensent method names. (defvar *qt-method-package* (or (find-package "Q-") (make-package "Q-" :use ())) "The package that will contains all qt methods (including enums).") (defmacro generate-all-qt-methods () "Generate all qt methods, each different method name converts to only one macro defination, which method will be invoked is determined by smoke, not in cl." `(progn ,@(mapcar #'expand-qt-method-macro (all-qmethod-names)))) (defmacro generate-all-qt-enums () "Generate all qt enums." `(progn ,@ (mapcar #'expand-qt-enum-macro (all-qenum-names)))) (defun expand-qt-method-macro (qmethod-name) "Generate a macro for the call of QMETHOD-NAME." (let* ((qmethod-symbol-name (convert-qt-method-name-to-lisp-name qmethod-name)) (qmethod-symbol (intern qmethod-symbol-name *qt-method-package*))) `(progn (export ',qmethod-symbol ,(package-name (symbol-package qmethod-symbol))) (defmacro ,qmethod-symbol (&rest args) `(let ((class-or-obj ,(car args))) (optimized-call t (if (symbolp class-or-obj) (convert-to-qt-class-name class-or-obj) class-or-obj) ,,qmethod-name ,@(cdr args))))))) (defun expand-qt-enum-macro (enum-class-and-name) "Generate a symbol macro for the enum in the format Q-CLASS/Q-ENUM." (let* ((qenum-symbol-name (mkstr (convert-to-lisp-name (car enum-class-and-name)) "/" (convert-qt-method-name-to-lisp-name (cdr enum-class-and-name)))) (qenum-symbol (intern qenum-symbol-name *qt-method-package*))) `(progn (export ',qenum-symbol ,(package-name (symbol-package qenum-symbol))) (define-symbol-macro ,qenum-symbol (optimized-call t ,(car enum-class-and-name) ,(cdr enum-class-and-name)))))) (defmacro q-new (qclass &rest args) "Make new qt non GUI element, maybe useful sometimes." `(optimized-new ,(convert-to-qt-class-name qclass) ,@args)) (defmacro q-connect (obj &rest spec) (translate-connect obj spec)) (defmacro q-connect* (obj &rest spec) (translate-connect* obj spec))
13,237
Common Lisp
.lisp
309
38.433657
93
0.66501
ailisp/simple-gui
15
5
0
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
f454de4ed4352b5ed57be1194f6641edced0fae39cbedc82c11eeb77e42faeff
8,684
[ -1 ]
8,685
greeting.lisp
ailisp_simple-gui/examples/greeting.lisp
(eval-when (:compile-toplevel :load-toplevel :execute) (use-package :simple-gui) (use-package :q-)) (defun main () (q-application) (q-widget main (:set (:window-title "What's your name?") (:layout (q-h-box-layout a (:add (q-line-edit name) (q-push-button button (:set (:text "OK")) (:connect (:clicked #'(lambda () (information 'q-message-box (gui main) "Simple GUI" (concatenate 'string "Hello, " (text (gui name))))))))))))) (show (gui main)) (exec (q-application)))
555
Common Lisp
.lisp
21
21.333333
61
0.579737
ailisp/simple-gui
15
5
0
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
1aa08bc1ae023b20596bcf1f843614b8b70a9492723b69cd8d63e77e59fa4784
8,685
[ -1 ]
8,686
cards.lisp
ailisp_simple-gui/examples/cards.lisp
(eval-when (:compile-toplevel :load-toplevel :execute) (use-package :simple-gui) (use-package :q-)) (defparameter *rows* 6) (defparameter *cols* 8) (defparameter *block-size* 90) (defparameter *kinds* 15) (defvar *empty-icon*) (defvar *current-flip* nil) (defvar *board-total-size*) (defvar *board*) (defvar *board-1d*) (defun build-data () (setf *board-total-size* (* *rows* *cols*)) (assert (evenp *board-total-size*)) (setf *board-1d* (make-array *board-total-size* :element-type 'integer)) (loop for i below (/ *board-total-size* 2) do (setf (aref *board-1d* i) (random *kinds*) (aref *board-1d* (- *board-total-size* 1 i)) (aref *board-1d* i))) (setf *board-1d* (alexandria:shuffle *board-1d*)) (setf *board* (make-array `(,*cols* ,*rows*) :displaced-to *board-1d*)) (setf *empty-icon* (q-new q-icon "./pic/empty.png"))) (defun mkstr (&rest args) "Make a string from ARGS by princ." (with-output-to-string (s) (dolist (a args) (princ a s)))) (defun build-widgets () (q-widget window (:set (:window-title "Cards Rolling-Over") (:geometry 200 200 800 600) (:layout (q-grid-layout grid)))) (simple-gui::mkstr) (loop for i below *cols* do (loop for j below *rows* do (progn (add-widget (layout (gui grid)) (let* ((data (list i j)) (button (q-tool-button - (:set (:icon-size (q-new q-size *block-size* *block-size*))) (:connect* (:clicked #'on-click-block (append data (list it))))))) button) j i 1 1))))) (defun flip-button-icon-and-delete (data) (show-button-icon data) (let ((timer (q-new q-timer))) (set-interval timer 1000) (q-connect timer :timeout #'(lambda () (stop timer) (set-visible (third data) nil))) (start timer))) (defun flip-button-icon (data) (show-button-icon data) (let ((timer (q-new q-timer))) (set-interval timer 1000) (q-connect timer :timeout #'(lambda () (stop timer) (hide-button-icon data))) (start timer))) (defun show-button-icon (data) (set-icon (third data) (q-new q-icon (mkstr "./pic/" (aref *board* (first data) (second data)) ".png")))) (defun hide-button-icon (data) (set-icon (third data) *empty-icon*)) (defun on-click-block (data) (cond ((null *current-flip*) (setf *current-flip* data) (show-button-icon data)) ((equal data *current-flip*)) ((eql (aref *board* (first data) (second data)) (aref *board* (first *current-flip*) (second *current-flip*))) (flip-button-icon-and-delete data) (flip-button-icon-and-delete *current-flip*) (setf *current-flip* nil)) (t (flip-button-icon data) (flip-button-icon *current-flip*) (setf *current-flip* nil)))) (defun main () (q-application) (build-data) (build-widgets) (show (gui window)) (exec (q-application)))
2,830
Common Lisp
.lisp
84
29.880952
107
0.638757
ailisp/simple-gui
15
5
0
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
ce0af7bf5c669d1ca81f912ac8bf28a6f405918a2a8116dea0dc1ea31eea55ba
8,686
[ -1 ]
8,687
web.lisp
ailisp_simple-gui/examples/web.lisp
(eval-when (:compile-toplevel :load-toplevel :execute) (use-package :simple-gui) (use-package :q-)) (defun main () (q-application) (q-main-window window (:set (:window-title "QWebView") (:geometry 100 100 800 600) (:central-widget (q-web-view web)))) (qload (gui web) (q-new q-url "http://www.cliki.net/")) (show (gui window)) (exec (q-application)))
392
Common Lisp
.lisp
14
24.071429
57
0.635638
ailisp/simple-gui
15
5
0
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
80f58464c16cc42ad93f0f512766d9fd4ede05df0e1c386aa089f64687445067
8,687
[ -1 ]