Skip to content

Commit

Permalink
Increase compatibility
Browse files Browse the repository at this point in the history
GCC 10, BSD
  • Loading branch information
attah committed Nov 25, 2024
1 parent 678b1ff commit 66be1ce
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ hexdump: bytestream.o hexdump.o
$(CXX) $^ $(LDFLAGS) -o $@

baselinify: bytestream.o baselinify.o baselinify_main.o
$(CXX) $^ -ljpeg $(LDFLAGS) -o $@
$(CXX) $^ $(shell pkg-config --libs libjpeg) $(LDFLAGS) -o $@

baselinify_mad: bytestream.o baselinify_mad.o baselinify_main.o
$(CXX) $^ -ldl -o $@
Expand All @@ -56,7 +56,7 @@ bsplit: bytestream.o bsplit.o
$(CXX) $^ $(LDFLAGS) -o $@

ippclient: ippmsg.o ippattr.o ippprinter.o ippprintjob.o printparameters.o ippclient.o json11.o curlrequester.o minimime.o pdf2printable.o ppm2pwg.o baselinify.o bytestream.o
$(CXX) $^ $(shell pkg-config --libs poppler-glib) -ljpeg -lcurl -lz -lpthread $(LDFLAGS) -o $@
$(CXX) $^ $(shell pkg-config --libs poppler-glib) $(shell pkg-config --libs libjpeg) -lcurl -lz -lpthread $(LDFLAGS) -o $@

minimime: minimime_main.o minimime.o bytestream.o
$(CXX) $^ $(LDFLAGS) -o $@
Expand Down
2 changes: 1 addition & 1 deletion bytestream
2 changes: 1 addition & 1 deletion lib/ippprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Error IppPrinter::refresh()
Bytestream bts(ifs);
try
{
if(bts.peek<char>() == '{')
if(bts.peek<int8_t>() == '{')
{
std::string errStr;
Json json = Json::parse(bts.getString(bts.size()), errStr);
Expand Down
20 changes: 16 additions & 4 deletions lib/printparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,28 @@ bool PrintParameters::setPageRange(const std::string& rangeStr)
return !pageRangeList.empty();
}

double from_string(std::string str)
{
size_t dotAt = str.find(".");
double res = std::stoul(str.substr(0, dotAt));
if(dotAt != std::string::npos)
{
std::string decimalString = str.substr(dotAt+1);
res += (std::stoul(decimalString) / (pow(10, decimalString.length())));
}
return res;
}

bool PrintParameters::setPaperSize(const std::string& sizeStr)
{
const std::regex nameRegex("^[0-9a-z_-]+_([0-9]+([.][0-9]+)?)x([0-9]+([.][0-9]+)?)(mm|in)$");
std::cmatch match;
std::smatch match;

if(std::regex_match(sizeStr.c_str(), match, nameRegex))
if(std::regex_match(sizeStr, match, nameRegex))
{
paperSizeName = sizeStr;
std::from_chars(match[1].first, match[1].second, paperSizeW);
std::from_chars(match[3].first, match[3].second, paperSizeH);
paperSizeW = from_string(match[1]);
paperSizeH = from_string(match[3]);
if(match[5] == "in")
{
paperSizeUnits = Inches;
Expand Down
4 changes: 2 additions & 2 deletions tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,8 @@ TEST(silly_locale_parse_page_size)

ASSERT(params.setPaperSize("fuuuuu_13.37x42.69mm"));
ASSERT(params.paperSizeName == "fuuuuu_13.37x42.69mm");
ASSERT(params.paperSizeW == 13.37);
ASSERT(params.paperSizeH == 42.69);
ASSERT((double)params.paperSizeW == (double)13.37);
ASSERT((float)params.paperSizeH == (float)42.69);
ASSERT(params.paperSizeUnits == PrintParameters::Millimeters);

std::setlocale(LC_ALL, locale.c_str());
Expand Down

0 comments on commit 66be1ce

Please sign in to comment.