Changeset: af3da2264af5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=af3da2264af5
Modified Files:
        
Branch: default
Log Message:

Merge with Oct2010 branch.


diffs (238 lines):

diff -r 44f144d7eeb4 -r af3da2264af5 clients/ChangeLog.Oct2010
--- a/clients/ChangeLog.Oct2010 Thu Nov 11 14:35:09 2010 +0100
+++ b/clients/ChangeLog.Oct2010 Fri Nov 12 15:40:40 2010 +0100
@@ -1,3 +1,6 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Fri Nov 12 2010 Sjoerd Mullender <sjo...@acm.org>
+- Fixed a corner case in the table display code.
+
diff -r 44f144d7eeb4 -r af3da2264af5 clients/src/mapiclient/mclient.c
--- a/clients/src/mapiclient/mclient.c  Thu Nov 11 14:35:09 2010 +0100
+++ b/clients/src/mapiclient/mclient.c  Fri Nov 12 15:40:40 2010 +0100
@@ -362,15 +362,16 @@
        }
 }
 
-/* return the display length of a UTF-8 string */
+/* return the display length of a UTF-8 string
+   if e is not NULL, return length up to e */
 static size_t
-utf8strlen(const char *s)
+utf8strlen(const char *s, const char *e)
 {
        size_t len = 0;
 
        if (s == NULL)
                return 0;
-       while (*s) {
+       while (*s && (e == NULL || s < e)) {
                /* only count first byte of a sequence */
                if ((*s & 0xC0) != 0x80)
                        len++;
@@ -410,10 +411,10 @@
        if (trim == 1) {
                for (i = 0; i < fields; i++) {
                        if ((t = rest[i]) != NULL &&
-                                       utf8strlen(t) > (size_t) len[i])
+                           utf8strlen(t, NULL) > (size_t) len[i])
                        {
                                /* eat leading whitespace */
-                               while (*t != 0 && isspace((int) *t))
+                               while (*t != 0 && isascii((int) *t) && 
isspace((int) *t))
                                        t++;
                                rest[i] = t;
                        }
@@ -431,7 +432,7 @@
                                                first ? '|' : i > 0 && 
cutafter[i - 1] == 0 ? '>' : ':',
                                                len[i], "");
                        } else {
-                               ulen = utf8strlen(rest[i]);
+                               ulen = utf8strlen(rest[i], NULL);
 
                                if (first && trim == 2) {
                                        /* calculate the height of this field 
according to
@@ -449,27 +450,43 @@
                                 * left-adjust them in the column */
                                t = strchr(rest[i], '\n');
                                if (ulen > (size_t) len[i] || t) {
+                                       char *s;
+
                                        t = utf8skip(rest[i], len[i]);
                                        if (trim == 1) {
-                                               while (t > rest[i] && 
!isspace((int) *t))
+                                               while (t > rest[i] && 
!(isascii((int) *t) && isspace((int) *t)))
                                                        while ((*--t & 0xC0) == 
0x80)
                                                                ;
-                                               if (t == rest[i] && 
!isspace((int) *t))
+                                               if (t == rest[i] && 
!(isascii((int) *t) && isspace((int) *t)))
                                                        t = utf8skip(rest[i], 
len[i]);
                                        }
                                        mnstr_printf(toConsole, "%c",
-                                                     first ? '|' : i > 0 && 
cutafter[i - 1] == 0 ? '>' : ':');
+                                                    first ? '|' : i > 0 && 
cutafter[i - 1] == 0 ? '>' : ':');
                                        if (numeric[i])
                                                mnstr_printf(toConsole, "%*s",
-                                                             (int) (len[i] - 
(ulen - utf8strlen(t))),
-                                                             "");
-                                       if ((int)(ulen - utf8strlen(t)) >= 
len[i] - 2 &&
-                                                       cutafter[i] == 0)
-                                       {
+                                                            (int) (len[i] - 
(ulen - utf8strlen(t, NULL))),
+                                                            "");
+                                       s = t;
+                                       if (trim == 1)
+                                               while (isascii((int) *s) &&
+                                                      isspace((int) *s))
+                                                       s++;
+                                       if (trim == 2 && *s == '\n')
+                                               s++;
+                                       if (*s && cutafter[i] == 0) {
                                                t = utf8skip(rest[i], len[i] - 
2);
-                                               mnstr_printf(toConsole, " 
%.*s...",
-                                                                 (int) (t - 
rest[i]),
-                                                                 rest[i]);
+                                               s = t;
+                                               if (trim == 1)
+                                                       while (isascii((int) 
*s) &&
+                                                              isspace((int) 
*s))
+                                                               s++;
+                                               if (trim == 2 && *s == '\n')
+                                                       s++;
+                                               mnstr_printf(toConsole, " 
%.*s...%*s",
+                                                            (int) (t - 
rest[i]),
+                                                            rest[i],
+                                                            len[i] - 2 - (int) 
utf8strlen(rest[i], t),
+                                                            "");
                                                croppedfields++;
                                        } else {
                                                mnstr_printf(toConsole, " %.*s 
",
@@ -477,19 +494,15 @@
                                                                  rest[i]);
                                                if (!numeric[i])
                                                        mnstr_printf(toConsole, 
"%*s",
-                                                                         (int) 
(len[i] - (ulen - utf8strlen(t))),
-                                                                         "");
+                                                                    (int) 
(len[i] - (ulen - utf8strlen(t, NULL))),
+                                                                    "");
+                                       }
+                                       rest[i] = *s ? s : 0;
+                                       if (rest[i] == NULL) {
                                                /* avoid > as border marker if 
everything
                                                 * actually just fits */
-                                               if (cutafter[i] == 0)
-                                                       cutafter[i] = -1;
+                                               cutafter[i] = -1;
                                        }
-                                       if (trim == 1)
-                                               while (isspace((int) *t))
-                                                       t++;
-                                       if (trim == 2 && *t == '\n')
-                                               t++;
-                                       rest[i] = *t ? t : 0;
                                        if (cutafter[i] == 0)
                                                rest[i] = NULL;
                                        if (rest[i])
@@ -1886,6 +1899,7 @@
                        if (mode != MAL)
                                while (length > 0 &&
                                       (*line & ~0x7F) == 0 &&
+                                      isascii((int) *line) &&
                                       isspace((int) *line)) {
                                        line++;
                                        length--;
@@ -1943,13 +1957,14 @@
                                case 'd':
                                        if (mode != SQL)
                                                break;
-                                       while (isspace((int) line[length - 1]))
+                                       while (isascii((int) line[length - 1]) 
&&
+                                              isspace((int) line[length - 1]))
                                                line[--length] = 0;
-                                       if (line[2] && !isspace(line[2])) {
+                                       if (line[2] && !(isascii((int) line[2]) 
&& isspace(line[2]))) {
                                                fprintf(stderr, "space required 
after \\d\n");
                                                continue;
                                        }
-                                       for (line += 2; *line && isspace((int) 
*line); line++)
+                                       for (line += 2; *line && isascii((int) 
*line) && isspace((int) *line); line++)
                                                ;
                                        if (*line) {
 #ifdef HAVE_POPEN
@@ -1995,13 +2010,14 @@
 
                                        if (mode != SQL)
                                                break;
-                                       while (isspace((int) line[length - 1]))
+                                       while (isascii((int) line[length - 1]) 
&&
+                                              isspace((int) line[length - 1]))
                                                line[--length] = 0;
-                                       if (line[2] && !isspace(line[2])) {
+                                       if (line[2] && !(isascii((int) line[2]) 
&& isspace(line[2]))) {
                                                fprintf(stderr, "space required 
after \\D\n");
                                                continue;
                                        }
-                                       for (line += 2; *line && isspace((int) 
*line); line++)
+                                       for (line += 2; *line && isascii((int) 
*line) && isspace((int) *line); line++)
                                                ;
 #ifdef HAVE_POPEN
                                        start_pager(&saveFD, &saveFD_raw);
@@ -2019,17 +2035,17 @@
                                }
                                case '<':
                                        /* read commands from file */
-                                       while (isspace((int) line[length - 1]))
+                                       while (isascii((int) line[length - 1]) 
&& isspace((int) line[length - 1]))
                                                line[--length] = 0;
-                                       for (line += 2; *line && isspace((int) 
*line); line++)
+                                       for (line += 2; *line && isascii((int) 
*line) && isspace((int) *line); line++)
                                                ;
                                        doFile(mid, line);
                                        continue;
                                case '>':
                                        /* redirect output to file */
-                                       while (isspace((int) line[length - 1]))
+                                       while (isascii((int) line[length - 1]) 
&& isspace((int) line[length - 1]))
                                                line[--length] = 0;
-                                       for (line += 2; *line && isspace((int) 
*line); line++)
+                                       for (line += 2; *line && isascii((int) 
*line) && isspace((int) *line); line++)
                                                ;
                                        if (toConsole != stdout_stream && 
toConsole != stderr_stream) {
                                                mnstr_close(toConsole);
@@ -2052,9 +2068,9 @@
                                case 'L':
                                        free(logfile);
                                        logfile = NULL;
-                                       while (isspace((int) line[length - 1]))
+                                       while (isascii((int) line[length - 1]) 
&& isspace((int) line[length - 1]))
                                                line[--length] = 0;
-                                       for (line += 2; *line && isspace((int) 
*line); line++)
+                                       for (line += 2; *line && isascii((int) 
*line) && isspace((int) *line); line++)
                                                ;
                                        if (*line == 0) {
                                                /* turn of logging */
@@ -2074,9 +2090,9 @@
                                        pager = NULL;
                                        setWidth();     /* reset to system 
default */
 
-                                       while (isspace((int) line[length - 1]))
+                                       while (isascii((int) line[length - 1]) 
&& isspace((int) line[length - 1]))
                                                line[--length] = 0;
-                                       for (line += 2; *line && isspace((int) 
*line); line++)
+                                       for (line += 2; *line && isascii((int) 
*line) && isspace((int) *line); line++)
                                                ;
                                        if (*line == 0)
                                                continue;
@@ -2116,9 +2132,9 @@
                                        echoquery = 1;
                                        continue;
                                case 'f':
-                                       while (isspace((int) line[length - 1]))
+                                       while (isascii((int) line[length - 1]) 
&& isspace((int) line[length - 1]))
                                                line[--length] = 0;
-                                       for (line += 2; *line && isspace((int) 
*line); line++)
+                                       for (line += 2; *line && isascii((int) 
*line) && isspace((int) *line); line++)
                                                ;
                                        if (*line == 0) {
                                                mnstr_printf(toConsole, 
"Current formatter: ");
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to