]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/parse_entry.c
ncurses 4.2
[ncurses.git] / ncurses / parse_entry.c
1 /****************************************************************************
2  * Copyright (c) 1998 Free Software Foundation, Inc.                        *
3  *                                                                          *
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:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
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.                               *
22  *                                                                          *
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       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  ****************************************************************************/
33
34
35 /*
36  *      parse_entry.c -- compile one terminfo or termcap entry
37  *
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.
42  */
43
44 #include <curses.priv.h>
45
46 #include <ctype.h>
47 #include <tic.h>
48 #define __INTERNAL_CAPS_VISIBLE
49 #include <term.h>
50 #include <term_entry.h>
51
52 MODULE_ID("$Id: parse_entry.c,v 1.22 1998/02/11 12:13:59 tom Exp $")
53
54 #ifdef LINT
55 static short const parametrized[] = { 0 };
56 #else
57 #include <parametrized.h>
58 #endif
59
60 struct token    _nc_curr_token;
61
62 static  void postprocess_termcap(TERMTYPE *, bool);
63 static  void postprocess_terminfo(TERMTYPE *);
64 static  struct name_table_entry const * lookup_fullname(const char *name);
65
66 /*
67  *      int
68  *      _nc_parse_entry(entry, literal, silent)
69  *
70  *      Compile one entry.  Doesn't try to resolve use or tc capabilities.
71  *
72  *      found-forward-use = FALSE
73  *      re-initialise internal arrays
74  *      get_token();
75  *      if the token was not a name in column 1, complain and die
76  *      save names in entry's string table
77  *      while (get_token() is not EOF and not NAMES)
78  *              check for existance and type-correctness
79  *              enter cap into structure
80  *              if STRING
81  *                  save string in entry's string table
82  *      push back token
83  */
84
85 int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
86 {
87     int                 token_type;
88     struct name_table_entry     const *entry_ptr;
89     char                        *ptr, namecpy[MAX_NAME_SIZE+1];
90
91     token_type = _nc_get_token();
92
93     if (token_type == EOF)
94         return(EOF);
95     if (token_type != NAMES)
96         _nc_err_abort("Entry does not start with terminal names in column one");
97
98     _nc_init_entry(&entryp->tterm);
99
100     entryp->cstart = _nc_comment_start;
101     entryp->cend = _nc_comment_end;
102     entryp->startline = _nc_start_line;
103     DEBUG(2, ("Comment range is %ld to %ld", entryp->cstart, entryp->cend));
104
105     /* junk the 2-character termcap name, if present */
106     ptr = _nc_curr_token.tk_name;
107     if (ptr[2] == '|')
108     {
109         ptr = _nc_curr_token.tk_name + 3;
110         _nc_curr_token.tk_name[2] = '\0';
111     }
112
113     entryp->tterm.str_table = entryp->tterm.term_names = _nc_save_str(ptr);
114
115     DEBUG(1, ("Starting '%s'", ptr));
116
117     /*
118      * We do this because the one-token lookahead in the parse loop
119      * results in the terminal type getting prematurely set to correspond
120      * to that of the next entry.
121      */
122     _nc_set_type(_nc_first_name(entryp->tterm.term_names));
123
124     /* check for overly-long names and aliases */
125     (void) strncpy(namecpy, entryp->tterm.term_names, MAX_NAME_SIZE);
126     namecpy[MAX_NAME_SIZE] = '\0';
127     if ((ptr = strrchr(namecpy, '|')) != (char *)NULL)
128         *ptr = '\0';
129     ptr = strtok(namecpy, "|");
130     if (strlen(ptr) > MAX_ALIAS)
131         _nc_warning("primary name may be too long");
132     while ((ptr = strtok((char *)NULL, "|")) != (char *)NULL)
133         if (strlen(ptr) > MAX_ALIAS)
134             _nc_warning("alias `%s' may be too long", ptr);
135
136     entryp->nuses = 0;
137
138     for (token_type = _nc_get_token();
139          token_type != EOF  &&  token_type != NAMES;
140          token_type = _nc_get_token())
141     {
142         if (strcmp(_nc_curr_token.tk_name, "use") == 0
143             || strcmp(_nc_curr_token.tk_name, "tc") == 0) {
144             entryp->uses[entryp->nuses].parent = (void *)_nc_save_str(_nc_curr_token.tk_valstring);
145             entryp->uses[entryp->nuses].line = _nc_curr_line;
146             entryp->nuses++;
147         } else {
148             /* normal token lookup */
149             entry_ptr = _nc_find_entry(_nc_curr_token.tk_name,
150                                        _nc_syntax ? _nc_cap_hash_table : _nc_info_hash_table);
151
152             /*
153              * Our kluge to handle aliasing.  The reason it's done
154              * this ugly way, with a linear search, is so the hashing
155              * machinery doesn't have to be made really complicated
156              * (also we get better warnings this way).  No point in
157              * making this case fast, aliased caps aren't common now
158              * and will get rarer.
159              */
160             if (entry_ptr == NOTFOUND)
161             {
162                 const struct alias      *ap;
163
164                 if (_nc_syntax == SYN_TERMCAP)
165                 {
166                     for (ap = _nc_capalias_table; ap->from; ap++)
167                         if (strcmp(ap->from, _nc_curr_token.tk_name) == 0)
168                         {
169                             if (ap->to == (char *)NULL)
170                             {
171                                 _nc_warning("%s (%s termcap extension) ignored",
172                                             ap->from, ap->source);
173                                 goto nexttok;
174                             }
175
176                             entry_ptr = _nc_find_entry(ap->to, _nc_cap_hash_table);
177                             if (entry_ptr && !silent)
178                                 _nc_warning("%s (%s termcap extension) aliased to %s", ap->from, ap->source, ap->to);
179                             break;
180                         }
181                 }
182                 else /* if (_nc_syntax == SYN_TERMINFO) */
183                 {
184                     for (ap = _nc_infoalias_table; ap->from; ap++)
185                         if (strcmp(ap->from, _nc_curr_token.tk_name) == 0)
186                         {
187                             if (ap->to == (char *)NULL)
188                             {
189                                 _nc_warning("%s (%s terminfo extension) ignored",
190                                             ap->from, ap->source);
191                                 goto nexttok;
192                             }
193
194                             entry_ptr = _nc_find_entry(ap->to, _nc_info_hash_table);
195                             if (entry_ptr && !silent)
196                                 _nc_warning("%s (%s terminfo extension) aliased to %s", ap->from, ap->source, ap->to);
197                             break;
198                         }
199
200                     /* last chance: a full-name */
201                     if (entry_ptr == NOTFOUND) {
202                         entry_ptr = lookup_fullname(_nc_curr_token.tk_name);
203                     }
204                 }
205             }
206
207             /* can't find this cap name, not even as an alias */
208             if (entry_ptr == NOTFOUND) {
209                 if (!silent)
210                     _nc_warning("unknown capability '%s'",
211                                 _nc_curr_token.tk_name);
212                 continue;
213             }
214
215             /* deal with bad type/value combinations. */
216             if (token_type != CANCEL &&  entry_ptr->nte_type != token_type)
217             {
218                 /*
219                  * Nasty special cases here handle situations in which type
220                  * information can resolve name clashes.  Normal lookup
221                  * finds the last instance in the capability table of a
222                  * given name, regardless of type.  find_type_entry looks
223                  * for a first matching instance with given type.  So as
224                  * long as all ambiguous names occur in pairs of distinct
225                  * type, this will do the job.
226                  */
227
228                 /* tell max_attributes from arrow_key_map */
229                 if (token_type == NUMBER && !strcmp("ma", _nc_curr_token.tk_name))
230                     entry_ptr = _nc_find_type_entry("ma", NUMBER,
231                                         _nc_get_table(_nc_syntax != 0));
232
233                 /* map terminfo's string MT to MT */
234                 else if (token_type==STRING &&!strcmp("MT",_nc_curr_token.tk_name))
235                     entry_ptr = _nc_find_type_entry("MT", STRING,
236                                         _nc_get_table(_nc_syntax != 0));
237
238                 /* treat strings without following "=" as empty strings */
239                 else if (token_type==BOOLEAN && entry_ptr->nte_type==STRING)
240                     token_type = STRING;
241                 /* we couldn't recover; skip this token */
242                 else
243                 {
244                     if (!silent)
245                     {
246                         const char *type_name;
247                         switch (entry_ptr->nte_type)
248                         {
249                         case BOOLEAN:
250                                 type_name = "boolean";
251                                 break;
252                         case STRING:
253                                 type_name = "string";
254                                 break;
255                         case NUMBER:
256                                 type_name = "numeric";
257                                 break;
258                         default:
259                                 type_name = "unknown";
260                                 break;
261                         }
262                         _nc_warning("wrong type used for %s capability '%s'",
263                                 type_name, _nc_curr_token.tk_name);
264                     }
265                     continue;
266                 }
267             }
268
269             /* now we know that the type/value combination is OK */
270             switch (token_type) {
271             case CANCEL:
272                 switch (entry_ptr->nte_type) {
273                 case BOOLEAN:
274                     entryp->tterm.Booleans[entry_ptr->nte_index] = CANCELLED_BOOLEAN;
275                     break;
276
277                 case NUMBER:
278                     entryp->tterm.Numbers[entry_ptr->nte_index] = CANCELLED_NUMERIC;
279                     break;
280
281                 case STRING:
282                     entryp->tterm.Strings[entry_ptr->nte_index] = CANCELLED_STRING;
283                     break;
284                 }
285                 break;
286
287             case BOOLEAN:
288                 entryp->tterm.Booleans[entry_ptr->nte_index] = TRUE;
289                 break;
290
291             case NUMBER:
292                 entryp->tterm.Numbers[entry_ptr->nte_index] =
293                     _nc_curr_token.tk_valnumber;
294                 break;
295
296             case STRING:
297                 ptr = _nc_curr_token.tk_valstring;
298                 if (_nc_syntax==SYN_TERMCAP)
299                     ptr = _nc_captoinfo(_nc_curr_token.tk_name,
300                                     ptr,
301                                     parametrized[entry_ptr->nte_index]);
302                 entryp->tterm.Strings[entry_ptr->nte_index] = _nc_save_str(ptr);
303                 break;
304
305             default:
306                 if (!silent)
307                     _nc_warning("unknown token type");
308                 _nc_panic_mode((_nc_syntax==SYN_TERMCAP) ? ':' : ',');
309                 continue;
310             }
311         } /* end else cur_token.name != "use" */
312     nexttok:
313         continue;       /* cannot have a label w/o statement */
314     } /* endwhile (not EOF and not NAMES) */
315
316     _nc_push_token(token_type);
317     _nc_set_type(_nc_first_name(entryp->tterm.term_names));
318
319     /*
320      * Try to deduce as much as possible from extension capabilities
321      * (this includes obsolete BSD capabilities).  Sigh...it would be more
322      * space-efficient to call this after use resolution, but it has
323      * to be done before entry allocation is wrapped up.
324      */
325     if (!literal)
326         if (_nc_syntax == SYN_TERMCAP)
327         {
328             bool        has_base_entry = FALSE;
329             int         i;
330
331             /*
332              * Don't insert defaults if this is a `+' entry meant only
333              * for inclusion in other entries (not sure termcap ever
334              * had these, actually).
335              */
336             if (strchr(entryp->tterm.term_names, '+'))
337                 has_base_entry = TRUE;
338             else
339                 /*
340                  * Otherwise, look for a base entry that will already
341                  * have picked up defaults via translation.
342                  */
343                 for (i = 0; i < entryp->nuses; i++)
344                     if (!strchr(entryp->uses[i].parent, '+'))
345                         has_base_entry = TRUE;
346
347             postprocess_termcap(&entryp->tterm, has_base_entry);
348         }
349         else
350             postprocess_terminfo(&entryp->tterm);
351
352     _nc_wrap_entry(entryp);
353
354     return(OK);
355 }
356
357 int _nc_capcmp(const char *s, const char *t)
358 /* compare two string capabilities, stripping out padding */
359 {
360     if (!s && !t)
361         return(0);
362     else if (!s || !t)
363         return(1);
364
365     for (;;)
366     {
367         if (s[0] == '$' && s[1] == '<')
368         {
369             for (s += 2; ; s++)
370                 if (!(isdigit(*s) || *s=='.' || *s=='*' || *s=='/' || *s=='>'))
371                     break;
372         }
373
374         if (t[0] == '$' && t[1] == '<')
375         {
376             for (t += 2; ; t++)
377                 if (!(isdigit(*t) || *t=='.' || *t=='*' || *t=='/' || *t=='>'))
378                     break;
379         }
380
381         /* we've now pushed s and t past any padding they were pointing at */
382
383         if (*s == '\0' && *t == '\0')
384                 return(0);
385
386         if (*s != *t)
387             return(*t - *s);
388
389         /* else *s == *t but one is not NUL, so continue */
390         s++, t++;
391     }
392 }
393
394 /*
395  * The ko capability, if present, consists of a comma-separated capability
396  * list.  For each capability, we may assume there is a keycap that sends the
397  * string which is the value of that capability.
398  */
399 typedef struct {const char *from; const char *to;} assoc;
400 static assoc const ko_xlate[] =
401 {
402     {"al",      "kil1"},        /* insert line key  -> KEY_IL    */
403     {"bt",      "kcbt"},        /* back tab         -> KEY_BTAB  */
404     {"cd",      "ked"},         /* clear-to-eos key -> KEY_EOL   */
405     {"ce",      "kel"},         /* clear-to-eol key -> KEY_EOS   */
406     {"cl",      "kclr"},        /* clear key        -> KEY_CLEAR */
407     {"ct",      "tbc"},         /* clear all tabs   -> KEY_CATAB */
408     {"dc",      "kdch1"},       /* delete char      -> KEY_DC    */
409     {"dl",      "kdl1"},        /* delete line      -> KEY_DL    */
410     {"do",      "kcud1"},       /* down key         -> KEY_DOWN  */
411     {"ei",      "krmir"},       /* exit insert key  -> KEY_EIC   */
412     {"ho",      "khome"},       /* home key         -> KEY_HOME  */
413     {"ic",      "kich1"},       /* insert char key  -> KEY_IC    */
414     {"im",      "kIC"},         /* insert-mode key  -> KEY_SIC   */
415     {"le",      "kcub1"},       /* le key           -> KEY_LEFT  */
416     {"nd",      "kcuf1"},       /* nd key           -> KEY_RIGHT */
417     {"nl",      "kent"},        /* new line key     -> KEY_ENTER */
418     {"st",      "khts"},        /* set-tab key      -> KEY_STAB  */
419     {"ta",      CANCELLED_STRING},
420     {"up",      "kcuu1"},       /* up-arrow key     -> KEY_UP    */
421     {(char *)NULL, (char *)NULL},
422 };
423
424 /*
425  * This routine fills in string caps that either had defaults under
426  * termcap or can be manufactured from obsolete termcap capabilities.
427  * It was lifted from Ross Ridge's mytinfo package.
428  */
429
430 static const char C_CR[] = "\r";
431 static const char C_LF[] = "\n";
432 static const char C_BS[] = "\b";
433 static const char C_HT[] = "\t";
434
435 /*
436  * Note that WANTED and PRESENT are not simple inverses!  If a capability
437  * has been explicitly cancelled, it's not considered WANTED.
438  */
439 #define WANTED(s)       ((s) == (char *)NULL)
440 #define PRESENT(s)      (((s) != (char *)NULL) && ((s) != CANCELLED_STRING))
441
442 /*
443  * This bit of legerdemain turns all the terminfo variable names into
444  * references to locations in the arrays Booleans, Numbers, and Strings ---
445  * precisely what's needed.
446  */
447
448 #undef CUR
449 #define CUR tp->
450
451 static
452 void postprocess_termcap(TERMTYPE *tp, bool has_base)
453 {
454     char buf[MAX_LINE * 2 + 2];
455
456     /*
457      * TERMCAP DEFAULTS AND OBSOLETE-CAPABILITY TRANSLATIONS
458      *
459      * This first part of the code is the functional inverse of the
460      * fragment in capdefaults.c.
461      * ----------------------------------------------------------------------
462      */
463
464     /* if there was a tc entry, assume we picked up defaults via that */
465     if (!has_base)
466     {
467         if (WANTED(init_3string) && termcap_init2)
468             init_3string = _nc_save_str(termcap_init2);
469
470         if (WANTED(reset_1string) && termcap_reset)
471             reset_1string = _nc_save_str(termcap_reset);
472
473         if (WANTED(carriage_return)) {
474             if (carriage_return_delay > 0) {
475                 sprintf(buf, "%s$<%d>", C_CR, carriage_return_delay);
476                 carriage_return = _nc_save_str(buf);
477             } else
478                 carriage_return = _nc_save_str(C_CR);
479         }
480         if (WANTED(cursor_left)) {
481             if (backspace_delay > 0) {
482                 sprintf(buf, "%s$<%d>", C_BS, backspace_delay);
483                 cursor_left = _nc_save_str(buf);
484             } else if (backspaces_with_bs == 1)
485                 cursor_left = _nc_save_str(C_BS);
486             else if (PRESENT(backspace_if_not_bs))
487                 cursor_left = backspace_if_not_bs;
488         }
489         /* vi doesn't use "do", but it does seems to use nl (or '\n') instead */
490         if (WANTED(cursor_down)) {
491             if (PRESENT(linefeed_if_not_lf))
492                 cursor_down = linefeed_if_not_lf;
493             else if (linefeed_is_newline != 1) {
494                 if (new_line_delay > 0) {
495                     sprintf(buf, "%s$<%d>", C_LF, new_line_delay);
496                     cursor_down = _nc_save_str(buf);
497                 } else
498                     cursor_down = _nc_save_str(C_LF);
499             }
500         }
501         if (WANTED(scroll_forward) && crt_no_scrolling != 1) {
502             if (PRESENT(linefeed_if_not_lf))
503                 cursor_down = linefeed_if_not_lf;
504             else if (linefeed_is_newline != 1) {
505                 if (new_line_delay > 0) {
506                     sprintf(buf, "%s$<%d>", C_LF, new_line_delay);
507                     scroll_forward = _nc_save_str(buf);
508                 } else
509                     scroll_forward = _nc_save_str(C_LF);
510             }
511         }
512         if (WANTED(newline)) {
513             if (linefeed_is_newline == 1) {
514                 if (new_line_delay > 0) {
515                     sprintf(buf, "%s$<%d>", C_LF, new_line_delay);
516                     newline = _nc_save_str(buf);
517                 } else
518                     newline = _nc_save_str(C_LF);
519             } else if (PRESENT(carriage_return) && PRESENT(scroll_forward)) {
520                 strncpy(buf, carriage_return, MAX_LINE-2);
521                 buf[MAX_LINE-1] = '\0';
522                 strncat(buf, scroll_forward, MAX_LINE-strlen(buf)-1);
523                 buf[MAX_LINE] = '\0';
524                 newline = _nc_save_str(buf);
525             } else if (PRESENT(carriage_return) && PRESENT(cursor_down)) {
526                 strncpy(buf, carriage_return, MAX_LINE-2);
527                 buf[MAX_LINE-1] = '\0';
528                 strncat(buf, cursor_down, MAX_LINE-strlen(buf)-1);
529                 buf[MAX_LINE] = '\0';
530                 newline = _nc_save_str(buf);
531             }
532         }
533     }
534
535     /*
536      * Inverse of capdefaults.c code ends here.
537      * ----------------------------------------------------------------------
538      *
539      * TERMCAP-TO TERMINFO MAPPINGS FOR SOURCE TRANSLATION
540      *
541      * These translations will *not* be inverted by tgetent().
542      */
543
544     if (!has_base)
545     {
546         /*
547          * We wait until now to decide if we've got a working cr because even
548          * one that doesn't work can be used for newline. Unfortunately the
549          * space allocated for it is wasted.
550          */
551         if (return_does_clr_eol == 1 || no_correctly_working_cr == 1)
552             carriage_return = NULL;
553
554         /*
555          * Supposedly most termcap entries have ta now and '\t' is no longer a
556          * default, but it doesn't seem to be true...
557          */
558         if (WANTED(tab)) {
559             if (horizontal_tab_delay > 0) {
560                 sprintf(buf, "%s$<%d>", C_HT, horizontal_tab_delay);
561                 tab = _nc_save_str(buf);
562             } else
563                 tab = _nc_save_str(C_HT);
564         }
565         if (init_tabs == ABSENT_NUMERIC && has_hardware_tabs == TRUE)
566             init_tabs = 8;
567
568         /*
569          * Assume we can beep with ^G unless we're given bl@.
570          */
571         if (WANTED(bell))
572             bell = _nc_save_str("\007");
573     }
574
575     /*
576      * Translate the old termcap :pt: capability to it#8 + ht=\t
577      */
578     if (has_hardware_tabs == TRUE)
579         if (init_tabs != 8 && init_tabs != ABSENT_NUMERIC)
580             _nc_warning("hardware tabs with a width other than 8: %d", init_tabs);
581         else
582         {
583             if (tab && _nc_capcmp(tab, C_HT))
584                 _nc_warning("hardware tabs with a non-^I tab string %s",
585                             _nc_visbuf(tab));
586             else
587             {
588                 if (WANTED(tab))
589                     tab = _nc_save_str(C_HT);
590                 init_tabs = 8;
591             }
592         }
593
594     /*
595      * Now translate the ko capability, if there is one.  This
596      * isn't from mytinfo...
597      */
598     if (PRESENT(other_non_function_keys))
599     {
600         char    *dp, *cp = strtok(other_non_function_keys, ",");
601         struct name_table_entry const *from_ptr;
602         struct name_table_entry const *to_ptr;
603         assoc   const *ap;
604         char    buf2[MAX_TERMINFO_LENGTH];
605         bool    foundim;
606
607         /* we're going to use this for a special case later */
608         dp = strchr(other_non_function_keys, 'i');
609         foundim = dp && dp[1] == 'm';
610
611         /* look at each comma-separated capability in the ko string... */
612         do {
613             for (ap = ko_xlate; ap->from; ap++)
614                 if (strcmp(ap->from, cp) == 0)
615                     break;
616             if (!ap->to)
617             {
618                 _nc_warning("unknown capability `%s' in ko string", cp);
619                 continue;
620             }
621             else if (ap->to == CANCELLED_STRING)        /* ignore it */
622                 continue;
623
624             /* now we know we found a match in ko_table, so... */
625
626             from_ptr = _nc_find_entry(ap->from, _nc_cap_hash_table);
627             to_ptr   = _nc_find_entry(ap->to,   _nc_info_hash_table);
628
629             if (!from_ptr || !to_ptr)   /* should never happen! */
630                 _nc_err_abort("ko translation table is invalid, I give up");
631
632             if (WANTED(tp->Strings[from_ptr->nte_index]))
633             {
634                 _nc_warning("no value for ko capability %s", ap->from);
635                 continue;
636             }
637
638             if (tp->Strings[to_ptr->nte_index])
639             {
640                 /* There's no point in warning about it if it's the same
641                  * string; that's just an inefficiency.
642                  */
643                 if (strcmp(
644                         tp->Strings[from_ptr->nte_index],
645                         tp->Strings[to_ptr->nte_index]) != 0)
646                     _nc_warning("%s (%s) already has an explicit value %s, ignoring ko",
647                             ap->to, ap->from,
648                             _nc_visbuf(tp->Strings[to_ptr->nte_index]) );
649                 continue;
650             }
651
652             /*
653              * The magic moment -- copy the mapped key string over,
654              * stripping out padding.
655              */
656             dp = buf2;
657             for (cp = tp->Strings[from_ptr->nte_index]; *cp; cp++)
658             {
659                 if (cp[0] == '$' && cp[1] == '<')
660                 {
661                     while (*cp && *cp != '>')
662                         if (!*cp)
663                             break;
664                         else
665                             ++cp;
666                 }
667                 else
668                     *dp++ = *cp;
669             }
670             *dp++ = '\0';
671
672             tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2);
673         } while
674             ((cp = strtok((char *)NULL, ",")) != 0);
675
676         /*
677          * Note: ko=im and ko=ic both want to grab the `Insert'
678          * keycap.  There's a kich1 but no ksmir, so the ic capability
679          * got mapped to kich1 and im to kIC to avoid a collision.
680          * If the description has im but not ic, hack kIC back to kich1.
681          */
682         if (foundim && WANTED(key_ic) && key_sic)
683         {
684             key_ic = key_sic;
685             key_sic = ABSENT_STRING;
686         }
687     }
688
689     if (!hard_copy)
690     {
691         if (WANTED(key_backspace))
692             key_backspace = _nc_save_str(C_BS);
693         if (WANTED(key_left))
694             key_left = _nc_save_str(C_BS);
695         if (WANTED(key_down))
696             key_down = _nc_save_str(C_LF);
697     }
698
699     /*
700      * Translate XENIX forms characters.
701      */
702     if (PRESENT(acs_ulcorner) ||
703         PRESENT(acs_llcorner) ||
704         PRESENT(acs_urcorner) ||
705         PRESENT(acs_lrcorner) ||
706         PRESENT(acs_ltee) ||
707         PRESENT(acs_rtee) ||
708         PRESENT(acs_btee) ||
709         PRESENT(acs_ttee) ||
710         PRESENT(acs_hline) ||
711         PRESENT(acs_vline) ||
712         PRESENT(acs_plus))
713     {
714         char    buf2[MAX_TERMCAP_LENGTH], *bp = buf2;
715
716         if (acs_chars)
717         {
718             (void)strcpy(bp, acs_chars);
719             bp += strlen(bp);
720         }
721
722         if (acs_ulcorner && acs_ulcorner[1] == '\0')
723         {
724             *bp++ = 'l';
725             *bp++ = *acs_ulcorner;
726         }
727         if (acs_llcorner && acs_llcorner[1] == '\0')
728         {
729             *bp++ = 'm';
730             *bp++ = *acs_llcorner;
731         }
732         if (acs_urcorner && acs_urcorner[1] == '\0')
733         {
734             *bp++ = 'k';
735             *bp++ = *acs_urcorner;
736         }
737         if (acs_lrcorner && acs_lrcorner[1] == '\0')
738         {
739             *bp++ = 'j';
740             *bp++ = *acs_lrcorner;
741         }
742         if (acs_ltee && acs_ltee[1] == '\0')
743         {
744             *bp++ = 't';
745             *bp++ = *acs_ltee;
746         }
747         if (acs_rtee && acs_rtee[1] == '\0')
748         {
749             *bp++ = 'u';
750             *bp++ = *acs_rtee;
751         }
752         if (acs_btee && acs_btee[1] == '\0')
753         {
754             *bp++ = 'v';
755             *bp++ = *acs_btee;
756         }
757         if (acs_ttee && acs_ttee[1] == '\0')
758         {
759             *bp++ = 'w';
760             *bp++ = *acs_ttee;
761         }
762         if (acs_hline && acs_hline[1] == '\0')
763         {
764             *bp++ = 'q';
765             *bp++ = *acs_hline;
766         }
767         if (acs_vline && acs_vline[1] == '\0')
768         {
769             *bp++ = 'x';
770             *bp++ = *acs_vline;
771         }
772         if (acs_plus)
773         {
774             *bp++ = 'n';
775             strcpy(bp, acs_plus);
776             bp = buf2 + strlen(buf2);
777         }
778
779         if (bp != buf2)
780         {
781             *bp++ = '\0';
782             acs_chars = _nc_save_str(buf2);
783             _nc_warning("acsc string synthesized from XENIX capabilities");
784         }
785     }
786 }
787
788 static
789 void postprocess_terminfo(TERMTYPE *tp)
790 {
791     /*
792      * TERMINFO-TO-TERMINFO MAPPINGS FOR SOURCE TRANSLATION
793      * ----------------------------------------------------------------------
794      */
795
796     /*
797      * Translate AIX forms characters.
798      */
799     if (PRESENT(box_chars_1))
800     {
801         char    buf2[MAX_TERMCAP_LENGTH], *bp = buf2;
802
803         if (acs_chars)
804         {
805             (void)strcpy(bp, acs_chars);
806             bp += strlen(bp);
807         }
808
809         if (box_chars_1[0])     /* ACS_ULCORNER */
810         {
811             *bp++ = 'l';
812             *bp++ = box_chars_1[0];
813         }
814         if (box_chars_1[1])     /* ACS_HLINE */
815         {
816             *bp++ = 'q';
817             *bp++ = box_chars_1[1];
818         }
819         if (box_chars_1[2])     /* ACS_URCORNER */
820         {
821             *bp++ = 'k';
822             *bp++ = box_chars_1[2];
823         }
824         if (box_chars_1[3])     /* ACS_VLINE */
825         {
826             *bp++ = 'x';
827             *bp++ = box_chars_1[3];
828         }
829         if (box_chars_1[4])     /* ACS_LRCORNER */
830         {
831             *bp++ = 'j';
832             *bp++ = box_chars_1[4];
833         }
834         if (box_chars_1[5])     /* ACS_LLCORNER */
835         {
836             *bp++ = 'm';
837             *bp++ = box_chars_1[5];
838         }
839         if (box_chars_1[6])     /* ACS_TTEE */
840         {
841             *bp++ = 'w';
842             *bp++ = box_chars_1[6];
843         }
844         if (box_chars_1[7])     /* ACS_RTEE */
845         {
846             *bp++ = 'u';
847             *bp++ = box_chars_1[7];
848         }
849         if (box_chars_1[8])     /* ACS_BTEE */
850         {
851             *bp++ = 'v';
852             *bp++ = box_chars_1[8];
853         }
854         if (box_chars_1[9])     /* ACS_LTEE */
855         {
856             *bp++ = 't';
857             *bp++ = box_chars_1[9];
858         }
859         if (box_chars_1[10])    /* ACS_PLUS */
860         {
861             *bp++ = 'n';
862             *bp++ = box_chars_1[10];
863         }
864
865         if (bp != buf2)
866         {
867             *bp++ = '\0';
868             acs_chars = _nc_save_str(buf2);
869             _nc_warning("acsc string synthesized from AIX capabilities");
870             box_chars_1 = ABSENT_STRING;
871         }
872     }
873     /*
874      * ----------------------------------------------------------------------
875      */
876 }
877
878 /*
879  * Do a linear search through the terminfo tables to find a given full-name.
880  * We don't expect to do this often, so there's no hashing function.
881  *
882  * In effect, this scans through the 3 lists of full-names, and looks them
883  * up in _nc_info_table, which is organized so that the nte_index fields are
884  * sorted, but the nte_type fields are not necessarily grouped together.
885  */
886 static
887 struct name_table_entry const * lookup_fullname(const char *find)
888 {
889     int state = -1;
890
891     for (;;) {
892         int count = 0;
893         NCURSES_CONST char *const *names;
894
895         switch (++state) {
896         case BOOLEAN:
897             names = boolfnames;
898             break;
899         case STRING:
900             names = strfnames;
901             break;
902         case NUMBER:
903             names = numfnames;
904             break;
905         default:
906             return NOTFOUND;
907         }
908
909         for (count = 0; names[count] != 0; count++) {
910             if (!strcmp(names[count], find)) {
911                 struct name_table_entry const *entry_ptr = _nc_get_table(FALSE);
912                 while (entry_ptr->nte_type  != state
913                     || entry_ptr->nte_index != count)
914                         entry_ptr++;
915                 return entry_ptr;
916             }
917         }
918     }
919 }
920
921 /* parse_entry.c ends here */