]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/parse_entry.c
ncurses 5.0
[ncurses.git] / ncurses / tinfo / parse_entry.c
similarity index 85%
rename from ncurses/parse_entry.c
rename to ncurses/tinfo/parse_entry.c
index fd41019bf0b747e112b249500ea7a1ff6be132cd..07f3868e0b44dd13b2172ca417161c435245708d 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc.                        *
+ * Copyright (c) 1999 Free Software Foundation, Inc.                        *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
 #include <ctype.h>
 #include <tic.h>
 #define __INTERNAL_CAPS_VISIBLE
-#include <term.h>
 #include <term_entry.h>
 
-MODULE_ID("$Id: parse_entry.c,v 1.22 1998/02/11 12:13:59 tom Exp $")
+MODULE_ID("$Id: parse_entry.c,v 1.39 1999/03/01 02:28:51 tom Exp $")
 
 #ifdef LINT
 static short const parametrized[] = { 0 };
@@ -63,6 +62,116 @@ static      void postprocess_termcap(TERMTYPE *, bool);
 static void postprocess_terminfo(TERMTYPE *);
 static struct name_table_entry const * lookup_fullname(const char *name);
 
+#if NCURSES_XNAMES
+
+static struct name_table_entry const *
+_nc_extend_names(ENTRY *entryp, char *name, int token_type)
+{
+    static struct name_table_entry temp;
+    TERMTYPE *tp = &(entryp->tterm);
+    unsigned offset = 0;
+    unsigned actual;
+    unsigned tindex;
+    unsigned first, last, n;
+    bool found;
+
+    switch (token_type) {
+    case BOOLEAN:
+       first  = 0;
+       last   = tp->ext_Booleans;
+       offset = tp->ext_Booleans;
+       tindex = tp->num_Booleans;
+       break;
+    case NUMBER:
+       first  = tp->ext_Booleans;
+       last   = tp->ext_Numbers  + first;
+       offset = tp->ext_Booleans + tp->ext_Numbers;
+       tindex = tp->num_Numbers;
+       break;
+    case STRING:
+       first  = tp->ext_Booleans + tp->ext_Numbers;
+       last   = tp->ext_Strings  + first;
+       offset = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings;
+       tindex = tp->num_Strings;
+       break;
+    case CANCEL:
+       actual = NUM_EXT_NAMES(tp);
+       for (n = 0; n < actual; n++) {
+           if (!strcmp(name, tp->ext_Names[n])) {
+               if (n > (unsigned)(tp->ext_Booleans + tp->ext_Numbers)) {
+                   token_type = STRING;
+               } else if (n > tp->ext_Booleans) {
+                   token_type = NUMBER;
+               } else {
+                   token_type = BOOLEAN;
+               }
+               return _nc_extend_names(entryp, name, token_type);
+           }
+       }
+       /* Well, we are given a cancel for a name that we don't recognize */
+       return _nc_extend_names(entryp, name, STRING);
+    default:
+       return 0;
+    }
+
+    /* Adjust the 'offset' (insertion-point) to keep the lists of extended
+     * names sorted.
+     */
+    for (n = first, found = FALSE; n < last; n++) {
+       int cmp = strcmp(tp->ext_Names[n], name);
+       if (cmp == 0)
+           found = TRUE;
+       if (cmp >= 0) {
+           offset = n;
+           tindex = n - first;
+           switch (token_type) {
+           case BOOLEAN:       tindex += BOOLCOUNT;    break;
+           case NUMBER:        tindex += NUMCOUNT;     break;
+           case STRING:        tindex += STRCOUNT;     break;
+           }
+           break;
+       }
+    }
+    if (!found) {
+       switch (token_type) {
+       case BOOLEAN:
+           tp->ext_Booleans += 1;
+           tp->num_Booleans += 1;
+           tp->Booleans = typeRealloc(char, tp->num_Booleans, tp->Booleans);
+           for (last = tp->num_Booleans-1; last > tindex; last--)
+               tp->Booleans[last] = tp->Booleans[last-1];
+           break;
+       case NUMBER:
+           tp->ext_Numbers += 1;
+           tp->num_Numbers += 1;
+           tp->Numbers = typeRealloc(short, tp->num_Numbers, tp->Numbers);
+           for (last = tp->num_Numbers-1; last > tindex; last--)
+               tp->Numbers[last] = tp->Numbers[last-1];
+           break;
+       case STRING:
+           tp->ext_Strings += 1;
+           tp->num_Strings += 1;
+           tp->Strings = typeRealloc(char *, tp->num_Strings, tp->Strings);
+           for (last = tp->num_Strings-1; last > tindex; last--)
+               tp->Strings[last] = tp->Strings[last-1];
+           break;
+       }
+       actual = NUM_EXT_NAMES(tp);
+       tp->ext_Names  = typeRealloc(char *, actual, tp->ext_Names);
+       while (--actual > offset)
+           tp->ext_Names[actual] = tp->ext_Names[actual-1];
+       tp->ext_Names[offset] = _nc_save_str(name);
+    }
+
+    temp.nte_name  = tp->ext_Names[offset];
+    temp.nte_type  = token_type;
+    temp.nte_index = tindex;
+    temp.nte_link  = -1;
+
+    return &temp;
+}
+#endif /* NCURSES_XNAMES */
+
 /*
  *     int
  *     _nc_parse_entry(entry, literal, silent)
@@ -124,12 +233,12 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
     /* check for overly-long names and aliases */
     (void) strncpy(namecpy, entryp->tterm.term_names, MAX_NAME_SIZE);
     namecpy[MAX_NAME_SIZE] = '\0';
-    if ((ptr = strrchr(namecpy, '|')) != (char *)NULL)
+    if ((ptr = strrchr(namecpy, '|')) != (char *)0)
        *ptr = '\0';
     ptr = strtok(namecpy, "|");
     if (strlen(ptr) > MAX_ALIAS)
        _nc_warning("primary name may be too long");
-    while ((ptr = strtok((char *)NULL, "|")) != (char *)NULL)
+    while ((ptr = strtok((char *)0, "|")) != (char *)0)
        if (strlen(ptr) > MAX_ALIAS)
            _nc_warning("alias `%s' may be too long", ptr);
 
@@ -166,7 +275,7 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
                    for (ap = _nc_capalias_table; ap->from; ap++)
                        if (strcmp(ap->from, _nc_curr_token.tk_name) == 0)
                        {
-                           if (ap->to == (char *)NULL)
+                           if (ap->to == (char *)0)
                            {
                                _nc_warning("%s (%s termcap extension) ignored",
                                            ap->from, ap->source);
@@ -184,7 +293,7 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
                    for (ap = _nc_infoalias_table; ap->from; ap++)
                        if (strcmp(ap->from, _nc_curr_token.tk_name) == 0)
                        {
-                           if (ap->to == (char *)NULL)
+                           if (ap->to == (char *)0)
                            {
                                _nc_warning("%s (%s terminfo extension) ignored",
                                            ap->from, ap->source);
@@ -197,13 +306,24 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
                            break;
                        }
 
-                   /* last chance: a full-name */
                    if (entry_ptr == NOTFOUND) {
                        entry_ptr = lookup_fullname(_nc_curr_token.tk_name);
                    }
                }
            }
 
+#if NCURSES_XNAMES
+           /*
+            * If we have extended-names active, we will automatically
+            * define a name based on its context.
+            */
+           if (entry_ptr == NOTFOUND
+            && _nc_user_definable
+            && (entry_ptr = _nc_extend_names(entryp, _nc_curr_token.tk_name, token_type)) != 0) {
+               _nc_warning("extended capability '%s'", _nc_curr_token.tk_name);
+           }
+#endif /* NCURSES_XNAMES */
+
            /* can't find this cap name, not even as an alias */
            if (entry_ptr == NOTFOUND) {
                if (!silent)
@@ -322,7 +442,7 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
      * space-efficient to call this after use resolution, but it has
      * to be done before entry allocation is wrapped up.
      */
-    if (!literal)
+    if (!literal) {
        if (_nc_syntax == SYN_TERMCAP)
        {
            bool        has_base_entry = FALSE;
@@ -341,14 +461,14 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
                 * have picked up defaults via translation.
                 */
                for (i = 0; i < entryp->nuses; i++)
-                   if (!strchr(entryp->uses[i].parent, '+'))
+                   if (!strchr((char *)entryp->uses[i].parent, '+'))
                        has_base_entry = TRUE;
 
            postprocess_termcap(&entryp->tterm, has_base_entry);
         }
        else
            postprocess_terminfo(&entryp->tterm);
-
+    }
     _nc_wrap_entry(entryp);
 
     return(OK);
@@ -418,7 +538,7 @@ static assoc const ko_xlate[] =
     {"st",     "khts"},        /* set-tab key      -> KEY_STAB  */
     {"ta",     CANCELLED_STRING},
     {"up",     "kcuu1"},       /* up-arrow key     -> KEY_UP    */
-    {(char *)NULL, (char *)NULL},
+    {(char *)0, (char *)0},
 };
 
 /*
@@ -436,8 +556,8 @@ static const char C_HT[] = "\t";
  * Note that WANTED and PRESENT are not simple inverses!  If a capability
  * has been explicitly cancelled, it's not considered WANTED.
  */
-#define WANTED(s)      ((s) == (char *)NULL)
-#define PRESENT(s)     (((s) != (char *)NULL) && ((s) != CANCELLED_STRING))
+#define WANTED(s)      ((s) == ABSENT_STRING)
+#define PRESENT(s)     (((s) != ABSENT_STRING) && ((s) != CANCELLED_STRING))
 
 /*
  * This bit of legerdemain turns all the terminfo variable names into
@@ -467,8 +587,8 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
        if (WANTED(init_3string) && termcap_init2)
            init_3string = _nc_save_str(termcap_init2);
 
-       if (WANTED(reset_1string) && termcap_reset)
-           reset_1string = _nc_save_str(termcap_reset);
+       if (WANTED(reset_2string) && termcap_reset)
+           reset_2string = _nc_save_str(termcap_reset);
 
        if (WANTED(carriage_return)) {
            if (carriage_return_delay > 0) {
@@ -549,7 +669,7 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
         * space allocated for it is wasted.
         */
        if (return_does_clr_eol == 1 || no_correctly_working_cr == 1)
-           carriage_return = NULL;
+           carriage_return = ABSENT_STRING;
 
        /*
         * Supposedly most termcap entries have ta now and '\t' is no longer a
@@ -575,7 +695,7 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
     /*
      * Translate the old termcap :pt: capability to it#8 + ht=\t
      */
-    if (has_hardware_tabs == TRUE)
+    if (has_hardware_tabs == TRUE) {
        if (init_tabs != 8 && init_tabs != ABSENT_NUMERIC)
            _nc_warning("hardware tabs with a width other than 8: %d", init_tabs);
         else
@@ -590,7 +710,7 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
                init_tabs = 8;
            }
        }
-
+    }
     /*
      * Now translate the ko capability, if there is one.  This
      * isn't from mytinfo...
@@ -671,7 +791,7 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
 
            tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2);
        } while
-           ((cp = strtok((char *)NULL, ",")) != 0);
+           ((cp = strtok((char *)0, ",")) != 0);
 
        /*
         * Note: ko=im and ko=ic both want to grab the `Insert'
@@ -783,6 +903,12 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
            _nc_warning("acsc string synthesized from XENIX capabilities");
        }
     }
+    else if (acs_chars == 0
+       && enter_alt_charset_mode != 0
+       && exit_alt_charset_mode != 0)
+    {
+       acs_chars = _nc_save_str("``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~");
+    }
 }
 
 static