Date: Fri, 31 Aug 2001 01:38:40 -0500 From: Mike Meyer <mwm@mired.org> To: Greg Black <gjb@gbch.net> Cc: hackers@freebsd.org Subject: Re: Should URL's be pervasive. Message-ID: <15247.12528.872288.911871@guru.mired.org> In-Reply-To: <nospam-999226294.68880@maxim.gbch.net> References: <20010830111018.A97057@ussenterprise.ufp.org> <nospam-999218204.57695@maxim.gbch.net> <20010830223746.A40540@ussenterprise.ufp.org> <nospam-999226294.68880@maxim.gbch.net>
next in thread | previous in thread | raw e-mail | index | archive | help
--trvpRMhWTP Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit Greg Black <gjb@gbch.net> 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. <mike -- Mike Meyer <mwm@mired.org> 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 <sys/param.h> #include <stdio.h> #include <fetch.h> #include <stdlib.h> #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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?15247.12528.872288.911871>