Greg Black <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
/*
* 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) ;
}