]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/comp_parse.c
ncurses 5.0
[ncurses.git] / ncurses / tinfo / comp_parse.c
similarity index 84%
rename from ncurses/comp_parse.c
rename to ncurses/tinfo/comp_parse.c
index 1b7ae1e8bb0976a00dd7eee3ccffa7467ec7f652..be419ca3e790c565a632ca3879b8897918459e3c 100644 (file)
 #include <ctype.h>
 
 #include <tic.h>
-#include <term.h>
 #include <term_entry.h>
 
-MODULE_ID("$Id: comp_parse.c,v 1.21 1998/02/11 12:14:00 tom Exp $")
+MODULE_ID("$Id: comp_parse.c,v 1.34 1999/02/27 22:13:02 tom Exp $")
 
 static void sanity_check(TERMTYPE *);
+void (*_nc_check_termtype)(TERMTYPE *) = sanity_check;
 
 /****************************************************************************
  *
@@ -85,13 +85,11 @@ ENTRY *_nc_head, *_nc_tail;
 static void enqueue(ENTRY *ep)
 /* add an entry to the in-core list */
 {
-       ENTRY   *newp = (ENTRY *)malloc(sizeof(ENTRY));
+       ENTRY   *newp = _nc_copy_entry(ep);
 
        if (newp == NULL)
            _nc_err_abort("Out of memory");
 
-       (void) memcpy(newp, ep, sizeof(ENTRY));
-
        newp->last = _nc_tail;
        _nc_tail = newp;
 
@@ -131,14 +129,16 @@ bool _nc_entry_match(char *n1, char *n2)
 
     if (strchr(n1, '|') == NULL)
     {
-       (void) strcpy(nc1, n1);
+       (void) strncpy(nc1, n1, sizeof(nc1) - 2);
+       nc1[sizeof(nc1) - 2] = '\0';
        (void) strcat(nc1, "|");
        n1 = nc1;
     }
 
     if (strchr(n2, '|') == NULL)
     {
-       (void) strcpy(nc2, n2);
+       (void) strncpy(nc2, n2, sizeof(nc2) - 2);
+       nc2[sizeof(nc2) - 2] = '\0';
        (void) strcat(nc2, "|");
        n2 = nc2;
     }
@@ -170,6 +170,7 @@ void _nc_read_entry_source(FILE *fp, char *buf,
     if (silent)
        _nc_suppress_warnings = TRUE;   /* shut the lexer up, too */
 
+    memset(&thisentry, 0, sizeof(thisentry));
     for (_nc_reset_input(fp, buf); _nc_parse_entry(&thisentry, literal, silent) != ERR; )
     {
        if (!isalnum(thisentry.tterm.term_names[0]))
@@ -195,8 +196,10 @@ void _nc_read_entry_source(FILE *fp, char *buf,
        DEBUG(1, ("head = %s", _nc_head->tterm.term_names));
        DEBUG(1, ("tail = %s", _nc_tail->tterm.term_names));
     }
+#ifdef TRACE
     else if (!immediate)
        DEBUG(1, ("no entries parsed"));
+#endif
 
     _nc_suppress_warnings = oldsuppress;
 }
@@ -279,13 +282,16 @@ int _nc_resolve_uses(void)
                TERMTYPE        thisterm;
                char            filename[PATH_MAX];
 
+               memset(&thisterm, 0, sizeof(thisterm));
                if (_nc_read_entry(lookfor, filename, &thisterm) == 1)
                {
                    DEBUG(2, ("%s: resolving use=%s (compiled)",
                              child, lookfor));
 
-                   rp = (ENTRY *)malloc(sizeof(ENTRY));
-                   memcpy(&rp->tterm, &thisterm, sizeof(TERMTYPE));
+                   rp = typeMalloc(ENTRY,1);
+                   if (rp == NULL)
+                       _nc_err_abort("Out of memory");
+                   rp->tterm = thisterm;
                    rp->nuses = 0;
                    rp->next = lastread;
                    lastread = rp;
@@ -326,6 +332,7 @@ int _nc_resolve_uses(void)
        keepgoing = FALSE;
 
        for_entry_list(qp)
+       {
            if (qp->nuses > 0)
            {
                DEBUG(2, ("%s: attempting merge", _nc_first_name(qp->tterm.term_names)));
@@ -347,7 +354,7 @@ int _nc_resolve_uses(void)
                 * as a side effect, copy into the merged entry the name
                 * field and string table pointer.
                 */
-               memcpy(&merged, &qp->tterm, sizeof(TERMTYPE));
+               _nc_copy_termtype(&merged, &(qp->tterm));
 
                /*
                 * Now merge in each use entry in the proper
@@ -365,7 +372,10 @@ int _nc_resolve_uses(void)
                /*
                 * Replace the original entry with the merged one.
                 */
-               memcpy(&qp->tterm, &merged, sizeof(TERMTYPE));
+               FreeIfNeeded(qp->tterm.Booleans);
+               FreeIfNeeded(qp->tterm.Numbers);
+               FreeIfNeeded(qp->tterm.Strings);
+               qp->tterm = merged;
 
                /*
                 * We know every entry is resolvable because name resolution
@@ -375,6 +385,7 @@ int _nc_resolve_uses(void)
            incomplete:
                keepgoing = TRUE;
            }
+       }
     } while
        (keepgoing);
 
@@ -387,13 +398,13 @@ int _nc_resolve_uses(void)
      */
     for_entry_list(qp)
     {
-       for (j = 0; j < BOOLCOUNT; j++)
+       for_each_boolean(j, &(qp->tterm))
            if (qp->tterm.Booleans[j] == CANCELLED_BOOLEAN)
                qp->tterm.Booleans[j] = FALSE;
-       for (j = 0; j < NUMCOUNT; j++)
+       for_each_number(j, &(qp->tterm))
            if (qp->tterm.Numbers[j] == CANCELLED_NUMERIC)
                qp->tterm.Numbers[j] = ABSENT_NUMERIC;
-       for (j = 0; j < STRCOUNT; j++)
+       for_each_string(j, &(qp->tterm))
            if (qp->tterm.Strings[j] == CANCELLED_STRING)
                qp->tterm.Strings[j] = ABSENT_STRING;
     }
@@ -407,16 +418,18 @@ int _nc_resolve_uses(void)
 
     DEBUG(2, ("RESOLUTION FINISHED"));
 
-    _nc_curr_col = -1;
-    for_entry_list(qp)
+    if (_nc_check_termtype != 0)
     {
-       _nc_curr_line = qp->startline;
-       _nc_set_type(_nc_first_name(qp->tterm.term_names));
-       sanity_check(&qp->tterm);
+       _nc_curr_col = -1;
+       for_entry_list(qp)
+       {
+           _nc_curr_line = qp->startline;
+           _nc_set_type(_nc_first_name(qp->tterm.term_names));
+           _nc_check_termtype(&qp->tterm);
+       }
+       DEBUG(2, ("SANITY CHECK FINISHED"));
     }
 
-    DEBUG(2, ("SANITY CHECK FINISHED"));
-
     return(TRUE);
 }
 
@@ -429,33 +442,12 @@ int _nc_resolve_uses(void)
 #undef CUR
 #define CUR tp->
 
-/*
- * 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) == ABSENT_STRING)
-#define PRESENT(s)     (((s) != ABSENT_STRING) && ((s) != CANCELLED_STRING))
-
-#define ANDMISSING(p,q) \
-               {if (PRESENT(p) && !PRESENT(q)) _nc_warning(#p " but no " #q);}
-
-#define PAIRED(p,q) \
-               { \
-               if (PRESENT(q) && !PRESENT(p)) \
-                       _nc_warning(#q " but no " #p); \
-               if (PRESENT(p) && !PRESENT(q)) \
-                       _nc_warning(#p " but no " #q); \
-               }
-
 static void sanity_check(TERMTYPE *tp)
 {
-#ifdef __UNUSED__      /* this casts too wide a net */
-    bool       terminal_entry = !strchr(tp->term_names, '+');
-#endif
-
     if (!PRESENT(exit_attribute_mode))
     {
 #ifdef __UNUSED__      /* this casts too wide a net */
+        bool       terminal_entry = !strchr(tp->term_names, '+');
        if (terminal_entry &&
                (PRESENT(set_attributes)
                || PRESENT(enter_standout_mode)
@@ -473,10 +465,6 @@ static void sanity_check(TERMTYPE *tp)
     }
 
      /* listed in structure-member order of first argument */
-#ifdef __UNUSED__
-     ANDMISSING(cursor_invisible,            cursor_normal)
-     ANDMISSING(cursor_visible,              cursor_normal)
-#endif /* __UNUSED__ */
      PAIRED(enter_alt_charset_mode,          exit_alt_charset_mode)
      ANDMISSING(enter_alt_charset_mode,      acs_chars)
      ANDMISSING(exit_alt_charset_mode,       acs_chars)
@@ -499,30 +487,4 @@ static void sanity_check(TERMTYPE *tp)
      ANDMISSING(label_off,                   label_on)
      PAIRED(display_clock,                   remove_clock)
      ANDMISSING(set_color_pair,              initialize_pair)
-
-     /* Some checks that we should make, but don't want to confuse people
-      * with.  Put those under the tic -v option so we can still get them.
-      */
-     if (_nc_tracing) {
-
-       /*
-        * From XSI & O'Reilly, we gather that sc/rc are required if csr is
-        * given, because the cursor position after the scrolling operation is
-        * performed is undefined.
-        */
-         ANDMISSING(change_scroll_region,        save_cursor)
-         ANDMISSING(change_scroll_region,        restore_cursor)
-
-         /*
-         * Some non-curses applications (e.g., jove) get confused if we have
-         * both ich/ich1 and smir/rmir.  Let's be nice and warn about that,
-         * too, even though ncurses handles it.
-          */
-         if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode))
-          && (PRESENT(insert_character)  || PRESENT(parm_ich))) {
-           _nc_warning("non-curses applications may be confused by ich/ich1 with smir/rmir");
-         }
-     }
-#undef PAIRED
-#undef ANDMISSING
 }