+ if ((used = decode_quickdump(buffer, path)) != 0
+ && (code = _nc_read_termtype(tp, buffer, used)) == TGETENT_YES
+ && (code = _nc_name_match(tp->term_names, name, "|")) == TGETENT_YES) {
+ TR(TRACE_DATABASE, ("loaded quick-dump for %s", name));
+ /* shorten name shown by infocmp */
+ _nc_STRCPY(filename, "$TERMINFO", limit);
+ } else
+#if USE_HASHED_DB
+ if (make_db_filename(filename, limit, path)
+ && (capdbp = _nc_db_open(filename, FALSE)) != 0) {
+
+ DBT key, data;
+ int reccnt = 0;
+ char *save = strdup(name);
+
+ memset(&key, 0, sizeof(key));
+ key.data = save;
+ key.size = strlen(save);
+
+ /*
+ * This lookup could return termcap data, which we do not want. We are
+ * looking for compiled (binary) terminfo data.
+ *
+ * cgetent uses a two-level lookup. On the first it uses the given
+ * name to return a record containing only the aliases for an entry.
+ * On the second (using that list of aliases as a key), it returns the
+ * content of the terminal description. We expect second lookup to
+ * return data beginning with the same set of aliases.
+ *
+ * For compiled terminfo, the list of aliases in the second case will
+ * be null-terminated. A termcap entry will not be, and will run on
+ * into the description. So we can easily distinguish between the two
+ * (source/binary) by checking the lengths.
+ */
+ while (_nc_db_get(capdbp, &key, &data) == 0) {
+ char *have = (char *) data.data;
+ used = (int) data.size - 1;
+
+ if (*have++ == 0) {
+ if (data.size > key.size
+ && IS_TIC_MAGIC(have)) {
+ code = _nc_read_termtype(tp, have, used);
+ if (code == TGETENT_NO) {
+ _nc_free_termtype2(tp);
+ }
+ }
+ break;
+ }