1 /****************************************************************************
2 * Copyright 2018-2022,2023 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 * parse_entry.c -- compile one terminfo or termcap entry
39 * Get an exact in-core representation of an entry. Don't
40 * try to resolve use or tc capabilities, that is someone
41 * else's job. Depends on the lexical analyzer to get tokens
42 * from the input stream.
45 #define __INTERNAL_CAPS_VISIBLE
46 #include <curses.priv.h>
51 MODULE_ID("$Id: parse_entry.c,v 1.108 2023/04/24 22:32:33 tom Exp $")
54 static short const parametrized[] =
57 #include <parametrized.h>
60 static void postprocess_termcap(TERMTYPE2 *, bool);
61 static void postprocess_terminfo(TERMTYPE2 *);
62 static struct name_table_entry const *lookup_fullname(const char *name);
66 static struct name_table_entry const *
67 _nc_extend_names(ENTRY * entryp, const char *name, int token_type)
69 static struct name_table_entry temp;
70 TERMTYPE2 *tp = &(entryp->tterm);
74 unsigned first, last, n;
80 last = tp->ext_Booleans;
81 offset = tp->ext_Booleans;
82 tindex = tp->num_Booleans;
85 first = tp->ext_Booleans;
86 last = tp->ext_Numbers + first;
87 offset = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
88 tindex = tp->num_Numbers;
91 first = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
92 last = tp->ext_Strings + first;
93 offset = (unsigned) (tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings);
94 tindex = tp->num_Strings;
97 actual = NUM_EXT_NAMES(tp);
98 for (n = 0; n < actual; n++) {
99 if (!strcmp(name, tp->ext_Names[n])) {
100 if (n > (unsigned) (tp->ext_Booleans + tp->ext_Numbers)) {
102 } else if (n > tp->ext_Booleans) {
105 token_type = BOOLEAN;
107 return _nc_extend_names(entryp, name, token_type);
110 /* Well, we are given a cancel for a name that we don't recognize */
111 return _nc_extend_names(entryp, name, STRING);
116 /* Adjust the 'offset' (insertion-point) to keep the lists of extended
119 for (n = first, found = FALSE; n < last; n++) {
120 int cmp = strcmp(tp->ext_Names[n], name);
126 switch (token_type) {
141 #define for_each_value(max) \
142 for (last = (unsigned) (max - 1); last > tindex; last--)
147 if ((saved = _nc_save_str(name)) == NULL)
150 switch (token_type) {
154 TYPE_REALLOC(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans);
155 for_each_value(tp->num_Booleans)
156 tp->Booleans[last] = tp->Booleans[last - 1];
161 TYPE_REALLOC(NCURSES_INT2, tp->num_Numbers, tp->Numbers);
162 for_each_value(tp->num_Numbers)
163 tp->Numbers[last] = tp->Numbers[last - 1];
168 TYPE_REALLOC(char *, tp->num_Strings, tp->Strings);
169 for_each_value(tp->num_Strings)
170 tp->Strings[last] = tp->Strings[last - 1];
173 actual = NUM_EXT_NAMES(tp);
174 TYPE_REALLOC(char *, actual, tp->ext_Names);
175 while (--actual > offset)
176 tp->ext_Names[actual] = tp->ext_Names[actual - 1];
177 tp->ext_Names[offset] = saved;
180 temp.nte_name = tp->ext_Names[offset];
181 temp.nte_type = token_type;
182 temp.nte_index = (short) tindex;
191 const char *result = "unknown";
192 if (mask & (1 << BOOLEAN)) {
194 } else if (mask & (1 << NUMBER)) {
196 } else if (mask & (1 << STRING)) {
203 expected_type(const char *name, int token_type, bool silent)
205 struct user_table_entry const *entry = _nc_find_user_entry(name);
207 if ((entry != 0) && (token_type != CANCEL)) {
208 int have_type = (1 << token_type);
209 if (!(entry->ute_type & have_type)) {
211 _nc_warning("expected %s-type for %s, have %s",
212 usertype2s(entry->ute_type),
214 usertype2s(have_type));
220 #endif /* NCURSES_XNAMES */
223 * A valid entry name uses characters from the "portable character set"
224 * (more commonly referred to as US-ASCII), and disallows some of the
225 * punctuation characters:
227 * '/' is a pathname separator
228 * '\' may be a pathname separator, but more important, is an escape
229 * '|' delimits names and description
230 * '#' denotes a numeric value
231 * '=' denotes a string value
232 * '@' denotes a cancelled symbol
233 * ',' separates terminfo capabilities
234 * ':' separates termcap capabilities
236 * Termcap capability names may begin with a '#' or '@' (since they have
237 * exactly two characters).
240 valid_entryname(const char *name)
245 while ((ch = UChar(*name++)) != '\0') {
246 if (ch <= ' ' || ch > '~' || strchr("/\\|=,:", ch) != NULL) {
250 if (!first && strchr("#@", ch) != NULL) {
261 * _nc_parse_entry(entry, literal, silent)
263 * Compile one entry. Doesn't try to resolve use or tc capabilities.
265 * found-forward-use = FALSE
266 * re-initialise internal arrays
268 * if the token was not a name in column 1, complain and die
269 * save names in entry's string table
270 * while (get_token() is not EOF and not NAMES)
271 * check for existence and type-correctness
272 * enter cap into structure
274 * save string in entry's string table
278 #define BAD_TC_USAGE if (!bad_tc_usage) \
279 { bad_tc_usage = TRUE; \
280 _nc_warning("Legacy termcap allows only a trailing tc= clause"); }
282 #define MAX_NUMBER MAX_OF_TYPE(NCURSES_INT2)
285 _nc_parse_entry(ENTRY * entryp, int literal, bool silent)
288 struct name_table_entry const *entry_ptr;
291 bool bad_tc_usage = FALSE;
294 (T_CALLED("_nc_parse_entry(entry=%p, literal=%d, silent=%d)"),
295 (void *) entryp, literal, silent));
297 token_type = _nc_get_token(silent);
299 if (token_type == EOF)
301 if (token_type != NAMES)
302 _nc_err_abort("Entry does not start with terminal names in column one");
304 _nc_init_entry(entryp);
306 entryp->cstart = _nc_comment_start;
307 entryp->cend = _nc_comment_end;
308 entryp->startline = _nc_start_line;
309 DEBUG(2, ("Comment range is %ld to %ld", entryp->cstart, entryp->cend));
312 * Strip off the 2-character termcap name, if present. Originally termcap
313 * used that as an indexing aid. We can retain 2-character terminfo names,
314 * but note that they would be lost if we translate to/from termcap. This
315 * feature is supposedly obsolete since "newer" BSD implementations do not
316 * use it; however our reference for this feature is SunOS 4.x, which
317 * implemented it. Note that the resulting terminal type was never the
318 * 2-character name, but was instead the first alias after that.
320 #define ok_TC2(s) (isgraph(UChar(s)) && (s) != '|')
321 ptr = _nc_curr_token.tk_name;
322 if (_nc_syntax == SYN_TERMCAP
324 && !_nc_user_definable
327 if (ok_TC2(ptr[0]) && ok_TC2(ptr[1]) && (ptr[2] == '|')) {
329 _nc_curr_token.tk_name[2] = '\0';
333 entryp->tterm.str_table = entryp->tterm.term_names = _nc_save_str(ptr);
335 if (entryp->tterm.str_table == 0)
338 DEBUG(2, ("Starting '%s'", ptr));
341 * We do this because the one-token lookahead in the parse loop
342 * results in the terminal type getting prematurely set to correspond
343 * to that of the next entry.
345 name = _nc_first_name(entryp->tterm.term_names);
346 if (!valid_entryname(name)) {
347 _nc_warning("invalid entry name \"%s\"", name);
352 /* check for overly-long names and aliases */
353 for (base = entryp->tterm.term_names; (ptr = strchr(base, '|')) != 0;
355 if (ptr - base > MAX_ALIAS) {
356 _nc_warning("%s `%.*s' may be too long",
357 (base == entryp->tterm.term_names)
360 (int) (ptr - base), base);
366 for (token_type = _nc_get_token(silent);
367 token_type != EOF && token_type != NAMES;
368 token_type = _nc_get_token(silent)) {
369 bool is_use = (strcmp(_nc_curr_token.tk_name, "use") == 0);
370 bool is_tc = !is_use && (strcmp(_nc_curr_token.tk_name, "tc") == 0);
371 if (is_use || is_tc) {
374 if (!VALID_STRING(_nc_curr_token.tk_valstring)
375 || _nc_curr_token.tk_valstring[0] == '\0') {
376 _nc_warning("missing name for use-clause");
378 } else if (!valid_entryname(_nc_curr_token.tk_valstring)) {
379 _nc_warning("invalid name for use-clause \"%s\"",
380 _nc_curr_token.tk_valstring);
382 } else if (entryp->nuses >= MAX_USES) {
383 _nc_warning("too many use-clauses, ignored \"%s\"",
384 _nc_curr_token.tk_valstring);
387 if ((saved = _nc_save_str(_nc_curr_token.tk_valstring)) != NULL) {
388 entryp->uses[entryp->nuses].name = saved;
389 entryp->uses[entryp->nuses].line = _nc_curr_line;
391 if (entryp->nuses > 1 && is_tc) {
396 /* normal token lookup */
397 entry_ptr = _nc_find_entry(_nc_curr_token.tk_name,
398 _nc_get_hash_table(_nc_syntax));
401 * Our kluge to handle aliasing. The reason it is done
402 * this ugly way, with a linear search, is so the hashing
403 * machinery doesn't have to be made really complicated
404 * (also we get better warnings this way). No point in
405 * making this case fast, aliased caps aren't common now
406 * and will get rarer.
408 if (entry_ptr == NOTFOUND) {
409 const struct alias *ap;
411 if (_nc_syntax == SYN_TERMCAP) {
412 if (entryp->nuses != 0) {
415 for (ap = _nc_get_alias_table(TRUE); ap->from; ap++)
416 if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) {
417 if (ap->to == (char *) 0) {
418 _nc_warning("%s (%s termcap extension) ignored",
419 ap->from, ap->source);
423 entry_ptr = _nc_find_entry(ap->to,
424 _nc_get_hash_table(TRUE));
425 if (entry_ptr && !silent)
426 _nc_warning("%s (%s termcap extension) aliased to %s",
427 ap->from, ap->source, ap->to);
430 } else { /* if (_nc_syntax == SYN_TERMINFO) */
431 for (ap = _nc_get_alias_table(FALSE); ap->from; ap++)
432 if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) {
433 if (ap->to == (char *) 0) {
434 _nc_warning("%s (%s terminfo extension) ignored",
435 ap->from, ap->source);
439 entry_ptr = _nc_find_entry(ap->to,
440 _nc_get_hash_table(FALSE));
441 if (entry_ptr && !silent)
442 _nc_warning("%s (%s terminfo extension) aliased to %s",
443 ap->from, ap->source, ap->to);
447 if (entry_ptr == NOTFOUND) {
448 entry_ptr = lookup_fullname(_nc_curr_token.tk_name);
454 * If we have extended-names active, we will automatically
455 * define a name based on its context.
457 if (entry_ptr == NOTFOUND
458 && _nc_user_definable) {
459 if (expected_type(_nc_curr_token.tk_name, token_type, silent)) {
460 if ((entry_ptr = _nc_extend_names(entryp,
461 _nc_curr_token.tk_name,
463 if (_nc_tracing >= DEBUG_LEVEL(1)) {
464 _nc_warning("extended capability '%s'",
465 _nc_curr_token.tk_name);
469 /* ignore it: we have already printed error message */
473 #endif /* NCURSES_XNAMES */
475 /* can't find this cap name, not even as an alias */
476 if (entry_ptr == NOTFOUND) {
478 _nc_warning("unknown capability '%s'",
479 _nc_curr_token.tk_name);
483 /* deal with bad type/value combinations. */
484 if (token_type == CANCEL) {
486 * Prefer terminfo in this (long-obsolete) ambiguity:
488 if (!strcmp("ma", _nc_curr_token.tk_name)) {
489 entry_ptr = _nc_find_type_entry("ma", NUMBER,
491 assert(entry_ptr != 0);
493 } else if (entry_ptr->nte_type != token_type) {
495 * Nasty special cases here handle situations in which type
496 * information can resolve name clashes. Normal lookup
497 * finds the last instance in the capability table of a
498 * given name, regardless of type. find_type_entry looks
499 * for a first matching instance with given type. So as
500 * long as all ambiguous names occur in pairs of distinct
501 * type, this will do the job.
504 if (token_type == NUMBER
505 && !strcmp("ma", _nc_curr_token.tk_name)) {
506 /* tell max_attributes from arrow_key_map */
507 entry_ptr = _nc_find_type_entry("ma", NUMBER,
509 assert(entry_ptr != 0);
511 } else if (token_type == STRING
512 && !strcmp("MT", _nc_curr_token.tk_name)) {
513 /* map terminfo's string MT to MT */
514 entry_ptr = _nc_find_type_entry("MT", STRING,
516 assert(entry_ptr != 0);
518 } else if (token_type == BOOLEAN
519 && entry_ptr->nte_type == STRING) {
520 /* treat strings without following "=" as empty strings */
523 /* we couldn't recover; skip this token */
525 const char *type_name;
526 switch (entry_ptr->nte_type) {
528 type_name = "boolean";
531 type_name = "string";
534 type_name = "numeric";
537 type_name = "unknown";
540 _nc_warning("wrong type used for %s capability '%s'",
541 type_name, _nc_curr_token.tk_name);
547 /* now we know that the type/value combination is OK */
548 switch (token_type) {
550 switch (entry_ptr->nte_type) {
552 entryp->tterm.Booleans[entry_ptr->nte_index] = CANCELLED_BOOLEAN;
556 entryp->tterm.Numbers[entry_ptr->nte_index] = CANCELLED_NUMERIC;
560 entryp->tterm.Strings[entry_ptr->nte_index] = CANCELLED_STRING;
566 entryp->tterm.Booleans[entry_ptr->nte_index] = TRUE;
570 #if !NCURSES_EXT_NUMBERS
571 if (_nc_curr_token.tk_valnumber > MAX_NUMBER) {
572 entryp->tterm.Numbers[entry_ptr->nte_index] = MAX_NUMBER;
576 entryp->tterm.Numbers[entry_ptr->nte_index] =
577 (NCURSES_INT2) _nc_curr_token.tk_valnumber;
582 ptr = _nc_curr_token.tk_valstring;
583 if (_nc_syntax == SYN_TERMCAP) {
584 int n = entry_ptr->nte_index;
585 ptr = _nc_captoinfo(_nc_curr_token.tk_name,
587 (n < (int) SIZEOF(parametrized))
591 entryp->tterm.Strings[entry_ptr->nte_index] = _nc_save_str(ptr);
596 _nc_warning("unknown token type");
597 _nc_panic_mode((char) ((_nc_syntax == SYN_TERMCAP) ? ':' : ','));
600 } /* end else cur_token.name != "use" */
602 continue; /* cannot have a label w/o statement */
603 } /* endwhile (not EOF and not NAMES) */
605 _nc_push_token(token_type);
606 _nc_set_type(_nc_first_name(entryp->tterm.term_names));
609 * Try to deduce as much as possible from extension capabilities
610 * (this includes obsolete BSD capabilities). Sigh...it would be more
611 * space-efficient to call this after use resolution, but it has
612 * to be done before entry allocation is wrapped up.
615 if (_nc_syntax == SYN_TERMCAP) {
616 bool has_base_entry = FALSE;
619 * Don't insert defaults if this is a `+' entry meant only
620 * for inclusion in other entries (not sure termcap ever
621 * had these, actually).
623 if (strchr(entryp->tterm.term_names, '+')) {
624 has_base_entry = TRUE;
628 * Otherwise, look for a base entry that will already
629 * have picked up defaults via translation.
631 for (i = 0; i < entryp->nuses; i++) {
632 if (entryp->uses[i].name != 0
633 && !strchr(entryp->uses[i].name, '+'))
634 has_base_entry = TRUE;
638 postprocess_termcap(&entryp->tterm, has_base_entry);
640 postprocess_terminfo(&entryp->tterm);
642 _nc_wrap_entry(entryp, FALSE);
648 _nc_capcmp(const char *s, const char *t)
649 /* compare two string capabilities, stripping out padding */
651 bool ok_s = VALID_STRING(s);
652 bool ok_t = VALID_STRING(t);
656 if (s[0] == '$' && s[1] == '<') {
658 if (!(isdigit(UChar(*s))
668 if (t[0] == '$' && t[1] == '<') {
670 if (!(isdigit(UChar(*t))
680 /* we've now pushed s and t past any padding they pointed at */
682 if (*s == '\0' && *t == '\0')
688 /* else *s == *t but one is not NUL, so continue */
691 } else if (ok_s || ok_t) {
698 append_acs0(string_desc * dst, int code, char *src, size_t off)
700 if (src != 0 && off < strlen(src)) {
702 temp[0] = (char) code;
705 _nc_safe_strcat(dst, temp);
710 append_acs(string_desc * dst, int code, char *src)
712 if (VALID_STRING(src) && strlen(src) == 1) {
713 append_acs0(dst, code, src, 0);
718 * The ko capability, if present, consists of a comma-separated capability
719 * list. For each capability, we may assume there is a keycap that sends the
720 * string which is the value of that capability.
722 #define DATA(from, to) { { from }, { to } }
727 static assoc const ko_xlate[] =
729 DATA("al", "kil1"), /* insert line key -> KEY_IL */
730 DATA("bt", "kcbt"), /* back tab -> KEY_BTAB */
731 DATA("cd", "ked"), /* clear-to-eos key -> KEY_EOL */
732 DATA("ce", "kel"), /* clear-to-eol key -> KEY_EOS */
733 DATA("cl", "kclr"), /* clear key -> KEY_CLEAR */
734 DATA("ct", "tbc"), /* clear all tabs -> KEY_CATAB */
735 DATA("dc", "kdch1"), /* delete char -> KEY_DC */
736 DATA("dl", "kdl1"), /* delete line -> KEY_DL */
737 DATA("do", "kcud1"), /* down key -> KEY_DOWN */
738 DATA("ei", "krmir"), /* exit insert key -> KEY_EIC */
739 DATA("ho", "khome"), /* home key -> KEY_HOME */
740 DATA("ic", "kich1"), /* insert char key -> KEY_IC */
741 DATA("im", "kIC"), /* insert-mode key -> KEY_SIC */
742 DATA("le", "kcub1"), /* le key -> KEY_LEFT */
743 DATA("nd", "kcuf1"), /* nd key -> KEY_RIGHT */
744 DATA("nl", "kent"), /* new line key -> KEY_ENTER */
745 DATA("st", "khts"), /* set-tab key -> KEY_STAB */
747 DATA("up", "kcuu1"), /* up-arrow key -> KEY_UP */
751 * This routine fills in string caps that either had defaults under
752 * termcap or can be manufactured from obsolete termcap capabilities.
753 * It was lifted from Ross Ridge's mytinfo package.
756 static const char C_CR[] = "\r";
757 static const char C_LF[] = "\n";
758 static const char C_BS[] = "\b";
759 static const char C_HT[] = "\t";
762 * This bit of legerdemain turns all the terminfo variable names into
763 * references to locations in the arrays Booleans, Numbers, and Strings ---
764 * precisely what's needed.
771 postprocess_termcap(TERMTYPE2 *tp, bool has_base)
773 char buf[MAX_LINE * 2 + 2];
777 (T_CALLED("postprocess_termcap(tp=%p, has_base=%d)"),
778 (void *) tp, has_base));
781 * TERMCAP DEFAULTS AND OBSOLETE-CAPABILITY TRANSLATIONS
783 * This first part of the code is the functional inverse of the
784 * fragment in capdefaults.c.
785 * ----------------------------------------------------------------------
788 /* if there was a tc entry, assume we picked up defaults via that */
790 if (WANTED(init_3string) && PRESENT(termcap_init2))
791 init_3string = _nc_save_str(termcap_init2);
793 if (WANTED(reset_2string) && PRESENT(termcap_reset))
794 reset_2string = _nc_save_str(termcap_reset);
796 if (WANTED(carriage_return)) {
797 if (carriage_return_delay > 0) {
798 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
799 "%s$<%d>", C_CR, carriage_return_delay);
800 carriage_return = _nc_save_str(buf);
802 carriage_return = _nc_save_str(C_CR);
804 if (WANTED(cursor_left)) {
805 if (backspace_delay > 0) {
806 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
807 "%s$<%d>", C_BS, backspace_delay);
808 cursor_left = _nc_save_str(buf);
809 } else if (backspaces_with_bs == 1)
810 cursor_left = _nc_save_str(C_BS);
811 else if (PRESENT(backspace_if_not_bs))
812 cursor_left = backspace_if_not_bs;
814 /* vi doesn't use "do", but it does seem to use nl (or '\n') instead */
815 if (WANTED(cursor_down)) {
816 if (PRESENT(linefeed_if_not_lf))
817 cursor_down = linefeed_if_not_lf;
818 else if (linefeed_is_newline != 1) {
819 if (new_line_delay > 0) {
820 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
821 "%s$<%d>", C_LF, new_line_delay);
822 cursor_down = _nc_save_str(buf);
824 cursor_down = _nc_save_str(C_LF);
827 if (WANTED(scroll_forward) && crt_no_scrolling != 1) {
828 if (PRESENT(linefeed_if_not_lf))
829 cursor_down = linefeed_if_not_lf;
830 else if (linefeed_is_newline != 1) {
831 if (new_line_delay > 0) {
832 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
833 "%s$<%d>", C_LF, new_line_delay);
834 scroll_forward = _nc_save_str(buf);
836 scroll_forward = _nc_save_str(C_LF);
839 if (WANTED(newline)) {
840 if (linefeed_is_newline == 1) {
841 if (new_line_delay > 0) {
842 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
843 "%s$<%d>", C_LF, new_line_delay);
844 newline = _nc_save_str(buf);
846 newline = _nc_save_str(C_LF);
847 } else if (PRESENT(carriage_return) && PRESENT(scroll_forward)) {
848 _nc_str_init(&result, buf, sizeof(buf));
849 if (_nc_safe_strcat(&result, carriage_return)
850 && _nc_safe_strcat(&result, scroll_forward))
851 newline = _nc_save_str(buf);
852 } else if (PRESENT(carriage_return) && PRESENT(cursor_down)) {
853 _nc_str_init(&result, buf, sizeof(buf));
854 if (_nc_safe_strcat(&result, carriage_return)
855 && _nc_safe_strcat(&result, cursor_down))
856 newline = _nc_save_str(buf);
862 * Inverse of capdefaults.c code ends here.
863 * ----------------------------------------------------------------------
865 * TERMCAP-TO TERMINFO MAPPINGS FOR SOURCE TRANSLATION
867 * These translations will *not* be inverted by tgetent().
872 * We wait until now to decide if we've got a working cr because even
873 * one that doesn't work can be used for newline. Unfortunately the
874 * space allocated for it is wasted.
876 if (return_does_clr_eol == 1 || no_correctly_working_cr == 1)
877 carriage_return = ABSENT_STRING;
880 * Supposedly most termcap entries have ta now and '\t' is no longer a
881 * default, but it doesn't seem to be true...
884 if (horizontal_tab_delay > 0) {
885 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
886 "%s$<%d>", C_HT, horizontal_tab_delay);
887 tab = _nc_save_str(buf);
889 tab = _nc_save_str(C_HT);
891 if (init_tabs == ABSENT_NUMERIC && has_hardware_tabs == TRUE)
895 * Assume we can beep with ^G unless we're given bl@.
898 bell = _nc_save_str("\007");
902 * Translate the old termcap :pt: capability to it#8 + ht=\t
904 if (has_hardware_tabs == TRUE) {
905 if (init_tabs != 8 && init_tabs != ABSENT_NUMERIC)
906 _nc_warning("hardware tabs with a width other than 8: %d", init_tabs);
908 if (PRESENT(tab) && _nc_capcmp(tab, C_HT))
909 _nc_warning("hardware tabs with a non-^I tab string %s",
913 tab = _nc_save_str(C_HT);
919 * Now translate the ko capability, if there is one. This
920 * isn't from mytinfo...
922 if (PRESENT(other_non_function_keys)) {
925 struct name_table_entry const *from_ptr;
926 struct name_table_entry const *to_ptr;
927 char buf2[MAX_TERMINFO_LENGTH];
930 /* we're going to use this for a special case later */
931 dp = strchr(other_non_function_keys, 'i');
932 foundim = (dp != 0) && (dp[1] == 'm');
934 /* look at each comma-separated capability in the ko string... */
935 for (base = other_non_function_keys;
936 (cp = strchr(base, ',')) != 0;
938 size_t len = (unsigned) (cp - base);
942 for (n = 0; n < SIZEOF(ko_xlate); ++n) {
943 if (len == strlen(ko_xlate[n].from)
944 && strncmp(ko_xlate[n].from, base, len) == 0) {
950 _nc_warning("unknown capability `%.*s' in ko string",
953 } else if (ap->to[0] == '\0') /* ignore it */
956 /* now we know we found a match in ko_table, so... */
958 from_ptr = _nc_find_entry(ap->from, _nc_get_hash_table(TRUE));
959 to_ptr = _nc_find_entry(ap->to, _nc_get_hash_table(FALSE));
961 if (!from_ptr || !to_ptr) /* should never happen! */
962 _nc_err_abort("ko translation table is invalid, I give up");
964 if (WANTED(tp->Strings[from_ptr->nte_index])) {
965 _nc_warning("no value for ko capability %s", ap->from);
969 if (tp->Strings[to_ptr->nte_index]) {
970 const char *s = tp->Strings[from_ptr->nte_index];
971 const char *t = tp->Strings[to_ptr->nte_index];
972 /* There's no point in warning about it if it is the same
973 * string; that's just an inefficiency.
975 if (VALID_STRING(s) && VALID_STRING(t) && strcmp(s, t) != 0)
976 _nc_warning("%s (%s) already has an explicit value %s, ignoring ko",
977 ap->to, ap->from, t);
982 * The magic moment -- copy the mapped key string over,
983 * stripping out padding.
985 bp = tp->Strings[from_ptr->nte_index];
986 if (VALID_STRING(bp)) {
987 for (dp = buf2; *bp; bp++) {
988 if (bp[0] == '$' && bp[1] == '<') {
989 while (*bp && *bp != '>') {
997 tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2);
999 tp->Strings[to_ptr->nte_index] = bp;
1004 * Note: ko=im and ko=ic both want to grab the `Insert'
1005 * keycap. There's a kich1 but no ksmir, so the ic capability
1006 * got mapped to kich1 and im to kIC to avoid a collision.
1007 * If the description has im but not ic, hack kIC back to kich1.
1009 if (foundim && WANTED(key_ic) && PRESENT(key_sic)) {
1011 key_sic = ABSENT_STRING;
1017 if (WANTED(key_backspace))
1018 key_backspace = _nc_save_str(C_BS);
1019 if (WANTED(key_left))
1020 key_left = _nc_save_str(C_BS);
1021 if (WANTED(key_down))
1022 key_down = _nc_save_str(C_LF);
1027 * Translate XENIX forms characters.
1029 if (PRESENT(acs_ulcorner) ||
1030 PRESENT(acs_llcorner) ||
1031 PRESENT(acs_urcorner) ||
1032 PRESENT(acs_lrcorner) ||
1033 PRESENT(acs_ltee) ||
1034 PRESENT(acs_rtee) ||
1035 PRESENT(acs_btee) ||
1036 PRESENT(acs_ttee) ||
1037 PRESENT(acs_hline) ||
1038 PRESENT(acs_vline) ||
1039 PRESENT(acs_plus)) {
1040 char buf2[MAX_TERMCAP_LENGTH];
1042 _nc_str_init(&result, buf2, sizeof(buf2));
1043 _nc_safe_strcat(&result, acs_chars);
1045 append_acs(&result, 'j', acs_lrcorner);
1046 append_acs(&result, 'k', acs_urcorner);
1047 append_acs(&result, 'l', acs_ulcorner);
1048 append_acs(&result, 'm', acs_llcorner);
1049 append_acs(&result, 'n', acs_plus);
1050 append_acs(&result, 'q', acs_hline);
1051 append_acs(&result, 't', acs_ltee);
1052 append_acs(&result, 'u', acs_rtee);
1053 append_acs(&result, 'v', acs_btee);
1054 append_acs(&result, 'w', acs_ttee);
1055 append_acs(&result, 'x', acs_vline);
1058 acs_chars = _nc_save_str(buf2);
1059 _nc_warning("acsc string synthesized from XENIX capabilities");
1061 } else if (acs_chars == ABSENT_STRING
1062 && PRESENT(enter_alt_charset_mode)
1063 && PRESENT(exit_alt_charset_mode)) {
1064 acs_chars = _nc_save_str(VT_ACSC);
1070 postprocess_terminfo(TERMTYPE2 *tp)
1073 (T_CALLED("postprocess_terminfo(tp=%p)"),
1077 * TERMINFO-TO-TERMINFO MAPPINGS FOR SOURCE TRANSLATION
1078 * ----------------------------------------------------------------------
1082 * Translate AIX forms characters.
1084 if (PRESENT(box_chars_1)) {
1085 char buf2[MAX_TERMCAP_LENGTH];
1088 _nc_str_init(&result, buf2, sizeof(buf2));
1089 _nc_safe_strcat(&result, acs_chars);
1091 append_acs0(&result, 'l', box_chars_1, 0); /* ACS_ULCORNER */
1092 append_acs0(&result, 'q', box_chars_1, 1); /* ACS_HLINE */
1093 append_acs0(&result, 'k', box_chars_1, 2); /* ACS_URCORNER */
1094 append_acs0(&result, 'x', box_chars_1, 3); /* ACS_VLINE */
1095 append_acs0(&result, 'j', box_chars_1, 4); /* ACS_LRCORNER */
1096 append_acs0(&result, 'm', box_chars_1, 5); /* ACS_LLCORNER */
1097 append_acs0(&result, 'w', box_chars_1, 6); /* ACS_TTEE */
1098 append_acs0(&result, 'u', box_chars_1, 7); /* ACS_RTEE */
1099 append_acs0(&result, 'v', box_chars_1, 8); /* ACS_BTEE */
1100 append_acs0(&result, 't', box_chars_1, 9); /* ACS_LTEE */
1101 append_acs0(&result, 'n', box_chars_1, 10); /* ACS_PLUS */
1104 acs_chars = _nc_save_str(buf2);
1105 _nc_warning("acsc string synthesized from AIX capabilities");
1106 box_chars_1 = ABSENT_STRING;
1110 * ----------------------------------------------------------------------
1116 * Do a linear search through the terminfo tables to find a given full-name.
1117 * We don't expect to do this often, so there's no hashing function.
1119 * In effect, this scans through the 3 lists of full-names, and looks them
1120 * up in _nc_info_table, which is organized so that the nte_index fields are
1121 * sorted, but the nte_type fields are not necessarily grouped together.
1123 static struct name_table_entry const *
1124 lookup_fullname(const char *find)
1130 NCURSES_CONST char *const *names;
1146 for (count = 0; names[count] != 0; count++) {
1147 if (!strcmp(names[count], find)) {
1148 struct name_table_entry const *entry_ptr = _nc_get_table(FALSE);
1149 while (entry_ptr->nte_type != state
1150 || entry_ptr->nte_index != count)
1158 /* parse_entry.c ends here */