Update to CVS snapshot, for testing
[alioth/jupp.git] / scrn.c
diff --git a/scrn.c b/scrn.c
index 0c520c4..a26d2eb 100644 (file)
--- a/scrn.c
+++ b/scrn.c
@@ -1,4 +1,4 @@
-/* $MirOS: contrib/code/jupp/scrn.c,v 1.19 2017/01/10 23:59:33 tg Exp $ */
+/* $MirOS: contrib/code/jupp/scrn.c,v 1.25 2017/07/09 01:19:54 tg Exp $ */
 /*
  *     Device independant TTY interface for JOE
  *     Copyright
@@ -205,26 +205,22 @@ void outatr(struct charmap *map,SCRN *t,int *scrn,int *attrf,int xx,int yy,int c
                if(locale_map->type) {
                        /* UTF-8 char to UTF-8 terminal */
                        int wid;
-                       int uni_ctrl = 0;
-                       unsigned char buf[16];
 
-                       /* Deal with control characters */
-                       if (c<32) {
-                               c = c + '@';
-                               a ^= UNDERLINE;
-                       } else if (c==127) {
-                               c = '?';
-                               a ^= UNDERLINE;
-                       } else if (unictrl(c)) {
+                       switch ((wid = unictrl(c))) {
+                       case 0:
+                               /* not a control character */
+                               wid = joe_wcwidth(1, c);
+                               break;
+                       case 1:
+                               c ^= 0x40;
+                       default:
                                a ^= UNDERLINE;
-                               uni_ctrl = 1;
+                               break;
                        }
 
                        if(*scrn==c && *attrf==a)
                                return;
 
-                       wid = joe_wcwidth(1,c);
-
                        *scrn = c;
                        *attrf = a;
                        if(t->ins)
@@ -233,12 +229,15 @@ void outatr(struct charmap *map,SCRN *t,int *scrn,int *attrf,int xx,int yy,int c
                                cpos(t, xx, yy);
                        if(t->attrib != a)
                                set_attr(t, a);
-                       if (uni_ctrl) {
-                               joe_snprintf_1((char *)buf,16,"<%X>",c);
-                               ttputs(buf);
+                       if (*unictrlbuf) {
+                               ttputs(unictrlbuf);
                        } else {
+                               unsigned char buf[7];
+
                                utf8_encode(buf,c);
                                ttputs(buf);
+                               if (wid == 0 && xx > 0)
+                                       attrf[-1] |= HAS_COMBINING;
                        }
                        t->x+=wid;
                        while (wid>1) {
@@ -304,7 +303,7 @@ void outatr(struct charmap *map,SCRN *t,int *scrn,int *attrf,int xx,int yy,int c
                        t->x++;
                } else {
                        /* Non UTF-8 char to UTF-8 terminal */
-                       unsigned char buf[16];
+                       unsigned char buf[7];
                        int wid;
 
                        /* Deal with control characters */
@@ -1212,6 +1211,10 @@ int cpos(register SCRN *t, register int x, register int y)
                                if(*cs<32 || *cs>=127)
                                        break;
 
+                               /* has a combining character attached? */
+                               if (*as & HAS_COMBINING)
+                                       break;
+
                                if (*as != t->attrib)
                                        set_attr(t, *as);
 
@@ -1379,7 +1382,8 @@ void magic(SCRN *t, int y, int *cs, int *ca,int *s, int *a, int placex)
                        if (q > 0) {
                                int z, fu;
 
-                               for (z = x; z != t->co - 1 && ofst[z] == q; ++z) ;
+                               for (z = x; z != t->co - 1 && ofst[z] == q; ++z)
+                                       ;
                                while (s[x] == cs[x] && x < placex)
                                        ++x;
                                dodelchr(t, x, y, q);
@@ -1390,7 +1394,8 @@ void magic(SCRN *t, int y, int *cs, int *ca,int *s, int *a, int placex)
                        } else {
                                int z, fu;
 
-                               for (z = x; z != t->co - 1 && ofst[z] == q; ++z) ;
+                               for (z = x; z != t->co - 1 && ofst[z] == q; ++z)
+                                       ;
                                while (s[x + q] == cs[x + q] && x - q < placex)
                                        ++x;
                                doinschr(t, x + q, y, s + x + q, a + x + q, -q);
@@ -1561,12 +1566,14 @@ void nscroll(SCRN *t)
                                doupscrl(t, y, z + q, q);
                                y = z - 1;
                        } else {
-                               for (r = y; r != t->li && (t->sary[r] < 0 || t->sary[r] == t->li); ++r) ;
+                               for (r = y; r != t->li && (t->sary[r] < 0 || t->sary[r] == t->li); ++r)
+                                       ;
                                p = r - 1;
                                do {
                                        q = t->sary[p];
                                        if (q && q != t->li) {
-                                               for (z = p; t->sary[z] = 0, (z && t->sary[z - 1] == q); --z) ;
+                                               for (z = p; t->sary[z] = 0, (z && t->sary[z - 1] == q); --z)
+                                                       ;
                                                dodnscrl(t, z + q, p + 1, -q);
                                                p = z + 1;
                                        }
@@ -1640,7 +1647,7 @@ void nscrldn(SCRN *t, int top, int bot, int amnt)
                for (x = top; x != top + amnt; ++x) {
                        t->updtab[x] = 1;
                        t->syntab[x] = -1;
-                       }
+               }
        }
        if (amnt > bot - top)
                amnt = bot - top;
@@ -1648,7 +1655,7 @@ void nscrldn(SCRN *t, int top, int bot, int amnt)
        if (amnt == bot - top) {
                msetI(t->updtab + top, 1, amnt);
                msetI(t->syntab + top, -1, amnt);
-               }
+       }
 }
 
 void nscrlup(SCRN *t, int top, int bot, int amnt)
@@ -1668,7 +1675,7 @@ void nscrlup(SCRN *t, int top, int bot, int amnt)
                for (x = bot - amnt; x != bot; ++x) {
                        t->updtab[x] = 1;
                        t->syntab[x] = -1;
-                       }
+               }
        }
        if (amnt > bot - top)
                amnt = bot - top;
@@ -1676,7 +1683,7 @@ void nscrlup(SCRN *t, int top, int bot, int amnt)
        if (amnt == bot - top) {
                msetI(t->updtab + bot - amnt, 1, amnt);
                msetI(t->syntab + bot - amnt, -1, amnt);
-               }
+       }
 }
 
 extern volatile int dostaupd;
@@ -1800,9 +1807,9 @@ void genfield(SCRN *t,int *scrn,int *attr,int x,int y,int ofst,unsigned char *s,
                                wid = joe_wcwidth(1,c);
                } else {
                        /* Byte mode: character is one column wide */
-                       wid = 1 ;
+                       wid = 1;
                }
-               if (wid>=0) {
+               if (wid >= 0) {
                        if (col >= ofst) {
                                if (x + wid > last_col) {
                                        /* Character crosses end of field, so fill balance of field with '>' characters instead */
@@ -1812,7 +1819,7 @@ void genfield(SCRN *t,int *scrn,int *attr,int x,int y,int ofst,unsigned char *s,
                                                ++attr;
                                                ++x;
                                        }
-                               } else if(wid) {
+                               } else /* if (wid >(=) 0) */ {
                                        /* Emit character */
                                        outatr(locale_map, t, scrn, attr, x, y, c, my_atr);
                                        x += wid;
@@ -1833,7 +1840,7 @@ void genfield(SCRN *t,int *scrn,int *attr,int x,int y,int ofst,unsigned char *s,
                                }
                        } else
                                col += wid;
-       }
+               }
        }
        /* Fill balance of field with spaces */
        while (x < last_col) {
@@ -1922,14 +1929,14 @@ void genfmt(SCRN *t, int x, int y, int ofst, const unsigned char *s, int flg)
                                /* UTF-8 mode: decode character and determine its width */
                                c = utf8_decode(&sm,c);
                                if (c >= 0) {
-                                               wid = joe_wcwidth(1,c);
+                                       wid = joe_wcwidth(1, c);
                                }
                        } else {
                                /* Byte mode: character is one column wide */
-                               wid = 1 ;
+                               wid = 1;
                        }
 
-                       if (wid>=0) {
+                       if (wid >= 0) {
                                if (col >= ofst) {
                                        outatr(locale_map, t, scrn, attr, x, y, c, atr);
                                        scrn += wid;