1
0
mirror of https://github.com/pdewacht/brlaser synced 2025-07-29 03:59:45 +02:00

Be tolerant of zero-page jobs

https://github.com/OpenPrinting/cups-filters/issues/117
This commit is contained in:
Peter De Wachter
2020-04-18 10:58:27 +02:00
parent eae5f9ba98
commit de0d48dfdb
5 changed files with 59 additions and 13 deletions

View File

@ -26,17 +26,18 @@
job::job(FILE *out, const std::string &job_name)
: out_(out),
job_name_(job_name),
page_params_() {
page_params_(),
pages_(0) {
// Delete dubious characters from job name
std::replace_if(job_name_.begin(), job_name_.end(), [](char c) {
return c < 32 || c >= 127 || c == '"' || c == '\\';
}, ' ');
begin_job();
}
job::~job() {
end_job();
if (pages_ != 0) {
end_job();
}
}
void job::begin_job() {
@ -86,6 +87,11 @@ void job::encode_page(const page_params &page_params,
int lines,
int linesize,
nextline_fn nextline) {
if (pages_ == 0) {
begin_job();
}
++pages_;
if (!(page_params_ == page_params)) {
page_params_ = page_params;
write_page_header();

View File

@ -55,6 +55,10 @@ class job {
int linesize,
nextline_fn nextline);
int pages() const {
return pages_;
}
private:
void begin_job();
void end_job();
@ -63,6 +67,7 @@ class job {
FILE *out_;
std::string job_name_;
page_params page_params_;
int pages_;
};
#endif // JOB_H

View File

@ -170,7 +170,6 @@ int main(int argc, char *argv[]) {
return 1;
}
int pages = 0;
{
job job(stdout, ascii_job_name(job_id, job_user, job_name));
cups_page_header2_t header;
@ -179,11 +178,11 @@ int main(int argc, char *argv[]) {
|| header.cupsBitsPerColor != 1
|| header.cupsNumColors != 1
|| 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);
return 1;
}
if (pages == 0) {
if (job.pages() == 0) {
fprintf(stderr, "DEBUG: " PACKAGE ": Page header of first page\n");
dump_page_header(header);
}
@ -191,13 +190,12 @@ int main(int argc, char *argv[]) {
header.cupsHeight,
header.cupsBytesPerLine,
next_line);
fprintf(stderr, "PAGE: %d %d\n", ++pages, header.NumCopies);
fprintf(stderr, "PAGE: %d %d\n", job.pages(), header.NumCopies);
}
}
if (pages == 0) {
fprintf(stderr, "ERROR: " PACKAGE ": No pages were found.\n");
return 1;
if (job.pages() == 0) {
fprintf(stderr, "ERROR: " PACKAGE ": No pages were found.\n");
}
}
fflush(stdout);