Recently Written · git

clic

MIRROR ONLY Gopher client with pretty colours in Common Lisp

git clone https://github.com/equwal/clic

Log | Files | Refs


commit 04aea88d00b8330bdbde6e6fca0b926821d9f1f1
Solene Rapenne <solene@perso.pw>
2018-02-01 19:54:29 +0100

Change local file support code

 clic.lisp | 61 ++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 32 insertions(+), 29 deletions(-)
diff --git a/clic.lisp b/clic.lisp
index e664d9d..61cd8aa 100644
--- 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 ?