Beispiel #1
0
static std::string sides(const std::string_view &v)
{
	if (v == CUPS_SIDES_ONE_SIDED)
		return _("Off");
	if (v == CUPS_SIDES_TWO_SIDED_PORTRAIT)
		return _("Duplex (Long Edge)");
	if (v == CUPS_SIDES_TWO_SIDED_LANDSCAPE)
		return _("Duplex (Short Edge)");
	return {v.begin(), v.end()};
}
Beispiel #2
0
static std::string print_color_mode(const std::string_view &v)
{
	if (v == CUPS_PRINT_COLOR_MODE_AUTO)
		return _("Automatic");
	if (v == CUPS_PRINT_COLOR_MODE_MONOCHROME)
		return _("Monochrome");
	if (v == CUPS_PRINT_COLOR_MODE_COLOR)
		return _("Color");
	return {v.begin(), v.end()};
}
Beispiel #3
0
void job_implObj::set_option(const std::string_view &name,
			     const std::string_view &value)
{
	size_t s=name.size();

	char name_str[s+1];

	std::copy(name.begin(), name.end(), name_str);
	name_str[s]=0;

	s=value.size();
	char value_str[s+1];

	std::copy(value.begin(), value.end(), value_str);
	value_str[s]=0;

	job_info_t::lock lock{job_info};

	lock->num_options=cupsAddOption(name_str, value_str,
					lock->num_options,
					&lock->options);
}
Beispiel #4
0
bool destination_implObj::supported(const std::string_view &option,
				    const std::string_view &value) const
{
	auto s=option.size();

	char option_s[s+1];

	std::copy(option.begin(), option.end(), option_s);
	option_s[s]=0;

	s=value.size();

	char value_s[s+1];
	std::copy(value.begin(), value.end(), value_s);
	value_s[s]=0;

	info_t::lock lock{*this};

	return !!cupsCheckDestSupported(lock->http,
					lock->dest,
					lock->info,
					option_s,
					value_s);
}
Beispiel #5
0
option_values_t
destination_implObj::ready_option_values(const std::string_view &option)
	const
{
	auto s=option.size();

	char option_s[s+1];

	std::copy(option.begin(), option.end(), option_s);
	option_s[s]=0;

	auto[name, unicode_flag]=parse_unicode_option(option_s);
	info_t::lock lock{*this};

	auto attrs=cupsFindDestReady(lock->http, lock->dest,
				     lock->info,
				     name);

	return parse_attribute_values(lock, attrs, name, unicode_flag);
}
Beispiel #6
0
int job_implObj::submit(const std::string_view &title)
{
	size_t s=title.size();

	char title_str[s+1];

	std::copy(title.begin(), title.end(), title_str);
	title_str[s]=0;

	job_info_t::lock job_lock{job_info};

	if (job_lock->documents.empty())
		return 0;

	destination_implObj::info_t::lock lock{*destination};

	int job_id;

	auto status=cupsCreateDestJob(lock->http,
				      lock->dest,
				      lock->info,
				      &job_id,
				      title_str,
				      job_lock->num_options,
				      job_lock->options);

	if (status != IPP_STATUS_OK)
		throw EXCEPTION(ippErrorString(status));

	auto job_sentry=make_sentry([&]
				    {
					    cupsCancelDestJob(lock->http,
							      lock->dest,
							      job_id);
				    });

	job_sentry.guard();

	for (const auto &doc:job_lock->documents)
	{
		auto [mime_type, contents]=doc.document();

		auto status=cupsStartDestDocument(lock->http,
						  lock->dest, lock->info,
						  job_id,
						  doc.name.c_str(),
						  mime_type.c_str(),
						  0, NULL, 0);
		if (status != HTTP_STATUS_CONTINUE)
			throw EXCEPTION(httpStatus(status));

		auto doc_sentry=make_sentry
			([&]
			 {
				 cupsFinishDestDocument(lock->http,
							lock->dest,
							lock->info);
			 });
		doc_sentry.guard();

		while (auto res=contents())
		{
			status=cupsWriteRequestData(lock->http,
						    res->data(),
						    res->size());

			if (status != HTTP_STATUS_CONTINUE)
				throw EXCEPTION(httpStatus(status));
		}
		doc_sentry.unguard();

		auto ipp_status=cupsFinishDestDocument(lock->http,
						       lock->dest,
						       lock->info);

		if (ipp_status != IPP_STATUS_OK)
			throw EXCEPTION(cupsLastErrorString());
	}

	job_sentry.unguard();

	auto ipp_status=cupsCloseDestJob(lock->http,
					 lock->dest,
					 lock->info,
					 job_id);

	if (ipp_status != IPP_STATUS_OK)
		throw EXCEPTION(cupsLastErrorString());
	return job_id;
}
Beispiel #7
0
		void log(ELoggingLevel lvl, std::string_view str, T&&... args) const
		{
			constexpr int index[]{-1, 1, 2, 3};
			std::cregex_token_iterator begin{str.begin(), str.end(), regex(), index}, end;
			std::ostringstream stream;
			while(begin != end)
			{
				unsigned position = -1U;
				int alignment = 0;
				char format = 0;
				int width = 0;
				for(int i : index)
				{
					if(begin == end)
						break;

					auto cm = *begin++;

					if(!cm.matched)
						continue;

					switch(i)
					{
					case -1:
						stream.write(cm.first, cm.length());
						break;

					case 1:
						position = number<unsigned>(cm.first, cm.second);
						break;

					case 2:
						alignment = number<int>(cm.first + 1, cm.second);
						break;

					case 3:
						format = cm.first[1];
						width = number<int>(cm.first + 2, cm.second);
						break;
					}
				}

				if(position < 10)
				{
					util::parameter_pack::at
					(
						position,
						[&stream, alignment, format, width](auto&& object)
						{
							auto&& str = print(format, width, std::forward<decltype(object)>(object));

							if(alignment > 0)
								stream << std::setw(alignment - int(str.tellp())) << "";

							stream << str.rdbuf();

							if(alignment < 0)
								stream << std::setw(-alignment - int(str.tellp())) << "";
						},
						std::forward<T>(args)...
					);
				}
			}

			this->log(lvl, stream.str().c_str());
		}
std::optional<int> CSeqConversionDefault::GetNextInteger(std::string_view &sv, bool Signed) const
{
	re::svmatch m;

	if (m_bHex) {
		static const std::regex HEX_RE {R"(^([\+-]?)[0-9A-Fa-f]+)", std::regex_constants::optimize};
		if (std::regex_search(sv.begin(), sv.end(), m, HEX_RE))
			if (!(Signed && !m[1].length()))
				if (auto val = conv::to_int(re::sv_from_submatch(m[0]), 16)) {
					sv.remove_prefix(std::distance(sv.begin(), m.suffix().first));
					return val;
				}
	}
	else {
		static const std::regex NUMBER_RE {R"(^([\+-]?)[0-9]+)", std::regex_constants::optimize};
		static const std::regex HEX_PREFIX_RE {R"(^([\+-]?)[\$x]([0-9A-Fa-f]+))", std::regex_constants::optimize}; // do not allow 0x prefix
		if (std::regex_search(sv.begin(), sv.end(), m, HEX_PREFIX_RE)) {
			if (!(Signed && !m[1].length()))
				if (auto val = conv::to_int(re::sv_from_submatch(m[2]), 16)) {
					if (m[1] == "-")
						*val = -*val;
					sv.remove_prefix(std::distance(sv.begin(), m.suffix().first));
					return val;
				}
		}
		else if (std::regex_search(sv.begin(), sv.end(), m, NUMBER_RE)) {
			if (!(Signed && !m[1].length()))
				if (auto val = conv::to_int(re::sv_from_submatch(m[0]))) {
					sv.remove_prefix(std::distance(sv.begin(), m.suffix().first));
					return val;
				}
		}
	}

	return std::nullopt;
}

std::optional<int> CSeqConversionDefault::GetNextTerm(std::string_view &sv)
{
	return GetNextInteger(sv);
}



std::string CSeqConversion5B::ToString(char Value) const
{
	std::string Str = std::to_string(Value & 0x1F);
	uint8_t m = (uint8_t)Value & 0xE0;
	if ((m & value_cast(s5b_mode_t::Square)) == value_cast(s5b_mode_t::Square))
		Str.push_back('t');
	if ((m & value_cast(s5b_mode_t::Noise)) == value_cast(s5b_mode_t::Noise))
		Str.push_back('n');
	if ((m & value_cast(s5b_mode_t::Envelope)) == value_cast(s5b_mode_t::Envelope))
		Str.push_back('e');
//	auto m = enum_cast<s5b_mode_t>((unsigned char)Value);
//	if ((m & s5b_mode_t::Square) == s5b_mode_t::Square)
//		Str.push_back('t');
//	if ((m & s5b_mode_t::Noise) == s5b_mode_t::Noise)
//		Str.push_back('n');
//	if ((m & s5b_mode_t::Envelope) == s5b_mode_t::Envelope)
//		Str.push_back('e');
	return Str;
}

bool CSeqConversion5B::ToValue(std::string_view sv)
{
	m_iEnableFlags = -1;
	return CSeqConversionDefault::ToValue(sv);
}

char CSeqConversion5B::GetValue()
{
	return CSeqConversionDefault::GetValue() | m_iEnableFlags;
}

std::optional<int> CSeqConversion5B::GetNextTerm(std::string_view &sv)
{
	if (auto o = GetNextInteger(sv)) {
		static const std::regex S5B_FLAGS_RE {R"(^[TtNnEe]*)", std::regex_constants::optimize};
		if (re::svmatch m; std::regex_search(sv.begin(), sv.end(), m, S5B_FLAGS_RE)) {
			if (m_iEnableFlags == -1) {
				m_iEnableFlags = 0;
				auto flags = re::sv_from_submatch(m[0]);
				if (flags.find_first_of("Tt") != std::string::npos)
					m_iEnableFlags |= value_cast(s5b_mode_t::Square);
				if (flags.find_first_of("Nn") != std::string::npos)
					m_iEnableFlags |= value_cast(s5b_mode_t::Noise);
				if (flags.find_first_of("Ee") != std::string::npos)
					m_iEnableFlags |= value_cast(s5b_mode_t::Envelope);
			}
			sv.remove_prefix(std::distance(sv.begin(), m.suffix().first));
		}
Beispiel #9
0
static std::string no_localizer(const std::string_view &v)
{
	return {v.begin(), v.end()};
}
inline int parseInt( std::string_view input, int fallback ){
	int value = 0;
	auto result = std::from_chars( input.begin(), input.end(), value, 10 );
	return result.ptr == input.begin() ? fallback : value;
}