1 /****************************************************************************
2 * Copyright 2018-2021,2022 Thomas E. Dickey *
3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 * and: Thomas E. Dickey 1996-on *
34 ****************************************************************************/
37 * read_entry.c -- Routine for reading in a compiled terminfo file
40 #include <curses.priv.h>
41 #include <hashed_db.h>
45 MODULE_ID("$Id: read_entry.c,v 1.162 2022/04/16 21:00:00 tom Exp $")
47 #define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts))
49 #define MyNumber(n) (short) LOW_MSB(n)
51 #define SIZEOF_32BITS 4
53 #if NCURSES_USE_DATABASE
54 #if NCURSES_EXT_NUMBERS
56 convert_16bits(char *buf, NCURSES_INT2 *Numbers, int count)
60 size_t size = SIZEOF_SHORT;
61 for (i = 0; i < count; i++) {
65 for (j = 0; j < size; ++j) {
67 Numbers[i] |= (ch << (8 * j));
72 Numbers[i] |= (int) mask;
76 TR(TRACE_DATABASE, ("get Numbers[%d]=%d", i, Numbers[i]));
82 convert_32bits(char *buf, NCURSES_INT2 *Numbers, int count)
86 size_t size = SIZEOF_INT2;
89 assert(sizeof(NCURSES_INT2) == size);
90 for (i = 0; i < count; i++) {
92 for (j = 0; j < size; ++j) {
94 Numbers[i] |= (ch << (8 * j));
96 /* "unsigned" and NCURSES_INT2 are the same size - no sign-extension */
97 TR(TRACE_DATABASE, ("get Numbers[%d]=%d", i, Numbers[i]));
103 convert_32bits(char *buf, NCURSES_INT2 *Numbers, int count)
107 for (i = 0; i < count; i++) {
109 for (j = 0; j < SIZEOF_32BITS; ++j) {
111 value |= (ch << (8 * j));
114 Numbers[i] = ABSENT_NUMERIC;
115 else if (value == -2)
116 Numbers[i] = CANCELLED_NUMERIC;
117 else if (value > MAX_OF_TYPE(NCURSES_INT2))
118 Numbers[i] = MAX_OF_TYPE(NCURSES_INT2);
120 Numbers[i] = (short) value;
121 TR(TRACE_DATABASE, ("get Numbers[%d]=%d", i, Numbers[i]));
127 convert_16bits(char *buf, NCURSES_INT2 *Numbers, int count)
130 for (i = 0; i < count; i++) {
131 if (IS_NEG1(buf + 2 * i))
132 Numbers[i] = ABSENT_NUMERIC;
133 else if (IS_NEG2(buf + 2 * i))
134 Numbers[i] = CANCELLED_NUMERIC;
136 Numbers[i] = MyNumber(buf + 2 * i);
137 TR(TRACE_DATABASE, ("get Numbers[%d]=%d", i, Numbers[i]));
144 convert_strings(char *buf, char **Strings, int count, int size, char *table)
148 bool corrupt = FALSE;
150 for (i = 0; i < count; i++) {
151 if (IS_NEG1(buf + 2 * i)) {
152 Strings[i] = ABSENT_STRING;
153 } else if (IS_NEG2(buf + 2 * i)) {
154 Strings[i] = CANCELLED_STRING;
155 } else if (MyNumber(buf + 2 * i) > size) {
156 Strings[i] = ABSENT_STRING;
158 int nn = MyNumber(buf + 2 * i);
159 if (nn >= 0 && nn < size) {
160 Strings[i] = (nn + table);
161 TR(TRACE_DATABASE, ("Strings[%d] = %s", i,
162 _nc_visbuf(Strings[i])));
167 ("ignore out-of-range index %d to Strings[]", nn));
168 _nc_warning("corrupt data found in convert_strings");
170 Strings[i] = ABSENT_STRING;
174 /* make sure all strings are NUL terminated */
175 if (VALID_STRING(Strings[i])) {
176 for (p = Strings[i]; p < table + size; p++)
179 /* if there is no NUL, ignore the string */
180 if (p >= table + size)
181 Strings[i] = ABSENT_STRING;
187 fake_read(char *src, int *offset, int limit, char *dst, unsigned want)
189 int have = (limit - *offset);
192 if ((int) want > have)
193 want = (unsigned) have;
194 memcpy(dst, src + *offset, (size_t) want);
195 *offset += (int) want;
202 #define Read(buf, count) fake_read(buffer, &offset, limit, (char *) buf, (unsigned) count)
204 #define read_shorts(buf, count) \
205 (Read(buf, (count)*SIZEOF_SHORT) == (int) (count)*SIZEOF_SHORT)
207 #define read_numbers(buf, count) \
208 (Read(buf, (count)*(unsigned)size_of_numbers) == (int) (count)*size_of_numbers)
210 #define even_boundary(value) \
211 if ((value) % 2 != 0) Read(buf, 1)
215 _nc_init_termtype(TERMTYPE2 *const tp)
220 tp->num_Booleans = BOOLCOUNT;
221 tp->num_Numbers = NUMCOUNT;
222 tp->num_Strings = STRCOUNT;
223 tp->ext_Booleans = 0;
227 if (tp->Booleans == 0)
228 TYPE_MALLOC(NCURSES_SBOOL, BOOLCOUNT, tp->Booleans);
229 if (tp->Numbers == 0)
230 TYPE_MALLOC(NCURSES_INT2, NUMCOUNT, tp->Numbers);
231 if (tp->Strings == 0)
232 TYPE_MALLOC(char *, STRCOUNT, tp->Strings);
234 for_each_boolean(i, tp)
235 tp->Booleans[i] = FALSE;
237 for_each_number(i, tp)
238 tp->Numbers[i] = ABSENT_NUMERIC;
240 for_each_string(i, tp)
241 tp->Strings[i] = ABSENT_STRING;
244 #if NCURSES_USE_DATABASE
247 valid_shorts(char *buffer, int limit)
251 for (n = 0; n < limit; ++n) {
252 if (MyNumber(buffer + (n * 2)) > 0) {
262 * Return TGETENT_YES if read, TGETENT_NO if not found or garbled.
265 _nc_read_termtype(TERMTYPE2 *ptr, char *buffer, int limit)
268 int name_size, bool_count, num_count, str_count, str_size;
270 char buf[MAX_ENTRY_SIZE + 2];
273 size_t (*convert_numbers) (char *, NCURSES_INT2 *, int);
275 int max_entry_size = MAX_ENTRY_SIZE;
278 (T_CALLED("_nc_read_termtype(ptr=%p, buffer=%p, limit=%d)"),
279 (void *) ptr, buffer, limit));
281 TR(TRACE_DATABASE, ("READ termtype header @%d", offset));
283 memset(ptr, 0, sizeof(*ptr));
285 /* grab the header */
286 if (!read_shorts(buf, 6)
287 || !IS_TIC_MAGIC(buf)) {
288 returnDB(TGETENT_NO);
290 #if NCURSES_EXT_NUMBERS
291 if (LOW_MSB(buf) == MAGIC2) {
292 convert_numbers = convert_32bits;
293 size_of_numbers = SIZEOF_INT2;
295 max_entry_size = MAX_ENTRY_SIZE1;
296 convert_numbers = convert_16bits;
297 size_of_numbers = SIZEOF_SHORT;
300 if (LOW_MSB(buf) == MAGIC2) {
301 convert_numbers = convert_32bits;
302 size_of_numbers = SIZEOF_32BITS;
304 convert_numbers = convert_16bits;
305 size_of_numbers = SIZEOF_INT2;
310 name_size = MyNumber(buf + 2);
311 bool_count = MyNumber(buf + 4);
312 num_count = MyNumber(buf + 6);
313 str_count = MyNumber(buf + 8);
314 str_size = MyNumber(buf + 10);
317 ("TERMTYPE name_size=%d, bool=%d/%d, num=%d/%d str=%d/%d(%d)",
318 name_size, bool_count, BOOLCOUNT, num_count, NUMCOUNT,
319 str_count, STRCOUNT, str_size));
325 returnDB(TGETENT_NO);
328 want = (unsigned) (str_size + name_size + 1);
329 /* try to allocate space for the string table */
330 if (str_count * SIZEOF_SHORT >= max_entry_size
331 || (string_table = typeMalloc(char, want)) == 0) {
332 returnDB(TGETENT_NO);
335 /* grab the name (a null-terminated string) */
336 want = min(MAX_NAME_SIZE, (unsigned) name_size);
337 ptr->str_table = string_table;
338 ptr->term_names = string_table;
339 if ((have = (unsigned) Read(ptr->term_names, want)) != want) {
340 memset(ptr->term_names + have, 0, (size_t) (want - have));
342 ptr->term_names[want] = '\0';
343 string_table += (want + 1);
345 if (have > MAX_NAME_SIZE)
346 offset = (int) (have - MAX_NAME_SIZE);
348 /* grab the booleans */
349 if ((ptr->Booleans = TYPE_CALLOC(NCURSES_SBOOL,
350 max(BOOLCOUNT, bool_count))) == 0
351 || Read(ptr->Booleans, (unsigned) bool_count) < bool_count) {
352 returnDB(TGETENT_NO);
356 * If booleans end on an odd byte, skip it. The machine they
357 * originally wrote terminfo on must have been a 16-bit
358 * word-oriented machine that would trap out if you tried a
359 * word access off a 2-byte boundary.
361 even_boundary(name_size + bool_count);
363 /* grab the numbers */
364 if (!(ptr->Numbers = TYPE_CALLOC(NCURSES_INT2, max(NUMCOUNT, num_count)))
365 || !read_numbers(buf, num_count)) {
366 returnDB(TGETENT_NO);
368 convert_numbers(buf, ptr->Numbers, num_count);
370 if ((ptr->Strings = TYPE_CALLOC(char *, max(STRCOUNT, str_count))) == 0) {
371 returnDB(TGETENT_NO);
375 /* grab the string offsets */
376 if (!read_shorts(buf, str_count)) {
377 returnDB(TGETENT_NO);
379 /* finally, grab the string table itself */
380 if (Read(string_table, (unsigned) str_size) != str_size) {
381 returnDB(TGETENT_NO);
383 convert_strings(buf, ptr->Strings, str_count, str_size, string_table);
387 ptr->num_Booleans = BOOLCOUNT;
388 ptr->num_Numbers = NUMCOUNT;
389 ptr->num_Strings = STRCOUNT;
392 * Read extended entries, if any, after the normal end of terminfo data.
394 even_boundary(str_size);
395 TR(TRACE_DATABASE, ("READ extended_header @%d", offset));
396 if (_nc_user_definable && read_shorts(buf, 5) && valid_shorts(buf, 5)) {
397 int ext_bool_count = MyNumber(buf + 0);
398 int ext_num_count = MyNumber(buf + 2);
399 int ext_str_count = MyNumber(buf + 4);
400 int ext_str_usage = MyNumber(buf + 6);
401 int ext_str_limit = MyNumber(buf + 8);
402 unsigned need = (unsigned) (ext_bool_count + ext_num_count + ext_str_count);
405 if ((int) need >= (max_entry_size / 2)
406 || ext_str_usage >= max_entry_size
407 || ext_str_limit >= max_entry_size
408 || ext_bool_count < 0
412 || ext_str_limit < 0) {
413 returnDB(TGETENT_NO);
416 ptr->num_Booleans = UShort(BOOLCOUNT + ext_bool_count);
417 ptr->num_Numbers = UShort(NUMCOUNT + ext_num_count);
418 ptr->num_Strings = UShort(STRCOUNT + ext_str_count);
420 TYPE_REALLOC(NCURSES_SBOOL, ptr->num_Booleans, ptr->Booleans);
421 TYPE_REALLOC(NCURSES_INT2, ptr->num_Numbers, ptr->Numbers);
422 TYPE_REALLOC(char *, ptr->num_Strings, ptr->Strings);
424 TR(TRACE_DATABASE, ("extended header: "
434 TR(TRACE_DATABASE, ("READ %d extended-booleans @%d",
435 ext_bool_count, offset));
436 if ((ptr->ext_Booleans = UShort(ext_bool_count)) != 0) {
437 if (Read(ptr->Booleans + BOOLCOUNT, (unsigned)
438 ext_bool_count) != ext_bool_count) {
439 returnDB(TGETENT_NO);
442 even_boundary(ext_bool_count);
444 TR(TRACE_DATABASE, ("READ %d extended-numbers @%d",
445 ext_num_count, offset));
446 if ((ptr->ext_Numbers = UShort(ext_num_count)) != 0) {
447 if (!read_numbers(buf, ext_num_count)) {
448 returnDB(TGETENT_NO);
450 TR(TRACE_DATABASE, ("Before converting extended-numbers"));
451 convert_numbers(buf, ptr->Numbers + NUMCOUNT, ext_num_count);
454 TR(TRACE_DATABASE, ("READ extended-offsets @%d", offset));
455 if ((ext_str_count + (int) need) >= (max_entry_size / 2)) {
456 returnDB(TGETENT_NO);
458 if ((ext_str_count || need)
459 && !read_shorts(buf, ext_str_count + (int) need)) {
460 returnDB(TGETENT_NO);
463 TR(TRACE_DATABASE, ("READ %d bytes of extended-strings @%d",
464 ext_str_limit, offset));
467 ptr->ext_str_table = typeMalloc(char, (size_t) ext_str_limit);
468 if (ptr->ext_str_table == 0) {
469 returnDB(TGETENT_NO);
471 if (Read(ptr->ext_str_table, (unsigned) ext_str_limit) != ext_str_limit) {
472 returnDB(TGETENT_NO);
474 TR(TRACE_DATABASE, ("first extended-string is %s", _nc_visbuf(ptr->ext_str_table)));
477 if ((ptr->ext_Strings = UShort(ext_str_count)) != 0) {
478 int check = (ext_bool_count + ext_num_count + ext_str_count);
481 ("Before computing extended-string capabilities "
482 "str_count=%d, ext_str_count=%d",
483 str_count, ext_str_count));
484 convert_strings(buf, ptr->Strings + str_count, ext_str_count,
485 ext_str_limit, ptr->ext_str_table);
486 for (i = ext_str_count - 1; i >= 0; i--) {
487 TR(TRACE_DATABASE, ("MOVE from [%d:%d] %s",
489 _nc_visbuf(ptr->Strings[i + str_count])));
490 ptr->Strings[i + STRCOUNT] = ptr->Strings[i + str_count];
491 if (VALID_STRING(ptr->Strings[i + STRCOUNT])) {
492 base += (int) (strlen(ptr->Strings[i + STRCOUNT]) + 1);
495 TR(TRACE_DATABASE, ("... to [%d] %s",
497 _nc_visbuf(ptr->Strings[i + STRCOUNT])));
499 TR(TRACE_DATABASE, ("Check table-size: %d/%d", check, ext_str_usage));
502 * Phasing in a proper check will be done "later".
504 if (check != ext_str_usage)
505 returnDB(TGETENT_NO);
510 if (ext_str_count >= (max_entry_size / 2)) {
511 returnDB(TGETENT_NO);
513 if ((ptr->ext_Names = TYPE_CALLOC(char *, need)) == 0) {
514 returnDB(TGETENT_NO);
517 ("ext_NAMES starting @%d in extended_strings, first = %s",
518 base, _nc_visbuf(ptr->ext_str_table + base)));
519 convert_strings(buf + (2 * ext_str_count),
522 ext_str_limit, ptr->ext_str_table + base);
526 ("...done reading terminfo bool %d(%d) num %d(%d) str %d(%d)",
527 ptr->num_Booleans, ptr->ext_Booleans,
528 ptr->num_Numbers, ptr->ext_Numbers,
529 ptr->num_Strings, ptr->ext_Strings));
531 TR(TRACE_DATABASE, ("extend: num_Booleans:%d", ptr->num_Booleans));
533 #endif /* NCURSES_XNAMES */
535 TR(TRACE_DATABASE, ("...done reading terminfo bool %d num %d str %d",
536 bool_count, num_count, str_count));
538 TR(TRACE_DATABASE, ("normal: num_Booleans:%d", ptr->num_Booleans));
542 for (i = bool_count; i < BOOLCOUNT; i++)
543 ptr->Booleans[i] = FALSE;
544 for (i = num_count; i < NUMCOUNT; i++)
545 ptr->Numbers[i] = ABSENT_NUMERIC;
546 for (i = str_count; i < STRCOUNT; i++)
547 ptr->Strings[i] = ABSENT_STRING;
549 returnDB(TGETENT_YES);
554 * _nc_read_file_entry(filename, ptr)
556 * Read the compiled terminfo entry in the given file into the
557 * structure pointed to by ptr, allocating space for the string
561 _nc_read_file_entry(const char *const filename, TERMTYPE2 *ptr)
562 /* return 1 if read, 0 if not found or garbled */
567 if (_nc_access(filename, R_OK) < 0
568 || (fp = safe_fopen(filename, BIN_R)) == 0) {
569 TR(TRACE_DATABASE, ("cannot open terminfo %s (errno=%d)", filename, errno));
573 char buffer[MAX_ENTRY_SIZE + 1];
575 if ((limit = (int) fread(buffer, sizeof(char), sizeof(buffer), fp))
578 TR(TRACE_DATABASE, ("read terminfo %s", filename));
579 if ((code = _nc_read_termtype(ptr, buffer, limit)) == TGETENT_NO) {
580 _nc_free_termtype2(ptr);
593 * Return if if we can build the filename of a ".db" file.
596 make_db_filename(char *filename, unsigned limit, const char *const path)
598 static const char suffix[] = DBM_SUFFIX;
600 size_t lens = sizeof(suffix) - 1;
601 size_t size = strlen(path);
602 size_t test = lens + size;
607 && !strcmp(path + size - lens, suffix))
608 _nc_STRCPY(filename, path, limit);
610 _nc_SPRINTF(filename, _nc_SLIMIT(limit) "%s%s", path, suffix);
618 * Return true if we can build the name of a filesystem entry.
621 make_dir_filename(char *filename,
623 const char *const path,
628 #if NCURSES_USE_TERMCAP
629 if (_nc_is_dir_path(path))
632 unsigned need = (unsigned) (LEAF_LEN + 3 + strlen(path) + strlen(name));
635 _nc_SPRINTF(filename, _nc_SLIMIT(limit)
636 "%s/" LEAF_FMT "/%s", path, *name, name);
644 lookup_b64(int *target, const char **source)
649 * ncurses' quickdump writes only RFC 4648 "url/filename-safe" encoding,
650 * but accepts RFC-3548
652 for (j = 0; j < 4; ++j) {
653 int ch = UChar(**source);
655 if (ch >= 'A' && ch <= 'Z') {
656 target[j] = (ch - 'A');
657 } else if (ch >= 'a' && ch <= 'z') {
658 target[j] = 26 + (ch - 'a');
659 } else if (ch >= '0' && ch <= '9') {
660 target[j] = 52 + (ch - '0');
661 } else if (ch == '-' || ch == '+') {
663 } else if (ch == '_' || ch == '/') {
665 } else if (ch == '=') {
677 decode_hex(const char **source)
682 for (nibble = 0; nibble < 2; ++nibble) {
683 int ch = UChar(**source);
686 if (ch >= '0' && ch <= '9') {
688 } else if (ch >= 'A' && ch <= 'F') {
691 } else if (ch >= 'a' && ch <= 'f') {
704 decode_quickdump(char *target, const char *source)
709 if (!strncmp(source, "b64:", (size_t) 4)) {
711 while (*source != '\0') {
713 int ch = lookup_b64(bits, &source);
714 if (ch < 0 || (ch + target - base) >= MAX_ENTRY_SIZE) {
719 *target++ = (char) ((bits[0] << 2) | (bits[1] >> 4));
721 *target++ = (char) ((bits[1] << 4) | (bits[2] >> 2));
723 *target++ = (char) ((bits[2] << 6) | bits[3]);
727 } else if (!strncmp(source, "hex:", (size_t) 4)) {
729 while (*source != '\0') {
730 int ch = decode_hex(&source);
731 if (ch < 0 || (target - base) >= MAX_ENTRY_SIZE) {
735 *target++ = (char) ch;
743 * Build a terminfo pathname and try to read the data. Returns TGETENT_YES on
744 * success, TGETENT_NO on failure.
747 _nc_read_tic_entry(char *filename,
749 const char *const path,
753 int code = TGETENT_NO;
757 char buffer[MAX_ENTRY_SIZE + 1];
761 (T_CALLED("_nc_read_tic_entry(file=%p, path=%s, name=%s)"),
762 filename, path, name));
764 assert(TGETENT_YES == TRUE); /* simplify call for _nc_name_match */
766 if ((used = decode_quickdump(buffer, path)) != 0
767 && (code = _nc_read_termtype(tp, buffer, used)) == TGETENT_YES
768 && (code = _nc_name_match(tp->term_names, name, "|")) == TGETENT_YES) {
769 TR(TRACE_DATABASE, ("loaded quick-dump for %s", name));
770 /* shorten name shown by infocmp */
771 _nc_STRCPY(filename, "$TERMINFO", limit);
774 if (make_db_filename(filename, limit, path)
775 && (capdbp = _nc_db_open(filename, FALSE)) != 0) {
779 char *save = strdup(name);
781 memset(&key, 0, sizeof(key));
783 key.size = strlen(save);
786 * This lookup could return termcap data, which we do not want. We are
787 * looking for compiled (binary) terminfo data.
789 * cgetent uses a two-level lookup. On the first it uses the given
790 * name to return a record containing only the aliases for an entry.
791 * On the second (using that list of aliases as a key), it returns the
792 * content of the terminal description. We expect second lookup to
793 * return data beginning with the same set of aliases.
795 * For compiled terminfo, the list of aliases in the second case will
796 * be null-terminated. A termcap entry will not be, and will run on
797 * into the description. So we can easily distinguish between the two
798 * (source/binary) by checking the lengths.
800 while (_nc_db_get(capdbp, &key, &data) == 0) {
801 char *have = (char *) data.data;
802 used = (int) data.size - 1;
805 if (data.size > key.size
806 && IS_TIC_MAGIC(have)) {
807 code = _nc_read_termtype(tp, have, used);
808 if (code == TGETENT_NO) {
809 _nc_free_termtype2(tp);
816 * Just in case we have a corrupt database, do not waste time with
823 * Prepare for the second level.
830 } else /* may be either filesystem or flat file */
832 if (make_dir_filename(filename, limit, path, name)) {
833 code = _nc_read_file_entry(filename, tp);
835 #if NCURSES_USE_TERMCAP
836 if (code != TGETENT_YES) {
837 code = _nc_read_termcap_entry(name, tp);
838 _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX)
839 "%.*s", PATH_MAX - 1, _nc_get_source());
844 #endif /* NCURSES_USE_DATABASE */
847 * Find and read the compiled entry for a given terminal type, if it exists.
848 * We take pains here to make sure no combination of environment variables and
849 * terminal type name can be used to overrun the file buffer.
852 _nc_read_entry2(const char *const name, char *const filename, TERMTYPE2 *const tp)
854 int code = TGETENT_NO;
857 return _nc_read_entry2("", filename, tp);
859 _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX)
860 "%.*s", PATH_MAX - 1, name);
862 if (strlen(name) == 0
863 || strcmp(name, ".") == 0
864 || strcmp(name, "..") == 0
865 || _nc_pathlast(name) != 0
866 || strchr(name, NCURSES_PATHSEP) != 0) {
867 TR(TRACE_DATABASE, ("illegal or missing entry name '%s'", name));
869 #if NCURSES_USE_DATABASE
874 _nc_first_db(&state, &offset);
876 while ((path = _nc_next_db(&state, &offset)) != 0) {
877 code = _nc_read_tic_entry(filename, PATH_MAX, path, name, tp);
878 if (code == TGETENT_YES) {
883 #elif NCURSES_USE_TERMCAP
884 if (code != TGETENT_YES) {
885 code = _nc_read_termcap_entry(name, tp);
886 _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX)
887 "%.*s", PATH_MAX - 1, _nc_get_source());
894 #if NCURSES_EXT_NUMBERS
896 * This entrypoint is used by tack 1.07
899 _nc_read_entry(const char *const name, char *const filename, TERMTYPE *const tp)
903 rc = _nc_read_entry2(name, filename, &dummy);
904 if (rc == TGETENT_YES)
905 _nc_export_termtype2(tp, &dummy);