gbranden pushed a commit to branch master in repository groff. commit 99f7e14275a67520c1887e7b72b8ba590fb72c39 Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Wed Jul 30 19:46:01 2025 -0500
[pre-grohtml]: Read "DESC"s more like libgroff. * src/preproc/html/pre-html.cpp (get_resolution, get_image_generator): Read devices' "DESC" files as libgroff does and as documented in groff_font(5) (and CSTR #54 [1992]); upon encountering a "charset" directive, we stop interpreting directives. --- ChangeLog | 8 ++++++++ src/preproc/html/pre-html.cpp | 24 +++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 50102af6b..4558fdd24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2025-07-30 G. Branden Robinson <g.branden.robin...@gmail.com> + + * src/preproc/html/pre-html.cpp (get_resolution) + (get_image_generator): Read devices' "DESC" files as libgroff + does and as documented in groff_font(5) (and CSTR #54 [1992]); + upon encountering a "charset" directive, we stop interpreting + directives. + 2025-07-30 G. Branden Robinson <g.branden.robin...@gmail.com> * src/preproc/html/pre-html.cpp (get_line): Clear heap-allocated diff --git a/src/preproc/html/pre-html.cpp b/src/preproc/html/pre-html.cpp index ebf0953a8..5feab1b29 100644 --- a/src/preproc/html/pre-html.cpp +++ b/src/preproc/html/pre-html.cpp @@ -24,6 +24,7 @@ #endif #include <assert.h> +#include <ctype.h> // isspace() #include <errno.h> #include <stdarg.h> // va_list, va_end(), va_start(), vsnprintf() #include <stdio.h> // EOF, FILE, fclose(), feof(), fflush(), fopen(), @@ -337,12 +338,17 @@ static unsigned int get_resolution(void) f = font_path.open_file(devps_desc, &pathp); if (0 /* nullptr */ == f) fatal("cannot open file '%1': %2", devps_desc, strerror(errno)); - // XXX: We should break out of this loop if we hit a "charset" line. - // "This line and everything following it in the file are ignored." - // (groff_font(5)) int lineno = 0; - while (get_line(f, pathp, lineno++)) + while (get_line(f, pathp, lineno++)) { (void) sscanf(linebuf, "res %u", &res); + // We must stop reading at a "charset" line; see groff_font(5). + if (strncmp(linebuf, "charset", sizeof "charset") == 0) { + // Don't be fooled by non-groff extensions. + char trailing_char = linebuf[(sizeof "charset") - 1]; + if (isspace(trailing_char) || '\0' == trailing_char) + break; + } + } free(pathp); fclose(f); return res; @@ -364,9 +370,6 @@ static char *get_image_generator(void) f = font_path.open_file(devhtml_desc, &pathp); if (0 /* nullptr */ == f) fatal("cannot open file '%1': %2", devhtml_desc, strerror(errno)); - // XXX: We should break out of this loop if we hit a "charset" line. - // "This line and everything following it in the file are ignored." - // (groff_font(5)) int lineno = 0; while (get_line(f, pathp, lineno++)) { char *cursor = linebuf; @@ -384,6 +387,13 @@ static char *get_image_generator(void) continue; generator = cursor; } + // We must stop reading at a "charset" line; see groff_font(5). + if (strncmp(linebuf, "charset", sizeof "charset") == 0) { + // Don't be fooled by non-groff extensions. + char trailing_char = linebuf[(sizeof "charset") - 1]; + if (isspace(trailing_char) || '\0' == trailing_char) + break; + } } free(pathp); fclose(f); _______________________________________________ groff-commit mailing list groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit