#include <stdio.h>
#include "url.h"

extern struct URL_module URL_module_file;
extern struct URL_module URL_module_dir;
extern struct URL_module URL_module_http;
extern struct URL_module URL_module_ftp;
extern struct URL_module URL_module_newsgroup;
extern struct URL_module URL_module_news;
#ifndef __WIN32__
extern struct URL_module URL_module_pipe;
#endif /* __WIN32__ */

void main(int argc, char** argv)
{
    int i;
    URL url;

    url_add_modules(
	&URL_module_file,
	&URL_module_dir,
	&URL_module_http,
	&URL_module_ftp,
	&URL_module_newsgroup,
	&URL_module_news,
#ifndef __WIN32__
	&URL_module_pipe,
#endif /* __WIN32__ */
	NULL);

    for(i = 1; i < argc; i++)
    {
	if((url = url_open(argv[i])) == NULL)
	{
	    fprintf(stderr, "Can't open URL: %s\n", argv[i]);
	    continue;
	}

	if(url->type != URL_dir_t && url->type != URL_newsgroup_t)
	{
	    int c;
	    while((c = url_getc(url)) != EOF)
		putchar(c);
	}
	else
	{
	    char buff[BUFSIZ];
	    while(url_gets(url, buff, sizeof(buff)) != NULL)
		puts(buff);
	}
	url_close(url);
    }
    exit(0);
}
