cleaning 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 6e9a0a50df3a58cdce03da5875fa63cef51cc469 DIR parent 1c31d4653e91070b9f3828a0965ccefda20747c9 HTML Author: Solene Rapenne <solene@perso.pw> Date: Sun, 5 Nov 2017 00:11:05 +0000 cleaning code Diffstat: M clic.lisp | 62 ++++++++++++++----------------- 1 file changed, 27 insertions(+), 35 deletions(-) --- DIR diff --git a/clic.lisp b/clic.lisp @@ -54,18 +54,18 @@ "Used to display gopher response with color one line at a time" (let ((line-type (subseq line 0 1)) (infos (split (subseq line 1) #\Tab))) - + ;; see RFC 1436 ;; section 3.8 (when (and (= (length infos) 4) (member line-type *allowed-selectors* :test #'equal)) - + (let ((text (car infos)) (uri (cadr infos)) (host (caddr infos)) (port (parse-integer (cadddr infos)))) - + ;; RFC, page 4 (check "i" (print-with-color text)) @@ -134,37 +134,35 @@ (push here *history*) ;; we reset the links table ONLY if we have a new folder - ;; and we store the location for "previous" command (when (string= "1" type) - (setf *links* (make-hash-table)) - (setf (gethash 0 *links*) here))) + (setf *links* (make-hash-table))) - ;; we prepare informations about the connection - (let* ((address (sb-bsd-sockets:get-host-by-name host)) - (host (car (sb-bsd-sockets:host-ent-addresses address))) - (socket (make-instance 'sb-bsd-sockets:inet-socket :type :stream :protocol :tcp))) - - (sb-bsd-sockets:socket-connect socket host port) - - ;; we open a stream for input/output - (let ((stream (sb-bsd-sockets:socket-make-stream socket :input t :output t))) + ;; we prepare informations about the connection + (let* ((address (sb-bsd-sockets:get-host-by-name host)) + (host (car (sb-bsd-sockets:host-ent-addresses address))) + (socket (make-instance 'sb-bsd-sockets:inet-socket :type :stream :protocol :tcp))) - ;; sending the request here - ;; if the selector is 1 we omit it - (format stream "~a~%" uri) - (force-output stream) + (sb-bsd-sockets:socket-connect socket host port) - ;; for each line we receive we display it - (loop for line = (read-line stream nil nil) - counting line into line-number - while line do - (cond - ((string= "1" type) - (formatted-output line line-number)) - ((string= "0" type) - (format t "~a~%" line)))))) - (format t "~aRequested gopher://~a:~a/~a~a~a~%" (getcolor 'cyan) host port type uri (getcolor 'white))) + ;; we open a stream for input/output + (let ((stream (sb-bsd-sockets:socket-make-stream socket :input t :output t))) + + ;; sending the request here + ;; if the selector is 1 we omit it + (format stream "~a~%" uri) + (force-output stream) + + ;; for each line we receive we display it + (loop for line = (read-line stream nil nil) + counting line into line-number + while line do + (cond + ((string= "1" type) + (formatted-output line line-number)) + ((string= "0" type) + (format t "~a~%" line)))))) + (format t "~aRequested gopher://~a:~a/~a~a~a~%" (getcolor 'cyan) host port type uri (getcolor 'white)))) (defun visit(destination) "visit a location" @@ -185,12 +183,6 @@ (pop *history*) (visit (pop *history*)))) -(defun help() - "show help" - (format t "HOW TO USE CLI !~%") - (format t "(getpage \"host\" port \"uri\")~%") - (format t "~%~%")) - (defun help-shell() "show help for the shell" (format t "number : go to link n~%")