示例#1
0
InputSource SourceFromStream(const char8 *description, FILE *file)
{
	FILE16 *file16;

	if(!(file16 = MakeFILE16FromFILE(file, "r")))
	return 0;

	return SourceFromFILE16(description, file16);
}
示例#2
0
InputSource SourceFromStream(const char8 *description, FILE *file)
{
    Entity e;

    e = NewExternalEntity("",0,description,0,0);
    if(!strchr8(description, '/'))
	EntitySetBaseURL(e, default_base_url());
    
    return NewInputSource(e, MakeFILE16FromFILE(file, "r"));
}
示例#3
0
文件: url.c 项目: gap-system/Mixer
static FILE16 *file_open(const char *url,
			 const char *host, int port, const char *path, 
			 const char *type, char **redirected_url)
{
    FILE *f;
    FILE16 *f16;
    const char *p;
    char *file, *q;
    
    file = malloc(strlen(path) + 16 + 1); /* 16 for cygdrive and similar */
    p = path;
    q = file;

#if defined(WIN32) && ! defined(__CYGWIN__)
    /* DOS: if name starts /X: skip the slash */
    if(path[0] == '/'&& ((path[1] && path[2] == ':')||(path[1]=='/'&&path[2]=='/')))
	p++;
#endif

#ifdef __CYGWIN__
    /* Cygwin: translate /c: to /cygdrive/c */

    if(path[0] == '/' && path[1] && path[2] == ':')
    {
	strcpy(q, "/cygdrive/");
	q += strlen(q);
	*q++ = path[1];
	p += 3;
    }
#endif

    for(; *p; p++)
    {
#if defined(WIN32) && ! defined(__CYGWIN__)
	/* DOS: translate slashes */
	if(*p == '/')
	{
	    *q++ = '\\';
	    continue;
	}
#endif

	/* We just convert %-escapes to single characters, which works
	   if the filesystem uses UTF-8.  On the other hand, we pass
	   non-ascii characters through unchanged, which works if the
	   filesystem is Latin-1 (we already lost any characters > 255
	   long ago).  One day we will switch to IRIs, and probably
	   become even more confused.  At least %20 will work. */

	if(*p == '%')
	{
	    int h1, h2;
	    
	    if((h1 = hexval(*++p)) < 0 ||
	       (h2 = hexval(*++p)) < 0)
	    {
		LT_ERROR1(LEFILE, "Error: bad %%-escape in file URL \"%s\"\n",
			  url);
		free(file);
		return 0;
	    }
	    *q++ = h1 * 16 + h2;
	}
	else
	    *q++ = *p;
    }

    *q = 0;

    f = fopen(file, type);
    if(!f)
    {
	perror(file);
	Free(file);
	return 0;
    }

    Free(file);
    
    f16 = MakeFILE16FromFILE(f, type);
    SetCloseUnderlying(f16, 1);

    if(redirected_url)
	*redirected_url = 0;

    return f16;
}