1 /****************************************************************************
2 * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1996-on *
33 ****************************************************************************/
36 * parse_entry.c -- compile one terminfo or termcap entry
38 * Get an exact in-core representation of an entry. Don't
39 * try to resolve use or tc capabilities, that is someone
40 * else's job. Depends on the lexical analyzer to get tokens
41 * from the input stream.
44 #define __INTERNAL_CAPS_VISIBLE
45 #include <curses.priv.h>
50 MODULE_ID("$Id: parse_entry.c,v 1.91 2017/08/26 16:13:34 tom Exp $")
53 static short const parametrized[] =
56 #include <parametrized.h>
59 static void postprocess_termcap(TERMTYPE2 *, bool);
60 static void postprocess_terminfo(TERMTYPE2 *);
61 static struct name_table_entry const *lookup_fullname(const char *name);
65 static struct name_table_entry const *
66 _nc_extend_names(ENTRY * entryp, char *name, int token_type)
68 static struct name_table_entry temp;
69 TERMTYPE2 *tp = &(entryp->tterm);
73 unsigned first, last, n;
79 last = tp->ext_Booleans;
80 offset = tp->ext_Booleans;
81 tindex = tp->num_Booleans;
84 first = tp->ext_Booleans;
85 last = tp->ext_Numbers + first;
86 offset = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
87 tindex = tp->num_Numbers;
90 first = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
91 last = tp->ext_Strings + first;
92 offset = (unsigned) (tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings);
93 tindex = tp->num_Strings;
96 actual = NUM_EXT_NAMES(tp);
97 for (n = 0; n < actual; n++) {
98 if (!strcmp(name, tp->ext_Names[n])) {
99 if (n > (unsigned) (tp->ext_Booleans + tp->ext_Numbers)) {
101 } else if (n > tp->ext_Booleans) {
104 token_type = BOOLEAN;
106 return _nc_extend_names(entryp, name, token_type);
109 /* Well, we are given a cancel for a name that we don't recognize */
110 return _nc_extend_names(entryp, name, STRING);
115 /* Adjust the 'offset' (insertion-point) to keep the lists of extended
118 for (n = first, found = FALSE; n < last; n++) {
119 int cmp = strcmp(tp->ext_Names[n], name);
125 switch (token_type) {
140 #define for_each_value(max) \
141 for (last = (unsigned) (max - 1); last > tindex; last--)
144 switch (token_type) {
148 TYPE_REALLOC(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans);
149 for_each_value(tp->num_Booleans)
150 tp->Booleans[last] = tp->Booleans[last - 1];
155 TYPE_REALLOC(NCURSES_INT2, tp->num_Numbers, tp->Numbers);
156 for_each_value(tp->num_Numbers)
157 tp->Numbers[last] = tp->Numbers[last - 1];
162 TYPE_REALLOC(char *, tp->num_Strings, tp->Strings);
163 for_each_value(tp->num_Strings)
164 tp->Strings[last] = tp->Strings[last - 1];
167 actual = NUM_EXT_NAMES(tp);
168 TYPE_REALLOC(char *, actual, tp->ext_Names);
169 while (--actual > offset)
170 tp->ext_Names[actual] = tp->ext_Names[actual - 1];
171 tp->ext_Names[offset] = _nc_save_str(name);
174 temp.nte_name = tp->ext_Names[offset];
175 temp.nte_type = token_type;
176 temp.nte_index = (short) tindex;
181 #endif /* NCURSES_XNAMES */
184 valid_entryname(const char *name)
188 while ((ch = UChar(*name++)) != '\0') {
189 if (ch <= ' ' || ch > '~' || ch == '/') {
199 * _nc_parse_entry(entry, literal, silent)
201 * Compile one entry. Doesn't try to resolve use or tc capabilities.
203 * found-forward-use = FALSE
204 * re-initialise internal arrays
206 * if the token was not a name in column 1, complain and die
207 * save names in entry's string table
208 * while (get_token() is not EOF and not NAMES)
209 * check for existence and type-correctness
210 * enter cap into structure
212 * save string in entry's string table
216 #define BAD_TC_USAGE if (!bad_tc_usage) \
217 { bad_tc_usage = TRUE; \
218 _nc_warning("Legacy termcap allows only a trailing tc= clause"); }
220 #define MAX_NUMBER 0x7fff /* positive shorts only */
223 _nc_parse_entry(ENTRY * entryp, int literal, bool silent)
226 struct name_table_entry const *entry_ptr;
229 bool bad_tc_usage = FALSE;
231 token_type = _nc_get_token(silent);
233 if (token_type == EOF)
235 if (token_type != NAMES)
236 _nc_err_abort("Entry does not start with terminal names in column one");
238 _nc_init_entry(entryp);
240 entryp->cstart = _nc_comment_start;
241 entryp->cend = _nc_comment_end;
242 entryp->startline = _nc_start_line;
243 DEBUG(2, ("Comment range is %ld to %ld", entryp->cstart, entryp->cend));
246 * Strip off the 2-character termcap name, if present. Originally termcap
247 * used that as an indexing aid. We can retain 2-character terminfo names,
248 * but note that they would be lost if we translate to/from termcap. This
249 * feature is supposedly obsolete since "newer" BSD implementations do not
250 * use it; however our reference for this feature is SunOS 4.x, which
251 * implemented it. Note that the resulting terminal type was never the
252 * 2-character name, but was instead the first alias after that.
254 #define ok_TC2(s) (isgraph(UChar(s)) && (s) != '|')
255 ptr = _nc_curr_token.tk_name;
256 if (_nc_syntax == SYN_TERMCAP
258 && !_nc_user_definable
261 if (ok_TC2(ptr[0]) && ok_TC2(ptr[1]) && (ptr[2] == '|')) {
263 _nc_curr_token.tk_name[2] = '\0';
267 entryp->tterm.str_table = entryp->tterm.term_names = _nc_save_str(ptr);
269 if (entryp->tterm.str_table == 0)
272 DEBUG(1, ("Starting '%s'", ptr));
275 * We do this because the one-token lookahead in the parse loop
276 * results in the terminal type getting prematurely set to correspond
277 * to that of the next entry.
279 name = _nc_first_name(entryp->tterm.term_names);
280 if (!valid_entryname(name)) {
281 _nc_warning("invalid entry name \"%s\"", name);
286 /* check for overly-long names and aliases */
287 for (base = entryp->tterm.term_names; (ptr = strchr(base, '|')) != 0;
289 if (ptr - base > MAX_ALIAS) {
290 _nc_warning("%s `%.*s' may be too long",
291 (base == entryp->tterm.term_names)
294 (int) (ptr - base), base);
300 for (token_type = _nc_get_token(silent);
301 token_type != EOF && token_type != NAMES;
302 token_type = _nc_get_token(silent)) {
303 bool is_use = (strcmp(_nc_curr_token.tk_name, "use") == 0);
304 bool is_tc = !is_use && (strcmp(_nc_curr_token.tk_name, "tc") == 0);
305 if (is_use || is_tc) {
306 if (!VALID_STRING(_nc_curr_token.tk_valstring)
307 || _nc_curr_token.tk_valstring[0] == '\0') {
308 _nc_warning("missing name for use-clause");
310 } else if (!valid_entryname(_nc_curr_token.tk_valstring)) {
311 _nc_warning("invalid name for use-clause \"%s\"",
312 _nc_curr_token.tk_valstring);
314 } else if (entryp->nuses >= MAX_USES) {
315 _nc_warning("too many use-clauses, ignored \"%s\"",
316 _nc_curr_token.tk_valstring);
319 entryp->uses[entryp->nuses].name = _nc_save_str(_nc_curr_token.tk_valstring);
320 entryp->uses[entryp->nuses].line = _nc_curr_line;
322 if (entryp->nuses > 1 && is_tc) {
326 /* normal token lookup */
327 entry_ptr = _nc_find_entry(_nc_curr_token.tk_name,
328 _nc_get_hash_table(_nc_syntax));
331 * Our kluge to handle aliasing. The reason it's done
332 * this ugly way, with a linear search, is so the hashing
333 * machinery doesn't have to be made really complicated
334 * (also we get better warnings this way). No point in
335 * making this case fast, aliased caps aren't common now
336 * and will get rarer.
338 if (entry_ptr == NOTFOUND) {
339 const struct alias *ap;
341 if (_nc_syntax == SYN_TERMCAP) {
342 if (entryp->nuses != 0) {
345 for (ap = _nc_get_alias_table(TRUE); ap->from; ap++)
346 if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) {
347 if (ap->to == (char *) 0) {
348 _nc_warning("%s (%s termcap extension) ignored",
349 ap->from, ap->source);
353 entry_ptr = _nc_find_entry(ap->to,
354 _nc_get_hash_table(TRUE));
355 if (entry_ptr && !silent)
356 _nc_warning("%s (%s termcap extension) aliased to %s",
357 ap->from, ap->source, ap->to);
360 } else { /* if (_nc_syntax == SYN_TERMINFO) */
361 for (ap = _nc_get_alias_table(FALSE); ap->from; ap++)
362 if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) {
363 if (ap->to == (char *) 0) {
364 _nc_warning("%s (%s terminfo extension) ignored",
365 ap->from, ap->source);
369 entry_ptr = _nc_find_entry(ap->to,
370 _nc_get_hash_table(FALSE));
371 if (entry_ptr && !silent)
372 _nc_warning("%s (%s terminfo extension) aliased to %s",
373 ap->from, ap->source, ap->to);
377 if (entry_ptr == NOTFOUND) {
378 entry_ptr = lookup_fullname(_nc_curr_token.tk_name);
384 * If we have extended-names active, we will automatically
385 * define a name based on its context.
387 if (entry_ptr == NOTFOUND
388 && _nc_user_definable
389 && (entry_ptr = _nc_extend_names(entryp,
390 _nc_curr_token.tk_name,
392 if (_nc_tracing >= DEBUG_LEVEL(1))
393 _nc_warning("extended capability '%s'", _nc_curr_token.tk_name);
395 #endif /* NCURSES_XNAMES */
397 /* can't find this cap name, not even as an alias */
398 if (entry_ptr == NOTFOUND) {
400 _nc_warning("unknown capability '%s'",
401 _nc_curr_token.tk_name);
405 /* deal with bad type/value combinations. */
406 if (token_type == CANCEL) {
408 * Prefer terminfo in this (long-obsolete) ambiguity:
410 if (!strcmp("ma", _nc_curr_token.tk_name)) {
411 entry_ptr = _nc_find_type_entry("ma", NUMBER,
413 assert(entry_ptr != 0);
415 } else if (entry_ptr->nte_type != token_type) {
417 * Nasty special cases here handle situations in which type
418 * information can resolve name clashes. Normal lookup
419 * finds the last instance in the capability table of a
420 * given name, regardless of type. find_type_entry looks
421 * for a first matching instance with given type. So as
422 * long as all ambiguous names occur in pairs of distinct
423 * type, this will do the job.
426 if (token_type == NUMBER
427 && !strcmp("ma", _nc_curr_token.tk_name)) {
428 /* tell max_attributes from arrow_key_map */
429 entry_ptr = _nc_find_type_entry("ma", NUMBER,
431 assert(entry_ptr != 0);
433 } else if (token_type == STRING
434 && !strcmp("MT", _nc_curr_token.tk_name)) {
435 /* map terminfo's string MT to MT */
436 entry_ptr = _nc_find_type_entry("MT", STRING,
438 assert(entry_ptr != 0);
440 } else if (token_type == BOOLEAN
441 && entry_ptr->nte_type == STRING) {
442 /* treat strings without following "=" as empty strings */
445 /* we couldn't recover; skip this token */
447 const char *type_name;
448 switch (entry_ptr->nte_type) {
450 type_name = "boolean";
453 type_name = "string";
456 type_name = "numeric";
459 type_name = "unknown";
462 _nc_warning("wrong type used for %s capability '%s'",
463 type_name, _nc_curr_token.tk_name);
469 /* now we know that the type/value combination is OK */
470 switch (token_type) {
472 switch (entry_ptr->nte_type) {
474 entryp->tterm.Booleans[entry_ptr->nte_index] = CANCELLED_BOOLEAN;
478 entryp->tterm.Numbers[entry_ptr->nte_index] = CANCELLED_NUMERIC;
482 entryp->tterm.Strings[entry_ptr->nte_index] = CANCELLED_STRING;
488 entryp->tterm.Booleans[entry_ptr->nte_index] = TRUE;
492 if (_nc_curr_token.tk_valnumber > MAX_NUMBER) {
493 entryp->tterm.Numbers[entry_ptr->nte_index] = MAX_NUMBER;
495 entryp->tterm.Numbers[entry_ptr->nte_index] =
496 (short) _nc_curr_token.tk_valnumber;
501 ptr = _nc_curr_token.tk_valstring;
502 if (_nc_syntax == SYN_TERMCAP)
503 ptr = _nc_captoinfo(_nc_curr_token.tk_name,
505 parametrized[entry_ptr->nte_index]);
506 entryp->tterm.Strings[entry_ptr->nte_index] = _nc_save_str(ptr);
511 _nc_warning("unknown token type");
512 _nc_panic_mode((char) ((_nc_syntax == SYN_TERMCAP) ? ':' : ','));
515 } /* end else cur_token.name != "use" */
517 continue; /* cannot have a label w/o statement */
518 } /* endwhile (not EOF and not NAMES) */
520 _nc_push_token(token_type);
521 _nc_set_type(_nc_first_name(entryp->tterm.term_names));
524 * Try to deduce as much as possible from extension capabilities
525 * (this includes obsolete BSD capabilities). Sigh...it would be more
526 * space-efficient to call this after use resolution, but it has
527 * to be done before entry allocation is wrapped up.
530 if (_nc_syntax == SYN_TERMCAP) {
531 bool has_base_entry = FALSE;
534 * Don't insert defaults if this is a `+' entry meant only
535 * for inclusion in other entries (not sure termcap ever
536 * had these, actually).
538 if (strchr(entryp->tterm.term_names, '+')) {
539 has_base_entry = TRUE;
543 * Otherwise, look for a base entry that will already
544 * have picked up defaults via translation.
546 for (i = 0; i < entryp->nuses; i++)
547 if (!strchr((char *) entryp->uses[i].name, '+'))
548 has_base_entry = TRUE;
551 postprocess_termcap(&entryp->tterm, has_base_entry);
553 postprocess_terminfo(&entryp->tterm);
555 _nc_wrap_entry(entryp, FALSE);
561 _nc_capcmp(const char *s, const char *t)
562 /* compare two string capabilities, stripping out padding */
564 bool ok_s = VALID_STRING(s);
565 bool ok_t = VALID_STRING(t);
569 if (s[0] == '$' && s[1] == '<') {
571 if (!(isdigit(UChar(*s))
581 if (t[0] == '$' && t[1] == '<') {
583 if (!(isdigit(UChar(*t))
593 /* we've now pushed s and t past any padding they pointed at */
595 if (*s == '\0' && *t == '\0')
601 /* else *s == *t but one is not NUL, so continue */
604 } else if (ok_s || ok_t) {
611 append_acs0(string_desc * dst, int code, int src)
615 temp[0] = (char) code;
616 temp[1] = (char) src;
618 _nc_safe_strcat(dst, temp);
623 append_acs(string_desc * dst, int code, char *src)
625 if (VALID_STRING(src) && strlen(src) == 1) {
626 append_acs0(dst, code, *src);
631 * The ko capability, if present, consists of a comma-separated capability
632 * list. For each capability, we may assume there is a keycap that sends the
633 * string which is the value of that capability.
635 #define DATA(from, to) { { from }, { to } }
640 static assoc const ko_xlate[] =
642 DATA("al", "kil1"), /* insert line key -> KEY_IL */
643 DATA("bt", "kcbt"), /* back tab -> KEY_BTAB */
644 DATA("cd", "ked"), /* clear-to-eos key -> KEY_EOL */
645 DATA("ce", "kel"), /* clear-to-eol key -> KEY_EOS */
646 DATA("cl", "kclr"), /* clear key -> KEY_CLEAR */
647 DATA("ct", "tbc"), /* clear all tabs -> KEY_CATAB */
648 DATA("dc", "kdch1"), /* delete char -> KEY_DC */
649 DATA("dl", "kdl1"), /* delete line -> KEY_DL */
650 DATA("do", "kcud1"), /* down key -> KEY_DOWN */
651 DATA("ei", "krmir"), /* exit insert key -> KEY_EIC */
652 DATA("ho", "khome"), /* home key -> KEY_HOME */
653 DATA("ic", "kich1"), /* insert char key -> KEY_IC */
654 DATA("im", "kIC"), /* insert-mode key -> KEY_SIC */
655 DATA("le", "kcub1"), /* le key -> KEY_LEFT */
656 DATA("nd", "kcuf1"), /* nd key -> KEY_RIGHT */
657 DATA("nl", "kent"), /* new line key -> KEY_ENTER */
658 DATA("st", "khts"), /* set-tab key -> KEY_STAB */
660 DATA("up", "kcuu1"), /* up-arrow key -> KEY_UP */
664 * This routine fills in string caps that either had defaults under
665 * termcap or can be manufactured from obsolete termcap capabilities.
666 * It was lifted from Ross Ridge's mytinfo package.
669 static const char C_CR[] = "\r";
670 static const char C_LF[] = "\n";
671 static const char C_BS[] = "\b";
672 static const char C_HT[] = "\t";
675 * This bit of legerdemain turns all the terminfo variable names into
676 * references to locations in the arrays Booleans, Numbers, and Strings ---
677 * precisely what's needed.
684 postprocess_termcap(TERMTYPE2 *tp, bool has_base)
686 char buf[MAX_LINE * 2 + 2];
690 * TERMCAP DEFAULTS AND OBSOLETE-CAPABILITY TRANSLATIONS
692 * This first part of the code is the functional inverse of the
693 * fragment in capdefaults.c.
694 * ----------------------------------------------------------------------
697 /* if there was a tc entry, assume we picked up defaults via that */
699 if (WANTED(init_3string) && PRESENT(termcap_init2))
700 init_3string = _nc_save_str(termcap_init2);
702 if (WANTED(reset_2string) && PRESENT(termcap_reset))
703 reset_2string = _nc_save_str(termcap_reset);
705 if (WANTED(carriage_return)) {
706 if (carriage_return_delay > 0) {
707 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
708 "%s$<%d>", C_CR, carriage_return_delay);
709 carriage_return = _nc_save_str(buf);
711 carriage_return = _nc_save_str(C_CR);
713 if (WANTED(cursor_left)) {
714 if (backspace_delay > 0) {
715 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
716 "%s$<%d>", C_BS, backspace_delay);
717 cursor_left = _nc_save_str(buf);
718 } else if (backspaces_with_bs == 1)
719 cursor_left = _nc_save_str(C_BS);
720 else if (PRESENT(backspace_if_not_bs))
721 cursor_left = backspace_if_not_bs;
723 /* vi doesn't use "do", but it does seem to use nl (or '\n') instead */
724 if (WANTED(cursor_down)) {
725 if (PRESENT(linefeed_if_not_lf))
726 cursor_down = linefeed_if_not_lf;
727 else if (linefeed_is_newline != 1) {
728 if (new_line_delay > 0) {
729 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
730 "%s$<%d>", C_LF, new_line_delay);
731 cursor_down = _nc_save_str(buf);
733 cursor_down = _nc_save_str(C_LF);
736 if (WANTED(scroll_forward) && crt_no_scrolling != 1) {
737 if (PRESENT(linefeed_if_not_lf))
738 cursor_down = linefeed_if_not_lf;
739 else if (linefeed_is_newline != 1) {
740 if (new_line_delay > 0) {
741 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
742 "%s$<%d>", C_LF, new_line_delay);
743 scroll_forward = _nc_save_str(buf);
745 scroll_forward = _nc_save_str(C_LF);
748 if (WANTED(newline)) {
749 if (linefeed_is_newline == 1) {
750 if (new_line_delay > 0) {
751 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
752 "%s$<%d>", C_LF, new_line_delay);
753 newline = _nc_save_str(buf);
755 newline = _nc_save_str(C_LF);
756 } else if (PRESENT(carriage_return) && PRESENT(scroll_forward)) {
757 _nc_str_init(&result, buf, sizeof(buf));
758 if (_nc_safe_strcat(&result, carriage_return)
759 && _nc_safe_strcat(&result, scroll_forward))
760 newline = _nc_save_str(buf);
761 } else if (PRESENT(carriage_return) && PRESENT(cursor_down)) {
762 _nc_str_init(&result, buf, sizeof(buf));
763 if (_nc_safe_strcat(&result, carriage_return)
764 && _nc_safe_strcat(&result, cursor_down))
765 newline = _nc_save_str(buf);
771 * Inverse of capdefaults.c code ends here.
772 * ----------------------------------------------------------------------
774 * TERMCAP-TO TERMINFO MAPPINGS FOR SOURCE TRANSLATION
776 * These translations will *not* be inverted by tgetent().
781 * We wait until now to decide if we've got a working cr because even
782 * one that doesn't work can be used for newline. Unfortunately the
783 * space allocated for it is wasted.
785 if (return_does_clr_eol == 1 || no_correctly_working_cr == 1)
786 carriage_return = ABSENT_STRING;
789 * Supposedly most termcap entries have ta now and '\t' is no longer a
790 * default, but it doesn't seem to be true...
793 if (horizontal_tab_delay > 0) {
794 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
795 "%s$<%d>", C_HT, horizontal_tab_delay);
796 tab = _nc_save_str(buf);
798 tab = _nc_save_str(C_HT);
800 if (init_tabs == ABSENT_NUMERIC && has_hardware_tabs == TRUE)
804 * Assume we can beep with ^G unless we're given bl@.
807 bell = _nc_save_str("\007");
811 * Translate the old termcap :pt: capability to it#8 + ht=\t
813 if (has_hardware_tabs == TRUE) {
814 if (init_tabs != 8 && init_tabs != ABSENT_NUMERIC)
815 _nc_warning("hardware tabs with a width other than 8: %d", init_tabs);
817 if (PRESENT(tab) && _nc_capcmp(tab, C_HT))
818 _nc_warning("hardware tabs with a non-^I tab string %s",
822 tab = _nc_save_str(C_HT);
828 * Now translate the ko capability, if there is one. This
829 * isn't from mytinfo...
831 if (PRESENT(other_non_function_keys)) {
834 struct name_table_entry const *from_ptr;
835 struct name_table_entry const *to_ptr;
836 char buf2[MAX_TERMINFO_LENGTH];
839 /* we're going to use this for a special case later */
840 dp = strchr(other_non_function_keys, 'i');
841 foundim = (dp != 0) && (dp[1] == 'm');
843 /* look at each comma-separated capability in the ko string... */
844 for (base = other_non_function_keys;
845 (cp = strchr(base, ',')) != 0;
847 size_t len = (unsigned) (cp - base);
851 for (n = 0; n < SIZEOF(ko_xlate); ++n) {
852 if (len == strlen(ko_xlate[n].from)
853 && strncmp(ko_xlate[n].from, base, len) == 0) {
859 _nc_warning("unknown capability `%.*s' in ko string",
862 } else if (ap->to[0] == '\0') /* ignore it */
865 /* now we know we found a match in ko_table, so... */
867 from_ptr = _nc_find_entry(ap->from, _nc_get_hash_table(TRUE));
868 to_ptr = _nc_find_entry(ap->to, _nc_get_hash_table(FALSE));
870 if (!from_ptr || !to_ptr) /* should never happen! */
871 _nc_err_abort("ko translation table is invalid, I give up");
873 if (WANTED(tp->Strings[from_ptr->nte_index])) {
874 _nc_warning("no value for ko capability %s", ap->from);
878 if (tp->Strings[to_ptr->nte_index]) {
879 const char *s = tp->Strings[from_ptr->nte_index];
880 const char *t = tp->Strings[to_ptr->nte_index];
881 /* There's no point in warning about it if it's the same
882 * string; that's just an inefficiency.
884 if (VALID_STRING(s) && VALID_STRING(t) && strcmp(s, t) != 0)
885 _nc_warning("%s (%s) already has an explicit value %s, ignoring ko",
886 ap->to, ap->from, t);
891 * The magic moment -- copy the mapped key string over,
892 * stripping out padding.
894 bp = tp->Strings[from_ptr->nte_index];
895 if (VALID_STRING(bp)) {
896 for (dp = buf2; *bp; bp++) {
897 if (bp[0] == '$' && bp[1] == '<') {
898 while (*bp && *bp != '>') {
906 tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2);
908 tp->Strings[to_ptr->nte_index] = bp;
913 * Note: ko=im and ko=ic both want to grab the `Insert'
914 * keycap. There's a kich1 but no ksmir, so the ic capability
915 * got mapped to kich1 and im to kIC to avoid a collision.
916 * If the description has im but not ic, hack kIC back to kich1.
918 if (foundim && WANTED(key_ic) && PRESENT(key_sic)) {
920 key_sic = ABSENT_STRING;
926 if (WANTED(key_backspace))
927 key_backspace = _nc_save_str(C_BS);
928 if (WANTED(key_left))
929 key_left = _nc_save_str(C_BS);
930 if (WANTED(key_down))
931 key_down = _nc_save_str(C_LF);
936 * Translate XENIX forms characters.
938 if (PRESENT(acs_ulcorner) ||
939 PRESENT(acs_llcorner) ||
940 PRESENT(acs_urcorner) ||
941 PRESENT(acs_lrcorner) ||
946 PRESENT(acs_hline) ||
947 PRESENT(acs_vline) ||
949 char buf2[MAX_TERMCAP_LENGTH];
951 _nc_str_init(&result, buf2, sizeof(buf2));
952 _nc_safe_strcat(&result, acs_chars);
954 append_acs(&result, 'j', acs_lrcorner);
955 append_acs(&result, 'k', acs_urcorner);
956 append_acs(&result, 'l', acs_ulcorner);
957 append_acs(&result, 'm', acs_llcorner);
958 append_acs(&result, 'n', acs_plus);
959 append_acs(&result, 'q', acs_hline);
960 append_acs(&result, 't', acs_ltee);
961 append_acs(&result, 'u', acs_rtee);
962 append_acs(&result, 'v', acs_btee);
963 append_acs(&result, 'w', acs_ttee);
964 append_acs(&result, 'x', acs_vline);
967 acs_chars = _nc_save_str(buf2);
968 _nc_warning("acsc string synthesized from XENIX capabilities");
970 } else if (acs_chars == ABSENT_STRING
971 && PRESENT(enter_alt_charset_mode)
972 && PRESENT(exit_alt_charset_mode)) {
973 acs_chars = _nc_save_str(VT_ACSC);
978 postprocess_terminfo(TERMTYPE2 *tp)
981 * TERMINFO-TO-TERMINFO MAPPINGS FOR SOURCE TRANSLATION
982 * ----------------------------------------------------------------------
986 * Translate AIX forms characters.
988 if (PRESENT(box_chars_1)) {
989 char buf2[MAX_TERMCAP_LENGTH];
992 _nc_str_init(&result, buf2, sizeof(buf2));
993 _nc_safe_strcat(&result, acs_chars);
995 append_acs0(&result, 'l', box_chars_1[0]); /* ACS_ULCORNER */
996 append_acs0(&result, 'q', box_chars_1[1]); /* ACS_HLINE */
997 append_acs0(&result, 'k', box_chars_1[2]); /* ACS_URCORNER */
998 append_acs0(&result, 'x', box_chars_1[3]); /* ACS_VLINE */
999 append_acs0(&result, 'j', box_chars_1[4]); /* ACS_LRCORNER */
1000 append_acs0(&result, 'm', box_chars_1[5]); /* ACS_LLCORNER */
1001 append_acs0(&result, 'w', box_chars_1[6]); /* ACS_TTEE */
1002 append_acs0(&result, 'u', box_chars_1[7]); /* ACS_RTEE */
1003 append_acs0(&result, 'v', box_chars_1[8]); /* ACS_BTEE */
1004 append_acs0(&result, 't', box_chars_1[9]); /* ACS_LTEE */
1005 append_acs0(&result, 'n', box_chars_1[10]); /* ACS_PLUS */
1008 acs_chars = _nc_save_str(buf2);
1009 _nc_warning("acsc string synthesized from AIX capabilities");
1010 box_chars_1 = ABSENT_STRING;
1014 * ----------------------------------------------------------------------
1019 * Do a linear search through the terminfo tables to find a given full-name.
1020 * We don't expect to do this often, so there's no hashing function.
1022 * In effect, this scans through the 3 lists of full-names, and looks them
1023 * up in _nc_info_table, which is organized so that the nte_index fields are
1024 * sorted, but the nte_type fields are not necessarily grouped together.
1026 static struct name_table_entry const *
1027 lookup_fullname(const char *find)
1033 NCURSES_CONST char *const *names;
1049 for (count = 0; names[count] != 0; count++) {
1050 if (!strcmp(names[count], find)) {
1051 struct name_table_entry const *entry_ptr = _nc_get_table(FALSE);
1052 while (entry_ptr->nte_type != state
1053 || entry_ptr->nte_index != count)
1061 /* parse_entry.c ends here */