mirror of
https://github.com/pdewacht/brlaser
synced 2024-12-27 07:48:21 +01:00
Be tolerant of zero-page jobs
https://github.com/OpenPrinting/cups-filters/issues/117
This commit is contained in:
parent
eae5f9ba98
commit
de0d48dfdb
@ -116,15 +116,17 @@ add_executable(brdecode EXCLUDE_FROM_ALL src/brdecode.cc)
|
|||||||
add_executable(test_lest test/test_lest.cc)
|
add_executable(test_lest test/test_lest.cc)
|
||||||
add_executable(test_line test/test_line.cc src/line.cc)
|
add_executable(test_line test/test_line.cc src/line.cc)
|
||||||
add_executable(test_block test/test_block.cc)
|
add_executable(test_block test/test_block.cc)
|
||||||
|
add_executable(test_job test/test_job.cc src/job.cc src/line.cc)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_test(test_lest test_lest)
|
add_test(test_lest test_lest)
|
||||||
add_test(test_line test_line)
|
add_test(test_line test_line)
|
||||||
add_test(test_block test_block)
|
add_test(test_block test_block)
|
||||||
|
add_test(test_job test_job)
|
||||||
|
|
||||||
# Autotools-style "make check" command
|
# Autotools-style "make check" command
|
||||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
|
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
|
||||||
add_dependencies(check test_lest test_line test_block)
|
add_dependencies(check test_lest test_line test_block test_job)
|
||||||
|
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
12
src/job.cc
12
src/job.cc
@ -26,18 +26,19 @@
|
|||||||
job::job(FILE *out, const std::string &job_name)
|
job::job(FILE *out, const std::string &job_name)
|
||||||
: out_(out),
|
: out_(out),
|
||||||
job_name_(job_name),
|
job_name_(job_name),
|
||||||
page_params_() {
|
page_params_(),
|
||||||
|
pages_(0) {
|
||||||
// Delete dubious characters from job name
|
// Delete dubious characters from job name
|
||||||
std::replace_if(job_name_.begin(), job_name_.end(), [](char c) {
|
std::replace_if(job_name_.begin(), job_name_.end(), [](char c) {
|
||||||
return c < 32 || c >= 127 || c == '"' || c == '\\';
|
return c < 32 || c >= 127 || c == '"' || c == '\\';
|
||||||
}, ' ');
|
}, ' ');
|
||||||
|
|
||||||
begin_job();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
job::~job() {
|
job::~job() {
|
||||||
|
if (pages_ != 0) {
|
||||||
end_job();
|
end_job();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void job::begin_job() {
|
void job::begin_job() {
|
||||||
for (int i = 0; i < 128; ++i) {
|
for (int i = 0; i < 128; ++i) {
|
||||||
@ -86,6 +87,11 @@ void job::encode_page(const page_params &page_params,
|
|||||||
int lines,
|
int lines,
|
||||||
int linesize,
|
int linesize,
|
||||||
nextline_fn nextline) {
|
nextline_fn nextline) {
|
||||||
|
if (pages_ == 0) {
|
||||||
|
begin_job();
|
||||||
|
}
|
||||||
|
++pages_;
|
||||||
|
|
||||||
if (!(page_params_ == page_params)) {
|
if (!(page_params_ == page_params)) {
|
||||||
page_params_ = page_params;
|
page_params_ = page_params;
|
||||||
write_page_header();
|
write_page_header();
|
||||||
|
@ -55,6 +55,10 @@ class job {
|
|||||||
int linesize,
|
int linesize,
|
||||||
nextline_fn nextline);
|
nextline_fn nextline);
|
||||||
|
|
||||||
|
int pages() const {
|
||||||
|
return pages_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void begin_job();
|
void begin_job();
|
||||||
void end_job();
|
void end_job();
|
||||||
@ -63,6 +67,7 @@ class job {
|
|||||||
FILE *out_;
|
FILE *out_;
|
||||||
std::string job_name_;
|
std::string job_name_;
|
||||||
page_params page_params_;
|
page_params page_params_;
|
||||||
|
int pages_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // JOB_H
|
#endif // JOB_H
|
||||||
|
12
src/main.cc
12
src/main.cc
@ -170,7 +170,6 @@ int main(int argc, char *argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pages = 0;
|
|
||||||
{
|
{
|
||||||
job job(stdout, ascii_job_name(job_id, job_user, job_name));
|
job job(stdout, ascii_job_name(job_id, job_user, job_name));
|
||||||
cups_page_header2_t header;
|
cups_page_header2_t header;
|
||||||
@ -179,11 +178,11 @@ int main(int argc, char *argv[]) {
|
|||||||
|| header.cupsBitsPerColor != 1
|
|| header.cupsBitsPerColor != 1
|
||||||
|| header.cupsNumColors != 1
|
|| header.cupsNumColors != 1
|
||||||
|| header.cupsBytesPerLine > 10000) {
|
|| header.cupsBytesPerLine > 10000) {
|
||||||
fprintf(stderr, "ERROR: " PACKAGE ": Page %d: Bogus raster data.\n", pages + 1);
|
fprintf(stderr, "ERROR: " PACKAGE ": Page %d: Bogus raster data.\n", job.pages() + 1);
|
||||||
dump_page_header(header);
|
dump_page_header(header);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (pages == 0) {
|
if (job.pages() == 0) {
|
||||||
fprintf(stderr, "DEBUG: " PACKAGE ": Page header of first page\n");
|
fprintf(stderr, "DEBUG: " PACKAGE ": Page header of first page\n");
|
||||||
dump_page_header(header);
|
dump_page_header(header);
|
||||||
}
|
}
|
||||||
@ -191,13 +190,12 @@ int main(int argc, char *argv[]) {
|
|||||||
header.cupsHeight,
|
header.cupsHeight,
|
||||||
header.cupsBytesPerLine,
|
header.cupsBytesPerLine,
|
||||||
next_line);
|
next_line);
|
||||||
fprintf(stderr, "PAGE: %d %d\n", ++pages, header.NumCopies);
|
fprintf(stderr, "PAGE: %d %d\n", job.pages(), header.NumCopies);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pages == 0) {
|
if (job.pages() == 0) {
|
||||||
fprintf(stderr, "ERROR: " PACKAGE ": No pages were found.\n");
|
fprintf(stderr, "ERROR: " PACKAGE ": No pages were found.\n");
|
||||||
return 1;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
35
test/test_job.cc
Normal file
35
test/test_job.cc
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// This file is part of the brlaser printer driver.
|
||||||
|
//
|
||||||
|
// Copyright 2020 Peter De Wachter
|
||||||
|
//
|
||||||
|
// brlaser is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 2 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// brlaser is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with brlaser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "lest.hpp"
|
||||||
|
#include "tempfile.h"
|
||||||
|
#include "../src/job.h"
|
||||||
|
|
||||||
|
const lest::test specification[] = {
|
||||||
|
"An empty job produces no output",
|
||||||
|
[] {
|
||||||
|
tempfile f;
|
||||||
|
{
|
||||||
|
job j(f.file(), "name");
|
||||||
|
}
|
||||||
|
EXPECT(f.data().empty());
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
return lest::run(specification);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user