bug-ncurses
[Top][All Lists]
Advanced

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

[PATCH] infocmp: Distinguish failure cases when looking up terminal type


From: G. Branden Robinson
Subject: [PATCH] infocmp: Distinguish failure cases when looking up terminal type entries.
Date: Sat, 28 Sep 2024 12:06:04 -0500

* progs/infocmp.c (main): Distinguish failure mode TGETENT_ERR from
  TGETENT_NO, and report problem appropriately.  Also add "error:" tag
  to diagnostic message, quote parameters, and omit trailing period from
  message.

Fixes:

$ infocmp xtermz
infocmp: couldn't open terminfo file /home/.../share/terminfo.db.

...when "/home/.../share/terminfo.db" exists and is readable.

`tfile[termcount]` gets clobbered in ncurses/tinfo/read_entry.c by the
terminal type name if the hashed database file _can_ be opened (possibly
holdover code from pre-hashed-db days such that the "basename" of a
resolved file name matches the terminal type name).

Moreover, TERMINFO_DIRS makes the lookup work like a $PATH search, so we
can only report the last of possibly several failures.  Reporting the
`sterror(errno)` of that last failure is better than nothing.
---
 progs/infocmp.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/progs/infocmp.c b/progs/infocmp.c
index af2ad7790..84204ba47 100644
--- a/progs/infocmp.c
+++ b/progs/infocmp.c
@@ -1878,10 +1878,32 @@ main(int argc, char *argv[])
            }
 
            if (status <= 0) {
-               (void) fprintf(stderr,
-                              "%s: couldn't open terminfo file %s.\n",
-                              _nc_progname,
-                              tfile[termcount]);
+               switch (status) {
+               case TGETENT_NO:
+                   (void) fprintf(stderr,
+                                  "%s: error: no match in terminfo"
+                                  " database for terminal type"
+                                  " \"%s\"\n",
+                                  _nc_progname,
+                                  tname[termcount]);
+                   break;
+               case TGETENT_ERR:
+                   /*
+                    * Several database files might be checked; their
+                    * file names are not exposed via this API.  The
+                    * best we can do is report how the final one
+                    * attempted failed.  Also, tfile[termcount] is
+                    * deeply misleading when a hashed database is used.
+                    */
+                   (void) fprintf(stderr,
+                                  "%s: error: unable to open terminfo"
+                                  " database: %s\n",
+                                  _nc_progname,
+                                  strerror(errno));
+                   break;
+               default:
+                   assert(0 == "unhandled _nc_read_entry2 return");
+               }
                MAIN_LEAKS();
                ExitProgram(EXIT_FAILURE);
            }
-- 
2.30.2

Attachment: signature.asc
Description: PGP signature


reply via email to

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