コード例 #1
0
/* this is a HACK */
Rune*
urlcombine(Rune *b, Rune *u)
{
	Rune *p, *q, *sep, *s;
	Rune endrune[] = { L'?', L'#' };
	int i, restore;

	if(u == nil)
		error("urlcombine: u == nil");

	if(validurl(u))
		return erunestrdup(u);

	if(b==nil || !validurl(b))
		error("urlcombine: b==nil || !validurl(b)");

	if(runestrncmp(u, L"//", 2) == 0){
		q =  runestrchr(b, L':');
		return runesmprint("%.*S:%S", (int)(q-b), b, u);
	}
	p = runestrstr(b, L"://");
	if(p != nil)
		p += 3;
	sep = L"";
	q = nil;
	if(*u ==L'/')
		q = runestrchr(p, L'/');
	else if(*u==L'#' || *u==L'?'){
		for(i=0; i<nelem(endrune); i++)
			if(q = runestrchr(p, endrune[i]))
				break;
	}else if(p != nil){
		sep = L"/";
		restore = 0;
		s = runestrchr(p, L'?');
		if(s != nil){
			*s = '\0';
			restore = 1;
		}
		q = runestrrchr(p, L'/');
		if(restore)
			*s = L'?';
	}else
		sep = L"/";
	if(q == nil)
		p = runesmprint("%S%S%S", b, sep, u);
	else
		p = runesmprint("%.*S%S%S", (int)(q-b), b, sep, u);
	urlcanon(p);
	return p;
}
コード例 #2
0
void
addhttp(Url *u)
{
	Rune *s;
	if(validurl(u->src.r))
		return;
	s = u->src.r;
	u->src.r = runesmprint("http://%S", u->src.r);
	free(s);
	u->src.nr = runestrlen(u->src.r);
}
コード例 #3
0
// tired of typing http://, tired of going to google first.
void
justgoogleit(Url *u)
{
	Rune *s;
	
	s = ucvt(u->src.r+2);
	free(u->src.r);
	u->src.r = runesmprint("http://www.google.com/search?hl=en&ie=UTF-8&q=%S", s);
	free(s);
	u->src.nr = runestrlen(u->src.r);
}
コード例 #4
0
static Runestr
getattr(int conn, char *s)
{
	char buf[BUFSIZE];
	int fd, n;

	n = 0;
	snprint(buf, sizeof buf, "%s/%d/%s", webmountpt, conn, s);
	if((fd = open(buf, OREAD)) >= 0){
		if((n = read(fd, buf, sizeof(buf)-1)) < 0)
			n = 0;
		close(fd);
	}
	buf[n] = '\0';
	return (Runestr){runesmprint("%s", buf), n};
}
コード例 #5
0
ファイル: urls.c プロジェクト: 99years/plan9
static
Runestr
getattr(int conn, char *s)
{
	char buf[BUFSIZE];
	int fd, n;

	snprint(buf, sizeof(buf), "%s/%d/%s", webmountpt, conn, s);
	fd = open(buf, OREAD);
	if(fd < 0)
		error("can't open attr file");

	n = read(fd, buf, sizeof(buf)-1);
	if(n < 0)
		error("can't read");

	close(fd);
	buf[n] = '\0';
	return (Runestr){runesmprint("%s", buf), n};
}
コード例 #6
0
ファイル: text.c プロジェクト: carriercomm/plan9-gpl
Rune*
textcomplete(Text *t)
{
	int i, nstr, npath;
	uint q;
	Rune tmp[200];
	Rune *str, *path;
	Rune *rp;
	Completion *c;
	char *s, *dirs;
	Runestr dir;

	/* control-f: filename completion; works back to white space or / */
	if(t->q0<t->file->nc && textreadc(t, t->q0)>' ')	/* must be at end of word */
		return nil;
	nstr = textfilewidth(t, t->q0, TRUE);
	str = runemalloc(nstr);
	npath = textfilewidth(t, t->q0-nstr, FALSE);
	path = runemalloc(npath);

	c = nil;
	rp = nil;
	dirs = nil;

	q = t->q0-nstr;
	for(i=0; i<nstr; i++)
		str[i] = textreadc(t, q++);
	q = t->q0-nstr-npath;
	for(i=0; i<npath; i++)
		path[i] = textreadc(t, q++);
	/* is path rooted? if not, we need to make it relative to window path */
	if(npath>0 && path[0]=='/')
		dir = (Runestr){path, npath};
	else{
		dir = dirname(t, nil, 0);
		if(dir.nr + 1 + npath > nelem(tmp)){
			free(dir.r);
			goto Return;
		}
		if(dir.nr == 0){
			dir.nr = 1;
			dir.r = runestrdup(L".");
		}
		runemove(tmp, dir.r, dir.nr);
		tmp[dir.nr] = '/';
		runemove(tmp+dir.nr+1, path, npath);
		free(dir.r);
		dir.r = tmp;
		dir.nr += 1+npath;
		dir = cleanrname(dir);
	}

	s = smprint("%.*S", nstr, str);
	dirs = smprint("%.*S", dir.nr, dir.r);
	c = complete(dirs, s);
	free(s);
	if(c == nil){
		warning(nil, "error attempting completion: %r\n");
		goto Return;
	}

	if(!c->advance){
		warning(nil, "%.*S%s%.*S*%s\n",
			dir.nr, dir.r,
			dir.nr>0 && dir.r[dir.nr-1]!='/' ? "/" : "",
			nstr, str,
			c->nmatch? "" : ": no matches in:");
		for(i=0; i<c->nfile; i++)
			warning(nil, " %s\n", c->filename[i]);
	}

	if(c->advance)
		rp = runesmprint("%s", c->string);
	else
		rp = nil;
  Return:
	freecompletion(c);
	free(dirs);
	free(str);
	free(path);
	return rp;
}