]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_screen.c
ncurses 6.2 - patch 20200531
[ncurses.git] / ncurses / base / lib_screen.c
index 729c11da93bb601c849a38a52acf09d38fff4711..6afba6611c6178f13c15105a290a2573577b472e 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2017,2018 Free Software Foundation, Inc.              *
+ * Copyright 2019,2020 Thomas E. Dickey                                     *
+ * Copyright 1998-2017,2018 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            *
@@ -41,7 +42,7 @@
 #define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_screen.c,v 1.92 2018/01/07 02:22:55 tom Exp $")
+MODULE_ID("$Id: lib_screen.c,v 1.100 2020/05/25 22:48:41 tom Exp $")
 
 #define MAX_SIZE 0x3fff                /* 16k is big enough for a window or pad */
 
@@ -57,7 +58,7 @@ MODULE_ID("$Id: lib_screen.c,v 1.92 2018/01/07 02:22:55 tom Exp $")
 #define ARG_SLIMIT(name)       /* nothing */
 #endif
 
-#define CUR_SLIMIT _nc_SLIMIT(limit - (target - base))
+#define CUR_SLIMIT _nc_SLIMIT(limit - (size_t) (target - base))
 #define TOP_SLIMIT _nc_SLIMIT(sizeof(buffer))
 
 /*
@@ -66,7 +67,7 @@ MODULE_ID("$Id: lib_screen.c,v 1.92 2018/01/07 02:22:55 tom Exp $")
  * format.  It happens to be unused in the file 5.22 database (2015/03/07).
  */
 static const char my_magic[] =
-{'\210', '\210', '\210', '\210'};
+{'\210', '\210', '\210', '\210', 0};
 
 #if NCURSES_EXT_PUTWIN
 typedef enum {
@@ -440,14 +441,14 @@ read_win(WINDOW *win, FILE *fp)
 }
 
 static int
-read_row(char *source, NCURSES_CH_T * prior, NCURSES_CH_T * target, int length)
+read_row(char *source, NCURSES_CH_T *prior, NCURSES_CH_T *target, int length)
 {
     while (*source != '\0' && length > 0) {
 #if NCURSES_WIDECHAR
        int len;
 
        source = decode_cchar(source, prior, target);
-       len = wcwidth(target->chars[0]);
+       len = _nc_wacs_width(target->chars[0]);
        if (len > 1) {
            int n;
 
@@ -514,13 +515,13 @@ NCURSES_SP_NAME(getwin) (NCURSES_SP_DCLx FILE *filep)
      * Read the first 4 bytes to determine first if this is an old-format
      * screen-dump, or new-format.
      */
-    if (read_block(&tmp, 4, filep) < 0) {
+    if (read_block(&tmp, (size_t) 4, filep) < 0) {
        returnWin(0);
     }
     /*
      * If this is a new-format file, and we do not support it, give up.
      */
-    if (!memcmp(&tmp, my_magic, 4)) {
+    if (!memcmp(&tmp, my_magic, (size_t) 4)) {
 #if NCURSES_EXT_PUTWIN
        if (read_win(&tmp, filep) < 0)
 #endif
@@ -823,7 +824,7 @@ putwin(WINDOW *win, FILE *filep)
            attr_t attr;
 
            *buffer = '\0';
-           if (!strncmp(name, "_pad.", 5) && !(win->_flags & _ISPAD)) {
+           if (!strncmp(name, "_pad.", (size_t) 5) && !(win->_flags & _ISPAD)) {
                continue;
            }
            switch (scr_params[y].type) {
@@ -832,7 +833,7 @@ putwin(WINDOW *win, FILE *filep)
                encode_attr(buffer, TOP_SLIMIT
                            (*(const attr_t *) dp) & ~A_CHARTEXT,
                            A_NORMAL,
-                           (int) COLOR_PAIR(attr),
+                           COLOR_PAIR((int) attr),
                            0);
                break;
            case pBOOL:
@@ -847,7 +848,7 @@ putwin(WINDOW *win, FILE *filep)
                encode_attr(buffer, TOP_SLIMIT
                            * (const attr_t *) dp,
                            A_NORMAL,
-                           (int) COLOR_PAIR(attr),
+                           COLOR_PAIR((int) attr),
                            0);
                break;
            case pINT:
@@ -894,7 +895,7 @@ putwin(WINDOW *win, FILE *filep)
                returnCode(code);
            for (x = 0; x <= win->_maxx; x++) {
 #if NCURSES_WIDECHAR
-               int len = wcwidth(data[x].chars[0]);
+               int len = _nc_wacs_width(data[x].chars[0]);
                encode_cell(buffer, TOP_SLIMIT CHREF(data[x]), CHREF(last_cell));
                last_cell = data[x];
                PUTS(buffer);
@@ -948,7 +949,7 @@ NCURSES_SP_NAME(scr_restore) (NCURSES_SP_DCLx const char *file)
     T((T_CALLED("scr_restore(%p,%s)"), (void *) SP_PARM, _nc_visbuf(file)));
 
     if (_nc_access(file, R_OK) >= 0
-       && (fp = fopen(file, "rb")) != 0) {
+       && (fp = fopen(file, BIN_R)) != 0) {
        delwin(NewScreen(SP_PARM));
        NewScreen(SP_PARM) = getwin(fp);
 #if !USE_REENTRANT
@@ -979,7 +980,7 @@ scr_dump(const char *file)
     T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file)));
 
     if (_nc_access(file, W_OK) < 0
-       || (fp = fopen(file, "wb")) == 0) {
+       || (fp = fopen(file, BIN_W)) == 0) {
        result = ERR;
     } else {
        (void) putwin(newscr, fp);
@@ -1006,7 +1007,7 @@ NCURSES_SP_NAME(scr_init) (NCURSES_SP_DCLx const char *file)
        FILE *fp = 0;
 
        if (_nc_access(file, R_OK) >= 0
-           && (fp = fopen(file, "rb")) != 0) {
+           && (fp = fopen(file, BIN_R)) != 0) {
            delwin(CurScreen(SP_PARM));
            CurScreen(SP_PARM) = getwin(fp);
 #if !USE_REENTRANT