groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 02/15: [troff]: Clarify file-opening diagnostics.


From: G. Branden Robinson
Subject: [groff] 02/15: [troff]: Clarify file-opening diagnostics.
Date: Wed, 3 Feb 2021 02:58:35 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit 4258aad04d28079fe4d317b8081e7ad9ae8420e6
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Feb 1 17:36:52 2021 +1100

    [troff]: Clarify file-opening diagnostics.
    
    * src/roff/troff/input.cpp (open_mac_file): Report problem when
      attempting to open macro files (-m arguments) and the error is
      something other than ENOENT.
    
      (process_macro_file): Update diagnostic to be more precise; the file
      couldn't be _opened_, not necessarily _found_, and clarify that the
      string being reported back to the user is the argument to the -m
      option, not a file name.
    
      (macro_source): Update diagnostic to report that the file couldn't be
      _opened_, not necessarily _found_, and include the nature of the
      problem.
    
    Also update some comments.
---
 ChangeLog                | 13 +++++++++++++
 src/roff/troff/input.cpp | 18 ++++++++++++------
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c74ba67..6476317 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2021-02-01  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/roff/troff/input.cpp (open_mac_file): Report problem when
+       attempting to open macro files (-m arguments) and the error is
+       something other than ENOENT.
+       (process_macro_file): Update diagnostic to be more precise; the
+       file couldn't be _opened_, not necessarily _found_, and clarify
+       that the string being reported back to the user is the argument
+       to the -m option, not a file name.
+       (macro_source): Update diagnostic to report that the file
+       couldn't be _opened_, not necessarily _found_, and include the
+       nature of the problem.
+
 2021-01-30  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [tbl]: Save and restore hyphenation parameters.
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index cb20e00..02fa02e 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7727,17 +7727,21 @@ static void parse_output_page_list(char *p)
 
 static FILE *open_mac_file(const char *mac, char **path)
 {
-  // Try first FOOBAR.tmac, then tmac.FOOBAR
+  // Try `mac`.tmac first, then tmac.`mac`.  Expect ENOENT errors.
   char *s1 = new char[strlen(mac)+strlen(MACRO_POSTFIX)+1];
   strcpy(s1, mac);
   strcat(s1, MACRO_POSTFIX);
   FILE *fp = mac_path->open_file(s1, path);
+  if (!fp && ENOENT != errno)
+    error("can't open macro file '%1': %2", s1, strerror(errno));
   a_delete s1;
   if (!fp) {
     char *s2 = new char[strlen(mac)+strlen(MACRO_PREFIX)+1];
     strcpy(s2, MACRO_PREFIX);
     strcat(s2, mac);
     fp = mac_path->open_file(s2, path);
+  if (!fp && ENOENT != errno)
+      error("can't open macro file '%1': %2", s2, strerror(errno));
     a_delete s2;
   }
   return fp;
@@ -7748,7 +7752,7 @@ static void process_macro_file(const char *mac)
   char *path;
   FILE *fp = open_mac_file(mac, &path);
   if (!fp)
-    fatal("can't find macro file %1", mac);
+    fatal("unable to open macro file for -m argument '%1'", mac);
   const char *s = symbol(path).contents();
   free(path);
   input_stack::push(new file_iterator(fp, s));
@@ -7781,9 +7785,10 @@ void macro_source()
       tok.next();
     char *path;
     FILE *fp = mac_path->open_file(nm.contents(), &path);
-    // .mso doesn't (and cannot) go through open_mac_file, so we
-    // need to do it here manually: If we have tmac.FOOBAR, try
-    // FOOBAR.tmac and vice versa
+    // .mso cannot go through open_mac_file, which handles the -m option
+    // and expects only an identifier like "s" or "an", not a file name.
+    // We need to do it here manually: If we have tmac.FOOBAR, try
+    // FOOBAR.tmac and vice versa.
     if (!fp) {
       const char *fn = nm.contents();
       size_t fnlen = strlen(fn);
@@ -7810,7 +7815,8 @@ void macro_source()
       free(path);
     }
     else
-      warning(WARN_FILE, "can't find macro file '%1'", nm.contents());
+      warning(WARN_FILE, "can't open macro file '%1': %2",
+             nm.contents(), strerror(errno));
     tok.next();
   }
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]