]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/toe.c
ncurses 6.2 - patch 20210418
[ncurses.git] / progs / toe.c
index 56c9d9fb7e277cf846d9201406b33d66c21cf239..8fd98d006c2706a70c4633e0c3f6d5b6bcac4acb 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 1998-2013,2017 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            *
@@ -44,7 +45,7 @@
 #include <hashed_db.h>
 #endif
 
-MODULE_ID("$Id: toe.c,v 1.69 2012/10/27 20:01:20 tom Exp $")
+MODULE_ID("$Id: toe.c,v 1.81 2021/04/03 22:54:52 tom Exp $")
 
 #define isDotname(name) (!strcmp(name, ".") || !strcmp(name, ".."))
 
@@ -63,7 +64,7 @@ static size_t len_termdata;   /* allocated size of ptr_termdata[] */
 
 #if NO_LEAKS
 #undef ExitProgram
-static void ExitProgram(int code) GCC_NORETURN;
+static GCC_NORETURN void ExitProgram(int code);
 static void
 ExitProgram(int code)
 {
@@ -72,7 +73,7 @@ ExitProgram(int code)
 }
 #endif
 
-static void failed(const char *) GCC_NORETURN;
+static GCC_NORETURN void failed(const char *);
 
 static void
 failed(const char *msg)
@@ -126,12 +127,15 @@ compare_termdata(const void *a, const void *b)
 static void
 show_termdata(int eargc, char **eargv)
 {
-    int j, k;
-    size_t n;
-
     if (use_termdata) {
+       size_t n;
+
        if (eargc > 1) {
+           int j;
+
            for (j = 0; j < eargc; ++j) {
+               int k;
+
                for (k = 0; k <= j; ++k) {
                    printf("--");
                }
@@ -148,7 +152,7 @@ show_termdata(int eargc, char **eargv)
             */
            if (eargc > 1) {
                unsigned long check = 0;
-               k = 0;
+               int k = 0;
                for (;;) {
                    for (; k < ptr_termdata[n].db_index; ++k) {
                        printf("--");
@@ -232,9 +236,9 @@ make_db_name(char *dst, const char *src, unsigned limit)
     static const char suffix[] = DBM_SUFFIX;
 
     bool result = FALSE;
-    unsigned lens = sizeof(suffix) - 1;
-    unsigned size = strlen(src);
-    unsigned need = lens + size;
+    size_t lens = sizeof(suffix) - 1;
+    size_t size = strlen(src);
+    size_t need = lens + size;
 
     if (need <= limit) {
        if (size >= lens
@@ -252,22 +256,25 @@ make_db_name(char *dst, const char *src, unsigned limit)
 typedef void (DescHook) (int /* db_index */ ,
                         int /* db_limit */ ,
                         const char * /* term_name */ ,
-                        TERMTYPE * /* term */ );
+                        TERMTYPE2 * /* term */ );
 
 static const char *
-term_description(TERMTYPE *tp)
+term_description(TERMTYPE2 *tp)
 {
     const char *desc;
 
-    if ((desc = strrchr(tp->term_names, '|')) == 0 || *++desc == '\0')
+    if (tp->term_names == 0
+       || (desc = strrchr(tp->term_names, '|')) == 0
+       || (*++desc == '\0')) {
        desc = "(No description)";
+    }
 
     return desc;
 }
 
 /* display a description for the type */
 static void
-deschook(int db_index, int db_limit, const char *term_name, TERMTYPE *tp)
+deschook(int db_index, int db_limit, const char *term_name, TERMTYPE2 *tp)
 {
     (void) db_index;
     (void) db_limit;
@@ -291,7 +298,7 @@ string_sum(const char *value)
 }
 
 static unsigned long
-checksum_of(TERMTYPE *tp)
+checksum_of(TERMTYPE2 *tp)
 {
     unsigned long result = string_sum(tp->term_names);
     unsigned i;
@@ -310,7 +317,7 @@ checksum_of(TERMTYPE *tp)
 
 /* collect data, to sort before display */
 static void
-sorthook(int db_index, int db_limit, const char *term_name, TERMTYPE *tp)
+sorthook(int db_index, int db_limit, const char *term_name, TERMTYPE2 *tp)
 {
     TERMDATA *data = new_termdata();
 
@@ -320,11 +327,11 @@ sorthook(int db_index, int db_limit, const char *term_name, TERMTYPE *tp)
     data->description = strmalloc(term_description(tp));
 }
 
-#if USE_TERMCAP
+#if NCURSES_USE_TERMCAP
 static void
 show_termcap(int db_index, int db_limit, char *buffer, DescHook hook)
 {
-    TERMTYPE data;
+    TERMTYPE2 data;
     char *next = strchr(buffer, ':');
     char *last;
     char *list = buffer;
@@ -347,7 +354,7 @@ show_termcap(int db_index, int db_limit, char *buffer, DescHook hook)
 }
 #endif
 
-#if USE_DATABASE
+#if NCURSES_USE_DATABASE
 static char *
 copy_entryname(DIRENT * src)
 {
@@ -364,14 +371,14 @@ copy_entryname(DIRENT * src)
 
 static int
 typelist(int eargc, char *eargv[],
-        bool verbosity,
+        int verbosity,
         DescHook hook)
 /* apply a function to each entry in given terminfo directories */
 {
     int i;
 
     for (i = 0; i < eargc; i++) {
-#if USE_DATABASE
+#if NCURSES_USE_DATABASE
        if (_nc_is_dir_path(eargv[i])) {
            char *cwd_buf = 0;
            DIR *termdir;
@@ -421,7 +428,7 @@ typelist(int eargc, char *eargv[],
                }
                while ((entry = readdir(entrydir)) != 0) {
                    char *name_2;
-                   TERMTYPE lterm;
+                   TERMTYPE2 lterm;
                    char *cn;
                    int status;
 
@@ -438,7 +445,7 @@ typelist(int eargc, char *eargv[],
                                       "%s: couldn't open terminfo file %s.\n",
                                       _nc_progname, name_2);
                        free(name_2);
-                       return (EXIT_FAILURE);
+                       continue;
                    }
 
                    /* only visit things once, by primary name */
@@ -447,7 +454,7 @@ typelist(int eargc, char *eargv[],
                        /* apply the selected hook function */
                        hook(i, eargc, cn, &lterm);
                    }
-                   _nc_free_termtype(&lterm);
+                   _nc_free_termtype2(&lterm);
                    free(name_2);
                }
                closedir(entrydir);
@@ -472,7 +479,7 @@ typelist(int eargc, char *eargv[],
 
                    code = _nc_db_first(capdbp, &key, &data);
                    while (code == 0) {
-                       TERMTYPE lterm;
+                       TERMTYPE2 lterm;
                        int used;
                        char *have;
                        char *cn;
@@ -483,7 +490,7 @@ typelist(int eargc, char *eargv[],
                                cn = _nc_first_name(lterm.term_names);
                                /* apply the selected hook function */
                                hook(i, eargc, cn, &lterm);
-                               _nc_free_termtype(&lterm);
+                               _nc_free_termtype2(&lterm);
                            }
                        }
                        code = _nc_db_next(capdbp, &key, &data);
@@ -494,9 +501,9 @@ typelist(int eargc, char *eargv[],
                }
            }
        }
-#endif
-#endif
-#if USE_TERMCAP
+#endif /* USE_HASHED_DB */
+#endif /* NCURSES_USE_DATABASE */
+#if NCURSES_USE_TERMCAP
 #if HAVE_BSD_CGETENT
        {
            CGETENT_CONST char *db_array[2];
@@ -566,7 +573,6 @@ main(int argc, char *argv[])
     bool invert_dependencies = FALSE;
     bool header = FALSE;
     char *report_file = 0;
-    unsigned i;
     int code;
     int this_opt, last_opt = '?';
     unsigned v_opt = 0;
@@ -654,11 +660,13 @@ main(int argc, char *argv[])
     /* maybe we want a reverse-dependency listing? */
     if (invert_dependencies) {
        ENTRY *qp, *rp;
-       int matchcount;
 
        for_entry_list(qp) {
-           matchcount = 0;
+           int matchcount = 0;
+
            for_entry_list(rp) {
+               unsigned i;
+
                if (rp->nuses == 0)
                    continue;
 
@@ -688,15 +696,17 @@ main(int argc, char *argv[])
        DBDIRS state;
        int offset;
        int pass;
-       const char *path;
        char **eargv = 0;
 
        code = EXIT_FAILURE;
        for (pass = 0; pass < 2; ++pass) {
            size_t count = 0;
+           const char *path;
 
            _nc_first_db(&state, &offset);
            while ((path = _nc_next_db(&state, &offset)) != 0) {
+               if (quick_prefix(path))
+                   continue;
                if (pass) {
                    eargv[count] = strmalloc(path);
                }
@@ -715,14 +725,15 @@ main(int argc, char *argv[])
        DBDIRS state;
        int offset;
        const char *path;
-       char **eargv = allocArgv(2);
+       char **eargv = allocArgv((size_t) 2);
        size_t count = 0;
 
        if (eargv == 0)
            failed("eargv");
        _nc_first_db(&state, &offset);
        if ((path = _nc_next_db(&state, &offset)) != 0) {
-           eargv[count++] = strmalloc(path);
+           if (!quick_prefix(path))
+               eargv[count++] = strmalloc(path);
        }
 
        code = typelist((int) count, eargv, header, hook);