Changeset: 8c2774f266aa for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8c2774f266aa
Modified Files:
        clients/ChangeLog.Apr2012
        clients/mapiclient/mclient.c
Branch: Apr2012
Log Message:

mclient: avoid misalignment when tabs are in the string values

When a tab occurs in the tuple values, misalignment would occur when
printing the tabular grid, since the tab takes only one "character" in
width calculations, but may result in at max 8 when printing to the
screen.
Taking into account that a tab can be 1 to 8 characters when printing,
based on the starting position is hard, so alternative would be to
replace the tab with multiple (a fixed amount of) spaces instead.  Doing
this, however, makes calculating the length of the strings, and places
to cut off (also taking into account UTF-8 encoding of the strings) very
complex.  It advocates to do a global replacement of all tabs with the
desired amount of spaces a priori, which requires expensive (re)mallocs.

Hence, instead, we just replace all tab-characters with a single space,
such that the originally reported width (by the server), as well as the
calculated utf8strlen (which both count that tab as one "character")
match with what we print, and hence all alignment calculations can
remain unmodified and result in the correct offsets.


diffs (62 lines):

diff --git a/clients/ChangeLog.Apr2012 b/clients/ChangeLog.Apr2012
--- a/clients/ChangeLog.Apr2012
+++ b/clients/ChangeLog.Apr2012
@@ -1,3 +1,8 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Wed May 23 2012 Fabian Groffen <[email protected]>
+- Resolved a cosmetical error where tab-characters would cause
+  misalignments in tabular result views.  For the time being, tabs are
+  now represented as a single space in tabular view.
+
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -469,6 +469,15 @@ SQLrow(int *len, int *numeric, char **re
                                                mnstr_printf(toConsole, "%*s",
                                                             (int) (len[i] - 
(ulen - utf8strlen(t, NULL))),
                                                             "");
+
+                                       if (!numeric[i]) {
+                                               /* replace tabs with a single 
space to avoid
+                                                * screwup the width 
calculations */
+                                               for (s = rest[i]; *s != *t; s++)
+                                                       if (*s == '\t')
+                                                               *s = ' ';
+                                       }
+
                                        s = t;
                                        if (trim == 1)
                                                while (isascii((int) *s) &&
@@ -513,16 +522,26 @@ SQLrow(int *len, int *numeric, char **re
                                } else {
                                        mnstr_printf(toConsole, "%c",
                                                        first ? '|' : i > 0 && 
cutafter[i - 1] == 0 ? '>' : ':');
-                                       if (numeric[i])
+                                       if (numeric[i]) {
                                                mnstr_printf(toConsole, "%*s",
                                                              (int) (len[i] - 
ulen),
                                                              "");
-                                       mnstr_printf(toConsole, " %s ",
-                                                     rest[i]);
-                                       if (!numeric[i])
+                                               mnstr_printf(toConsole, " %s ",
+                                                                 rest[i]);
+                                       }
+                                       if (!numeric[i]) {
+                                               char *p;
+                                               /* replace tabs with a single 
space to avoid
+                                                * screwup the width 
calculations */
+                                               for (p = rest[i]; *p != '\0'; 
p++)
+                                                       if (*p == '\t')
+                                                               *p = ' ';
+                                               mnstr_printf(toConsole, " %s ",
+                                                                 rest[i]);
                                                mnstr_printf(toConsole, "%*s",
                                                              (int) (len[i] - 
ulen),
                                                              "");
+                                       }
                                        rest[i] = 0;
                                        /* avoid > as border marker if 
everything
                                         * actually just fits */
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to