[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 29/30: [grops]: Improve file-related diagnostics.
From: |
G. Branden Robinson |
Subject: |
[groff] 29/30: [grops]: Improve file-related diagnostics. |
Date: |
Fri, 8 Nov 2024 01:14:32 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 5b56f9b1dac407836a8b652b0ba832983f20f41b
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Nov 7 16:38:41 2024 -0600
[grops]: Improve file-related diagnostics.
* src/devices/grops/ps.cpp (ps_printer::define_encoding):
* src/devices/grops/psrm.cpp (resource_manager::output_prolog)
(resource_manager::supply_resource)
(resource_manager::read_download_file): Align diagnostic message
wording with recent revisions to GNU troff.
* src/devices/grops/ps.cpp (ps_printer::define_encoding): Substantially
improve fatal diagnostic thrown when failing to parse a grops encoding
file, replacing "bad second field" with information a user is more
likely to be able to act on.
Also wrap long source line.
Exhibit:
Let's say we have a text.enc file that is damaged like this.
-Scaron 2
+Scaron AA
Before:
$ echo x | groff -F ./font > /dev/null
grops:./font/devps/text.enc:7: fatal error: bad second field
Now:
$ echo foo | ./build/test-groff -F ./font > /dev/null
grops:./font/devps/text.enc:7: fatal error: invalid encoding file: expected
integer in range 0-255 as second word on line, got 'AA'
Lengthy, yes, but much more helpful to the user.
---
ChangeLog | 13 +++++++++++++
src/devices/grops/ps.cpp | 9 ++++++---
src/devices/grops/psrm.cpp | 12 ++++++------
3 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7137bbd3f..70e5e7f7c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-11-07 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/devices/grops/ps.cpp (ps_printer::define_encoding):
+ * src/devices/grops/psrm.cpp (resource_manager::output_prolog)
+ (resource_manager::supply_resource)
+ (resource_manager::read_download_file): Align diagnostic message
+ wording with recent revisions to GNU troff.
+
+ * src/devices/grops/ps.cpp (ps_printer::define_encoding):
+ Substantially improve fatal diagnostic thrown when failing to
+ parse a grops encoding file, replacing "bad second field" with
+ information a user is more likely to be able to act on.
+
2024-11-07 G. Branden Robinson <g.branden.robinson@gmail.com>
* tmac/cs.tmac:
diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp
index 65fd5e953..7cdf24e6f 100644
--- a/src/devices/grops/ps.cpp
+++ b/src/devices/grops/ps.cpp
@@ -782,7 +782,8 @@ static char *make_subencoding_name(int subencoding_index)
const char *const WS = " \t\n\r";
-void ps_printer::define_encoding(const char *encoding, int encoding_index)
+void ps_printer::define_encoding(const char *encoding,
+ int encoding_index)
{
char *vec[256];
int i;
@@ -795,7 +796,7 @@ void ps_printer::define_encoding(const char *encoding, int
encoding_index)
if (errno <= 0)
fatal("refusing to traverse directories to open PostScript"
" encoding file '%1'");
- fatal("can't open encoding file '%1'", encoding);
+ fatal("cannot open encoding file '%1'", encoding);
}
int lineno = 1;
const int BUFFER_SIZE = 512;
@@ -808,7 +809,9 @@ void ps_printer::define_encoding(const char *encoding, int
encoding_index)
char *q = strtok(0, WS);
int n = 0; // pacify compiler
if (q == 0 || sscanf(q, "%d", &n) != 1 || n < 0 || n >= 256)
- fatal_with_file_and_line(path, lineno, "bad second field");
+ fatal_with_file_and_line(path, lineno, "invalid encoding file:"
+ " expected integer in range 0-255 as second word on line,"
+ " got '%1'", q);
vec[n] = new char[strlen(p) + 1];
strcpy(vec[n], p);
}
diff --git a/src/devices/grops/psrm.cpp b/src/devices/grops/psrm.cpp
index dcd061824..f939d1e6d 100644
--- a/src/devices/grops/psrm.cpp
+++ b/src/devices/grops/psrm.cpp
@@ -290,7 +290,7 @@ void resource_manager::output_prolog(ps_output &out)
e += GROPS_PROLOGUE;
e += '\0';
if (putenv(strsave(e.contents())))
- fatal("unable to update environment: %1", strerror(errno));
+ fatal("cannot update environment: %1", strerror(errno));
}
char *prologue = getenv("GROPS_PROLOGUE");
FILE *fp = font::open_file(prologue, &path);
@@ -299,7 +299,7 @@ void resource_manager::output_prolog(ps_output &out)
if (errno <= 0)
fatal("refusing to traverse directories to open PostScript"
" prologue file '%1'");
- fatal("unable to open PostScript prologue file '%1': %2", prologue,
+ fatal("cannot open PostScript prologue file '%1': %2", prologue,
strerror(errno));
}
fputs("%%BeginResource: ", outfp);
@@ -342,7 +342,7 @@ void resource_manager::supply_resource(resource *r, int
rank,
error("refusing to traverse directories to open PostScript"
" resource file '%1'");
else
- error("unable to open PostScript resource file '%1': %2",
+ error("cannot open PostScript font file '%1': %2",
r->filename, strerror(errno));
delete[] r->filename;
r->filename = 0 /* nullptr */;
@@ -351,8 +351,8 @@ void resource_manager::supply_resource(resource *r, int
rank,
else {
fp = include_search_path.open_file_cautious(r->filename);
if (0 /* nullptr */ == fp) {
- error("unable to open file '%1': %2", r->filename,
- strerror(errno));
+ error("cannot open PostScript resource file '%1': %2",
+ r->filename, strerror(errno));
delete[] r->filename;
r->filename = 0 /* nullptr */;
}
@@ -1069,7 +1069,7 @@ void resource_manager::read_download_file()
char *path = 0 /* nullptr */;
FILE *fp = font::open_file("download", &path);
if (0 /* nullptr */ == fp)
- fatal("unable to open 'download' file: %1", strerror(errno));
+ fatal("cannot open 'download' file: %1", strerror(errno));
char buf[512];
int lineno = 0;
while (fgets(buf, sizeof buf, fp)) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 29/30: [grops]: Improve file-related diagnostics.,
G. Branden Robinson <=