inline
void
asuset(
  str_cref spgnam,
  int const& numsgp,
  str_ref pgname,
  int const& msym,
  arr_ref<float, 3> rrsym,
  int& msymp,
  int& mlaue,
  bool const& lprint)
{
  ccp4_ftn_logical lprint_ = lprint;
  asuset_(
    spgnam.elems(),
    &numsgp,
    pgname.elems(),
    &msym,
    rrsym.begin(),
    &msymp,
    &mlaue,
    &lprint_,
    spgnam.len(),
    pgname.len());
}
inline
void
msymlb(
  int const& ist,
  int& lspgrp,
  str_ref namspg,
  str_ref nampg,
  int& nsymp,
  int& nsym,
  arr_ref<float, 3> rot)
{
  msymlb_(
    &ist, &lspgrp, namspg.elems(), nampg.elems(), &nsymp, &nsym, rot.begin(),
    namspg.len(), nampg.len());
}
Beispiel #3
0
static int send_recv(const string& host, int port, str_ref s0, string& d)
{
	Csocket s;
	s.open(SOCK_STREAM, true);
	if (s == -1)
	{
		d += "unable to create socket: " + Csocket::error2a(WSAGetLastError());
		return 1;
	}
	d = (boost::format("server: %s:%d (%s)\r\n") % host % port % Csocket::inet_ntoa(Csocket::get_host(host))).str();
	if (s.connect(Csocket::get_host(host), htons(port)))
	{
		d += "unable to connect: " + Csocket::error2a(WSAGetLastError());
		return 1;
	}
	if (s0.size() != s.send(s0))
	{
		d += "unable to send: " + Csocket::error2a(WSAGetLastError());
		return 1;
	}
	array<char, 4 << 10> d0;
	while (int e = s.recv(d0))
	{
		if (e == SOCKET_ERROR)
		{
			d += "unable to receive: " + Csocket::error2a(WSAGetLastError());
			return 1;
		}
		d.append(d0.data(), e);
	}
	return 0;
}
Beispiel #4
0
std::string encode_text(str_ref v, bool add_quote_class)
{
	std::string r;
	r.reserve(v.size() << 1);
	while (v)
	{
		str_ref line = read_until(v, '\n');
		r += add_quote_class && boost::istarts_with(line, "> ") ? "<span class=quote>" + encode_field(line) + "</span>" : encode_field(line);
		r += "<br>";
	}
	return r;
}
Beispiel #5
0
static std::string web_encode(str_ref v)
{
	std::string d;
	d.reserve(v.size() << 1);
	while (v)
	{
		switch (v.front())
		{
		case '"': 
			d += "&quot;"; 
			break;
		case '&': 
			d += "&amp;"; 
			break;
		case '<':
			d += "&lt;";
			break;
		default:
			d += v.front();
		}
		v.pop_front();
	}
	return d;
}
Beispiel #6
0
std::string encode_field(str_ref v, bool add_br)
{
	std::string r;
	r.reserve(v.size() << 1);
	while (v)
	{
		if (boost::istarts_with(v, "ftp://")
			|| boost::istarts_with(v, "http://")
			|| boost::istarts_with(v, "https://")
			|| boost::istarts_with(v, "mailto:"))
		{
			size_t p = 0;
			while (p < v.size() && !isspace(v[p] & 0xff) && v[p] != '\"' && v[p] != '<' && v[p] != '>' && v[p] != '[' && v[p] != ']')
				p++;
			if (v[p - 1] == '!' || v[p - 1] == ',' || v[p - 1] == '.' || v[p - 1] == '?')
				p--;
			if (v[p - 1] == ')')
				p--;
			str_ref url = v.substr(0, p);
			if (boost::istarts_with(v, "ftp."))
				r += web_link(url, "ftp://" + url.s());
			else if (boost::istarts_with(v, "www."))
				r += web_link(url, "http://" + url.s());
			else
				r += web_link(boost::istarts_with(v, "mailto:") ? url.substr(7) : url, url);
			while (p--)
				v.pop_front();
		}
		else
		{
			switch (v.front())
			{
			case '\n':
				r += add_br ? "<br>" : " ";
				break;
			case '\r':
				break;
			case '&':
				r += "&amp;";
				break;
			case '<':
				r += "&lt;";
				break;
			default:
				r += v.front();
			}
			v.pop_front();
		}
	}
	return r;
}
inline
void
msymlb3(
  int const& ist,
  int& lspgrp,
  str_ref namspg_cif,
  str_ref namspg_cifs,
  str_ref nampg,
  int& nsymp,
  int& nsym,
  arr_ref<float, 3> rlsymmmatrx)
{
  msymlb3_(
    &ist, &lspgrp, namspg_cif.elems(), namspg_cifs.elems(), nampg.elems(),
    &nsymp, &nsym, rlsymmmatrx.begin(),
    namspg_cif.len(), namspg_cifs.len(), nampg.len());
}
Beispiel #8
0
int Cbvalue::write(str_ref s)
{
	return write(s.data(), s.size());
}
Beispiel #9
0
static std::string web_link(str_ref title, str_ref link)
{
	return "<a href=\"" + web_encode(link) + "\">" + web_encode(title.empty() ? link : title) + "</a>";
}
Beispiel #10
0
bb_t get_next(str_ref& s, str_ref& a0)
{
	if (!s)
		return bb_end;
	if (s.front() != '[')
	{
		auto a = std::find(s.begin(), s.end(), '[');
		if (a == s.end())
		{
			a0 = s;
			s.clear();
		}
		else
		{
			a0 = str_ref(s.begin(), a);
			s.set_begin(a);
		}
		return bb_literal;
	}
	auto a = std::find(s.begin(), s.end(), ']');
	if (a == s.end())
	{
		a0 = s;
		s.clear();
		return bb_literal;
	}
	str_ref tag = { &s[1], a };
	s.set_begin(a + 1);
	a0.clear();
	if (tag == "b")
		return bb_bold;
	if (tag == "/b")
		return bb_bold_close;
	if (tag == "center")
		return bb_center;
	if (tag == "/center")
		return bb_center_close;
	if (boost::starts_with(tag, "color="))
	{
		a0 = tag.substr(6);
		return bb_color;
	}
	if (tag == "/color")
		return bb_color_close;
	if (boost::starts_with(tag, "font=") || tag == "/font")
		return bb_none;
	if (tag == "i" || tag == "/i")
		return bb_none;
	if (tag == "img" || tag == "IMG" || tag == "/img" || tag == "/IMG")
		return bb_none;
	if (boost::starts_with(tag, "img="))
	{
		a0 = tag.substr(4);
		return bb_literal;
	}
	if (tag == "q" || tag == "quote")
		return bb_quote;
	if (boost::starts_with(tag, "quote="))
	{
		a0 = tag.substr(6);
		return bb_quote;
	}
	if (tag == "/q" || tag == "/quote")
		return bb_quote_close;
	if (tag == "s")
		return bb_strike;
	if (tag == "/s")
		return bb_strike_close;
	if (boost::starts_with(tag, "size=") || tag == "/size")
		return bb_none;
	if (tag == "u")
		return bb_underline;
	if (tag == "/u")
		return bb_underline_close;
	if (boost::starts_with(tag, "url="))
	{
		a0 = tag.substr(4);
		return bb_url;
	}
	if (tag == "/url")
		return bb_none;
	if (boost::starts_with(tag, "video="))
	{
		a0 = tag.substr(6);
		return bb_video;
	}
	a0 = tag;
	return bb_unknown;
}
Beispiel #11
0
static bool operator==(str_ref a, const char* b)
{
	return a.size() == strlen(b) && !memcmp(a.data(), b, a.size());
}
Beispiel #12
0
int Csocket::sendto(str_ref s, const sockaddr* a, socklen_t cb_a) const
{
	return ::sendto(*this, s.data(), s.size(), MSG_NOSIGNAL, a, cb_a);
}
Beispiel #13
0
int Csocket::send(str_ref s) const
{
	return ::send(*this, s.data(), s.size(), MSG_NOSIGNAL);
}