Change local file support code - clic - Clic is an command line interactive client for gopher written in Common LISP HTML git clone git://bitreich.org/clic/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/clic/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 04aea88d00b8330bdbde6e6fca0b926821d9f1f1 DIR parent bb2be59d780c8ba98921bdd20ea3383a1c87fb93 HTML Author: Solene Rapenne <solene@perso.pw> Date: Thu, 1 Feb 2018 19:54:29 +0100 Change local file support code Diffstat: M clic.lisp | 61 ++++++++++++++++--------------- 1 file changed, 32 insertions(+), 29 deletions(-) --- DIR diff --git a/clic.lisp b/clic.lisp @@ -378,36 +378,30 @@ (defun parse-url(url) "parse a gopher url and return a location" - (if (= 0 (search "file://" url)) - (progn - (load-file-menu (subseq url 7)) - (make-location :host 'local-file - :port nil - :type "1" - :uri url)) - (let ((url (if (search "gopher://" url) - (subseq url 9) - url))) - - ;; splitting with / to get host:port and uri - ;; splitting host and port to get them - (let* ((infos (split url #\/)) - (host-port (split (pop infos) #\:))) - - ;; create the location to visit - (make-location :host (pop host-port) + + (let ((url (if (search "gopher://" url) + (subseq url 9) + url))) + + ;; splitting with / to get host:port and uri + ;; splitting host and port to get them + (let* ((infos (split url #\/)) + (host-port (split (pop infos) #\:))) + + ;; create the location to visit + (make-location :host (pop host-port) - ;; default to port 70 if not supplied - :port (if host-port ;; <- empty if no port given - (parse-integer (car host-port)) - 70) - - ;; if type is empty we default to "1" - :type (let ((type (pop infos))) - (if (< 0 (length type)) type "1")) + ;; default to port 70 if not supplied + :port (if host-port ;; <- empty if no port given + (parse-integer (car host-port)) + 70) + + ;; if type is empty we default to "1" + :type (let ((type (pop infos))) + (if (< 0 (length type)) type "1")) - ;; glue remaining args between them - :uri (format nil "~{/~a~}" infos)))))) + ;; glue remaining args between them + :uri (format nil "~{/~a~}" infos))))) (defun get-argv() "Parse argv and return it" @@ -682,7 +676,16 @@ ;; parsing command line parameter ;; if not empty we use it or we will use a default url (if argv - (parse-url argv) + ;; is it a file ? + (if (= 0 (search "file://" argv)) + (progn + (load-file-menu (subseq argv 7)) + (make-location :host 'local-file + :port nil + :type "1" + :uri argv)) + ;; it's not a file, create a location + (parse-url argv)) (make-location :host "gopherproject.org" :port 70 :uri "/" :type "1"))))) ;; is there an output redirection ?