Ejemplo n.º 1
0
void ReferenceIndex::save(const CL_StringRef &filename)
{
	CL_File index_file(filename, CL_File::create_always, CL_File::access_write);
	CL_String html =
		"<!-- clanlib header begin -->"
		"<HTML>"
		"<HEAD>"
		"<TITLE>Index - ClanLib Game SDK</TITLE>"
		"<STYLE TYPE=\"text/css\"><!--"
		"HTML BODY"
		"{"
		"        font-family: verdana, helvetica, sans-serif;"
		"        font-size: 12px;"
		"}"
		"H1 { font-size: 22px; }"
		"H2 { font-size: 18px; }"
		"H3 { font-size: 16px; }"
		"H4 { font-size: 14px; }"
		"P { font-size: 12px; }"
		"LI { font-size: 12px; }"
		".reflink:link { text-decoration: none; font-weight: bold; color: black; }"
		".reflink:visited { text-decoration: none; font-weight: bold; color: black; }"
		".reflink:active { text-decoration: none; font-weight: bold; color: black; }"
		".reflink:hover { text-decoration: underline; font-weight: bold; color: black; }"
		"--></STYLE>"
		"</HEAD>"
		"<body bgcolor=white text=black link=blue vlink=#800080>"
		"<center>"
		"<img src=\"http://clanlib.org/gfx/clanlib.png\">"
		"</center>"
		"<!-- clanlib header end -->"
		"<center>"
		"<p>"
//		"<a href=\"http://clanlib.org/docs.html\">Home</a> |"
		"<a href=\"classes.html\">All Classes</a> |"
		"<a href=\"modules.html\">Grouped Classes</a> |"
		"<a href=\"index.html\">Index</a>"
//		"<a href=\"search.html\">Search</a>"
		"</p>"
		"</center>"
		"<h1>Index</h1>";
	index_file.write(html.data(), html.length());

	html =
		"<!-- clanlib footer begin -->"
//		"<center><br><br><font color=\"#a0a0a0\">"
//		"Questions or comments, write to the <a href=\"http://clanlib.org/contact.html\">ClanLib mailing list</a>."
//		"</font></center>"
		"<!-- clanlib footer end -->"
		"</body>"
		"</html>";
	index_file.write(html.data(), html.length());
}
Ejemplo n.º 2
0
CL_String CL_File::read_text(const CL_String &filename)
{
    CL_File file(filename);
    CL_String str;
    str.resize(file.get_size());
    file.read(str.data(), str.length());
    file.close();
    return str;
}
Ejemplo n.º 3
0
void ReferenceFunction::save(const CL_StringRef &filename)
{
	CL_File function_file(filename, CL_File::create_always, CL_File::access_write);


	CL_String html = cl_format(
		"<!-- clanlib header begin -->"
		"<HTML>"
		"<HEAD>"
		"<TITLE>%1 - ClanLib Game SDK</TITLE>"
		"<STYLE TYPE=\"text/css\"><!--"
		"HTML BODY"
		"{"
		"        font-family: verdana, helvetica, sans-serif;"
		"        font-size: 12px;"
		"}"
		"H1 { font-size: 22px; }"
		"H2 { font-size: 18px; }"
		"H3 { font-size: 16px; }"
		"H4 { font-size: 14px; }"
		"P { font-size: 12px; }"
		"LI { font-size: 12px; }"
		".reflink:link { text-decoration: none; font-weight: bold; color: black; }"
		".reflink:visited { text-decoration: none; font-weight: bold; color: black; }"
		".reflink:active { text-decoration: none; font-weight: bold; color: black; }"
		".reflink:hover { text-decoration: underline; font-weight: bold; color: black; }"
		"--></STYLE>"
		"</HEAD>"
		"<body bgcolor=white text=black link=blue vlink=#800080>"
		"<center>"
		"<img src=\"http://clanlib.org/gfx/clanlib.png\">"
		"</center>"
		"<!-- clanlib header end -->"
		"<center>"
		"<p>"
//		"<a href=\"http://clanlib.org/docs.html\">Home</a> |"
		"<a href=\"classes.html\">All Classes</a> |"
		"<a href=\"modules.html\">Grouped Classes</a> |"
		"<a href=\"index.html\">Index</a>"
//		"<a href=\"search.html\">Search</a>"
		"</p>"
		"</center>",
		name);
	function_file.write(html.data(), html.length());

	html = cl_format(
		"<h1>Function %1</h1>"
		"<p>%2</p>"
		"<pre>\n"
		"%3\n"
		"</pre>",
		name,
		brief_description,
		declaration);
	function_file.write(html.data(), html.length());
	
	if (!parameters.empty())
	{
		html = "<p><b>Parameters:</b></p>";
		function_file.write(html.data(), html.length());

		for (unsigned int index = 0; index < parameters.size(); index++)
		{
			html = cl_format("<dt><i>%1</i></dt><dd>%2</dd>", parameters[index].name, parameters[index].description);
			function_file.write(html.data(), html.length());
		}
	}
/*
        print FILE "<p><b>Return value:</b></p>\n";
        print FILE "<p>";
        print_description(&addCrossRef($funcretval{$filename}));
        print FILE "</p>\n";
*/

	if (!CL_StringHelp::trim(detailed_description).empty())
	{
		html = cl_format(
			"<p><b>Detailed description:</b></p>"
			"<p>%1</p>",
			detailed_description);
		function_file.write(html.data(), html.length());
        }
/*
	html = cl_format(
		"<p><b>See also:</b></p>"
		"<p><a href=\"%1.html\">%2</a></p>",
		class_name,
		to_filename(class_name));
	function_file.write(html.data(), html.length());
*/
/*
      print FILE "<p><b>See also:</b></p>\n";
      $see_also{$classname} = "<a href=\"$classfilename.html\">$classname</a>";

      my $str;
      my $cur_also;
      foreach $cur_also (keys %see_also)
      {
        $str .= " | " if ($str ne "");
        $str .= $see_also{$cur_also};
      }

      print FILE "<p>$str</p>\n";
*/

	html = 
		"<!-- clanlib footer begin -->"
//		"<center><br><br><font color=\"#a0a0a0\">"
//		"Questions or comments, write to the <a href=\"http://clanlib.org/contact.html\">ClanLib mailing list</a>."
//		"</font></center>"
		"<!-- clanlib footer end -->"
		"</body>"
		"</html>";
	function_file.write(html.data(), html.length());
}
Ejemplo n.º 4
0
CL_Image HTMLPage::load_image(CL_GraphicContext &gc, const CL_String &image_url)
{
	HTMLUrl url(image_url, pageurl);
	CL_Console::write_line("Downloading image: %1", url.to_string());
	CL_String8 request;
	request = cl_format("GET %1 HTTP/1.1\r\n", url.path+url.query);
	request += cl_format("Host: %1\r\nConnection: close\r\nReferer: %2\r\nAccept: image/png, image/jpeg\r\nUser-Agent: CSSTokenize/0.1\r\n\r\n", url.host, pageurl.to_string());

	CL_TCPConnection connection(CL_SocketName(url.host, url.port));
	connection.set_nodelay(true);
	connection.send(request.data(), request.length(), true);

	CL_String response;
	while (connection.get_read_event().wait(15000))
	{
		char buffer[16*1024];
		int received = connection.read(buffer, 16*1024, false);
		if (received == 0)
			break;
		response.append(buffer, received);
	}
	connection.disconnect_graceful();

	CL_String response_header = response.substr(0, response.find("\r\n\r\n"));
	CL_String content = response.substr(response_header.length() + 4);

	if (response_header.find("Transfer-Encoding: chunked") != CL_String::npos)
	{
		CL_String::size_type start = 0;
		while (true)
		{
			CL_String::size_type end = content.find("\r\n", start);
			if (end == CL_String::npos)
				end = content.length();

			CL_String str_length = content.substr(start, end-start);
			int length = CL_StringHelp::text_to_int(str_length, 16);
			content = content.substr(0, start) + content.substr(end+2);
			start += length;


			end = content.find("\r\n", start);
			if (end == CL_String::npos)
				end = content.length();
			content = content.substr(0, start) + content.substr(end+2);

			if (length == 0)
				break;
		}
	}

	CL_DataBuffer buffer(content.data(), content.length());
	CL_IODevice_Memory device(buffer);
	if (response_header.find("image/png") != CL_String::npos)
	{
		CL_PixelBuffer pb = CL_PNGProvider::load(device);
		return CL_Image(gc, pb, pb.get_size());
	}
	else if (response_header.find("image/jpeg") != CL_String::npos)
	{
		CL_PixelBuffer pb = CL_JPEGProvider::load(device);
		return CL_Image(gc, pb, pb.get_size());
	}
	else if (response_header.find("image/gif") != CL_String::npos)
	{
		CL_PixelBuffer pb = GIFProvider::load(device);
		return CL_Image(gc, pb, pb.get_size());
	}
	else
	{
		CL_Console::write_line("Unknown image type: %1", CL_String8(buffer.get_data(), buffer.get_size()));
		return CL_Image();
	}
}