コード例 #1
0
ファイル: page.c プロジェクト: carriercomm/legacy
static
Cimage *
loadimg(Rune *src, int x , int y)
{
	Channel *sync;
	Cimage *ci;
	Runestr rs;
	Exec *e;
	char *filter;
	int fd, p[2], q[2];

	ci = emalloc(sizeof(Cimage));
	rs. r = src;
	rs.nr = runestrlen(rs.r);
	ci->url = urlalloc(&rs, nil, HGet);
	fd = urlopen(ci->url);
	if(fd < 0){
    Err1:
		return ci;
	}
	filter = getfilter(ci->url->ctype.r, x, y);
	if(filter == nil){
		werrstr("%S unsupported: %S", ci->url->ctype.r, ci->url->act.r);
    Err2:
		close(fd);
		goto Err1;
	}

	if(pipe(p)<0 || pipe(q)<0)
		error("can't create pipe");
	close(p[0]);
	p[0] = fd;
	sync = chancreate(sizeof(ulong), 0);
	if(sync == nil)
		error("can't create channel");
	e = emalloc(sizeof(Exec));
	e->p[0] = p[0];
	e->p[1] = p[1];
	e->q[0] = q[0];
	e->q[1] = q[1];
	e->cmd = filter;
	e->sync = sync;
	proccreate(execproc, e, STACK);
	recvul(sync);
	chanfree(sync);
	close(p[0]);
	close(p[1]);
	close(q[1]);

	ci->mi = readmemimage(q[0]);
	close(q[0]);
	if(ci->mi == nil){
		werrstr("can't read image");
		goto Err2;
	}
	free(filter);
	return ci;
}
コード例 #2
0
ファイル: GSistant.cpp プロジェクト: ananthvyas/GSistant
void interpret(char* str)
{
	vector<string> strs;
	string line(str);
	boost::split(strs,line,boost::is_any_of(" "));
	if(strs[0]=="open")
	{
		if(boost::starts_with(strs[1],"http://") || boost::starts_with(strs[1],"www") || boost::ends_with(strs[1],".com"))
			urlopen(strs[1].c_str());
		else
			fileopen((char*)strs[1].c_str());
	}else if(strs[0]=="search")
	{
		string term(strs[1]);
		for(int i=2;i<strs.size();i++)
		{
			term+=string(" ");
			term+=string(strs[i]);
		}
		websearch(term.c_str());
	}else if(strs[0]=="drive")
	{
		std::string s = string(str);
		std::string delimiter = " from ";
		std::string from,to;
		size_t pos = 0;
		std::string token;
		pos = s.find(delimiter);
    	token = s.substr(0, pos);
    	std::cout << token << std::endl;
    	s.erase(0, pos + delimiter.length());
		
		delimiter=" to ";
		while ((pos = s.find(delimiter)) != std::string::npos) {
    		from = s.substr(0, pos);
    		s.erase(0, pos + delimiter.length());
		}
		to=s;
		maps(from.c_str(),to.c_str());
	}
}
コード例 #3
0
ファイル: page.c プロジェクト: carriercomm/legacy
static
void
pageloadproc(void *v)
{
	Page *p;
	char buf[BUFSIZE], *s;
	int32_t n, l;
	int fd, i, ctype;

	threadsetname("pageloadproc");
	rfork(RFFDG);

	p = v;
	addrefresh(p, "opening: %S...", p->url->src.r);
	fd = urlopen(p->url);
	if(fd < 0){
		addrefresh(p, "%S: %r", p->url->src.r);
    Err:
		p->loading = FALSE;
		return;
	}
	if(runestrlen(p->url->ctype.r) == 0) /* assume .html when headers don't say anyting */
		goto Html;

	snprint(buf, sizeof(buf), "%S", p->url->ctype.r);
	for(i=0; mimetab[i]!=nil; i++)
		if(cistrncmp(buf, mimetab[i], strlen(mimetab[i])) == 0)
			break;

	if(mimetab[i]){
    Html:
		ctype = TextHtml;
	}else if(cistrncmp(buf, "text/", 5) == 0)
		ctype = TextPlain;
	else{
		close(fd);
		addrefresh(p, "%S: unsupported mime type: '%S'", p->url->act.r, p->url->ctype.r);
		goto Err;
	}
	addrefresh(p, "loading: %S...", p->url->src.r);
	s = nil;
	l = 0;
	while((n=read(fd, buf, sizeof(buf))) > 0){
		if(p->aborting){
			if(s){
				free(s);
				s = nil;
			}
			break;
		}
		s = erealloc(s, l+n+1);
		memmove(s+l, buf, n);
		l += n;
		s[l] = '\0';
	}
	close(fd);
	n = l;
	if(s){
		s = convert(p->url->ctype, s, &n);
		p->items = parsehtml((uint8_t *)s, n, p->url->act.r, ctype,
				     UTF_8, &p->doc);
		free(s);
		fixtext(p);
		if(ctype==TextHtml && p->aborting==FALSE){
			p->changed = TRUE;
			addrefresh(p, "");
			if(p->doc->doctitle){
				p->title.r = erunestrdup(p->doc->doctitle);
				p->title.nr = runestrlen(p->title.r);
			}
			p->loading = XXX;
			if(p->doc->kidinfo)
				loadchilds(p, p->doc->kidinfo);
			else if(p->doc->images)
				loadimages(p);
		}
	}
	p->changed = TRUE;
	p->loading = FALSE;
	addrefresh(p, "");
}