From owner-freebsd-hackers Thu Aug 30 23:40:59 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from guru.mired.org (okc-94-248-46.mmcable.com [24.94.248.46]) by hub.freebsd.org (Postfix) with SMTP id 3F55B37B401 for ; Thu, 30 Aug 2001 23:40:53 -0700 (PDT) (envelope-from mwm@mired.org) Received: (qmail 44385 invoked by uid 100); 31 Aug 2001 06:38:40 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="trvpRMhWTP" Content-Transfer-Encoding: 7bit Message-ID: <15247.12528.872288.911871@guru.mired.org> Date: Fri, 31 Aug 2001 01:38:40 -0500 To: Greg Black Cc: hackers@freebsd.org Subject: Re: Should URL's be pervasive. In-Reply-To: References: <20010830111018.A97057@ussenterprise.ufp.org> <20010830223746.A40540@ussenterprise.ufp.org> X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ 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 --trvpRMhWTP Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit Greg Black types: > | 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). > If I was doing it, I'd do the command line program first in awk > or Python to get on top of the parsing in an easy way and to > have a test tool working. As already mentioned, libfetch can do the parsing - but fetchParseURL is either buggy or needs extending; I haven't checked. A simple C program to use that and spit out the parts is easy (see attached). I have a good idea for how to do output formatting; I think I'm going to work on that tonight. The real question is whether or not DES will let us fool with libfetch to add this stuff. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. --trvpRMhWTP Content-Type: text/plain Content-Description: url.c - link with -lfetch Content-Disposition: inline; filename="url.c" Content-Transfer-Encoding: 7bit /* * A QAD hack for pulling values out of urls. */ #include #include #include #include #define OPTIONS "fhmPpsU" void usage(char *name) { fprintf(stderr, "usage: %s [-f | -h | -m | -P | -p | -s | -U] URL\n", name) ; exit(EXIT_FAILURE) ; } int main(int argc, char **argv) { int outf ; char *in ; struct url *out ; if (argc == 2) { outf = 0 ; in = argv[1] ; } else if (argc == 3) { if (argv[1][0] != '-' || argv[1][2] != '\0') usage(argv[0]) ; outf = argv[1][1] ; if (index(OPTIONS, outf) == NULL) usage(argv[0]) ; in = argv[2] ; } else usage(argv[0]) ; if ((out = fetchParseURL(in)) == NULL) { fprintf(stderr, "%s: Failed to parse URL\n", argv[0]) ; exit(EXIT_FAILURE) ; } else { switch (outf) { case 'f': puts(out->doc) ; break ; case 'h': puts(out->host) ; break ; case 'm': printf("%s@%s\n", out->user, out->host) ; break ; case 'P': puts(out->pwd) ; break ; case 'p': printf("%d\n", out->port) ; break ; case 's': puts(out->scheme) ; break ; case 'U': puts(out->user) ; break ; default: printf("We need a scheme-based formatting thing here...\n") ; break ; } fetchFreeURL(out) ; } exit(EXIT_SUCCESS) ; } --trvpRMhWTP-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message