]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_screen.c
ncurses 6.0 - patch 20150912
[ncurses.git] / ncurses / base / lib_screen.c
index 8569a556c79488d1e61acabe1c1f28e690866f27..484f36505063bbf0ad51844d16bee103ec674aa4 100644 (file)
@@ -41,7 +41,7 @@
 #define CUR SP_TERMTYPE
 #endif
 
 #define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_screen.c,v 1.70 2015/03/29 00:16:00 tom Exp $")
+MODULE_ID("$Id: lib_screen.c,v 1.78 2015/09/12 20:47:43 tom Exp $")
 
 #define MAX_SIZE 0x3fff                /* 16k is big enough for a window or pad */
 
 
 #define MAX_SIZE 0x3fff                /* 16k is big enough for a window or pad */
 
@@ -56,7 +56,7 @@ MODULE_ID("$Id: lib_screen.c,v 1.70 2015/03/29 00:16:00 tom Exp $")
  * mistaken for the _cury/_curx pair of 16-bit numbers which start the old
  * format.  It happens to be unused in the file 5.22 database (2015/03/07).
  */
  * mistaken for the _cury/_curx pair of 16-bit numbers which start the old
  * format.  It happens to be unused in the file 5.22 database (2015/03/07).
  */
-static char my_magic[] =
+static const char my_magic[] =
 {'\210', '\210', '\210', '\210'};
 
 #if NCURSES_EXT_PUTWIN
 {'\210', '\210', '\210', '\210'};
 
 #if NCURSES_EXT_PUTWIN
@@ -73,19 +73,19 @@ typedef enum {
 } PARAM_TYPE;
 
 typedef struct {
 } PARAM_TYPE;
 
 typedef struct {
-    const char *name;
+    const char name[11];
     attr_t attr;
 } SCR_ATTRS;
 
 typedef struct {
     attr_t attr;
 } SCR_ATTRS;
 
 typedef struct {
-    const char *name;
+    const char name[17];
     PARAM_TYPE type;
     size_t size;
     size_t offset;
 } SCR_PARAMS;
 
     PARAM_TYPE type;
     size_t size;
     size_t offset;
 } SCR_PARAMS;
 
-#define DATA(name) { #name, A_##name }
-static SCR_ATTRS scr_attrs[] =
+#define DATA(name) { { #name }, A_##name }
+static const SCR_ATTRS scr_attrs[] =
 {
     DATA(NORMAL),
     DATA(STANDOUT),
 {
     DATA(NORMAL),
     DATA(STANDOUT),
@@ -111,9 +111,9 @@ static SCR_ATTRS scr_attrs[] =
 #undef DATA
 
 #define sizeof2(type,name) sizeof(((type *)0)->name)
 #undef DATA
 
 #define sizeof2(type,name) sizeof(((type *)0)->name)
-#define DATA(name, type) { #name, type, sizeof2(WINDOW, name), offsetof(WINDOW, name) }
+#define DATA(name, type) { { #name }, type, sizeof2(WINDOW, name), offsetof(WINDOW, name) }
 
 
-static SCR_PARAMS scr_params[] =
+static const SCR_PARAMS scr_params[] =
 {
     DATA(_cury, pSIZE),
     DATA(_curx, pSIZE),
 {
     DATA(_cury, pSIZE),
     DATA(_curx, pSIZE),
@@ -179,6 +179,7 @@ read_txt(FILE *fp)
                    result = 0;
                    break;
                }
                    result = 0;
                    break;
                }
+               result = buffer;
            }
            ch = fgetc(fp);
            if (ch == EOF)
            }
            ch = fgetc(fp);
            if (ch == EOF)
@@ -220,16 +221,16 @@ decode_attr(char *source, attr_t *target, int *color)
                ++next;
            } else if (*next == 'C') {
                int value = 0;
                ++next;
            } else if (*next == 'C') {
                int value = 0;
+               unsigned pair;
                next++;
                while (isdigit(UChar(*next))) {
                    value = value * 10 + (*next++ - '0');
                }
                *target &= ~A_COLOR;
                next++;
                while (isdigit(UChar(*next))) {
                    value = value * 10 + (*next++ - '0');
                }
                *target &= ~A_COLOR;
-               if (value > 256) {
-                   *target |= COLOR_PAIR(255);
-               } else {
-                   *target |= COLOR_PAIR(value);
-               }
+               pair = (unsigned) ((value > 256)
+                                  ? COLOR_PAIR(255)
+                                  : COLOR_PAIR(value));
+               *target |= pair;
                *color = value;
            } else {
                while (isalnum(UChar(*next))) {
                *color = value;
            } else {
                while (isalnum(UChar(*next))) {
@@ -315,13 +316,13 @@ static char *
 decode_chtype(char *source, chtype fillin, chtype *target)
 {
     attr_t attr = ChAttrOf(fillin);
 decode_chtype(char *source, chtype fillin, chtype *target)
 {
     attr_t attr = ChAttrOf(fillin);
-    int color = PAIR_NUMBER(attr);
+    int color = PAIR_NUMBER((int) attr);
     int value;
 
     T(("decode_chtype '%s'", source));
     source = decode_attr(source, &attr, &color);
     source = decode_char(source, &value);
     int value;
 
     T(("decode_chtype '%s'", source));
     source = decode_attr(source, &attr, &color);
     source = decode_char(source, &value);
-    *target = ChCharOf(value) | attr | COLOR_PAIR(color);
+    *target = (ChCharOf(value) | attr | (chtype) COLOR_PAIR(color));
     /* FIXME - ignore combining characters */
     return source;
 }
     /* FIXME - ignore combining characters */
     return source;
 }
@@ -334,6 +335,7 @@ decode_cchar(char *source, cchar_t *fillin, cchar_t *target)
     attr_t attr = fillin->attr;
     wchar_t chars[CCHARW_MAX];
     int append = 0;
     attr_t attr = fillin->attr;
     wchar_t chars[CCHARW_MAX];
     int append = 0;
+    int value = 0;
 
     T(("decode_cchar  '%s'", source));
     *target = blank;
 
     T(("decode_cchar  '%s'", source));
     *target = blank;
@@ -344,14 +346,14 @@ decode_cchar(char *source, cchar_t *fillin, cchar_t *target)
 #endif
     source = decode_attr(source, &attr, &color);
     memset(chars, 0, sizeof(chars));
 #endif
     source = decode_attr(source, &attr, &color);
     memset(chars, 0, sizeof(chars));
-    source = decode_char(source, &chars[0]);
+    source = decode_char(source, &value);
+    chars[0] = (wchar_t) value;
     /* handle combining characters */
     while (source[0] == MARKER && source[1] == APPEND) {
     /* handle combining characters */
     while (source[0] == MARKER && source[1] == APPEND) {
-       int value;
        source += 2;
        source = decode_char(source, &value);
        source += 2;
        source = decode_char(source, &value);
-       if (append++ < CCHARW_MAX) {
-           chars[append] = value;
+       if (++append < CCHARW_MAX) {
+           chars[append] = (wchar_t) value;
        }
     }
     setcchar(target, chars, attr, (short) color, NULL);
        }
     }
     setcchar(target, chars, attr, (short) color, NULL);
@@ -668,7 +670,7 @@ encode_attr(char *target, attr_t source, attr_t prior)
        if ((source & A_COLOR) != (prior & A_COLOR)) {
            if (!first)
                *target++ = '|';
        if ((source & A_COLOR) != (prior & A_COLOR)) {
            if (!first)
                *target++ = '|';
-           sprintf(target, "C%d", PAIR_NUMBER(source));
+           sprintf(target, "C%d", PAIR_NUMBER((int) source));
            target += strlen(target);
        }
 
            target += strlen(target);
        }
 
@@ -694,21 +696,22 @@ encode_cell(char *target, CARG_CH_T source, CARG_CH_T previous)
     }
 #endif
     for (n = 0; n < SIZEOF(source->chars); ++n) {
     }
 #endif
     for (n = 0; n < SIZEOF(source->chars); ++n) {
-       if (source->chars[n] == 0)
+       unsigned uch = (unsigned) source->chars[n];
+       if (uch == 0)
            continue;
        if (n) {
            *target++ = MARKER;
            *target++ = APPEND;
        }
        *target++ = MARKER;
            continue;
        if (n) {
            *target++ = MARKER;
            *target++ = APPEND;
        }
        *target++ = MARKER;
-       if (source->chars[n] > 0xffff) {
-           sprintf(target, "U%08x", source->chars[n]);
-       } else if (source->chars[n] > 0xff) {
-           sprintf(target, "u%04x", source->chars[n]);
-       } else if (source->chars[n] < 32 || source->chars[n] >= 127) {
-           sprintf(target, "%03o", source->chars[n] & 0xff);
+       if (uch > 0xffff) {
+           sprintf(target, "U%08x", uch);
+       } else if (uch > 0xff) {
+           sprintf(target, "u%04x", uch);
+       } else if (uch < 32 || uch >= 127) {
+           sprintf(target, "%03o", uch & 0xff);
        } else {
        } else {
-           switch (source->chars[n]) {
+           switch (uch) {
            case ' ':
                strcpy(target, "s");
                break;
            case ' ':
                strcpy(target, "s");
                break;
@@ -717,7 +720,7 @@ encode_cell(char *target, CARG_CH_T source, CARG_CH_T previous)
                *target = '\0';
                break;
            default:
                *target = '\0';
                break;
            default:
-               sprintf(--target, "%c", source->chars[n]);
+               sprintf(--target, "%c", uch);
                break;
            }
        }
                break;
            }
        }
@@ -733,7 +736,7 @@ encode_cell(char *target, CARG_CH_T source, CARG_CH_T previous)
     target += strlen(target);
     *target++ = MARKER;
     if (ch < 32 || ch >= 127) {
     target += strlen(target);
     *target++ = MARKER;
     if (ch < 32 || ch >= 127) {
-       sprintf(target, "%03o", ch);
+       sprintf(target, "%03o", UChar(ch));
     } else {
        switch (ch) {
        case ' ':
     } else {
        switch (ch) {
        case ' ':
@@ -744,11 +747,10 @@ encode_cell(char *target, CARG_CH_T source, CARG_CH_T previous)
            *target = '\0';
            break;
        default:
            *target = '\0';
            break;
        default:
-           sprintf(--target, "%c", ch);
+           sprintf(--target, "%c", UChar(ch));
            break;
        }
     }
            break;
        }
     }
-    target += strlen(target);
 #endif
 }
 #endif
 #endif
 }
 #endif
@@ -841,12 +843,18 @@ putwin(WINDOW *win, FILE *filep)
                || ferror(filep))
                returnCode(code);
            for (x = 0; x <= win->_maxx; x++) {
                || ferror(filep))
                returnCode(code);
            for (x = 0; x <= win->_maxx; x++) {
+#if NCURSES_WIDECHAR
                int len = wcwidth(data[x].chars[0]);
                encode_cell(buffer, CHREF(data[x]), CHREF(last_cell));
                last_cell = data[x];
                PUTS(buffer);
                if (len > 1)
                    x += (len - 1);
                int len = wcwidth(data[x].chars[0]);
                encode_cell(buffer, CHREF(data[x]), CHREF(last_cell));
                last_cell = data[x];
                PUTS(buffer);
                if (len > 1)
                    x += (len - 1);
+#else
+               encode_cell(buffer, CHREF(data[x]), CHREF(last_cell));
+               last_cell = data[x];
+               PUTS(buffer);
+#endif
            }
            PUTS("\n");
        }
            }
            PUTS("\n");
        }