Author: vangyzen
Date: Thu Dec  1 17:36:31 2016
New Revision: 309367
URL: https://svnweb.freebsd.org/changeset/base/309367

Log:
  locale: enable more warnings; fix them
  
  Do not set WARNS, so it gets the current default of 6.
  Fix the warnings by sprinkling static, const, or strdup.
  Make some constant data tables const.  Fix whitespace.
  
  MFC after:    1 week
  Sponsored by: Dell EMC

Modified:
  head/usr.bin/locale/Makefile
  head/usr.bin/locale/locale.c

Modified: head/usr.bin/locale/Makefile
==============================================================================
--- head/usr.bin/locale/Makefile        Thu Dec  1 17:28:45 2016        
(r309366)
+++ head/usr.bin/locale/Makefile        Thu Dec  1 17:36:31 2016        
(r309367)
@@ -1,7 +1,6 @@
 # $FreeBSD$
 
 PROG=  locale
-WARNS?=        3
 CFLAGS+= -I${.CURDIR}/../../lib/libc/locale
 
 .include <bsd.prog.mk>

Modified: head/usr.bin/locale/locale.c
==============================================================================
--- head/usr.bin/locale/locale.c        Thu Dec  1 17:28:45 2016        
(r309366)
+++ head/usr.bin/locale/locale.c        Thu Dec  1 17:36:31 2016        
(r309367)
@@ -57,8 +57,8 @@ void  list_charmaps(void);
 void   list_locales(void);
 const char *lookup_localecat(int);
 char   *kwval_lconv(int);
-int    kwval_lookup(char *, char **, int *, int *);
-void   showdetails(char *);
+int    kwval_lookup(const char *, char **, int *, int *);
+void   showdetails(const char *);
 void   showkeywordslist(char *substring);
 void   showlocale(void);
 void   usage(void);
@@ -66,13 +66,12 @@ void        usage(void);
 /* Global variables */
 static StringList *locales = NULL;
 
-int    all_locales = 0;
-int    all_charmaps = 0;
-int    prt_categories = 0;
-int    prt_keywords = 0;
-int    more_params = 0;
+static int     all_locales = 0;
+static int     all_charmaps = 0;
+static int     prt_categories = 0;
+static int     prt_keywords = 0;
 
-struct _lcinfo {
+static const struct _lcinfo {
        const char      *name;
        int             id;
 } lcinfo [] = {
@@ -110,7 +109,7 @@ struct _lcinfo {
 #define        KW_INT_P_SIGN_POSN      (KW_ZERO+21)
 #define        KW_INT_N_SIGN_POSN      (KW_ZERO+22)
 
-struct _kwinfo {
+static const struct _kwinfo {
        const char      *name;
        int             isstr;          /* true - string, false - number */
        int             catid;          /* LC_* */
@@ -224,7 +223,7 @@ struct _kwinfo {
 };
 #define        NKWINFO (nitems(kwinfo))
 
-const char *boguslocales[] = { "UTF-8" };
+static const char *boguslocales[] = { "UTF-8" };
 #define        NBOGUS  (nitems(boguslocales))
 
 int
@@ -296,7 +295,7 @@ main(int argc, char *argv[])
                } else {
                        uint i;
                        for (i = 0; i < nitems(kwinfo); i++)
-                               showdetails ((char *)kwinfo [i].name);
+                               showdetails(kwinfo[i].name);
                }
                exit(0);
        }
@@ -341,7 +340,7 @@ list_locales(void)
 static int
 scmp(const void *s1, const void *s2)
 {
-       return strcmp(*(const char **)s1, *(const char **)s2);
+       return strcmp(*(const char * const *)s1, *(const char * const *)s2);
 }
 
 /*
@@ -378,7 +377,7 @@ list_charmaps(void)
 
        /* add US-ASCII, if not yet added */
        if (sl_find(charmaps, "US-ASCII") == NULL)
-               sl_add(charmaps, "US-ASCII");
+               sl_add(charmaps, strdup("US-ASCII"));
 
        /* sort the list */
        qsort(charmaps->sl_str, charmaps->sl_cur, sizeof(char *), scmp);
@@ -437,10 +436,10 @@ init_locales_list(void)
         * we also list 'C' for constistency
         */
        if (sl_find(locales, "POSIX") == NULL)
-               sl_add(locales, "POSIX");
+               sl_add(locales, strdup("POSIX"));
 
        if (sl_find(locales, "C") == NULL)
-               sl_add(locales, "C");
+               sl_add(locales, strdup("C"));
 
        /* make output nicer, sort the list */
        qsort(locales->sl_str, locales->sl_cur, sizeof(char *), scmp);
@@ -606,7 +605,7 @@ kwval_lconv(int id)
  * keyword value and properties lookup
  */
 int
-kwval_lookup(char *kwname, char **kwval, int *cat, int *isstr)
+kwval_lookup(const char *kwname, char **kwval, int *cat, int *isstr)
 {
        int     rval;
        size_t  i;
@@ -634,7 +633,7 @@ kwval_lookup(char *kwname, char **kwval,
  * command line options specified.
  */
 void
-showdetails(char *kw)
+showdetails(const char *kw)
 {
        int     isstr, cat, tmpval;
        char    *kwval;
@@ -649,9 +648,9 @@ showdetails(char *kw)
        }
 
        if (prt_categories) {
-                 if (prt_keywords)
+               if (prt_keywords)
                        printf("%-20s ", lookup_localecat(cat));
-                 else
+               else
                        printf("%-20s\t%s\n", kw, lookup_localecat(cat));
        }
 
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to