Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; gauche scheme: https://practical-scheme.net/gauche/memo.html
- (use sxml.ssax)
- (use sxml.sxpath)
- (use sxml.serializer)
- (use sxml.tools)
- (define format-filter
- (lambda (type)
- (format "not(contains(@href, \"~a\"))" type)))
- (define href-filter
- (lambda (types filters)
- (cond
- ((null? types)
- (if (null? filters)
- (format "/xbel/bookmark")
- (format "/xbel/bookmark[~a]" (string-join filters " and "))))
- (#t (href-filter (cdr types) (cons (format-filter (car types)) filters))))))
- ;; works in repl to give a list that does not contain image types:
- ;; ((sxpath "//bookmark[not(contains(@href, \"jpg\")) and not(contains(@href, \"svg\"))]") bs)
- (define add-root
- (lambda (results)
- `(*TOP*
- (@@ (*NAMESPACES* (ns0 "http://www.freedesktop.org/standards/shared-mime-info")
- (ns1 "http://www.freedesktop.org/standards/desktop-bookmarks")))
- (xbel (@ (version "1.0")) ,@results))))
- (define main
- (lambda (argv)
- (with-input-from-file "example-small.xbel"
- (lambda ()
- (let* ((bookmarks
- (ssax:xml->sxml (current-input-port)
- '((ns0 . "http://www.freedesktop.org/standards/shared-mime-info")
- (ns1 . "http://www.freedesktop.org/standards/desktop-bookmarks"))))
- (filters (href-filter (cdr argv) '())))
- (display (format "~%filters: ~a~%" filters))
- (display (format "~%results: ~a~%" ((sxpath filters) bookmarks)))
- (display (format "~%xml : ~a~%" (srl:sxml->xml (add-root ((sxpath filters) bookmarks)))))
- (with-output-to-file "example-filtered.xbel"
- (lambda ()
- ;; doesn't quite work, namespaces are all jacked up - I think
- (srl:sxml->xml (add-root ((sxpath filters) bookmarks)) (current-output-port)))))))))
Add Comment
Please, Sign In to add comment