/****************************************************************************
- * Copyright 2018-2020,2021 Thomas E. Dickey *
+ * Copyright 2018-2022,2023 Thomas E. Dickey *
* Copyright 1998-2013,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
#include <hashed_db.h>
#endif
-MODULE_ID("$Id: toe.c,v 1.83 2021/09/21 20:07:51 tom Exp $")
+MODULE_ID("$Id: toe.c,v 1.89 2023/07/01 17:04:46 tom Exp $")
#define isDotname(name) (!strcmp(name, ".") || !strcmp(name, ".."))
if (use_termdata > 1)
qsort(ptr_termdata, use_termdata, sizeof(TERMDATA), compare_termdata);
for (n = 0; n < use_termdata; ++n) {
+ int nk = -1;
/*
* If there is more than one database, show how they differ.
unsigned long check = 0;
int k = 0;
for (;;) {
+ char mark = ((check == 0
+ || (check != ptr_termdata[n].checksum))
+ ? '*'
+ : '+');
+
for (; k < ptr_termdata[n].db_index; ++k) {
printf("--");
}
* from the first entry's checksum, print "*". Otherwise
* it looks enough like a duplicate to print "+".
*/
- printf("%c-", ((check == 0
- || (check != ptr_termdata[n].checksum))
- ? '*'
- : '+'));
+ printf("%c-", mark);
check = ptr_termdata[n].checksum;
+ if (mark == '*' && nk < 0)
+ nk = (int) n;
++k;
if ((n + 1) >= use_termdata
}
printf(":\t");
}
+ if (nk < 0)
+ nk = (int) n;
(void) printf("%-10s\t%s\n",
ptr_termdata[n].term_name,
- ptr_termdata[n].description);
+ ptr_termdata[nk].description);
}
}
}
}
#if NCURSES_USE_TERMCAP
+/*
+ * Check if the buffer contents are printable ASCII, ensuring that we do not
+ * accidentally pick up incompatible binary content from a hashed database.
+ */
+static bool
+is_termcap(char *buffer)
+{
+ bool result = TRUE;
+ while (*buffer != '\0') {
+ int ch = UChar(*buffer++);
+ if (ch == '\t')
+ continue;
+ if (ch < ' ' || ch > '~') {
+ result = FALSE;
+ break;
+ }
+ }
+ return result;
+}
+
static void
show_termcap(int db_index, int db_limit, char *buffer, DescHook hook)
{
db_array[1] = 0;
if (cgetfirst(&buffer, db_array) > 0) {
- show_termcap(i, eargc, buffer, hook);
- free(buffer);
- while (cgetnext(&buffer, db_array) > 0) {
+ if (is_termcap(buffer)) {
show_termcap(i, eargc, buffer, hook);
free(buffer);
+ while (cgetnext(&buffer, db_array) > 0) {
+ show_termcap(i, eargc, buffer, hook);
+ free(buffer);
+ }
}
cgetclose();
continue;
if ((fp = safe_fopen(eargv[i], "r")) != 0) {
while (fgets(buffer, sizeof(buffer), fp) != 0) {
+ if (!is_termcap(buffer))
+ break;
if (*buffer == '#')
continue;
- if (isspace(*buffer))
+ if (isspace(UChar(*buffer)))
continue;
show_termcap(i, eargc, buffer, hook);
}
usage();
}
}
- set_trace_level(v_opt);
+ use_verbosity(v_opt);
if (report_file != 0) {
if (freopen(report_file, "r", stdin) == 0) {