From owner-freebsd-hackers Fri Aug 31 0:19:16 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from tepid.osl.fast.no (tepid.osl.fast.no [213.188.9.130]) by hub.freebsd.org (Postfix) with ESMTP id A7FB937B401 for ; Fri, 31 Aug 2001 00:19:10 -0700 (PDT) (envelope-from raw@fast.no) Received: from raw.grenland.fast.no (fw-oslo.fast.no [213.188.9.129]) by tepid.osl.fast.no (8.9.3/8.9.1) with ESMTP id JAA97222; Fri, 31 Aug 2001 09:18:55 +0200 (CEST) (envelope-from raw@fast.no) Received: (from raw@localhost) by raw.grenland.fast.no (8.11.3/8.11.3) id f7V7IrJ90546; Fri, 31 Aug 2001 09:18:53 +0200 (CEST) (envelope-from raw) From: Raymond Wiker MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15247.14941.211628.708473@raw.grenland.fast.no> Date: Fri, 31 Aug 2001 09:18:53 +0200 To: freebsd-hackers@FreeBSD.ORG Subject: Re: Should URL's be pervasive. In-Reply-To: <20010830223746.A40540@ussenterprise.ufp.org> References: <20010830111018.A97057@ussenterprise.ufp.org> <20010830223746.A40540@ussenterprise.ufp.org> X-Mailer: VM 6.92 under 21.1 (patch 12) "Channel Islands" XEmacs Lucid Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Leo Bicknell writes: > On Fri, Aug 31, 2001 at 10:36:44AM +1000, Greg Black wrote: > > Why not do it the Unix way? Create a new application, e.g., > > url(1), to parse the URLs and use it like so: > > Sometimes the solution is so obvious. :-) Well, part of it. I'm > thinking it's worth creating liburl, with parse routines, and then > a front end for the command line, url(1). > > Some quick google work shows nothing quite like url(1) (save one > obscure reference to the MKS toolkit on Windows), and searching > for a lex/yacc grammar for parsing urls doesn't turn up anything > useful. > > If only there were more hours in a day. OK, here's a Common Lisp function that works for some of the common cases. One of my colleagues rewrote this to C++, for a total of about 100 lines. If there's any interest, I can ask him if I can post the code here. Alternatively, we could start rewriting FreeBSD in Common Lisp :-) BTW: There are at least two IETF RFCs that deal exclusively with URL/URI parsing, but I don't have the RFC numbers handy. (defun split-url (url-string) "Splits the given URL into components representing the protocol, user, password, host, port number, path and arguments." (flet ((split (sep string) (let ((pos (search sep string))) (if pos (list (subseq string 0 pos) (subseq string (+ pos (length sep)))) string)))) (macrolet ((try-split (sep str (true-1-var true-2-var) &optional false-var) (let ((ressym (gensym))) `(let ((,ressym (split ,sep ,str))) (if (listp ,ressym) (setf ,true-1-var (car ,ressym) ,true-2-var (cadr ,ressym)) ,(when false-var `(setf ,false-var ,ressym))))))) (let (proto user pass host port path args) (try-split "://" url-string (proto host) host) (try-split "/" host (host path)) (try-split "@" host (user host)) (when user (try-split ":" user (user pass))) (try-split ":" host (host port)) (if path (let ((argstr nil)) (try-split "?" path (path argstr)) (when argstr (setq args (let ((args '()) (end nil)) (loop (try-split "&" argstr (arg argstr) end) (if end (return-from nil (nreverse (cons end args))) (push arg args))))))) (setq path "/")) (values proto user pass host port path args))))) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message