% parse-selector.c-nw
% Bert Bos <bert@let.rug.nl>
% 21 Feb '94

	Parse Goper selector strings

	[[URL_parse_selector()]] parses a Gopher selector string. The
	path part of a URL looks like 00/path/file. The type is `0'
	and the path is `0/path/file'. Arguments are: [[selector]] =
	the `path' part of the URL; [[type]] = pointer to a character
	in which the type will be stored; [[path]] = returns pointer
	to the Gopher selector proper (allocated on the heap)

<<*>>=
#include <config.h>
#include <export.h>
#include <str.h>
#include "unescape.e"

EXPORT int URL_parse_selector(char *selector, char *type, char **path)
{
    if (!selector || selector[0] == '\0') {
	*type = '1';
	*path = "/";
	return 1;
    }
    if (selector[0] != '/') {
	return 0;				/* Incorrect selector */
    }
    if (selector[1] == '\0') {
	*type = '1';
	*path = "/";
	return 1;
    }
    *type = selector[1];
    *path = URL_unescape(newstring(selector + 2));
    return 1;
}
