ncurses 5.7 - patch 20100424
[ncurses.git] / ncurses / tinfo / trim_sgr0.c
index 7e7d15dfbe5682f2a3f4d100cf99d2f7db25656b..4eb4951d02decd65cb8d95d49abee5457eadf225 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2005 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2005-2007,2010 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            *
@@ -35,9 +35,8 @@
 #include <ctype.h>
 
 #include <tic.h>
-#include <term_entry.h>
 
-MODULE_ID("$Id: trim_sgr0.c,v 1.5 2005/07/17 00:13:24 tom Exp $")
+MODULE_ID("$Id: trim_sgr0.c,v 1.10 2010/01/23 17:12:45 tom Exp $")
 
 #undef CUR
 #define CUR tp->
@@ -83,7 +82,7 @@ skip_delay(const char *s)
 {
     if (s[0] == '$' && s[1] == '<') {
        s += 2;
-       while ((*s != '\0') && (isdigit(*s) || *s == '/'))
+       while (isdigit(UChar(*s)) || *s == '/')
            ++s;
        if (*s == '>')
            ++s;
@@ -170,13 +169,13 @@ chop_out(char *string, unsigned i, unsigned j)
  * Returns the number of chars from 'full' that we matched.  If any mismatch
  * occurs, return zero.
  */
-static int
+static unsigned
 compare_part(const char *part, const char *full)
 {
     const char *next_part;
     const char *next_full;
-    int used_full = 0;
-    int used_delay = 0;
+    unsigned used_full = 0;
+    unsigned used_delay = 0;
 
     while (*part != 0) {
        if (*part != *full) {
@@ -199,7 +198,7 @@ compare_part(const char *part, const char *full)
            next_part = skip_delay(part);
            next_full = skip_delay(full);
            if (next_part != part && next_full != full) {
-               used_delay += (next_full - full);
+               used_delay += (unsigned) (next_full - full);
                full = next_full;
                part = next_part;
                continue;
@@ -247,9 +246,7 @@ _nc_trim_sgr0(TERMTYPE *tp)
        if (!rewrite_sgr(on, enter_alt_charset_mode)
            || !rewrite_sgr(off, exit_alt_charset_mode)
            || !rewrite_sgr(end, exit_alt_charset_mode)) {
-           FreeIfNeeded(on);
            FreeIfNeeded(off);
-           FreeIfNeeded(end);
        } else if (similar_sgr(off, end)
                   && !similar_sgr(off, on)) {
            TR(TRACE_DATABASE, ("adjusting sgr(9:off) : %s", _nc_visbuf(off)));
@@ -263,7 +260,8 @@ _nc_trim_sgr0(TERMTYPE *tp)
                k = strlen(exit_alt_charset_mode);
                if (j > k) {
                    for (i = 0; i <= (j - k); ++i) {
-                       int k2 = compare_part(exit_alt_charset_mode, off + i);
+                       unsigned k2 = compare_part(exit_alt_charset_mode,
+                                                  off + i);
                        if (k2 != 0) {
                            found = TRUE;
                            chop_out(off, i, i + k2);
@@ -276,17 +274,17 @@ _nc_trim_sgr0(TERMTYPE *tp)
             * SGR 10 would reset to normal font.
             */
            if (!found) {
-               if ((i = is_csi(off)) != 0
+               if ((i = (size_t) is_csi(off)) != 0
                    && off[strlen(off) - 1] == 'm') {
                    TR(TRACE_DATABASE, ("looking for SGR 10 in %s",
                                        _nc_visbuf(off)));
                    tmp = skip_zero(off + i);
                    if (tmp[0] == '1'
                        && skip_zero(tmp + 1) != tmp + 1) {
-                       i = tmp - off;
+                       i = (size_t) (tmp - off);
                        if (off[i - 1] == ';')
                            i--;
-                       j = skip_zero(tmp + 1) - off;
+                       j = (size_t) (skip_zero(tmp + 1) - off);
                        i = chop_out(off, i, j);
                        found = TRUE;
                    }
@@ -295,7 +293,7 @@ _nc_trim_sgr0(TERMTYPE *tp)
            if (!found
                && (tmp = strstr(end, off)) != 0
                && strcmp(end, off) != 0) {
-               i = tmp - end;
+               i = (size_t) (tmp - end);
                j = strlen(off);
                tmp = strdup(end);
                chop_out(tmp, i, j);
@@ -315,8 +313,8 @@ _nc_trim_sgr0(TERMTYPE *tp)
             */
            free(off);
        }
-       free(end);
-       free(on);
+       FreeIfNeeded(end);
+       FreeIfNeeded(on);
     } else {
        /*
         * Possibly some applications are confused if sgr0 contains rmacs,