]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_slkset.c
ncurses 6.1 - patch 20200118
[ncurses.git] / ncurses / base / lib_slkset.c
index 51d0bfdec2d8c518337082b65fc745de8e55b1ed..66a4d043a6878f118dd65d9317977fa6f0ba1717 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2009 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2019 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            *
 #endif
 #endif
 
-MODULE_ID("$Id: lib_slkset.c,v 1.18 2009/02/15 00:33:48 tom Exp $")
+MODULE_ID("$Id: lib_slkset.c,v 1.25 2019/05/04 20:46:24 tom Exp $")
 
 NCURSES_EXPORT(int)
 NCURSES_SP_NAME(slk_set) (NCURSES_SP_DCLx int i, const char *astr, int format)
 {
     SLK *slk;
-    int offset;
+    int offset = 0;
     int numchrs;
     int numcols;
     int limit;
     const char *str = astr;
     const char *p;
 
-    T((T_CALLED("slk_set(%d, \"%s\", %d)"), i, str, format));
+    T((T_CALLED("slk_set(%p, %d, \"%s\", %d)"), (void *) SP_PARM, i, str, format));
 
     if (SP_PARM == 0
        || (slk = SP_PARM->_slk) == 0
@@ -66,7 +66,7 @@ NCURSES_SP_NAME(slk_set) (NCURSES_SP_DCLx int i, const char *astr, int format)
        || format < 0
        || format > 2)
        returnCode(ERR);
-    if (str == NULL)
+    if (str == 0)
        str = "";
     --i;                       /* Adjust numbering of labels */
 
@@ -89,17 +89,17 @@ NCURSES_SP_NAME(slk_set) (NCURSES_SP_DCLx int i, const char *astr, int format)
        mbrtowc(&wc, p, need, &state);
        if (!iswprint((wint_t) wc))
            break;
-       if (wcwidth(wc) + numcols > limit)
+       if (_nc_wacs_width(wc) + numcols > limit)
            break;
-       numcols += wcwidth(wc);
+       numcols += _nc_wacs_width(wc);
        p += need;
     }
-    numchrs = (p - str);
+    numchrs = (int) (p - str);
 #else
     while (isprint(UChar(*p)))
        p++;                    /* The first non-print stops */
 
-    numcols = (p - str);
+    numcols = (int) (p - str);
     if (numcols > limit)
        numcols = limit;
     numchrs = numcols;
@@ -111,13 +111,12 @@ NCURSES_SP_NAME(slk_set) (NCURSES_SP_DCLx int i, const char *astr, int format)
     slk->ent[i].ent_text[numchrs] = '\0';
 
     if ((slk->ent[i].form_text = (char *) _nc_doalloc(slk->ent[i].form_text,
-                                                     (unsigned) (limit +
-                                                                 numchrs + 1))
+                                                     (size_t) (limit +
+                                                               numchrs + 1))
        ) == 0)
        returnCode(ERR);
 
     switch (format) {
-    default:
     case 0:                    /* left-justified */
        offset = 0;
        break;
@@ -131,16 +130,16 @@ NCURSES_SP_NAME(slk_set) (NCURSES_SP_DCLx int i, const char *astr, int format)
     if (offset <= 0)
        offset = 0;
     else
-       memset(slk->ent[i].form_text, ' ', (unsigned) offset);
+       memset(slk->ent[i].form_text, ' ', (size_t) offset);
 
     memcpy(slk->ent[i].form_text + offset,
           slk->ent[i].ent_text,
-          (unsigned) numchrs);
+          (size_t) numchrs);
 
     if (offset < limit) {
        memset(slk->ent[i].form_text + offset + numchrs,
               ' ',
-              (unsigned) (limit - (offset + numcols)));
+              (size_t) (limit - (offset + numcols)));
     }
 
     slk->ent[i].form_text[numchrs - numcols + limit] = 0;